Nessuna descrizione
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 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 供應商資料
  4. Dim conn1 As New SqlConnection
  5. Dim cmd1 As New SqlCommand
  6. Dim dr1 As SqlDataReader
  7. Dim da As New SqlDataAdapter
  8. Dim ds As New DataSet
  9. Private Sub 讀取供應商料表()
  10. DataGridView1.DataSource = Nothing : ds.Clear()
  11. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  12. DataGridView1.ColumnHeadersHeight = 25
  13. DataGridView1.AllowUserToAddRows = False
  14. If conn1.State = ConnectionState.Closed Then : conn1.ConnectionString = ConString : conn1.Open() : End If
  15. SQL1 = "SELECT 流水碼, 供應商, 公司名, 公司地址, 公司電話1, 公司電話2, 公司電話3, 公司傳真1, 公司傳真2, 公司傳真3, 聯繫人1, 聯繫人2, 聯繫人3, " &
  16. "聯繫人1職稱, 聯繫人2職稱, 聯繫人3職稱, 聯繫人1電話, 聯繫人2電話, 聯繫人3電話 FROM 供應商資料表"
  17. cmd1.Connection = conn1 : cmd1.CommandText = SQL1 : da.SelectCommand = cmd1 : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn1.Close()
  18. End Sub
  19. Private Sub Set_grid()
  20. DataGridView1.Columns(0).Width = 60 : DataGridView1.Columns(1).Width = 75 : DataGridView1.Columns(2).Width = 140
  21. DataGridView1.Columns(3).Width = 200 : DataGridView1.Columns(4).Width = 90 : DataGridView1.Columns(5).Width = 90
  22. DataGridView1.Columns(6).Width = 90 : DataGridView1.Columns(7).Width = 90 : DataGridView1.Columns(8).Width = 90
  23. DataGridView1.Columns(9).Width = 90
  24. DataGridView1.Columns(10).Width = 90 : DataGridView1.Columns(11).Width = 90 : DataGridView1.Columns(12).Width = 90
  25. DataGridView1.Columns(13).Visible = False : DataGridView1.Columns(14).Visible = False : DataGridView1.Columns(15).Visible = False
  26. DataGridView1.Columns(16).Visible = False : DataGridView1.Columns(17).Visible = False : DataGridView1.Columns(18).Visible = False
  27. End Sub
  28. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  29. If e.RowIndex = -1 Then : Else
  30. TextBox1.Text = DataGridView1(0, e.RowIndex).Value.ToString : TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString
  31. TextBox3.Text = DataGridView1(2, e.RowIndex).Value.ToString : TextBox4.Text = DataGridView1(3, e.RowIndex).Value.ToString
  32. TextBox5.Text = DataGridView1(4, e.RowIndex).Value.ToString : TextBox6.Text = DataGridView1(5, e.RowIndex).Value.ToString
  33. TextBox7.Text = DataGridView1(6, e.RowIndex).Value.ToString : TextBox8.Text = DataGridView1(7, e.RowIndex).Value.ToString
  34. TextBox9.Text = DataGridView1(8, e.RowIndex).Value.ToString : TextBox10.Text = DataGridView1(9, e.RowIndex).Value.ToString
  35. TextBox11.Text = DataGridView1(10, e.RowIndex).Value.ToString : TextBox12.Text = DataGridView1(11, e.RowIndex).Value.ToString
  36. TextBox13.Text = DataGridView1(12, e.RowIndex).Value.ToString : TextBox14.Text = DataGridView1(13, e.RowIndex).Value.ToString
  37. TextBox15.Text = DataGridView1(14, e.RowIndex).Value.ToString : TextBox16.Text = DataGridView1(15, e.RowIndex).Value.ToString
  38. TextBox17.Text = DataGridView1(16, e.RowIndex).Value.ToString : TextBox18.Text = DataGridView1(17, e.RowIndex).Value.ToString
  39. TextBox19.Text = DataGridView1(18, e.RowIndex).Value.ToString
  40. End If
  41. End Sub
  42. Private Sub 供應商資料_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  43. Me.MdiParent = GCM_ERP_SYS
  44. Me.WindowState = 2
  45. 讀取供應商料表() : Set_grid()
  46. End Sub
  47. Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
  48. timeNow = 0
  49. GCM_ERP_SYS.Timer1.Enabled = False
  50. GCM_ERP_SYS.Timer1.Enabled = True
  51. End Sub
  52. Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
  53. timeNow = 0
  54. GCM_ERP_SYS.Timer1.Enabled = False
  55. GCM_ERP_SYS.Timer1.Enabled = True
  56. End Sub
  57. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  58. Dim a As String = InputBox("請輸入供應商名稱") : Dim b As String = InputBox("請輸入供應商公司名稱") : Dim c As String = InputBox("請輸入供應商地址")
  59. Dim d As String = InputBox("請輸入供應商公司電話1") : Dim f As String = InputBox("請輸入供應商公司電話2") : Dim g As String = InputBox("請輸入供應商公司電話3")
  60. Dim h As String = InputBox("請輸入供應商公司傳真1") : Dim i As String = InputBox("請輸入供應商公司傳真2") : Dim j As String = InputBox("請輸入供應商公司傳真3")
  61. Dim k As String = InputBox("請輸入供應商聯繫人1") : Dim n As String = InputBox("請輸入供應商聯繫人1職稱") : Dim q As String = InputBox("請輸入供應商聯繫人1電話")
  62. Dim l As String = InputBox("請輸入供應商聯繫人2") : Dim o As String = InputBox("請輸入供應商聯繫人2職稱") : Dim r As String = InputBox("請輸入供應商聯繫人2電話")
  63. Dim m As String = InputBox("請輸入供應商聯繫人3") : Dim p As String = InputBox("請輸入供應商聯繫人3職稱") : Dim s As String = InputBox("請輸入供應商聯繫人3電話")
  64. TextBox2.Text = a : TextBox3.Text = b : TextBox4.Text = c : TextBox5.Text = d : TextBox6.Text = f : TextBox7.Text = g : TextBox8.Text = h : TextBox9.Text = i
  65. TextBox10.Text = j : TextBox11.Text = k : TextBox12.Text = l : TextBox13.Text = m : TextBox14.Text = n : TextBox15.Text = o : TextBox16.Text = p
  66. TextBox17.Text = q : TextBox18.Text = r : TextBox19.Text = s
  67. If TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox5.Text = "" Then
  68. MsgBox("請供應商、公司銘及公司電話1不可為空白")
  69. Else
  70. Dim NUM1 As Integer
  71. For NUM1 = 0 To 9999
  72. If NUM1 < 10 Then
  73. TextBox20.Text = "SU" & "00" & NUM1
  74. ElseIf NUM1 > 9 And NUM1 < 100 Then
  75. TextBox20.Text = "SU" & "0" & NUM1
  76. ElseIf NUM1 > 99 Then
  77. TextBox20.Text = "SU" & NUM1
  78. End If
  79. If conn1.State = ConnectionState.Closed Then : conn1.ConnectionString = ConString : conn1.Open() : End If
  80. SQL1 = "SELECT 流水碼 FROM 供應商資料表 WHERE (流水碼 ='" & TextBox20.Text & "')"
  81. cmd1.Connection = conn1 : cmd1.CommandText = SQL1 : dr1 = cmd1.ExecuteReader
  82. If dr1.Read() Then : TextBox1.Text = dr1("流水碼").ToString : Else : TextBox1.Text = "" : End If
  83. conn1.Close()
  84. If TextBox1.Text = "" Then
  85. TextBox1.Text = TextBox20.Text : TextBox20.Text = "可用"
  86. NUM1 = 9999
  87. End If
  88. Next
  89. If TextBox20.Text = "可用" Then
  90. If conn1.State = ConnectionState.Closed Then : conn1.ConnectionString = ConString : conn1.Open() : End If
  91. SQL1 = "INSERT INTO 供應商資料表 (流水碼, 供應商, 公司名, 公司地址, 公司電話1, 公司電話2, 公司電話3, 公司傳真1, 公司傳真2, 公司傳真3, 聯繫人1, 聯繫人2, 聯繫人3, " &
  92. "聯繫人1職稱, 聯繫人2職稱, 聯繫人3職稱, 聯繫人1電話, 聯繫人2電話, 聯繫人3電話) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text &
  93. "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text &
  94. "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox11.Text & "','" & TextBox12.Text & "','" & TextBox13.Text & "','" & TextBox14.Text &
  95. "','" & TextBox15.Text & "','" & TextBox16.Text & "','" & TextBox17.Text & "','" & TextBox18.Text & "','" & TextBox19.Text & "')"
  96. cmd1.Connection = conn1 : cmd1.CommandText = SQL1 : cmd1.ExecuteNonQuery()
  97. MsgBox("新增完成")
  98. conn1.Close()
  99. End If
  100. End If
  101. TextBox20.Text = ""
  102. 讀取供應商料表() : Set_grid()
  103. End Sub
  104. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  105. If conn1.State = ConnectionState.Closed Then : conn1.Open() : End If
  106. SQL1 = "UPDATE 供應商資料表 SET 供應商 = '" & TextBox2.Text & "', 公司名 = '" & TextBox3.Text & "', 公司地址 = '" & TextBox4.Text &
  107. "', 公司電話1 = '" & TextBox5.Text & "', 公司電話2 = '" & TextBox6.Text & "', 公司電話3 = '" & TextBox7.Text & "', 公司傳真1 = '" & TextBox8.Text &
  108. "', 公司傳真2 = '" & TextBox9.Text & "', 公司傳真3 = '" & TextBox10.Text & "', 聯繫人1 = '" & TextBox11.Text & "', 聯繫人2 = '" & TextBox12.Text &
  109. "', 聯繫人3 = '" & TextBox13.Text & "', 聯繫人1職稱 = '" & TextBox14.Text & "', 聯繫人2職稱 = '" & TextBox15.Text & "', 聯繫人3職稱 = '" & TextBox16.Text &
  110. "', 聯繫人1電話 = '" & TextBox17.Text & "', 聯繫人2電話 = '" & TextBox18.Text & "', 聯繫人3電話 = '" & TextBox19.Text &
  111. "' WHERE (流水碼 = '" & TextBox1.Text & "')"
  112. cmd1.CommandText = SQL1 : cmd1.ExecuteNonQuery()
  113. MsgBox("修改完成")
  114. conn1.Close()
  115. 讀取供應商料表() : Set_grid()
  116. End Sub
  117. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  118. SQL1 = "DELETE FROM 供應商資料表 WHERE (流水碼 = '" & TextBox1.Text & "')"
  119. cmd1.CommandText = SQL1 : cmd1.Connection = conn1
  120. If conn1.State = ConnectionState.Closed Then : conn1.Open() : End If
  121. Dim aa As MsgBoxResult
  122. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  123. If aa = MsgBoxResult.Ok Then : cmd1.ExecuteNonQuery() : MsgBox("刪除完成") : End If
  124. conn1.Close()
  125. 讀取供應商料表() : Set_grid()
  126. End Sub
  127. End Class