會員管理.vb 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. Imports System.Data.SqlClient
  2. Public Class 會員管理
  3. Dim conn As New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\奕穎\Documents\資管\大三上\系分\謎鹿\謎鹿.mdf;Integrated Security=True;Connect Timeout=30")
  4. Private Sub 會員管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  5. 'TODO: 這行程式碼會將資料載入 '謎鹿DataSet.會員' 資料表。您可以視需要進行移動或移除。
  6. Me.會員TableAdapter.Fill(Me.謎鹿DataSet.會員)
  7. 'TODO: 這行程式碼會將資料載入 '謎鹿DataSet.會員' 資料表。您可以視需要進行移動或移除。
  8. Me.會員TableAdapter.Fill(Me.謎鹿DataSet.會員)
  9. End Sub
  10. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  11. 商品管理.Show()
  12. Me.Visible = False
  13. End Sub
  14. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  15. 訂單管理.Show()
  16. Me.Visible = False
  17. End Sub
  18. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  19. 商品銷售紀錄.Show()
  20. Me.Visible = False
  21. End Sub
  22. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  23. 會員購買紀錄.Show()
  24. Me.Visible = False
  25. End Sub
  26. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  27. 管理者登入.Show()
  28. Me.Visible = False
  29. End Sub
  30. Private Sub 搜尋_Click(sender As Object, e As EventArgs) Handles 搜尋.Click
  31. Try
  32. Try
  33. Me.會員TableAdapter.FillByKeyword(Me.謎鹿DataSet.會員, Trim(ToolStripTextBox1.Text))
  34. Catch ex As Exception
  35. Me.會員TableAdapter.FillBysql(Me.謎鹿DataSet.會員, Trim(ToolStripTextBox1.Text))
  36. End Try
  37. Catch ex2 As Exception
  38. Me.會員TableAdapter.FillByemail(Me.謎鹿DataSet.會員, Trim(ToolStripTextBox1.Text))
  39. End Try
  40. End Sub
  41. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  42. conn.Open()
  43. Dim i As Integer = 會員DataGridView.CurrentRow.Index
  44. Dim m_會員編號 = 會員編號TextBox.Text
  45. Dim m_帳號 = 帳號TextBox.Text
  46. Dim m_密碼 = 密碼TextBox.Text
  47. Dim m_姓名 = 姓名TextBox.Text
  48. Dim m_電話 = 電話TextBox.Text
  49. Dim m_住址 = 住址TextBox.Text
  50. Dim m_email = EmailTextBox.Text
  51. Dim sqladd As String = "INSERT INTO 會員(會員編號,帳號,密碼,姓名,電話,住址,email) VALUES('" & 會員編號TextBox.Text & "','" & 帳號TextBox.Text & "','" & 密碼TextBox.Text & "',N'" & 姓名TextBox.Text & "','" & 電話TextBox.Text & "',N'" & 住址TextBox.Text & "','" & EmailTextBox.Text & "')"
  52. Dim add = New SqlCommand(sqladd, conn)
  53. Try
  54. add.ExecuteNonQuery()
  55. Catch ex3 As Exception
  56. MsgBox("會員編號已存在")
  57. End Try
  58. MsgBox("新增結束")
  59. conn.Close()
  60. Try
  61. Me.會員TableAdapter.InsertQuery(m_會員編號, m_帳號, m_密碼, m_姓名, m_電話, m_住址, m_email)
  62. Catch ex4 As Exception
  63. End Try
  64. Me.會員DataGridView.Refresh()
  65. Me.會員BindingSource.DataSource = 會員TableAdapter.GetData()
  66. Me.會員BindingSource.ResetBindings(False)
  67. End Sub
  68. Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
  69. conn.Open()
  70. Dim i As Integer = 會員DataGridView.CurrentRow.Index
  71. Dim m_會員編號 = 會員編號TextBox.Text
  72. Dim sqldel As String = "DELETE FROM 會員 WHERE 會員編號 IN('" & 會員編號TextBox.Text & "')"
  73. Dim del = New SqlCommand(sqldel, conn)
  74. Try
  75. del.ExecuteNonQuery()
  76. Catch ex5 As Exception
  77. MsgBox("會員編號不存在")
  78. End Try
  79. MsgBox("刪除結束")
  80. conn.Close()
  81. Try
  82. Me.會員TableAdapter.DeleteQuery(m_會員編號)
  83. Catch ex6 As Exception
  84. End Try
  85. Me.會員DataGridView.Refresh()
  86. Me.會員BindingSource.DataSource = 會員TableAdapter.GetData()
  87. Me.會員BindingSource.ResetBindings(False)
  88. End Sub
  89. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
  90. conn.Open()
  91. Dim i As Integer = 會員DataGridView.CurrentRow.Index
  92. Dim m_會員編號 = 會員編號TextBox.Text
  93. Dim m_帳號 = 帳號TextBox.Text
  94. Dim m_密碼 = 密碼TextBox.Text
  95. Dim m_姓名 = 姓名TextBox.Text
  96. Dim m_電話 = 電話TextBox.Text
  97. Dim m_住址 = 住址TextBox.Text
  98. Dim m_email = EmailTextBox.Text
  99. Dim sqlupd As String = "UPDATE 會員 Set 會員編號 = '" & 會員編號TextBox.Text & "',帳號 = N'" & 帳號TextBox.Text & "',密碼 = '" & 密碼TextBox.Text & "', 姓名 = N'" & 姓名TextBox.Text & "', 電話 = '" & 電話TextBox.Text & "', 住址 = N'" & 住址TextBox.Text & "', email = '" & EmailTextBox.Text & "' WHERE ID = '" & ComboBox1.Text & "'"
  100. Dim upd = New SqlCommand(sqlupd, conn)
  101. Try
  102. upd.ExecuteNonQuery()
  103. Catch ex7 As Exception
  104. End Try
  105. MsgBox("修改結束")
  106. conn.Close()
  107. Try
  108. Me.會員TableAdapter.UpdateQuery(m_會員編號, m_帳號, m_密碼, m_姓名, m_電話, m_住址, m_email)
  109. Catch ex8 As Exception
  110. End Try
  111. Me.會員DataGridView.Refresh()
  112. Me.會員BindingSource.DataSource = 會員TableAdapter.GetData()
  113. Me.會員BindingSource.ResetBindings(False)
  114. End Sub
  115. Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
  116. Me.會員TableAdapter.Fill(Me.謎鹿DataSet.會員)
  117. End Sub
  118. End Class