Ei kuvausta
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 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. Option Strict Off
  2. Public Class 出貨單申請
  3. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet
  4. Dim EDR As Integer = 0 : Dim ESTR As String : Dim HHJJ As String
  5. Private Sub Set_清單()
  6. DataGridView1.DataSource = Nothing : ds.Clear() : DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView1.ColumnHeadersHeight = 40
  7. DataGridView1.AllowUserToAddRows = False : DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView1.MultiSelect = True
  8. SQL_出貨單申請清單()
  9. da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  10. DataGridView1.Columns(0).FillWeight = 130 : DataGridView1.Columns(1).Visible = False : DataGridView1.Columns(2).Visible = False : DataGridView1.Columns(3).FillWeight = 350
  11. DataGridView1.Columns(4).Visible = False : DataGridView1.Columns(5).Visible = False : DataGridView1.Columns(6).Visible = False : DataGridView1.Columns(7).FillWeight = 85
  12. DataGridView1.Columns(8).Visible = False : DataGridView1.Columns(9).FillWeight = 85 : DataGridView1.Columns(10).Visible = False : DataGridView1.Columns(11).FillWeight = 90
  13. DataGridView1.Columns(12).Visible = False : DataGridView1.Columns(13).FillWeight = 90 : DataGridView1.Columns(14).Visible = False
  14. DataGridView1.Columns(6).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(7).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(8).DefaultCellStyle.Format = "#,##0"
  15. DataGridView1.Columns(9).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(10).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(11).DefaultCellStyle.Format = "#,##0"
  16. DataGridView1.Columns(12).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(13).DefaultCellStyle.Format = "#,##0"
  17. DataGridView1.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  18. DataGridView1.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  19. DataGridView1.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  20. DataGridView1.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  21. DataGridView1.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  22. DataGridView1.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  23. DataGridView1.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(11).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  24. DataGridView1.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(12).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  25. DataGridView1.Columns(13).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(13).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  26. DataGridView1.Columns(0).ReadOnly = True : DataGridView1.Columns(3).ReadOnly = True : DataGridView1.Columns(4).ReadOnly = True : DataGridView1.Columns(5).ReadOnly = True
  27. DataGridView1.Columns(6).ReadOnly = True : DataGridView1.Columns(7).ReadOnly = True : DataGridView1.Columns(8).ReadOnly = True : DataGridView1.Columns(9).ReadOnly = True
  28. DataGridView1.Columns(10).ReadOnly = True : DataGridView1.Columns(11).ReadOnly = True : DataGridView1.Columns(12).ReadOnly = True : DataGridView1.Columns(13).ReadOnly = True
  29. DataGridView1.Columns(7).DefaultCellStyle.BackColor = Color.MistyRose : DataGridView1.Columns(8).DefaultCellStyle.BackColor = Color.MistyRose
  30. DataGridView1.Columns(9).DefaultCellStyle.BackColor = Color.LightYellow : DataGridView1.Columns(10).DefaultCellStyle.BackColor = Color.LightYellow
  31. DataGridView1.Columns(11).DefaultCellStyle.BackColor = Color.LightGreen : DataGridView1.Columns(12).DefaultCellStyle.BackColor = Color.LightGreen
  32. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  33. If DataGridView1.Rows(i).Cells("未入庫").Value.ToString = "" Then : DataGridView1.Rows(i).Cells("未入庫").Value = 0 : End If
  34. If DataGridView1.Rows(i).Cells("在途成本_台幣").Value.ToString = "" Then : DataGridView1.Rows(i).Cells("在途成本_台幣").Value = 0 : End If
  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. DataGridView1.Rows(i).Cells("可領用").Value = DataGridView1.Rows(i).Cells("庫存").Value + DataGridView1.Rows(i).Cells("未入庫").Value - DataGridView1.Rows(i).Cells("未出庫").Value
  38. Next
  39. TextBox13.Text = "" : TextBox7.Text = "" : TextBox15.Text = "0" : NumericUpDown1.Value = 0
  40. End Sub
  41. Private Sub Set_銷售清單()
  42. DataGridView2.DataSource = Nothing : ds1.Clear() : DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView2.ColumnHeadersHeight = 25
  43. DataGridView2.AllowUserToAddRows = False : DataGridView2.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView2.MultiSelect = True
  44. SQL_出貨單申請_彙總()
  45. da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close()
  46. DataGridView2.Columns(0).FillWeight = 150 : DataGridView2.Columns(1).FillWeight = 90 : DataGridView2.Columns(2).Visible = False : DataGridView2.Columns(3).FillWeight = 100
  47. DataGridView2.Columns(4).FillWeight = 80 : DataGridView2.Columns(5).FillWeight = 90 : DataGridView2.Columns(6).Visible = False : DataGridView2.Columns(7).Visible = False
  48. DataGridView2.Columns(8).Visible = False : DataGridView2.Columns(9).Visible = False
  49. For i As Integer = 0 To DataGridView2.Rows.Count - 1
  50. If DataGridView2.Rows(i).Cells("業務比例").Value.ToString = "" Then : DataGridView2.Rows(i).Cells("業務比例").Value = 0 : End If
  51. If DataGridView2.Rows(i).Cells("司機比例").Value.ToString = "" Then : DataGridView2.Rows(i).Cells("司機比例").Value = 0 : End If
  52. Next
  53. End Sub
  54. Private Sub Set_單據明細()
  55. DataGridView3.DataSource = Nothing : ds2.Clear() : DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView3.ColumnHeadersHeight = 25
  56. DataGridView3.AllowUserToAddRows = False : DataGridView3.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView3.MultiSelect = True
  57. SQL_出貨單申請_清單()
  58. da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close()
  59. DataGridView3.Columns(6).DefaultCellStyle.Format = "#,##0" : DataGridView3.Columns(7).DefaultCellStyle.Format = "#,##0"
  60. DataGridView3.Columns(8).DefaultCellStyle.Format = "#,##0.0000" : DataGridView3.Columns(9).DefaultCellStyle.Format = "#,##0" : DataGridView3.Columns(10).DefaultCellStyle.Format = "#,##0"
  61. DataGridView3.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  62. DataGridView3.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  63. DataGridView3.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  64. DataGridView3.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  65. DataGridView3.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  66. DataGridView3.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  67. DataGridView3.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  68. DataGridView3.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(12).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  69. DataGridView3.Columns(13).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(13).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  70. DataGridView3.Columns(0).Visible = False : DataGridView3.Columns(1).FillWeight = 30 : DataGridView3.Columns(2).FillWeight = 80 : DataGridView3.Columns(3).FillWeight = 150
  71. DataGridView3.Columns(4).FillWeight = 80 : DataGridView3.Columns(5).FillWeight = 80 : DataGridView3.Columns(6).FillWeight = 50 : DataGridView3.Columns(7).FillWeight = 50
  72. DataGridView3.Columns(8).Visible = False : DataGridView3.Columns(9).Visible = False : DataGridView3.Columns(10).Visible = False : DataGridView3.Columns(11).FillWeight = 100
  73. DataGridView3.Columns(12).FillWeight = 80 : DataGridView3.Columns(13).FillWeight = 50 : DataGridView3.Columns(14).Visible = False
  74. DataGridView3.EditMode = DataGridViewEditMode.EditOnEnter
  75. DataGridView3.Columns(1).ReadOnly = True : DataGridView3.Columns(2).ReadOnly = True : DataGridView3.Columns(3).ReadOnly = True : DataGridView3.Columns(4).ReadOnly = True
  76. DataGridView3.Columns(5).ReadOnly = True : DataGridView3.Columns(6).ReadOnly = True : DataGridView3.Columns(8).ReadOnly = True : DataGridView3.Columns(9).ReadOnly = True
  77. DataGridView3.Columns(10).ReadOnly = True : DataGridView3.Columns(12).ReadOnly = True
  78. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  79. DataGridView3(1, i).Value = i + 1
  80. Next
  81. End Sub
  82. Private Sub ComboBox1下拉表單資料載入()
  83. SQL_物料頁碼清單()
  84. ComboBox1.Items.Clear() : While (dr.Read()) : ComboBox1.Items.Add(dr("頁碼")) : End While : conn.Close()
  85. End Sub
  86. Private Sub ComboBox2下拉表單資料載入()
  87. SQL_客戶資料表_下拉清單讀取()
  88. ComboBox2.Items.Clear() : ComboBox3.Items.Clear() : While (dr.Read()) : ComboBox2.Items.Add(dr("簡稱")) : ComboBox3.Items.Add(dr("編號")) : End While : conn.Close()
  89. End Sub
  90. Private Sub ComboBox5下拉表單資料載入()
  91. SQL_倉名下拉清單()
  92. ComboBox5.Items.Clear() : While (dr.Read()) : ComboBox5.Items.Add(dr("倉名")) : End While : conn.Close()
  93. End Sub
  94. Private Sub ComboBox6下拉表單資料載入()
  95. SQL_員工名稱下拉清單()
  96. ComboBox6.Items.Clear() : ComboBox8.Items.Clear() : While (dr.Read()) : ComboBox6.Items.Add(dr("名稱")) : ComboBox8.Items.Add(dr("名稱")) : End While : conn.Close()
  97. End Sub
  98. Private Sub ComboBox7下拉表單資料載入()
  99. SQL_傭金比例下拉清單()
  100. ComboBox7.Items.Clear() : ComboBox9.Items.Clear()
  101. While (dr.Read()) : ComboBox7.Items.Add(Format(dr("比例"), "#,##0.0")) : ComboBox9.Items.Add(Format(dr("比例"), "#,##0.0")) : End While : conn.Close()
  102. End Sub
  103. Private Sub ComboBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox5.SelectedIndexChanged
  104. PA = ComboBox5.Text : SQL_倉名編號取得()
  105. If dr.Read() Then : TextBox19.Text = dr("倉名編號") : End If : conn.Close() : Set_清單()
  106. End Sub
  107. Private Sub 出貨單申請_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  108. Me.MdiParent = MAOJI_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  109. CheckBox1.Checked = True : TextBox7.Enabled = False : TextBox13.Enabled = False : TextBox15.Enabled = False : TextBox9.Enabled = False : TextBox14.Enabled = False
  110. RadioButton4.Checked = True : TextBox16.Visible = False : ComboBox3.Visible = False : ComboBox4.SelectedIndex = 0 : TextBox18.Visible = False : TextBox4.Enabled = False
  111. ComboBox5下拉表單資料載入() : ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : ComboBox6下拉表單資料載入() : ComboBox7下拉表單資料載入() : Set_銷售清單()
  112. ComboBox5.SelectedIndex = 0
  113. End Sub
  114. Private Sub 出貨單申請_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
  115. If DataGridView3.Rows.Count = 0 And CheckBox5.Checked = True Then
  116. SQL_出貨單申請_零售客戶記錄表刪除() : conn.Close()
  117. End If
  118. End Sub
  119. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  120. If e.RowIndex = -1 Then : Else
  121. TextBox13.Text = DataGridView1.Rows(e.RowIndex).Cells("供應商編號").Value.ToString : TextBox7.Text = DataGridView1.Rows(e.RowIndex).Cells("料號").Value.ToString
  122. TextBox16.Text = DataGridView1.Rows(e.RowIndex).Cells("加權成本_台幣").Value.ToString : TextBox17.Text = DataGridView1.Rows(e.RowIndex).Cells("售價").Value.ToString
  123. TextBox15.Text = Format(DataGridView1.Rows(e.RowIndex).Cells("庫存").Value - DataGridView1.Rows(e.RowIndex).Cells("未出庫").Value, "#,##0")
  124. TextBox17.Text = Format(Val(TextBox17.Text), "#,##0")
  125. End If
  126. End Sub
  127. Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
  128. Dim linePen As New Pen(Color.Blue, 2)
  129. If e.RowIndex = DataGridView1.Rows.Count - 1 Then : Exit Sub
  130. Else
  131. If CheckBox1.Checked = True Then
  132. If DataGridView1(0, e.RowIndex).Value.ToString <> DataGridView1(0, e.RowIndex + 1).Value.ToString Then
  133. Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  134. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  135. Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
  136. e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
  137. End If
  138. Else
  139. If DataGridView1(2, e.RowIndex).Value.ToString <> DataGridView1(2, e.RowIndex + 1).Value.ToString Then
  140. Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  141. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  142. Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
  143. e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
  144. End If
  145. End If
  146. End If
  147. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  148. If DataGridView1.Rows(i).Cells("可領用").Value = 0 Then : DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightPink : End If
  149. Next
  150. End Sub
  151. Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  152. If e.RowIndex = -1 Then : Else
  153. If CheckBox4.Checked = True Then
  154. ComboBox6下拉表單資料載入() : ComboBox7下拉表單資料載入()
  155. TextBox9.Text = DataGridView2.Rows(e.RowIndex).Cells("單據編號").Value.ToString : ComboBox3.Text = DataGridView2.Rows(e.RowIndex).Cells("客戶編號").Value.ToString
  156. TextBox18.Text = DataGridView2.Rows(e.RowIndex).Cells("狀態").Value.ToString : DateTimePicker1.Value = DataGridView2.Rows(e.RowIndex).Cells("銷售下單").Value.ToString
  157. DateTimePicker2.Value = DataGridView2.Rows(e.RowIndex).Cells("客戶交期").Value.ToString : ComboBox6.Text = DataGridView2.Rows(e.RowIndex).Cells("業務").Value.ToString
  158. ComboBox7.Text = Format(DataGridView2.Rows(e.RowIndex).Cells("業務比例").Value, "#,##0.0") : ComboBox8.Text = DataGridView2.Rows(e.RowIndex).Cells("司機").Value.ToString
  159. ComboBox9.Text = Format(DataGridView2.Rows(e.RowIndex).Cells("司機比例").Value, "#,##0.0") : 列印用SQL = TextBox9.Text
  160. Set_單據明細() : 客戶資料()
  161. End If
  162. End If
  163. End Sub
  164. Private Sub DataGridView3_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellClick
  165. If e.RowIndex = -1 Then : Else
  166. TextBox14.Text = DataGridView3.Rows(e.RowIndex).Cells("資料流水號").Value.ToString
  167. End If
  168. End Sub
  169. Private Sub DataGridView3_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView3.CellEnter
  170. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  171. DataGridView3.Rows(i).Cells("台幣單價").Value = DataGridView3.Rows(i).Cells("單價").Value * DataGridView3.Rows(i).Cells("匯率").Value
  172. DataGridView3.Rows(i).Cells("出貨成本_台幣").Value = DataGridView3.Rows(i).Cells("單價").Value * DataGridView3.Rows(i).Cells("匯率").Value * DataGridView3.Rows(i).Cells("數量").Value
  173. DataGridView3(1, i).Value = i + 1
  174. Next i
  175. End Sub
  176. Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.Click
  177. CheckBox1.Checked = True : CheckBox2.Checked = False : Set_清單()
  178. End Sub
  179. Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.Click
  180. CheckBox1.Checked = False : CheckBox2.Checked = True : Set_清單()
  181. End Sub
  182. Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
  183. PA = TextBox5.Text : SQL_客戶資料表關鍵字查詢()
  184. ComboBox2.Items.Clear() : ComboBox3.Items.Clear() : While (dr.Read()) : ComboBox2.Items.Add(dr("簡稱")) : ComboBox3.Items.Add(dr("編號")) : End While : conn.Close()
  185. End Sub
  186. Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  187. Set_清單()
  188. End Sub
  189. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  190. Set_清單()
  191. End Sub
  192. Private Sub 客戶資料()
  193. conn.Close()
  194. If ComboBox3.Text = "CI00000000" Then
  195. SQL_出貨單申請_客戶資料_零售一()
  196. If (dr.Read()) Then
  197. TextBox4.Text = dr("付款方式")
  198. End If : conn.Close()
  199. SQL_出貨單申請_客戶資料_零售二()
  200. If (dr.Read()) Then
  201. TextBox2.Text = dr("客戶名稱") : TextBox6.Text = dr("手機") : TextBox3.Text = dr("電話") : TextBox8.Text = dr("傳真") : TextBox11.Text = dr("郵遞區號")
  202. TextBox10.Text = dr("店面地址") : TextBox12.Text = dr("送貨地址") : TextBox26.Text = dr("統一編號")
  203. End If : conn.Close()
  204. Else
  205. SQL_出貨單申請_客戶資料_銷售二()
  206. If (dr.Read()) Then
  207. TextBox2.Text = dr("店名") : TextBox6.Text = dr("手機") : TextBox3.Text = dr("電話") : TextBox8.Text = dr("傳真") : TextBox11.Text = dr("店面地址郵遞區號")
  208. TextBox10.Text = dr("店面地址") : TextBox12.Text = dr("送貨地址") : TextBox26.Text = dr("統編") : TextBox4.Text = dr("付款方式")
  209. End If : conn.Close()
  210. End If
  211. End Sub
  212. Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
  213. ComboBox3.SelectedIndex = ComboBox2.SelectedIndex : 客戶資料()
  214. End Sub
  215. Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
  216. ComboBox2.SelectedIndex = ComboBox3.SelectedIndex : 客戶資料()
  217. End Sub
  218. Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.TextChanged
  219. If NumericUpDown1.Value > Val(TextBox15.Text) Then
  220. MsgBox("可申請數只剩下 " & TextBox15.Text & " ,不可大於可申請數。")
  221. NumericUpDown1.Value = 0
  222. End If
  223. End Sub
  224. Private Sub Set_日期格式轉換()
  225. If TextBox9.Text = "" Then
  226. If CheckBox3.Checked = False Then
  227. DTP = Format(Today(), "yyyy/MM/dd") : DTP1 = Format(Today(), "yyyyMMdd") : DTP2 = Format(DateTimePicker2.Value, "yyyy/MM/dd")
  228. Else
  229. DTP = Format(DateTimePicker1.Value, "yyyy/MM/dd") : DTP1 = Format(DateTimePicker1.Value, "yyyyMMdd") : DTP2 = Format(DateTimePicker2.Value, "yyyy/MM/dd")
  230. End If
  231. Else
  232. DTP = Format(DateTimePicker1.Value, "yyyy/MM/dd") : DTP1 = Format(DateTimePicker1.Value, "yyyyMMdd") : DTP2 = Format(DateTimePicker2.Value, "yyyy/MM/dd")
  233. End If
  234. End Sub
  235. Private Sub Set_自動生成流水號()
  236. SQL_倉儲明細表流水號最後一筆()
  237. If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("資料流水號").ToString, 8)) : Else : EDR = 0 : End If : conn.Close() : EDR += 1
  238. If EDR < 10 Then : ESTR = "WD" & "0000000" & EDR
  239. ElseIf EDR > 9 And EDR < 100 Then : ESTR = "WD" & "000000" & EDR
  240. ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "WD" & "00000" & EDR
  241. ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "WD" & "0000" & EDR
  242. ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "WD" & "000" & EDR
  243. ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "WD" & "00" & EDR
  244. ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "WD" & "0" & EDR
  245. ElseIf EDR > 9999999 Then : ESTR = "WD" & EDR : End If
  246. End Sub
  247. Private Sub 存檔1()
  248. Dim SSDD As Integer = 0
  249. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  250. 資料數 = DataGridView3.Rows.Count : MyModule1.進度條()
  251. PA1 = DataGridView3.Rows(i).Cells("資料流水號").Value
  252. SQL_倉儲明細表_入庫日期讀取()
  253. If dr.Read() Then
  254. If dr("入庫日期").ToString = "" Then
  255. NU1 = DataGridView3.Rows(i).Cells("單價").Value : NU2 = DataGridView3.Rows(i).Cells("數量").Value
  256. PA1 = DataGridView3.Rows(i).Cells("備註").Value : PA2 = DTP2 : PA3 = DataGridView3.Rows(i).Cells("資料流水號").Value
  257. SQL_出貨單申請_倉儲明細表修改_出庫() : conn.Close()
  258. Else
  259. conn.Close() : SSDD += 1
  260. End If
  261. End If
  262. PA1 = ComboBox6.Text : NU1 = ComboBox7.Text : PA2 = ComboBox8.Text : NU2 = ComboBox9.Text : PA = TextBox9.Text
  263. SQL_出貨單業務司機指定()
  264. Next : MAOJI_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : If SSDD = 0 Then : Else : MsgBox("共有 " & SSDD & "筆資料已入庫,沒有變更。") : End If
  265. End Sub
  266. Private Sub Set_新增明細()
  267. If ComboBox4.Text = "直接出貨" Then : HHJJ = "銷售出庫" : Else : HHJJ = "組裝出庫" : End If
  268. PA1 = ESTR : PA2 = TextBox9.Text : PA3 = TextBox13.Text : PA4 = TextBox7.Text : NU1 = TextBox16.Text : NU2 = 1 : NU3 = 0 : NU4 = NumericUpDown1.Value : PA5 = HHJJ : PA6 = DTP
  269. PA7 = ComboBox3.Text : NU5 = TextBox17.Text : PA8 = TextBox19.Text : PA9 = DTP2
  270. SQL_倉儲明細表新增() : conn.Close() : MsgBox("資料新增完畢 。") : Set_單據明細()
  271. End Sub
  272. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  273. If CheckBox5.Checked = True And TextBox9.Text = "" Then : MsgBox("零售功能需要在介面上先輸入客戶資料,並點下開立出貨單取得出貨單具號碼後才可以新增物料到單據中。") : Else
  274. If TextBox7.Text = "" Then : MsgBox("料號沒有選擇") : Else
  275. If ComboBox3.Text = "" Then : MsgBox("客戶沒有選擇") : Else
  276. If ComboBox4.Text = "" Then : MsgBox("請選擇--直接出貨--還是--組裝出貨--。") : Else
  277. If NumericUpDown1.Value = 0 Then : MsgBox("數量不可為零") : Else
  278. If TextBox9.Text = "" Then
  279. '----------------------自动生成單據編號-------------------------------------------------------------------------
  280. Dim NUM1 As Integer : Set_日期格式轉換()
  281. For i As Integer = 1 To 999
  282. NUM1 = 0 + i
  283. If NUM1 < 10 Then : TextBox9.Text = "WD-" & DTP1 & "-00" & NUM1
  284. ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox9.Text = "WD-" & DTP1 & "-0" & NUM1
  285. ElseIf NUM1 > 99 Then : TextBox9.Text = "WD-" & DTP1 & "-" & NUM1 : End If
  286. PA1 = TextBox9.Text : 列印用SQL = TextBox9.Text : SQL_倉儲明細表生成單據編號()
  287. If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
  288. Next
  289. Set_自動生成流水號() : TextBox14.Text = ESTR : conn.Close() : 存檔1() : Set_新增明細() : Set_銷售清單()
  290. Else
  291. Set_日期格式轉換() : Set_自動生成流水號() : TextBox14.Text = ESTR : conn.Close() : 存檔1() : Set_新增明細()
  292. End If : Set_清單()
  293. End If
  294. End If
  295. End If
  296. End If
  297. End If
  298. End Sub
  299. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  300. If CheckBox5.Checked = True Then
  301. If DataGridView3.Rows.Count = 0 Then
  302. Dim aa1 As MsgBoxResult = MsgBox("零售單據沒有資料,是否放棄編輯?", MsgBoxStyle.OkCancel)
  303. If aa1 = MsgBoxResult.Ok Then
  304. RadioButton1.Enabled = True : RadioButton4.Enabled = True : RadioButton3.Enabled = True : DataGridView2.Enabled = True
  305. SQL_出貨單申請_零售客戶記錄表刪除() : conn.Close() : MsgBox("已放棄編輯 。") : 切換時格式清空()
  306. End If
  307. Else
  308. RadioButton1.Enabled = True : RadioButton4.Enabled = True : RadioButton3.Enabled = True : DataGridView2.Enabled = True : Button2.Enabled = True : CheckBox4.Enabled = True
  309. Set_日期格式轉換() : 存檔1() : Set_單據明細() : Set_清單() : Set_銷售清單() : MsgBox("資料修改,存檔完畢 。")
  310. End If
  311. Else
  312. Set_日期格式轉換() : 存檔1() : Set_單據明細() : Set_清單() : Set_銷售清單() : MsgBox("資料修改,存檔完畢 。")
  313. End If
  314. End Sub
  315. Private Sub 切換時格式清空()
  316. TextBox9.Text = "" : TextBox15.Text = "0" : DateTimePicker1.Value = Today() : DateTimePicker2.Value = Today() : TextBox14.Text = "" : TextBox18.Text = "" : TextBox2.Text = "" : TextBox6.Text = ""
  317. TextBox3.Text = "" : TextBox8.Text = "" : TextBox11.Text = "" : TextBox10.Text = "" : TextBox13.Text = "" : TextBox12.Text = "" : TextBox26.Text = "" : TextBox4.Text = ""
  318. DataGridView3.DataSource = Nothing : ds2.Clear()
  319. End Sub
  320. Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.Click
  321. RadioButton4.Checked = False : RadioButton3.Checked = False : RadioButton1.Checked = True : Set_銷售清單() : Button1.Enabled = True : Button3.Enabled = True
  322. 新增物料到採購單ToolStripMenuItem.Enabled = True : 刪除採購單中選中的物料ToolStripMenuItem.Enabled = True : 修改存檔ToolStripMenuItem.Enabled = True
  323. 切換時格式清空() : CheckBox4.Checked = True : CheckBox5.Checked = False : ComboBox2.Enabled = True
  324. End Sub
  325. Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.Click
  326. RadioButton4.Checked = True : RadioButton3.Checked = False : RadioButton1.Checked = False : Set_銷售清單() : Button1.Enabled = True : Button3.Enabled = True
  327. 新增物料到採購單ToolStripMenuItem.Enabled = True : 刪除採購單中選中的物料ToolStripMenuItem.Enabled = True : 修改存檔ToolStripMenuItem.Enabled = True
  328. 切換時格式清空() : CheckBox4.Checked = True : CheckBox5.Checked = False : ComboBox2.Enabled = True
  329. End Sub
  330. Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.Click
  331. RadioButton4.Checked = False : RadioButton3.Checked = True : RadioButton1.Checked = False : Set_銷售清單() : Button1.Enabled = False : Button3.Enabled = False
  332. 新增物料到採購單ToolStripMenuItem.Enabled = False : 刪除採購單中選中的物料ToolStripMenuItem.Enabled = False : 修改存檔ToolStripMenuItem.Enabled = False
  333. 切換時格式清空() : CheckBox4.Checked = True : CheckBox5.Checked = False : ComboBox2.Enabled = True
  334. End Sub
  335. Private Sub TextBox18_TextChanged(sender As Object, e As EventArgs) Handles TextBox18.TextChanged
  336. If TextBox18.Text = "銷售出庫" Then : ComboBox4.Text = "直接出貨"
  337. ElseIf TextBox18.Text = "組裝出貨" Then : ComboBox4.Text = "組裝出貨"
  338. Else : ComboBox4.Text = "直接出貨" : End If
  339. End Sub
  340. Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox4.Click
  341. CheckBox4.Checked = True : CheckBox5.Checked = False : ComboBox2下拉表單資料載入() : ComboBox2.Enabled = True : TextBox5.Enabled = True : 切換時格式清空()
  342. End Sub
  343. Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox5.Click
  344. 切換時格式清空()
  345. CheckBox4.Checked = False : CheckBox5.Checked = True : ComboBox3.Text = "CI00000000" : ComboBox2.Text = "其他-零售" : ComboBox2.Enabled = False : TextBox5.Enabled = False
  346. End Sub
  347. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  348. Me.開立新的採購單ToolStripMenuItem.PerformClick()
  349. End Sub
  350. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  351. PA1 = ComboBox6.Text : NU1 = ComboBox7.Text : PA2 = ComboBox8.Text : NU2 = ComboBox9.Text : PA = TextBox9.Text
  352. SQL_出貨單業務司機指定() : MsgBox("修改完成。") : Me.重新整理ToolStripMenuItem.PerformClick()
  353. End Sub
  354. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  355. If 列印用SQL = "" Then : MsgBox("請選擇出貨單。") : Else : 列印_出貨單.ShowDialog() : End If : 列印用SQL = ""
  356. End Sub
  357. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  358. If TextBox9.Text = "" Then : MsgBox("沒有選擇要列印的單號 。") : Else : 列印用SQL = TextBox9.Text : PA = "銷售出貨單" : 列印_產品標籤介面.ShowDialog() : End If
  359. End Sub
  360. '-----------------------------滑鼠右鍵------------------------------------------------------------------------------------------------------------------------------------------
  361. Private Sub 重新整理ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 重新整理ToolStripMenuItem.Click
  362. Set_清單() : Set_銷售清單() : ComboBox2下拉表單資料載入()
  363. End Sub
  364. Private Sub 開立新的採購單ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 開立新的採購單ToolStripMenuItem.Click
  365. If CheckBox4.Checked = True Then
  366. 切換時格式清空() : ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : Set_清單() : Set_銷售清單()
  367. If ComboBox4.Text = "直接出貨" Then : Me.RadioButton4.PerformClick() : Else : Me.RadioButton1.PerformClick() : End If
  368. Else
  369. Dim aa1 As MsgBoxResult = MsgBox("零售模式,單據生成之前請在介面中填入零售客戶資料,開單過程無法更改,請確定資料已經填好?", MsgBoxStyle.OkCancel)
  370. If aa1 = MsgBoxResult.Ok Then
  371. '----------------------自动生成單據編號-------------------------------------------------------------------------
  372. Dim NUM1 As Integer : Set_日期格式轉換()
  373. For i As Integer = 1 To 999
  374. NUM1 = 0 + i
  375. If NUM1 < 10 Then : TextBox9.Text = "WD-" & DTP1 & "-00" & NUM1
  376. ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox9.Text = "WD-" & DTP1 & "-0" & NUM1
  377. ElseIf NUM1 > 99 Then : TextBox9.Text = "WD-" & DTP1 & "-" & NUM1 : End If
  378. PA1 = TextBox9.Text : 列印用SQL = TextBox9.Text : SQL_倉儲明細表生成單據編號()
  379. If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
  380. Next
  381. SQL_出貨單申請_零售客戶記錄表流水號最後一筆()
  382. If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("零售流水號").ToString, 8)) : Else : EDR = 0 : End If : conn.Close() : EDR += 1
  383. If EDR < 10 Then : ESTR = "B" & "0000000" & EDR
  384. ElseIf EDR > 9 And EDR < 100 Then : ESTR = "B" & "000000" & EDR
  385. ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "B" & "00000" & EDR
  386. ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "B" & "0000" & EDR
  387. ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "B" & "000" & EDR
  388. ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "B" & "00" & EDR
  389. ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "B" & "0" & EDR
  390. ElseIf EDR > 9999999 Then : ESTR = "B" & EDR : End If : PA1 = ESTR
  391. SQL_出貨單申請_零售客戶記錄表新增() : conn.Close()
  392. RadioButton1.Enabled = False : RadioButton4.Enabled = False : RadioButton3.Enabled = False : DataGridView2.Enabled = False : Button2.Enabled = False
  393. RadioButton4.Checked = True : RadioButton3.Checked = False : RadioButton1.Checked = False : Set_銷售清單() : Button1.Enabled = True : Button3.Enabled = True
  394. 新增物料到採購單ToolStripMenuItem.Enabled = True : 刪除採購單中選中的物料ToolStripMenuItem.Enabled = True : 修改存檔ToolStripMenuItem.Enabled = True
  395. ComboBox1下拉表單資料載入() : Set_清單() : DataGridView3.DataSource = Nothing : ds2.Clear() : CheckBox4.Enabled = False
  396. End If
  397. End If
  398. End Sub
  399. Private Sub 新增物料到採購單ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 新增物料到採購單ToolStripMenuItem.Click
  400. Me.Button1.PerformClick()
  401. End Sub
  402. Private Sub 刪除採購單中選中的物料ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 刪除採購單中選中的物料ToolStripMenuItem.Click
  403. PA1 = TextBox14.Text : SQL_倉儲明細表_出庫日期讀取()
  404. If dr("出庫日期") = "" Then : conn.Close()
  405. If TextBox14.Text = "" Then : MsgBox("沒有選擇要刪除了料號 。")
  406. Else
  407. Dim aa1 As MsgBoxResult = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  408. If aa1 = MsgBoxResult.Ok Then
  409. PA1 = TextBox14.Text : SQL_倉儲明細表刪除() : conn.Close()
  410. '-----------------最後一筆資料刪除時要把零售客戶紀錄中的資料一起刪除-----------------------------------------------------
  411. If DataGridView3.Rows.Count = 1 Then : SQL_出貨單申請_零售客戶記錄表刪除() : conn.Close() : End If : TextBox14.Text = "" : Set_單據明細()
  412. End If
  413. End If
  414. Else
  415. conn.Close() : MsgBox("已入庫的資料不可刪除 。")
  416. End If
  417. End Sub
  418. Private Sub 修改存檔ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 修改存檔ToolStripMenuItem.Click
  419. Me.Button3.PerformClick()
  420. End Sub
  421. Private Sub 列印成EXCELToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 列印成EXCELToolStripMenuItem.Click
  422. Me.Button5.PerformClick()
  423. End Sub
  424. Private Sub 列印產品標籤ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 列印產品標籤ToolStripMenuItem.Click
  425. Me.Button6.PerformClick()
  426. End Sub
  427. End Class