Нема описа
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 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. Option Strict Off
  2. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  3. Imports Microsoft.Office.Interop.Excel.Constants
  4. Imports Microsoft.Office.Interop.Excel.XlOrder
  5. Imports Microsoft.Office.Interop.Excel.XlThemeFont
  6. Imports Microsoft.Office.Interop.Excel.XlThemeColor
  7. Imports Microsoft.Office.Interop.Excel.XlWindowState
  8. Public Class 列印_樣品貼標
  9. Private ReadOnly ds, ds1, ds2, ds3 As New DataSet
  10. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  11. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  12. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  13. Private Sub Set_DGV1載入前設定()
  14. 標籤1_dgv.DataSource = Nothing : ds.Clear()
  15. 標籤1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  16. 標籤1_dgv.ColumnHeadersHeight = 25
  17. 標籤1_dgv.AllowUserToAddRows = False
  18. End Sub
  19. Private Sub Set_DGV1載入後設定()
  20. da.Fill(ds) : 標籤1_dgv.DataSource = ds.Tables(0) : conn.Close()
  21. End Sub
  22. Private Sub Set_清單()
  23. Set_DGV1載入前設定()
  24. SQL_標籤1清單()
  25. Set_DGV1載入後設定()
  26. End Sub
  27. Private Sub Set_DGV2載入前設定()
  28. 標籤2_dgv.DataSource = Nothing : ds1.Clear()
  29. 標籤2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  30. 標籤2_dgv.ColumnHeadersHeight = 25
  31. 標籤2_dgv.AllowUserToAddRows = False
  32. End Sub
  33. Private Sub Set_DGV2載入後設定()
  34. da.Fill(ds1) : 標籤2_dgv.DataSource = ds1.Tables(0) : conn.Close() : Set_grid2()
  35. End Sub
  36. Private Sub Set_清單2()
  37. Set_DGV2載入前設定()
  38. SQL_標籤2清單()
  39. Set_DGV2載入後設定()
  40. End Sub
  41. Private Sub Set_grid2()
  42. 標籤2_dgv.Columns(0).FillWeight = 40 : 標籤2_dgv.Columns(1).FillWeight = 300 : 標籤2_dgv.Columns(2).FillWeight = 170
  43. End Sub
  44. Private Sub ComboBox1下拉表單資料載入()
  45. SQL_顏色下拉清單()
  46. Color_cb.Items.Clear() : While (dr.Read()) : Color_cb.Items.Add(dr("顏色")) : End While : conn.Close()
  47. End Sub
  48. Private Sub ComboBox2下拉表單資料載入()
  49. SQL_貼標對應名稱下拉()
  50. 大項_cb.Items.Clear() : While (dr.Read()) : 大項_cb.Items.Add(dr("貼標對應名稱")) : End While : conn.Close()
  51. End Sub
  52. Private Sub Set_格式設定()
  53. 標籤1_dgv.Visible = False : 流水號_tb.Visible = False
  54. ShoeName_tb.Enabled = False : StyleNo_tb.Enabled = False : Upper_tb.Enabled = False : Season_tb.Enabled = False : Size_tb.Enabled = False : Date_tb.Enabled = False
  55. SO_tb.Enabled = False : Customer_tb.Enabled = False : Lining_tb.Enabled = False : SockLining_tb.Enabled = False : Bottom_tb.Enabled = False
  56. End Sub
  57. Private Sub 列印_樣品貼標_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  58. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
  59. Set_清單() : Set_清單2() : ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : Set_格式設定()
  60. ShoeName_tb.Text = 標籤1_dgv.Rows(0).Cells("型體名稱").Value
  61. StyleNo_tb.Text = 標籤1_dgv.Rows(0).Cells("型體號碼").Value
  62. Season_tb.Text = 標籤1_dgv.Rows(0).Cells("季節").Value
  63. Date_tb.Text = 標籤1_dgv.Rows(0).Cells("制單時間").Value
  64. SO_tb.Text = 標籤1_dgv.Rows(0).Cells("SO").Value
  65. Customer_tb.Text = 標籤1_dgv.Rows(0).Cells("客戶").Value
  66. End Sub
  67. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Color_cb.SelectedIndexChanged
  68. SQL_樣品訂單清單連動()
  69. If dr.Read() Then
  70. Size_tb.Text = dr("SIZE")
  71. 流水號_tb.Text = dr("流水號")
  72. End If : conn.Close()
  73. End Sub
  74. Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 大項_cb.SelectedIndexChanged
  75. If Size_tb.Text = "" Or 流水號_tb.Text = "" Then
  76. Else
  77. Set_清單2()
  78. For i As Integer = 0 To 標籤2_dgv.Rows.Count - 1
  79. 標籤2_dgv.Rows(i).Cells("選擇").Value = False
  80. Next
  81. End If
  82. End Sub
  83. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 資料生成_bt.Click
  84. Dim II As Integer = 0
  85. For i As Integer = 0 To 標籤2_dgv.Rows.Count - 1
  86. If 標籤2_dgv.Rows(i).Cells("選擇").Value = True Then
  87. If 大項_cb.Text = "UPPER" Then
  88. Upper_tb.Text = Upper_tb.Text & II + 1 & ". " & 標籤2_dgv.Rows(i).Cells("材料名稱").Value & "/" & 標籤2_dgv.Rows(i).Cells("材料說明").Value & " " : II += 1
  89. End If
  90. If 大項_cb.Text = "LINING" Then
  91. Lining_tb.Text = Lining_tb.Text & II + 1 & ". " & 標籤2_dgv.Rows(i).Cells("材料名稱").Value & "/" & 標籤2_dgv.Rows(i).Cells("材料說明").Value & " " : II += 1
  92. End If
  93. If 大項_cb.Text = "SOCK LINING" Then
  94. SockLining_tb.Text = SockLining_tb.Text & II + 1 & ". " & 標籤2_dgv.Rows(i).Cells("材料名稱").Value & "/" & 標籤2_dgv.Rows(i).Cells("材料說明").Value & " " : II += 1
  95. End If
  96. If 大項_cb.Text = "BOTTOM" Then
  97. Bottom_tb.Text = Bottom_tb.Text & II + 1 & ". " & 標籤2_dgv.Rows(i).Cells("材料名稱").Value & "/" & 標籤2_dgv.Rows(i).Cells("材料說明").Value & " " : II += 1
  98. End If
  99. End If
  100. Next
  101. End Sub
  102. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 清除1_bt.Click
  103. Upper_tb.Text = ""
  104. End Sub
  105. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles 清除2_bt.Click
  106. Lining_tb.Text = ""
  107. End Sub
  108. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles 清除3_bt.Click
  109. SockLining_tb.Text = ""
  110. End Sub
  111. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles 清除4_bt.Click
  112. Bottom_tb.Text = ""
  113. End Sub
  114. Private Sub Button11_Click(sender As Object, e As EventArgs) Handles 確認列印_bt.Click
  115. xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
  116. xlBook = xlApp.Workbooks.Add
  117. xlApp.DisplayAlerts = True
  118. xlBook.Activate()
  119. xlSheet = NewMethod(xlBook)
  120. xlSheet.Activate()
  121. xlApp.Visible = True
  122. xlApp.Application.WindowState = xlMaximized
  123. xlSheet.Cells(1, 1) = "Shoe Name : "
  124. xlSheet.Cells(2, 1) = "Style No : "
  125. xlSheet.Cells(3, 1) = "Upper : "
  126. xlSheet.Cells(4, 1) = "Lining : "
  127. xlSheet.Cells(5, 1) = "Sock Lining : "
  128. xlSheet.Cells(6, 1) = "Bottom : "
  129. xlSheet.Cells(7, 1) = "Season : "
  130. xlSheet.Cells(8, 1) = "Customer : "
  131. xlSheet.Cells(1, 2) = ShoeName_tb.Text
  132. xlSheet.Cells(2, 2) = StyleNo_tb.Text
  133. xlSheet.Cells(3, 2) = Upper_tb.Text
  134. xlSheet.Cells(4, 2) = Lining_tb.Text
  135. xlSheet.Cells(5, 2) = SockLining_tb.Text
  136. xlSheet.Cells(6, 2) = Bottom_tb.Text
  137. xlSheet.Cells(7, 2) = Season_tb.Text
  138. xlSheet.Cells(8, 2) = Customer_tb.Text
  139. xlSheet.Cells(7, 3) = "Size : "
  140. xlSheet.Cells(7, 4) = Size_tb.Text
  141. xlSheet.Cells(1, 5) = "PURPOSE"
  142. xlSheet.Cells(2, 5) = "Color : "
  143. xlSheet.Cells(7, 5) = "Date : "
  144. xlSheet.Cells(8, 5) = "S/O# : "
  145. xlSheet.Cells(2, 6) = Color_cb.Text
  146. xlSheet.Cells(7, 6) = Date_tb.Text
  147. xlSheet.Cells(8, 6) = SO_tb.Text
  148. AA(xlApp, xlSheet)
  149. xlSheet.PageSetup.PrintArea = ""
  150. xlApp.Cells.Select()
  151. xlSheet.Range("B1").Select()
  152. xlApp.Application.WindowState = xlMinimized
  153. MsgBox("列印完成")
  154. Me.Close()
  155. End Sub
  156. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 取消列印_bt.Click
  157. 列印用SQL = "" : Me.Close()
  158. End Sub
  159. Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
  160. Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
  161. End Function
  162. Private Sub AA(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  163. xlSheet.Cells.Select()
  164. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
  165. .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  166. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 12
  167. xlSheet.Columns("B:D").Select : myExcel.Selection.ColumnWidth = 8
  168. xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 8
  169. xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 9
  170. xlSheet.Rows("1:8").Select : myExcel.Selection.RowHeight = 25
  171. xlSheet.Range("B2:D2").Select() : myExcel.Selection.Merge
  172. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  173. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  174. xlSheet.Range("B3:F3").Select() : myExcel.Selection.Merge
  175. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  176. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  177. xlSheet.Range("B4:F4").Select() : myExcel.Selection.Merge
  178. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  179. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  180. xlSheet.Range("B5:F5").Select() : myExcel.Selection.Merge
  181. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  182. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  183. xlSheet.Range("B6:F6").Select() : myExcel.Selection.Merge
  184. With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  185. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
  186. myExcel.ActiveWindow.DisplayGridlines = False
  187. 'xlSheet.Range("A1:F8").Select()
  188. 'myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  189. 'With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  190. 'With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  191. 'With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  192. 'With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  193. 'myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
  194. 'xlSheet.Range("I5").Select()
  195. myExcel.Application.PrintCommunication = False
  196. With myExcel.ActiveSheet.PageSetup
  197. .PrintTitleRows = ""
  198. .PrintTitleColumns = ""
  199. End With
  200. myExcel.Application.PrintCommunication = True
  201. myExcel.ActiveSheet.PageSetup.PrintArea = ""
  202. myExcel.Application.PrintCommunication = False
  203. With myExcel.ActiveSheet.PageSetup
  204. .LeftHeader = ""
  205. .CenterHeader = ""
  206. .RightHeader = ""
  207. .LeftFooter = ""
  208. .CenterFooter = ""
  209. .RightFooter = ""
  210. .LeftMargin = myExcel.Application.InchesToPoints(0.236220472440945)
  211. .RightMargin = myExcel.Application.InchesToPoints(0.078740157480315)
  212. .TopMargin = myExcel.Application.InchesToPoints(0.078740157480315)
  213. .BottomMargin = myExcel.Application.InchesToPoints(0.078740157480315)
  214. .HeaderMargin = myExcel.Application.InchesToPoints(0)
  215. .FooterMargin = myExcel.Application.InchesToPoints(0)
  216. .PrintHeadings = False
  217. .PrintGridlines = False
  218. .PrintQuality = 203
  219. .CenterHorizontally = True
  220. .CenterVertically = True
  221. .Draft = False
  222. .PaperSize = 262
  223. .FirstPageNumber = xlAutomatic
  224. .Order = xlDownThenOver
  225. .BlackAndWhite = False
  226. .Zoom = False
  227. .FitToPagesWide = 1
  228. .FitToPagesTall = 1
  229. .OddAndEvenPagesHeaderFooter = False
  230. .DifferentFirstPageHeaderFooter = False
  231. .ScaleWithDocHeaderFooter = True
  232. .AlignMarginsHeaderFooter = True
  233. .EvenPage.LeftHeader.Text = ""
  234. .EvenPage.CenterHeader.Text = ""
  235. .EvenPage.RightHeader.Text = ""
  236. .EvenPage.LeftFooter.Text = ""
  237. .EvenPage.CenterFooter.Text = ""
  238. .EvenPage.RightFooter.Text = ""
  239. .FirstPage.LeftHeader.Text = ""
  240. .FirstPage.CenterHeader.Text = ""
  241. .FirstPage.RightHeader.Text = ""
  242. .FirstPage.LeftFooter.Text = ""
  243. .FirstPage.CenterFooter.Text = ""
  244. End With
  245. End Sub
  246. End Class