ZooFlow: PropertyDialog, ContextMenu, Async Queries in Database
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports System.Windows.Forms
|
||||
Imports DevExpress.XtraEditors
|
||||
Imports DevExpress.XtraEditors.Repository
|
||||
Imports DevExpress.XtraLayout
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.ZooFlow
|
||||
|
||||
Public Class frmObjectPropertyDialog
|
||||
@@ -6,6 +11,8 @@ Public Class frmObjectPropertyDialog
|
||||
Private _Logger As Logger
|
||||
Private _Environment As Environment
|
||||
Private _ObjectId As Int64
|
||||
Private _Db As MSSQLServer
|
||||
Private _Controls As PropertyControls
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Environment As Environment, ObjectId As Long)
|
||||
' Dieser Aufruf ist für den Designer erforderlich.
|
||||
@@ -16,9 +23,96 @@ Public Class frmObjectPropertyDialog
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_Environment = Environment
|
||||
_ObjectId = ObjectId
|
||||
_Db = _Environment.DatabaseIDB
|
||||
_Controls = New PropertyControls(_LogConfig, _Db)
|
||||
End Sub
|
||||
|
||||
Private Sub frmObjectPropertyDialog_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Private Async Sub frmObjectPropertyDialog_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Try
|
||||
Dim EntityIds = Await GetBusinessEntitiesForObjectId(_ObjectId)
|
||||
Dim oCombobox As RepositoryItemComboBox = DirectCast(cmbBusinessEntity.Edit, RepositoryItemComboBox)
|
||||
oCombobox.Items.AddRange(EntityIds)
|
||||
|
||||
If EntityIds.Count = 1 Then
|
||||
cmbBusinessEntity.EditValue = EntityIds.First()
|
||||
End If
|
||||
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", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Async Function GetAttributesForBusinessEntity(EntityId As Long) As Task(Of List(Of Attribute))
|
||||
Dim oSQL = $"SELECT * FROM VWIDB_BE_ATTRIBUTE WHERE BE_ID = {EntityId}"
|
||||
Dim oDatatable = Await _Db.GetDatatableAsync(oSQL)
|
||||
|
||||
If oDatatable.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 oDatatable.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")
|
||||
})
|
||||
Next
|
||||
|
||||
Return oAttributes
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Async Function GetBusinessEntitiesForObjectId(ObjectId) As Task(Of List(Of Long))
|
||||
Dim oSQL = $"SELECT BE_ID FROM TBIDB_OBJECT_BE WHERE IDB_OBJ_ID = {ObjectId}"
|
||||
Dim oDatatable = Await _Db.GetDatatableAsync(oSQL)
|
||||
|
||||
If oDatatable.Rows.Count = 0 Then
|
||||
Throw New ApplicationException($"ObjectId {ObjectId} is not assigned to any business entity!")
|
||||
Else
|
||||
Dim oEntities As New List(Of Long)
|
||||
|
||||
For Each oRow In oDatatable.Rows
|
||||
oEntities.Add(oRow.item("BE_ID"))
|
||||
Next
|
||||
|
||||
Return oEntities
|
||||
End If
|
||||
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 oTermValue = Await _Db.GetScalarValueAsync(oSQL)
|
||||
|
||||
Return oTermValue
|
||||
End Function
|
||||
|
||||
Private Async Sub cmbBusinessEntity_EditValueChanged(sender As Object, e As EventArgs) Handles cmbBusinessEntity.EditValueChanged
|
||||
Dim oEntityId As Long
|
||||
|
||||
If Long.TryParse(cmbBusinessEntity.EditValue, oEntityId) = False Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oAttributes = Await GetAttributesForBusinessEntity(oEntityId)
|
||||
|
||||
For Each oAttribute As Attribute In oAttributes
|
||||
Dim oControl = _Controls.GetControlForAttribute(oAttribute)
|
||||
Dim oItem As LayoutControlItem = Root.AddItem()
|
||||
oItem.Text = oAttribute.Title
|
||||
oItem.Name = oAttribute.Title
|
||||
oItem.Control = oControl
|
||||
Next
|
||||
|
||||
For Each oItem As LayoutControlItem In Root.Items
|
||||
Dim oValue = Await GetAttributeValue(oItem.Name, _ObjectId)
|
||||
Dim oEdit = DirectCast(oItem.Control, BaseEdit)
|
||||
oEdit.EditValue = oValue
|
||||
Next
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user