Guest User

Untitled

a guest
Jan 26th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. Private WithEvents ligardb As ADODB.Connection
  3. Private WithEvents RecordDB As ADODB.Recordset
  4. Dim mblnAddMode As Boolean
  5.  
  6. Private Sub Command1_Click()
  7.  
  8. Dim strConnect As String
  9. Dim user_id As String
  10. Dim pass As String
  11.  
  12. user_id = "jeff"
  13. pass = "123"
  14.  
  15. strConnect = "DRIVER={MySQL ODBC 3.51 Driver};user =" & user_id & ";password=" & pass & _
  16. ";server=localhost; Database = dbusers"
  17.  
  18. Set ligardb = New ADODB.Connection
  19.  
  20. ligardb.CursorLocation = adUseClient
  21.  
  22. ligardb.Open strConnect
  23.  
  24. Set RecordDB = New ADODB.Recordset
  25.  
  26. RecordDB.CursorType = adOpenStatic
  27.  
  28. RecordDB.CursorLocation = adUseClient
  29.  
  30. RecordDB.LockType = adLockPessimistic
  31.  
  32. RecordDB.Source = "select * from users"
  33.  
  34. RecordDB.ActiveConnection = ligardb
  35.  
  36. RecordDB.Open
  37.  
  38. Command1.Enabled = False
  39.  
  40. Command2.Enabled = True
  41.  
  42. Frame1.Visible = True
  43. Command8.Visible = True
  44. Command10.Visible = True
  45. Command11.Visible = True
  46.  
  47. Command4.Enabled = True
  48. Command5.Enabled = True
  49. Command6.Enabled = True
  50. Command7.Enabled = True
  51. carregaregistos
  52.  
  53.  
  54. End Sub
  55.  
  56.  
  57. Private Sub gravar()
  58. RecordDB.Fields("ID").Value = Val(Text3.Text)
  59. RecordDB.Fields("Nome").Value = Text4.Text
  60. RecordDB!Morada = Text5.Text
  61. RecordDB!Data = CDate(Text6.Text)
  62. RecordDB.Fields("Password").Value = Text7.Text
  63.  
  64. End Sub
  65.  
  66. Private Sub Command10_Click()
  67. Dim g As Integer
  68. g = MsgBox("Irá editar o dado ja existente. Tem a certeza que quer guardar?", vbYesNo, "Guardar?")
  69. If g = vbYes Then
  70.  
  71.     If Text3.Text <> "" And Text4 <> "" And Text5 <> "" Then
  72.        Call gravar
  73.        RecordDB.Update
  74.     Else
  75.        MsgBox "Falta informar dados !!!!", vbCritical, "Incluindo dados"
  76.        RecordDB.CancelUpdate
  77.        mblnAddMode = False
  78.        Exit Sub
  79.     End If
  80.    
  81.     mblnAddMode = False
  82.  
  83. End If
  84. End Sub
  85.  
  86. Private Sub Command11_Click()
  87.      
  88.       If MsgBox("Confirma Exclusão deste Registro ? ", vbYesNo, "Excluir Registros") = vbYes Then
  89.        
  90.         On Error Resume Next
  91.  
  92.         RecordDB.Delete
  93.         RecordDB.Update
  94.        
  95. End If
  96.  
  97.  
  98. End Sub
  99.  
  100. Private Sub Command2_Click()
  101.  
  102. ligardb.Close
  103. Set ligardb = Nothing
  104.  
  105. Command2.Enabled = False
  106. Command1.Enabled = True
  107.  
  108. Command2.Enabled = False
  109. Command4.Enabled = False
  110. Command5.Enabled = False
  111. Command6.Enabled = False
  112. Command7.Enabled = False
  113.  
  114. Frame1.Visible = False
  115. Command8.Visible = False
  116. Command10.Visible = False
  117. Command11.Visible = False
  118.  
  119. End Sub
  120.  
  121. Private Sub Command3_Click()
  122. Dim terminar As Integer
  123. terminar = MsgBox("Deseja mesmo sair da aplicação?", vbYesNo, "Sair?")
  124. If terminar = vbYes Then
  125. End
  126. Else
  127. If terminar = vbNo Then
  128. MsgBox ("Clique OK para continuar")
  129. End If
  130. End If
  131. End Sub
  132.  
  133. Private Sub Command4_Click()
  134. If RecordDB.BOF = False Then
  135. RecordDB.MovePrevious
  136. If RecordDB.BOF = True Then
  137. RecordDB.MoveFirst
  138. End If
  139. Else
  140. If RecordDB.EOF Then
  141. MsgBox ("Não há dados no Arquivo!")
  142. Else
  143. RecordDB.MoveFirst
  144. End If
  145. End If
  146.  
  147. carregaregistos
  148. End Sub
  149.  
  150. Private Sub Command5_Click()
  151. If RecordDB.EOF = True Then
  152. MsgBox "Não há dados no Arquivo!", , "Sem dados !"
  153. Else
  154. RecorDB.MoveNext
  155. carregaregistos
  156. EndIf
  157. End Sub
  158.  
  159. Private Sub Command6_Click()
  160. If RecordDB.BOF = False Then
  161. RecordDB.MoveFirst
  162. ElseIf RecordDB.BOF = True _
  163. And RecordDB.EOF = True Then
  164.  
  165. MsgBox "Não há dados no Arquivo!", , "Sem dados !"
  166. End If
  167.  
  168. carregaregistos
  169. End Sub
  170.  
  171. Private Sub Command7_Click()
  172. If RecordDB.EOF = False Then
  173. RecordDB.MoveLast
  174. ElseIf RecordDB.BOF = True _
  175. And RecordDB.EOF = True Then
  176.  
  177. MsgBox "Não há dados no Arquivo!", , "Sem dados !"
  178. End If
  179.  
  180. carregaregistos
  181. End Sub
  182.  
  183. Private Sub carregaregistos()
  184. If RecordDB.BOF = True Or RecordDB.EOF = True Then
  185. Exit Sub
  186. End If
  187.  
  188. Text3.Text = RecordDB.Fields("ID").Value & " "
  189. Text4.Text = RecordDB!nome & " "
  190. Text5.Text = RecordDB!Morada & " "
  191. Text6.Text = RecordDB!Data & " "
  192. Text7.Text = RecordDB!Password & " "
  193. End Sub
  194.  
  195. Private Sub Command8_Click()
  196.  
  197.         RecordDB.AddNew
  198.         Call gravar
  199.        
  200.         RecordDB.Update
  201.        
  202. End Sub
  203.  
  204. Private Sub Form_Load()
  205.  
  206. Command2.Enabled = False
  207.  
  208. Frame1.Visible = False
  209. Command8.Visible = False
  210. Command10.Visible = False
  211. Command11.Visible = False
  212.  
  213. End Sub
Add Comment
Please, Sign In to add comment