diff --git a/app/DD-Record-Organiser/ClassControlBuilder.vb b/app/DD-Record-Organiser/ClassControlBuilder.vb index 02be6ca..3d19be6 100644 --- a/app/DD-Record-Organiser/ClassControlBuilder.vb +++ b/app/DD-Record-Organiser/ClassControlBuilder.vb @@ -218,46 +218,14 @@ Public Class ClassControlBuilder ' Jetzt wird das SQL Command ausgeführt, es MUSS einen Boolschen Wert zurückgeben, True, False, 0, 1 Dim dt As DataTable = ClassDatabase.Return_Datatable(sqlcommand) - Dim type = dependingControl.GetType().Name - If dt.Rows.Count = 1 Then - ' Jetzt können wir das dependingControl enablen/disablen - Select Case type - Case "DateEdit" - Try - Dim enabled As Boolean = CBool(dt.Rows(0).Item(0)) - dependingControl.Enabled = enabled - Catch ex As Exception - ClassLogger.Add("Unexpected Error in EnableControls - DateEdit: " & ex.Message, True) - End Try - Case "CustomComboBox" - Try - Dim enabled As Boolean = CBool(dt.Rows(0).Item(0)) - dependingControl.Enabled = enabled - Catch ex As Exception - ClassLogger.Add("Unexpected Error in EnableControls - CustomComboBox: " & ex.Message, True) - End Try - Case "TextBox" - Try - Dim enabled As Boolean = CBool(dt.Rows(0).Item(0)) - dependingControl.Enabled = enabled - Catch ex As Exception - ClassLogger.Add("Unexpected Error in EnableControls - TextBox: " & ex.Message, True) - End Try - Case "CheckBox" - Try - Dim enabled As Boolean = CBool(dt.Rows(0).Item(0)) - dependingControl.Enabled = enabled - Catch ex As Exception - ClassLogger.Add("Unexpected Error in EnableControls - Checkbox: " & ex.Message, True) - End Try - End Select + If dt.Rows.Count = 1 Then + Dim enabled As Boolean = CBool(dt.Rows(0).Item(0)) + dependingControl.Enabled = enabled Else ClassLogger.Add(" >> Attention: RowCount for enabling control was '" & dt.Rows.Count.ToString & "' and not 1 as expected - Check SQL: '" & sqlcommand & "'") End If - - End If Next Catch ex As Exception @@ -290,6 +258,8 @@ Public Class ClassControlBuilder DirectCast(dependingControl, Label).Text = "" Case "TextBox" DirectCast(dependingControl, TextBox).Text = "" + Case "GridControl" + DirectCast(dependingControl, DevExpress.XtraGrid.GridControl).DataSource = Nothing End Select Next @@ -368,7 +338,7 @@ Public Class ClassControlBuilder ClassLogger.Add("Unexpected Error in converting Value '" & value & "' to date - Control-ID: " & dependingControlId.ToString & "- Error: " & ex.Message) Continue For End Try - + ControlLoader.DateTimePicker.LoadValue(dependingControl, dateValue) Dim sql1 = String.Format("SELECT GUID FROM TBPMO_CONTROL_VALUE WHERE CONTROL_ID = {0} AND RECORD_ID = {1}", dependingControlId, CURRENT_RECORD_ID) Dim id = ClassDatabase.Execute_Scalar(sql1) @@ -399,15 +369,18 @@ Public Class ClassControlBuilder Case "CustomComboBox" ControlLoader.Combobox.SetDataSource(DirectCast(dependingControl, CustomComboBox), dt) Case "CheckedListBoxControl" - ControlLoader.CheckedListBox.SetDataSource(DirectCast(dependingControl, DevExpress.XtraEditors.CheckedListBoxControl), dt) - 'Hier werden nun evtl schon gesetzte Werte für CheckedListBox angehakt + Dim checkedlistbox = DirectCast(dependingControl, DevExpress.XtraEditors.CheckedListBoxControl) + ControlLoader.CheckedListBox.SetDataSource(checkedlistbox, dt) + + ' Hier werden nun evtl schon gesetzte Werte für CheckedListBox angehakt ' Wert per LINQ aus DT_ControlValues suchen der zur aktuellen controlId passt Dim values As List(Of Object) = (From row1 In CURRENT_CONTROL_VALUES.AsEnumerable() Where row1.Item("CONTROL_ID") = dependingControlId Select row1.Item("VALUE")).ToList() - ClassControlValues.LoadControlValue(CURRENT_RECORD_ID, CURRENT_PARENT_RECORD_ID, dependingControlId, dependingControl, values, CURRENT_FORM_ID) + 'ClassControlValues.LoadControlValue(CURRENT_RECORD_ID, CURRENT_PARENT_RECORD_ID, dependingControlId, dependingControl, values, CURRENT_FORM_ID) + ControlLoader.CheckedListBox.LoadValue(checkedlistbox, values) Case "Label" If dt.Rows.Count = 1 Then @@ -448,6 +421,15 @@ Public Class ClassControlBuilder Else ClassLogger.Add(" >> Attention: RowCount for depending control was '" & dt.Rows.Count.ToString & "' and not 1 as expected - Check SQL: '" & sqlcommand & "'") End If + Case "GridControl" + Dim gridControl = DirectCast(dependingControl, DevExpress.XtraGrid.GridControl) + ControlLoader.DataGridViewCheckable.SetDataSource(gridControl, dt) + + Dim values As List(Of Object) = (From row1 In CURRENT_CONTROL_VALUES.AsEnumerable() + Where row1.Item("CONTROL_ID") = dependingControlId + Select row1.Item("VALUE")).ToList() + + ControlLoader.DataGridViewCheckable.LoadValue(gridControl, values) End Select diff --git a/app/DD-Record-Organiser/ClassControlLoader.vb b/app/DD-Record-Organiser/ClassControlLoader.vb index 874b86b..ddeedec 100644 --- a/app/DD-Record-Organiser/ClassControlLoader.vb +++ b/app/DD-Record-Organiser/ClassControlLoader.vb @@ -110,20 +110,27 @@ End Function Overloads Shared Sub SetDataSource(control As DevExpress.XtraGrid.GridControl, dt As DataTable) - Dim sw As Stopwatch = Stopwatch.StartNew() - Dim columnCount As Integer = dt.Columns.Count + Try + Dim columnCount As Integer = dt.Columns.Count + Dim rowCount As Integer = dt.Rows.Count - control.BeginUpdate() + ' Zuerst die Datasource leeren und neu setzen + control.DataSource = Nothing + control.DataSource = dt - ' Damit beim Setzen von DisplayMember und ValueMember kein Fehler auftritt, - ' muss die Datasource zunächst geleert werden und der selected index auf -1 gesetzt werden. - control.DataSource = Nothing + ' Wir müssen PopulateColumns und RefreshData nach dem Setzen der Datasource aufrufen + ' ansonsten wird das Grid leer bleiben und die neuen Daten nicht anzeigen + control.MainView.PopulateColumns() + control.MainView.RefreshData() - ' Als letztes setzen wir die DataSource - control.DataSource = dt - control.EndUpdate() - sw.Stop() - ' Console.WriteLine("SetDataSource for {0} took {1}ms", control.Name, sw.ElapsedMilliseconds) + 'Jetzt noch den Columnname ändern + Dim gridview = DirectCast(control.MainView, DevExpress.XtraGrid.Views.Grid.GridView) + + Dim caption As String = ClassDatabase.Execute_Scalar(String.Format("SELECT COL_NAME FROM TBPMO_CONTROL WHERE GUID = {0}", DirectCast(control.Tag, ClassControlMetadata).Id)) + gridview.Columns(0).Caption = caption + Catch ex As Exception + MsgBox("Error in SetDataSource - GridControl: " & ex.Message, MsgBoxStyle.Critical) + End Try End Sub Overloads Shared Sub SetDataSource(control As CustomComboBox, dt As DataTable) diff --git a/app/DD-Record-Organiser/ClassControlValues.vb b/app/DD-Record-Organiser/ClassControlValues.vb index 814d4b6..37f80eb 100644 --- a/app/DD-Record-Organiser/ClassControlValues.vb +++ b/app/DD-Record-Organiser/ClassControlValues.vb @@ -444,6 +444,10 @@ Public Class ClassControlValues Dim chlistbox = DirectCast(Ctrl, DevExpress.XtraEditors.CheckedListBoxControl) ControlLoader.CheckedListBox.LoadList(chlistbox, FormId, connID, sqlcommand) + Case GetType(DevExpress.XtraGrid.GridControl) + Dim gridControl = DirectCast(Ctrl, DevExpress.XtraGrid.GridControl) + ControlLoader.DataGridViewCheckable.LoadList(gridControl, FormId, connID, sqlcommand) + End Select PerfomanceHelper.ResumeDraw(Ctrl) @@ -460,7 +464,8 @@ Public Class ClassControlValues ''' - ''' Sucht alle Controls in der aktuellen Entität, die eine Abhängigkeit besitzen + ''' Sucht alle Controls in der aktuellen Entität, die eine Abhängigkeit besitzen, + ''' und (de)aktiviert sie basierend auf dem Wert er Abhängigkeit ''' ''' Public Shared Sub Enable_Depending_Controls(FormId As Integer, RecordId As Integer, ParentRecordId As Integer, controls As Control.ControlCollection, entity_ID As Integer) @@ -523,42 +528,13 @@ Public Class ClassControlValues DependingControlSQL = regex.Replace(DependingControlSQL, value) Dim enableDT As DataTable = ClassDatabase.Return_Datatable(DependingControlSQL) - Dim type = DependingControl.GetType().Name - - ' Jetzt wird basierend auf dem Ergebnis das DependingControl aktiviert/deaktiviert - Select Case type - Case "DateEdit" - Try - Dim enabled As Boolean = CBool(enableDT.Rows(0).Item(0)) - DependingControl.Enabled = enabled - Catch ex As Exception - ClassLogger.Add("Unexpected Error in EnableControls - DateEdit: " & ex.Message, True) - End Try - Case "CustomComboBox" - Try - Dim enabled As Boolean = CBool(enableDT.Rows(0).Item(0)) - DependingControl.Enabled = enabled - Catch ex As Exception - ClassLogger.Add("Unexpected Error in EnableControls - CustomComboBox: " & ex.Message, True) - End Try - Case "TextBox" - Try - Dim enabled As Boolean = CBool(enableDT.Rows(0).Item(0)) - DependingControl.Enabled = enabled - Catch ex As Exception - ClassLogger.Add("Unexpected Error in EnableControls - TextBox: " & ex.Message, True) - End Try - Case "CheckBox" - Try - Dim enabled As Boolean = CBool(enableDT.Rows(0).Item(0)) - DependingControl.Enabled = enabled - Catch ex As Exception - ClassLogger.Add("Unexpected Error in EnableControls - Checkbox: " & ex.Message, True) - End Try - - End Select - + If dt.Rows.Count = 1 Then + Dim enabled As Boolean = CBool(dt.Rows(0).Item(0)) + DependingControl.Enabled = enabled + Else + ClassLogger.Add(" >> Attention: RowCount for enabling control was '" & dt.Rows.Count.ToString & "' and not 1 as expected - Check SQL: '" & DependingControlSQL & "'") + End If End If Next