Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. Imports MySql.Data
  2. Imports MySql.Data.MySqlClient
  3.  
  4.  
  5.  
  6. Public Class MainForm
  7.  
  8. Dim dbCon As MySqlConnection
  9. Dim strQuery As String = ""
  10. Dim SQLCmd As MySqlCommand
  11. Dim DA As New MySqlDataAdapter
  12. Dim bSource As New BindingSource
  13. Dim strDBCon = "Server=178.33.89.130;Database=zenrelo1_login;Uid=zenrelo1_secure;Pwd=hailzr0097"
  14.  
  15. Sub UpdateTable()
  16. Try
  17. tblData.RowsDefaultCellStyle.BackColor = Color.FromArgb(50, 50, 50)
  18.  
  19. Dim tblPub As New DataTable
  20. dbCon = New MySqlConnection(strDBCon)
  21. strQuery = "SELECT * FROM zenrelo1_login.users;"
  22.  
  23. SQLCmd = New MySqlCommand(strQuery, dbCon)
  24. dbCon.Open()
  25.  
  26. With SQLCmd
  27. .Connection = dbCon
  28. .CommandText = strQuery
  29. End With
  30. DA.SelectCommand = SQLCmd
  31. DA.Fill(tblPub)
  32. bSource.DataSource = tblPub
  33. tblData.DataSource = bSource
  34.  
  35. tblData.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
  36. Catch ex As Exception
  37. MessageBox.Show("Error occurred while deleting record on table!" & vbNewLine & "Error: " & ex.Message, "ZR_Admin")
  38. End Try
  39.  
  40. End Sub
  41.  
  42. Private Sub BtnAdd_Click(sender As Object, e As EventArgs) Handles BtnAdd.Click
  43. If lblUsername.Text = "customerUsername" Or lblPassword.Text = "customerPassword" Or lblHWID.Text = "customerHWID" Or lblExpiryDate.Text = "customerExpiryDate" Then
  44. MsgBox("Details are not completed!")
  45. Else
  46. Dim res As MsgBoxResult = MsgBoxResult.Yes
  47. If MsgBox("Confirm add credentials?" & vbNewLine & "Username: " & lblUsername.Text & vbNewLine & "Password: " & lblPassword.Text & vbNewLine & "HWID: " & lblHWID.Text & vbNewLine & "Expiry Date: " & lblExpiryDate.Text, MsgBoxStyle.YesNo, "ZR_Admin") = res Then
  48. Try
  49. dbCon = New MySqlConnection(strDBCon)
  50. SQLCmd = New MySqlCommand(strQuery, dbCon)
  51.  
  52. dbCon.Open()
  53. SQLCmd.Connection = dbCon
  54. SQLCmd.CommandText = "INSERT INTO users_sdo (`username`, `password`, `hwid`, `userlevel`, `creationdate`, `expirydate`) VALUES ('" & lblUsername.Text & "', '" & lblPassword.Text & "', '" & lblHWID.Text & "', 'SDO', '" & timenowPicker.Text & "', '" & lblExpiryDate.Text & "');"
  55. SQLCmd.ExecuteNonQuery()
  56. UpdateTable()
  57. MsgBox("[Credentials added successfully]" & vbNewLine & "Username: " & lblUsername.Text & vbNewLine & "Password: " & lblPassword.Text & vbNewLine & "HWID: " & lblHWID.Text & vbNewLine & "Expiry Date: " & lblExpiryDate.Text, MsgBoxStyle.Information, "ZR_Admin")
  58.  
  59. Catch ex As Exception
  60. MessageBox.Show("Error occurred while inserting record on table!" & vbNewLine & "Error: " & ex.Message, "ZR_Admin")
  61. End Try
  62. End If
  63.  
  64. End If
  65. End Sub
  66.  
  67. Private Sub BtnRemove_Click(sender As Object, e As EventArgs) Handles BtnRemove.Click
  68. Try
  69. If MsgBox("Confirm remove credentials?" & vbNewLine & "UserID: " & txtID.Text & vbNewLine & "Username: " & txtUser.Text, MsgBoxStyle.YesNo, "ZR_Admin") = MsgBoxResult.Yes Then
  70.  
  71. dbCon = New MySqlConnection(strDBCon)
  72. SQLCmd = New MySqlCommand(strQuery, dbCon)
  73. dbCon.Open()
  74. SQLCmd.Connection = dbCon
  75. SQLCmd.CommandText = "DELETE FROM uers WHERE `id`=' " & txtID.Text & "';"
  76. SQLCmd.ExecuteNonQuery()
  77. UpdateTable()
  78. MsgBox("[Credentials removed successfully]" & vbNewLine & "UserID: " & txtID.Text & vbNewLine & "Username: " & txtUser.Text, MsgBoxStyle.Information, "ZR_Admin")
  79.  
  80. End If
  81. Catch ex As Exception
  82. MessageBox.Show("Error occurred while deleting record on table!" & vbNewLine & "Error: " & ex.Message, "ZR_Admin")
  83. Finally
  84. dbCon.Close()
  85. End Try
  86.  
  87. End Sub
  88.  
  89. Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles Me.Load
  90. UpdateTable()
  91. timePicker.ShowUpDown = True
  92. End Sub
  93.  
  94. Private Sub cbOptions_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbOptions.SelectedIndexChanged
  95. If cbOptions.Text = "Expiry Date" Then
  96. timePicker.BringToFront()
  97. Else
  98. timePicker.SendToBack()
  99. End If
  100. End Sub
  101.  
  102. Private Sub tmrUpdateTime_Tick(sender As Object, e As EventArgs) Handles tmrUpdateTime.Tick
  103. timenowPicker.Value = DateTime.Now
  104. End Sub
  105.  
  106.  
  107. Private Sub BtnExtend_Click(sender As Object, e As EventArgs) Handles BtnExtend.Click
  108. If txtID.Text = "" Or lblExpiryDate.Text = "customerExpiryDate" Then
  109. MsgBox("Details are not completed!")
  110. Else
  111. Dim res As MsgBoxResult = MsgBoxResult.Yes
  112. If MsgBox("Confirm extend period?" & vbNewLine & "UserID: " & txtID.Text & vbNewLine & "Username: " & txtUser.Text & vbNewLine & "Expiry Date: " & lblExpiryDate.Text, MsgBoxStyle.YesNo, "ZR_Admin") = res Then
  113. Try
  114.  
  115. dbCon = New MySqlConnection(strDBCon)
  116. SQLCmd = New MySqlCommand(strQuery, dbCon)
  117.  
  118. dbCon.Open()
  119. SQLCmd.Connection = dbCon
  120. SQLCmd.CommandText = "UPDATE memberships SET `expirydate`='" & lblExpiryDate.Text & "' WHERE `id`='" & txtID.Text & "';"
  121. SQLCmd.ExecuteNonQuery()
  122. Catch ex As Exception
  123. MessageBox.Show("Error occurred while inserting record on table!" & vbNewLine & "Error: " & ex.Message, "ZR_Admin")
  124. Finally
  125. dbCon.Close()
  126. End Try
  127.  
  128. End If
  129. End If
  130. End Sub
  131. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement