商品管理.vb 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. End Sub
  8. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  9. 訂單管理.Show()
  10. Me.Visible = False
  11. End Sub
  12. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  13. 會員管理.Show()
  14. Me.Visible = False
  15. End Sub
  16. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  17. 商品銷售紀錄.Show()
  18. Me.Visible = False
  19. End Sub
  20. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  21. 會員購買紀錄.Show()
  22. Me.Visible = False
  23. End Sub
  24. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  25. 管理者登入.Show()
  26. Me.Visible = False
  27. End Sub
  28. Private Sub 搜尋_Click(sender As Object, e As EventArgs) Handles 搜尋.Click
  29. Try
  30. Me.商品TableAdapter.FillByKeyword(Me.謎鹿DataSet.商品, Trim(ToolStripTextBox1.Text))
  31. Catch ex As Exception
  32. Me.商品TableAdapter.FillBysql(Me.謎鹿DataSet.商品, Trim(ToolStripTextBox1.Text))
  33. End Try
  34. End Sub
  35. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  36. conn.Open()
  37. Dim i As Integer = 商品DataGridView.CurrentRow.Index
  38. Dim m_商品編號 = 商品編號TextBox.Text
  39. Dim m_商品名稱 = 商品名稱TextBox.Text
  40. Dim m_庫存數量 = 庫存數量TextBox.Text
  41. Dim m_定價 = 定價TextBox.Text
  42. Dim m_種類 = 種類TextBox.Text
  43. Dim m_管理者編號 = 管理者編號TextBox.Text
  44. Dim sqladd As String = "INSERT INTO 商品(商品編號,商品名稱,庫存數量,定價,種類,管理者編號) VALUES('" & 商品編號TextBox.Text & "',N'" & 商品名稱TextBox.Text & "','" & 庫存數量TextBox.Text & "','" & 定價TextBox.Text & "',N'" & 種類TextBox.Text & "','" & 管理者編號TextBox.Text & "')"
  45. Dim add = New SqlCommand(sqladd, conn)
  46. Try
  47. add.ExecuteNonQuery()
  48. Catch ex2 As Exception
  49. End Try
  50. MsgBox("新增結束")
  51. conn.Close()
  52. Try
  53. Me.商品TableAdapter.InsertQuery(m_商品編號, m_商品名稱, m_庫存數量, m_定價, m_種類, m_管理者編號)
  54. Catch ex3 As Exception
  55. End Try
  56. Me.商品DataGridView.Refresh()
  57. Me.商品BindingSource.DataSource = 商品TableAdapter.GetData()
  58. Me.商品BindingSource.ResetBindings(False)
  59. End Sub
  60. Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
  61. conn.Open()
  62. Dim i As Integer = 商品DataGridView.CurrentRow.Index
  63. Dim m_商品編號 = 商品編號TextBox.Text
  64. Dim sqldel As String = "DELETE FROM 商品 WHERE 商品編號 IN('" & 商品編號TextBox.Text & "')"
  65. Dim del = New SqlCommand(sqldel, conn)
  66. Try
  67. del.ExecuteNonQuery()
  68. Catch ex4 As Exception
  69. MsgBox("商品編號不存在")
  70. End Try
  71. MsgBox("刪除結束")
  72. conn.Close()
  73. Try
  74. Me.商品TableAdapter.DeleteQuery(m_商品編號)
  75. Catch ex5 As Exception
  76. End Try
  77. Me.商品DataGridView.Refresh()
  78. Me.商品BindingSource.DataSource = 商品TableAdapter.GetData()
  79. Me.商品BindingSource.ResetBindings(False)
  80. End Sub
  81. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
  82. conn.Open()
  83. Dim i As Integer = 商品DataGridView.CurrentRow.Index
  84. Dim m_商品編號 = 商品編號TextBox.Text
  85. Dim m_商品名稱 = 商品名稱TextBox.Text
  86. Dim m_庫存數量 = 庫存數量TextBox.Text
  87. Dim m_定價 = 定價TextBox.Text
  88. Dim m_種類 = 種類TextBox.Text
  89. Dim m_管理者編號 = 管理者編號TextBox.Text
  90. Dim sqlupd As String = "UPDATE 商品 Set 商品編號 = '" & 商品編號TextBox.Text & "',商品名稱 = N'" & 商品名稱TextBox.Text & "',庫存數量 = '" & 庫存數量TextBox.Text & "', 定價 = '" & 定價TextBox.Text & "', 種類 = N'" & 種類TextBox.Text & "', 管理者編號 = '" & 管理者編號TextBox.Text & "' WHERE ID = '" & ComboBox1.Text & "'"
  91. Dim upd = New SqlCommand(sqlupd, conn)
  92. Try
  93. upd.ExecuteNonQuery()
  94. Catch ex6 As Exception
  95. End Try
  96. MsgBox("修改結束")
  97. conn.Close()
  98. Try
  99. Me.商品TableAdapter.UpdateQuery(m_商品編號, m_商品名稱, m_庫存數量, m_定價, m_種類, m_管理者編號)
  100. Catch ex7 As Exception
  101. End Try
  102. Me.商品DataGridView.Refresh()
  103. Me.商品BindingSource.DataSource = 商品TableAdapter.GetData()
  104. Me.商品BindingSource.ResetBindings(False)
  105. End Sub
  106. Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
  107. Me.商品TableAdapter.Fill(Me.謎鹿DataSet.商品)
  108. End Sub
  109. End Class