Hi All
I have used B4A to get a customer database from an SQL file (Just the Names) and then display them in a SearchView process so that it can be easily searched and selected.
The problem is that if there is an update on the SQL database, I have to restart the app to see the updates. The customer list is saved to a text file.
Possibly I am going about it the wrong way. If you have time to look at the code and give some advise, I would appreciate it.
Thank you
I have used B4A to get a customer database from an SQL file (Just the Names) and then display them in a SearchView process so that it can be easily searched and selected.
The problem is that if there is an update on the SQL database, I have to restart the app to see the updates. The customer list is saved to a text file.
Possibly I am going about it the wrong way. If you have time to look at the code and give some advise, I would appreciate it.
Thank you
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: CustomerUpdateSearch
#VersionCode: 4
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
'Activity module
Sub Process_Globals
Private index As Object
Private CUSTOMER_LIST = "customer_list", CUSTOMER_NUMBER = "customer_number" As String
End Sub
Sub Globals
Private SearchView1 As SearchView
Private ime As IME
Type TwoLines (First As String, Second As String)
Dim Writer As TextWriter
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
If FirstTime Then
FetchCustomerList
Dim names As List = File.ReadList(File.DirDefaultExternal, "peterh.txt")
index = SearchView1.SetItems(names)
Else
SearchView1.SetIndex(index)
End If
ime.Initialize("ime")
ime.AddHeightChangedEvent
End Sub
Private Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
SearchView1.ActivityHeightChanged(NewHeight)
End Sub
Sub SearchView1_ItemClick(Value As String)
Msgbox("Chosen value: " & Value, "")
End Sub
Sub FetchCustomerList
ProgressDialogShow("Fetching list of Customers")
ExecuteRemoteQuery("SELECT Name, CustNo FROM Customer ", CUSTOMER_LIST)
End Sub
Sub ExecuteRemoteQuery(Query As String, JobName As String)
Dim job As HttpJob
job.Initialize(JobName, Me)
job.PostString("http://www.@@@@@@/get_data.php", Query)
End Sub
Sub JobDone(Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim res As String
res = Job.GetString
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select Job.JobName
Case CUSTOMER_LIST
Dim CUSTOMERS As List
CUSTOMERS = parser.NextArray
Writer.Initialize(File.OpenOutput(File.DirDefaultExternal, "peterh.txt", False))
Writer.Close
Writer.Initialize(File.OpenOutput(File.DirDefaultExternal, "peterh.txt", True))
For i = 0 To CUSTOMERS.Size - 1
Dim m As Map
m = CUSTOMERS.Get(i)
Dim tl As TwoLines
tl.Second = m.Get("Name")
Writer.WriteLine(tl.Second)
Next
Writer.Close
Case CUSTOMER_NUMBER
End Select
Else
Log(Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub