' code from for MainOptions.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private UpdateDB = "update", JOB_LIST = "jobs", LNKJOBS = "lnkjob", BOQ = "boq", CUST = "cust", JOBCARDS = "jobcards" As String
Private ChargeH ="chargh", GetSQL = "getsql", HEADERID = "headerid", VEHREP = "vehrep", EXPH = "EXPH" As String
Public bMy As Boolean
Dim SQL1 As SQL
Dim Row As Int
Dim Cursor1 As Cursor
Dim CurrentIndex = -1 As Int ' index of the current entry
Dim RowNumber = 0 As Int ' number of rows
Dim iSecondMan As Int
Dim iVeh As Int
Dim iSelVeh As Int
Dim sDeviceID As String
Dim iLoginID As Int
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 cmdUpdateDB As Button
Dim cmdDailyVehCheck As Button
Dim cmdListMyJobs As Button
Dim Label1 As Label
Dim spCrewMember As Spinner
Dim sSQL As String
Dim Label3 As Label
Dim spVehicles As Spinner
Dim lblUser As Label
Dim cmdExit As Button
Dim sToday As String
Dim lvwCrew As ListView
Dim iHeader As Int
Dim ProgressBar1 As ProgressBar
End Sub
Sub cmdUpdateDB_Click
'First - send jobs if exists
Dim sSQL As String
Dim Cursor1 As Cursor
Dim iID As Int
iID=0
ProgressDialogShow("Please wait!")
Try
sSQL="SELECT QID FROM importlog ORDER BY QID DESC LIMIT 1"
Cursor1 = SQL1.ExecQuery(sSQL)
If Cursor1.RowCount > 0 Then 'check if entries exist
RowNumber = Cursor1.RowCount 'set the row count variable
For Row = 0 To RowNumber - 1
Cursor1.Position = Row
Try
iID = Cursor1.GetInt("QID")
Catch
iID=0
End Try
Next
End If
Cursor1.Close
Catch
iID=0
End Try
ProgressBar1.Visible = True
'###########Break point on next line, step on and nothing happens
Wait For (CallSub(RoadsJDBC, "GetNewJobs")) Complete (Result As Boolean)
ProgressBar1.Visible = False
ProgressDialogHide
End Sub
' service module RoadsJDBC:
Sub Process_Globals
Public mysql As JdbcSQL
Private driver As String = "com.mysql.jdbc.Driver"
Private jdbcUrl As String = "jdbc:mysql://<url>/<databasename>"
Private Username As String = "<username>"
Private Password As String = "<password>"
Private sSQL As String
Private SQL1 As SQL
End Sub
Sub Service_Create
'need to disable it as reading from large JdbcResultSet will cause network requests to be sent on the main thread.
DisableStrictMode
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub DisableStrictMode
Dim jo As JavaObject
jo.InitializeStatic("android.os.Build.VERSION")
If jo.GetField("SDK_INT") > 9 Then
Dim policy As JavaObject
policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
Dim sm As JavaObject
sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
End If
End Sub
Sub Connect As ResumableSub
mysql.InitializeAsync("mysql", driver, jdbcUrl, Username, Password)
Wait For MySQL_Ready (Success As Boolean)
If Success = False Then
ToastMessageShow ("Connection to database has failed, please try again.",False)
Log("Check unfiltered logs for JDBC errors.")
End If
Return Success
End Sub
Sub CloseConnection
mysql.Close
End Sub
Sub GetNewJobs As ResumableSub
Wait For (Connect) Complete (Success As Boolean)
If Success Then
Try
sSQL="SELECT * FROM statements_for_client WHERE (Client = " & Main.iUserID & " OR Client = 0) AND ID NOT IN (SELECT ID FROM statements_collected WHERE Client = " & Main.iUserID & " ) ORDER BY Requested ASC "
Dim sf As Object = mysql.ExecQueryAsync("mysql", sSQL,Null)
Wait For (sf) mysql_QueryComplete (Success As Boolean, Crsr As JdbcResultSet)
If Success Then
Do While Crsr.NextRow
Log(Crsr.GetString("Statement"))
Do While Crsr.NextRow
SQL1.ExecNonQuery(Crsr.GetString("Statement"))
sSQL="DELETE FROM importlog"
SQL1.ExecNonQuery(sSQL)
sSQL="INSERT INTO importlog (QID, Date) VALUES ('" & Crsr.getint("ID") & "', datetime())"
SQL1.ExecNonQuery(sSQL)
sSQL="INSERT INTO statements_collected(ID, Client, DeviceID) VALUES(" &Crsr.getint("ID") & "," & Main.iUserID & ",'" & MainOptions.sDeviceID & "')"
Dim sf1 As Object = mysql.ExecQueryAsync("mysql", sSQL,Null)
Wait For (sf1) mysql_QueryComplete (Success As Boolean)
If Success Then
ToastMessageShow("Update to main database failed",False)
End If
Loop
Loop
Crsr.Close
Else
Log(LastException)
End If
Catch
Success = False
Log(LastException)
End Try
CloseConnection
End If
Return Success
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub