Common: ObjectPropertyDialog

This commit is contained in:
Jonathan Jenne
2022-03-11 15:46:59 +01:00
parent a6de7e0af2
commit 7f9fd6ee58
36 changed files with 785 additions and 326 deletions

View File

@@ -9,28 +9,37 @@ Imports DigitalData.Modules.ZooFlow
Imports DigitalData.Modules.Language
Imports DevExpress.XtraGrid
Imports DigitalData.Modules.EDMI.API
Imports DigitalData.GUIs.Common.Base
Imports DigitalData.Modules.Base
Public Class frmObjectPropertyDialog
Private _LogConfig As LogConfig
Private _Logger As Logger
Private _Environment As Environment
Private ReadOnly _Client As Client
Private _ObjectId As Int64
Private _Db As MSSQLServer
Private _Controls As PropertyControls
Implements IBaseForm
Public Sub New(LogConfig As LogConfig, Environment As Environment, Client As Client, ObjectId As Long)
Private ReadOnly Environment As Environment
Private ReadOnly Client As Client
Private ReadOnly ObjectId As Int64
Private ReadOnly DatabaseIDB As MSSQLServer
Private ReadOnly ControlManager As PropertyControls
Private ReadOnly Property LogConfig As LogConfig Implements IBaseForm.LogConfig
Private ReadOnly Property Logger As Logger Implements IBaseForm.Logger
Private ReadOnly Property ErrorHandler As BaseErrorHandler Implements IBaseForm.ErrorHandler
Private ReadOnly Changes As New Dictionary(Of String, Object)
Public Sub New(pLogConfig As LogConfig, pEnvironment As Environment, pClient As Client, pObjectId As Long)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
_Environment = Environment
_Client = Client
_ObjectId = ObjectId
_Db = _Environment.DatabaseIDB
_Controls = New PropertyControls(_LogConfig, _Db)
LogConfig = pLogConfig
Logger = pLogConfig.GetLogger()
Environment = pEnvironment
Client = pClient
ObjectId = pObjectId
DatabaseIDB = Environment.DatabaseIDB
ControlManager = New PropertyControls(LogConfig, DatabaseIDB)
ErrorHandler = New BaseErrorHandler(LogConfig, Me)
End Sub
Private Async Sub frmObjectPropertyDialog_Load(sender As Object, e As EventArgs) Handles MyBase.Load
@@ -39,31 +48,27 @@ Public Class frmObjectPropertyDialog
Try
oHandle = SplashScreenManager.ShowOverlayForm(Me)
If IsNothing(_ObjectId) Then
If IsNothing(ObjectId) Then
Throw New ApplicationException("No valid Object Id supplied!")
End If
Dim oEntityIds = Await GetBusinessEntitiesForObjectId(_ObjectId)
Dim oHistoryDataTable = Await GetValueHistoryForObjectId(_ObjectId)
Dim oObjectProperties = Await GetPropertiesForObjectId(_ObjectId)
Dim oEntityIds = Await GetBusinessEntitiesForObjectId(ObjectId)
Dim oValueHistoryTable = Await GetValueHistoryForObjectId(ObjectId)
Dim oObjectHistoryTable = Await GetObjectHistoryForObjectID(ObjectId)
Dim oObjectProperties = Await GetPropertiesForObjectId(ObjectId)
Dim oCombobox As RepositoryItemComboBox = DirectCast(cmbBusinessEntity.Edit, RepositoryItemComboBox)
oCombobox.Items.AddRange(oEntityIds)
ShowAttributeHistory(oHistoryDataTable)
ShowAttributeHistory(oValueHistoryTable)
ShowObjectHistory(oObjectHistoryTable)
ShowObjectProperties(oObjectProperties)
'If oEntityIds.Count = 1 Then
' cmbBusinessEntity.EditValue = oEntityIds.First()
'End If
cmbBusinessEntity.EditValue = oEntityIds.First()
Catch ex As ApplicationException
_Logger.Error(ex)
MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ex As Exception
_Logger.Error(ex)
MessageBox.Show("Unhandled exception occurred. Please check the log." & vbNewLine & ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ErrorHandler.ShowErrorMessage(ex, "frmObjectPropertyDialog_Load")
Finally
If oHandle IsNot Nothing
If oHandle IsNot Nothing Then
SplashScreenManager.CloseOverlayForm(oHandle)
End If
End Try
@@ -71,8 +76,8 @@ Public Class frmObjectPropertyDialog
Private Async Function GetAttributesForBusinessEntity(EntityId As Long) As Task(Of List(Of Attribute))
Try
Dim oSQL = $"SELECT * FROM VWIDB_BE_ATTRIBUTE WHERE BE_ID = {EntityId} AND LANG_CODE = '{_Environment.User.Language}'"
Dim oResult = Await _Client.GetDatatableFromIDBAsync(oSQL)
Dim oSQL = $"SELECT * FROM VWIDB_BE_ATTRIBUTE WHERE BE_ID = {EntityId} AND LANG_CODE = '{Environment.User.Language}'"
Dim oResult = Await Client.GetDatatableFromIDBAsync(oSQL)
If oResult.OK = False Then
Throw New ApplicationException($"Attributes for Business Entity {EntityId} could not be retrieved!")
@@ -96,7 +101,7 @@ Public Class frmObjectPropertyDialog
Return oAttributes
End If
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
Return New List(Of Attribute)
End Try
End Function
@@ -104,7 +109,7 @@ Public Class frmObjectPropertyDialog
Private Async Function GetBusinessEntitiesForObjectId(ObjectId As Long) As Task(Of List(Of Long))
Try
Dim oSQL = $"SELECT BE_ID FROM TBIDB_OBJECT_BE WHERE IDB_OBJ_ID = {ObjectId}"
Dim oResult = Await _Client.GetDatatableFromIDBAsync(oSQL)
Dim oResult = Await Client.GetDatatableFromIDBAsync(oSQL)
If oResult.OK = False Then
Throw New ApplicationException($"Business Entities could not be retrieved!")
@@ -122,21 +127,36 @@ Public Class frmObjectPropertyDialog
Return oEntities
End If
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
Return New List(Of Long)
End Try
End Function
Private Async Function GetValueHistoryForObjectId(ObjectId As Long) As Task(Of DataTable)
Dim oSQL As String = $"SELECT * FROM VWIDB_CHANGE_LOG WHERE IDB_OBJ_ID = {ObjectId} ORDER BY ChangeID DESC"
Dim oResult = Await _Client.GetDatatableFromIDBAsync(oSQL)
Dim oSQL As String = $"
SELECT * FROM VWIDB_CHANGE_LOG
WHERE IDB_OBJ_ID = {ObjectId} AND
ORDER BY ChangeID DESC
"
Dim oResult = Await Client.GetDatatableFromIDBAsync(oSQL)
Return oResult.Table
End Function
Private Async Function GetObjectHistoryForObjectId(ObjectId As Long) As Task(Of DataTable)
Dim oSQL As String = $"
SELECT * FROM VWIDB_DOC_STATES
WHERE IDB_OBJ_ID = {ObjectId} AND LANG_CODE = '{Environment.User.Language}'
ORDER BY ADDED_WHEN DESC
"
Dim oResult = Await Client.GetDatatableFromIDBAsync(oSQL)
Return oResult.Table
End Function
Private Async Function GetPropertiesForObjectId(ObjectId As Long) As Task(Of DataTable)
Dim oSQL As String = $"SELECT * FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {ObjectId}"
Dim oResult = Await _Client.GetDatatableFromIDBAsync(oSQL)
Dim oResult = Await Client.GetDatatableFromIDBAsync(oSQL)
Return oResult.Table
End Function
@@ -144,7 +164,7 @@ Public Class frmObjectPropertyDialog
Private Async Function GetAttributeValue(AttributeName As String, ObjectId As Long, Optional LanguageCode As String = "de-DE", Optional IsForeign As Boolean = False) As Task(Of Object)
Dim oIsForeign = IIf(IsForeign, 1, 0)
Dim oSQL = $"SELECT TERM_VALUE FROM [dbo].[FNIDB_PM_GET_VARIABLE_VALUE] ({ObjectId}, '{AttributeName}', '{LanguageCode}', {oIsForeign})"
Dim oResult = Await _Client.GetScalarValueFromIDBAsync(oSQL)
Dim oResult = Await Client.GetScalarValueFromIDBAsync(oSQL)
Return oResult.Scalar
End Function
@@ -152,12 +172,12 @@ Public Class frmObjectPropertyDialog
Private Async Function GetAttributeValueAsTable(AttributeName As String, ObjectId As Long, Optional LanguageCode As String = "de-DE", Optional IsForeign As Boolean = False) As Task(Of DataTable)
Dim oIsForeign = IIf(IsForeign, 1, 0)
Dim oSQL = $"SELECT TERM_VALUE FROM [dbo].[FNIDB_PM_GET_VARIABLE_VALUE] ({ObjectId}, '{AttributeName}', '{LanguageCode}', {oIsForeign})"
Dim oResult = Await _Client.GetDatatableFromIDBAsync(oSQL)
Dim oResult = Await Client.GetDatatableFromIDBAsync(oSQL)
Return oResult.Table
End Function
Private Async Sub cmbBusinessEntity_EditValueChanged(sender As Object, e As EventArgs) Handles cmbBusinessEntity.EditValueChanged
Private Sub cmbBusinessEntity_EditValueChanged(sender As Object, e As EventArgs) Handles cmbBusinessEntity.EditValueChanged
Load_Attributes()
End Sub
Private Async Sub Load_Attributes()
@@ -172,12 +192,12 @@ Public Class frmObjectPropertyDialog
Dim oAttributes = Await GetAttributesForBusinessEntity(oEntityId)
If oAttributes.Count = 0 Then
MsgBox($"Es konnten keine Attribute für das Objekt '{_ObjectId}' geladen werden!", MsgBoxStyle.Critical, Text)
MsgBox($"Es konnten keine Attribute für das Objekt '{ObjectId}' geladen werden!", MsgBoxStyle.Critical, Text)
End If
For Each oAttribute As Attribute In oAttributes
Dim oEditable = ShouldControlBeEditable(oAttribute)
Dim oControl = _Controls.GetControlForAttribute(oAttribute, Not oEditable)
Dim oControl = ControlManager.GetControlForAttribute(oAttribute, Not oEditable)
Dim oItem As LayoutControlItem = AttributeLayout.AddItem()
oItem.Text = oAttribute.Title
@@ -187,12 +207,14 @@ Public Class frmObjectPropertyDialog
For Each oItem As LayoutControlItem In AttributeLayout.Items
If TypeOf oItem.Control Is BaseEdit Then
Dim oValue = Await GetAttributeValue(oItem.Name, _ObjectId)
Dim oValue = Await GetAttributeValue(oItem.Name, ObjectId)
Dim oEdit = DirectCast(oItem.Control, BaseEdit)
oEdit.EditValue = oValue
AddHandler oEdit.EditValueChanged, AddressOf BaseEdit_EditValueChanged
ElseIf TypeOf oItem.Control Is GridControl Then
Dim oValueTable = Await GetAttributeValueAsTable(oItem.Name, _ObjectId)
Dim oValueTable = Await GetAttributeValueAsTable(oItem.Name, ObjectId)
Dim oGrid = DirectCast(oItem.Control, GridControl)
oGrid.DataSource = oValueTable
@@ -200,9 +222,22 @@ Public Class frmObjectPropertyDialog
End If
Next
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
End Try
End Sub
Private Sub BaseEdit_EditValueChanged(sender As Object, e As EventArgs)
Dim oControl As BaseEdit = sender
Dim oAttribute As Attribute = oControl.Tag
Dim oValue = oControl.EditValue
Dim oKey = oAttribute.Title
If Changes.ContainsKey(oKey) Then
Changes.Item(oKey) = oValue
Else
Changes.Add(oAttribute.Title, oValue)
End If
End Sub
Private Function ShouldControlBeEditable(pAttribute As Attribute) As Boolean
@@ -215,15 +250,22 @@ Public Class frmObjectPropertyDialog
Private Function ShowAttributeHistory(pDatatable As DataTable) As Boolean
Try
If pDatatable.Rows.Count > 0
GridValueHistory.DataSource = pDatatable
Else
TabPageHistory.Visible = False
End If
GridValueHistory.DataSource = pDatatable
Return True
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
Return False
End Try
End Function
Private Function ShowObjectHistory(pDatatable As DataTable) As Boolean
Try
GridObjectHistory.DataSource = pDatatable
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
@@ -243,8 +285,39 @@ Public Class frmObjectPropertyDialog
Return True
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
Return False
End Try
End Function
Private Async Sub btnSave_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSave.ItemClick
Try
For Each oChange As KeyValuePair(Of String, Object) In Changes
Logger.Info("Updating Attribute [{0}] with value [{1}]", oChange.Key, oChange.Value.ToString)
Await Client.SetAttributeValueAsync(ObjectId, oChange.Key, oChange.Value, New Options.SetAttributeValueOptions With {
.Language = Environment.User.Language,
.Username = Environment.User.UserName
})
Logger.Info("Updating Object State for Object [{0}]", ObjectId)
Await Client.SetObjectStateAsync(ObjectId, IDB.FileStore.OBJECT_STATE_METADATA_CHANGED, New Options.SetObjectStateOptions With {
.Language = Environment.User.Language,
.Username = Environment.User.UserName
})
Next
ErrorHandler.ShowInfoMessage($"{Changes.Count} Änderungen gespeichert!")
Changes.Clear()
Catch ex As Exception
ErrorHandler.ShowErrorMessage(ex, "btnSave_ItemClick")
End Try
End Sub
Private Sub TabFormControl1_Click(sender As Object, e As EventArgs) Handles TabFormControl1.Click
End Sub
Private Sub GroupControl1_Paint(sender As Object, e As PaintEventArgs) Handles GroupControl1.Paint
End Sub
End Class