Ingen beskrivning
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.

FACTORY_資料管理.vb 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class FACTORY_資料管理
  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
  8. Dim dr As SqlDataReader
  9. Dim OO As Boolean
  10. Private Sub Set_DGV1載入前設定()
  11. DataGridView1.DataSource = Nothing : ds.Clear()
  12. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  13. DataGridView1.ColumnHeadersHeight = 25
  14. DataGridView1.AllowUserToAddRows = False
  15. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  16. End Sub
  17. Private Sub Set_DGV1載入後設定()
  18. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  19. End Sub
  20. Private Sub Set_FACTORY清單()
  21. Set_DGV1載入前設定()
  22. SQL1 = "SELECT 工廠 AS Factory_Code, 供應商資料 AS Vendor_Name, 供應商地址 AS Ship_From_Name_Ship_From_Address FROM 工廠控制表"
  23. Set_DGV1載入後設定()
  24. End Sub
  25. Private Sub Set_grid1()
  26. DataGridView1.Columns(0).Width = 125 : DataGridView1.Columns(1).Width = 300 : DataGridView1.Columns(2).Width = 885
  27. End Sub
  28. Private Sub FACTORY_資料管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  29. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
  30. Set_FACTORY清單() : Set_grid1()
  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 : TextBox3.Text = DataGridView1(1, e.RowIndex).Value.ToString
  35. TextBox2.Text = DataGridView1(2, e.RowIndex).Value.ToString
  36. End If
  37. End Sub
  38. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  39. Me.Close()
  40. End Sub
  41. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  42. If TextBox1.Text <> "" Then
  43. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  44. SQL1 = "SELECT 工廠 FROM 工廠控制表 WHERE 工廠 LIKE '" & TextBox1.Text & "'"
  45. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  46. If dr.Read() Then
  47. OO = True : MsgBox("資料重複") : conn.Close() : Exit Sub
  48. Else
  49. OO = False
  50. End If : conn.Close()
  51. If OO = False Then
  52. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  53. SQL1 = "INSERT INTO 工廠控制表 (工廠, 供應商資料, 供應商地址) VALUES ('" & TextBox1.Text & "', '" & TextBox3.Text & "', '" & TextBox2.Text & "')"
  54. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  55. End If
  56. Set_FACTORY清單() : Set_grid1()
  57. MsgBox("新增完成")
  58. Else
  59. MsgBox("Key index 不可空白")
  60. End If
  61. End Sub
  62. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  63. If TextBox1.Text <> "" Then
  64. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  65. SQL1 = "UPDATE 工廠控制表 SET 供應商資料 = '" & TextBox3.Text & "', 供應商地址 = '" & TextBox2.Text & "' WHERE (工廠 = '" & TextBox1.Text & "')"
  66. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  67. Set_FACTORY清單() : Set_grid1()
  68. MsgBox("修改完成")
  69. Else
  70. MsgBox("Key index 不可空白")
  71. End If
  72. End Sub
  73. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  74. Dim aa As MsgBoxResult
  75. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  76. If aa = MsgBoxResult.Ok Then
  77. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  78. SQL1 = "DELETE FROM 工廠控制表 WHERE (工廠 = '" & TextBox1.Text & "')"
  79. cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : conn.Close()
  80. Set_FACTORY清單() : Set_grid1()
  81. MsgBox("刪除完成")
  82. End If
  83. End Sub
  84. End Class