#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
'Activity module
Sub Process_Globals
Dim ph As Phone
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim SQLQuery As String
Dim cur As Cursor
Dim spnAuswahl As Spinner
Dim lblID As Label
Dim lblKennzeichen As EditText
Dim spnBild As Spinner
Dim lblTank As EditText
Dim lblVerbrauch As EditText
Dim lblPIN As EditText 'Um diesen Eintrag geht es bei den führenden Nullen
Dim lblLFL As EditText
Dim lblLFB As EditText
Dim lblLFH As EditText
Dim lblNutzlast As EditText
Dim lblStellplatz As EditText
Dim updatedb As Boolean : updatedb = True
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.AddMenuItem2("Neu", "men_new", LoadBitmap(File.DirAssets,"new.png"))
Activity.AddMenuItem2("Speichern", "men_save", LoadBitmap(File.DirAssets,"save.png"))
Activity.AddMenuItem2("Löschen", "men_delete", LoadBitmap(File.DirAssets,"delete.png"))
If FirstTime Then
Dim TargetDir As String
If File.ExternalWritable Then TargetDir = File.DirDefaultExternal Else TargetDir = File.DirInternal
If File.Exists(TargetDir, Main.DBFileName) = False Then
File.Copy(File.DirAssets, Main.DBFileName, TargetDir, Main.DBFileName)
End If
End If
'Im Editor-Modus nur Portrait zulassen
ph.SetScreenOrientation(1)
Main.SQLDB.Initialize(Main.DBFileDir, Main.DBFileName, True)
Activity.LoadLayout("lay_lkw")
spnBild.AddAll(Array As String("1","2","3","4"))
spnAuswahl_Fill
End Sub
Sub Activity_Resume
lblTank.InputType = lblTank.INPUT_TYPE_NUMBERS
lblVerbrauch.InputType = lblVerbrauch.INPUT_TYPE_DECIMAL_NUMBERS
lblPIN.InputType = lblTankkarte.INPUT_TYPE_NUMBERS
lblNutzlast.InputType = lblNutzlast.INPUT_TYPE_NUMBERS
lblStellplatz.InputType = lblStellplatz.INPUT_TYPE_NUMBERS
lblLFL.InputType = lblLFL.INPUT_TYPE_DECIMAL_NUMBERS
lblLFB.InputType = lblLFB.INPUT_TYPE_DECIMAL_NUMBERS
lblLFH.InputType = lblLFH.INPUT_TYPE_DECIMAL_NUMBERS
End Sub
Sub Activity_Pause (UserClosed As Boolean)
'Activity schliessen und zum Hauptscreen zurückkehren
If UserClosed = True Then Activity.Finish
End Sub
Sub spnAuswahl_Fill
SQLQuery = "SELECT DISTINCT Kennzeichen FROM lkw ORDER by Kennzeichen COLLATE NOCASE"
spnAuswahl.Clear
' snpAuswahl.Height = 50dip
' snpAuswahl.Color = Colors.Green
' snpAuswahl.TextSize = 20dip
' snpAuswahl.TextColor = Colors.Blue
cur = Main.SQLDB.ExecQuery(SQLQuery)
For i = 0 To cur.RowCount - 1
cur.Position = i
spnAuswahl.Add(cur.GetString2(0)) ' Use this if only one column in cur
' snpAuswahl.Add(cur.GetString("Continent")) ' Use this if more than one column in cur
Next
spnAuswahl.SelectedIndex = 0
spnAuswahl_ItemClick(spnAuswahl.SelectedIndex,spnAuswahl.SelectedItem)
End Sub
Sub spnAuswahl_ItemClick (Position As Int, Value As Object)
updatedb = True
Activity.Title = "Fahrzeuge bearbeiten"
Dim Cursor1 As Cursor
Cursor1 = Main.SQLDB.ExecQuery("SELECT ID, Kennzeichen, Bild, Tank, Verbrauch, Tankkarte, LF_L, LF_B, LF_H, Nutzlast, Stellplatz FROM lkw WHERE Kennzeichen='" & Value & "'")
Cursor1.Position = 0
lblID.Text = Cursor1.GetString("ID")
lblKennzeichen.Text = Value
spnBild.SelectedIndex = spnBild.IndexOf(Cursor1.GetString("Bild"))
lblTank.Text = Cursor1.GetString("Tank")
lblVerbrauch.Text = Cursor1.GetString("Verbrauch")
lblPIN.Text = Cursor1.GetString("Tankkarte")
lblLFL.Text = Cursor1.GetString("LF_L")
lblLFB.Text = Cursor1.GetString("LF_B")
lblLFH.Text = Cursor1.GetString("LF_H")
lblNutzlast.Text = Cursor1.GetString("Nutzlast")
lblStellplatz.Text = Cursor1.GetString("Stellplatz")
Cursor1.Close
End Sub
Sub men_new_Click()
'Neuen Datensatz erstellen
Activity.Title = "Neues Fahrzeug hinzufügen"
updatedb = False
spnAuswahl.Clear
For i = 0 To Activity.NumberOfViews - 1
Dim View1 As View
View1 = Activity.GetView(i)
Log(i & " " & GetType(View1))
Select GetType(View1)
Case "android.widget.TextView"
Log(i & " Label")
'Dim l As Label
'l = Activity.GetView(i)
Case "android.widget.EditText"
Log(i & " EditText")
Dim e As EditText
e = Activity.GetView(i)
e.Text = ""
Case "anywheresoftware.b4a.objects.SpinnerWrapper$B4ASpinner"
Log(i & " Spinner")
Dim s As Spinner
s = Activity.GetView(i)
s.SelectedIndex = 0
' Case "android.widget.CheckBox"
' Log(i & " CheckBox")
' Dim c As CheckBox
' c = Activity.GetView(i)
' c.Checked = False
End Select
Next
End Sub
Sub men_save_Click()
'Alle geänderten Daten speichern
'Wenn kein Titel eingetragen ist, dann abbrechen.
If lblKennzeichen.Text = "" Then
Msgbox2("Sie müssen ein Kennzeichen angeben!","Datensatz speichern","Ok","","",LoadBitmap(File.DirAssets,"alert.png"))
spnAuswahl_Fill
Return
End If
Dim m As Map
Dim nr As Int
nr = spnAuswahl.SelectedIndex
m.Initialize
m.Put("Kennzeichen", lblKennzeichen.Text)
m.Put("Bild", spnBild.SelectedItem)
m.Put("Tank", lblTank.Text)
m.Put("Verbrauch", lblVerbrauch.Text)
m.Put("Tankkarte", lblPIN.Text) 'Hier werden führende Nullen nicht gespeichert
m.Put("LF_L", lblLFL.Text)
m.Put("LF_B", lblLFB.Text)
m.Put("LF_H", lblLFH.Text)
m.Put("Nutzlast", lblNutzlast.Text)
m.Put("Stellplatz", lblStellplatz.Text)
' Wenn updatedb = true, dann nicht speichern sondern update
If updatedb = True Then
Dim wf As Map
wf.Initialize
wf.Put("ID",lblID.Text)
DBUtils.UpdateRecord2(Main.SQLDB,"lkw",m,wf)
Else
Dim ListOfMaps As List
ListOfMaps.Initialize
ListOfMaps.Add(m)
DBUtils.InsertMaps(Main.SQLDB, "lkw", ListOfMaps)
End If
'Spinner mit geänderten Daten aktualisieren und anschliessend
'die letzte Auswahl wieder im Editor anzeigen
spnAuswahl_Fill
spnAuswahl.SelectedIndex = nr
spnAuswahl_ItemClick(spnAuswahl.SelectedIndex,spnAuswahl.SelectedItem)
End Sub
Sub men_delete_Click()
'Aktuellen Datensatz löschen
'Wenn kein Titel eingetragen ist, dann abbrechen.
If lblKennzeichen.Text = "" Then
Msgbox2("Sie müssen ein Fahrzeug wählen!","Fahrzeug löschen","Ok","","",LoadBitmap(File.DirAssets,"alert.png"))
spnAuswahl_Fill
Return
End If
Dim Answ As Int
Answ = Msgbox2("Soll das Kfz '" & lblKennzeichen.Text & "' wirklich gelöscht werden?","Fahrzeug löschen","Ja","","Nein",LoadBitmap(File.DirAssets,"alert.png"))
If Answ = DialogResponse.POSITIVE Then
Dim wf As Map
wf.Initialize
wf.Put("ID",lblID.Text)
DBUtils.DeleteRecord(Main.SQLDB,"lkw",wf)
spnAuswahl_Fill
End If
End Sub