Option Strict Off Public Class 部件清單控制表 Private ReadOnly ds, ds1, ds2, ds4, ds5 As New DataSet Private Sub Set_清單() 清單_dgv.DataSource = Nothing : ds.Clear() 清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 清單_dgv.ColumnHeadersHeight = 25 清單_dgv.AllowUserToAddRows = False SQL_部件清單() : da.Fill(ds) : 清單_dgv.DataSource = ds.Tables(0) : conn.Close() 清單_dgv.Columns(0).Width = 200 : 清單_dgv.Columns(1).Width = 100 : 清單_dgv.Columns(2).Width = 100 For i As Integer = 0 To 清單_dgv.Rows.Count - 1 If 清單_dgv.Rows(i).Cells("樣品單用選擇").Value Is DBNull.Value Then 清單_dgv.Rows(i).Cells("樣品單用選擇").Value = False End If Next i End Sub Private Sub ComboBox1下拉表單資料載入() SQL_下拉部件類別1() 部件大項分類_cb.Items.Clear() : While (dr.Read()) : 部件大項分類_cb.Items.Add(dr("部件類別")) : End While : conn.Close() End Sub Private Sub ComboBox2下拉表單資料載入() SQL_下拉部件類別2() 貼標對應名稱_cb.Items.Clear() : While (dr.Read()) : 貼標對應名稱_cb.Items.Add(dr("貼標對應名稱")) : End While : conn.Close() End Sub Private Sub 部件清單控制表_Load(sender As Object, e As EventArgs) Handles MyBase.Load FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = True 部件_cb.Enabled = False : 確認新增_bt.Enabled = False ComboBox2下拉表單資料載入() : ComboBox1下拉表單資料載入() Set_清單() End Sub Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 部件大項分類_cb.SelectedIndexChanged 部件_cb.Text = Strings.Left(部件大項分類_cb.Text, 2) End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 清單_dgv.CellClick If e.RowIndex = -1 Then : Else 部件_cb.Text = Strings.Left(清單_dgv.Rows(e.RowIndex).Cells("部件").Value, 2) SQL_讀取部件大項分類() If dr.Read() Then 部件大項分類_cb.Text = dr("部件類別") End If 部件1_cb.Text = Strings.Mid(清單_dgv.Rows(e.RowIndex).Cells("部件").Value, 3, 100) ComboBox2下拉表單資料載入() 貼標對應名稱_cb.Text = 清單_dgv.Rows(e.RowIndex).Cells("貼標對應名稱").Value End If End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 清空_bt.Click ComboBox2下拉表單資料載入() End Sub Private Sub Button29_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click ComboBox2下拉表單資料載入() : ComboBox1下拉表單資料載入() 部件_cb.Text = "" : 部件1_cb.Text = "" 新增_bt.Enabled = False : 確認新增_bt.Enabled = True End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 確認新增_bt.Click If 部件_cb.Text = "" Or 部件1_cb.Text = "" Then MsgBox("部件大項資料沒有選擇或是部件名稱空白") Else SQL_查閱部件清單() If dr.Read() Then MsgBox("資料重複,請從新輸入或檢查") : conn.Close() : dr.Close() Else conn.Close() : dr.Close() SQL_新增部件清單() MsgBox("新增完成") : Set_清單() conn.Close() : dr.Close() 新增_bt.Enabled = True : 確認新增_bt.Enabled = False End If End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click Dim aa As MsgBoxResult aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel) If aa = MsgBoxResult.Ok Then : SQL_刪除部件清單() : MsgBox("刪除完成") : Set_清單() : End If conn.Close() End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles 儲存修改_bt.Click For i As Integer = 0 To 清單_dgv.Rows.Count - 1 資料數 = 清單_dgv.Rows.Count : MyModule1.進度條() PA5 = 清單_dgv.Rows(i).Cells("樣品單用選擇").Value : PA6 = 清單_dgv.Rows(i).Cells("部件").Value SQL_更改部件清單() : conn.Close() Next i : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 MsgBox("存檔完成") End Sub Private Sub Button11_Click(sender As Object, e As EventArgs) Handles 全部選擇_bt.Click For i As Integer = 0 To 清單_dgv.Rows.Count - 1 : 清單_dgv.Rows(i).Cells("樣品單用選擇").Value = True : Next i End Sub Private Sub Button10_Click(sender As Object, e As EventArgs) Handles 全部取消選_bt.Click For i As Integer = 0 To 清單_dgv.Rows.Count - 1 : 清單_dgv.Rows(i).Cells("樣品單用選擇").Value = False : Next i End Sub End Class