説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

供應商管理(製鞋樣品).vb 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 供應商管理_製鞋樣品
  4. Dim conn As New SqlConnection
  5. Dim cmd As New SqlCommand
  6. Dim dr As SqlDataReader
  7. Dim da As New SqlDataAdapter
  8. Dim ds As New DataSet
  9. Dim DTP As String
  10. Private Sub 讀取供應商料表()
  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. If PA = "" Then
  17. SQL1 = "SELECT 供應商編碼, 廠商, 公司名, 公司地址, 公司電話1, 公司電話2, 公司電話3, 公司傳真1, 公司傳真2, 公司傳真3 AS 廠商類別, 聯繫人1, 聯繫人2, 聯繫人3, 聯繫人1職稱, " &
  18. "聯繫人2職稱, 聯繫人3職稱, 聯繫人1電話, 聯繫人2電話, 聯繫人3電話, 聯繫人1郵箱, 聯繫人2郵箱, 聯繫人3郵箱 FROM 供應商清單 ORDER BY 供應商編碼"
  19. Else
  20. SQL1 = "SELECT 供應商編碼, 廠商, 公司名, 公司地址, 公司電話1, 公司電話2, 公司電話3, 公司傳真1, 公司傳真2, 公司傳真3, 聯繫人1, 聯繫人2, 聯繫人3, 聯繫人1職稱, " &
  21. "聯繫人2職稱, 聯繫人3職稱, 聯繫人1電話, 聯繫人2電話, 聯繫人3電話, 聯繫人1郵箱, 聯繫人2郵箱, 聯繫人3郵箱 FROM 供應商清單 " &
  22. "WHERE 供應商編碼 LIKE N'%" & PA & "%' OR 廠商 LIKE N'%" & PA & "%' OR 公司名 LIKE N'%" & PA & "%' OR 公司地址 LIKE N'%" & PA & "%' OR " &
  23. "聯繫人1 LIKE N'%" & PA & "%' OR 聯繫人2 LIKE N'%" & PA & "%' OR 聯繫人3 LIKE N'%" & PA & "%' ORDER BY 供應商編碼"
  24. End If
  25. 列印用SQL = SQL1
  26. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  27. End Sub
  28. Private Sub Set_grid()
  29. DataGridView1.Columns(0).Width = 80 : DataGridView1.Columns(1).Width = 90 : DataGridView1.Columns(2).Width = 200
  30. DataGridView1.Columns(3).Width = 400 : DataGridView1.Columns(4).Width = 120 : DataGridView1.Columns(5).Width = 120
  31. DataGridView1.Columns(6).Width = 120 : DataGridView1.Columns(7).Width = 120 : DataGridView1.Columns(8).Width = 120
  32. DataGridView1.Columns(9).Width = 120 : DataGridView1.Columns(10).Width = 120 : DataGridView1.Columns(11).Width = 120
  33. DataGridView1.Columns(12).Width = 120
  34. DataGridView1.Columns(13).Visible = False : DataGridView1.Columns(14).Visible = False : DataGridView1.Columns(15).Visible = False
  35. DataGridView1.Columns(16).Visible = False : DataGridView1.Columns(17).Visible = False : DataGridView1.Columns(18).Visible = False
  36. DataGridView1.Columns(19).Visible = False : DataGridView1.Columns(20).Visible = False : DataGridView1.Columns(21).Visible = False
  37. End Sub
  38. Private Sub 格式設定1()
  39. TextBox1.Enabled = False : Button5.Enabled = False : Button1.Enabled = True : Button7.Enabled = True : Button2.Enabled = False : Button3.Enabled = True
  40. Label2.ForeColor = Color.Black : Label3.ForeColor = Color.Black : Label4.ForeColor = Color.Black : Label5.ForeColor = Color.Black : Label8.ForeColor = Color.Black
  41. End Sub
  42. Private Sub 格式設定2()
  43. Label2.ForeColor = Color.Red : Label3.ForeColor = Color.Red : Label4.ForeColor = Color.Red : Label5.ForeColor = Color.Red : Label8.ForeColor = Color.Red
  44. End Sub
  45. Private Sub Set_日期格式轉換()
  46. DTP = Format(Today(), "yyyy/MM/dd") & "-" & Format(TimeOfDay(), "HH:mm:ss")
  47. End Sub
  48. Private Sub ComboBox1下拉表單資料載入()
  49. conn.Close()
  50. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  51. SQL1 = "SELECT 廠商類別 FROM 廠商類別 ORDER BY 廠商類別"
  52. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
  53. ComboBox1.Items.Clear()
  54. While (dr.Read()) : ComboBox1.Items.Add(dr("廠商類別")) : End While : conn.Close()
  55. End Sub
  56. Private Sub 供應商管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  57. Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  58. ComboBox1下拉表單資料載入() : 格式設定1() : 讀取供應商料表() : Set_grid()
  59. TextBox2.Enabled = False : TextBox3.Enabled = False : TextBox4.Enabled = False : TextBox5.Enabled = False : TextBox6.Enabled = False : TextBox7.Enabled = False : TextBox8.Enabled = False
  60. TextBox9.Enabled = False : ComboBox1.Enabled = False : TextBox11.Enabled = False : TextBox12.Enabled = False : TextBox13.Enabled = False : TextBox14.Enabled = False : TextBox15.Enabled = False
  61. TextBox16.Enabled = False : TextBox17.Enabled = False : TextBox18.Enabled = False : TextBox19.Enabled = False : TextBox21.Enabled = False : TextBox22.Enabled = False : TextBox23.Enabled = False
  62. End Sub
  63. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  64. If e.RowIndex = -1 Then : Else
  65. TextBox1.Text = DataGridView1(0, e.RowIndex).Value.ToString : TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString
  66. TextBox3.Text = DataGridView1(2, e.RowIndex).Value.ToString : TextBox4.Text = DataGridView1(3, e.RowIndex).Value.ToString
  67. TextBox5.Text = DataGridView1(4, e.RowIndex).Value.ToString : TextBox6.Text = DataGridView1(5, e.RowIndex).Value.ToString
  68. TextBox7.Text = DataGridView1(6, e.RowIndex).Value.ToString : TextBox8.Text = DataGridView1(7, e.RowIndex).Value.ToString
  69. TextBox9.Text = DataGridView1(8, e.RowIndex).Value.ToString : ComboBox1.Text = DataGridView1(9, e.RowIndex).Value.ToString
  70. TextBox11.Text = DataGridView1(10, e.RowIndex).Value.ToString : TextBox12.Text = DataGridView1(11, e.RowIndex).Value.ToString
  71. TextBox13.Text = DataGridView1(12, e.RowIndex).Value.ToString : TextBox14.Text = DataGridView1(13, e.RowIndex).Value.ToString
  72. TextBox15.Text = DataGridView1(14, e.RowIndex).Value.ToString : TextBox16.Text = DataGridView1(15, e.RowIndex).Value.ToString
  73. TextBox17.Text = DataGridView1(16, e.RowIndex).Value.ToString : TextBox18.Text = DataGridView1(17, e.RowIndex).Value.ToString
  74. TextBox19.Text = DataGridView1(18, e.RowIndex).Value.ToString : TextBox21.Text = DataGridView1(19, e.RowIndex).Value.ToString
  75. TextBox22.Text = DataGridView1(20, e.RowIndex).Value.ToString : TextBox23.Text = DataGridView1(21, e.RowIndex).Value.ToString
  76. End If
  77. End Sub
  78. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  79. TextBox2.Text = "" : TextBox3.Text = "" : TextBox4.Text = "" : TextBox5.Text = "" : TextBox6.Text = "" : TextBox7.Text = "" : TextBox8.Text = "" : TextBox9.Text = "" : ComboBox1.Text = ""
  80. TextBox11.Text = "" : TextBox12.Text = "" : TextBox13.Text = "" : TextBox14.Text = "" : TextBox15.Text = "" : TextBox16.Text = "" : TextBox17.Text = "" : TextBox18.Text = ""
  81. TextBox19.Text = "" : TextBox21.Text = "" : TextBox22.Text = "" : TextBox23.Text = ""
  82. TextBox2.Enabled = True : TextBox3.Enabled = True : TextBox4.Enabled = True : TextBox5.Enabled = True : TextBox6.Enabled = True : TextBox7.Enabled = True : TextBox8.Enabled = True
  83. TextBox9.Enabled = True : ComboBox1.Enabled = True : TextBox11.Enabled = True : TextBox12.Enabled = True : TextBox13.Enabled = True : TextBox14.Enabled = True : TextBox15.Enabled = True
  84. TextBox16.Enabled = True : TextBox17.Enabled = True : TextBox18.Enabled = True : TextBox19.Enabled = True : TextBox21.Enabled = True : TextBox22.Enabled = True : TextBox23.Enabled = True
  85. DataGridView1.Enabled = False
  86. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  87. SQL1 = "SELECT TOP (1) 供應商編碼 FROM 供應商清單 ORDER BY 供應商編碼 DESC"
  88. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  89. If dr.Read() Then : TextBox1.Text = dr("供應商編碼").ToString : Else : TextBox1.Text = "" : End If
  90. conn.Close()
  91. Dim NUM1 As Integer
  92. NUM1 = Double.Parse(Strings.Right(TextBox1.Text, 4)) + 1
  93. If NUM1 < 10 Then : TextBox1.Text = "SU" & "000" & NUM1
  94. ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox1.Text = "SU" & "00" & NUM1
  95. ElseIf NUM1 > 99 And NUM1 < 1000 Then : TextBox1.Text = "SU" & "0" & NUM1
  96. ElseIf NUM1 > 999 Then : TextBox1.Text = "SU" & NUM1
  97. End If
  98. 格式設定2()
  99. Button5.Enabled = True : Button1.Enabled = False : Button7.Enabled = False : Button2.Enabled = False : Button3.Enabled = False
  100. End Sub
  101. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  102. If TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox8.Text = "" Then
  103. MsgBox("紅色字體處為必填項,不可空白")
  104. Else
  105. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  106. SQL1 = "INSERT INTO 供應商清單 (供應商編碼, 廠商, 公司名, 公司地址, 公司電話1, 公司電話2, 公司電話3, 公司傳真1, 公司傳真2, 公司傳真3, 聯繫人1, 聯繫人2, 聯繫人3, " &
  107. "聯繫人1職稱, 聯繫人2職稱, 聯繫人3職稱, 聯繫人1電話, 聯繫人2電話, 聯繫人3電話, 聯繫人1郵箱, 聯繫人2郵箱, 聯繫人3郵箱) VALUES (N'" & TextBox1.Text & "',N'" & TextBox2.Text &
  108. "',N'" & TextBox3.Text & "',N'" & TextBox4.Text & "',N'" & TextBox5.Text & "',N'" & TextBox6.Text & "',N'" & TextBox7.Text & "',N'" & TextBox8.Text &
  109. "',N'" & TextBox9.Text & "',N'" & ComboBox1.Text & "',N'" & TextBox11.Text & "',N'" & TextBox12.Text & "',N'" & TextBox13.Text & "',N'" & TextBox14.Text &
  110. "',N'" & TextBox15.Text & "',N'" & TextBox16.Text & "',N'" & TextBox17.Text & "',N'" & TextBox18.Text & "',N'" & TextBox19.Text & "',N'" & TextBox21.Text &
  111. "',N'" & TextBox22.Text & "',N'" & TextBox23.Text & "')"
  112. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  113. conn.Close()
  114. MsgBox("新增完成")
  115. 格式設定1()
  116. 讀取供應商料表() : Set_grid()
  117. TextBox2.Enabled = False : TextBox3.Enabled = False : TextBox4.Enabled = False : TextBox5.Enabled = False : TextBox6.Enabled = False : TextBox7.Enabled = False : TextBox8.Enabled = False
  118. TextBox9.Enabled = False : ComboBox1.Enabled = False : TextBox11.Enabled = False : TextBox12.Enabled = False : TextBox13.Enabled = False : TextBox14.Enabled = False : TextBox15.Enabled = False
  119. TextBox16.Enabled = False : TextBox17.Enabled = False : TextBox18.Enabled = False : TextBox19.Enabled = False : TextBox21.Enabled = False : TextBox22.Enabled = False : TextBox23.Enabled = False
  120. DataGridView1.Enabled = True
  121. End If
  122. End Sub
  123. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  124. If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  125. SQL1 = "UPDATE 供應商清單 SET 廠商 = N'" & TextBox2.Text & "', 公司名 = N'" & TextBox3.Text & "', 公司地址 = N'" & TextBox4.Text &
  126. "', 公司電話1 = N'" & TextBox5.Text & "', 公司電話2 = N'" & TextBox6.Text & "', 公司電話3 = N'" & TextBox7.Text & "', 公司傳真1 = N'" & TextBox8.Text &
  127. "', 公司傳真2 = N'" & TextBox9.Text & "', 公司傳真3 = N'" & ComboBox1.Text & "', 聯繫人1 = N'" & TextBox11.Text & "', 聯繫人2 = N'" & TextBox12.Text &
  128. "', 聯繫人3 = N'" & TextBox13.Text & "', 聯繫人1職稱 = N'" & TextBox14.Text & "', 聯繫人2職稱 = N'" & TextBox15.Text & "', 聯繫人3職稱 = N'" & TextBox16.Text &
  129. "', 聯繫人1電話 = N'" & TextBox17.Text & "', 聯繫人2電話 = N'" & TextBox18.Text & "', 聯繫人3電話 = N'" & TextBox19.Text & "', 聯繫人1郵箱 = N'" & TextBox21.Text &
  130. "', 聯繫人2郵箱 = N'" & TextBox22.Text & "', 聯繫人3郵箱 = N'" & TextBox23.Text & "' WHERE (供應商編碼 = '" & TextBox1.Text & "')"
  131. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  132. conn.Close()
  133. Set_日期格式轉換() : 格式設定1()
  134. MsgBox("修改完成")
  135. 讀取供應商料表() : Set_grid()
  136. TextBox2.Enabled = False : TextBox3.Enabled = False : TextBox4.Enabled = False : TextBox5.Enabled = False : TextBox6.Enabled = False : TextBox7.Enabled = False : TextBox8.Enabled = False
  137. TextBox9.Enabled = False : ComboBox1.Enabled = False : TextBox11.Enabled = False : TextBox12.Enabled = False : TextBox13.Enabled = False : TextBox14.Enabled = False : TextBox15.Enabled = False
  138. TextBox16.Enabled = False : TextBox17.Enabled = False : TextBox18.Enabled = False : TextBox19.Enabled = False : TextBox21.Enabled = False : TextBox22.Enabled = False : TextBox23.Enabled = False
  139. End Sub
  140. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  141. SQL1 = "DELETE FROM 供應商清單 WHERE (供應商編碼 = '" & TextBox1.Text & "')"
  142. cmd.CommandText = SQL1 : cmd.Connection = conn
  143. If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  144. Dim aa As MsgBoxResult
  145. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  146. If aa = MsgBoxResult.Ok Then
  147. cmd.ExecuteNonQuery() : conn.Close()
  148. Set_日期格式轉換()
  149. MsgBox("刪除完成")
  150. 讀取供應商料表() : Set_grid()
  151. End If
  152. End Sub
  153. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  154. PA = InputBox("請輸入要查詢的供應商資料") : 讀取供應商料表() : Set_grid() : PA = ""
  155. End Sub
  156. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  157. 列印_供應商資料表.Show()
  158. End Sub
  159. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  160. Button5.Enabled = False : Button1.Enabled = False : Button7.Enabled = False : Button2.Enabled = True : Button3.Enabled = False
  161. TextBox2.Enabled = True : TextBox3.Enabled = True : TextBox4.Enabled = True : TextBox5.Enabled = True : TextBox6.Enabled = True : TextBox7.Enabled = True : TextBox8.Enabled = True
  162. TextBox9.Enabled = True : ComboBox1.Enabled = True : TextBox11.Enabled = True : TextBox12.Enabled = True : TextBox13.Enabled = True : TextBox14.Enabled = True : TextBox15.Enabled = True
  163. TextBox16.Enabled = True : TextBox17.Enabled = True : TextBox18.Enabled = True : TextBox19.Enabled = True : TextBox21.Enabled = True : TextBox22.Enabled = True : TextBox23.Enabled = True
  164. End Sub
  165. End Class