Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

清單修改2.vb 4.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 清單修改2
  4. ReadOnly conn As New SqlConnection
  5. ReadOnly da As New SqlDataAdapter
  6. ReadOnly cmd As New SqlCommand
  7. ReadOnly ds As New DataSet
  8. Dim dr As SqlDataReader
  9. Private Sub Set_DGV1載入前設定()
  10. DataGridView1.DataSource = Nothing : ds.Clear()
  11. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  12. DataGridView1.ColumnHeadersHeight = 25
  13. DataGridView1.AllowUserToAddRows = False
  14. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  15. End Sub
  16. Private Sub Set_DGV1載入後設定()
  17. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  18. End Sub
  19. Private Sub Set_資料清單()
  20. Set_DGV1載入前設定()
  21. If INVOICE用客戶資料 = True Then : SQL1 = "SELECT ATTN, TEL FROM INVOICE用客戶資料 ORDER BY ATTN"
  22. End If
  23. Set_DGV1載入後設定()
  24. End Sub
  25. Private Sub Set_grid()
  26. DataGridView1.Columns(0).Width = 188 : DataGridView1.Columns(1).Width = 187
  27. End Sub
  28. Private Sub 清單修改2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  29. FormBorderStyle = FormBorderStyle.SizableToolWindow
  30. Set_資料清單() : Set_grid()
  31. End Sub
  32. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  33. If e.RowIndex = -1 Then : Else
  34. TextBox1.Text = DataGridView1(0, e.RowIndex).Value.ToString : TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString
  35. TextBox3.Text = DataGridView1(0, e.RowIndex).Value.ToString
  36. End If
  37. End Sub
  38. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  39. If TextBox1.Text = "" Then
  40. MsgBox("資料有缺或有誤,請重新檢查")
  41. Else
  42. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  43. If INVOICE用客戶資料 = True Then : SQL1 = "SELECT ATTN, TEL FROM INVOICE用客戶資料 WHERE ATTN LIKE N'" & TextBox1.Text & "'"
  44. End If
  45. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  46. If dr.Read() Then
  47. MsgBox("資料重複,請從新輸入或檢查")
  48. conn.Close() : dr.Close()
  49. Else
  50. conn.Close() : dr.Close()
  51. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  52. If INVOICE用客戶資料 = True Then : SQL1 = "INSERT INTO INVOICE用客戶資料 (ATTN, TEL) VALUES (N'" & TextBox1.Text & "', N'" & TextBox2.Text & "')"
  53. End If
  54. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  55. MsgBox("新增完成")
  56. conn.Close() : dr.Close()
  57. End If
  58. End If
  59. Set_資料清單() : Set_grid()
  60. End Sub
  61. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  62. If TextBox1.Text = "" Then
  63. MsgBox("資料有缺或有誤,請重新檢查")
  64. Else
  65. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  66. If INVOICE用客戶資料 = True Then : SQL1 = "UPDATE INVOICE用客戶資料 SET ATTN = N'" & TextBox1.Text & "', TEL = N'" & TextBox2.Text & "' WHERE ATTN LIKE N'" & TextBox3.Text & "'"
  67. End If
  68. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  69. MsgBox("修改完成")
  70. conn.Close()
  71. End If
  72. Set_資料清單() : Set_grid()
  73. End Sub
  74. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  75. If INVOICE用客戶資料 = True Then : SQL1 = "DELETE FROM INVOICE用客戶資料 WHERE (ATTN = N'" & TextBox1.Text & "')"
  76. End If
  77. cmd.CommandText = SQL1 : cmd.Connection = conn
  78. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  79. Dim aa As MsgBoxResult
  80. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  81. If aa = MsgBoxResult.Ok Then : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : MsgBox("刪除完成") : End If
  82. conn.Close()
  83. Set_資料清單() : Set_grid()
  84. End Sub
  85. End Class