Sub btnEdit_Click
Try
Dim RowId As Long = GetRowId(Sender)
Dim Item As Map = B4XTable1.GetRow(RowId)
Dim WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename As String
'Get the b4xtable values and store it in variable
WhatRo = Item.GetDefault("RO", "")
WhatDate = Item.GetDefault("Date", "")
WhatFirstName = Item.GetDefault("First Name", "")
WhatLastName = Item.GetDefault("Last Name", "")
WhatVin = Item.GetDefault("VIN", "")
WhatYear = Item.GetDefault("Year", "")
WhatMake = Item.GetDefault("Make", "")
WhatModel = Item.GetDefault("Model", "")
WhatFilename = Item.GetDefault("File Name", "")
' Private Query As String
' Private Cursor1 As Cursor
'
' 'first we check if the entry already does exist
' Query = "SELECT * FROM diagnosticlog WHERE RO = ? AND Date = ? AND FirstName = ? AND LastName = ? AND VIN = ? AND Year = ? AND Make = ? AND Model = ? AND FileName = ?"
' Cursor1 = Starter.SQL1.ExecQuery2(Query, Array As String (WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename))
'
' If Cursor1.RowCount > 0 Then
' Log("yes")
' End If
'Set the maps with the coloumn values from b4xtable
Dim Options1 As Map
Options1.Initialize
Options1.Put("WhatRO", WhatRo)
Options1.Put("WhatFirstName", WhatFirstName)
Options1.Put("WhatLastName", WhatLastName)
Options1.Put("WhatVin", WhatVin)
Options1.Put("WhatYear", WhatYear)
Options1.Put("WhatMake", WhatMake)
Options1.Put("WhatModel", WhatModel)
Wait For (prefdialog.ShowDialog(Options1, "OK", "CANCEL")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
'Get the updated maps
WhatRo = Options1.GetDefault("WhatRO", "")
WhatFirstName = Options1.GetDefault("WhatFirstName", "")
WhatLastName = Options1.GetDefault("WhatLastName", "")
WhatVin = Options1.GetDefault("WhatVin", "")
WhatYear = Options1.GetDefault("WhatYear", "")
WhatMake = Options1.GetDefault("WhatMake", "")
WhatModel = Options1.GetDefault("WhatModel", "")
'Update the Start SQL (Main one used)
Starter.SQL1.ExecNonQuery2("UPDATE diagnosticlog SET RO = ?, Date = ?, FirstName = ?, LastName = ?, VIN = ?, Year = ?, Make = ?, Model = ?, FileName = ? WHERE rowid = ?", Array As String(WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename, RowId))
'Update the B4xTable just for viewing only
B4XTable1.SQL1.ExecNonQuery2("UPDATE data SET c2 = ?, c3 = ?, c4 = ?, c5 = ?, c6 = ?, c7 = ?, c8 = ?, c9 = ?, c10 = ? WHERE rowid = ?", Array As String(WhatRo, WhatDate, WhatFirstName, WhatLastName, WhatVin, WhatYear, WhatMake, WhatModel, WhatFilename, RowId))
B4XTable1.Refresh
' B4XTable1.UpdateTableCounters
' Cursor1.Close
'Update the File
Dim TempFileName As String
Dim WhatPath As String
If WhatFilename.Length > 1 Then
If WhatFilename.SubString2(0,1) = "*" Then
TempFileName = WhatFilename.SubString(1)
WhatPath = File.DirRootExternal
Else
TempFileName = WhatFilename
WhatPath = File.DirInternal
End If
End If
'Init map to file
Dim Map1 As Map
Map1.Initialize
File.ReadMap2(WhatPath, Starter.DiagReportDir2 & TempFileName, Map1)
'Date and Filename cannot be changed
'Update the map with lastest info from b4xpreference
Map1.Put("Date", WhatDate)
Map1.Put("RO", WhatRo)
Map1.Put("FirstName", WhatFirstName)
Map1.Put("LastName", WhatLastName)
Map1.Put("Vin", WhatVin)
Map1.Put("Year", WhatYear)
Map1.Put("Make", WhatMake)
Map1.Put("Model", WhatModel)
'Write the updated map values to the file
If File.Exists(WhatPath, Starter.DiagReportDir2 & TempFileName) Then
File.Delete(WhatPath, Starter.DiagReportDir2 & TempFileName)
End If
File.WriteMap(WhatPath, Starter.DiagReportDir2 & TempFileName, Map1) '.cdl
End If
Catch
Msgbox2Async("The following error occurred" & Chr(10) & Chr(10) & LastException.Message, "Database Edit Error", "OK", "", "", LoadBitmap(File.DirAssets, "disclaimer.png"), True)
End Try
End Sub