手工餅乾.vb 9.0 KB

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