diff --git a/app/DD-Record-Organiser/ClassControlValues.vb b/app/DD-Record-Organiser/ClassControlValues.vb index 738db65..9fa9d98 100644 --- a/app/DD-Record-Organiser/ClassControlValues.vb +++ b/app/DD-Record-Organiser/ClassControlValues.vb @@ -2,6 +2,100 @@ Public Class ClassControlValues + Public Shared Function ControlHasValue(control As Control) As Boolean + + Select Case control.GetType() + Case GetType(TextBox) + Dim textbox As TextBox = DirectCast(control, TextBox) + If textbox.Text.Trim() = String.Empty Then + Return False + Else + Return True + End If + + Case GetType(ComboBox) + Dim combobox As ComboBox = DirectCast(control, ComboBox) + If combobox.Text.Trim() = String.Empty Then + Return False + Else + Return True + End If + + Case GetType(CheckBox) + Dim checkbox As CheckBox = DirectCast(control, CheckBox) + Return checkbox.Checked + + Case GetType(RadioButton) + Dim radiobutton As RadioButton = DirectCast(control, RadioButton) + Return radiobutton.Checked + + Case GetType(DevExpress.XtraEditors.DateEdit) + Dim datepicker As DevExpress.XtraEditors.DateEdit = DirectCast(control, DevExpress.XtraEditors.DateEdit) + If IsDBNull(datepicker.EditValue) Then + Return False + Else + Return True + End If + + Case GetType(DevExpress.XtraEditors.ListBoxControl) + Dim listbox As DevExpress.XtraEditors.ListBoxControl = DirectCast(control, DevExpress.XtraEditors.ListBoxControl) + If listbox.SelectedIndex = -1 Then + Return False + Else + Return True + End If + + Case GetType(DevExpress.XtraEditors.CheckedListBoxControl) + Dim checkedlistbox As DevExpress.XtraEditors.CheckedListBoxControl = DirectCast(control, DevExpress.XtraEditors.CheckedListBoxControl) + If checkedlistbox.SelectedItems.Count = 0 Then + Return False + Else + Return True + End If + + Case GetType(PictureBox) + Dim picturebox = DirectCast(control, PictureBox) + If IsNothing(picturebox.BackgroundImage) Then + Return False + Else + Return True + End If + + Case Else + If LogErrorsOnly = False Then ClassLogger.Add(">> Sub LoadControlValue - Control-Type nicht berücksichtigt: " & GetType(Control).ToString(), False) + End Select + + End Function + + ' Überprüft, welche Controls "Required" sind + Public Shared Function CheckRequiredControlValues(controls As Control.ControlCollection) As List(Of String) + Dim missingValues As New List(Of String) + + For Each Control As Control In controls + + Dim metadata = DirectCast(Control.Tag, ClassControlMetadata) + + ' Groupbox muss rekursiv überprüft werden + If TypeOf Control Is GroupBox Then + Dim groupbox As GroupBox = DirectCast(Control, GroupBox) + Dim gbfields As List(Of String) = CheckRequiredControlValues(groupbox.Controls) + missingValues.AddRange(gbfields) + Continue For + End If + + If IsNothing(metadata.Required) OrElse metadata.Required = False Then + Continue For + End If + + If Not ControlHasValue(Control) Then + missingValues.Add(Control.Name) + End If + + + Next + + Return missingValues + End Function Public Shared Sub LoadControlValues(RecordId As Integer, ParentRecordId As Integer, FormId As Integer, controls As Control.ControlCollection) Try @@ -365,6 +459,10 @@ Public Class ClassControlValues Case GetType(DevExpress.XtraEditors.DateEdit) Dim datepicker As DevExpress.XtraEditors.DateEdit = DirectCast(control, DevExpress.XtraEditors.DateEdit) + If IsDBNull(autoValue) Then + autoValue = String.Empty + End If + Dim result As EnumDateTimePickerDefaultValueOptions = EnumDateTimePickerDefaultValueOptions.Empty Dim success = [Enum].TryParse(Of EnumDateTimePickerDefaultValueOptions)(autoValue, result) @@ -390,7 +488,7 @@ Public Class ClassControlValues End Sub #End Region - + Public Shared Function Get_Control_Value_for_ID(Control_ID As Integer, Record_ID As Integer) Try Return ClassDatabase.Execute_Scalar("SELECT VALUE FROM TBPMO_CONTROL_VALUE WHERE CONTROL_ID = " & Control_ID & " AND RECORD_ID = " & Record_ID, True) diff --git a/app/DD-Record-Organiser/My Project/AssemblyInfo.vb b/app/DD-Record-Organiser/My Project/AssemblyInfo.vb index 32d50d2..07c3534 100644 --- a/app/DD-Record-Organiser/My Project/AssemblyInfo.vb +++ b/app/DD-Record-Organiser/My Project/AssemblyInfo.vb @@ -33,7 +33,7 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + \ No newline at end of file diff --git a/app/DD-Record-Organiser/frmForm_Constructor_Main_2.vb b/app/DD-Record-Organiser/frmForm_Constructor_Main_2.vb index d69955d..b620673 100644 --- a/app/DD-Record-Organiser/frmForm_Constructor_Main_2.vb +++ b/app/DD-Record-Organiser/frmForm_Constructor_Main_2.vb @@ -975,7 +975,7 @@ Public Class frmForm_Constructor_Main_2 Try Dim Control As Control = sender Dim ControlName As String = Control.Name - Dim ControlId As Integer = Control.Tag ' GetControlID_for_Name(ControlName, FORM_ID) + Dim ControlId As Integer = DirectCast(Control.Tag, ClassControlMetadata).Id ' GetControlID_for_Name(ControlName, FORM_ID) Dim dr As DataRow = ClassFunctionCommands.LoadFunction(ControlId) @@ -1048,7 +1048,16 @@ Public Class frmForm_Constructor_Main_2 End If End If 'Update aller Control-Werte - Dim ResultMessage = Update_Record_OnChange() + Dim ResultMessage + ' Wenn MussFelder nicht ausgefüllt werden, wird eine exception geworfen und abgefangen + Try + ResultMessage = Update_Record_OnChange() + Catch ex As Exception + MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Fehler beim Speichern des Datensatzes") + Me.Cursor = Cursors.Default + Exit Sub + End Try + Dim recid As Integer Update_Status_Label(True, ResultMessage, EDIT_STATE) @@ -1773,7 +1782,13 @@ Public Class frmForm_Constructor_Main_2 'Me.pnlDetails.Enabled = False 'CtrlCommandUI.IsInsert = False End If - Update_Record_OnChange() + + Try + Update_Record_OnChange() + Catch ex As Exception + MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Fehler beim Speichern des Datensatzes") + End Try + End If CtrlCommandUI.IsInsert = False RECORD_CHANGED = False @@ -2297,6 +2312,17 @@ Public Class frmForm_Constructor_Main_2 End Sub Private Function Update_Record_OnChange() As String + ' Überprüfen, ob alle "Required Felder ausgefüllt wurden" + + Dim missingControlValues As List(Of String) = ClassControlValues.CheckRequiredControlValues(CtrlBuilder.MasterPanel.Controls) + If missingControlValues.Count > 0 Then + + Dim nameString As String = String.Join(vbNewLine, missingControlValues) + Dim errorMessage As String = String.Format("Die folgenden Steuerelemente müssen ausgefüllt sein: {0}{1}", vbNewLine, nameString) + + Throw New Exception(errorMessage) + End If + ' Record Speichern Dim ResultMessage = CtrlCommandUI.SaveRecord(SELECTED_RECORD_ID, FORM_ID, PARENT_RECORDID) 'Jetzt die für die Entität notwendigen Prroceduren ausführen