MS_07122015
This commit is contained in:
@@ -265,42 +265,47 @@ Public Class ClassControlCommandsUI
|
||||
|
||||
|
||||
Function SaveRecord(RecordID As Integer, FormID As Integer, Optional foreignRecordID As Integer = 0) As String
|
||||
Dim ADDED_WHO As String = Environment.UserName
|
||||
Dim RECORD_ID As Integer
|
||||
Try
|
||||
Dim ADDED_WHO As String = Environment.UserName
|
||||
Dim RECORD_ID As Integer
|
||||
|
||||
If IsInsert Then
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> (SaveRecord) Insert", False)
|
||||
If IsInsert Then
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> (SaveRecord) Insert", False)
|
||||
|
||||
' Den Record erstellen
|
||||
If CreateRecord(FormID) = False Then
|
||||
' Den Record erstellen
|
||||
If CreateRecord(FormID) = False Then
|
||||
IsInsert = False
|
||||
Return "ERROR - INSERT RECORD NOT SUCCESSFUL"
|
||||
End If
|
||||
|
||||
' Die eben erstellte RecordID holen
|
||||
RECORD_ID = GetLastRecord()
|
||||
|
||||
' Wenn gegeben, foreignrecordID mit Record verknüpfen
|
||||
If foreignRecordID > 0 Then
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> foreignRecordID: " & foreignRecordID & "; Record-ID: " & RECORD_ID, False)
|
||||
ConnectRecord(foreignRecordID, RECORD_ID)
|
||||
End If
|
||||
|
||||
' Für angegebene Control Typen den Wert speichern
|
||||
InsertAllControls(FormID, RECORD_ID, _CtrlBuilder.AllControls)
|
||||
|
||||
' Status zurücksetzen
|
||||
IsInsert = False
|
||||
Return "ERROR - INSERT RECORD NOT SUCCESSFUL"
|
||||
|
||||
NEW_RECORD_ID = RECORD_ID
|
||||
CURRENT_RECORD_ID = RECORD_ID
|
||||
Return "Neuer Datensatz eingefügt - " & Now
|
||||
ElseIf IsInsert = False Then
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> (SaveRecord) Update RecordID: " & RECORD_ID, False)
|
||||
UpdateAllControls(FormID, RecordID, _CtrlBuilder.AllControls)
|
||||
|
||||
Return "Datensatz aktualisiert - " & Now
|
||||
End If
|
||||
|
||||
' Die eben erstellte RecordID holen
|
||||
RECORD_ID = GetLastRecord()
|
||||
|
||||
' Wenn gegeben, foreignrecordID mit Record verknüpfen
|
||||
If foreignRecordID > 0 Then
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> foreignRecordID: " & foreignRecordID & "; Record-ID: " & RECORD_ID, False)
|
||||
ConnectRecord(foreignRecordID, RECORD_ID)
|
||||
End If
|
||||
|
||||
' Für angegebene Control Typen den Wert speichern
|
||||
InsertAllControls(FormID, RECORD_ID, _CtrlBuilder.AllControls)
|
||||
|
||||
' Status zurücksetzen
|
||||
IsInsert = False
|
||||
|
||||
NEW_RECORD_ID = RECORD_ID
|
||||
CURRENT_RECORD_ID = RECORD_ID
|
||||
Return "Neuer Datensatz eingefügt - " & Now
|
||||
ElseIf IsInsert = False Then
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> (SaveRecord) Update RecordID: " & RECORD_ID, False)
|
||||
UpdateAllControls(FormID, RecordID, _CtrlBuilder.AllControls)
|
||||
|
||||
Return "Datensatz aktualisiert - " & Now
|
||||
End If
|
||||
Catch ex As Exception
|
||||
MsgBox("Unexpected Error in SaveRecord: " & ex.Message, MsgBoxStyle.Critical)
|
||||
End Try
|
||||
|
||||
End Function
|
||||
|
||||
Private Sub InsertAllControls(FormID As Integer, RecordID As Integer, controls As Control.ControlCollection)
|
||||
@@ -444,54 +449,64 @@ Public Class ClassControlCommandsUI
|
||||
End Sub
|
||||
|
||||
Private Sub UpdateAllControls(FormID As Integer, RecordID As Integer, controls As Control.ControlCollection)
|
||||
For Each ctrl As Control In controls
|
||||
Dim CONTROL_ID As Integer = GetControlID_for_RecordID(ctrl.Name, RecordID)
|
||||
Dim CONTROL_VALUE As String = Nothing
|
||||
Try
|
||||
For Each ctrl As Control In controls
|
||||
Dim CONTROL_ID As Integer = GetControlID_for_RecordID(ctrl.Name, RecordID)
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> CONTROL_ID: " & CONTROL_ID, False)
|
||||
Dim CONTROL_VALUE As String = Nothing
|
||||
|
||||
If TypeOf ctrl Is PictureBox Then
|
||||
Dim id As Integer = GetControlID_for_Name(ctrl.Name, FormID)
|
||||
UpsertImage(id, RecordID, ctrl.BackgroundImage)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
' Neues Control
|
||||
If CONTROL_ID = -1 Then
|
||||
CONTROL_VALUE = GetControlValue(ctrl)
|
||||
|
||||
' Kein Bekanntes Control oder Groupbox
|
||||
If IsNothing(CONTROL_VALUE) Then
|
||||
If TypeOf ctrl Is GroupBox Then
|
||||
Dim ctrls As Control.ControlCollection = DirectCast(ctrl, GroupBox).Controls
|
||||
|
||||
UpdateAllControls(FormID, RecordID, ctrls)
|
||||
End If
|
||||
Else
|
||||
InsertControlValue(ctrl.Name, RecordID, CONTROL_VALUE)
|
||||
If TypeOf ctrl Is PictureBox Then
|
||||
Dim id As Integer = GetControlID_for_Name(ctrl.Name, FormID)
|
||||
UpsertImage(id, RecordID, ctrl.BackgroundImage)
|
||||
Continue For
|
||||
End If
|
||||
Else ' Control Updaten
|
||||
CONTROL_VALUE = GetControlValue(ctrl)
|
||||
' Kein Bekanntes Control oder Groupbox
|
||||
If IsNothing(CONTROL_VALUE) Then
|
||||
If TypeOf ctrl Is GroupBox Then
|
||||
Dim ctrls As Control.ControlCollection = DirectCast(ctrl, GroupBox).Controls
|
||||
|
||||
UpdateAllControls(FormID, RecordID, ctrls)
|
||||
' Neues Control
|
||||
If CONTROL_ID = -1 Then
|
||||
CONTROL_VALUE = GetControlValue(ctrl)
|
||||
|
||||
' Kein Bekanntes Control oder Groupbox
|
||||
If IsNothing(CONTROL_VALUE) Then
|
||||
If TypeOf ctrl Is GroupBox Then
|
||||
Dim ctrls As Control.ControlCollection = DirectCast(ctrl, GroupBox).Controls
|
||||
|
||||
UpdateAllControls(FormID, RecordID, ctrls)
|
||||
End If
|
||||
Else
|
||||
Dim ctrlid As Integer = GetControlID_for_Name(ctrl.Name, FormID)
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> InsertControlValue: " & CONTROL_ID & "|" & RecordID & "|" & CONTROL_VALUE, False)
|
||||
InsertControlValue(ctrlid, RecordID, CONTROL_VALUE)
|
||||
End If
|
||||
Else ' Control Updaten
|
||||
CONTROL_VALUE = GetControlValue(ctrl)
|
||||
' Kein Bekanntes Control oder Groupbox
|
||||
If IsNothing(CONTROL_VALUE) Then
|
||||
If TypeOf ctrl Is GroupBox Then
|
||||
Dim ctrls As Control.ControlCollection = DirectCast(ctrl, GroupBox).Controls
|
||||
UpdateAllControls(FormID, RecordID, ctrls)
|
||||
End If
|
||||
Else
|
||||
UpdateControlValue(CONTROL_ID, RecordID, CONTROL_VALUE)
|
||||
End If
|
||||
Else
|
||||
UpdateControlValue(CONTROL_ID, RecordID, CONTROL_VALUE)
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
Catch ex As Exception
|
||||
MsgBox("Unexpected Error in UpdateAllControls: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Function GetControlValue(ctrl As Control) As String
|
||||
Dim type = ctrl.GetType().Name
|
||||
Dim CONTROL_ID As Integer = GetControlID_for_RecordID(ctrl.Name, CURRENT_RECORD_ID)
|
||||
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> GetControlValue CONTROL_ID: " & CONTROL_ID, False)
|
||||
Dim CONTROL_VALUE As String = Nothing
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> type = " & type.ToString, False)
|
||||
Select Case type
|
||||
Case "TextBox"
|
||||
Return DirectCast(ctrl, TextBox).Text
|
||||
Case "ComboBox"
|
||||
If LogErrorsOnly = False Then ClassLogger.Add(">> Return Value: " & DirectCast(ctrl, ComboBox).Text, False)
|
||||
Return DirectCast(ctrl, ComboBox).Text
|
||||
Case "CheckBox"
|
||||
Return DirectCast(ctrl, CheckBox).Checked.ToString()
|
||||
|
||||
Reference in New Issue
Block a user