Option Strict Off Public Class 供應商資料 ReadOnly ds As New DataSet Private Sub 讀取供應商料表() DataGridView1.DataSource = Nothing : ds.Clear() DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView1.ColumnHeadersHeight = 25 DataGridView1.AllowUserToAddRows = False ConnOpen() SQL1 = "SELECT 流水碼, 供應商, 公司名, 公司地址, 公司電話1, 公司電話2, 公司電話3, 公司傳真1, 公司傳真2, 公司傳真3, 聯繫人1, 聯繫人2, 聯繫人3, " & "聯繫人1職稱, 聯繫人2職稱, 聯繫人3職稱, 聯繫人1電話, 聯繫人2電話, 聯繫人3電話 FROM 供應商資料表" CmdSet_For_DGV() : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() End Sub Private Sub Set_grid() DataGridView1.Columns(0).Width = 60 : DataGridView1.Columns(1).Width = 75 : DataGridView1.Columns(2).Width = 140 DataGridView1.Columns(3).Width = 200 : DataGridView1.Columns(4).Width = 90 : DataGridView1.Columns(5).Width = 90 DataGridView1.Columns(6).Width = 90 : DataGridView1.Columns(7).Width = 90 : DataGridView1.Columns(8).Width = 90 DataGridView1.Columns(9).Width = 90 DataGridView1.Columns(10).Width = 90 : DataGridView1.Columns(11).Width = 90 : DataGridView1.Columns(12).Width = 90 DataGridView1.Columns(13).Visible = False : DataGridView1.Columns(14).Visible = False : DataGridView1.Columns(15).Visible = False DataGridView1.Columns(16).Visible = False : DataGridView1.Columns(17).Visible = False : DataGridView1.Columns(18).Visible = False End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick If e.RowIndex = -1 Then : Else TextBox1.Text = DataGridView1(0, e.RowIndex).Value.ToString : TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString TextBox3.Text = DataGridView1(2, e.RowIndex).Value.ToString : TextBox4.Text = DataGridView1(3, e.RowIndex).Value.ToString TextBox5.Text = DataGridView1(4, e.RowIndex).Value.ToString : TextBox6.Text = DataGridView1(5, e.RowIndex).Value.ToString TextBox7.Text = DataGridView1(6, e.RowIndex).Value.ToString : TextBox8.Text = DataGridView1(7, e.RowIndex).Value.ToString TextBox9.Text = DataGridView1(8, e.RowIndex).Value.ToString : TextBox10.Text = DataGridView1(9, e.RowIndex).Value.ToString TextBox11.Text = DataGridView1(10, e.RowIndex).Value.ToString : TextBox12.Text = DataGridView1(11, e.RowIndex).Value.ToString TextBox13.Text = DataGridView1(12, e.RowIndex).Value.ToString : TextBox14.Text = DataGridView1(13, e.RowIndex).Value.ToString TextBox15.Text = DataGridView1(14, e.RowIndex).Value.ToString : TextBox16.Text = DataGridView1(15, e.RowIndex).Value.ToString TextBox17.Text = DataGridView1(16, e.RowIndex).Value.ToString : TextBox18.Text = DataGridView1(17, e.RowIndex).Value.ToString TextBox19.Text = DataGridView1(18, e.RowIndex).Value.ToString End If End Sub Private Sub 供應商資料_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.MdiParent = GCM_ERP_SYS Me.WindowState = 2 讀取供應商料表() : Set_grid() End Sub Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove timeNow = 0 GCM_ERP_SYS.Timer1.Enabled = False GCM_ERP_SYS.Timer1.Enabled = True End Sub Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress timeNow = 0 GCM_ERP_SYS.Timer1.Enabled = False GCM_ERP_SYS.Timer1.Enabled = True End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim a As String = InputBox("請輸入供應商名稱") : Dim b As String = InputBox("請輸入供應商公司名稱") : Dim c As String = InputBox("請輸入供應商地址") Dim d As String = InputBox("請輸入供應商公司電話1") : Dim f As String = InputBox("請輸入供應商公司電話2") : Dim g As String = InputBox("請輸入供應商公司電話3") Dim h As String = InputBox("請輸入供應商公司傳真1") : Dim i As String = InputBox("請輸入供應商公司傳真2") : Dim j As String = InputBox("請輸入供應商公司傳真3") Dim k As String = InputBox("請輸入供應商聯繫人1") : Dim n As String = InputBox("請輸入供應商聯繫人1職稱") : Dim q As String = InputBox("請輸入供應商聯繫人1電話") Dim l As String = InputBox("請輸入供應商聯繫人2") : Dim o As String = InputBox("請輸入供應商聯繫人2職稱") : Dim r As String = InputBox("請輸入供應商聯繫人2電話") Dim m As String = InputBox("請輸入供應商聯繫人3") : Dim p As String = InputBox("請輸入供應商聯繫人3職稱") : Dim s As String = InputBox("請輸入供應商聯繫人3電話") TextBox2.Text = a : TextBox3.Text = b : TextBox4.Text = c : TextBox5.Text = d : TextBox6.Text = f : TextBox7.Text = g : TextBox8.Text = h : TextBox9.Text = i TextBox10.Text = j : TextBox11.Text = k : TextBox12.Text = l : TextBox13.Text = m : TextBox14.Text = n : TextBox15.Text = o : TextBox16.Text = p TextBox17.Text = q : TextBox18.Text = r : TextBox19.Text = s If TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox5.Text = "" Then MsgBox("請供應商、公司銘及公司電話1不可為空白") Else Dim NUM1 As Integer For NUM1 = 0 To 9999 If NUM1 < 10 Then TextBox20.Text = "SU" & "00" & NUM1 ElseIf NUM1 > 9 And NUM1 < 100 Then TextBox20.Text = "SU" & "0" & NUM1 ElseIf NUM1 > 99 Then TextBox20.Text = "SU" & NUM1 End If ConnOpen() SQL1 = "SELECT 流水碼 FROM 供應商資料表 WHERE (流水碼 ='" & TextBox20.Text & "')" CmdSet_For_dr() If dr.Read() Then : TextBox1.Text = dr("流水碼").ToString : Else : TextBox1.Text = "" : End If conn.Close() If TextBox1.Text = "" Then TextBox1.Text = TextBox20.Text : TextBox20.Text = "可用" NUM1 = 9999 End If Next If TextBox20.Text = "可用" Then ConnOpen() SQL1 = "INSERT INTO 供應商資料表 (流水碼, 供應商, 公司名, 公司地址, 公司電話1, 公司電話2, 公司電話3, 公司傳真1, 公司傳真2, 公司傳真3, 聯繫人1, 聯繫人2, 聯繫人3, " & "聯繫人1職稱, 聯繫人2職稱, 聯繫人3職稱, 聯繫人1電話, 聯繫人2電話, 聯繫人3電話) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox11.Text & "','" & TextBox12.Text & "','" & TextBox13.Text & "','" & TextBox14.Text & "','" & TextBox15.Text & "','" & TextBox16.Text & "','" & TextBox17.Text & "','" & TextBox18.Text & "','" & TextBox19.Text & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() MsgBox("新增完成") conn.Close() End If End If TextBox20.Text = "" 讀取供應商料表() : Set_grid() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click ConnOpen() SQL1 = "UPDATE 供應商資料表 SET 供應商 = '" & TextBox2.Text & "', 公司名 = '" & TextBox3.Text & "', 公司地址 = '" & TextBox4.Text & "', 公司電話1 = '" & TextBox5.Text & "', 公司電話2 = '" & TextBox6.Text & "', 公司電話3 = '" & TextBox7.Text & "', 公司傳真1 = '" & TextBox8.Text & "', 公司傳真2 = '" & TextBox9.Text & "', 公司傳真3 = '" & TextBox10.Text & "', 聯繫人1 = '" & TextBox11.Text & "', 聯繫人2 = '" & TextBox12.Text & "', 聯繫人3 = '" & TextBox13.Text & "', 聯繫人1職稱 = '" & TextBox14.Text & "', 聯繫人2職稱 = '" & TextBox15.Text & "', 聯繫人3職稱 = '" & TextBox16.Text & "', 聯繫人1電話 = '" & TextBox17.Text & "', 聯繫人2電話 = '" & TextBox18.Text & "', 聯繫人3電話 = '" & TextBox19.Text & "' WHERE (流水碼 = '" & TextBox1.Text & "')" cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() MsgBox("修改完成") conn.Close() 讀取供應商料表() : Set_grid() End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click SQL1 = "DELETE FROM 供應商資料表 WHERE (流水碼 = '" & TextBox1.Text & "')" cmd.CommandText = SQL1 : cmd.Connection = conn ConnOpen() Dim aa As MsgBoxResult aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel) If aa = MsgBoxResult.Ok Then : cmd.ExecuteNonQuery() : MsgBox("刪除完成") : End If conn.Close() 讀取供應商料表() : Set_grid() End Sub End Class