訂單.vb 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 訂單_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  9. 'TODO: 這行程式碼會將資料載入 '謎鹿DataSet.訂單' 資料表。您可以視需要進行移動或移除。
  10. Me.訂單TableAdapter.Fill(Me.謎鹿DataSet.訂單)
  11. Dim myReader1 As SqlDataReader
  12. Dim mySqlCommand1 As SqlCommand
  13. mySqlCommand1 = New SqlCommand("SELECT 會員編號 from 訂單 WHERE 會員編號= '" & 耳環.Label6.Text & "'", conn)
  14. Try
  15. conn.Open()
  16. myReader1 = mySqlCommand1.ExecuteReader()
  17. Do While (myReader1.Read())
  18. Label7.Text = myReader1("會員編號").ToString() '→給Label值
  19. Loop
  20. Catch ex As Exception
  21. MessageBox.Show(ex.ToString())
  22. Finally
  23. If Not (myReader1 Is Nothing) Then
  24. myReader1.Close()
  25. End If
  26. If (conn.State = ConnectionState.Open) Then
  27. conn.Close()
  28. End If
  29. End Try
  30. Dim myReader2 As SqlDataReader
  31. Dim mySqlCommand2 As SqlCommand
  32. mySqlCommand2 = New SqlCommand("SELECT 付款方式 from 訂單 WHERE 會員編號= '" & 耳環.Label6.Text & "'", conn)
  33. Try
  34. conn.Open()
  35. myReader2 = mySqlCommand2.ExecuteReader()
  36. Do While (myReader2.Read())
  37. Label8.Text = myReader2("付款方式").ToString() '→給Label值
  38. Loop
  39. Catch ex As Exception
  40. MessageBox.Show(ex.ToString())
  41. Finally
  42. If Not (myReader2 Is Nothing) Then
  43. myReader2.Close()
  44. End If
  45. If (conn.State = ConnectionState.Open) Then
  46. conn.Close()
  47. End If
  48. End Try
  49. Dim myReader3 As SqlDataReader
  50. Dim mySqlCommand3 As SqlCommand
  51. mySqlCommand3 = New SqlCommand("SELECT 取貨方式 from 訂單 WHERE 會員編號= '" & 耳環.Label6.Text & "'", conn)
  52. Try
  53. conn.Open()
  54. myReader3 = mySqlCommand3.ExecuteReader()
  55. Do While (myReader3.Read())
  56. Label9.Text = myReader3("取貨方式").ToString() '→給Label值
  57. Loop
  58. Catch ex As Exception
  59. MessageBox.Show(ex.ToString())
  60. Finally
  61. If Not (myReader3 Is Nothing) Then
  62. myReader3.Close()
  63. End If
  64. If (conn.State = ConnectionState.Open) Then
  65. conn.Close()
  66. End If
  67. End Try
  68. Dim myReader4 As SqlDataReader
  69. Dim mySqlCommand4 As SqlCommand
  70. mySqlCommand4 = New SqlCommand("SELECT 訂單日期 from 訂單 WHERE 會員編號= '" & 耳環.Label6.Text & "'", conn)
  71. Try
  72. conn.Open()
  73. myReader4 = mySqlCommand4.ExecuteReader()
  74. Do While (myReader4.Read())
  75. Label10.Text = myReader4("訂單日期").ToString() '→給Label值
  76. Loop
  77. Catch ex As Exception
  78. MessageBox.Show(ex.ToString())
  79. Finally
  80. If Not (myReader4 Is Nothing) Then
  81. myReader4.Close()
  82. End If
  83. If (conn.State = ConnectionState.Open) Then
  84. conn.Close()
  85. End If
  86. End Try
  87. Dim myReader5 As SqlDataReader
  88. Dim mySqlCommand5 As SqlCommand
  89. mySqlCommand5 = New SqlCommand("SELECT 訂單編號 from 訂單 WHERE 會員編號= '" & 耳環.Label6.Text & "'", conn)
  90. Try
  91. conn.Open()
  92. myReader5 = mySqlCommand5.ExecuteReader()
  93. Do While (myReader5.Read())
  94. Label11.Text = myReader5("訂單編號").ToString() '→給Label值
  95. Loop
  96. Catch ex As Exception
  97. MessageBox.Show(ex.ToString())
  98. Finally
  99. If Not (myReader5 Is Nothing) Then
  100. myReader5.Close()
  101. End If
  102. If (conn.State = ConnectionState.Open) Then
  103. conn.Close()
  104. End If
  105. End Try
  106. End Sub
  107. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  108. conn.Open()
  109. Dim m_訂單編號 = 耳環.Label6.Text
  110. Dim sqldel As String = "DELETE FROM 訂單 WHERE 訂單編號 IN ('" & Label11.Text & "')"
  111. Dim del = New SqlCommand(sqldel, conn)
  112. del.ExecuteNonQuery()
  113. MsgBox("刪除成功!!!")
  114. conn.Close()
  115. Me.訂單TableAdapter.DeleteQuery(m_訂單編號)
  116. 訂單DataGridView.Refresh()
  117. Me.訂單BindingSource.DataSource = 訂單TableAdapter.GetData()
  118. Me.訂單BindingSource.ResetBindings(False)
  119. End Sub
  120. End Class