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.

樣品INVOICE.vb 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. Option Strict Off
  2. Imports System.Text.RegularExpressions
  3. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  4. Imports Microsoft.Office.Interop.Excel.Constants
  5. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  6. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  7. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  8. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  9. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  10. Imports Microsoft.Office.Interop.Excel.XlWindowState
  11. Imports Microsoft.Office.Interop.Excel
  12. Public Class 樣品INVOICE
  13. Private ReadOnly ds, ds2, ds3 As New DataSet
  14. Dim DDFF, BBNN11, AAWW, HHGG As String
  15. Dim N1, BBNN1 As Integer
  16. Private ReadOnly RRTT As New Regex("[\u4e00-\u9fa5]")
  17. Dim 已超出 As Boolean
  18. Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
  19. Private Sub Set_DGV2載入前設定()
  20. 表單2_dgv.DataSource = Nothing : ds2.Clear()
  21. 表單2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  22. 表單2_dgv.ColumnHeadersHeight = 25
  23. 表單2_dgv.AllowUserToAddRows = False
  24. 表單2_dgv.RowTemplate.Height = 25
  25. End Sub
  26. Private Sub Set_DGV2載入後設定()
  27. da.Fill(ds2) : 表單2_dgv.DataSource = ds2.Tables(0) : conn.Close() : Set_grid()
  28. End Sub
  29. Private Sub Set_清單()
  30. Set_DGV2載入前設定()
  31. SQL_樣品INVOICE表單2()
  32. Set_DGV2載入後設定()
  33. End Sub
  34. Private Sub Set_grid()
  35. 表單2_dgv.Columns(0).Width = 195 : 表單2_dgv.Columns(1).Width = 265 : 表單2_dgv.Columns(2).Width = 165 : 表單2_dgv.Columns(3).Width = 100 : 表單2_dgv.Columns(4).Width = 100
  36. End Sub
  37. Private Sub Set_DGV1載入前設定()
  38. 表單1_dgv.DataSource = Nothing : ds.Clear()
  39. 表單1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  40. 表單1_dgv.ColumnHeadersHeight = 25
  41. 表單1_dgv.AllowUserToAddRows = False
  42. 表單1_dgv.RowTemplate.Height = 50
  43. End Sub
  44. Private Sub Set_DGV1載入後設定()
  45. da.Fill(ds) : 表單1_dgv.DataSource = ds.Tables(0) : conn.Close() : Set_grid1()
  46. End Sub
  47. Private Sub Set_清單1()
  48. Set_DGV1載入前設定()
  49. SQL_樣品INVOICE表單1()
  50. Set_DGV1載入後設定()
  51. End Sub
  52. Private Sub Set_grid1()
  53. 表單1_dgv.Columns(0).Width = 100 : 表單1_dgv.Columns(1).Width = 100 : 表單1_dgv.Columns(2).Width = 85 : 表單1_dgv.Columns(3).Width = 100 : 表單1_dgv.Columns(4).Width = 100
  54. 表單1_dgv.Columns(5).Width = 163 : 表單1_dgv.Columns(6).Width = 162 : 表單1_dgv.Columns(7).Width = 50 : 表單1_dgv.Columns(8).Width = 50 : 表單1_dgv.Columns(9).Width = 50
  55. 表單1_dgv.Columns(10).Width = 50 : 表單1_dgv.Columns(11).Visible = False
  56. 表單1_dgv.Columns(8).DefaultCellStyle.Format = "#,##0.0" : 表單1_dgv.Columns(9).DefaultCellStyle.Format = "#,##0.0" : 表單1_dgv.Columns(10).DefaultCellStyle.Format = "#,##0.0"
  57. 表單1_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  58. 表單1_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 表單1_dgv.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  59. 表單1_dgv.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  60. 表單1_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight : 表單1_dgv.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  61. For i As Integer = 0 To 表單1_dgv.Rows.Count - 1
  62. 資料數 = 表單1_dgv.Rows.Count : MyModule1.進度條()
  63. PA = 表單1_dgv.Rows(i).Cells("對應流水號").Value
  64. SQL_第一筆材料名稱()
  65. If (dr.Read()) Then : DDFF = dr("材料名稱") : Else : DDFF = "" : End If : conn.Close()
  66. '--------------------------------------------------------------------------------------------
  67. BBNN1 = DDFF.Length.ToString()
  68. For II As Integer = 0 To BBNN1 - 1
  69. If II = 0 Then
  70. AAWW = Strings.Left(DDFF, 1)
  71. If RRTT.IsMatch(AAWW) Then : Else : BBNN11 = Strings.Left(DDFF, 1) : End If
  72. Else
  73. AAWW = Strings.Mid(DDFF, II + 1, 1) : If RRTT.IsMatch(AAWW) Then : Else : HHGG = BBNN11 : BBNN11 = HHGG & AAWW : End If
  74. End If
  75. Next : 表單1_dgv.Rows(i).Cells("Upper Material").Value = BBNN11
  76. '--------------------------------------------------------------------------------------------
  77. SQL_第一筆材料名稱1()
  78. If (dr.Read()) Then : DDFF = dr("材料名稱") : Else : DDFF = "" : End If : conn.Close()
  79. '--------------------------------------------------------------------------------------------
  80. BBNN1 = DDFF.Length.ToString()
  81. For II As Integer = 0 To BBNN1 - 1
  82. If II = 0 Then
  83. AAWW = Strings.Left(DDFF, 1)
  84. If RRTT.IsMatch(AAWW) Then : Else : BBNN11 = Strings.Left(DDFF, 1) : End If
  85. Else
  86. AAWW = Strings.Mid(DDFF, II + 1, 1) : If RRTT.IsMatch(AAWW) Then : Else : HHGG = BBNN11 : BBNN11 = HHGG & AAWW : End If
  87. End If
  88. Next : 表單1_dgv.Rows(i).Cells("Outsole Material").Value = BBNN11
  89. '--------------------------------------------------------------------------------------------
  90. Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
  91. End Sub
  92. Private Sub Set_DGV3載入前設定()
  93. 表單3_dgv.DataSource = Nothing : ds3.Clear()
  94. 表單3_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  95. 表單3_dgv.ColumnHeadersHeight = 25
  96. 表單3_dgv.AllowUserToAddRows = False
  97. End Sub
  98. Private Sub Set_DGV3載入後設定()
  99. da.Fill(ds3) : 表單3_dgv.DataSource = ds3.Tables(0) : conn.Close() : Set_grid4()
  100. End Sub
  101. Private Sub Set_清單3()
  102. Set_DGV3載入前設定()
  103. SQL_樣品INVOICE表單3()
  104. Set_DGV3載入後設定()
  105. End Sub
  106. Private Sub Set_grid4()
  107. 表單3_dgv.Columns(0).Width = 85 : 表單3_dgv.Columns(1).Width = 140 : 表單3_dgv.Columns(2).Width = 60 : 表單3_dgv.Columns(3).Width = 40 : 表單3_dgv.Columns(4).Width = 120
  108. 表單3_dgv.Columns(5).Width = 140 : 表單3_dgv.Columns(6).Width = 120 : 表單3_dgv.Columns(7).Width = 40 : 表單3_dgv.Columns(8).Width = 40 : 表單3_dgv.Columns(9).Width = 40
  109. 表單3_dgv.Columns(10).Visible = False
  110. 表單3_dgv.Columns(7).DefaultCellStyle.Format = "#,##0.0" : 表單3_dgv.Columns(8).DefaultCellStyle.Format = "#,##0.0" : 表單3_dgv.Columns(9).DefaultCellStyle.Format = "#,##0.0"
  111. 表單3_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 表單3_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  112. 表單3_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  113. 表單3_dgv.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight : 表單3_dgv.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  114. 表單3_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  115. End Sub
  116. Private Sub ComboBox1下拉表單資料載入()
  117. SQL_下拉ATTN()
  118. ATTN_cb.Items.Clear() : While (dr.Read()) : ATTN_cb.Items.Add(dr("ATTN")) : End While : conn.Close()
  119. End Sub
  120. Private Sub 樣品INVOICE_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  121. WINPROFIT_ERP_SYS.WindowState = 2 : Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  122. SQL_修改樣品訂單清單3() : conn.Close()
  123. SQL_修改樣品訂單清單4() : conn.Close()
  124. ComboBox1下拉表單資料載入()
  125. Set_清單3() : Set_清單()
  126. 材質_cb.Text = "NA" : Custon_cb.Text = "NA" : GenderSizeFoot_cb.Text = "NA"
  127. 資料存檔_bt.Enabled = False : 修改存檔_bt.Enabled = False : 新增1_bt.Enabled = False : 刪除1_bt.Enabled = False : 新增_bt.Enabled = False
  128. 刪除_bt.Enabled = False : 可寄出數_tb.Enabled = False : 流水號_tb.Enabled = False
  129. 表單2_dgv.Visible = True : 表單3_dgv.Visible = False
  130. End Sub
  131. Private Sub 樣品INVOICE_Unload(sender As Object, e As EventArgs) Handles MyBase.Closing
  132. If 資料存檔_bt.Enabled = True Then
  133. SQL_刪除INVOICE樣品單() : conn.Close()
  134. End If
  135. End Sub
  136. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 表單1_dgv.CellClick
  137. If e.RowIndex = -1 Then : Else
  138. 流水號_tb.Text = 表單1_dgv.Rows(e.RowIndex).Cells("對應流水號").Value : 本次寄出數_tb.Text = 表單1_dgv.Rows(e.RowIndex).Cells("PAIRS").Value
  139. End If
  140. End Sub
  141. Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 表單2_dgv.CellClick
  142. If e.RowIndex = -1 Then : Else
  143. UPS_tb.Text = 表單2_dgv.Rows(e.RowIndex).Cells("UPS").Value
  144. ATTN_cb.Text = 表單2_dgv.Rows(e.RowIndex).Cells("ATTN").Value
  145. Custon_cb.Text = 表單2_dgv.Rows(e.RowIndex).Cells("CARTON").Value
  146. 日期_tb.Text = 表單2_dgv.Rows(e.RowIndex).Cells("DATE").Value
  147. Set_清單1()
  148. End If
  149. End Sub
  150. Private Sub DataGridView3_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 表單3_dgv.CellClick
  151. If e.RowIndex = -1 Then : Else
  152. 流水號_tb.Text = 表單3_dgv.Rows(e.RowIndex).Cells("流水號").Value
  153. 可寄出數_tb.Text = 表單3_dgv.Rows(e.RowIndex).Cells("數量").Value - 表單3_dgv.Rows(e.RowIndex).Cells("KEEP").Value - 表單3_dgv.Rows(e.RowIndex).Cells("寄出").Value
  154. 可寄出數_tb.Text = Strings.Format(Val(可寄出數_tb.Text), "#,##0.0")
  155. End If
  156. End Sub
  157. Private Sub DataGridView3_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 表單3_dgv.RowPostPaint
  158. Dim linePen As New Pen(Color.Blue, 2)
  159. If e.RowIndex = 表單3_dgv.Rows.Count - 1 Then
  160. Exit Sub
  161. Else
  162. If 表單3_dgv(4, e.RowIndex).Value.ToString <> 表單3_dgv(4, e.RowIndex + 1).Value.ToString Then
  163. Dim startX As Integer = IIf(表單3_dgv.RowHeadersVisible, 表單3_dgv.RowHeadersWidth, 0)
  164. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  165. Dim endX As Integer = startX + 表單3_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 表單3_dgv.HorizontalScrollingOffset
  166. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  167. Exit Sub
  168. End If
  169. End If
  170. End Sub
  171. Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles 本次寄出數_tb.TextChanged
  172. If 本次寄出數_tb.Text = "" Then
  173. 本次寄出數_tb.Text = "0"
  174. Else
  175. End If
  176. End Sub
  177. Private Sub Button18_Click(sender As Object, e As EventArgs) Handles 新增清單_bt.Click
  178. 清單修改2.Close() : INVOICE用客戶資料 = True : 清單修改2.ShowDialog() : ComboBox1下拉表單資料載入() : INVOICE用客戶資料 = False
  179. End Sub
  180. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ATTN_cb.SelectedIndexChanged
  181. SQL_INVOICE用客戶資料()
  182. If (dr.Read()) Then : TEL_tb.Text = dr("TEL") : End If : conn.Close()
  183. End Sub
  184. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 準備新增_bt.Click
  185. If UPS_tb.Text = "" Or ATTN_cb.Text = "" Or Custon_cb.Text = "NA" Then
  186. MsgBox("資料不齊全,請檢查UPS號、ATTN、CARTON等位置不可空白或NA")
  187. Else
  188. 準備新增_bt.Enabled = False : UPS_tb.Enabled = False : 新增1_bt.Enabled = True : 刪除1_bt.Enabled = True
  189. 新增清單_bt.Enabled = False : ATTN_cb.Enabled = False : Custon_cb.Enabled = False : 表單2_dgv.Visible = False : 表單3_dgv.Visible = True
  190. SQL_最後一筆UPS()
  191. If (dr.Read()) Then
  192. 修改存檔_bt.Enabled = True : conn.Close()
  193. 新增1_bt.Visible = False : 刪除1_bt.Visible = False : 新增1_bt.Enabled = False : 刪除1_bt.Enabled = False
  194. 新增_bt.Visible = True : 刪除_bt.Visible = True : 新增_bt.Enabled = True : 刪除_bt.Enabled = True
  195. Else
  196. 資料存檔_bt.Enabled = True : conn.Close()
  197. 新增1_bt.Visible = True : 刪除1_bt.Visible = True : 新增1_bt.Enabled = True : 刪除1_bt.Enabled = True
  198. 新增_bt.Visible = False : 刪除_bt.Visible = False : 新增_bt.Enabled = False : 刪除_bt.Enabled = False
  199. 表單1_dgv.DataSource = Nothing : ds.Clear()
  200. End If
  201. Set_清單3()
  202. End If
  203. End Sub
  204. Private Sub Button8_Click(sender As Object, e As EventArgs) Handles 資料存檔_bt.Click
  205. 準備新增_bt.Enabled = True : 資料存檔_bt.Enabled = False : UPS_tb.Enabled = True : 新增1_bt.Enabled = False : 刪除1_bt.Enabled = False : 新增_bt.Enabled = False : 刪除_bt.Enabled = False
  206. 新增清單_bt.Enabled = True : ATTN_cb.Enabled = True : Custon_cb.Enabled = True : 表單2_dgv.Visible = True : 表單3_dgv.Visible = False
  207. For i As Integer = 0 To 表單1_dgv.Rows.Count - 1
  208. 資料數 = 表單1_dgv.Rows.Count : MyModule1.進度條()
  209. PA = 表單1_dgv.Rows(i).Cells("對應流水號").Value
  210. SQL_讀取寄出()
  211. If (dr.Read()) Then
  212. KKOO = dr("寄出")
  213. End If : conn.Close()
  214. KKOO += 表單1_dgv.Rows(i).Cells("PAIRS").Value
  215. SQL_修改樣品訂單清單5() : conn.Close()
  216. Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
  217. Set_清單()
  218. UPS_tb.Text = "" : ComboBox1下拉表單資料載入() : 材質_cb.Text = "NA" : Custon_cb.Text = "NA" : GenderSizeFoot_cb.Text = "NA" : 表單1_dgv.DataSource = Nothing : ds.Clear()
  219. End Sub
  220. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 修改存檔_bt.Click
  221. 準備新增_bt.Enabled = True : 修改存檔_bt.Enabled = False : UPS_tb.Enabled = True : 新增1_bt.Enabled = False : 刪除1_bt.Enabled = False : 新增_bt.Enabled = False : 刪除_bt.Enabled = False
  222. 新增清單_bt.Enabled = True : ATTN_cb.Enabled = True : Custon_cb.Enabled = True : 表單2_dgv.Visible = True : 表單3_dgv.Visible = False
  223. Set_清單()
  224. End Sub
  225. Private Sub Set_日期格式轉換()
  226. DTP = Strings.Format(Today(), "yyyy/MM/dd")
  227. End Sub
  228. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles 新增1_bt.Click
  229. If 材質_cb.Text = "NA" Then
  230. MsgBox("材質不可為NA")
  231. ElseIf GenderSizeFoot_cb.Text = "NA" Then
  232. MsgBox("size不可為NA")
  233. Else
  234. If Val(可寄出數_tb.Text) < Val(本次寄出數_tb.Text) Then
  235. MsgBox("寄出數不可大於可寄數,哪來的鞋子?")
  236. ElseIf Val(本次寄出數_tb.Text) = 0 Then
  237. MsgBox("寄出數不可為零,快遞公司無法寄幽靈?")
  238. Else
  239. Set_日期格式轉換()
  240. SQL_讀取INVOICE樣品單()
  241. If (dr.Read()) Then
  242. MsgBox("本單號中已有新增過該資料,如有錯誤請刪除後從新添加。")
  243. conn.Close()
  244. Else
  245. If 材質_cb.Text = "皮" Then : GGHH = "6403990090" : ElseIf 材質_cb.Text = "PU" Then : GGHH = "6402992900" : ElseIf 材質_cb.Text = "布" Then : GGHH = "6404199000" : End If
  246. dr.Close() : SQL_新增INVOICE樣品單() : conn.Close()
  247. Set_清單1()
  248. End If
  249. End If
  250. End If
  251. End Sub
  252. Private Sub Button15_Click(sender As Object, e As EventArgs) Handles 刪除1_bt.Click
  253. If 流水號_tb.Text = "" Then
  254. MsgBox("沒有選擇要刪除的資料")
  255. Else
  256. SQL_刪除INVOICE樣品單1() : conn.Close()
  257. Set_清單1()
  258. End If
  259. End Sub
  260. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
  261. If 材質_cb.Text = "NA" Then
  262. MsgBox("材質不可為NA")
  263. ElseIf GenderSizeFoot_cb.Text = "NA" Then
  264. MsgBox("size不可為NA")
  265. Else
  266. If Val(可寄出數_tb.Text) < Val(本次寄出數_tb.Text) Then
  267. MsgBox("寄出數不可大於可寄數,哪來的鞋子?")
  268. ElseIf Val(本次寄出數_tb.Text) = 0 Then
  269. MsgBox("寄出數不可為零,快遞公司無法寄幽靈?")
  270. Else
  271. Set_日期格式轉換()
  272. SQL_讀取INVOICE樣品單()
  273. If (dr.Read()) Then
  274. MsgBox("本單號中已有新增過該資料,如有錯誤請刪除後從新添加。")
  275. conn.Close()
  276. Else
  277. SQL_讀取寄出1()
  278. If (dr.Read()) Then
  279. KKOO = dr("寄出")
  280. End If : conn.Close()
  281. KKOO += Val(本次寄出數_tb.Text)
  282. SQL_修改樣品訂單清單6() : conn.Close()
  283. Set_清單3()
  284. If 材質_cb.Text = "皮" Then : GGHH = "6403990090" : ElseIf 材質_cb.Text = "PU" Then : GGHH = "6402992900" : ElseIf 材質_cb.Text = "布" Then : GGHH = "6404199000" : End If
  285. dr.Close() : SQL_新增INVOICE樣品單() : conn.Close()
  286. Set_清單1()
  287. End If
  288. End If
  289. End If
  290. End Sub
  291. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
  292. If 流水號_tb.Text = "" Then
  293. MsgBox("沒有選擇要刪除的資料")
  294. Else
  295. SQL_讀取寄出1()
  296. If (dr.Read()) Then
  297. KKOO = dr("寄出")
  298. End If : conn.Close()
  299. KKOO -= Val(本次寄出數_tb.Text)
  300. SQL_修改樣品訂單清單6() : conn.Close()
  301. Set_清單3()
  302. SQL_刪除INVOICE樣品單1() : conn.Close()
  303. Set_清單1()
  304. End If
  305. End Sub
  306. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles 列印_bt.Click
  307. xlApp = CType(CreateObject("Excel.Application"), Application)
  308. xlBook = xlApp.Workbooks.Add
  309. xlApp.DisplayAlerts = True
  310. xlBook.Activate()
  311. xlSheet = NewMethod(xlBook)
  312. xlSheet.Activate()
  313. xlApp.Visible = True
  314. xlApp.Application.WindowState = xlMaximized
  315. xlSheet.Cells(1, 1) = "SHIP TO :" : xlSheet.Cells(1, 2) = "Me Too LLC" : xlSheet.Cells(2, 2) = "49, West 37th street-2nd FL." : xlSheet.Cells(3, 2) = "New York, NY 10018" : xlSheet.Cells(4, 2) = "USA"
  316. xlSheet.Cells(1, 6) = "FROM :" : xlSheet.Cells(1, 7) = "DONGGUAN SEN KANG FOOTWEAR CO.,LTD" : xlSheet.Cells(2, 7) = "HuJing Road, Jiao yuan village," : xlSheet.Cells(3, 7) = "He Tian Managemet District.HouJie Town, "
  317. xlSheet.Cells(4, 7) = "Dongguan City Guangdong, CN 523945" : xlSheet.Cells(5, 7) = "China"
  318. xlSheet.Cells(6, 1) = "ATTN : " : xlSheet.Cells(6, 2) = ATTN_cb.Text : xlSheet.Cells(7, 1) = "TEL : " : xlSheet.Cells(7, 2) = TEL_tb.Text : xlSheet.Cells(8, 1) = "FAX : "
  319. xlSheet.Cells(9, 1) = "DATE : " : xlSheet.Cells(9, 2) = 日期_tb.Text : xlSheet.Cells(7, 6) = "TEL : " : xlSheet.Cells(7, 7) = "0769-38937740"
  320. xlSheet.Cells(10, 1) = "INVOICE" : xlSheet.Cells(11, 1) = "Carton# : " & Custon_cb.Text
  321. xlSheet.Cells(12, 1) = "Customer" : xlSheet.Cells(12, 2) = "Sample type" : xlSheet.Cells(12, 3) = "HTS CODE" : xlSheet.Cells(12, 4) = "Style Name" : xlSheet.Cells(12, 5) = "Colorway"
  322. xlSheet.Cells(12, 6) = "Upper Material" : xlSheet.Cells(12, 7) = "Outsole Material" : xlSheet.Cells(12, 8) = "Gender/Size/Foot" : xlSheet.Cells(12, 9) = "Pairs" : xlSheet.Cells(12, 10) = "UNIT(US$)"
  323. xlSheet.Cells(12, 11) = "TTL(US$)"
  324. N1 = 0
  325. For i As Integer = 0 To 表單1_dgv.Rows.Count - 1
  326. xlSheet.Cells(i + 13, 1) = 表單1_dgv.Rows(i).Cells("Customer").Value
  327. xlSheet.Cells(i + 13, 2) = 表單1_dgv.Rows(i).Cells("Sample type").Value
  328. xlSheet.Cells(i + 13, 3) = 表單1_dgv.Rows(i).Cells("Hts Code").Value
  329. xlSheet.Cells(i + 13, 4) = 表單1_dgv.Rows(i).Cells("Styie Number").Value
  330. xlSheet.Cells(i + 13, 5) = 表單1_dgv.Rows(i).Cells("Colorway").Value
  331. xlSheet.Cells(i + 13, 6) = 表單1_dgv.Rows(i).Cells("Upper Material").Value
  332. xlSheet.Cells(i + 13, 7) = 表單1_dgv.Rows(i).Cells("Outsole Material").Value
  333. xlSheet.Cells(i + 13, 8) = 表單1_dgv.Rows(i).Cells("G_S_F").Value
  334. xlSheet.Cells(i + 13, 9) = 表單1_dgv.Rows(i).Cells("PAIRS").Value
  335. xlSheet.Cells(i + 13, 10) = 表單1_dgv.Rows(i).Cells("UNIT").Value
  336. xlSheet.Cells(i + 13, 11) = 表單1_dgv.Rows(i).Cells("TTL").Value
  337. N1 = i
  338. Next
  339. xlSheet.Cells(N1 + 15, 8) = "TOTAL" : xlSheet.Cells(N1 + 15, 9) = "=SUM(I13:I" & N1 + 14 & ")" : xlSheet.Cells(N1 + 15, 11) = "=SUM(K13:K" & N1 + 14 & ")"
  340. xlSheet.Cells(N1 + 16, 1) = "Samples are marked or mutilated and classified HTS 6403990090&6402992900& 6404199000 per ruling letter N247780 attached"
  341. xlSheet.Cells(N1 + 17, 1) = "VALUE FOR CUSTOMS PURPOSES ONLY"
  342. xlSheet.Cells(N1 + 18, 1) = "UPS " & UPS_tb.Text
  343. xlSheet.Cells(N1 + 19, 1) = "MADE IN CHINA SAMPLE NOT FOR RESALE"
  344. xlSheet.Cells(N1 + 20, 1) = "SIGNATURE : " & gUserName
  345. AA(xlApp, xlSheet)
  346. xlSheet.PageSetup.PrintArea = ""
  347. xlApp.Cells.Select()
  348. xlSheet.Range("B1").Select()
  349. xlApp.Application.WindowState = xlMinimized
  350. MsgBox("列印完成")
  351. End Sub
  352. Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
  353. Return CType(xlBook.Worksheets.Add, Worksheet)
  354. End Function
  355. Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  356. xlSheet.Cells.Select()
  357. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  358. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  359. xlSheet.Range("A1:A9").Select()
  360. myExcel.Selection.Font.Bold = True
  361. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  362. .ReadingOrder = xlContext : .MergeCells = False : End With
  363. xlSheet.Range("F1:F9").Select()
  364. myExcel.Selection.Font.Bold = True
  365. With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  366. .ReadingOrder = xlContext : .MergeCells = False : End With
  367. xlSheet.Rows("1:9").Select : myExcel.Selection.RowHeight = 20 : xlSheet.Rows("10:10").Select : myExcel.Selection.RowHeight = 25
  368. xlSheet.Rows("11:11").Select : myExcel.Selection.RowHeight = 30 : xlSheet.Rows("12:12").Select : myExcel.Selection.RowHeight = 25
  369. xlSheet.Rows("13:" & N1 + 15).Select : myExcel.Selection.RowHeight = 30
  370. With myExcel.Selection : .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  371. .ReadingOrder = xlContext : .MergeCells = False : End With
  372. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 20
  373. xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 15
  374. xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 13
  375. xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 15
  376. xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 15
  377. xlSheet.Columns("F:G").Select : myExcel.Selection.ColumnWidth = 20
  378. xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 15
  379. xlSheet.Columns("I:K").Select : myExcel.Selection.ColumnWidth = 8
  380. xlSheet.Rows("12:" & N1 + 15).Select
  381. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  382. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  383. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  384. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  385. xlSheet.Rows(13 + N1 + 3 & ":" & 13 + N1 + 7).Select : myExcel.Selection.RowHeight = 25 : myExcel.Selection.Font.Bold = True
  386. xlSheet.Rows("10:11").Select : myExcel.Selection.Font.Bold = True
  387. xlSheet.Range("A10:K10").Select()
  388. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  389. .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  390. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 20 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  391. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  392. xlSheet.Range("A11:K11").Select()
  393. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  394. .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  395. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 16 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  396. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  397. xlSheet.Range("A" & 13 + N1 + 3 & ":K" & 13 + N1 + 3).Select()
  398. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  399. .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  400. xlSheet.Range("A" & 13 + N1 + 4 & ":K" & 13 + N1 + 4).Select()
  401. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  402. .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  403. xlSheet.Range("A" & 13 + N1 + 5 & ":K" & 13 + N1 + 5).Select()
  404. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  405. .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  406. xlSheet.Range("A" & 13 + N1 + 6 & ":K" & 13 + N1 + 6).Select()
  407. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  408. .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  409. xlSheet.Range("A" & 13 + N1 + 7 & ":K" & 13 + N1 + 7).Select()
  410. With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False
  411. .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge
  412. xlSheet.Range("A10:K10").Select()
  413. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  414. myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
  415. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  416. myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  417. xlSheet.Range("A12:K" & 13 + N1 + 2).Select()
  418. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  419. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  420. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  421. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  422. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  423. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  424. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  425. myExcel.ActiveWindow.DisplayGridlines = False
  426. myExcel.Application.CutCopyMode = False
  427. myExcel.Application.PrintCommunication = False
  428. With myExcel.ActiveSheet.PageSetup
  429. .PrintTitleRows = "$1:$12"
  430. .PrintTitleColumns = ""
  431. End With
  432. myExcel.Application.PrintCommunication = True
  433. myExcel.ActiveSheet.PageSetup.PrintArea = ""
  434. myExcel.Application.PrintCommunication = False
  435. With myExcel.ActiveSheet.PageSetup
  436. .LeftHeader = ""
  437. .CenterHeader = ""
  438. .RightHeader = ""
  439. .LeftFooter = ""
  440. .CenterFooter = ""
  441. .RightFooter = ""
  442. .LeftMargin = myExcel.Application.InchesToPoints(0.236220472440945)
  443. .RightMargin = myExcel.Application.InchesToPoints(0.236220472440945)
  444. .TopMargin = myExcel.Application.InchesToPoints(0.748031496062992)
  445. .BottomMargin = myExcel.Application.InchesToPoints(0.748031496062992)
  446. .HeaderMargin = myExcel.Application.InchesToPoints(0.31496062992126)
  447. .FooterMargin = myExcel.Application.InchesToPoints(0.31496062992126)
  448. .PrintHeadings = False
  449. .PrintGridlines = False
  450. .PrintQuality = 600
  451. .CenterHorizontally = False
  452. .CenterVertically = False
  453. .Draft = False
  454. .FirstPageNumber = xlAutomatic
  455. .BlackAndWhite = False
  456. .Zoom = False
  457. .FitToPagesWide = 1
  458. .FitToPagesTall = 1
  459. .OddAndEvenPagesHeaderFooter = False
  460. .DifferentFirstPageHeaderFooter = False
  461. .ScaleWithDocHeaderFooter = True
  462. .AlignMarginsHeaderFooter = True
  463. .EvenPage.LeftHeader.Text = ""
  464. .EvenPage.CenterHeader.Text = ""
  465. .EvenPage.RightHeader.Text = ""
  466. .EvenPage.LeftFooter.Text = ""
  467. .EvenPage.CenterFooter.Text = ""
  468. .EvenPage.RightFooter.Text = ""
  469. .FirstPage.LeftHeader.Text = ""
  470. .FirstPage.CenterHeader.Text = ""
  471. .FirstPage.RightHeader.Text = ""
  472. .FirstPage.LeftFooter.Text = ""
  473. .FirstPage.CenterFooter.Text = ""
  474. .FirstPage.RightFooter.Text = ""
  475. End With
  476. myExcel.Application.PrintCommunication = True
  477. End Sub
  478. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles INVO_bt.Click
  479. 表單2_dgv.Visible = True : 表單3_dgv.Visible = False
  480. End Sub
  481. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles 樣品單_bt.Click
  482. 表單2_dgv.Visible = False : 表單3_dgv.Visible = True
  483. End Sub
  484. Private Sub 表單3_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 表單3_dgv.MouseUp
  485. If 表單3_dgv.SelectedCells.Count = 1 Then
  486. 已超出 = False
  487. End If
  488. If 表單3_dgv.SelectedCells.Count > 0 Then
  489. '設定滑鼠點擊DGV時候的範圍,超出範圍時有可能不是數字所以不計算
  490. If 表單3_dgv.SelectedCells(0).ColumnIndex >= 7 And 表單3_dgv.SelectedCells(0).ColumnIndex <= 9 Then
  491. If 已超出 = False Then
  492. Dim x As Double = 0
  493. For i As Integer = 0 To 表單3_dgv.SelectedCells.Count - 1
  494. '表單3_dgv.SelectedCells.Item(i).ColumnIndex + 8 是因為該DGV顯示項與計算像剛好差8格,使用時要注意可直接計算的不需要加數字。
  495. x += Val(表單3_dgv.Rows(表單3_dgv.SelectedCells.Item(i).RowIndex).Cells(表單3_dgv.SelectedCells.Item(i).ColumnIndex).Value)
  496. Next i
  497. '將計算好的資料放置到指定的控件中
  498. WINPROFIT_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0")
  499. Else
  500. WINPROFIT_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
  501. End If
  502. Else
  503. 已超出 = True
  504. WINPROFIT_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0")
  505. End If
  506. End If
  507. End Sub
  508. End Class