Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

列印_樣品報價單.vb 17KB

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