#Region Project Attributes
#ApplicationLabel: Xampp php MySql
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#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 Chooser As ContentChooser
Dim img64 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.
Dim Base64Con As Base64Image
Private PersonsListview As ListView
Private CountPersonsButton As Button
Private GetPersonsButton As Button
Private NameET As EditText
Private AgeET As EditText
Private InsertNewPersonButton As Button
Private Label1 As Label
Private Label2 As Label
Private ServerIP As String
Private btnupdate As Button
Private btndelete As Button
Private ImageView1 As ImageView
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("1")
Activity.Title ="Playing with php/MySql"
ServerIP="mohammadnew-001-site1.dtempurl.com" ' The ip address where you Xampp installation runs
End Sub
Sub getdata
PersonsListview.Clear
Dim GetPersons As HttpJob
GetPersons.Initialize("GetP", Me)
' GetPersons.download2("http://" & ServerIP & "/persons.php", Array As String ("action", "GetPersons"))
GetPersons.PostString("http://" & ServerIP & "/persons.php", ("action=GetPersons"))
NameET.Text = ""
AgeET.Text = ""
NameET.RequestFocus
End Sub
Sub CountPersonsButton_Click
Dim CountPersons As HttpJob
CountPersons.Initialize("CountP", Me)
CountPersons.download2("http://" & ServerIP & "/persons.php", Array As String ("action", "CountPersons"))
End Sub
Sub GetPersonsButton_Click
getdata
End Sub
Sub InsertNewPersonButton_Click
If NameET.Text = "" Then
Msgbox("Name is missing or to short", "Name")
Return
End If
If AgeET.Text = "" Then
Msgbox("Age is missing", "Age")
Return
End If
Dim InsertNewPerson As HttpJob
InsertNewPerson.Initialize("InsertNewP", Me)
' InsertNewPerson.download2("http://" & ServerIP & "/persons.php", Array As String ("action", "InsertNewPerson", "name", NameET.Text, "age", AgeET.Text, "img",img64))
InsertNewPerson.postString("http://" & ServerIP & "/persons.php","action=InsertNewPerson&name="& NameET.Text &"&age="& AgeET.Text &"&img="& img64)
getdata
End Sub
Sub JobDone(Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim res As String
res = Job.GetString
Log("Back from Job:" & Job.JobName )
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select Job.JobName
Case "GetP"
Dim ListOfPersons As List
Dim PersonName As String
Dim PersonAge As Int
ListOfPersons = parser.NextArray 'returns a list with maps
PersonsListview.Clear
If ListOfPersons.Size=0 Then
PersonsListview.AddSingleLine ("No persons found...")
Else
For i = 0 To ListOfPersons.Size - 1
Dim Person As Map
Person = ListOfPersons.Get(i)
PersonName = Person.Get("name")
PersonAge = Person.Get("age")
PersonsListview.AddSingleLine (PersonName & ", " & PersonAge)
Next
End If
Case "CountP"
PersonsListview.AddSingleLine ("Persons in table: " & parser.NextValue)
Case "InsertNewP"
'Do nothing
End Select
Else
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ImageView1_Click
If Chooser.IsInitialized = False Then
Chooser.Initialize("chooser")
End If
Chooser.Show("image/*", "Choose image")
End Sub
Sub chooser_Result(Success As Boolean, Dir As String, FileName As String)
If Success Then
img64 = Base64Con.EncodeFromImage(Dir,FileName)
ImageView1.Bitmap=LoadBitmap(Dir,FileName)
Else
ToastMessageShow("No image selected", True)
End If
End Sub
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int, Filter As Boolean) As Bitmap
Dim jo As JavaObject
jo.InitializeStatic("android.graphics.Bitmap")
Return jo.RunMethod("createScaledBitmap", Array (Original, Width, Height, Filter))
End Sub