Açıklama Yok
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

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