Sub UpdateRecord_Click
Try
'1 ## get values from the input mask by event in the activity/page
' ## store the values in DBNValueMap(Fieldname, Value)
If SubExists(mCallBack, mEventName & "_GetValues") = True Then
' get col name,type and value
CallSub2(mCallBack,mEventName & "_GetValues",DBNDataSet
End If
'2 ## check all column values
Dim tempColumnInfo As ResultSet
Dim Error As Boolean = False
Dim checkUnique As Boolean =True
Dim ColumnType As String
Dim SQLstring As String
Dim ColumnNames As String
Dim ColumnValues As String
ToastMessageShow("Prüfe eingegebene Werte....",True)
For Each ColumnName As String In DBNValueMap.Keys
' get the column info
tempColumnInfo = getColumnInfo(ColumnName)
tempColumnInfo.Position = 0
' check if null values allowed and if input field has a value
If tempColumnInfo.Getstring("col_not_null") = True Then
If DBNValueMap.Get(ColumnName) = Null Then
xui.Msgbox2Async( _
"Keine Eingabe in dem einem Pflichtfeld!" & CRLF & _
"Funktion wird abgebrochen.","Eingabefehler " & ColumnName,"OK","","",IcoAttention)
Error = True
Exit
End If
End If
' check if the value must be unique
If DBNNewRecord = False Then
' for update check if unique check is nessessary
ColumnType = tempColumnInfo.Getstring("col_type")
Select ColumnType
Case "text"
If DBNDataSet.GetString(ColumnName) = DBNValueMap.Get(ColumnName) Then checkUnique = False
Case "Int"
If DBNDataSet.GetInt(ColumnName) = DBNValueMap.Get(ColumnName) Then checkUnique = False
End Select
End If
If checkUnique = True And DBNValueMap.ContainsKey(ColumnName & "_unique") = True Then
If checkIsUnique(ColumnName) = True Then
xui.Msgbox2Async( _
"Eingabe bereits gespeichert!" & CRLF & _
"Der Wert muss eindeutig sein," & CRLF & _
"Funktion wird abgebrochen.","Eingabefehler " & ColumnName,"OK","","",IcoAttention)
Error = True
Exit
End If
End If
Next
'3 ## if new record perform insert
If Error = False And DBNNewRecord = True Then
ToastMessageShow("Füge Daten hinzu....",True)
' bulid colum name part
ColumnNames = "("
For Each ColumnName As String In DBNValueMap.Keys
ColumnNames = ColumnNames & ColumnName & ","
Next
' strip last comma off
ColumnNames = ColumnNames.SubString2(0,ColumnNames.Length-1) & ")"
' build values part
ColumnValues = "("
For Each ColumnName As String In DBNValueMap.Keys
ColumnType = tempColumnInfo.Getstring("col_type")
Select ColumnType
Case "text"
ColumnValues = ColumnValues & "'" & DBNValueMap.Get(ColumnName)& "',"
Case "Int"
ColumnValues = ColumnValues & DBNValueMap.Get(ColumnName)& ","
End Select
Next
' strip last comma off
ColumnValues = ColumnValues.SubString2(0,ColumnNames.Length-1) & ")"
' perform dtatabase insert
DBNSQL.ExecNonQuery("INSERT INTO " & DBNTableName & ColumnNames & " VALUES" & ColumnValues)
ToastMessageShow("Daten erfolgreich hinzugefügt.",True)
' set record pointer to last record
DBNCurrentIndex = DBNDataSet.rowcount-1
' fire event
If SubExists(mCallBack, mEventName & "_CurrentIndexChanged") = True Then
CallSub2(mCallBack,mEventName & "_CurrentIndexChanged",DBNDataSet)
End If
'4 ## perform update
Else if Error = False And DBNNewRecord = False Then
ToastMessageShow("Speichere die Änderungen....",True)
' bulid colum name part
For Each ColumnName As String In DBNValueMap.Keys
ColumnType = tempColumnInfo.Getstring("col_type")
[COLOR=rgb(65, 168, 95)] Select ColumnType
Case "text"
ColumnValues = ColumnValues & ColumnName & "= '" & DBNValueMap.Get(ColumnName)& "',"
Case "Int"
ColumnValues = ColumnValues & ColumnName & "=" & DBNValueMap.Get(ColumnName)& ","
End Select[/COLOR]
Next
' strip last comma off
ColumnValues = ColumnValues.SubString2(0,ColumnNames.Length-1) & ")"
' get rowid
SQLstring = "UPDATE " & DBNTableName & "SET " & ColumnValues & "WHERE rowid=" & DBNCurrentRowid
DBNSQL.ExecNonQuery(SQLstring)
ToastMessageShow("Änderungen erfolgreich gespeichert.",True)
End If
' reset new record flag
DBNNewRecord = False
' release resultset
tempColumnInfo.close
Catch
If DBNNewRecord = True Then
ToastMessageShow("Neue Daten konnten nicht gespeichert werden!",True)
Else
ToastMessageShow("Änderungen konnten nicht gespeichert werden!",True)
End If
xui1.Msgbox2Async(LastException,"Fehler: DBN002","OK","","",IcoError)
End Try
End Sub