Sin descripción
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 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 訂單管理控制表
  4. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet
  5. Dim EDR As Integer = 0 : Dim ESTR As String
  6. Dim 狀態 As String : Dim GGHH As String : Dim HHJJ As String : Dim 申請數量 As Integer
  7. Private Sub Set_清單()
  8. DataGridView1.DataSource = Nothing : ds.Clear() : DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView1.ColumnHeadersHeight = 50
  9. DataGridView1.AllowUserToAddRows = False : DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView1.MultiSelect = True
  10. SQL_訂單管理控制表庫存()
  11. da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  12. DataGridView1.Columns(0).FillWeight = 115 : DataGridView1.Columns(1).Visible = False : DataGridView1.Columns(2).Visible = False : DataGridView1.Columns(3).FillWeight = 330
  13. DataGridView1.Columns(4).Visible = False : DataGridView1.Columns(5).Visible = False : DataGridView1.Columns(6).Visible = False : DataGridView1.Columns(7).FillWeight = 70
  14. DataGridView1.Columns(8).Visible = False : DataGridView1.Columns(9).FillWeight = 70 : DataGridView1.Columns(10).Visible = False : DataGridView1.Columns(11).FillWeight = 70
  15. DataGridView1.Columns(12).Visible = False : DataGridView1.Columns(13).FillWeight = 70 : DataGridView1.Columns(14).Visible = False : DataGridView1.Columns(15).Visible = False
  16. DataGridView1.Columns(6).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(7).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(8).DefaultCellStyle.Format = "#,##0"
  17. DataGridView1.Columns(9).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(10).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(11).DefaultCellStyle.Format = "#,##0"
  18. DataGridView1.Columns(12).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(13).DefaultCellStyle.Format = "#,##0"
  19. DataGridView1.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  20. DataGridView1.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  21. DataGridView1.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  22. DataGridView1.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  23. DataGridView1.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  24. DataGridView1.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  25. DataGridView1.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(11).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  26. DataGridView1.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(12).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  27. DataGridView1.Columns(13).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(13).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  28. DataGridView1.Columns(0).ReadOnly = True : DataGridView1.Columns(3).ReadOnly = True : DataGridView1.Columns(4).ReadOnly = True : DataGridView1.Columns(5).ReadOnly = True
  29. DataGridView1.Columns(6).ReadOnly = True : DataGridView1.Columns(7).ReadOnly = True : DataGridView1.Columns(8).ReadOnly = True : DataGridView1.Columns(9).ReadOnly = True
  30. DataGridView1.Columns(10).ReadOnly = True : DataGridView1.Columns(11).ReadOnly = True : DataGridView1.Columns(12).ReadOnly = True : DataGridView1.Columns(13).ReadOnly = True
  31. DataGridView1.Columns(7).DefaultCellStyle.BackColor = Color.MistyRose : DataGridView1.Columns(8).DefaultCellStyle.BackColor = Color.MistyRose
  32. DataGridView1.Columns(9).DefaultCellStyle.BackColor = Color.LightYellow : DataGridView1.Columns(10).DefaultCellStyle.BackColor = Color.LightYellow
  33. DataGridView1.Columns(11).DefaultCellStyle.BackColor = Color.LightGreen : DataGridView1.Columns(12).DefaultCellStyle.BackColor = Color.LightGreen
  34. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  35. If DataGridView1.Rows(i).Cells("庫存").Value.ToString = "" Then : DataGridView1.Rows(i).Cells("庫存").Value = 0 : End If
  36. If DataGridView1.Rows(i).Cells("未入庫").Value.ToString = "" Then : DataGridView1.Rows(i).Cells("未入庫").Value = 0 : End If
  37. If DataGridView1.Rows(i).Cells("在途成本_台幣").Value.ToString = "" Then : DataGridView1.Rows(i).Cells("在途成本_台幣").Value = 0 : End If
  38. If DataGridView1.Rows(i).Cells("未出庫").Value.ToString = "" Then : DataGridView1.Rows(i).Cells("未出庫").Value = 0 : End If
  39. If DataGridView1.Rows(i).Cells("備貨成本_台幣").Value.ToString = "" Then : DataGridView1.Rows(i).Cells("備貨成本_台幣").Value = 0 : End If
  40. DataGridView1.Rows(i).Cells("可領用").Value = DataGridView1.Rows(i).Cells("庫存").Value - DataGridView1.Rows(i).Cells("未出庫").Value
  41. Next
  42. End Sub
  43. Private Sub Set_訂單控制表()
  44. DataGridView3.DataSource = Nothing : ds2.Clear() : DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView3.ColumnHeadersHeight = 25
  45. DataGridView3.AllowUserToAddRows = False : DataGridView3.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView3.MultiSelect = True
  46. SQL_訂單管理控制表控制表()
  47. da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close()
  48. DataGridView3.Columns(0).FillWeight = 80 : DataGridView3.Columns(1).FillWeight = 80 : DataGridView3.Columns(2).Visible = False : DataGridView3.Columns(3).FillWeight = 80
  49. DataGridView3.Columns(4).FillWeight = 80 : DataGridView3.Columns(5).FillWeight = 80 : DataGridView3.Columns(6).FillWeight = 80 : DataGridView3.Columns(7).FillWeight = 80
  50. DataGridView3.Columns(8).Visible = False
  51. DataGridView3.Columns(0).ReadOnly = True : DataGridView3.Columns(1).ReadOnly = True : DataGridView3.Columns(2).ReadOnly = True : DataGridView3.Columns(3).ReadOnly = True
  52. DataGridView3.Columns(4).ReadOnly = True : DataGridView3.Columns(5).ReadOnly = True : DataGridView3.Columns(6).ReadOnly = True : DataGridView3.Columns(7).ReadOnly = True
  53. DataGridView3.Columns(8).ReadOnly = True
  54. End Sub
  55. Private Sub Set_訂單明細表()
  56. DataGridView2.DataSource = Nothing : ds1.Clear() : DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView2.ColumnHeadersHeight = 25
  57. DataGridView2.AllowUserToAddRows = False : DataGridView2.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView2.MultiSelect = True
  58. SQL_訂單管理控制表控明細()
  59. da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close()
  60. DataGridView2.Columns(0).Visible = False : DataGridView2.Columns(1).Visible = False : DataGridView2.Columns(2).Visible = False : DataGridView2.Columns(3).FillWeight = 100
  61. DataGridView2.Columns(4).Visible = False : DataGridView2.Columns(5).Visible = False : DataGridView2.Columns(6).FillWeight = 30 : DataGridView2.Columns(7).FillWeight = 65
  62. DataGridView2.Columns(8).FillWeight = 65 : DataGridView2.Columns(9).FillWeight = 65 : DataGridView2.Columns(10).FillWeight = 25 : DataGridView2.Columns(11).FillWeight = 60
  63. DataGridView2.Columns(6).DefaultCellStyle.Format = "#,##0"
  64. DataGridView2.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  65. DataGridView2.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  66. DataGridView2.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  67. DataGridView2.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  68. DataGridView2.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView2.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  69. DataGridView2.Columns(0).ReadOnly = True : DataGridView2.Columns(1).ReadOnly = True : DataGridView2.Columns(2).ReadOnly = True : DataGridView2.Columns(3).ReadOnly = True
  70. DataGridView2.Columns(4).ReadOnly = True : DataGridView2.Columns(5).ReadOnly = True : DataGridView2.Columns(6).ReadOnly = True : DataGridView2.Columns(7).ReadOnly = True
  71. DataGridView2.Columns(8).ReadOnly = True : DataGridView2.Columns(9).ReadOnly = True : DataGridView2.Columns(10).ReadOnly = True : DataGridView2.Columns(11).ReadOnly = True
  72. End Sub
  73. Private Sub ComboBox1下拉表單資料載入()
  74. SQL_物料頁碼清單()
  75. ComboBox1.Items.Clear() : While (dr.Read()) : ComboBox1.Items.Add(dr("頁碼")) : End While : conn.Close()
  76. End Sub
  77. Private Sub ComboBox2下拉表單資料載入()
  78. SQL_客戶資料表_下拉清單讀取()
  79. ComboBox2.Items.Clear() : ComboBox3.Items.Clear() : While (dr.Read()) : ComboBox2.Items.Add(dr("簡稱")) : ComboBox3.Items.Add(dr("編號")) : End While : conn.Close()
  80. End Sub
  81. Private Sub ComboBox5下拉表單資料載入()
  82. SQL_倉名下拉清單()
  83. ComboBox5.Items.Clear() : While (dr.Read()) : ComboBox5.Items.Add(dr("倉名")) : End While : conn.Close()
  84. End Sub
  85. Private Sub 訂單資料輸入_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  86. Me.MdiParent = MAOJI_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  87. CheckBox1.Checked = True : TextBox7.Enabled = False : TextBox13.Enabled = False : TextBox15.Enabled = False : TextBox16.Visible = False : ComboBox3.Visible = False : RadioButton1.Checked = True
  88. Button1.Enabled = False : DataGridView2.Visible = False : DataGridView3.Visible = True : ComboBox4.SelectedIndex = 0
  89. Set_訂單控制表() : ComboBox2下拉表單資料載入()
  90. ComboBox5.SelectedIndex = 0
  91. '-----------------------------------------判別訂單準備是否已經齊套-------------------------------------------------------------------------------------------------------------------------------
  92. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  93. 資料數 = DataGridView3.Rows.Count : MyModule1.進度條()
  94. Dim 判別齊套 As Boolean = True
  95. If DataGridView3.Rows(i).Cells("出貨備齊").Value = True Then : Else
  96. TextBox9.Text = DataGridView3.Rows(i).Cells("訂單流水號").Value.ToString : DateTimePicker1.Value = DataGridView3.Rows(i).Cells("下單日").Value.ToString
  97. DateTimePicker2.Value = DataGridView3.Rows(i).Cells("交期").Value.ToString : ComboBox3.Text = DataGridView3.Rows(i).Cells("客戶編號").Value.ToString
  98. Set_訂單明細表()
  99. For ii As Integer = 0 To DataGridView2.Rows.Count - 1
  100. If DataGridView2.Rows(ii).Cells("出貨單號").Value.ToString = "" Then
  101. 判別齊套 = False
  102. Exit For
  103. End If
  104. Next
  105. If 判別齊套 = False Then : Else
  106. PA1 = TextBox9.Text : SQL_訂單控制表_出貨備齊() : conn.Close()
  107. End If
  108. End If
  109. Next : MAOJI_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
  110. Set_訂單控制表() : ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : ComboBox5下拉表單資料載入() : TextBox9.Text = "" : ComboBox5.SelectedIndex = 0
  111. End Sub
  112. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  113. If e.RowIndex = -1 Then : Else
  114. TextBox13.Text = DataGridView1.Rows(e.RowIndex).Cells("供應商編號").Value.ToString : TextBox7.Text = DataGridView1.Rows(e.RowIndex).Cells("料號").Value.ToString
  115. TextBox16.Text = DataGridView1.Rows(e.RowIndex).Cells("加權成本_台幣").Value.ToString : TextBox17.Text = DataGridView1.Rows(e.RowIndex).Cells("售價").Value.ToString
  116. TextBox15.Text = Format(DataGridView1.Rows(e.RowIndex).Cells("庫存").Value - DataGridView1.Rows(e.RowIndex).Cells("未出庫").Value, "#,##0")
  117. TextBox17.Text = Format(Val(TextBox17.Text), "#,##0")
  118. End If
  119. End Sub
  120. Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  121. If e.RowIndex = -1 Then : Else
  122. TextBox2.Text = DataGridView2.Rows(e.RowIndex).Cells("出貨單號").Value.ToString
  123. End If
  124. End Sub
  125. Private Sub DataGridView3_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellClick
  126. If e.RowIndex = -1 Then : Else
  127. ComboBox2下拉表單資料載入()
  128. TextBox9.Text = DataGridView3.Rows(e.RowIndex).Cells("訂單流水號").Value.ToString : DateTimePicker1.Value = DataGridView3.Rows(e.RowIndex).Cells("下單日").Value.ToString
  129. DateTimePicker2.Value = DataGridView3.Rows(e.RowIndex).Cells("交期").Value.ToString : ComboBox3.Text = DataGridView3.Rows(e.RowIndex).Cells("客戶編號").Value.ToString
  130. Set_訂單明細表()
  131. End If
  132. End Sub
  133. Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
  134. Dim linePen As New Pen(Color.Blue, 2)
  135. If e.RowIndex = DataGridView1.Rows.Count - 1 Then : Exit Sub
  136. Else
  137. If CheckBox1.Checked = True Then
  138. If DataGridView1(0, e.RowIndex).Value.ToString <> DataGridView1(0, e.RowIndex + 1).Value.ToString Then
  139. Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  140. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  141. Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
  142. e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
  143. End If
  144. Else
  145. If DataGridView1(2, e.RowIndex).Value.ToString <> DataGridView1(2, e.RowIndex + 1).Value.ToString Then
  146. Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  147. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  148. Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
  149. e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
  150. End If
  151. End If
  152. End If
  153. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  154. If DataGridView1.Rows(i).Cells("可領用").Value = 0 Then : DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightPink : End If
  155. Next
  156. End Sub
  157. Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
  158. PA = TextBox5.Text
  159. SQL_客戶資料表關鍵字查詢()
  160. ComboBox2.Items.Clear() : ComboBox3.Items.Clear() : While (dr.Read()) : ComboBox2.Items.Add(dr("簡稱")) : ComboBox3.Items.Add(dr("編號")) : End While : conn.Close()
  161. End Sub
  162. Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.Click
  163. Set_清單()
  164. End Sub
  165. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.Click
  166. Set_清單()
  167. End Sub
  168. Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.Click
  169. CheckBox1.Checked = True : CheckBox2.Checked = False : Set_清單()
  170. End Sub
  171. Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.Click
  172. CheckBox1.Checked = False : CheckBox2.Checked = True : Set_清單()
  173. End Sub
  174. Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
  175. ComboBox3.SelectedIndex = ComboBox2.SelectedIndex
  176. End Sub
  177. Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
  178. ComboBox2.SelectedIndex = ComboBox3.SelectedIndex
  179. End Sub
  180. Private Sub ComboBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox5.SelectedIndexChanged
  181. PA = ComboBox5.Text : SQL_倉名編號取得()
  182. If dr.Read() Then : TextBox19.Text = dr("倉名編號") : End If : conn.Close() : Set_清單()
  183. End Sub
  184. Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.Click
  185. DataGridView2.Visible = False : DataGridView3.Visible = True : Button1.Enabled = False : RadioButton1.Checked = True : RadioButton2.Checked = False : TextBox2.Text = ""
  186. End Sub
  187. Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.Click
  188. If TextBox9.Text = "" Then
  189. MsgBox("請先選擇訂單。") : RadioButton1.Checked = True : RadioButton2.Checked = False : DataGridView2.Visible = False : DataGridView3.Visible = True : Button1.Enabled = False : TextBox2.Text = ""
  190. Else
  191. RadioButton1.Checked = False : RadioButton2.Checked = True : DataGridView2.Visible = True : DataGridView3.Visible = False : Button1.Enabled = True : TextBox2.Text = ""
  192. If DataGridView2.Rows.Count > 0 Then
  193. TextBox2.Text = DataGridView2.Rows(0).Cells("出貨單號").Value.ToString
  194. End If
  195. End If
  196. End Sub
  197. Private Sub Set_日期格式轉換()
  198. If CheckBox1.Checked = False Then
  199. DTP = Format(Today(), "yyyy/MM/dd") : DTP1 = Format(Today(), "yyyyMMdd") : DTP2 = Format(DateTimePicker2.Value, "yyyy/MM/dd")
  200. Else
  201. DTP1 = Format(DateTimePicker1.Value, "yyyyMMdd") : DTP = Format(DateTimePicker1.Value, "yyyy/MM/dd") : DTP2 = Format(DateTimePicker2.Value, "yyyy/MM/dd")
  202. End If
  203. End Sub
  204. Private Sub Set_日期格式轉換1()
  205. If TextBox2.Text = "" Then
  206. If CheckBox3.Checked = False Then
  207. DTP = Format(Today(), "yyyy/MM/dd") : DTP1 = Format(Today(), "yyyyMMdd") : DTP2 = Format(DateTimePicker2.Value, "yyyy/MM/dd")
  208. Else
  209. DTP = Format(DateTimePicker1.Value, "yyyy/MM/dd") : DTP1 = Format(DateTimePicker1.Value, "yyyyMMdd") : DTP2 = Format(DateTimePicker2.Value, "yyyy/MM/dd")
  210. End If
  211. Else
  212. DTP = Format(DateTimePicker1.Value, "yyyy/MM/dd") : DTP1 = Format(DateTimePicker1.Value, "yyyyMMdd") : DTP2 = Format(DateTimePicker2.Value, "yyyy/MM/dd")
  213. End If
  214. End Sub
  215. Private Sub Set_自動生成流水號1()
  216. SQL_倉儲明細表流水號最後一筆()
  217. If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("資料流水號").ToString, 8)) : Else : EDR = 0 : End If : conn.Close() : EDR += 1
  218. If EDR < 10 Then : ESTR = "WD" & "0000000" & EDR
  219. ElseIf EDR > 9 And EDR < 100 Then : ESTR = "WD" & "000000" & EDR
  220. ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "WD" & "00000" & EDR
  221. ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "WD" & "0000" & EDR
  222. ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "WD" & "000" & EDR
  223. ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "WD" & "00" & EDR
  224. ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "WD" & "0" & EDR
  225. ElseIf EDR > 9999999 Then : ESTR = "WD" & EDR : End If
  226. End Sub
  227. Private Sub Set_新增明細()
  228. If ComboBox4.Text = "直接出貨" Then : HHJJ = "銷售出庫" : Else : HHJJ = "組裝出庫" : End If
  229. PA1 = ESTR : PA2 = TextBox2.Text : PA3 = TextBox13.Text : PA4 = TextBox7.Text : NU1 = TextBox16.Text : NU2 = 1 : NU3 = 0 : NU4 = 申請數量 : PA5 = HHJJ : PA6 = DTP
  230. PA7 = ComboBox3.Text : NU5 = TextBox17.Text : PA8 = TextBox19.Text : PA9 = DTP2 : PA10 = TextBox9.Text
  231. SQL_倉儲明細表新增_含訂單編號() : conn.Close() : MsgBox("資料新增完畢 。")
  232. End Sub
  233. Private Sub Set_生成出貨單()
  234. If TextBox2.Text = "" Then
  235. '----------------------自动生成單據編號-------------------------------------------------------------------------
  236. Dim NUM1 As Integer : Set_日期格式轉換()
  237. For i As Integer = 1 To 999
  238. NUM1 = 0 + i
  239. If NUM1 < 10 Then : TextBox2.Text = "WD-" & DTP1 & "-00" & NUM1
  240. ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox2.Text = "WD-" & DTP1 & "-0" & NUM1
  241. ElseIf NUM1 > 99 Then : TextBox2.Text = "WD-" & DTP1 & "-" & NUM1 : End If
  242. PA1 = TextBox2.Text : SQL_倉儲明細表生成單據編號()
  243. If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
  244. Next
  245. Set_自動生成流水號1() : TextBox14.Text = ESTR : conn.Close() : Set_新增明細()
  246. Else
  247. Set_日期格式轉換1() : Set_自動生成流水號1() : TextBox14.Text = ESTR : conn.Close() : Set_新增明細()
  248. End If : Set_清單()
  249. End Sub
  250. Private Sub Set_自動生成流水號2()
  251. SQL_訂單明細表流水號最後一筆()
  252. If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("資料流水號").ToString, 8)) : Else : EDR = 0 : End If : conn.Close() : EDR += 1
  253. If EDR < 10 Then : GGHH = "A" & "0000000" & EDR
  254. ElseIf EDR > 9 And EDR < 100 Then : GGHH = "A" & "000000" & EDR
  255. ElseIf EDR > 99 And EDR < 1000 Then : GGHH = "A" & "00000" & EDR
  256. ElseIf EDR > 999 And EDR < 10000 Then : GGHH = "A" & "0000" & EDR
  257. ElseIf EDR > 9999 And EDR < 100000 Then : GGHH = "A" & "000" & EDR
  258. ElseIf EDR > 99999 And EDR < 100000 Then : GGHH = "A" & "00" & EDR
  259. ElseIf EDR > 999999 And EDR < 1000000 Then : GGHH = "A" & "0" & EDR
  260. ElseIf EDR > 9999999 Then : GGHH = "A" & EDR : End If
  261. End Sub
  262. Private Sub Set_新增訂單明細資料()
  263. PA1 = GGHH : PA2 = TextBox9.Text : PA3 = TextBox7.Text : NU1 = 申請數量 : PA4 = TextBox2.Text : PA5 = 狀態 : SQL_訂單明細表新增() : conn.Close()
  264. End Sub
  265. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  266. If TextBox7.Text = "" Then : MsgBox("料號沒有選擇") : Else
  267. If ComboBox3.Text = "" Then : MsgBox("客戶沒有選擇") : Else
  268. If ComboBox4.Text = "" Then : MsgBox("請選擇--直接出貨--還是--組裝出貨--。") : Else
  269. If NumericUpDown1.Value = 0 Then : MsgBox("數量不可為零") : Else
  270. If TextBox7.Text = "" Then
  271. MsgBox("請先選擇物料。") : Else
  272. If Val(TextBox15.Text) = 0 And NumericUpDown1.Value > 0 Then
  273. '------------------開訂單-----出貨單----------------------------------------------------------------------------------------------------------------------------------
  274. 狀態 = "C"
  275. 申請數量 = NumericUpDown1.Value
  276. Set_自動生成流水號2() : Set_新增訂單明細資料()
  277. Set_清單() : Set_訂單明細表()
  278. ElseIf Val(TextBox15.Text) >= NumericUpDown1.Value And NumericUpDown1.Value > 0 Then
  279. '------------------開訂單-----出貨單----------------------------------------------------------------------------------------------------------------------------------
  280. 狀態 = "A"
  281. 申請數量 = NumericUpDown1.Value
  282. Set_生成出貨單() : Set_自動生成流水號2() : Set_新增訂單明細資料()
  283. Set_清單() : Set_訂單明細表()
  284. ElseIf Val(TextBox15.Text) < NumericUpDown1.Value And Val(TextBox15.Text) > 0 And NumericUpDown1.Value > 0 Then
  285. '------------------開訂單---------------------------------------------------------------------------------------------------------------------------------------------
  286. 狀態 = "B"
  287. 申請數量 = Val(TextBox15.Text)
  288. Set_生成出貨單() : Dim OOPP As String = TextBox2.Text
  289. Set_自動生成流水號2() : Set_新增訂單明細資料()
  290. 申請數量 = NumericUpDown1.Value - Val(TextBox15.Text) : TextBox2.Text = ""
  291. Set_自動生成流水號2() : Set_新增訂單明細資料()
  292. TextBox2.Text = OOPP
  293. Set_清單() : Set_訂單明細表()
  294. End If
  295. End If
  296. End If
  297. End If
  298. End If
  299. End If
  300. End Sub
  301. '-----------------------------滑鼠右鍵------------------------------------------------------------------------------------------------------------------------------------------
  302. Private Sub 重新整理ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 重新整理ToolStripMenuItem.Click
  303. ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : ComboBox5下拉表單資料載入() : Set_訂單控制表()
  304. End Sub
  305. Private Sub 開立新的採購單ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 開立新的採購單ToolStripMenuItem.Click
  306. If ComboBox2.Text = "" Then : MsgBox("請先選擇客戶。")
  307. Else
  308. Dim NUM1 As Integer : Set_日期格式轉換()
  309. For i As Integer = 1 To 999
  310. NUM1 = 0 + i
  311. If NUM1 < 10 Then : TextBox9.Text = "PO-" & DTP1 & "-00" & NUM1
  312. ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox9.Text = "PO-" & DTP1 & "-0" & NUM1
  313. ElseIf NUM1 > 99 Then : TextBox9.Text = "PO-" & DTP1 & "-" & NUM1 : End If
  314. SQL_訂單控制表流水號最後一筆()
  315. If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
  316. Next
  317. SQL_訂單控制表新增() : conn.Close() : Set_訂單控制表() : Set_訂單明細表()
  318. RadioButton1.Checked = False : RadioButton2.Checked = True : DataGridView2.Visible = True : DataGridView3.Visible = False : Button1.Enabled = True
  319. End If
  320. End Sub
  321. End Class