No Description
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 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. Option Strict Off
  2. Imports System.IO
  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 列印_樣品報價單
  13. Private ReadOnly ds1 As New DataSet
  14. Dim N1, N3, N4 As Integer
  15. Dim 位置1 As String
  16. Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet
  17. Private Sub Set_訂單清單1()
  18. DataGridView1.DataSource = Nothing : ds1.Clear()
  19. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  20. DataGridView1.ColumnHeadersHeight = 25
  21. DataGridView1.AllowUserToAddRows = False
  22. ConnOpen()
  23. SQL1 = 列印用SQL
  24. CmdSet_For_DGV()
  25. da.Fill(ds1) : DataGridView1.DataSource = ds1.Tables(0) : conn.Close()
  26. End Sub
  27. Private Sub 列印_樣品報價單_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  28. DataGridView1.Visible = False : DataGridView2.Visible = False : PictureBox1.Visible = False
  29. FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
  30. Set_訂單清單1()
  31. End Sub
  32. Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
  33. xlApp = CType(CreateObject("Excel.Application"), Application)
  34. xlBook = xlApp.Workbooks.Add
  35. xlApp.DisplayAlerts = True
  36. xlBook.Activate()
  37. xlSheet = NewMethod(xlBook)
  38. xlSheet.Activate()
  39. xlApp.Visible = True
  40. xlApp.Application.WindowState = xlMaximized
  41. xlSheet.Cells(1, 1) = "WTL ENTERPRISE CO., LTD" : xlSheet.Cells(2, 1) = "PRICING LINESHEET-lot" : xlSheet.Cells(3, 1) = "SKETCH" : xlSheet.Cells(3, 2) = "SEASON" : xlSheet.Cells(3, 3) = "CUST"
  42. xlSheet.Cells(3, 4) = "FCTY" : xlSheet.Cells(3, 5) = "STYLE" : xlSheet.Cells(3, 6) = "STYLENAME" : xlSheet.Cells(3, 7) = "COLOR" : xlSheet.Cells(3, 8) = "SO" : xlSheet.Cells(3, 9) = "Edition"
  43. xlSheet.Cells(3, 10) = "Item" : xlSheet.Cells(3, 11) = "MATERIALS" : xlSheet.Cells(3, 12) = "MATERIAL_CLASS" : xlSheet.Cells(3, 13) = "OUTSOLE" : xlSheet.Cells(3, 14) = "INSOLE"
  44. xlSheet.Cells(3, 15) = "FC" : xlSheet.Cells(3, 16) = "REMARK"
  45. AA(xlApp, xlSheet)
  46. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  47. If i = 0 Then
  48. xlSheet.Cells(i + 4, 2) = DataGridView1.Rows(i).Cells("SEASON").Value : xlSheet.Cells(i + 4, 3) = DataGridView1.Rows(i).Cells("CUST").Value
  49. xlSheet.Cells(i + 4, 4) = DataGridView1.Rows(i).Cells("FCTY").Value : xlSheet.Cells(i + 4, 5) = DataGridView1.Rows(i).Cells("STYLE").Value
  50. xlSheet.Cells(i + 4, 6) = DataGridView1.Rows(i).Cells("STYLENAME").Value : xlSheet.Cells(i + 4, 7) = DataGridView1.Rows(i).Cells("COLOR").Value
  51. xlSheet.Cells(i + 4, 8) = DataGridView1.Rows(i).Cells("SO").Value : xlSheet.Cells(i + 4, 9) = DataGridView1.Rows(i).Cells("版次").Value
  52. xlSheet.Cells(i + 4, 10) = DataGridView1.Rows(i).Cells("項次").Value : xlSheet.Cells(i + 4, 11) = DataGridView1.Rows(i).Cells("MATERIALS").Value
  53. xlSheet.Cells(i + 4, 12) = DataGridView1.Rows(i).Cells("MATERIAL_CLASS").Value : xlSheet.Cells(i + 4, 13) = DataGridView1.Rows(i).Cells("OUTSOLE").Value
  54. xlSheet.Cells(i + 4, 14) = DataGridView1.Rows(i).Cells("INSOLE").Value : xlSheet.Cells(i + 4, 15) = DataGridView1.Rows(i).Cells("FC").Value
  55. xlSheet.Cells(i + 4, 16) = DataGridView1.Rows(i).Cells("REMARK").Value
  56. N3 = i + 4 : N4 = i + 4
  57. PictureBox1.Image = Nothing
  58. ConnOpen()
  59. SQL1 = "SELECT TOP(1) 圖片 FROM 鞋型圖片資料庫 " &
  60. "WHERE 客戶 LIKE N'" & DataGridView1.Rows(i).Cells("CUST").Value & "' AND 形體號 LIKE N'" & DataGridView1.Rows(i).Cells("STYLE").Value &
  61. "' AND 形體名 LIKE N'" & DataGridView1.Rows(i).Cells("STYLENAME").Value & "' AND 類別 LIKE N'設計圖'"
  62. CmdSet_For_dr()
  63. If dr.Read() Then
  64. PictureBox1.Image = Nothing
  65. ConnOpen()
  66. SQL1 = "SELECT TOP(1) 圖片 FROM 鞋型圖片資料庫 " &
  67. "WHERE 客戶 LIKE N'" & DataGridView1.Rows(i).Cells("CUST").Value & "' AND 形體號 LIKE N'" & DataGridView1.Rows(i).Cells("STYLE").Value &
  68. "' AND 形體名 LIKE N'" & DataGridView1.Rows(i).Cells("STYLENAME").Value & "' AND 類別 LIKE N'設計圖'"
  69. CmdSet_For_dr()
  70. While dr.Read() = True
  71. Dim unused As Byte() = New Byte(-1) {}
  72. Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
  73. Dim oStream As New MemoryStream(bytes)
  74. PictureBox1.Image = Bitmap.FromStream(oStream)
  75. End While
  76. conn.Close() : GG(xlApp, xlSheet)
  77. Else
  78. xlSheet.Cells(i + 4, 1) = "系統中無圖片"
  79. conn.Close()
  80. End If : PictureBox1.SizeMode = 4
  81. ElseIf DataGridView1.Rows(i - 1).Cells("SO").Value = DataGridView1.Rows(i).Cells("SO").Value And DataGridView1.Rows(i - 1).Cells("版次").Value = DataGridView1.Rows(i).Cells("版次").Value Then
  82. xlSheet.Cells(i + 4, 7) = DataGridView1.Rows(i).Cells("COLOR").Value : xlSheet.Cells(i + 4, 10) = DataGridView1.Rows(i).Cells("項次").Value
  83. xlSheet.Cells(i + 4, 11) = DataGridView1.Rows(i).Cells("MATERIALS").Value : xlSheet.Cells(i + 4, 12) = DataGridView1.Rows(i).Cells("MATERIAL_CLASS").Value
  84. xlSheet.Cells(i + 4, 13) = DataGridView1.Rows(i).Cells("OUTSOLE").Value : xlSheet.Cells(i + 4, 14) = DataGridView1.Rows(i).Cells("INSOLE").Value
  85. xlSheet.Cells(i + 4, 15) = DataGridView1.Rows(i).Cells("FC").Value : xlSheet.Cells(i + 4, 16) = DataGridView1.Rows(i).Cells("REMARK").Value
  86. N4 = i + 4
  87. ElseIf DataGridView1.Rows(i - 1).Cells("SO").Value <> DataGridView1.Rows(i).Cells("SO").Value Or DataGridView1.Rows(i - 1).Cells("版次").Value <> DataGridView1.Rows(i).Cells("版次").Value Then
  88. CC(xlApp, xlSheet)
  89. xlSheet.Cells(i + 4, 2) = DataGridView1.Rows(i).Cells("SEASON").Value : xlSheet.Cells(i + 4, 3) = DataGridView1.Rows(i).Cells("CUST").Value
  90. xlSheet.Cells(i + 4, 4) = DataGridView1.Rows(i).Cells("FCTY").Value : xlSheet.Cells(i + 4, 5) = DataGridView1.Rows(i).Cells("STYLE").Value
  91. xlSheet.Cells(i + 4, 6) = DataGridView1.Rows(i).Cells("STYLENAME").Value : xlSheet.Cells(i + 4, 7) = DataGridView1.Rows(i).Cells("COLOR").Value
  92. xlSheet.Cells(i + 4, 8) = DataGridView1.Rows(i).Cells("SO").Value : xlSheet.Cells(i + 4, 9) = DataGridView1.Rows(i).Cells("版次").Value
  93. xlSheet.Cells(i + 4, 10) = DataGridView1.Rows(i).Cells("項次").Value : xlSheet.Cells(i + 4, 11) = DataGridView1.Rows(i).Cells("MATERIALS").Value
  94. xlSheet.Cells(i + 4, 12) = DataGridView1.Rows(i).Cells("MATERIAL_CLASS").Value : xlSheet.Cells(i + 4, 13) = DataGridView1.Rows(i).Cells("OUTSOLE").Value
  95. xlSheet.Cells(i + 4, 14) = DataGridView1.Rows(i).Cells("INSOLE").Value : xlSheet.Cells(i + 4, 15) = DataGridView1.Rows(i).Cells("FC").Value
  96. xlSheet.Cells(i + 4, 16) = DataGridView1.Rows(i).Cells("REMARK").Value
  97. N3 = i + 4 : N4 = i + 4
  98. PictureBox1.Image = Nothing
  99. ConnOpen()
  100. SQL1 = "SELECT TOP(1) 圖片 FROM 鞋型圖片資料庫 " &
  101. "WHERE 客戶 LIKE N'" & DataGridView1.Rows(i).Cells("CUST").Value & "' AND 形體號 LIKE N'" & DataGridView1.Rows(i).Cells("STYLE").Value &
  102. "' AND 形體名 LIKE N'" & DataGridView1.Rows(i).Cells("STYLENAME").Value & "' AND 類別 LIKE N'設計圖'"
  103. CmdSet_For_dr()
  104. If dr.Read() Then
  105. PictureBox1.Image = Nothing
  106. ConnOpen()
  107. SQL1 = "SELECT TOP(1) 圖片 FROM 鞋型圖片資料庫 " &
  108. "WHERE 客戶 LIKE N'" & DataGridView1.Rows(i).Cells("CUST").Value & "' AND 形體號 LIKE N'" & DataGridView1.Rows(i).Cells("STYLE").Value &
  109. "' AND 形體名 LIKE N'" & DataGridView1.Rows(i).Cells("STYLENAME").Value & "' AND 類別 LIKE N'設計圖'"
  110. CmdSet_For_dr()
  111. While dr.Read() = True
  112. Dim bytes As Byte() = New Byte(-1) {} : bytes = DirectCast(dr.Item("圖片"), Byte()) : Dim oStream As New MemoryStream(bytes) : PictureBox1.Image = Bitmap.FromStream(oStream)
  113. End While
  114. conn.Close() : GG(xlApp, xlSheet)
  115. Else
  116. xlSheet.Cells(i + 4, 1) = "系統中無圖片"
  117. conn.Close()
  118. End If : PictureBox1.SizeMode = 4
  119. End If
  120. With xlApp.Selection
  121. .Font.Bold = True
  122. End With
  123. N1 = i + 4
  124. Next i
  125. CC(xlApp, xlSheet) : BB(xlApp, xlSheet)
  126. xlSheet.PageSetup.PrintArea = ""
  127. xlApp.Cells.Select()
  128. xlSheet.Range("B1").Select()
  129. xlApp.Application.WindowState = xlMinimized
  130. MsgBox("列印完成")
  131. Me.Close()
  132. End Sub
  133. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  134. 列印用SQL = "" : Me.Close()
  135. End Sub
  136. Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
  137. Return CType(xlBook.Worksheets.Add, Worksheet)
  138. End Function
  139. Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  140. xlSheet.Cells.Select()
  141. With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 9 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
  142. .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
  143. With myExcel.Selection : .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlTop : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
  144. .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With
  145. myExcel.Selection.RowHeight = 45
  146. xlSheet.Range("A1").Select() : With myExcel.Selection.Font : .Size = 22 : End With
  147. xlSheet.Range("A2").Select() : With myExcel.Selection.Font : .Size = 18 : End With
  148. xlSheet.Rows("3:3").Select : myExcel.Selection.RowHeight = 30 : xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 25 : xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 30
  149. xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 8.25
  150. xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 8
  151. xlSheet.Columns("C:G").Select : myExcel.Selection.ColumnWidth = 10
  152. xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 6.75
  153. xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 5.75
  154. xlSheet.Columns("J:J").Select : myExcel.Selection.ColumnWidth = 4
  155. xlSheet.Columns("K:K").Select : myExcel.Selection.ColumnWidth = 45
  156. xlSheet.Columns("L:L").Select : myExcel.Selection.ColumnWidth = 12.75
  157. xlSheet.Columns("M:M").Select : myExcel.Selection.ColumnWidth = 40
  158. xlSheet.Columns("N:N").Select : myExcel.Selection.ColumnWidth = 6.6
  159. xlSheet.Columns("O:O").Select : myExcel.Selection.ColumnWidth = 6
  160. xlSheet.Columns("P:P").Select : myExcel.Selection.ColumnWidth = 30
  161. xlSheet.Range("A3:P3").Select()
  162. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  163. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  164. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  165. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  166. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  167. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  168. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  169. With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent1 : .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0 : End With
  170. xlSheet.Rows("4:4").Select : myExcel.ActiveWindow.FreezePanes = True
  171. xlSheet.Range("A1:P1").Select() : myExcel.Selection.Merge : With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : End With
  172. xlSheet.Range("A2:P2").Select() : myExcel.Selection.Merge : With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlTop : End With
  173. End Sub
  174. Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  175. 位置1 = "A4:P" & N1 : xlSheet.Range(位置1).Select()
  176. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  177. With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  178. With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  179. With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  180. With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  181. With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  182. With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
  183. End Sub
  184. Private Sub CC(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
  185. 位置1 = "A" & N3 & ":A" & N4 : xlSheet.Range(位置1).Select() : myExcel.Selection.Merge
  186. 位置1 = "B" & N3 & ":B" & N4 : xlSheet.Range(位置1).Select() : myExcel.Selection.Merge
  187. 位置1 = "C" & N3 & ":C" & N4 : xlSheet.Range(位置1).Select() : myExcel.Selection.Merge
  188. 位置1 = "D" & N3 & ":D" & N4 : xlSheet.Range(位置1).Select() : myExcel.Selection.Merge
  189. 位置1 = "E" & N3 & ":E" & N4 : xlSheet.Range(位置1).Select() : myExcel.Selection.Merge
  190. 位置1 = "F" & N3 & ":F" & N4 : xlSheet.Range(位置1).Select() : myExcel.Selection.Merge
  191. 位置1 = "H" & N3 & ":H" & N4 : xlSheet.Range(位置1).Select() : myExcel.Selection.Merge
  192. 位置1 = "I" & N3 & ":I" & N4 : xlSheet.Range(位置1).Select() : myExcel.Selection.Merge
  193. End Sub
  194. Private Sub GG(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  195. Dim 位置1 As String
  196. Clipboard.SetDataObject(PictureBox1.Image)
  197. 位置1 = "A" & N3 : xlSheet.Range(位置1).Select()
  198. myExcel.ActiveSheet.Pictures.Paste.Select
  199. myExcel.Selection.ShapeRange.Width = 8
  200. End Sub
  201. End Class