Common/DocumentResultList: Rework layout with DockManager

This commit is contained in:
Jonathan Jenne
2022-03-14 16:33:15 +01:00
parent 262ed2143f
commit 538790aa42
16 changed files with 1797 additions and 519 deletions

View File

@@ -19,7 +19,7 @@ Public Class frmObjectPropertyDialog
Private ReadOnly Client As Client
Private ReadOnly ObjectId As Int64
Private ReadOnly DatabaseIDB As MSSQLServer
Private ReadOnly ControlManager As PropertyControls
Private ReadOnly ControlManager As AttributeControls
Private ReadOnly Property LogConfig As LogConfig Implements IBaseForm.LogConfig
Private ReadOnly Property Logger As Logger Implements IBaseForm.Logger
@@ -38,7 +38,9 @@ Public Class frmObjectPropertyDialog
Client = pClient
ObjectId = pObjectId
DatabaseIDB = Environment.DatabaseIDB
ControlManager = New PropertyControls(LogConfig, DatabaseIDB)
ControlManager = New AttributeControls(LogConfig, Environment, pClient)
AddHandler ControlManager.EditValueChanged, AddressOf BaseEdit_EditValueChanged
ErrorHandler = New BaseErrorHandler(LogConfig, Me)
End Sub
@@ -74,37 +76,7 @@ Public Class frmObjectPropertyDialog
End Try
End Sub
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)
If oResult.OK = False Then
Throw New ApplicationException($"Attributes for Business Entity {EntityId} could not be retrieved!")
ElseIf oResult.Table.Rows.Count = 0 Then
Throw New ApplicationException($"BusinessEntity {EntityId} does not have any attributes!")
Else
Dim oAttributes As New List(Of Attribute)
For Each oRow As DataRow In oResult.Table.Rows
oAttributes.Add(New Attribute() With {
.ID = oRow.Item("ATTR_ID"),
.Title = oRow.Item("ATTR_TITLE"),
.TypeID = oRow.Item("TYPE_ID"),
.TypeName = oRow.Item("TYPE_NAME"),
.IsSystem = Convert.ToBoolean(oRow.Item("SYS_ATTRIBUTE"))
})
Next
Return oAttributes
End If
Catch ex As Exception
Logger.Error(ex)
Return New List(Of Attribute)
End Try
End Function
Private Async Function GetBusinessEntitiesForObjectId(ObjectId As Long) As Task(Of List(Of Long))
Try
@@ -161,22 +133,6 @@ Public Class frmObjectPropertyDialog
Return oResult.Table
End Function
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)
Return oResult.Scalar
End Function
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)
Return oResult.Table
End Function
Private Sub cmbBusinessEntity_EditValueChanged(sender As Object, e As EventArgs) Handles cmbBusinessEntity.EditValueChanged
Load_Attributes()
End Sub
@@ -189,38 +145,13 @@ Public Class frmObjectPropertyDialog
Exit Sub
End If
Dim oAttributes = Await GetAttributesForBusinessEntity(oEntityId)
Dim oAttributes = Await ControlManager.GetAttributesForBusinessEntity(oEntityId)
If oAttributes.Count = 0 Then
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 = ControlManager.GetControlForAttribute(oAttribute, Not oEditable)
Dim oItem As LayoutControlItem = AttributeLayout.AddItem()
oItem.Text = oAttribute.Title
oItem.Name = oAttribute.Title
oItem.Control = oControl
Next
For Each oItem As LayoutControlItem In AttributeLayout.Items
If TypeOf oItem.Control Is BaseEdit Then
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 oGrid = DirectCast(oItem.Control, GridControl)
oGrid.DataSource = oValueTable
End If
Next
Await ControlManager.LoadControlsForAttributes(ObjectId, oAttributes, AttributeLayout)
Catch ex As Exception
Logger.Error(ex)
End Try
@@ -240,14 +171,6 @@ Public Class frmObjectPropertyDialog
End If
End Sub
Private Function ShouldControlBeEditable(pAttribute As Attribute) As Boolean
If pAttribute.IsSystem Then
Return False
End If
Return True
End Function
Private Function ShowAttributeHistory(pDatatable As DataTable) As Boolean
Try
GridValueHistory.DataSource = pDatatable
@@ -312,8 +235,4 @@ Public Class frmObjectPropertyDialog
ErrorHandler.ShowErrorMessage(ex, "btnSave_ItemClick")
End Try
End Sub
Private Sub TabFormControl1_Click(sender As Object, e As EventArgs) Handles TabFormControl1.Click
End Sub
End Class