#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.
Type Message (Body As String, From As String)
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 txtMessage As EditText
Private Rsms As EditText
Private Rsms2 As Label
Private Rsms3 As Label
Private Rsms4 As Label
Private classr As Label
Private stream As Label
Private account As Label
Private txtLogs As EditText
Private serializator As B4XSerializator
Private chat As EditText
Dim cursor1 As Cursor
Private ClassAll As RadioButton
Private RadioButton1 As RadioButton
Private Nurse As RadioButton
Private Admin As RadioButton
Private spnFirstName As Spinner
Private spnFirstName2 As Spinner
Private badger1 As Badger
Private btnSend As Button
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("2")
badger1.Initialize
If IsConnectedToInternet=True Then
InitSpinners
InitSpinners2
Dim intCount As Int
intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Atk) as Id FROM SMSlist")
If intCount > 0 Then
Dim ms As Int = intCount
Else
Dim ms As Int = 0
End If
Log(ms)
badger1.SetBadge(btnSend, ms)
Else
MsgboxAsync("Error Connecting to the Server Please Check Your Internet Connection","Server Error")
Return
End If
End Sub
Private Sub client_MessageArrived (Topic As String, Payload() As Byte)
Dim receivedObject As Object = serializator.ConvertBytesToObject(Payload)
Dim m As Message = receivedObject
CallSub2(chat, "NewMessage", m)
End Sub
Private Sub CreateMessage(Body As String) As Byte()
Dim m As Message
m.Initialize
m.Body = Body
m.From = "currentName"
Return serializator.ConvertObjectToBytes(m)
End Sub
Public Sub NewMessage(msg As Message)
txtLogs.Text = $"${msg.From}: ${msg.Body}"$ & CRLF & txtLogs.Text
End Sub
Sub Activity_Resume
badger1.Initialize
Dim intCount As Int
intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Atk) as Id FROM SMSlist")
If intCount > 0 Then
Dim ms As Int = intCount
Else
Dim ms As Int = 0
End If
Log(ms)
badger1.SetBadge(btnSend, ms)
cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Phone,Sex,sms,Datesent,Atk FROM SMSlist where Names = ?", Array As String(spnFirstName.SelectedItem))
If cursor1.RowCount<>0 Then
'user registered
' For i = 0 To cursor1.RowCount - 1
cursor1.Position = 0
'Dim act As String= cursor1.GetString("Account")
'Dim phone As String= cursor1.GetString("Phone")
'Dim sx As String= cursor1.GetString("Sex")
Rsms.Text=cursor1.GetString("sms")
Log(Rsms.Text)
Rsms2.Text=cursor1.GetString("Datesent")
Log(Rsms2.Text)
Rsms4.Text=cursor1.GetString("Atk")
'Next
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnSend_Click
If txtMessage.Text <> "" And RadioButton1.Checked=True Then
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 jBr As HttpJob
jBr.Initialize("", Me)
jBr.Download($"http://kccug.com/Generic_Handler_JSON/HandlerVBSingleparent.ashx?customerId=${txtMessage.Text}&customerId2=${account.Text}&customerId3=${sx}"$)
txtMessage.Text=""
MsgboxAsync("SMS Sent Successfully ", "SMIS")
Return
End If
If txtMessage.Text <> "" And ClassAll.Checked=True Then
cursor1 = Starter.SQL1.ExecQuery("SELECT Class,stream FROM Activeclass GROUP BY Class,stream")
If cursor1.RowCount > 0 Then
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
Dim clas As String =cursor1.GetString("Class")
Dim stre As String =cursor1.GetString("stream")
Next
End If
Dim jB As HttpJob
jB.Initialize("", Me)
jB.Download($"http://kccug.com/Generic_Handler_JSON/HandlerVBClassmessage.ashx?customerId=${txtMessage.Text}&customerId2=${clas}&customerId3=${stre}"$)
txtMessage.Text=""
MsgboxAsync("SMS Sent Successfully ", "SMIS")
Return
Else
'Msgbox("You should type the Message you want to send ", "SMIS")
End If
If txtMessage.Text <> "" And ClassAll.Checked=False And RadioButton1.Checked=False Then
If txtMessage.Text <> "" Then
If spnFirstName.SelectedItem ="no filter" Then
Msgbox("You Must Select the Student Name. ", "SMIS")
spnFirstName.RequestFocus
Return
End If
CallSub2(Starter, "SendMessage", txtMessage.Text)
txtLogs.Text = txtMessage.Text
CreateMessage(txtMessage.Text)
Else
If txtMessage.Text="" Then
MsgboxAsync("You Must Enter Some Text To Countinue. ", "SMIS")
txtMessage.RequestFocus
Return
End If
'NewMessage
End If
If IsConnectedToInternet=True Then
cursor1 = Starter.SQL1.ExecQuery("SELECT ID FROM Sentmessages")
If cursor1.RowCount > 0 Then
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
Dim NewID As Int
NewID = cursor1.GetInt("ID")
Next
End If
NewID = NewID +1 ' add 1 to the ID number to make a new ID field
Dim l As Long
DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
Dim datestring As String = DateTime.Date(JsonDateToTick(DateTime.Now))
l = DateTime.DateParse(datestring)
DateTime.DateFormat = "dd/MM/yyyy"
Log(DateTime.Date(l))
Dim now As Long
now = DateTime.Now
Log(DateTime.Now)
DateTime.DateFormat = "dd/MM/yyyy" : DateTime.TimeFormat = "hh:mm a"
Log(DateTime.Date(l)& " "& DateTime.Time(now))
'Starter.SQL1.ExecNonQuery("INSERT INTO Sentmessages VALUES('" & DateTime.Date(l) & "','" & txtMessage.Text & "','" & NewID & "')")
Starter.SQL1.ExecNonQuery2("INSERT INTO Sentmessages VALUES(?, ?, ?)", Array As Object(DateTime.Date(l)& " "& DateTime.Time(now), txtMessage.Text, NewID))
'txtMessage.Text=""
cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Phone,Sex,sms,Datesent,coded,Type FROM SMSlist where Names = ?", Array As String(spnFirstName.SelectedItem))
If cursor1.RowCount<>0 Then
'user registered
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
Dim act As String= cursor1.GetString("Account")
Dim phone As String= cursor1.GetString("Phone")
Dim sx As String= cursor1.GetString("Type")
Rsms.Text=cursor1.GetString("sms")
Dim cod As String=cursor1.GetString("coded")
Next
Dim now As Long
now = DateTime.Now
Log(DateTime.Now)
DateTime.DateFormat = "dd/MM/yyyy" : DateTime.TimeFormat = "hh:mm a"
Dim j As HttpJob
j.Initialize("", Me)
j.Download($"http://kccug.com/Generic_Handler_JSON/RecieveSMSReply.ashx?customerId=${act}&s=${txtMessage.Text}&d=${DateTime.Date(l)& " "& DateTime.Time(now)}&id=${cod}&ph=${phone}&f=${sx}&tk=${Rsms4.Text}"$ )
txtMessage.Text=""
cursor1 =Starter.SQL1.ExecQuery2("DELETE FROM SMSlist where Atk = ?", Array As String(Rsms4.Text))
badger1.Initialize
Dim intCount As Int
intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Id) as Id FROM SMSlist")
If intCount > 0 Then
Dim ms As Int = intCount
Else
Dim ms As Int = 0
End If
If ms>0 Then
Dim mst As Int
mst=ms
Dim mstb As Int=1
ms = mst - mstb
Log(ms)
badger1.SetBadge(btnSend, ms)
Else
Dim ms As Int = 0
badger1.SetBadge(btnSend, ms)
End If
MsgboxAsync("SMS Sent Successfully ", "SMIS")
End If
Else
MsgboxAsync("Error Connecting to the Server Please Check Your Internet Connection","Server Error")
Return
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 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 InitSpinners
Private i As Int
Private Query1 As String
Private Curs As Cursor
'query = "CREATE TABLE SMSlist (Account Text, Names Text,Phone text,Sex, ID INTEGER )"
'We execute a query for each column and fill the Spinner
'We use SELECT DISTINCT to have each existing first name in the database only once
Query1 = "SELECT DISTINCT Account,Names FROM SMSlist ORDER BY Names ASC"
Curs = Starter.SQL1.ExecQuery(Query1)
'we add 'no filter' as no selection
spnFirstName.Add("no filter")
'we fill the Spinner with the data from the database
For i = 0 To Curs.RowCount - 1
Curs.Position = i
'spnFirstName.Add(Curs.GetString("Account"))
spnFirstName.Add(Curs.GetString("Names"))
'Dim kk As String = Curs.GetString("Names")
'Log(kk)
Next
'Curs.Close
End Sub
Sub InitSpinners2
Private i As Int
Private Query1 As String
Private Curs As Cursor
'query = "CREATE TABLE SMSlist (Account Text, Names Text,Phone text,Sex, ID INTEGER )"
'We execute a query for each column and fill the Spinner
'We use SELECT DISTINCT to have each existing first name in the database only once
Query1 = "SELECT DISTINCT Account,Name FROM Activeclass ORDER BY Name ASC"
Curs = Starter.SQL1.ExecQuery(Query1)
'we add 'no filter' as no selection
spnFirstName2.Add("no filter")
'we fill the Spinner with the data from the database
For i = 0 To Curs.RowCount - 1
Curs.Position = i
'spnFirstName.Add(Curs.GetString("Account"))
spnFirstName2.Add(Curs.GetString("Name"))
'Dim kk As String = Curs.GetString("Names")
'Log(kk)
Next
'Curs.Close
End Sub
Sub btnEdit_Click
'ShowTable
End Sub
Sub spnFirstName_ItemClick (Position As Int, Value As Object)
'cursor1.Close
cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Phone,Sex,sms,Datesent,Atk FROM SMSlist where Names = ?", Array As String(spnFirstName.SelectedItem))
If cursor1.RowCount<>0 Then
'user registered
For i = 0 To cursor1.RowCount - 1
cursor1.Position = 0
If Rsms.Text = cursor1.GetString("sms") Then
'Exit
'Rsms.Text=""
Else
Rsms.Text=cursor1.GetString("sms")
Log(Rsms.Text)
Rsms2.Text=cursor1.GetString("Datesent")
Log(Rsms2.Text)
Rsms4.Text=cursor1.GetString("Atk")
End If
Next
End If
End Sub
Sub spnFirstName2_ItemClick (Position As Int, Value As Object)
If spnFirstName2.SelectedItem ="no filter" Then
RadioButton1.Checked=False
Return
End If
cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Class,stream FROM Activeclass where Name = ?", Array As String(spnFirstName2.SelectedItem))
If cursor1.RowCount<>0 Then
'user registered
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
account.Text=cursor1.GetString("Account")
classr.Text=cursor1.GetString("Class")
stream.Text=cursor1.GetString("stream")
RadioButton1.Checked=True
Next
End If
End Sub
Sub Nurse_CheckedChange(Checked As Boolean)
Private Answ As Int
Answ = Msgbox2("Do you really want to Refer this Case to the Nurse?", "NURSE", "Yes", "", "No", Null)
If Answ = DialogResponse.POSITIVE Then
If Nurse.Checked=True Then
Dim jt As HttpJob
jt.Initialize("", Me)
jt.Download($"http://kccug.com/Generic_Handler_JSON/HandlerVBNurse.ashx?customerId=${Rsms4.Text}"$ )
Nurse.Checked=False
cursor1 =Starter.SQL1.ExecQuery2("DELETE FROM SMSlist where Atk = ?", Array As String(Rsms4.Text))
badger1.Initialize
Dim intCount As Int
intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Atk) as Id FROM SMSlist")
If intCount > 0 Then
Dim ms As Int = intCount
Else
Dim ms As Int = 0
End If
If ms>0 Then
Dim mst As Int
mst=ms
Dim mstb As Int=1
ms = mst - mstb
Log(ms)
badger1.SetBadge(btnSend, ms)
Else
cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Phone,Sex,sms,Datesent,Atk FROM SMSlist where Names = ?", Array As String(spnFirstName.SelectedItem))
If cursor1.RowCount<>0 Then
'user registered
' For i = 0 To cursor1.RowCount - 1
cursor1.Position = 0
'Dim act As String= cursor1.GetString("Account")
'Dim phone As String= cursor1.GetString("Phone")
'Dim sx As String= cursor1.GetString("Sex")
Rsms.Text=cursor1.GetString("sms")
Log(Rsms.Text)
Rsms2.Text=cursor1.GetString("Datesent")
Log(Rsms2.Text)
Rsms4.Text=cursor1.GetString("Atk")
'Next
cursor1.Close
End If
Dim ms As Int = 0
badger1.SetBadge(btnSend, ms)
End If
MsgboxAsync("SMS Forwarded Successfully ", "SMIS")
End If
End If
End Sub
Sub Admin_CheckedChange(Checked As Boolean)
Private Answ As Int
Answ = Msgbox2("Do you really want to Refer this Case to the Administrators?", "Admin", "Yes", "", "No", Null)
If Answ = DialogResponse.POSITIVE Then
If Admin.Checked=True Then
Dim jt As HttpJob
jt.Initialize("", Me)
jt.Download($"http://kccug.com/Generic_Handler_JSON/HandlerVBAdmin.ashx?customerId=${Rsms4.Text}"$ )
Admin.Checked=False
cursor1 =Starter.SQL1.ExecQuery2("DELETE FROM SMSlist where Atk = ?", Array As String(Rsms4.Text))
badger1.Initialize
Dim intCount As Int
intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Atk) as Id FROM SMSlist")
If intCount > 0 Then
Dim ms As Int = intCount
Else
Dim ms As Int = 0
End If
Log(ms)
If ms>0 Then
Dim mst As Int
mst=ms
Dim mstb As Int=1
ms = mst - mstb
Log(ms)
badger1.SetBadge(btnSend, ms)
Else
cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Phone,Sex,sms,Datesent,Atk FROM SMSlist where Names = ?", Array As String(spnFirstName.SelectedItem))
If cursor1.RowCount<>0 Then
'user registered
For i = 0 To cursor1.RowCount - 1
cursor1.Position = 0
'Dim act As String= cursor1.GetString("Account")
'Dim phone As String= cursor1.GetString("Phone")
'Dim sx As String= cursor1.GetString("Sex")
If Rsms.Text = cursor1.GetString("sms") Then
Exit
Else
Rsms.Text=cursor1.GetString("sms")
Log(Rsms.Text)
Rsms2.Text=cursor1.GetString("Datesent")
Log(Rsms2.Text)
Rsms4.Text=cursor1.GetString("Atk")
End If
Rsms.Text=cursor1.GetString("sms")
Log(Rsms.Text)
Rsms2.Text=cursor1.GetString("Datesent")
Log(Rsms2.Text)
Rsms4.Text=cursor1.GetString("Atk")
Next
cursor1.Close
End If
Dim ms As Int = 0
badger1.SetBadge(btnSend, ms)
End If
MsgboxAsync("SMS Forwarded Successfully ", "SMIS")
End If
End If
End Sub