Нема описа
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.

型體控制表.vb 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 型體控制表
  4. ReadOnly conn As New SqlConnection
  5. ReadOnly da As New SqlDataAdapter
  6. ReadOnly cmd As New SqlCommand
  7. ReadOnly ds As New DataSet : ReadOnly ds1 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() : Set_grid()
  18. End Sub
  19. Private Sub Set_清單()
  20. Set_DGV1載入前設定()
  21. If PA = "" Then
  22. SQL1 = "SELECT 客戶簡稱 FROM 客戶控制表 ORDER BY 客戶簡稱"
  23. Else
  24. SQL1 = "SELECT 客戶簡稱 FROM 客戶控制表 WHERE (客戶簡稱 LIKE N'%" & PA & "%') ORDER BY 客戶簡稱"
  25. End If
  26. Set_DGV1載入後設定()
  27. End Sub
  28. Private Sub Set_grid()
  29. DataGridView1.Columns(0).Width = 150
  30. End Sub
  31. Private Sub Set_DGV2載入前設定()
  32. DataGridView2.DataSource = Nothing : ds1.Clear()
  33. DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  34. DataGridView2.ColumnHeadersHeight = 25
  35. DataGridView2.AllowUserToAddRows = False
  36. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  37. End Sub
  38. Private Sub Set_DGV2載入後設定()
  39. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close() : Set_grid1()
  40. End Sub
  41. Private Sub Set_清單1()
  42. Set_DGV2載入前設定()
  43. SQL1 = "SELECT 客戶簡稱 AS 項次, 型體號碼, 型體名稱 FROM 型體控制表 WHERE (客戶簡稱 LIKE N'" & TextBox1.Text & "') ORDER BY 客戶簡稱"
  44. Set_DGV2載入後設定()
  45. End Sub
  46. Private Sub Set_grid1()
  47. DataGridView2.Columns(0).Width = 60 : DataGridView2.Columns(1).Width = 250 : DataGridView2.Columns(2).Width = 350
  48. For i As Integer = 0 To DataGridView2.Rows.Count - 1
  49. DataGridView2(0, i).Value = i + 1
  50. Next
  51. End Sub
  52. Private Sub 型體控制表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  53. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = True
  54. TextBox1.Enabled = False : TextBox4.Visible = False : TextBox5.Visible = False
  55. Set_清單()
  56. If CC(15) = False Then : Button4.Enabled = False : Button5.Enabled = False : End If
  57. If CC(16) = False Then : Button3.Enabled = False : End If
  58. End Sub
  59. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  60. If e.RowIndex = -1 Then : Else
  61. TextBox1.Text = DataGridView1(0, e.RowIndex).Value.ToString
  62. Set_清單1()
  63. End If
  64. End Sub
  65. Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  66. If e.RowIndex = -1 Then : Else
  67. TextBox2.Text = DataGridView2(1, e.RowIndex).Value.ToString : TextBox3.Text = DataGridView2(2, e.RowIndex).Value.ToString
  68. TextBox4.Text = DataGridView2(1, e.RowIndex).Value.ToString : TextBox5.Text = DataGridView2(2, e.RowIndex).Value.ToString
  69. End If
  70. End Sub
  71. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  72. 清單修改.Close() : 客戶清單修改 = True : 清單修改.ShowDialog() : 客戶清單修改 = False : Set_清單()
  73. End Sub
  74. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
  75. PA = InputBox("請輸入要查詢的關鍵字") : Set_清單() : PA = ""
  76. End Sub
  77. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  78. PA = InputBox("請輸入要查詢的關鍵字")
  79. Set_DGV2載入前設定()
  80. SQL1 = "SELECT 客戶簡稱 AS 項次, 型體號碼, 型體名稱 FROM 型體控制表 WHERE (客戶簡稱 LIKE N'" & TextBox1.Text & "') AND (型體號碼 LIKE N'%" & PA & "%' OR 型體名稱 LIKE N'%" & PA & "%') ORDER BY 型體號碼 DESC"
  81. Set_DGV2載入後設定()
  82. PA = ""
  83. End Sub
  84. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  85. If TextBox1.Text = "" Or TextBox2.Text = "" Then
  86. MsgBox("資料有缺或有誤,請重新檢查")
  87. Else
  88. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  89. SQL1 = "SELECT 客戶簡稱, 型體號碼, 型體名稱 FROM 型體控制表 WHERE 客戶簡稱 LIKE N'" & TextBox1.Text & "' AND 型體號碼 LIKE N'" & TextBox2.Text & "' AND 型體名稱 LIKE N'" & TextBox3.Text & "'"
  90. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  91. If dr.Read() Then
  92. MsgBox("資料重複,請從新輸入或檢查")
  93. conn.Close() : dr.Close()
  94. Else
  95. conn.Close() : dr.Close()
  96. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  97. SQL1 = "INSERT INTO 型體控制表 (客戶簡稱, 型體號碼, 型體名稱) VALUES (N'" & TextBox1.Text & "', N'" & TextBox2.Text & "', N'" & TextBox3.Text & "')"
  98. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  99. MsgBox("新增完成")
  100. conn.Close() : dr.Close()
  101. End If
  102. End If
  103. Set_清單1()
  104. End Sub
  105. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  106. If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
  107. MsgBox("資料有缺或有誤,請重新檢查")
  108. Else
  109. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  110. SQL1 = "UPDATE 型體控制表 SET 型體號碼 = N'" & TextBox2.Text & "', 型體名稱 = N'" & TextBox3.Text & "' " &
  111. "WHERE 客戶簡稱 LIKE N'" & TextBox1.Text & "' AND 型體號碼 LIKE N'" & TextBox4.Text & "' AND 型體名稱 LIKE N'" & TextBox5.Text & "'"
  112. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  113. MsgBox("修改完成")
  114. conn.Close()
  115. End If
  116. Set_清單1()
  117. End Sub
  118. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  119. SQL1 = "DELETE FROM 型體控制表 WHERE 客戶簡稱 LIKE N'" & TextBox1.Text & "' AND 型體號碼 LIKE N'" & TextBox2.Text & "' AND 型體名稱 LIKE N'" & TextBox3.Text & "'"
  120. cmd.CommandText = SQL1 : cmd.Connection = conn
  121. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  122. Dim aa As MsgBoxResult
  123. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  124. If aa = MsgBoxResult.Ok Then : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : MsgBox("刪除完成") : End If
  125. conn.Close()
  126. Set_清單1() : Set_grid()
  127. End Sub
  128. End Class