Option Strict Off Imports System.IO Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle Imports Microsoft.Office.Interop.Excel.Constants Imports Microsoft.Office.Interop.Excel.XlBordersIndex Imports Microsoft.Office.Interop.Excel.XlLineStyle Imports Microsoft.Office.Interop.Excel.XlBorderWeight Imports Microsoft.Office.Interop.Excel.XlThemeFont Imports Microsoft.Office.Interop.Excel.XlThemeColor Imports Microsoft.Office.Interop.Excel.XlWindowState Imports Microsoft.Office.Interop.Excel Public Class 試穿_訂料授權書 Private ReadOnly ds, ds1, ds2 As New DataSet Dim N1 As Integer Dim 位置1 As String Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet Private Sub Set_清單() 主表單_dgv.DataSource = Nothing : ds.Clear() 主表單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 主表單_dgv.ColumnHeadersHeight = 25 主表單_dgv.AllowUserToAddRows = False 主表單_dgv.RowTemplate.Height = 50 SQL_預告訂單控制表單() da.Fill(ds) : 主表單_dgv.DataSource = ds.Tables(0) : conn.Close() : Set_grid() End Sub Private Sub Set_grid() Dim YY As Integer = 主表單_dgv.Size.Height If 清單伸展_ch.Checked = False Then 主表單_dgv.Size = New Size(475, YY) 主表單_dgv.Columns(0).Width = 85 : 主表單_dgv.Columns(1).Width = 55 : 主表單_dgv.Columns(2).Width = 65 : 主表單_dgv.Columns(3).Width = 100 : 主表單_dgv.Columns(6).Width = 100 主表單_dgv.Columns(7).Visible = False Else 主表單_dgv.Size = New Size(745, YY) 主表單_dgv.Columns(0).Width = 85 : 主表單_dgv.Columns(1).Width = 55 : 主表單_dgv.Columns(2).Width = 65 : 主表單_dgv.Columns(3).Width = 170 : 主表單_dgv.Columns(6).Width = 150 主表單_dgv.Columns(7).Visible = True : 主表單_dgv.Columns(7).Width = 150 End If 主表單_dgv.Columns(4).Visible = False : 主表單_dgv.Columns(5).Visible = False : 主表單_dgv.Columns(8).Visible = False 主表單_dgv.Columns(9).Visible = False : 主表單_dgv.Columns(10).Visible = False : 主表單_dgv.Columns(11).Visible = False : 主表單_dgv.Columns(12).Visible = False 主表單_dgv.Columns(13).Visible = False : 主表單_dgv.Columns(14).Visible = False : 主表單_dgv.Columns(15).Visible = False : 主表單_dgv.Columns(16).Width = 45 End Sub Private Sub Set_清單1() 明細1_dgv.DataSource = Nothing : ds1.Clear() 明細1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 明細1_dgv.ColumnHeadersHeight = 40 明細1_dgv.AllowUserToAddRows = False 明細1_dgv.RowTemplate.Height = 150 SQL_明細1() da.Fill(ds1) : 明細1_dgv.DataSource = ds1.Tables(0) : conn.Close() For i As Integer = 0 To 明細1_dgv.Rows.Count - 1 If IsDBNull(明細1_dgv.Rows(i).Cells("FITTING COMMENTS").Value) Then : 明細1_dgv.Rows(i).Cells("FITTING COMMENTS").Value = " " : End If If IsDBNull(明細1_dgv.Rows(i).Cells("MATERAL COMMENTS").Value) Then : 明細1_dgv.Rows(i).Cells("MATERAL COMMENTS").Value = " " : End If If IsDBNull(明細1_dgv.Rows(i).Cells("FITTING回簽確認").Value) Then : 明細1_dgv.Rows(i).Cells("FITTING回簽確認").Value = " " : End If If IsDBNull(明細1_dgv.Rows(i).Cells("FITTING回簽日期").Value) Then : 明細1_dgv.Rows(i).Cells("FITTING回簽日期").Value = " " : End If If IsDBNull(明細1_dgv.Rows(i).Cells("MATERAIL回簽確認").Value) Then : 明細1_dgv.Rows(i).Cells("MATERAIL回簽確認").Value = " " : End If If IsDBNull(明細1_dgv.Rows(i).Cells("MATERAIL回簽日期").Value) Then : 明細1_dgv.Rows(i).Cells("MATERAIL回簽日期").Value = " " : End If Next 明細1_dgv.Columns(0).Visible = False : 明細1_dgv.Columns(1).Visible = False : 明細1_dgv.Columns(2).Visible = False : 明細1_dgv.Columns(3).Width = 100 明細1_dgv.Columns(4).Width = 100 : 明細1_dgv.Columns(5).Width = 100 : 明細1_dgv.Columns(6).Width = 275 : 明細1_dgv.Columns(7).Width = 80 : 明細1_dgv.Columns(8).Width = 80 明細1_dgv.Columns(9).Width = 125 : 明細1_dgv.Columns(10).Width = 125 : 明細1_dgv.Columns(11).Width = 100 : 明細1_dgv.Columns(12).Width = 100 : 明細1_dgv.Columns(13).Width = 100 明細1_dgv.Columns(14).Width = 100 : 明細1_dgv.Columns(15).Visible = False : 明細1_dgv.Columns(16).Visible = False 明細1_dgv.EditMode = DataGridViewEditMode.EditOnEnter For i As Integer = 0 To 明細1_dgv.Rows.Count - 1 資料數 = 明細1_dgv.Rows.Count : MyModule1.進度條() 明細1_dgv.Rows(i).Cells("MATERIAL_DESCRIPTION").Value = "" Dim aa As Integer = 1 For ii As Integer = 0 To 明細2_dgv.Rows.Count - 1 If 明細1_dgv.Rows(i).Cells("流水號").Value = 明細2_dgv.Rows(ii).Cells("流水號").Value Then If aa = 1 Then 明細1_dgv.Rows(i).Cells("MATERIAL_DESCRIPTION").Value = aa & "、" & 明細2_dgv.Rows(ii).Cells("材料名稱").Value & "-" & 明細2_dgv.Rows(ii).Cells("材料說明").Value aa += 1 Else 明細1_dgv.Rows(i).Cells("MATERIAL_DESCRIPTION").Value = 明細1_dgv.Rows(i).Cells("MATERIAL_DESCRIPTION").Value & " " & aa & "、" & 明細2_dgv.Rows(ii).Cells("材料名稱").Value & "-" & 明細2_dgv.Rows(ii).Cells("材料說明").Value aa += 1 End If End If Next Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 End Sub Private Sub Set_清單2() 明細2_dgv.DataSource = Nothing : ds2.Clear() 明細2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 明細2_dgv.ColumnHeadersHeight = 25 明細2_dgv.AllowUserToAddRows = False 明細2_dgv.RowTemplate.Height = 50 SQL_明細2() da.Fill(ds2) : 明細2_dgv.DataSource = ds2.Tables(0) : conn.Close() End Sub Private Sub 試穿_定料授權書_Load(sender As Object, e As EventArgs) Handles MyBase.Load WINPROFIT_ERP_SYS.WindowState = 2 : Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True 明細2_dgv.Visible = False Set_清單() End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If 提醒_lb.Visible = True Then : 提醒_lb.Visible = False : Else : 提醒_lb.Visible = True : End If End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 主表單_dgv.CellClick If e.RowIndex = -1 Then : Else 預告訂單單號_tb.Text = 主表單_dgv.Rows(e.RowIndex).Cells("PAO").Value : 版次_tb.Text = 主表單_dgv.Rows(e.RowIndex).Cells("版次").Value : Set_清單2() : Set_清單1() 客戶_tb.Text = 主表單_dgv.Rows(e.RowIndex).Cells("客戶").Value : Timer1.Enabled = False PictureBox2.Image = Nothing PA = 主表單_dgv.Rows(e.RowIndex).Cells("客戶").Value : PA1 = 主表單_dgv.Rows(e.RowIndex).Cells("型體號碼").Value SQL_鞋型圖片資料庫() While dr.Read() = True Dim unused As Byte() = New Byte(-1) {} : Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte()) Dim oStream As New MemoryStream(bytes) : PictureBox2.Image = Bitmap.FromStream(oStream) End While conn.Close() : PictureBox2.SizeMode = 4 : PictureBox1.Image = Nothing End If End Sub Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 明細1_dgv.CellClick If e.RowIndex = -1 Then : Else Timer1.Enabled = True PictureBox1.Image = Nothing PA = 明細1_dgv.Rows(e.RowIndex).Cells("客戶").Value : PA1 = 明細1_dgv.Rows(e.RowIndex).Cells("型體號碼").Value PA2 = 明細1_dgv.Rows(e.RowIndex).Cells("STYLE_NAME").Value : PA3 = 明細1_dgv.Rows(e.RowIndex).Cells("COLOR").Value SQL_鞋型圖片資料庫1() If dr.Read() Then PictureBox1.Image = Nothing SQL_鞋型圖片資料庫1() While dr.Read() = True Dim unused1 As Byte() = New Byte(-1) {} : Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte()) Dim oStream As New MemoryStream(bytes) : PictureBox1.Image = Bitmap.FromStream(oStream) End While conn.Close() Else PictureBox1.Image = Nothing PA4 = 明細1_dgv.Rows(e.RowIndex).Cells("客戶").Value : PA5 = 明細1_dgv.Rows(e.RowIndex).Cells("型體號碼").Value SQL_鞋型圖片資料庫2() If dr.Read() Then PictureBox1.Image = Nothing SQL_鞋型圖片資料庫2() While dr.Read() = True Dim unused As Byte() = New Byte(-1) {} : Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte()) Dim oStream As New MemoryStream(bytes) : PictureBox1.Image = Bitmap.FromStream(oStream) End While conn.Close() Else PictureBox1.Image = Nothing End If conn.Close() End If : PictureBox1.SizeMode = 4 End If End Sub Private Sub Button9_Click(sender As Object, e As EventArgs) Handles 搜尋_bt.Click PA = InputBox("請輸入要查詢的關鍵字") : Set_清單() : PA = "" End Sub Private Sub Button32_Click(sender As Object, e As EventArgs) Handles 返回_bt.Click PA = "" : Set_清單() End Sub Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles 清單伸展_ch.Click Set_grid() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click For i As Integer = 0 To 明細1_dgv.Rows.Count - 1 資料數 = 明細1_dgv.Rows.Count : MyModule1.進度條() PA = 明細1_dgv.Rows(i).Cells("FITTING COMMENTS").Value : PA1 = 明細1_dgv.Rows(i).Cells("MATERAL COMMENTS").Value PA2 = 明細1_dgv.Rows(i).Cells("FITTING回簽確認").Value : PA3 = 明細1_dgv.Rows(i).Cells("FITTING回簽日期").Value PA4 = 明細1_dgv.Rows(i).Cells("MATERAIL回簽確認").Value : PA5 = 明細1_dgv.Rows(i).Cells("MATERAIL回簽日期").Value PA6 = 明細1_dgv.Rows(i).Cells("流水號").Value SQL_修改預告訂單清單() : conn.Close() Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 Timer1.Enabled = False : Set_清單1() : MsgBox("存檔完成。") End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 列印_bt.Click xlApp = CType(CreateObject("Excel.Application"), 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) = "FIT MATERIAL AUTHORIZATION FORM" : xlSheet.Cells(2, 1) = 客戶_tb.Text : xlSheet.Cells(3, 1) = "DATE : " & Strings.Format(Today(), "yyyy/MM/dd") xlSheet.Cells(4, 1) = "PHOTO" : xlSheet.Cells(4, 2) = "BUYER" : xlSheet.Cells(4, 3) = "STYLE NAME" xlSheet.Cells(4, 4) = "COLOR" : xlSheet.Cells(4, 5) = " MATERIAL DESCRIPTION" xlSheet.Cells(4, 6) = "XF" : xlSheet.Cells(4, 7) = "REFERENCE SAMPLE" xlSheet.Cells(4, 8) = "FITTING COMMENTS" xlSheet.Cells(4, 9) = "MATERAL COMMENTS" N1 = 0 For i As Integer = 0 To 明細1_dgv.Rows.Count - 1 xlSheet.Cells(i + 5, 2) = 明細1_dgv.Rows(i).Cells("客戶").Value xlSheet.Cells(i + 5, 3) = 明細1_dgv.Rows(i).Cells("STYLE_NAME").Value xlSheet.Cells(i + 5, 4) = 明細1_dgv.Rows(i).Cells("COLOR").Value xlSheet.Cells(i + 5, 5) = 明細1_dgv.Rows(i).Cells("MATERIAL_DESCRIPTION").Value xlSheet.Cells(i + 5, 6) = 明細1_dgv.Rows(i).Cells("XF").Value xlSheet.Cells(i + 5, 7) = 明細1_dgv.Rows(i).Cells("REFERENCE SAMPL").Value xlSheet.Cells(i + 5, 8) = 明細1_dgv.Rows(i).Cells("FITTING COMMENTS").Value xlSheet.Cells(i + 5, 9) = 明細1_dgv.Rows(i).Cells("MATERAL COMMENTS").Value N1 = i + 5 PictureBox1.Image = Nothing PA = 明細1_dgv.Rows(i).Cells("客戶").Value : PA1 = 明細1_dgv.Rows(i).Cells("型體號碼").Value PA2 = 明細1_dgv.Rows(i).Cells("STYLE_NAME").Value : PA3 = 明細1_dgv.Rows(i).Cells("COLOR").Value SQL_鞋型圖片資料庫3() If dr.Read() Then PictureBox1.Image = Nothing SQL_鞋型圖片資料庫3() While dr.Read() = True Dim unused1 As Byte() = New Byte(-1) {} : Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte()) Dim oStream As New MemoryStream(bytes) : PictureBox1.Image = Bitmap.FromStream(oStream) End While conn.Close() : GG(xlApp, xlSheet) Else PictureBox1.Image = Nothing PA4 = 明細1_dgv.Rows(i).Cells("客戶").Value : PA5 = 明細1_dgv.Rows(i).Cells("型體號碼").Value SQL_鞋型圖片資料庫4() If dr.Read() Then PictureBox1.Image = Nothing SQL_鞋型圖片資料庫4() While dr.Read() = True Dim unused As Byte() = New Byte(-1) {} : Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte()) Dim oStream As New MemoryStream(bytes) : PictureBox1.Image = Bitmap.FromStream(oStream) End While conn.Close() : GG(xlApp, xlSheet) Else xlSheet.Cells(i + 5, 1) = "系統中無圖片" conn.Close() End If End If : PictureBox1.SizeMode = 4 Next i BB(xlApp, xlSheet) xlSheet.PageSetup.PrintArea = "" xlApp.Cells.Select() xlSheet.Range("B1").Select() xlApp.Application.WindowState = xlMinimized MsgBox("列印完成") End Sub Private Shared Function NewMethod(xlBook As Workbook) As Worksheet Return CType(xlBook.Worksheets.Add, Worksheet) End Function Private Sub BB(ByVal myExcel As Application, ByVal xlSheet As 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.Rows("1:1").Select With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 28 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With xlSheet.Rows("2:2").Select With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 16 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With xlSheet.Rows("3:3").Select With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 16 : .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:B").Select : myExcel.Selection.ColumnWidth = 15 xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 12 : xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 15 xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 60 : xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 12 xlSheet.Columns("G:G").Select : myExcel.Selection.ColumnWidth = 15 : xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 20 xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 20 : xlSheet.Rows("4:4").Select : myExcel.Selection.RowHeight = 40 : myExcel.Selection.Font.Bold = True For i As Integer = 5 To N1 'xlSheet.Rows(i & ":" & i).Select : myExcel.Rows(i & ":" & i).EntireRow.AutoFit xlSheet.Rows(i & ":" & i).Select : myExcel.Selection.RowHeight = 80 Next xlSheet.Columns("F:F").Select With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With 位置1 = "A4:I" & N1 : xlSheet.Range(位置1).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 With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With xlSheet.Rows("5:5").Select : myExcel.ActiveWindow.FreezePanes = True : myExcel.ActiveWindow.DisplayGridlines = False xlSheet.Range("F1").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.25) : .RightMargin = myExcel.Application.InchesToPoints(0.25) .TopMargin = myExcel.Application.InchesToPoints(0.75) : .BottomMargin = myExcel.Application.InchesToPoints(0.75) .HeaderMargin = myExcel.Application.InchesToPoints(0.3) : .FooterMargin = myExcel.Application.InchesToPoints(0.3) .PrintHeadings = False : .PrintGridlines = False : .PrintQuality = 600 : .CenterHorizontally = False : .CenterVertically = False : .Draft = False .FirstPageNumber = xlAutomatic : .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 = "" : .FirstPage.RightFooter.Text = "" End With myExcel.Application.PrintCommunication = True End Sub Private Sub GG(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet) Dim 位置1 As String Clipboard.SetDataObject(PictureBox1.Image) 位置1 = "A" & N1 : xlSheet.Range(位置1).Select() myExcel.ActiveSheet.Pictures.Paste.Select myExcel.Selection.ShapeRange.Width = 70 myExcel.Selection.ShapeRange.IncrementLeft(3) myExcel.Selection.ShapeRange.IncrementTop(3) End Sub End Class