Option Strict Off Imports System.Text.RegularExpressions 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 樣品INVOICE Private ReadOnly ds, ds2, ds3 As New DataSet Dim DDFF, BBNN11, AAWW, HHGG As String Dim N1, BBNN1 As Integer Private ReadOnly RRTT As New Regex("[\u4e00-\u9fa5]") Dim 已超出 As Boolean Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet Private Sub Set_DGV2載入前設定() 表單2_dgv.DataSource = Nothing : ds2.Clear() 表單2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 表單2_dgv.ColumnHeadersHeight = 25 表單2_dgv.AllowUserToAddRows = False 表單2_dgv.RowTemplate.Height = 25 End Sub Private Sub Set_DGV2載入後設定() da.Fill(ds2) : 表單2_dgv.DataSource = ds2.Tables(0) : conn.Close() : Set_grid() End Sub Private Sub Set_清單() Set_DGV2載入前設定() SQL_樣品INVOICE表單2() Set_DGV2載入後設定() End Sub Private Sub Set_grid() 表單2_dgv.Columns(0).Width = 195 : 表單2_dgv.Columns(1).Width = 265 : 表單2_dgv.Columns(2).Width = 165 : 表單2_dgv.Columns(3).Width = 100 : 表單2_dgv.Columns(4).Width = 100 End Sub Private Sub Set_DGV1載入前設定() 表單1_dgv.DataSource = Nothing : ds.Clear() 表單1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 表單1_dgv.ColumnHeadersHeight = 25 表單1_dgv.AllowUserToAddRows = False 表單1_dgv.RowTemplate.Height = 50 End Sub Private Sub Set_DGV1載入後設定() da.Fill(ds) : 表單1_dgv.DataSource = ds.Tables(0) : conn.Close() : Set_grid1() End Sub Private Sub Set_清單1() Set_DGV1載入前設定() SQL_樣品INVOICE表單1() Set_DGV1載入後設定() End Sub Private Sub Set_grid1() 表單1_dgv.Columns(0).Width = 100 : 表單1_dgv.Columns(1).Width = 100 : 表單1_dgv.Columns(2).Width = 85 : 表單1_dgv.Columns(3).Width = 100 : 表單1_dgv.Columns(4).Width = 100 表單1_dgv.Columns(5).Width = 163 : 表單1_dgv.Columns(6).Width = 162 : 表單1_dgv.Columns(7).Width = 50 : 表單1_dgv.Columns(8).Width = 50 : 表單1_dgv.Columns(9).Width = 50 表單1_dgv.Columns(10).Width = 50 : 表單1_dgv.Columns(11).Visible = False 表單1_dgv.Columns(8).DefaultCellStyle.Format = "#,##0.0" : 表單1_dgv.Columns(9).DefaultCellStyle.Format = "#,##0.0" : 表單1_dgv.Columns(10).DefaultCellStyle.Format = "#,##0.0" 表單1_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 表單1_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 表單1_dgv.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 表單1_dgv.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 表單1_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight : 表單1_dgv.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight For i As Integer = 0 To 表單1_dgv.Rows.Count - 1 資料數 = 表單1_dgv.Rows.Count : MyModule1.進度條() PA = 表單1_dgv.Rows(i).Cells("對應流水號").Value SQL_第一筆材料名稱() If (dr.Read()) Then : DDFF = dr("材料名稱") : Else : DDFF = "" : End If : conn.Close() '-------------------------------------------------------------------------------------------- BBNN1 = DDFF.Length.ToString() For II As Integer = 0 To BBNN1 - 1 If II = 0 Then AAWW = Strings.Left(DDFF, 1) If RRTT.IsMatch(AAWW) Then : Else : BBNN11 = Strings.Left(DDFF, 1) : End If Else AAWW = Strings.Mid(DDFF, II + 1, 1) : If RRTT.IsMatch(AAWW) Then : Else : HHGG = BBNN11 : BBNN11 = HHGG & AAWW : End If End If Next : 表單1_dgv.Rows(i).Cells("Upper Material").Value = BBNN11 '-------------------------------------------------------------------------------------------- SQL_第一筆材料名稱1() If (dr.Read()) Then : DDFF = dr("材料名稱") : Else : DDFF = "" : End If : conn.Close() '-------------------------------------------------------------------------------------------- BBNN1 = DDFF.Length.ToString() For II As Integer = 0 To BBNN1 - 1 If II = 0 Then AAWW = Strings.Left(DDFF, 1) If RRTT.IsMatch(AAWW) Then : Else : BBNN11 = Strings.Left(DDFF, 1) : End If Else AAWW = Strings.Mid(DDFF, II + 1, 1) : If RRTT.IsMatch(AAWW) Then : Else : HHGG = BBNN11 : BBNN11 = HHGG & AAWW : End If End If Next : 表單1_dgv.Rows(i).Cells("Outsole Material").Value = BBNN11 '-------------------------------------------------------------------------------------------- Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 End Sub Private Sub Set_DGV3載入前設定() 表單3_dgv.DataSource = Nothing : ds3.Clear() 表單3_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 表單3_dgv.ColumnHeadersHeight = 25 表單3_dgv.AllowUserToAddRows = False End Sub Private Sub Set_DGV3載入後設定() da.Fill(ds3) : 表單3_dgv.DataSource = ds3.Tables(0) : conn.Close() : Set_grid4() End Sub Private Sub Set_清單3() Set_DGV3載入前設定() SQL_樣品INVOICE表單3() Set_DGV3載入後設定() End Sub Private Sub Set_grid4() 表單3_dgv.Columns(0).Width = 85 : 表單3_dgv.Columns(1).Width = 140 : 表單3_dgv.Columns(2).Width = 60 : 表單3_dgv.Columns(3).Width = 40 : 表單3_dgv.Columns(4).Width = 120 表單3_dgv.Columns(5).Width = 140 : 表單3_dgv.Columns(6).Width = 120 : 表單3_dgv.Columns(7).Width = 40 : 表單3_dgv.Columns(8).Width = 40 : 表單3_dgv.Columns(9).Width = 40 表單3_dgv.Columns(10).Visible = False 表單3_dgv.Columns(7).DefaultCellStyle.Format = "#,##0.0" : 表單3_dgv.Columns(8).DefaultCellStyle.Format = "#,##0.0" : 表單3_dgv.Columns(9).DefaultCellStyle.Format = "#,##0.0" 表單3_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 表單3_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 表單3_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 表單3_dgv.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight : 表單3_dgv.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 表單3_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight End Sub Private Sub ComboBox1下拉表單資料載入() SQL_下拉ATTN() ATTN_cb.Items.Clear() : While (dr.Read()) : ATTN_cb.Items.Add(dr("ATTN")) : End While : conn.Close() End Sub Private Sub 樣品INVOICE_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 SQL_修改樣品訂單清單3() : conn.Close() SQL_修改樣品訂單清單4() : conn.Close() ComboBox1下拉表單資料載入() Set_清單3() : Set_清單() 材質_cb.Text = "NA" : Custon_cb.Text = "NA" : GenderSizeFoot_cb.Text = "NA" 資料存檔_bt.Enabled = False : 修改存檔_bt.Enabled = False : 新增1_bt.Enabled = False : 刪除1_bt.Enabled = False : 新增_bt.Enabled = False 刪除_bt.Enabled = False : 可寄出數_tb.Enabled = False : 流水號_tb.Enabled = False 表單2_dgv.Visible = True : 表單3_dgv.Visible = False End Sub Private Sub 樣品INVOICE_Unload(sender As Object, e As EventArgs) Handles MyBase.Closing If 資料存檔_bt.Enabled = True Then SQL_刪除INVOICE樣品單() : conn.Close() End If End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 表單1_dgv.CellClick If e.RowIndex = -1 Then : Else 流水號_tb.Text = 表單1_dgv.Rows(e.RowIndex).Cells("對應流水號").Value : 本次寄出數_tb.Text = 表單1_dgv.Rows(e.RowIndex).Cells("PAIRS").Value End If End Sub Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 表單2_dgv.CellClick If e.RowIndex = -1 Then : Else UPS_tb.Text = 表單2_dgv.Rows(e.RowIndex).Cells("UPS").Value ATTN_cb.Text = 表單2_dgv.Rows(e.RowIndex).Cells("ATTN").Value Custon_cb.Text = 表單2_dgv.Rows(e.RowIndex).Cells("CARTON").Value 日期_tb.Text = 表單2_dgv.Rows(e.RowIndex).Cells("DATE").Value Set_清單1() End If End Sub Private Sub DataGridView3_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 表單3_dgv.CellClick If e.RowIndex = -1 Then : Else 流水號_tb.Text = 表單3_dgv.Rows(e.RowIndex).Cells("流水號").Value 可寄出數_tb.Text = 表單3_dgv.Rows(e.RowIndex).Cells("數量").Value - 表單3_dgv.Rows(e.RowIndex).Cells("KEEP").Value - 表單3_dgv.Rows(e.RowIndex).Cells("寄出").Value 可寄出數_tb.Text = Strings.Format(Val(可寄出數_tb.Text), "#,##0.0") End If End Sub Private Sub DataGridView3_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 表單3_dgv.RowPostPaint Dim linePen As New Pen(Color.Blue, 2) If e.RowIndex = 表單3_dgv.Rows.Count - 1 Then Exit Sub Else If 表單3_dgv(4, e.RowIndex).Value.ToString <> 表單3_dgv(4, e.RowIndex + 1).Value.ToString Then Dim startX As Integer = IIf(表單3_dgv.RowHeadersVisible, 表單3_dgv.RowHeadersWidth, 0) Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1 Dim endX As Integer = startX + 表單3_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 表單3_dgv.HorizontalScrollingOffset e.Graphics.DrawLine(linePen, startX, startY, endX, startY) Exit Sub End If End If End Sub Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles 本次寄出數_tb.TextChanged If 本次寄出數_tb.Text = "" Then 本次寄出數_tb.Text = "0" Else End If End Sub Private Sub Button18_Click(sender As Object, e As EventArgs) Handles 新增清單_bt.Click 清單修改2.Close() : INVOICE用客戶資料 = True : 清單修改2.ShowDialog() : ComboBox1下拉表單資料載入() : INVOICE用客戶資料 = False End Sub Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ATTN_cb.SelectedIndexChanged SQL_INVOICE用客戶資料() If (dr.Read()) Then : TEL_tb.Text = dr("TEL") : End If : conn.Close() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 準備新增_bt.Click If UPS_tb.Text = "" Or ATTN_cb.Text = "" Or Custon_cb.Text = "NA" Then MsgBox("資料不齊全,請檢查UPS號、ATTN、CARTON等位置不可空白或NA") Else 準備新增_bt.Enabled = False : UPS_tb.Enabled = False : 新增1_bt.Enabled = True : 刪除1_bt.Enabled = True 新增清單_bt.Enabled = False : ATTN_cb.Enabled = False : Custon_cb.Enabled = False : 表單2_dgv.Visible = False : 表單3_dgv.Visible = True SQL_最後一筆UPS() If (dr.Read()) Then 修改存檔_bt.Enabled = True : conn.Close() 新增1_bt.Visible = False : 刪除1_bt.Visible = False : 新增1_bt.Enabled = False : 刪除1_bt.Enabled = False 新增_bt.Visible = True : 刪除_bt.Visible = True : 新增_bt.Enabled = True : 刪除_bt.Enabled = True Else 資料存檔_bt.Enabled = True : conn.Close() 新增1_bt.Visible = True : 刪除1_bt.Visible = True : 新增1_bt.Enabled = True : 刪除1_bt.Enabled = True 新增_bt.Visible = False : 刪除_bt.Visible = False : 新增_bt.Enabled = False : 刪除_bt.Enabled = False 表單1_dgv.DataSource = Nothing : ds.Clear() End If Set_清單3() End If End Sub Private Sub Button8_Click(sender As Object, e As EventArgs) Handles 資料存檔_bt.Click 準備新增_bt.Enabled = True : 資料存檔_bt.Enabled = False : UPS_tb.Enabled = True : 新增1_bt.Enabled = False : 刪除1_bt.Enabled = False : 新增_bt.Enabled = False : 刪除_bt.Enabled = False 新增清單_bt.Enabled = True : ATTN_cb.Enabled = True : Custon_cb.Enabled = True : 表單2_dgv.Visible = True : 表單3_dgv.Visible = False For i As Integer = 0 To 表單1_dgv.Rows.Count - 1 資料數 = 表單1_dgv.Rows.Count : MyModule1.進度條() PA = 表單1_dgv.Rows(i).Cells("對應流水號").Value SQL_讀取寄出() If (dr.Read()) Then KKOO = dr("寄出") End If : conn.Close() KKOO += 表單1_dgv.Rows(i).Cells("PAIRS").Value SQL_修改樣品訂單清單5() : conn.Close() Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 Set_清單() UPS_tb.Text = "" : ComboBox1下拉表單資料載入() : 材質_cb.Text = "NA" : Custon_cb.Text = "NA" : GenderSizeFoot_cb.Text = "NA" : 表單1_dgv.DataSource = Nothing : ds.Clear() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles 修改存檔_bt.Click 準備新增_bt.Enabled = True : 修改存檔_bt.Enabled = False : UPS_tb.Enabled = True : 新增1_bt.Enabled = False : 刪除1_bt.Enabled = False : 新增_bt.Enabled = False : 刪除_bt.Enabled = False 新增清單_bt.Enabled = True : ATTN_cb.Enabled = True : Custon_cb.Enabled = True : 表單2_dgv.Visible = True : 表單3_dgv.Visible = False Set_清單() End Sub Private Sub Set_日期格式轉換() DTP = Strings.Format(Today(), "yyyy/MM/dd") End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles 新增1_bt.Click If 材質_cb.Text = "NA" Then MsgBox("材質不可為NA") ElseIf GenderSizeFoot_cb.Text = "NA" Then MsgBox("size不可為NA") Else If Val(可寄出數_tb.Text) < Val(本次寄出數_tb.Text) Then MsgBox("寄出數不可大於可寄數,哪來的鞋子?") ElseIf Val(本次寄出數_tb.Text) = 0 Then MsgBox("寄出數不可為零,快遞公司無法寄幽靈?") Else Set_日期格式轉換() SQL_讀取INVOICE樣品單() If (dr.Read()) Then MsgBox("本單號中已有新增過該資料,如有錯誤請刪除後從新添加。") conn.Close() Else If 材質_cb.Text = "皮" Then : GGHH = "6403990090" : ElseIf 材質_cb.Text = "PU" Then : GGHH = "6402992900" : ElseIf 材質_cb.Text = "布" Then : GGHH = "6404199000" : End If dr.Close() : SQL_新增INVOICE樣品單() : conn.Close() Set_清單1() End If End If End If End Sub Private Sub Button15_Click(sender As Object, e As EventArgs) Handles 刪除1_bt.Click If 流水號_tb.Text = "" Then MsgBox("沒有選擇要刪除的資料") Else SQL_刪除INVOICE樣品單1() : conn.Close() Set_清單1() End If End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click If 材質_cb.Text = "NA" Then MsgBox("材質不可為NA") ElseIf GenderSizeFoot_cb.Text = "NA" Then MsgBox("size不可為NA") Else If Val(可寄出數_tb.Text) < Val(本次寄出數_tb.Text) Then MsgBox("寄出數不可大於可寄數,哪來的鞋子?") ElseIf Val(本次寄出數_tb.Text) = 0 Then MsgBox("寄出數不可為零,快遞公司無法寄幽靈?") Else Set_日期格式轉換() SQL_讀取INVOICE樣品單() If (dr.Read()) Then MsgBox("本單號中已有新增過該資料,如有錯誤請刪除後從新添加。") conn.Close() Else SQL_讀取寄出1() If (dr.Read()) Then KKOO = dr("寄出") End If : conn.Close() KKOO += Val(本次寄出數_tb.Text) SQL_修改樣品訂單清單6() : conn.Close() Set_清單3() If 材質_cb.Text = "皮" Then : GGHH = "6403990090" : ElseIf 材質_cb.Text = "PU" Then : GGHH = "6402992900" : ElseIf 材質_cb.Text = "布" Then : GGHH = "6404199000" : End If dr.Close() : SQL_新增INVOICE樣品單() : conn.Close() Set_清單1() End If End If End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click If 流水號_tb.Text = "" Then MsgBox("沒有選擇要刪除的資料") Else SQL_讀取寄出1() If (dr.Read()) Then KKOO = dr("寄出") End If : conn.Close() KKOO -= Val(本次寄出數_tb.Text) SQL_修改樣品訂單清單6() : conn.Close() Set_清單3() SQL_刪除INVOICE樣品單1() : conn.Close() Set_清單1() End If End Sub Private Sub Button5_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) = "SHIP TO :" : xlSheet.Cells(1, 2) = "Me Too LLC" : xlSheet.Cells(2, 2) = "49, West 37th street-2nd FL." : xlSheet.Cells(3, 2) = "New York, NY 10018" : xlSheet.Cells(4, 2) = "USA" xlSheet.Cells(1, 6) = "FROM :" : xlSheet.Cells(1, 7) = "DONGGUAN SEN KANG FOOTWEAR CO.,LTD" : xlSheet.Cells(2, 7) = "HuJing Road, Jiao yuan village," : xlSheet.Cells(3, 7) = "He Tian Managemet District.HouJie Town, " xlSheet.Cells(4, 7) = "Dongguan City Guangdong, CN 523945" : xlSheet.Cells(5, 7) = "China" xlSheet.Cells(6, 1) = "ATTN : " : xlSheet.Cells(6, 2) = ATTN_cb.Text : xlSheet.Cells(7, 1) = "TEL : " : xlSheet.Cells(7, 2) = TEL_tb.Text : xlSheet.Cells(8, 1) = "FAX : " xlSheet.Cells(9, 1) = "DATE : " : xlSheet.Cells(9, 2) = 日期_tb.Text : xlSheet.Cells(7, 6) = "TEL : " : xlSheet.Cells(7, 7) = "0769-38937740" xlSheet.Cells(10, 1) = "INVOICE" : xlSheet.Cells(11, 1) = "Carton# : " & Custon_cb.Text xlSheet.Cells(12, 1) = "Customer" : xlSheet.Cells(12, 2) = "Sample type" : xlSheet.Cells(12, 3) = "HTS CODE" : xlSheet.Cells(12, 4) = "Style Name" : xlSheet.Cells(12, 5) = "Colorway" xlSheet.Cells(12, 6) = "Upper Material" : xlSheet.Cells(12, 7) = "Outsole Material" : xlSheet.Cells(12, 8) = "Gender/Size/Foot" : xlSheet.Cells(12, 9) = "Pairs" : xlSheet.Cells(12, 10) = "UNIT(US$)" xlSheet.Cells(12, 11) = "TTL(US$)" N1 = 0 For i As Integer = 0 To 表單1_dgv.Rows.Count - 1 xlSheet.Cells(i + 13, 1) = 表單1_dgv.Rows(i).Cells("Customer").Value xlSheet.Cells(i + 13, 2) = 表單1_dgv.Rows(i).Cells("Sample type").Value xlSheet.Cells(i + 13, 3) = 表單1_dgv.Rows(i).Cells("Hts Code").Value xlSheet.Cells(i + 13, 4) = 表單1_dgv.Rows(i).Cells("Styie Number").Value xlSheet.Cells(i + 13, 5) = 表單1_dgv.Rows(i).Cells("Colorway").Value xlSheet.Cells(i + 13, 6) = 表單1_dgv.Rows(i).Cells("Upper Material").Value xlSheet.Cells(i + 13, 7) = 表單1_dgv.Rows(i).Cells("Outsole Material").Value xlSheet.Cells(i + 13, 8) = 表單1_dgv.Rows(i).Cells("G_S_F").Value xlSheet.Cells(i + 13, 9) = 表單1_dgv.Rows(i).Cells("PAIRS").Value xlSheet.Cells(i + 13, 10) = 表單1_dgv.Rows(i).Cells("UNIT").Value xlSheet.Cells(i + 13, 11) = 表單1_dgv.Rows(i).Cells("TTL").Value N1 = i Next xlSheet.Cells(N1 + 15, 8) = "TOTAL" : xlSheet.Cells(N1 + 15, 9) = "=SUM(I13:I" & N1 + 14 & ")" : xlSheet.Cells(N1 + 15, 11) = "=SUM(K13:K" & N1 + 14 & ")" xlSheet.Cells(N1 + 16, 1) = "Samples are marked or mutilated and classified HTS 6403990090&6402992900& 6404199000 per ruling letter N247780 attached" xlSheet.Cells(N1 + 17, 1) = "VALUE FOR CUSTOMS PURPOSES ONLY" xlSheet.Cells(N1 + 18, 1) = "UPS " & UPS_tb.Text xlSheet.Cells(N1 + 19, 1) = "MADE IN CHINA SAMPLE NOT FOR RESALE" xlSheet.Cells(N1 + 20, 1) = "SIGNATURE : " & gUserName AA(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 AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet) xlSheet.Cells.Select() With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With xlSheet.Range("A1:A9").Select() myExcel.Selection.Font.Bold = True With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With xlSheet.Range("F1:F9").Select() myExcel.Selection.Font.Bold = True With myExcel.Selection : .HorizontalAlignment = xlRight : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With xlSheet.Rows("1:9").Select : myExcel.Selection.RowHeight = 20 : xlSheet.Rows("10:10").Select : myExcel.Selection.RowHeight = 25 xlSheet.Rows("11:11").Select : myExcel.Selection.RowHeight = 30 : xlSheet.Rows("12:12").Select : myExcel.Selection.RowHeight = 25 xlSheet.Rows("13:" & N1 + 15).Select : myExcel.Selection.RowHeight = 30 With myExcel.Selection : .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 20 xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 15 xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 13 xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 15 xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 15 xlSheet.Columns("F:G").Select : myExcel.Selection.ColumnWidth = 20 xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 15 xlSheet.Columns("I:K").Select : myExcel.Selection.ColumnWidth = 8 xlSheet.Rows("12:" & N1 + 15).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 With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With xlSheet.Rows(13 + N1 + 3 & ":" & 13 + N1 + 7).Select : myExcel.Selection.RowHeight = 25 : myExcel.Selection.Font.Bold = True xlSheet.Rows("10:11").Select : myExcel.Selection.Font.Bold = True xlSheet.Range("A10:K10").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 20 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone : End With xlSheet.Range("A11:K11").Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge 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.Range("A" & 13 + N1 + 3 & ":K" & 13 + N1 + 3).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge xlSheet.Range("A" & 13 + N1 + 4 & ":K" & 13 + N1 + 4).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge xlSheet.Range("A" & 13 + N1 + 5 & ":K" & 13 + N1 + 5).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge xlSheet.Range("A" & 13 + N1 + 6 & ":K" & 13 + N1 + 6).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge xlSheet.Range("A" & 13 + N1 + 7 & ":K" & 13 + N1 + 7).Select() With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False .ReadingOrder = xlContext : .MergeCells = False : End With : myExcel.Selection.Merge xlSheet.Range("A10:K10").Select() myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone xlSheet.Range("A12:K" & 13 + N1 + 2).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 myExcel.ActiveWindow.DisplayGridlines = False myExcel.Application.CutCopyMode = False myExcel.Application.PrintCommunication = False With myExcel.ActiveSheet.PageSetup .PrintTitleRows = "$1:$12" .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.236220472440945) .TopMargin = myExcel.Application.InchesToPoints(0.748031496062992) .BottomMargin = myExcel.Application.InchesToPoints(0.748031496062992) .HeaderMargin = myExcel.Application.InchesToPoints(0.31496062992126) .FooterMargin = myExcel.Application.InchesToPoints(0.31496062992126) .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 Button7_Click(sender As Object, e As EventArgs) Handles INVO_bt.Click 表單2_dgv.Visible = True : 表單3_dgv.Visible = False End Sub Private Sub Button9_Click(sender As Object, e As EventArgs) Handles 樣品單_bt.Click 表單2_dgv.Visible = False : 表單3_dgv.Visible = True End Sub Private Sub 表單3_dgv_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 表單3_dgv.MouseUp If 表單3_dgv.SelectedCells.Count = 1 Then 已超出 = False End If If 表單3_dgv.SelectedCells.Count > 0 Then '設定滑鼠點擊DGV時候的範圍,超出範圍時有可能不是數字所以不計算 If 表單3_dgv.SelectedCells(0).ColumnIndex >= 7 And 表單3_dgv.SelectedCells(0).ColumnIndex <= 9 Then If 已超出 = False Then Dim x As Double = 0 For i As Integer = 0 To 表單3_dgv.SelectedCells.Count - 1 '表單3_dgv.SelectedCells.Item(i).ColumnIndex + 8 是因為該DGV顯示項與計算像剛好差8格,使用時要注意可直接計算的不需要加數字。 x += Val(表單3_dgv.Rows(表單3_dgv.SelectedCells.Item(i).RowIndex).Cells(表單3_dgv.SelectedCells.Item(i).ColumnIndex).Value) Next i '將計算好的資料放置到指定的控件中 WINPROFIT_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(x, "#,##0") Else WINPROFIT_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") End If Else 已超出 = True WINPROFIT_ERP_SYS.合計_TSSL.Text = "合計 : " & Strings.Format(0, "#,##0") End If End If End Sub End Class