Please help iam trying to read the list of sent messages from the sent message table all i can see is empty rows . but when you look and the search record it appears that there records in the table because i can see 1 out of 2 records
2. When i clicked on the received sms . it displays both the send and received columns yet i wanted to display only the columns for recivied sms
Here is my code please help
2. When i clicked on the received sms . it displays both the send and received columns yet i wanted to display only the columns for recivied sms
Here is my code please help
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.
Dim cursor1 As Cursor
Private smiley As Bitmap
'Dim SelectedRow As Int : SelectedRow = -1
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 lblSelectedItem As Label
'Dim wbvTable2 As ScrollView
Private B4XTable1 As B4XTable
Private xui As XUI
Dim data As List
End Sub
Sub ShowTable
B4XTable1.AddColumn("Datesent", B4XTable1.COLUMN_TYPE_DATE)
B4XTable1.AddColumn("Sms", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("ID", B4XTable1.COLUMN_TYPE_TEXT)
data.Initialize
Dim rs As ResultSet = Starter.SQL1.ExecQuery("SELECT DISTINCT Datesent,Sms as SentMessage,ID FROM Sentmessages")
Do While rs.NextRow
Dim row(4) As Object
row(0) = rs.GetDouble("Datesent")
row(1) = rs.GetString("SentMessage")
'Log(row(0))
'Log(row(1))
'Log(row(2))
'& " " & rs.GetString("LastName")
row(2) = rs.GetString("ID")
'Some of the fields are Null. We need to convert them to empty strings:
If row(2) = Null Then row(2) = ""
row(3) = rs.GetString("SentMessage")
data.Add(row)
Loop
rs.Close
B4XTable1.SetData(data)
End Sub
Sub ShowTable2
B4XTable1.AddColumn("DateRecieved", B4XTable1.COLUMN_TYPE_DATE)
B4XTable1.AddColumn("Sms", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("ID", B4XTable1.COLUMN_TYPE_TEXT)
data.Initialize
Dim rs As ResultSet = Starter.SQL1.ExecQuery("SELECT DISTINCT Daterecieved,Sms as RecievedMessage,ID FROM Recievedsms")
Do While rs.NextRow
Dim row(4) As Object
row(0) = rs.GetDouble("Daterecieved")
row(1) = rs.GetString("RecievedMessage")
'& " " & rs.GetString("LastName")
row(2) = rs.GetString("ID")
'Some of the fields are Null. We need to convert them to empty strings:
If row(2) = Null Then row(2) = ""
row(3) = rs.GetString("RecievedMessage")
data.Add(row)
Loop
rs.Close
B4XTable1.SetData(data)
End Sub
Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
If ColumnId <> "Datesent" Then Return
Dim sf As Object = xui.Msgbox2Async("Delete row?", "Title", "Yes", "Cancel", "No", Null)
Wait For (sf) Msgbox_Result (Result As Int)
If Result = xui.DialogResponse_Positive Then
DeleteRow(B4XTable1, RowId)
End If
End Sub
Sub DeleteRow (tbl As B4XTable, RowId As Long)
Dim RowData As Map = tbl.GetRow(RowId)
Dim customerID As String = RowData.Get("Datesent")
tbl.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array (RowId)) 'deletes record from Table
Starter.SQL1.ExecNonQuery2("DELETE FROM Sentmessages WHERE Datesent = ?", Array (customerID)) 'deletes from DB
Dim page As Int = tbl.CurrentPage
Dim FirstIndex As Int = tbl.FirstRowIndex
tbl.ClearDataView 'Updates the rows count.
If FirstIndex + 1 >= tbl.mCurrentCount Then
page = page - 1
End If
tbl.CurrentPage = page
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
smiley = LoadBitmapResize(File.DirAssets, "smiley.png", 24dip, 24dip, False)
End If
'Do not forget to load the layout file created with the visual designer. For example:
If IsConnectedToInternet=True Then
replysms
'HighPriority_Notification
Activity.LoadLayout("simplechat")
Activity.Title="Chat"
B4XTable1.AddColumn("Datesent", B4XTable1.COLUMN_TYPE_DATE)
B4XTable1.AddColumn("Sms", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("ID", B4XTable1.COLUMN_TYPE_TEXT)
data.Initialize
Dim rs As ResultSet = Starter.SQL1.ExecQuery("SELECT DISTINCT Datesent,Sms as SentMessage,ID FROM Sentmessages")
Do While rs.NextRow
Dim row(4) As Object
row(0) = rs.GetDouble("Datesent")
row(1) = rs.GetString("SentMessage")
Log(row(0))
Log(row(1))
Log(row(2))
'& " " & rs.GetString("LastName")
row(2) = rs.GetString("ID")
'Some of the fields are Null. We need to convert them to empty strings:
If row(2) = Null Then row(2) = ""
row(3) = rs.GetString("SentMessage")
data.Add(row)
Loop
rs.Close
B4XTable1.SetData(data)
Dim SQLQry As String = "DELETE FROM SMSlist"
Starter.SQL1.ExecNonQuery(SQLQry)
cursor1 = Starter.SQL1.ExecQuery("SELECT phone AS Phone,Sex FROM Register")
If cursor1.RowCount > 0 Then
cursor1.Position =0
Dim phone As String
phone = cursor1.Getstring("Phone")
Dim sx As String
sx = cursor1.Getstring("Sex")
'Next
End If
Dim CustID As String = phone' Customer ID
Dim jt As HttpJob
jt.Initialize("", Me)
jt.Download("http://kccug.com/Generic_Handler_JSON/HandlerVBRegistration.ashx?customerid=" & CustID & "&sx=" & sx)
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
If jt.GetString = "[]" Then
'Msgbox("Please try Again ","SMIS")
'Return
Else
Dim jpt As JSONParser
jpt.Initialize(jt.GetString)
'Log(jpt) ' will pr
Log($"Token(${jpt})"$)
Dim quotes As List = jpt.NextArray
For Each quot As Map In quotes
' Log("Account: " & quot.Get("Account"))
Log("Name: " & quot.Get("Name"))
Log("Category: " & quot.Get("Category"))
Log("Froms: " & quot.Get("Froms"))
Log("Tos: " & quot.Get("Tos"))
Log(DateTime.Date(JsonDateToTick( quot.Get("Froms"))))
Dim l As Long
DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
Dim datestring As String = DateTime.Date(JsonDateToTick( quot.Get("Froms")))
l = DateTime.DateParse(datestring)
DateTime.DateFormat = "dd/MM/yyyy"
Log(DateTime.Date(l))
Log(DateTime.Date(JsonDateToTick( quot.Get("Tos"))))
Dim lt As Long
DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
Dim datestring As String = DateTime.Date(JsonDateToTick( quot.Get("Tos")))
lt = DateTime.DateParse(datestring)
DateTime.DateFormat = "dd/MM/yyyy"
Log(DateTime.Date(lt))
'End If
'Grab the last ID number which is the highest number
If quot.Get("Category")="Inactive" Then
MsgboxAsync("Your Account is Inactive Please Pay 60000/= Via Mobile Money On 0782911364 Or 0702822227 to Activate" ,"SMIS")
Return
End If
If quot.Get("Category")="Expired" Then
MsgboxAsync("Your Registration has Already Expired it was Valid from: " & DateTime.Date(l) &" To:"& DateTime.Date(lt) &" Please Pay 60000/= Via Mobile Money On 0782911364 Or 0702822227 to Activate" ,"SMIS")
Return
Else
'Starter.SQL1.ExecNonQuery("INSERT INTO SMSlist VALUES('" & quot.Get("Account") & "','" & quot.Get("Name") & "','" & CustID & "','" & sx & "','" & 1 & "')")
Starter.SQL1.ExecNonQuery2("INSERT INTO SMSlist VALUES(?, ?, ?,?,?)", Array As Object(quot.Get("Account"), quot.Get("Name"),CustID ,sx, 1))
'Log(quot.Get("Account"))
'Log(quot.Get("Name"))
'Log(quot.Get(phone))
'Log(quot.Get(sx))
Log(RetVal) ' will print in log value returned from the server
End If
Next
End If
End If
Else
MsgboxAsync("Error Connecting to the Server Please Check Your Internet Connection","Server Error")
Activity.LoadLayout("simplechat")
Activity.Title="Chat"
Return
End If
End Sub
Sub IsConnectedToInternet As Boolean
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
r.Target = r.RunMethod("getActiveNetworkInfo")
If r.Target <> Null Then
Return r.RunMethod("isConnectedOrConnecting")
End If
Return False
End Sub
Sub replysms
'Dim SQLQry As String = "DELETE FROM Recievedsms"
'Starter.SQL1.ExecNonQuery(SQLQry)
cursor1 = Starter.SQL1.ExecQuery("SELECT phone AS Phone,Sex FROM Register")
If cursor1.RowCount > 0 Then
cursor1.Position =0
Dim phone As String
phone = cursor1.Getstring("Phone")
Dim sx As String
sx = cursor1.Getstring("Sex")
' sx = "Father"
End If
Dim CustID As String = phone' Customer ID
Dim jtk As HttpJob
jtk.Initialize("", Me)
'j.Download("http://192.168.1.239/Generic_Handler_JSON/HandlerVB.ashx?customerid=" & CustID)
jtk.Download("http://kccug.com/Generic_Handler_JSON/HandlerVBGetreply.ashx?customerid=" & CustID & "&bcode=" & sx)
'jtk.Download("http://192.168.1.239/Generic_Handler_JSON/HandlerVBGetreply.ashx?customerid=" & CustID & "&bcode=" & sx)
jtk.GetRequest.Timeout = 10000 ' 10 seconds
Wait For (jtk) JobDone(jtk As HttpJob)
If jtk.Success Then ' if job is success (http status code 200)
Dim RetVal As String
Log(RetVal)
RetVal = jtk.GetString
If jtk.GetString = "[]" Then
'Msgbox("Please try Again ","SMIS")
'Return
Else
Dim jpt As JSONParser
jpt.Initialize(jtk.GetString)
'Log(jpt) ' will pr
Log($"Token(${jpt})"$)
Dim quotes As List = jpt.NextArray
For Each quot As Map In quotes
Log("Account: " & quot.Get("Account"))
Log("sms: " & quot.Get("sms"))
Log("Datesent: " & quot.Get("Datesent"))
Log("Status: " & quot.Get("Status"))
Log("codes: " & quot.Get("Code"))
Log("atk: " & quot.Get("atk"))
'Log("Tos: " & quot.Get("Tos"))
Dim ltt As Long
DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
Dim datestring As String = DateTime.Date(JsonDateToTick( quot.Get("Datesent")))
ltt = DateTime.DateParse(datestring)
DateTime.DateFormat = "dd/MM/yyyy"
Log(DateTime.Date(ltt))
Dim now As Long
now = DateTime.Now
Log(DateTime.Now)
DateTime.DateFormat = "dd/MM/yyyy" : DateTime.TimeFormat = "hh:mm a"
Log(DateTime.Date(ltt)& " "& DateTime.Time(now))
Starter.SQL1.ExecNonQuery2("INSERT INTO Recievedsms VALUES(?, ?, ?)", Array As Object(DateTime.Date(ltt)& " "& DateTime.Time(now), quot.Get("sms"), quot.Get("Code")))
Dim n As NB6
n.Initialize("default", Application.LabelName, "HIGH").SmallIcon(smiley)
n.Build(quot.Get("sms"), "Kabojja Junior School", "tag", Main).Notify(9)
Dim jtkt As HttpJob
jtkt.Initialize("", Me)
jtkt.Download("http://kccug.com/Generic_Handler_JSON/HandlerVBDelReply.ashx?customerid=" & quot.Get("atk"))
Next
End If
End If
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 Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnFilter_Click
If IsConnectedToInternet=True Then
cursor1 = Starter.SQL1.ExecQuery("SELECT Account FROM SMSlist")
If cursor1.RowCount > 0 Then
StartActivity(Sendsms)
'Activity.Title="Send SMS"
Else
Dim SQLQry As String = "DELETE FROM SMSlist"
Starter.SQL1.ExecNonQuery(SQLQry)
cursor1 = Starter.SQL1.ExecQuery("SELECT phone AS Phone,Sex FROM Register")
If cursor1.RowCount > 0 Then
cursor1.Position =0
Dim phone As String
phone = cursor1.Getstring("Phone")
Dim sx As String
sx = cursor1.Getstring("Sex")
'Next
End If
Dim CustID As String = phone' Customer ID
Dim jt As HttpJob
jt.Initialize("", Me)
jt.Download("http://kccug.com/Generic_Handler_JSON/HandlerVBRegistration.ashx?customerid=" & CustID & "&sx=" & sx)
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
If jt.GetString = "[]" Then
'Msgbox("Please try Again ","SMIS")
'Return
Else
Dim jpt As JSONParser
jpt.Initialize(jt.GetString)
'Log(jpt) ' will pr
Log($"Token(${jpt})"$)
Dim quotes As List = jpt.NextArray
For Each quot As Map In quotes
' Log("Account: " & quot.Get("Account"))
Log("Name: " & quot.Get("Name"))
Log("Category: " & quot.Get("Category"))
Log("Froms: " & quot.Get("Froms"))
Log("Tos: " & quot.Get("Tos"))
Log(DateTime.Date(JsonDateToTick( quot.Get("Froms"))))
Dim l As Long
DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
Dim datestring As String = DateTime.Date(JsonDateToTick( quot.Get("Froms")))
l = DateTime.DateParse(datestring)
DateTime.DateFormat = "dd/MM/yyyy"
Log(DateTime.Date(l))
Log(DateTime.Date(JsonDateToTick( quot.Get("Tos"))))
Dim lt As Long
DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
Dim datestring As String = DateTime.Date(JsonDateToTick( quot.Get("Tos")))
lt = DateTime.DateParse(datestring)
DateTime.DateFormat = "dd/MM/yyyy"
Log(DateTime.Date(lt))
'End If
'Grab the last ID number which is the highest number
If quot.Get("Category")="Inactive" Then
MsgboxAsync("Your Account is Inactive Please Pay 60000/= Via Mobile Money On 0782911364 Or 0702822227 to Activate" ,"SMIS")
Return
End If
If quot.Get("Category")="Expired" Then
MsgboxAsync("Your Registration has Already Expired it was Valid from: " & DateTime.Date(l) &" To:"& DateTime.Date(lt) &" Please Pay 60000/= Via Mobile Money On 0782911364 Or 0702822227 to Activate" ,"SMIS")
Return
Else
'Starter.SQL1.ExecNonQuery("INSERT INTO SMSlist VALUES('" & quot.Get("Account") & "','" & quot.Get("Name") & "','" & CustID & "','" & sx & "','" & 1 & "')")
Starter.SQL1.ExecNonQuery2("INSERT INTO SMSlist VALUES(?,?,?,?,?)", Array As Object(quot.Get("Account"), quot.Get("Name"), CustID,sx,1))
'Log(quot.Get("Account"))
'Log(quot.Get("Name"))
'Log(quot.Get(phone))
'Log(quot.Get(sx))
Log(RetVal) ' will print in log value returned from the server
End If
Next
End If
End If
End If
StartActivity(Sendsms)
Else
MsgboxAsync("Error Connecting to the Server Please Check Your Internet Connection","Server Error")
Return
End If
End Sub
Sub HighPriority_Notification
Dim n As NB6
n.Initialize("default", Application.LabelName, "HIGH").SmallIcon(smiley)
n.Build("Important Good Work sula!!!", "Content", "tag", Me).Notify(9)
End Sub
Sub btnEdit_Click
B4XTable1.Clear
ShowTable
lblSelectedItem.Text="Send"
End Sub
Sub btnAdd_Click
B4XTable1.Clear
ShowTable2
lblSelectedItem.Text="Recieved"
End Sub