123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- Option Strict Off
- Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
- Imports Microsoft.Office.Interop.Excel.Constants
- Imports Microsoft.Office.Interop.Excel.XlOrder
- Imports Microsoft.Office.Interop.Excel.XlThemeFont
- Imports Microsoft.Office.Interop.Excel.XlThemeColor
- Imports Microsoft.Office.Interop.Excel.XlWindowState
- Public Class 列印_樣品貼標
- Private ReadOnly ds, ds1, ds2, ds3 As New DataSet
- Dim xlApp As Microsoft.Office.Interop.Excel.Application
- Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
- Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
- Private Sub Set_DGV1載入前設定()
- 標籤1_dgv.DataSource = Nothing : ds.Clear()
- 標籤1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- 標籤1_dgv.ColumnHeadersHeight = 25
- 標籤1_dgv.AllowUserToAddRows = False
- End Sub
- Private Sub Set_DGV1載入後設定()
- da.Fill(ds) : 標籤1_dgv.DataSource = ds.Tables(0) : conn.Close()
- End Sub
- Private Sub Set_清單()
- Set_DGV1載入前設定()
- SQL_標籤1清單()
- Set_DGV1載入後設定()
- End Sub
- Private Sub Set_DGV2載入前設定()
- 標籤2_dgv.DataSource = Nothing : ds1.Clear()
- 標籤2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- 標籤2_dgv.ColumnHeadersHeight = 25
- 標籤2_dgv.AllowUserToAddRows = False
- End Sub
- Private Sub Set_DGV2載入後設定()
- da.Fill(ds1) : 標籤2_dgv.DataSource = ds1.Tables(0) : conn.Close() : Set_grid2()
- End Sub
- Private Sub Set_清單2()
- Set_DGV2載入前設定()
- SQL_標籤2清單()
- Set_DGV2載入後設定()
- End Sub
- Private Sub Set_grid2()
- 標籤2_dgv.Columns(0).FillWeight = 40 : 標籤2_dgv.Columns(1).FillWeight = 300 : 標籤2_dgv.Columns(2).FillWeight = 170
- End Sub
- Private Sub ComboBox1下拉表單資料載入()
- SQL_顏色下拉清單()
- Color_cb.Items.Clear() : While (dr.Read()) : Color_cb.Items.Add(dr("顏色")) : End While : conn.Close()
- End Sub
- Private Sub ComboBox2下拉表單資料載入()
- SQL_貼標對應名稱下拉()
- 大項_cb.Items.Clear() : While (dr.Read()) : 大項_cb.Items.Add(dr("貼標對應名稱")) : End While : conn.Close()
- End Sub
- Private Sub Set_格式設定()
- 標籤1_dgv.Visible = False : 流水號_tb.Visible = False
- ShoeName_tb.Enabled = False : StyleNo_tb.Enabled = False : Upper_tb.Enabled = False : Season_tb.Enabled = False : Size_tb.Enabled = False : Date_tb.Enabled = False
- SO_tb.Enabled = False : Customer_tb.Enabled = False : Lining_tb.Enabled = False : SockLining_tb.Enabled = False : Bottom_tb.Enabled = False
- End Sub
- Private Sub 列印_樣品貼標_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- FormBorderStyle = FormBorderStyle.SizableToolWindow : ControlBox = False
- Set_清單() : Set_清單2() : ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : Set_格式設定()
- ShoeName_tb.Text = 標籤1_dgv.Rows(0).Cells("型體名稱").Value
- StyleNo_tb.Text = 標籤1_dgv.Rows(0).Cells("型體號碼").Value
- Season_tb.Text = 標籤1_dgv.Rows(0).Cells("季節").Value
- Date_tb.Text = 標籤1_dgv.Rows(0).Cells("制單時間").Value
- SO_tb.Text = 標籤1_dgv.Rows(0).Cells("SO").Value
- Customer_tb.Text = 標籤1_dgv.Rows(0).Cells("客戶").Value
- End Sub
- Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Color_cb.SelectedIndexChanged
- SQL_樣品訂單清單連動()
- If dr.Read() Then
- Size_tb.Text = dr("SIZE")
- 流水號_tb.Text = dr("流水號")
- End If : conn.Close()
- End Sub
- Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 大項_cb.SelectedIndexChanged
- If Size_tb.Text = "" Or 流水號_tb.Text = "" Then
- Else
- Set_清單2()
- For i As Integer = 0 To 標籤2_dgv.Rows.Count - 1
- 標籤2_dgv.Rows(i).Cells("選擇").Value = False
- Next
- End If
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 資料生成_bt.Click
- Dim II As Integer = 0
- For i As Integer = 0 To 標籤2_dgv.Rows.Count - 1
- If 標籤2_dgv.Rows(i).Cells("選擇").Value = True Then
- If 大項_cb.Text = "UPPER" Then
- Upper_tb.Text = Upper_tb.Text & II + 1 & ". " & 標籤2_dgv.Rows(i).Cells("材料名稱").Value & "/" & 標籤2_dgv.Rows(i).Cells("材料說明").Value & " " : II += 1
- End If
- If 大項_cb.Text = "LINING" Then
- Lining_tb.Text = Lining_tb.Text & II + 1 & ". " & 標籤2_dgv.Rows(i).Cells("材料名稱").Value & "/" & 標籤2_dgv.Rows(i).Cells("材料說明").Value & " " : II += 1
- End If
- If 大項_cb.Text = "SOCK LINING" Then
- SockLining_tb.Text = SockLining_tb.Text & II + 1 & ". " & 標籤2_dgv.Rows(i).Cells("材料名稱").Value & "/" & 標籤2_dgv.Rows(i).Cells("材料說明").Value & " " : II += 1
- End If
- If 大項_cb.Text = "BOTTOM" Then
- Bottom_tb.Text = Bottom_tb.Text & II + 1 & ". " & 標籤2_dgv.Rows(i).Cells("材料名稱").Value & "/" & 標籤2_dgv.Rows(i).Cells("材料說明").Value & " " : II += 1
- End If
- End If
- Next
- End Sub
- Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 清除1_bt.Click
- Upper_tb.Text = ""
- End Sub
- Private Sub Button4_Click(sender As Object, e As EventArgs) Handles 清除2_bt.Click
- Lining_tb.Text = ""
- End Sub
- Private Sub Button5_Click(sender As Object, e As EventArgs) Handles 清除3_bt.Click
- SockLining_tb.Text = ""
- End Sub
- Private Sub Button6_Click(sender As Object, e As EventArgs) Handles 清除4_bt.Click
- Bottom_tb.Text = ""
- End Sub
- Private Sub Button11_Click(sender As Object, e As EventArgs) Handles 確認列印_bt.Click
- xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
- xlBook = xlApp.Workbooks.Add
- xlApp.DisplayAlerts = True
- xlBook.Activate()
- xlSheet = NewMethod(xlBook)
- xlSheet.Activate()
- xlApp.Visible = True
- xlApp.Application.WindowState = xlMaximized
-
- xlSheet.Cells(1, 1) = "Shoe Name : "
- xlSheet.Cells(2, 1) = "Style No : "
- xlSheet.Cells(3, 1) = "Upper : "
- xlSheet.Cells(4, 1) = "Lining : "
- xlSheet.Cells(5, 1) = "Sock Lining : "
- xlSheet.Cells(6, 1) = "Bottom : "
- xlSheet.Cells(7, 1) = "Season : "
- xlSheet.Cells(8, 1) = "Customer : "
- xlSheet.Cells(1, 2) = ShoeName_tb.Text
- xlSheet.Cells(2, 2) = StyleNo_tb.Text
- xlSheet.Cells(3, 2) = Upper_tb.Text
- xlSheet.Cells(4, 2) = Lining_tb.Text
- xlSheet.Cells(5, 2) = SockLining_tb.Text
- xlSheet.Cells(6, 2) = Bottom_tb.Text
- xlSheet.Cells(7, 2) = Season_tb.Text
- xlSheet.Cells(8, 2) = Customer_tb.Text
- xlSheet.Cells(7, 3) = "Size : "
- xlSheet.Cells(7, 4) = Size_tb.Text
- xlSheet.Cells(1, 5) = "PURPOSE"
- xlSheet.Cells(2, 5) = "Color : "
- xlSheet.Cells(7, 5) = "Date : "
- xlSheet.Cells(8, 5) = "S/O# : "
- xlSheet.Cells(2, 6) = Color_cb.Text
- xlSheet.Cells(7, 6) = Date_tb.Text
- xlSheet.Cells(8, 6) = SO_tb.Text
- AA(xlApp, xlSheet)
- xlSheet.PageSetup.PrintArea = ""
- xlApp.Cells.Select()
- xlSheet.Range("B1").Select()
- xlApp.Application.WindowState = xlMinimized
- MsgBox("列印完成")
- Me.Close()
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 取消列印_bt.Click
- 列印用SQL = "" : Me.Close()
- End Sub
- Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
- Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
- End Function
- Private Sub AA(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
- xlSheet.Cells.Select()
- With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False
- .Shadow = False : .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With
-
- xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 12
- xlSheet.Columns("B:D").Select : myExcel.Selection.ColumnWidth = 8
- xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 8
- xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 9
- xlSheet.Rows("1:8").Select : myExcel.Selection.RowHeight = 25
-
- xlSheet.Range("B2:D2").Select() : myExcel.Selection.Merge
- With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
- .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
-
- xlSheet.Range("B3:F3").Select() : myExcel.Selection.Merge
- With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
- .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
-
- xlSheet.Range("B4:F4").Select() : myExcel.Selection.Merge
- With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
- .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
-
- xlSheet.Range("B5:F5").Select() : myExcel.Selection.Merge
- With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
- .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
-
- xlSheet.Range("B6:F6").Select() : myExcel.Selection.Merge
- With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
- .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = True : End With
-
- myExcel.ActiveWindow.DisplayGridlines = False
-
- 'xlSheet.Range("A1:F8").Select()
- 'myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- 'With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
- 'With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
- 'With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
- 'With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
- 'myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
- 'xlSheet.Range("I5").Select()
-
- myExcel.Application.PrintCommunication = False
- With myExcel.ActiveSheet.PageSetup
- .PrintTitleRows = ""
- .PrintTitleColumns = ""
- End With
- myExcel.Application.PrintCommunication = True
- myExcel.ActiveSheet.PageSetup.PrintArea = ""
- myExcel.Application.PrintCommunication = False
- With myExcel.ActiveSheet.PageSetup
- .LeftHeader = ""
- .CenterHeader = ""
- .RightHeader = ""
- .LeftFooter = ""
- .CenterFooter = ""
- .RightFooter = ""
- .LeftMargin = myExcel.Application.InchesToPoints(0.236220472440945)
- .RightMargin = myExcel.Application.InchesToPoints(0.078740157480315)
- .TopMargin = myExcel.Application.InchesToPoints(0.078740157480315)
- .BottomMargin = myExcel.Application.InchesToPoints(0.078740157480315)
- .HeaderMargin = myExcel.Application.InchesToPoints(0)
- .FooterMargin = myExcel.Application.InchesToPoints(0)
- .PrintHeadings = False
- .PrintGridlines = False
- .PrintQuality = 203
- .CenterHorizontally = True
- .CenterVertically = True
- .Draft = False
- .PaperSize = 262
- .FirstPageNumber = xlAutomatic
- .Order = xlDownThenOver
- .BlackAndWhite = False
- .Zoom = False
- .FitToPagesWide = 1
- .FitToPagesTall = 1
- .OddAndEvenPagesHeaderFooter = False
- .DifferentFirstPageHeaderFooter = False
- .ScaleWithDocHeaderFooter = True
- .AlignMarginsHeaderFooter = True
- .EvenPage.LeftHeader.Text = ""
- .EvenPage.CenterHeader.Text = ""
- .EvenPage.RightHeader.Text = ""
- .EvenPage.LeftFooter.Text = ""
- .EvenPage.CenterFooter.Text = ""
- .EvenPage.RightFooter.Text = ""
- .FirstPage.LeftHeader.Text = ""
- .FirstPage.CenterHeader.Text = ""
- .FirstPage.RightHeader.Text = ""
- .FirstPage.LeftFooter.Text = ""
- .FirstPage.CenterFooter.Text = ""
- End With
- End Sub
- End Class
|