耳環.vb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  5. 吊飾.Show()
  6. Me.Visible = False
  7. End Sub
  8. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  9. 指甲油.Show()
  10. Me.Visible = False
  11. End Sub
  12. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  13. 便籤夾.Show()
  14. Me.Visible = False
  15. End Sub
  16. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  17. 手工餅乾.Show()
  18. Me.Visible = False
  19. End Sub
  20. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  21. 購物車.Show()
  22. Me.Visible = False
  23. 購物車.Label48.Text = Val(購物車.Label14.Text) + Val(購物車.Label15.Text) + Val(購物車.Label16.Text) + Val(購物車.Label17.Text) + Val(購物車.Label51.Text)
  24. End Sub
  25. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  26. 訂單.Show()
  27. End Sub
  28. Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click '新增購物車紀錄
  29. conn.Open()
  30. 購物車.Label10.Text = Val(購物車.Label10.Text) + Val(TextBox2.Text)
  31. 購物車.Label11.Text = Val(購物車.Label11.Text) + Val(TextBox3.Text)
  32. 購物車.Label12.Text = Val(購物車.Label12.Text) + Val(TextBox4.Text)
  33. 購物車.Label13.Text = Val(購物車.Label13.Text) + Val(TextBox5.Text)
  34. 購物車.Label25.Text = Val(購物車.Label25.Text) + Val(吊飾.TextBox5.Text)
  35. 購物車.Label24.Text = Val(購物車.Label24.Text) + Val(吊飾.TextBox3.Text)
  36. 購物車.Label23.Text = Val(購物車.Label23.Text) + Val(吊飾.TextBox4.Text)
  37. 購物車.Label22.Text = Val(購物車.Label22.Text) + Val(吊飾.TextBox2.Text)
  38. 購物車.Label37.Text = Val(購物車.Label37.Text) + Val(指甲油.TextBox3.Text)
  39. 購物車.Label36.Text = Val(購物車.Label36.Text) + Val(指甲油.TextBox2.Text)
  40. 購物車.Label35.Text = Val(購物車.Label35.Text) + Val(指甲油.TextBox4.Text)
  41. 購物車.Label34.Text = Val(購物車.Label34.Text) + Val(指甲油.TextBox5.Text)
  42. 購物車.Label44.Text = Val(購物車.Label44.Text) + Val(便籤夾.TextBox3.Text)
  43. 購物車.Label46.Text = Val(購物車.Label46.Text) + Val(手工餅乾.TextBox3.Text)
  44. 購物車.Label14.Text = 290 * TextBox2.Text
  45. 購物車.Label15.Text = 190 * TextBox3.Text
  46. 購物車.Label16.Text = 190 * TextBox4.Text
  47. 購物車.Label17.Text = 290 * TextBox5.Text
  48. 購物車.Label21.Text = 200 * 吊飾.TextBox2.Text
  49. 購物車.Label20.Text = 200 * 吊飾.TextBox3.Text
  50. 購物車.Label19.Text = 200 * 吊飾.TextBox4.Text
  51. 購物車.Label18.Text = 200 * 吊飾.TextBox5.Text
  52. 購物車.Label32.Text = 380 * 指甲油.TextBox2.Text
  53. 購物車.Label33.Text = 380 * 指甲油.TextBox3.Text
  54. 購物車.Label31.Text = 380 * 指甲油.TextBox4.Text
  55. 購物車.Label30.Text = 290 * 指甲油.TextBox5.Text
  56. 購物車.Label43.Text = 85 * 便籤夾.TextBox3.Text
  57. 購物車.Label45.Text = 30 * 手工餅乾.TextBox3.Text
  58. 購物車.Label48.Text = Val(購物車.Label14.Text) + Val(購物車.Label15.Text) + Val(購物車.Label16.Text) + Val(購物車.Label17.Text) + Val(購物車.Label18.Text) + Val(購物車.Label19.Text) + Val(購物車.Label20.Text) + Val(購物車.Label21.Text) + Val(購物車.Label30.Text) + Val(購物車.Label31.Text) + Val(購物車.Label32.Text) + Val(購物車.Label33.Text) + Val(購物車.Label43.Text) + Val(購物車.Label45.Text) + Val(購物車.Label51.Text)
  59. Dim m_會員編號 = Label6.Text
  60. Dim m_運費 = 購物車.Label51.Text
  61. Dim m_總金額 = 購物車.Label48.Text
  62. Dim m_購物車編號 = Label6.Text + "cart"
  63. Dim sqladd As String = "INSERT INTO 購物車(會員編號,運費,總金額,購物車編號) VALUES('" & Label6.Text & "','" & 購物車.Label51.Text & "','" & 購物車.Label48.Text & "',,'" & Label6.Text + "cart" & "')"
  64. Dim add = New SqlCommand(sqladd, conn)
  65. Try
  66. add.ExecuteNonQuery()
  67. Catch ex As Exception
  68. End Try
  69. conn.Close()
  70. Try
  71. 購物車TableAdapter.InsertQuery(m_會員編號, m_運費, m_總金額, m_購物車編號)
  72. Catch ex2 As Exception
  73. MsgBox("請先清空購物車後,重新確認購買數量~", 64)
  74. End Try
  75. MsgBox("完成新增")
  76. Me.購物車DataGridView.Refresh()
  77. Me.購物車BindingSource.DataSource = 購物車TableAdapter.GetData()
  78. Me.購物車BindingSource.ResetBindings(False)
  79. End Sub
  80. Private Sub 耳環_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  81. 'TODO: 這行程式碼會將資料載入 '謎鹿DataSet.購物車' 資料表。您可以視需要進行移動或移除。
  82. Me.購物車TableAdapter.Fill(Me.謎鹿DataSet.購物車)
  83. Label6.Text = 登入.TextBox1.Text
  84. Label20.Text = Format(Now, "yyMMdHHmmss")
  85. Dim myReader1 As SqlDataReader
  86. Dim mySqlCommand1 As SqlCommand
  87. mySqlCommand1 = New SqlCommand("SELECT 庫存數量 from 商品 WHERE 商品編號= '" & Label25.Text & "'", conn)
  88. Try
  89. conn.Open()
  90. myReader1 = mySqlCommand1.ExecuteReader()
  91. Do While (myReader1.Read())
  92. Label21.Text = myReader1("庫存數量").ToString() '→給Label值
  93. Loop
  94. Catch ex As Exception
  95. MessageBox.Show(ex.ToString())
  96. Finally
  97. If Not (myReader1 Is Nothing) Then
  98. myReader1.Close()
  99. End If
  100. If (conn.State = ConnectionState.Open) Then
  101. conn.Close()
  102. End If
  103. End Try
  104. mySqlCommand1 = New SqlCommand("SELECT 庫存數量 from 商品 WHERE 商品編號= '" & Label26.Text & "'", conn)
  105. Try
  106. conn.Open()
  107. myReader1 = mySqlCommand1.ExecuteReader()
  108. Do While (myReader1.Read())
  109. Label22.Text = myReader1("庫存數量").ToString() '→給Label值
  110. Loop
  111. Catch ex As Exception
  112. MessageBox.Show(ex.ToString())
  113. Finally
  114. If Not (myReader1 Is Nothing) Then
  115. myReader1.Close()
  116. End If
  117. If (conn.State = ConnectionState.Open) Then
  118. conn.Close()
  119. End If
  120. End Try
  121. mySqlCommand1 = New SqlCommand("SELECT 庫存數量 from 商品 WHERE 商品編號= '" & Label27.Text & "'", conn)
  122. Try
  123. conn.Open()
  124. myReader1 = mySqlCommand1.ExecuteReader()
  125. Do While (myReader1.Read())
  126. Label23.Text = myReader1("庫存數量").ToString() '→給Label值
  127. Loop
  128. Catch ex As Exception
  129. MessageBox.Show(ex.ToString())
  130. Finally
  131. If Not (myReader1 Is Nothing) Then
  132. myReader1.Close()
  133. End If
  134. If (conn.State = ConnectionState.Open) Then
  135. conn.Close()
  136. End If
  137. End Try
  138. mySqlCommand1 = New SqlCommand("SELECT 庫存數量 from 商品 WHERE 商品編號= '" & Label28.Text & "'", conn)
  139. Try
  140. conn.Open()
  141. myReader1 = mySqlCommand1.ExecuteReader()
  142. Do While (myReader1.Read())
  143. Label24.Text = myReader1("庫存數量").ToString() '→給Label值
  144. Loop
  145. Catch ex As Exception
  146. MessageBox.Show(ex.ToString())
  147. Finally
  148. If Not (myReader1 Is Nothing) Then
  149. myReader1.Close()
  150. End If
  151. If (conn.State = ConnectionState.Open) Then
  152. conn.Close()
  153. End If
  154. End Try
  155. End Sub
  156. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click '刪除購物車紀錄
  157. Dim m_會員編號 = Label6.Text
  158. 購物車.Label10.Text = Nothing
  159. 購物車.Label11.Text = Nothing
  160. 購物車.Label12.Text = Nothing
  161. 購物車.Label13.Text = Nothing
  162. 購物車.Label14.Text = Nothing
  163. 購物車.Label15.Text = Nothing
  164. 購物車.Label16.Text = Nothing
  165. 購物車.Label17.Text = Nothing
  166. 購物車.Label18.Text = Nothing
  167. 購物車.Label19.Text = Nothing
  168. 購物車.Label20.Text = Nothing
  169. 購物車.Label21.Text = Nothing
  170. 購物車.Label22.Text = Nothing
  171. 購物車.Label23.Text = Nothing
  172. 購物車.Label24.Text = Nothing
  173. 購物車.Label25.Text = Nothing
  174. 購物車.Label30.Text = Nothing
  175. 購物車.Label31.Text = Nothing
  176. 購物車.Label32.Text = Nothing
  177. 購物車.Label33.Text = Nothing
  178. 購物車.Label34.Text = Nothing
  179. 購物車.Label35.Text = Nothing
  180. 購物車.Label36.Text = Nothing
  181. 購物車.Label37.Text = Nothing
  182. 購物車.Label43.Text = Nothing
  183. 購物車.Label44.Text = Nothing
  184. 購物車.Label45.Text = Nothing
  185. 購物車.Label46.Text = Nothing
  186. conn.Open()
  187. Dim sqldel As String = "DELETE FROM 購物車 WHERE 會員編號 IN ('" & Label6.Text & "')"
  188. Dim del = New SqlCommand(sqldel, conn)
  189. del.ExecuteNonQuery()
  190. MsgBox("刪除成功!!!")
  191. conn.Close()
  192. Me.購物車TableAdapter.DeleteQuery(m_會員編號)
  193. 購物車DataGridView.Refresh()
  194. Me.購物車BindingSource.DataSource = 購物車TableAdapter.GetData()
  195. Me.購物車BindingSource.ResetBindings(False)
  196. End Sub
  197. Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
  198. If (TextBox1.Text = "小橘花朵" Or TextBox1.Text = "雙園耳環" Or TextBox1.Text = "螺旋金" Or TextBox1.Text = "毛球") Then
  199. MsgBox("該商品位於耳環類別")
  200. End If
  201. If (TextBox1.Text = "艷紫碎花" Or TextBox1.Text = "亮黃碎花" Or TextBox1.Text = "柔橘碎花" Or TextBox1.Text = "甜粉碎花") Then
  202. MsgBox("該商品位於吊飾類別")
  203. End If
  204. If (TextBox1.Text = "Sandcastles沙堡" Or TextBox1.Text = "Blush酡顏" Or TextBox1.Text = "Agate紅瑪瑙" Or TextBox1.Text = "Olive橄欖") Then
  205. MsgBox("該商品位於指甲油類別")
  206. End If
  207. If (TextBox1.Text = "萌柴便籤夾") Then
  208. MsgBox("該商品位於便籤夾類別")
  209. End If
  210. If (TextBox1.Text = "謎鹿手工餅乾") Then
  211. MsgBox("該商品位於手工餅乾類別")
  212. End If
  213. End Sub
  214. End Class