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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 部件清單控制表
  4. Dim conn As New SqlConnection
  5. Dim da As New SqlDataAdapter
  6. Dim cmd As New SqlCommand
  7. Dim ds As New DataSet : Dim ds1 As New DataSet : Dim ds2 As New DataSet : Dim ds4 As New DataSet : Dim ds5 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. SQL1 = "SELECT 部件, 貼標對應名稱,樣品單用選擇 FROM 部件清單 ORDER BY 部件"
  22. Set_DGV1載入後設定()
  23. End Sub
  24. Private Sub Set_grid()
  25. DataGridView1.Columns(0).Width = 200 : DataGridView1.Columns(1).Width = 100 : DataGridView1.Columns(2).Width = 100
  26. End Sub
  27. Private Sub ComboBox1下拉表單資料載入()
  28. conn.Close()
  29. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  30. SQL1 = "SELECT 部件類別 FROM 部件大項分類 ORDER BY 部件類別"
  31. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  32. ComboBox1.Items.Clear() : While (dr.Read()) : ComboBox1.Items.Add(dr("部件類別")) : End While : conn.Close()
  33. End Sub
  34. Private Sub ComboBox2下拉表單資料載入()
  35. conn.Close()
  36. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  37. SQL1 = "SELECT 貼標對應名稱 FROM 貼標對應名稱清單"
  38. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  39. ComboBox2.Items.Clear() : While (dr.Read()) : ComboBox2.Items.Add(dr("貼標對應名稱")) : End While : conn.Close()
  40. End Sub
  41. Private Sub 部件清單控制表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  42. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = True
  43. TextBox1.Enabled = False : Button1.Enabled = False
  44. ComboBox2下拉表單資料載入() : ComboBox1下拉表單資料載入()
  45. Set_清單()
  46. End Sub
  47. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  48. TextBox1.Text = Strings.Left(ComboBox1.Text, 2)
  49. End Sub
  50. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  51. If e.RowIndex = -1 Then : Else
  52. TextBox1.Text = Strings.Left(DataGridView1.Rows(e.RowIndex).Cells("部件").Value, 2)
  53. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  54. SQL1 = "SELECT 部件類別 FROM 部件大項分類 WHERE 部件類別 LIKE N'" & TextBox1.Text & "%' ORDER BY 部件類別"
  55. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  56. If dr.Read() Then
  57. ComboBox1.Text = dr("部件類別")
  58. End If
  59. TextBox2.Text = Strings.Mid(DataGridView1.Rows(e.RowIndex).Cells("部件").Value, 3, 100)
  60. ComboBox2下拉表單資料載入()
  61. ComboBox2.Text = DataGridView1.Rows(e.RowIndex).Cells("貼標對應名稱").Value
  62. End If
  63. End Sub
  64. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  65. ComboBox2下拉表單資料載入()
  66. End Sub
  67. Private Sub Button29_Click(sender As Object, e As EventArgs) Handles Button29.Click
  68. ComboBox2下拉表單資料載入() : ComboBox1下拉表單資料載入()
  69. TextBox1.Text = "" : TextBox2.Text = ""
  70. Button29.Enabled = False : Button1.Enabled = True
  71. End Sub
  72. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  73. If TextBox1.Text = "" Or TextBox2.Text = "" Then
  74. MsgBox("部件大項資料沒有選擇或是部件名稱空白")
  75. Else
  76. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  77. SQL1 = "SELECT 部件 FROM 部件清單 WHERE 部件 LIKE N'" & TextBox1.Text & TextBox2.Text & "'"
  78. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  79. If dr.Read() Then
  80. MsgBox("資料重複,請從新輸入或檢查") : conn.Close() : dr.Close()
  81. Else
  82. conn.Close() : dr.Close()
  83. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  84. SQL1 = "INSERT INTO 部件清單 (部件, 貼標對應名稱) VALUES (N'" & TextBox1.Text & TextBox2.Text & "', N'" & ComboBox2.Text & "')"
  85. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  86. MsgBox("新增完成") : Set_清單()
  87. conn.Close() : dr.Close()
  88. Button29.Enabled = True : Button1.Enabled = False
  89. End If
  90. End If
  91. End Sub
  92. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  93. SQL1 = "DELETE FROM 部件清單 WHERE (部件 LIKE N'" & TextBox1.Text & TextBox2.Text & "')"
  94. cmd.CommandText = SQL1 : cmd.Connection = conn
  95. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  96. Dim aa As MsgBoxResult
  97. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  98. If aa = MsgBoxResult.Ok Then : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : MsgBox("刪除完成") : Set_清單() : End If
  99. conn.Close()
  100. End Sub
  101. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  102. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  103. 資料數 = DataGridView1.Rows.Count : MyModule1.進度條()
  104. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  105. SQL1 = "UPDATE 部件清單 SET 樣品單用選擇 = N'" & DataGridView1.Rows(i).Cells("樣品單用選擇").Value & "' WHERE (部件 LIKE N'" & DataGridView1.Rows(i).Cells("部件").Value & "')"
  106. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  107. Next i : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
  108. MsgBox("存檔完成")
  109. End Sub
  110. Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
  111. For i As Integer = 0 To DataGridView1.Rows.Count - 1 : DataGridView1.Rows(i).Cells("樣品單用選擇").Value = True : Next i
  112. End Sub
  113. Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
  114. For i As Integer = 0 To DataGridView1.Rows.Count - 1 : DataGridView1.Rows(i).Cells("樣品單用選擇").Value = False : Next i
  115. End Sub
  116. End Class