#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#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.
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 dbSQL As SQL
Dim sSQLQuery As String
Dim txtUser As EditText
Dim txtPassword As EditText
Dim pnlRegistration As Panel
Dim txtRegUserID As EditText
Dim txtRegPass As EditText
Dim txtRegRetypePass As EditText
Dim pnlLogin As Panel
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("Layout1")
Activity.LoadLayout("registration")
pnlRegistration.Visible=False
If FirstTime Then
'If File.Exists(File.DirRootExternal,"registration.db")=False Then
If File.Exists(File.DirInternal ,"registration.db")=False Then
'Msgbox(File.DirAssets,"")
Try
'File.Copy(File.DirAssets,"registration.db" ,File.DirRootExternal ,"registration.db")
File.Copy(File.DirAssets,"registration.db" , File.DirInternal ,"registration.db")
'File.Copy(File.DirAssets,"registration.db" ,File.DirDefaultExternal ,"registration.db")
ToastMessageShow("Successfully copy the database.",True)
'Msgbox("No database found.")
Catch
ToastMessageShow("Can not find the database file to copy.",True)
Return
End Try
Else
'ToastMessageShow("Database found in " & File.DirInternal,True)
Msgbox("Database found in " & File.DirInternal,"Database")
End If
'dbSQL.Initialize(File.DirRootExternal, "registration.db", True)
'dbSQL.Initialize(File.DirDefaultExternal, "registration.db", True)
dbSQL.Initialize(File.DirInternal , "registration.db", True)
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnLogin_Click
Dim cCursor As Cursor
If txtUser.Text="" Then
Msgbox("You must enter the username.","Message")
'Exit Sub
Return
End If
'Try
sSQLQuery="select * from user where user_name='" & txtUser.Text & "'"
cCursor=dbSQL.ExecQuery(sSQLQuery)
cCursor.Position=0
If cCursor.RowCount=0 Then
'Msgbox("Invlid username. Please type the correct user.","Wrong User")
ToastMessageShow("No data found. Please create new user then login again.",True)
Else
' cCursor.Position=0
If cCursor.GetString2(0)=txtUser.Text Then
If cCursor.GetString2(1)=txtPassword.Text Then
ToastMessageShow("Successfully login.",True)
cCursor.Close
Else
ToastMessageShow("Invalid password.",True)
Return
End If
Else
ToastMessageShow("Invalid username.",True)
Return
End If
End If
' Catch
' ToastMessageShow("No such table found.",True)
' End Try
End Sub
Sub btnCancel_Click
Activity.Finish
End Sub
Sub btnRegister_Click
pnlRegistration.Visible=True
pnlLogin.Visible=False
End Sub
Sub btnSave_Click
Dim answ As Int
If txtRegUserID.Text<>"" AND txtRegPass.Text<>"" Then
answ = Msgbox2("Do you really want to save the data?","Attention","Yes","","No",Null)
If answ=DialogResponse.POSITIVE Then
sSQLQuery="insert into user values(?,?)"
'Try
dbSQL.ExecNonQuery2(sSQLQuery,Array As String(txtRegUserID,txtRegPass))
ToastMessageShow("Data has been saved successfully.",True)
txtRegUserID.Text=""
txtRegPass.Text=""
txtRegRetypePass.Text=""
txtRegUserID.RequestFocus
' Catch
' ToastMessageShow("There is a problem with Data and couldn't save.",True)
' Return
' End Try
End If
End If
End Sub
Sub btnRegCancel_Click
pnlRegistration.Visible=False
pnlLogin.Visible=True
End Sub