吊飾.vb 11 KB

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