Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. 'Activity module
  2. Sub Process_Globals
  3. Dim SQL1 As SQL
  4. Dim cursor1 As Cursor
  5. End Sub
  6.  
  7. Sub Globals
  8. Dim txtUsername As EditText
  9. Dim txtPassword As EditText
  10. Dim LVDb As ListView
  11. Dim cmdAdd As Button
  12. Dim cmdDelete As Button
  13. Dim cmdEdit As Button
  14. Dim ID As String
  15.  
  16. End Sub
  17.  
  18. Sub Activity_Create(FirstTime As Boolean)
  19.  
  20. Activity.LoadLayout("main")
  21. If File.Exists(File.DirInternal,"db.sql") = False Then
  22. File.Copy(File.DirAssets,"db.sql",File.DirInternal,"db.sql")
  23. End If
  24.  
  25. If SQL1.IsInitialized = False Then
  26. SQL1.Initialize(File.DirInternal, "db.sql", False)
  27. End If
  28.  
  29. DBload
  30.  
  31.  
  32. End Sub
  33.  
  34. Sub Activity_Resume
  35.  
  36. End Sub
  37.  
  38. Sub Activity_Pause (UserClosed As Boolean)
  39.  
  40. End Sub
  41.  
  42. Sub DBload
  43. LVDb.Clear'need to clear the list
  44. cursor1 = SQL1.ExecQuery("SELECT * FROM tblUsers")
  45. For i = 0 To cursor1.RowCount - 1
  46. cursor1.Position = i
  47. LVDb.AddSingleLine(cursor1.GetString("ID")& "|" &cursor1.GetString("Username")& " | " & cursor1.GetString("Password"))
  48. LVDb.SingleLineLayout.ItemHeight = 40
  49. LVDb.SingleLineLayout.Label.TextSize = 20
  50. LVDb.SingleLineLayout.label.TextColor = Colors.Black
  51. LVDb.SingleLineLayout.label.Color = Colors.Gray
  52. Next
  53. End Sub
  54.  
  55. Sub cmdAdd_Click
  56.  
  57. If txtUsername.Text = "" OR txtPassword.Text = "" Then
  58. Msgbox("You have to enter all fields","Missed data field")
  59. Else
  60.  
  61. 'Grab the last ID number which is the highest number
  62. cursor1 = SQL1.ExecQuery("SELECT ID FROM tblUsers")
  63. If cursor1.RowCount > 0 Then
  64. For i = 0 To cursor1.RowCount - 1
  65. cursor1.Position = i
  66.  
  67. Dim NewID As Int
  68. NewID = cursor1.GetInt("ID")
  69. Next
  70.  
  71. End If
  72. NewID = NewID +1 ' add 1 to the ID number to make a new ID field
  73. SQL1.ExecNonQuery("INSERT INTO tblUsers VALUES('" & NewID & "','" & txtUsername.Text & "','" & txtPassword.Text & "')")
  74. DBload
  75. txtUsername.Text = ""
  76. txtPassword.Text = ""
  77. txtUsername.RequestFocus
  78. End If
  79.  
  80.  
  81. End Sub
  82. Sub cmdDelete_Click
  83.  
  84.  
  85. SQL1.ExecNonQuery("DELETE FROM tblUsers where ID = '" &ID & "' ")
  86. DBload
  87. txtUsername.Text = ""
  88. txtPassword.Text =""
  89.  
  90. End Sub
  91.  
  92. Sub LVDb_ItemClick (Position As Int, Value As Object)' click on the entry in the list
  93. Dim idvalue As String
  94. Dim countIt As Int
  95.  
  96. idvalue = Value
  97. countIt = idvalue.IndexOf("|") 'find location of sperator
  98. idvalue = idvalue.SubString2(0,countIt) 'find first part of label text
  99. ID = idvalue
  100. cursor1 = SQL1.ExecQuery("SELECT * FROM tblUsers where ID = '" & ID & "' ")
  101. For i = 0 To cursor1.RowCount - 1
  102. cursor1.Position = i
  103. txtUsername.text=cursor1.getString("Username")
  104. txtPassword.text=cursor1.getString("Password")
  105. Next
  106. End Sub
  107.  
  108. Sub cmdEdit_Click
  109. SQL1.ExecNonQuery("UPDATE tblUsers set Username ='"& txtUsername.text &"',Password ='"& txtPassword.text &"' WHERE ID = " & ID)
  110. DBload
  111. End Sub
  112. Sub cmdExit_Click
  113. Activity.finish
  114. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement