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 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. Option Strict Off
  2. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  3. Imports Microsoft.Office.Interop.Excel.Constants
  4. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  5. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  6. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  7. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  8. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  9. Imports Microsoft.Office.Interop.Excel.XlWindowState
  10. Imports Microsoft.Office.Interop.Excel
  11. Public Class 採購單申請
  12. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet
  13. Dim EDR As Integer = 0 : Dim ESTR As String : Dim N1 As Integer
  14. Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
  15. Private Sub Set_物料清單()
  16. DataGridView1.DataSource = Nothing : ds.Clear() : DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView1.ColumnHeadersHeight = 25
  17. DataGridView1.AllowUserToAddRows = False : DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView1.MultiSelect = True
  18. SQL_採購單申請_物料清單()
  19. da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  20. DataGridView1.Columns(0).FillWeight = 10 : DataGridView1.Columns(1).Visible = False : DataGridView1.Columns(2).FillWeight = 20 : DataGridView1.Columns(3).FillWeight = 5
  21. DataGridView1.Columns(4).Visible = False : DataGridView1.Columns(5).Visible = False : DataGridView1.Columns(6).Visible = False : DataGridView1.Columns(7).Visible = False
  22. DataGridView1.Columns(8).Visible = False : DataGridView1.Columns(9).Visible = False : DataGridView1.Columns(10).Visible = False
  23. DataGridView1.Columns(3).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(4).DefaultCellStyle.Format = "#,##0"
  24. DataGridView1.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  25. DataGridView1.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  26. DataGridView1.Columns(1).ReadOnly = True : DataGridView1.Columns(2).ReadOnly = True : DataGridView1.Columns(3).ReadOnly = True : DataGridView1.Columns(4).ReadOnly = True
  27. DataGridView1.Columns(5).ReadOnly = True : DataGridView1.Columns(6).ReadOnly = True : DataGridView1.Columns(7).ReadOnly = True : DataGridView1.Columns(8).ReadOnly = True
  28. DataGridView1.Columns(9).ReadOnly = True : DataGridView1.Columns(10).ReadOnly = True : DataGridView1.Columns(0).ReadOnly = True
  29. End Sub
  30. Private Sub Set_採購清單()
  31. DataGridView2.DataSource = Nothing : ds1.Clear() : DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView2.ColumnHeadersHeight = 25
  32. DataGridView2.AllowUserToAddRows = False : DataGridView2.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView2.MultiSelect = True
  33. SQL_採購單申請_單號彙總()
  34. da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close()
  35. DataGridView2.Columns(0).FillWeight = 135 : DataGridView2.Columns(1).FillWeight = 90 : DataGridView2.Columns(2).Visible = False : DataGridView2.Columns(3).FillWeight = 100
  36. DataGridView2.Columns(4).FillWeight = 90
  37. End Sub
  38. Private Sub Set_單據明細()
  39. DataGridView3.DataSource = Nothing : ds2.Clear() : DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing : DataGridView3.ColumnHeadersHeight = 25
  40. DataGridView3.AllowUserToAddRows = False : DataGridView3.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText : DataGridView3.MultiSelect = True
  41. SQL_採購單申請明細()
  42. da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close()
  43. TextBox15.Text = "0"
  44. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  45. DataGridView3(1, i).Value = i + 1 : TextBox15.Text = Val(TextBox15.Text) + DataGridView3.Rows(i).Cells("進貨成本_台幣").Value
  46. DataGridView3.Rows(i).Cells("選擇").Value = False
  47. Next
  48. TextBox15.Text = Strings.Format(Val(TextBox15.Text), "#,#00")
  49. DataGridView3.Columns(6).DefaultCellStyle.Format = "#,##0" : DataGridView3.Columns(7).DefaultCellStyle.Format = "#,##0.00"
  50. DataGridView3.Columns(8).DefaultCellStyle.Format = "#,##0.0000" : DataGridView3.Columns(9).DefaultCellStyle.Format = "#,##0" : DataGridView3.Columns(10).DefaultCellStyle.Format = "#,##0"
  51. DataGridView3.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  52. DataGridView3.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  53. DataGridView3.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  54. DataGridView3.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  55. DataGridView3.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  56. DataGridView3.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  57. DataGridView3.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  58. DataGridView3.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView3.Columns(12).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  59. DataGridView3.Columns(0).Visible = False : DataGridView3.Columns(1).FillWeight = 50 : DataGridView3.Columns(2).FillWeight = 80 : DataGridView3.Columns(3).FillWeight = 200
  60. DataGridView3.Columns(4).Visible = False : DataGridView3.Columns(5).Visible = False : DataGridView3.Columns(6).FillWeight = 50 : DataGridView3.Columns(7).FillWeight = 50
  61. DataGridView3.Columns(8).FillWeight = 50 : DataGridView3.Columns(9).FillWeight = 50 : DataGridView3.Columns(10).FillWeight = 65 : DataGridView3.Columns(11).FillWeight = 100
  62. DataGridView3.Columns(12).FillWeight = 80 : DataGridView3.Columns(13).Visible = False : DataGridView3.Columns(14).Visible = False : DataGridView3.Columns(15).Visible = False
  63. DataGridView3.Columns(16).Visible = False : DataGridView3.Columns(17).FillWeight = 50
  64. DataGridView3.EditMode = DataGridViewEditMode.EditOnEnter
  65. DataGridView3.Columns(1).ReadOnly = True : DataGridView3.Columns(2).ReadOnly = True : DataGridView3.Columns(3).ReadOnly = True : DataGridView3.Columns(4).ReadOnly = True
  66. DataGridView3.Columns(5).ReadOnly = True : DataGridView3.Columns(8).ReadOnly = True : DataGridView3.Columns(9).ReadOnly = True : DataGridView3.Columns(10).ReadOnly = True
  67. DataGridView3.Columns(12).ReadOnly = True
  68. End Sub
  69. Private Sub ComboBox1下拉表單資料載入()
  70. SQL_物料頁碼清單()
  71. ComboBox1.Items.Clear() : While (dr.Read()) : ComboBox1.Items.Add(dr("頁碼")) : End While : conn.Close()
  72. End Sub
  73. Private Sub ComboBox2下拉表單資料載入()
  74. SQL_供應商資料表下拉清單()
  75. ComboBox2.Items.Clear() : ComboBox3.Items.Clear() : While (dr.Read()) : ComboBox2.Items.Add(dr("簡稱")) : ComboBox3.Items.Add(dr("編號")) : End While : conn.Close()
  76. End Sub
  77. Private Sub 採購單申請_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  78. Me.MdiParent = MAOJI_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  79. TextBox9.Enabled = False : TextBox7.Enabled = False : TextBox14.Enabled = False : RadioButton1.Checked = True : ComboBox3.Visible = False
  80. ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : Set_採購清單() : Set_物料清單()
  81. End Sub
  82. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  83. If e.RowIndex = -1 Then : Else
  84. TextBox7.Text = DataGridView1.Rows(e.RowIndex).Cells("料號").Value.ToString
  85. NumericUpDown2.Value = DataGridView1.Rows(e.RowIndex).Cells("成本").Value.ToString
  86. End If
  87. End Sub
  88. Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  89. If e.RowIndex = -1 Then : Else
  90. TextBox9.Text = DataGridView2.Rows(e.RowIndex).Cells("單據編號").Value.ToString : ComboBox3.Text = DataGridView2.Rows(e.RowIndex).Cells("供應商編號").Value.ToString
  91. DateTimePicker1.Value = DataGridView2.Rows(e.RowIndex).Cells("採購下單").Value.ToString : DateTimePicker2.Value = DataGridView2.Rows(e.RowIndex).Cells("交期").Value.ToString
  92. Set_單據明細()
  93. End If
  94. End Sub
  95. Private Sub DataGridView3_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView3.CellClick
  96. If e.RowIndex = -1 Then : Else
  97. TextBox14.Text = DataGridView3.Rows(e.RowIndex).Cells("資料流水號").Value.ToString
  98. For i As Integer = 0 To DataGridView3.Rows.Count - 1 : DataGridView3.Rows(i).Cells("選擇").Value = False : Next
  99. DataGridView3.Rows(e.RowIndex).Cells("選擇").Value = True
  100. End If
  101. End Sub
  102. Private Sub DataGridView3_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView3.CellEnter
  103. TextBox15.Text = "0"
  104. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  105. DataGridView3.Rows(i).Cells("台幣單價").Value = DataGridView3.Rows(i).Cells("單價").Value * DataGridView3.Rows(i).Cells("匯率").Value
  106. DataGridView3.Rows(i).Cells("進貨成本_台幣").Value = DataGridView3.Rows(i).Cells("單價").Value * DataGridView3.Rows(i).Cells("匯率").Value * DataGridView3.Rows(i).Cells("數量").Value
  107. DataGridView3(1, i).Value = i + 1
  108. TextBox15.Text = Val(TextBox15.Text) + DataGridView3.Rows(i).Cells("進貨成本_台幣").Value
  109. Next i
  110. TextBox15.Text = Strings.Format(Val(TextBox15.Text), "#,#00")
  111. End Sub
  112. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged
  113. Set_物料清單()
  114. End Sub
  115. Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  116. Set_物料清單()
  117. End Sub
  118. Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
  119. PA = TextBox5.Text
  120. SQL_供應商資料表關鍵字查詢()
  121. ComboBox2.Items.Clear() : ComboBox3.Items.Clear() : While (dr.Read()) : ComboBox2.Items.Add(dr("簡稱")) : ComboBox3.Items.Add(dr("編號")) : End While : conn.Close() : PA = ""
  122. End Sub
  123. Private Sub 供應商資料()
  124. SQL_採購單申請_供應商資料表讀取()
  125. If (dr.Read()) Then
  126. TextBox2.Text = dr("名稱") : TextBox6.Text = dr("公司電話1") : TextBox3.Text = dr("公司電話2") : TextBox8.Text = dr("傳真1") : TextBox11.Text = dr("郵遞區號1")
  127. TextBox10.Text = dr("地址1") : TextBox13.Text = dr("郵遞區號2") : TextBox12.Text = dr("地址2") : TextBox26.Text = dr("統一編號") : TextBox4.Text = dr("付款方式")
  128. End If : conn.Close()
  129. End Sub
  130. Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
  131. ComboBox3.SelectedIndex = ComboBox2.SelectedIndex : 供應商資料()
  132. End Sub
  133. Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
  134. ComboBox2.SelectedIndex = ComboBox3.SelectedIndex : 供應商資料()
  135. End Sub
  136. Private Sub Set_日期格式轉換()
  137. DTP = Strings.Format(DateTimePicker1.Value, "yyyy/MM/dd") : DTP1 = Strings.Format(DateTimePicker1.Value, "yyyyMMdd") : DTP2 = Strings.Format(DateTimePicker2.Value, "yyyy/MM/dd")
  138. End Sub
  139. Private Sub Set_自動生成流水號()
  140. SQL_倉儲明細表流水號最後一筆()
  141. If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("資料流水號").ToString, 8)) : Else : EDR = 0 : End If : conn.Close() : EDR += 1
  142. If EDR < 10 Then : ESTR = "WD" & "0000000" & EDR
  143. ElseIf EDR > 9 And EDR < 100 Then : ESTR = "WD" & "000000" & EDR
  144. ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "WD" & "00000" & EDR
  145. ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "WD" & "0000" & EDR
  146. ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "WD" & "000" & EDR
  147. ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "WD" & "00" & EDR
  148. ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "WD" & "0" & EDR
  149. ElseIf EDR > 9999999 Then : ESTR = "WD" & EDR
  150. End If
  151. End Sub
  152. Private Sub Set_新增明細()
  153. PA1 = TextBox7.Text : SQL_物料資料庫成本查詢()
  154. If dr.Read() Then
  155. If dr("成本") = 0 Then : NU1 = NumericUpDown2.Value : PA1 = TextBox7.Text : SQL_物料資料庫成本修改() : conn.Close() : Else : conn.Close() : End If
  156. End If
  157. PA1 = ESTR : PA2 = TextBox9.Text : PA3 = ComboBox3.Text : PA4 = TextBox7.Text : NU1 = NumericUpDown2.Value : NU2 = NumericUpDown3.Value
  158. NU3 = NumericUpDown1.Value : NU4 = 0 : PA5 = "採購入庫" : PA6 = DTP : PA7 = "" : NU5 = 0 : PA8 = "" : PA9 = DTP2
  159. SQL_倉儲明細表新增() : conn.Close()
  160. MsgBox("資料新增完畢 。") : Set_單據明細() : Set_物料清單()
  161. End Sub
  162. Private Sub 存檔1()
  163. Dim SSDD As Integer = 0
  164. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  165. 資料數 = DataGridView3.Rows.Count : MyModule1.進度條()
  166. PA1 = DataGridView3.Rows(i).Cells("資料流水號").Value : SQL_倉儲明細表_入庫日期讀取()
  167. If dr.Read() Then
  168. If dr("入庫日期").ToString = "" Then
  169. NU1 = DataGridView3.Rows(i).Cells("單價").Value : NU2 = DataGridView3.Rows(i).Cells("數量").Value
  170. PA1 = DataGridView3.Rows(i).Cells("備註").Value : PA2 = DTP2 : PA3 = DataGridView3.Rows(i).Cells("資料流水號").Value
  171. SQL_採購單申請_倉儲明細表修改_入庫() : conn.Close()
  172. Else
  173. conn.Close() : SSDD += 1
  174. End If
  175. End If
  176. Next : MAOJI_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : If SSDD = 0 Then : Else : MsgBox("共有 " & SSDD & "筆資料已入庫,沒有變更。") : End If
  177. End Sub
  178. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  179. If TextBox7.Text = "" Then : MsgBox("料號沒有選擇") : Else
  180. If ComboBox3.Text = "" Then : MsgBox("供應商沒有選擇") : Else
  181. If NumericUpDown3.Value = 0 Then : MsgBox("採購金額沒有填寫") : Else
  182. If NumericUpDown2.Value = 0 Then : MsgBox("匯率不可為零") : Else
  183. If NumericUpDown1.Value = 0 Then : MsgBox("數量不可為零") : Else
  184. If TextBox9.Text = "" Then
  185. '----------------------自动生成單據編號-------------------------------------------------------------------------
  186. If CheckBox1.Checked = True Then : Else : DateTimePicker1.Value = Today() : End If
  187. Dim NUM1 As Integer : Set_日期格式轉換()
  188. For i As Integer = 1 To 999
  189. NUM1 = 0 + i
  190. If NUM1 < 10 Then : TextBox9.Text = "WD-" & DTP1 & "-00" & NUM1
  191. ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox9.Text = "WD-" & DTP1 & "-0" & NUM1
  192. ElseIf NUM1 > 99 Then : TextBox9.Text = "WD-" & DTP1 & "-" & NUM1 : End If : PA1 = TextBox9.Text
  193. SQL_倉儲明細表生成單據編號()
  194. If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
  195. Next
  196. Set_自動生成流水號() : TextBox14.Text = ESTR : conn.Close() : 存檔1() : Set_新增明細() : Set_採購清單()
  197. Else
  198. Set_日期格式轉換() : Set_自動生成流水號() : TextBox14.Text = ESTR : conn.Close() : 存檔1() : Set_新增明細()
  199. End If
  200. End If
  201. End If
  202. End If
  203. End If
  204. End If
  205. End Sub
  206. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  207. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  208. 資料數 = DataGridView3.Rows.Count : MyModule1.進度條()
  209. NU1 = NumericUpDown3.Value : PA1 = DataGridView3.Rows(i).Cells("資料流水號").Value : SQL_採購單申請_倉儲明細表匯率修改() : conn.Close()
  210. Next : MAOJI_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : Set_單據明細() : MsgBox("資料修改,存檔完畢 。")
  211. End Sub
  212. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  213. Set_日期格式轉換() : 存檔1() : Set_單據明細() : Set_採購清單() : MsgBox("資料修改,存檔完畢 。")
  214. End Sub
  215. Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.Click
  216. RadioButton1.Checked = True : RadioButton2.Checked = False : Set_採購清單() : Button1.Enabled = True : Button2.Enabled = True : Button3.Enabled = True
  217. 新增物料到採購單ToolStripMenuItem.Enabled = True : 刪除採購單中選中的物料ToolStripMenuItem.Enabled = True : 修改匯率ToolStripMenuItem.Enabled = True
  218. 修改存檔ToolStripMenuItem.Enabled = True
  219. End Sub
  220. Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.Click
  221. If CC(35) = False Then
  222. RadioButton1.Checked = False : RadioButton2.Checked = True : Set_採購清單() : Button1.Enabled = False : Button2.Enabled = False : Button3.Enabled = False
  223. 新增物料到採購單ToolStripMenuItem.Enabled = False : 刪除採購單中選中的物料ToolStripMenuItem.Enabled = False : 修改匯率ToolStripMenuItem.Enabled = False
  224. 修改存檔ToolStripMenuItem.Enabled = False
  225. Else
  226. RadioButton1.Checked = False : RadioButton2.Checked = True : Set_採購清單() : Button1.Enabled = True : Button2.Enabled = True : Button3.Enabled = True
  227. 新增物料到採購單ToolStripMenuItem.Enabled = True : 刪除採購單中選中的物料ToolStripMenuItem.Enabled = True : 修改匯率ToolStripMenuItem.Enabled = True
  228. 修改存檔ToolStripMenuItem.Enabled = True
  229. End If
  230. End Sub
  231. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  232. '----------------------自动生成單據編號-------------------------------------------------------------------------
  233. Dim NUM1 As Integer : Set_日期格式轉換()
  234. For i As Integer = 1 To 999
  235. NUM1 = 0 + i
  236. If NUM1 < 10 Then : TextBox9.Text = "WD-" & DTP1 & "-00" & NUM1
  237. ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox9.Text = "WD-" & DTP1 & "-0" & NUM1
  238. ElseIf NUM1 > 99 Then : TextBox9.Text = "WD-" & DTP1 & "-" & NUM1 : End If : PA1 = TextBox9.Text
  239. SQL_倉儲明細表生成單據編號()
  240. If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
  241. Next
  242. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  243. 資料數 = DataGridView3.Rows.Count : MyModule1.進度條()
  244. PA1 = DataGridView3.Rows(i).Cells("料號").Value
  245. SQL_物料資料庫成本查詢()
  246. If dr.Read() Then
  247. If dr("成本") = 0 Then : NU1 = DataGridView3.Rows(i).Cells("單價").Value : PA1 = DataGridView3.Rows(i).Cells("料號").Value
  248. SQL_物料資料庫成本修改() : conn.Close()
  249. Else : conn.Close() : End If
  250. End If
  251. Set_自動生成流水號() : TextBox14.Text = ESTR
  252. PA1 = ESTR : PA2 = TextBox9.Text : PA3 = DataGridView3.Rows(i).Cells("供應商編號").Value : PA4 = DataGridView3.Rows(i).Cells("料號").Value : NU1 = DataGridView3.Rows(i).Cells("單價").Value
  253. NU2 = DataGridView3.Rows(i).Cells("匯率").Value : NU3 = DataGridView3.Rows(i).Cells("數量").Value : NU4 = 0 : PA5 = "採購入庫" : PA6 = DTP : PA7 = "" : NU5 = 0 : PA8 = "" : PA9 = DTP2
  254. SQL_倉儲明細表新增() : conn.Close()
  255. Next : MAOJI_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : MsgBox("單據複製完畢 。") : Set_物料清單()
  256. End Sub
  257. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  258. If TextBox9.Text = "" Then : MsgBox("沒有選擇要列印的單號 。") : Else : 列印用SQL = TextBox9.Text : PA = "採購訂貨單" : 列印_產品標籤介面.ShowDialog() : End If
  259. End Sub
  260. '-----------------------------列印成EXCEL------------------------------------------------------------------------------------------------------------------------------------------
  261. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  262. xlApp = CType(CreateObject("Excel.Application"), Application)
  263. xlBook = xlApp.Workbooks.Add
  264. xlApp.DisplayAlerts = True
  265. xlBook.Activate()
  266. xlSheet = NewMethod(xlBook)
  267. xlSheet.Activate()
  268. xlApp.Visible = True
  269. xlApp.Application.WindowState = xlMaximized
  270. xlSheet.Cells(1, 1) = MAOJI_ERP_SYS.ComboBox2.Text : xlSheet.Cells(2, 1) = 公司地址 : xlSheet.Cells(3, 1) = "採購訂單" : xlSheet.Cells(4, 1) = "採購編號 : " : xlSheet.Cells(4, 3) = TextBox9.Text
  271. xlSheet.Cells(5, 1) = "採購日期 : " : xlSheet.Cells(5, 3) = DateTimePicker1.Value : xlSheet.Cells(5, 6) = "付款方式 : " : xlSheet.Cells(5, 7) = TextBox4.Text : xlSheet.Cells(5, 9) = "需求交期 : "
  272. xlSheet.Cells(5, 10) = DateTimePicker2.Value : xlSheet.Cells(4, 9) = "統一編號 : " : xlSheet.Cells(4, 10) = 公司統編 : xlSheet.Cells(7, 1) = "TO : " : xlSheet.Cells(8, 1) = "郵號1 : "
  273. xlSheet.Cells(9, 1) = "郵號1 : " : xlSheet.Cells(7, 2) = TextBox2.Text : xlSheet.Cells(8, 2) = TextBox11.Text : xlSheet.Cells(9, 2) = TextBox13.Text : xlSheet.Cells(8, 3) = "地址1 : "
  274. xlSheet.Cells(9, 3) = "地址2 : " : xlSheet.Cells(8, 4) = TextBox10.Text : xlSheet.Cells(9, 4) = TextBox12.Text : xlSheet.Cells(7, 9) = "公司電話1 : " : xlSheet.Cells(8, 9) = "公司電話2 : "
  275. xlSheet.Cells(9, 9) = "傳真 : " : xlSheet.Cells(7, 10) = TextBox6.Text : xlSheet.Cells(8, 10) = TextBox3.Text : xlSheet.Cells(9, 10) = TextBox8.Text : xlSheet.Cells(11, 1) = "項次"
  276. xlSheet.Cells(11, 2) = "料號" : xlSheet.Cells(11, 4) = "品名" : xlSheet.Cells(11, 6) = "數量" : xlSheet.Cells(11, 7) = "單價" : xlSheet.Cells(11, 8) = "匯率" : xlSheet.Cells(11, 9) = "採購金額"
  277. xlSheet.Cells(11, 10) = "備註"
  278. For i As Integer = 0 To DataGridView3.Rows.Count - 1
  279. xlSheet.Cells(i + 12, 1) = DataGridView3.Rows(i).Cells("項次").Value
  280. xlSheet.Cells(i + 12, 2) = DataGridView3.Rows(i).Cells("料號").Value
  281. xlSheet.Cells(i + 12, 4) = DataGridView3.Rows(i).Cells("品名").Value
  282. xlSheet.Cells(i + 12, 6) = DataGridView3.Rows(i).Cells("數量").Value
  283. xlSheet.Cells(i + 12, 7) = DataGridView3.Rows(i).Cells("單價").Value
  284. xlSheet.Cells(i + 12, 8) = DataGridView3.Rows(i).Cells("匯率").Value
  285. xlSheet.Cells(i + 12, 9) = "=F" & i + 12 & "*G" & i + 12 & "*H" & i + 12
  286. xlSheet.Cells(i + 12, 10) = DataGridView3.Rows(i).Cells("備註").Value
  287. N1 = i + 12
  288. Next
  289. xlSheet.Cells(N1 + 1, 5) = "TOTAL : " : xlSheet.Cells(N1 + 1, 6) = "=SUM(F12:F" & N1 & ")" : xlSheet.Cells(N1 + 1, 9) = "=SUM(I12:I" & N1 & ")" : xlSheet.Cells(N1 + 2, 1) = "核准 : "
  290. xlSheet.Cells(N1 + 2, 9) = "製表人 : " : xlSheet.Cells(N1 + 2, 10) = gUserName
  291. AA(xlApp, xlSheet)
  292. xlSheet.PageSetup.PrintArea = ""
  293. xlApp.Cells.Select()
  294. xlSheet.Range("B1").Select()
  295. xlApp.Application.WindowState = xlMinimized
  296. xlSheet.Cells.Select()
  297. xlApp.ActiveSheet.Protect(DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="0911274990")
  298. xlApp.ActiveSheet.EnableSelection = 1
  299. MsgBox("列印完成。")
  300. End Sub
  301. Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
  302. Return CType(xlBook.Worksheets.Add, Worksheet)
  303. End Function
  304. Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  305. xlSheet.Cells.Select()
  306. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  307. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  308. xlSheet.Columns("A:C").Select : myExcel.Selection.ColumnWidth = 6
  309. xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 10
  310. xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 20
  311. xlSheet.Columns("F:G").Select : myExcel.Selection.ColumnWidth = 10
  312. xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 8
  313. xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 12
  314. xlSheet.Columns("J:J").Select : myExcel.Selection.ColumnWidth = 30
  315. xlSheet.Rows("1:1").Select
  316. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 28 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  317. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  318. xlSheet.Rows("2:2").Select
  319. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 16 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  320. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  321. xlSheet.Rows("3:3").Select
  322. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  323. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  324. xlSheet.Range("A1:J1").Select()
  325. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  326. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  327. xlSheet.Range("A2:J2").Select()
  328. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  329. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  330. xlSheet.Range("A3:J3").Select()
  331. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  332. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  333. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  334. myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
  335. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  336. myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  337. xlSheet.Range("A4:B4").Select()
  338. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  339. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  340. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  341. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  342. xlSheet.Range("A5:B5").Select()
  343. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  344. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  345. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  346. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  347. xlSheet.Range("C4:D4").Select()
  348. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  349. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  350. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  351. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  352. xlSheet.Range("C5:D5").Select()
  353. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  354. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  355. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  356. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  357. xlSheet.Range("J4").Select()
  358. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  359. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  360. xlSheet.Range("J5").Select()
  361. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  362. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  363. xlSheet.Range("A7:A9").Select()
  364. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  365. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  366. xlSheet.Range("I4:I9").Select()
  367. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  368. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  369. xlSheet.Range("B8").Select()
  370. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  371. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  372. xlSheet.Range("C8:C9").Select()
  373. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  374. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  375. xlSheet.Rows("4:9").Select : myExcel.Selection.RowHeight = 18
  376. xlSheet.Rows("6:6").Select : myExcel.Selection.RowHeight = 5
  377. xlSheet.Rows("10:10").Select : myExcel.Selection.RowHeight = 5
  378. xlSheet.Rows("11:11").Select : myExcel.Selection.RowHeight = 25
  379. xlSheet.Rows("12:" & N1 + 1).Select : myExcel.Selection.RowHeight = 18
  380. xlSheet.Rows(N1 + 2 & ":" & N1 + 2).Select : myExcel.Selection.RowHeight = 30
  381. xlSheet.Range("A4:B5").Select()
  382. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  383. xlSheet.Range("F5").Select()
  384. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  385. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  386. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  387. xlSheet.Range("I4:I5").Select()
  388. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  389. xlSheet.Range("A5:J5").Select()
  390. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  391. myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
  392. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  393. myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  394. xlSheet.Range("A7:A9").Select()
  395. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  396. xlSheet.Range("C8:C9").Select()
  397. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  398. xlSheet.Range("I7:I9").Select()
  399. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  400. xlSheet.Range("A9:J9").Select()
  401. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  402. myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
  403. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlMedium : End With
  404. myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  405. xlSheet.Range("A11:J" & N1).Select()
  406. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  407. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  408. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  409. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  410. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  411. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  412. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  413. xlSheet.Range("A" & N1 + 1 & ":J" & N1 + 1).Select()
  414. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  415. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  416. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  417. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  418. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  419. myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  420. xlSheet.Range("A11:A" & N1).Select()
  421. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  422. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  423. For i As Integer = 11 To N1
  424. xlSheet.Range("B" & i & ":C" & i).Select()
  425. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
  426. .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  427. xlSheet.Range("D" & i & ":E" & i).Select()
  428. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
  429. .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  430. Next
  431. xlSheet.Range("F11:F" & N1 + 1).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
  432. xlSheet.Range("F11").Select()
  433. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  434. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  435. xlSheet.Range("G11:G" & N1).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0.0_-;-* #,##0.0_-;_-* ""-""??_-;_-@_-"
  436. xlSheet.Range("G11").Select()
  437. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  438. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  439. xlSheet.Range("H11:H" & N1).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0.000_-;-* #,##0.000_-;_-* ""-""??_-;_-@_-"
  440. xlSheet.Range("H11").Select()
  441. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  442. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  443. xlSheet.Range("I11:I" & N1 + 1).Select() : myExcel.Selection.Style = "Comma" : myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
  444. xlSheet.Range("I11").Select()
  445. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  446. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  447. xlSheet.Range("E" & N1 + 1).Select()
  448. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  449. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  450. xlSheet.Range("A" & N1 + 2).Select()
  451. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  452. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  453. xlSheet.Range("I" & N1 + 2).Select()
  454. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  455. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  456. myExcel.ActiveWindow.DisplayGridlines = False
  457. End Sub
  458. '-----------------------------滑鼠右鍵------------------------------------------------------------------------------------------------------------------------------------------
  459. Private Sub 重新整理ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 重新整理ToolStripMenuItem.Click
  460. Set_採購清單() : Set_物料清單() : ComboBox2下拉表單資料載入()
  461. End Sub
  462. Private Sub 開立新的採購單ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 開立新的採購單ToolStripMenuItem.Click
  463. If CheckBox1.Checked = True Then : Else : DateTimePicker1.Value = Today() : End If
  464. TextBox9.Text = "" : TextBox15.Text = "0" : DateTimePicker1.Value = Today() : TextBox14.Text = ""
  465. TextBox2.Text = "" : TextBox6.Text = "" : TextBox3.Text = "" : TextBox8.Text = "" : TextBox11.Text = ""
  466. TextBox10.Text = "" : TextBox13.Text = "" : TextBox12.Text = "" : TextBox26.Text = "" : TextBox4.Text = ""
  467. ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : Set_採購清單() : Set_物料清單()
  468. DataGridView3.DataSource = Nothing : ds2.Clear() : Me.RadioButton1.PerformClick()
  469. End Sub
  470. Private Sub 刪除採購單中選中的物料ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 刪除採購單中選中的物料ToolStripMenuItem.Click
  471. PA1 = TextBox14.Text : SQL_倉儲明細表_入庫日期讀取()
  472. If dr("入庫日期") = "" Then : conn.Close()
  473. If TextBox14.Text = "" Then : MsgBox("沒有選擇要刪除了料號 。")
  474. Else
  475. Dim aa1 As MsgBoxResult = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  476. If aa1 = MsgBoxResult.Ok Then
  477. PA1 = TextBox14.Text : SQL_倉儲明細表刪除() : conn.Close() : TextBox14.Text = "" : Set_單據明細()
  478. End If
  479. End If
  480. Else
  481. conn.Close() : MsgBox("已入庫的資料不可刪除 。")
  482. End If
  483. End Sub
  484. Private Sub 新增物料到採購單ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 新增物料到採購單ToolStripMenuItem.Click
  485. Me.Button1.PerformClick()
  486. End Sub
  487. Private Sub 修改匯率ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 修改匯率ToolStripMenuItem.Click
  488. Me.Button2.PerformClick() : MsgBox("資料修改,存檔完畢 。")
  489. End Sub
  490. Private Sub 修改存檔ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 修改存檔ToolStripMenuItem.Click
  491. Me.Button3.PerformClick() : MsgBox("資料修改,存檔完畢 。")
  492. End Sub
  493. Private Sub 列印成EXCELToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 列印成EXCELToolStripMenuItem.Click
  494. Me.Button5.PerformClick()
  495. End Sub
  496. Private Sub 列印產品標籤ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 列印產品標籤ToolStripMenuItem.Click
  497. Me.Button6.PerformClick()
  498. End Sub
  499. End Class