Please help i tried use this code to display second layout but my biggest challenge is that some times it displays and some time does not display at all. please help i would want it to display after the user has finished processing
This is my first code which does the processing
this is the code which is run to display the results
This is my first code which does the processing
B4X:
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
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.
Private wbvTable As WebView
'Private lblSelectedItem As Label
Dim MaskedEditText1 As MaskedEditText
Dim MaskedEditText2 As MaskedEditText
'Dim panel1, panel2 As Panel
'Dim From As EditText
Dim Account As EditText
Private HtmlCSS As String
HtmlCSS = "table {width: 100%;border: 1px solid #cef;text-align: left; }" _
& " th { font-weight: bold; background-color: #acf; border-bottom: 1px solid #cef; }" _
& "td,th { padding: 4px 5px; }" _
& ".odd {background-color: #def; } .odd td {border-bottom: 1px solid #cef; }" _
& "a { text-decoration:none; color: #000;}"
'Dim froms As MaskedEditText
'Dim sendtt As Button
End Sub
Sub ShowTable
'Dim SQLQry As String = "DELETE FROM Balances"
'Starter.SQL1.ExecNonQuery(SQLQry)
Private Query As String
Query = "SELECT DISTINCT Names,Class || Stream As CS,Amount As Balance FROM Balances"
'depending if the filter is active or not we add the filter query at the end of the query
'the filter query is defined in the Filter Activity
If Starter.flagFilterActive = False Then
'btnFilter.Initialize("Filter")
'btnFilter.Text = "Filter" 'change the text in the Filter button
Else
Query = Query & Starter.FilterQuery
'btnFilter.Text = "UnFilter" 'change the text in the Filter button
End If
'displays the database in a table
wbvTable.LoadHtml(ExecuteHtml(Starter.SQL1, Query, Null, 0, True))
ReadDataBaseIDs
End Sub
Sub ReadDataBaseIDs
Private Row As Int
Private cursor1 As Cursor
Starter.IDList.Initialize 'initialize the ID list
'We read only the ID column and put them in a List
If Starter.flagFilterActive = False Then
cursor1 = Starter.SQL1.ExecQuery("SELECT ID FROM Balances")
Else
cursor1 = Starter.SQL1.ExecQuery("SELECT ID FROM Balances" & Starter.FilterQuery)
End If
If cursor1.RowCount > 0 Then 'check if entries exist
Starter.RowNumber = cursor1.RowCount 'set the row count variable
Starter.IDList.Initialize 'initialize the ID list
For Row = 0 To Starter.RowNumber - 1
cursor1.Position = Row 'set the Cursor to each row
Starter.IDList.Add(cursor1.GetInt("ID")) 'add the ID's to the ID list
Next
Starter.CurrentIndex = 0 'set the current index to 0
Else
Starter.CurrentIndex = -1 'set the current index to -1, no selected item
ToastMessageShow("No items found", False)
End If
cursor1.Close 'close the cursor, we don't need it anymore
End Sub
Sub wbvTable_OverrideUrl (Url As String) As Boolean
'parse the row and column numbers from the URL
Private values() As String
values = Regex.Split("[.]", Url.SubString(7))
Private row As Int
row = values(1)
Starter.CurrentIndex = row
UpdateSelectedItem
Return True 'Don't try to navigate to this URL
End Sub
Sub UpdateSelectedItem
Private Query As String
Private Curs As Cursor
Query = "SELECT DISTINCT Account,Names, Class,Stream,Amount FROM Balances WHERE ID = " & Starter.IDList.Get(Starter.CurrentIndex)
Curs = Starter.SQL1.ExecQuery(Query)
Curs.Position = 0
'lblSelectedItem.Text = Curs.GetString("Names") & " " & Curs.GetString("Class")& " " & Curs.GetString("Amount")
Account.Text = Curs.GetString("Account")
Curs.Close
End Sub
Sub ExecuteHtml(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, Clickable As Boolean) As String
Private cur As Cursor
If StringArgs <> Null Then
cur = SQL.ExecQuery2(Query, StringArgs)
Else
cur = SQL.ExecQuery(Query)
End If
Log("ExecuteHtml: " & Query)
If Limit > 0 Then Limit = Min(Limit, cur.RowCount) Else Limit = cur.RowCount
Private sb As StringBuilder
sb.Initialize
sb.Append("<html><body>").Append(CRLF)
sb.Append("<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
sb.Append("<table><tr>").Append(CRLF)
For i = 0 To cur.ColumnCount - 1
sb.Append("<th>").Append(cur.GetColumnName(i)).Append("</th>")
Next
sb.Append("</tr>").Append(CRLF)
For row = 0 To Limit - 1
cur.Position = row
If row Mod 2 = 0 Then
sb.Append("<tr>")
Else
sb.Append("<tr class='odd'>")
End If
For i = 0 To cur.ColumnCount - 1
sb.Append("<td>")
If Clickable Then
sb.Append("<a href='http://").Append(i).Append(".")
sb.Append(row)
' sb.Append(".com'>").Append(cur.GetString2(i)).Append("</a>")
sb.Append(".stub'>").Append(cur.GetString2(i)).Append("</a>")
Else
sb.Append(cur.GetString2(i))
End If
sb.Append("</td>")
Next
sb.Append("</tr>").Append(CRLF)
Next
cur.Close
sb.Append("</table></body></html>")
Return sb.ToString
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("accountstatement")
Activity.Title="Provisional Account Statement"
ShowTable
MaskedEditText1.Text = DateTime.Date(DateTime.Now)
'MaskedEditText2.Text = DateTime.Add(DateTime.Now,0,0,1)
MaskedEditText2.Text = DateTime.Date(DateTime.Now)
DateTime.DateFormat = "yyyy-MM-dd"
Dim t As Long = DateTime.DateTimeParse(DateTime.Date(DateTime.Now), "15:04:00")
DateTime.DateFormat = "dd/MM/yyyy"
Log(DateTime.Date(t) & " " & DateTime.Time(t))
MaskedEditText1.Text=DateTime.Date(t)
DateTime.DateFormat = "yyyy-MM-dd"
Dim t As Long = DateTime.DateTimeParse(DateTime.Date(DateTime.Now), "15:04:00")
DateTime.DateFormat = "dd/MM/yyyy"
Log(DateTime.Date(t) & " " & DateTime.Time(t))
MaskedEditText2.Text=DateTime.Date(t)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
'StartActivity(Statementdisplay)
End Sub
Sub Button1_Click
Dim SQLQry As String = "DELETE FROM Statement"
Starter.SQL1.ExecNonQuery(SQLQry)
Dim j As HttpJob
j.Initialize("", Me)
j.Download($"http://192.168.1.239/Generic_Handler_JSON/HandlerVBStatement.ashx?customerId=${Account.Text}&code=${MaskedEditText1.Text}&code2=${MaskedEditText2.Text}"$ )
Dim jt As HttpJob
jt.Initialize("", Me)
jt.Download("http://192.168.1.239/Generic_Handler_JSON/HandlerVBBalancestatement.ashx")
jt.GetRequest.Timeout = 10000 ' 10 seconds
Wait For (jt) JobDone(jt As HttpJob)
If jt.Success Then ' if job is success (http status code 200)
Dim RetVal As String
RetVal = jt.GetString
Log(RetVal)
If jt.GetString = "[]" Then
MsgboxAsync("No Records to Upload Yet for: " & Account.Text ,"SMIS")
Return
Else
Dim jpt As JSONParser
jpt.Initialize(jt.GetString)
Log(jpt) ' will pr
Dim quotes As List = jpt.NextArray
For Each quot As Map In quotes
Log("Account: " & quot.Get("ACCOUNT"))
Log("TITTLE: " & quot.Get("TITTLE"))
Log("TREF: " & quot.Get("TREF"))
Log("TRDATE: " & quot.Get("TRDATE"))
Log("DESCRIPT: " & quot.Get("DESCRIPT"))
Log("DEBITAMNT: " & quot.Get("DEBITAMNT"))
Log("CREDITAMNT: " & quot.Get("CREDITAMNT"))
Log("BAL: " & quot.Get("BAL"))
Dim lt As Long
DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
Dim datestring As String = DateTime.Date(JsonDateToTick( quot.Get("TRDATE")))
lt = DateTime.DateParse(datestring)
DateTime.DateFormat = "dd/MM/yyyy"
Log(DateTime.Date(lt))
'Starter.SQL1.ExecNonQuery("INSERT INTO Balances VALUES('" & quot.Get("Account") & "','" & quot.Get("Names") & "','" & quot.Get("class") & "','" & DateTime.Date(lt) & "','" & quot.Get("balance") & "','" & quot.Get("autofield") & "')")
Starter.SQL1.ExecNonQuery("INSERT INTO Statement VALUES('" & quot.Get("ACCOUNT") & "','" & quot.Get("TITTLE") & "','" & quot.Get("DESCRIPT") & "','" & quot.Get("DEBITAMNT") & "','" & quot.Get("CREDITAMNT") & "','" & quot.Get("TREF") & "','" & DateTime.Date(lt) & "','" & quot.Get("BAL") & "')")
'query = "CREATE TABLE Statement (Account Text,Names text,DESCRIPT text,DEBITAMNT text,CREDITAMNT text, TREF text,TRDATE text,BAL text)"
Next
End If
End If
'Msgbox("Records Uploaded Successfully ", "SMIS")
jt.Release
j.Release
'Activity.Finish
'StartActivity(Statementdisplay)
'Activity.LoadLayout("Statementdisplay")
Msgbox("Click on View Statement Buttom ", "SMIS")
Return
End Sub
Sub JsonDateToTick(s As String) As Long
Dim m As Matcher = Regex.Matcher("\d+", s)
If m.Find Then
Return m.Match
End If
Log("Invalid date: " & s)
Return 0
End Sub
Sub MaskedEditText2_FocusChanged(HasFocus As Boolean)
If HasFocus Then
Dim Test As String
Test = MaskedEditText2.Text
Test = Test.Replace("/", "")
If IsNumber(Test) Then
'DateTick = DateTime.DateParse(MaskedEditText1.Text)
'Msgbox("Date = " & DateTick, "")
'Msgbox("Good Date entered", "")
'Return
Else
MaskedEditText2.ShowError("Invalid date")
Return
End If
End If
End Sub
Sub RawText(Mask As String, Text As String) As String
'Returns a copy of the text without the mask characters
Dim Raw As StringBuilder
Raw.Initialize
Dim mskCar, txtCar As Char
For i = 0 To Mask.Length - 1
If i >= Text.Length Then Exit
mskCar = Mask.CharAt(i)
If mskCar = "#" Or mskCar = "A" Or mskCar = "H" Or mskCar = "L" Or mskCar = "?" Then
txtCar = Text.CharAt(i)
If txtCar <> MaskedEditText1.Placeholder Then
Raw.Append(txtCar)
End If
End If
Next
Return Raw.ToString
End Sub
Sub MaskedEditText1_FocusChanged(HasFocus As Boolean)
If HasFocus Then
Dim Test As String
Test = MaskedEditText1.Text
Test = Test.Replace("/", "")
If IsNumber(Test) Then
'MaskedEditText2.RequestFocus
Else
MaskedEditText1.ShowError("Invalid date")
Return
End If
End If
End Sub
Sub MaskedEditText1_TextChanged(Old As String, New As String)
Log("New=" & New & " / Old=" & Old)
Log("Raw=" & RawText(MaskedEditText1.Format, MaskedEditText1.Text) & " / Compact=" & MaskedEditText1.CompactText)
End Sub
Sub Button2_Click
' StartActivity(Statementdisplay)
End Sub
this is the code which is run to display the results
B4X:
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
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.
Private wbvTable As WebView
'Dim MaskedEditText1 As MaskedEditText
'Dim MaskedEditText2 As MaskedEditText
'Dim pnlLayout1, pnlLayout2 As Panel
'Private lblSelectedItem As Label
'Dim MaskedEditText1 As MaskedEditText
'Dim MaskedEditText2 As MaskedEditText
'Dim From As EditText
'Dim Account As EditText
Private HtmlCSS As String
HtmlCSS = "table {width: 100%;border: 1px solid #cef;text-align: left; }" _
& " th { font-weight: bold; background-color: #acf; border-bottom: 1px solid #cef; }" _
& "td,th { padding: 4px 5px; }" _
& ".odd {background-color: #def; } .odd td {border-bottom: 1px solid #cef; }" _
& "a { text-decoration:none; color: #000;}"
'Dim froms As MaskedEditText
'Dim sendtt As Button
End Sub
Sub ShowTable
'Dim SQLQry As String = "DELETE FROM Balances"
'Starter.SQL1.ExecNonQuery(SQLQry)
Private Query As String
Query = "SELECT DISTINCT Names,DESCRIPT,DEBITAMNT,CREDITAMNT,TREF,TRDATE,BAL As Balance FROM Statement"
'depending if the filter is active or not we add the filter query at the end of the query
'the filter query is defined in the Filter Activity
If Starter.flagFilterActive = False Then
'btnFilter.Initialize("Filter")
'btnFilter.Text = "Filter" 'change the text in the Filter button
Else
Query = Query & Starter.FilterQuery
'btnFilter.Text = "UnFilter" 'change the text in the Filter button
End If
'displays the database in a table
wbvTable.LoadHtml(ExecuteHtml(Starter.SQL1, Query, Null, 0, True))
ReadDataBaseIDs
End Sub
Sub ReadDataBaseIDs
Private Row As Int
Private cursor1 As Cursor
Starter.IDList.Initialize 'initialize the ID list
'We read only the ID column and put them in a List
If Starter.flagFilterActive = False Then
cursor1 = Starter.SQL1.ExecQuery("SELECT Account FROM Statement")
Else
cursor1 = Starter.SQL1.ExecQuery("SELECT Account FROM Statement" & Starter.FilterQuery)
End If
If cursor1.RowCount > 0 Then 'check if entries exist
Starter.RowNumber = cursor1.RowCount 'set the row count variable
Starter.IDList.Initialize 'initialize the ID list
For Row = 0 To Starter.RowNumber - 1
cursor1.Position = Row 'set the Cursor to each row
Starter.IDList.Add(cursor1.GetInt("Account")) 'add the ID's to the ID list
Next
Starter.CurrentIndex = 0 'set the current index to 0
Else
Starter.CurrentIndex = -1 'set the current index to -1, no selected item
ToastMessageShow("No items found", False)
End If
cursor1.Close 'close the cursor, we don't need it anymore
End Sub
Sub wbvTable_OverrideUrl (Url As String) As Boolean
'parse the row and column numbers from the URL
Private values() As String
values = Regex.Split("[.]", Url.SubString(7))
Private row As Int
row = values(1)
Starter.CurrentIndex = row
UpdateSelectedItem
Return True 'Don't try to navigate to this URL
End Sub
Sub UpdateSelectedItem
'Private Query As String
'Private Curs As Cursor
'Query = "SELECT DISTINCT Account,Names, Class,Stream,Amount FROM Balances WHERE ID = " & Starter.IDList.Get(Starter.CurrentIndex)
'Curs = Starter.SQL1.ExecQuery(Query)
'Curs.Position = 0
'lblSelectedItem.Text = Curs.GetString("Names") & " " & Curs.GetString("Class")& " " & Curs.GetString("Amount")
'Account.Text = Curs.GetString("Account")
'Curs.Close
End Sub
Sub ExecuteHtml(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, Clickable As Boolean) As String
Private cur As Cursor
If StringArgs <> Null Then
cur = SQL.ExecQuery2(Query, StringArgs)
Else
cur = SQL.ExecQuery(Query)
End If
Log("ExecuteHtml: " & Query)
If Limit > 0 Then Limit = Min(Limit, cur.RowCount) Else Limit = cur.RowCount
Private sb As StringBuilder
sb.Initialize
sb.Append("<html><body>").Append(CRLF)
sb.Append("<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
sb.Append("<table><tr>").Append(CRLF)
For i = 0 To cur.ColumnCount - 1
sb.Append("<th>").Append(cur.GetColumnName(i)).Append("</th>")
Next
sb.Append("</tr>").Append(CRLF)
For row = 0 To Limit - 1
cur.Position = row
If row Mod 2 = 0 Then
sb.Append("<tr>")
Else
sb.Append("<tr class='odd'>")
End If
For i = 0 To cur.ColumnCount - 1
sb.Append("<td>")
If Clickable Then
sb.Append("<a href='http://").Append(i).Append(".")
sb.Append(row)
' sb.Append(".com'>").Append(cur.GetString2(i)).Append("</a>")
sb.Append(".stub'>").Append(cur.GetString2(i)).Append("</a>")
Else
sb.Append(cur.GetString2(i))
End If
sb.Append("</td>")
Next
sb.Append("</tr>").Append(CRLF)
Next
cur.Close
sb.Append("</table></body></html>")
Return sb.ToString
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.Finish
Activity.LoadLayout("Statementdisplay")
Activity.Title="Provisional Account Statement"
ShowTable
End Sub
Sub Activity_Resume
'StartActivity(Accountstatement)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
StartActivity(Accountstatement)
'StartActivity(Accountstatement)
'Activity.RemoveAllViews
'Activity.LoadLayout("AccountStatement")
'Activity.Title="Provisional Account Statement"
'ShowTable2
End Sub