Advertisement
Guest User

source db

a guest
Oct 19th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. #Region Project Attributes
  2. #ApplicationLabel: Sql Exercise
  3. #VersionCode: 1
  4. #VersionName:'SupportedOrientations possible values: unspecified, landscape or portrait.
  5. #SupportedOrientations: portrait
  6. #CanInstallToExternalStorage:False
  7.  
  8. #End Region
  9. #Region Activity Attributes
  10. #FullScreen: False
  11. #IncludeTitle: True
  12. #End Region
  13.  
  14.  
  15. Sub Process_Globals
  16. 'These global variables will be declared once when the application starts.
  17. 'These variables can be accessed from all modules.
  18. Dim SQL1 As SQL
  19. Dim cursor1 As Cursor
  20. End Sub
  21.  
  22.  
  23. Sub Globals
  24. 'These global variables will be redeclared each time the activity is created.
  25. 'These variables can only be accessed from this module.
  26. Private txtUsername As EditText
  27. Private txtPassword As EditText
  28. Private LVDb As ListView
  29. Private cmdAdd As Button
  30. Private cmdDelete As Button
  31. Private cmdEdit As Button
  32. Private cmdExit As Button
  33. Private ID As String
  34. End Sub
  35. Sub Activity_Create(FirstTime As Boolean)
  36.  
  37. Activity.LoadLayout("lay1")
  38. If File.Exists(File.DirInternal,"pbu.sql") = False Then
  39. File.Copy(File.DirAssets,"pbu.sql",File.DirInternal,"pbu.sql")
  40. End If
  41. If SQL1.IsInitialized = False Then
  42. SQL1.Initialize(File.DirInternal, "pbu.sql", False)
  43. End If
  44. DBload' Call Function DBload
  45. End Sub
  46.  
  47.  
  48.  
  49.  
  50. Sub DBload
  51. LVDb.Clear'need to clear the list
  52. cursor1 = SQL1.ExecQuery("SELECT * FROM tblUser")
  53. For i =0 To cursor1.RowCount -1
  54. cursor1.Position = i
  55. LVDb.AddSingleLine(cursor1.GetString("ID")&"|" &cursor1.GetString("Username")&" | "& cursor1.GetString("Password"))
  56. LVDb.SingleLineLayout.ItemHeight =40
  57. LVDb.SingleLineLayout.Label.TextSize =10
  58. LVDb.SingleLineLayout.label.TextColor =Colors.Black
  59. LVDb.SingleLineLayout.label.Color =Colors.White
  60. Next
  61. End Sub
  62.  
  63.  
  64. Sub cmdAdd_Click
  65.  
  66. If txtUsername.Text ="" Or txtPassword.Text ="" Then
  67. Msgbox("You have to enter all fields","Missed data field")
  68. Else
  69. 'Grab the last ID number which is the highest number
  70. cursor1 = SQL1.ExecQuery("SELECT ID FROM tblUser")
  71. If cursor1.RowCount >0 Then
  72. For i =0 To cursor1.RowCount -1
  73. cursor1.Position = i
  74. Dim NewID As Int
  75. NewID = cursor1.GetInt("ID")
  76. Next
  77. End If
  78. NewID = NewID +1' add 1 to the ID number to make a new ID Field
  79. SQL1.ExecNonQuery("INSERT INTO tblUser VALUES('"& NewID & "','"& txtUsername.Text&"','"&txtPassword.Text&"')")
  80. DBload
  81. txtUsername.Text =" "
  82. txtPassword.Text = ""
  83. txtUsername.RequestFocus
  84. End If
  85.  
  86. End Sub
  87.  
  88.  
  89. Sub cmdDelete_Click
  90. SQL1.ExecNonQuery("DELETE FROM tblUser where ID = '"& ID &"' ")
  91. DBload
  92. txtUsername.Text =""
  93. txtPassword.Text=""
  94. End Sub
  95.  
  96.  
  97. Sub LVDb_ItemClick (Position As Int, Value As Object)' click on the entry in the list
  98.  
  99. Dim idvalue As String
  100. Dim countIt As Int
  101. idvalue = Value
  102. countIt = idvalue.IndexOf("|") 'find location of sperator
  103. idvalue = idvalue.SubString2(0,countIt) 'find first part of label
  104. ID = idvalue
  105. cursor1 = SQL1.ExecQuery("SELECT * FROM tblUser where ID = '"& ID &"' ")
  106. For i =0 To cursor1.RowCount -1
  107. cursor1.Position = i
  108. txtUsername.text=cursor1.getString("Username")
  109. txtPassword.text=cursor1.getString("Password")
  110. Next
  111.  
  112. End Sub
  113.  
  114.  
  115. Sub cmdEdit_Click
  116.  
  117. If txtUsername.Text ="" Or txtPassword.Text ="" Then
  118. Msgbox("Select item to edit","Missed data item")
  119. Else
  120. SQL1.ExecNonQuery("UPDATE tblUser set Username ='"&txtUsername.text&"', Password ='"&txtPassword.text&"' WHERE ID = "& ID)
  121. DBload
  122.  
  123. End If
  124.  
  125. End Sub
  126.  
  127. Sub cmdExit_Click
  128.  
  129. Activity.Finish
  130. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement