指甲油.vb 10 KB

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