Option Strict Off Imports System.Data.SqlClient 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 Dim conn As New SqlConnection Dim da As New SqlDataAdapter Dim cmd As New SqlCommand Dim ds As New DataSet : Dim ds2 As New DataSet : Dim ds3 As New DataSet Dim dr As SqlDataReader Dim DTP As String : Dim GGHH As String : Dim DDFF As String Dim BBNN1 As Integer : Dim BBNN11 As String : Dim AAWW As String : Dim HHGG As String Dim RRTT As New Regex("[\u4e00-\u9fa5]") Dim KKOO As Double : Dim N1 As Integer Dim xlApp As Application Dim xlBook As Workbook Dim xlSheet As Worksheet Private Sub Set_DGV2載入前設定() DataGridView2.DataSource = Nothing : ds2.Clear() DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView2.ColumnHeadersHeight = 25 DataGridView2.AllowUserToAddRows = False DataGridView2.RowTemplate.Height = 25 If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If End Sub Private Sub Set_DGV2載入後設定() cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds2) : DataGridView2.DataSource = ds2.Tables(0) : conn.Close() : Set_grid() End Sub Private Sub Set_清單() Set_DGV2載入前設定() SQL1 = "SELECT 樣品訂單控制表.客戶, INVOICE樣品單.UPS, INVOICE樣品單.ATTN, INVOICE樣品單.CARTON, INVOICE樣品單.DATE FROM 樣品訂單控制表 INNER JOIN 樣品訂單清單 ON 樣品訂單控制表.SO = 樣品訂單清單.SO AND 樣品訂單控制表.版次 = 樣品訂單清單.版次 RIGHT OUTER JOIN INVOICE樣品單 ON 樣品訂單清單.流水號 = INVOICE樣品單.對應流水號 WHERE INVOICE樣品單.狀態 LIKE N'" & 樣品進度表分類4 & "' GROUP BY 樣品訂單控制表.客戶, INVOICE樣品單.UPS, INVOICE樣品單.ATTN, INVOICE樣品單.CARTON, INVOICE樣品單.DATE ORDER BY INVOICE樣品單.UPS DESC" Set_DGV2載入後設定() End Sub Private Sub Set_grid() DataGridView2.Columns(0).Width = 195 : DataGridView2.Columns(1).Width = 265 : DataGridView2.Columns(2).Width = 165 : DataGridView2.Columns(3).Width = 100 : DataGridView2.Columns(4).Width = 100 End Sub Private Sub Set_DGV1載入前設定() DataGridView1.DataSource = Nothing : ds.Clear() DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView1.ColumnHeadersHeight = 25 DataGridView1.AllowUserToAddRows = False DataGridView1.RowTemplate.Height = 50 If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If End Sub Private Sub Set_DGV1載入後設定() cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid1() End Sub Private Sub Set_清單1() Set_DGV1載入前設定() SQL1 = "SELECT 樣品訂單控制表.客戶 AS Customer, 樣品訂單控制表.狀態 AS [Sample type], INVOICE樣品單.HTS_CODE AS [Hts Code], 樣品訂單控制表.型體號碼 AS [Styie Number], 樣品訂單清單.顏色 AS Colorway, 樣品訂單清單.SO AS [Upper Material], 樣品訂單清單.SO AS [Outsole Material], INVOICE樣品單.G_S_F, INVOICE樣品單.PAIRS, INVOICE樣品單.UNIT AS [UNIT], INVOICE樣品單.PAIRS * INVOICE樣品單.UNIT AS [TTL], INVOICE樣品單.對應流水號 FROM 樣品訂單控制表 INNER JOIN 樣品訂單清單 ON 樣品訂單控制表.SO = 樣品訂單清單.SO AND 樣品訂單控制表.版次 = 樣品訂單清單.版次 RIGHT OUTER JOIN INVOICE樣品單 ON 樣品訂單清單.流水號 = INVOICE樣品單.對應流水號 WHERE (INVOICE樣品單.UPS LIKE N'" & TextBox2.Text & "') ORDER BY [Styie Number], Colorway" Set_DGV1載入後設定() End Sub Private Sub Set_grid1() DataGridView1.Columns(0).Width = 100 : DataGridView1.Columns(1).Width = 100 : DataGridView1.Columns(2).Width = 85 : DataGridView1.Columns(3).Width = 100 : DataGridView1.Columns(4).Width = 100 DataGridView1.Columns(5).Width = 163 : DataGridView1.Columns(6).Width = 162 : DataGridView1.Columns(7).Width = 50 : DataGridView1.Columns(8).Width = 50 : DataGridView1.Columns(9).Width = 50 DataGridView1.Columns(10).Width = 50 : DataGridView1.Columns(11).Visible = False DataGridView1.Columns(8).DefaultCellStyle.Format = "#,##0.0" : DataGridView1.Columns(9).DefaultCellStyle.Format = "#,##0.0" : DataGridView1.Columns(10).DefaultCellStyle.Format = "#,##0.0" DataGridView1.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView1.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView1.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView1.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight For i As Integer = 0 To DataGridView1.Rows.Count - 1 資料數 = DataGridView1.Rows.Count : MyModule1.進度條() conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT TOP (1) 材料名稱 FROM 樣品訂單部件表 WHERE (流水號 LIKE N'" & DataGridView1.Rows(i).Cells("對應流水號").Value & "') AND (部件 LIKE 'A.%') AND (部件 LIKE '%面料A' OR 部件 LIKE '%面料')" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader 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 : DataGridView1.Rows(i).Cells("Upper Material").Value = BBNN11 '-------------------------------------------------------------------------------------------- conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT TOP (1) 材料名稱 FROM 樣品訂單部件表 WHERE (流水號 LIKE N'" & DataGridView1.Rows(i).Cells("對應流水號").Value & "') AND (部件 LIKE N'E.OUTSOLE 大底')" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader 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 : DataGridView1.Rows(i).Cells("Outsole Material").Value = BBNN11 '-------------------------------------------------------------------------------------------- Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 End Sub Private Sub Set_DGV3載入前設定() DataGridView3.DataSource = Nothing : ds3.Clear() DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView3.ColumnHeadersHeight = 25 DataGridView3.AllowUserToAddRows = False If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If End Sub Private Sub Set_DGV3載入後設定() cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds3) : DataGridView3.DataSource = ds3.Tables(0) : conn.Close() : Set_grid4() End Sub Private Sub Set_清單3() Set_DGV3載入前設定() SQL1 = "SELECT 樣品訂單控制表.季節, 樣品訂單控制表.客戶, 樣品訂單控制表.SO, 樣品訂單控制表.版次, 樣品訂單控制表.型體號碼, 樣品訂單控制表.型體名稱, 樣品訂單清單.顏色, 樣品訂單清單.數量, CONVERT(money, 樣品訂單清單.KEEP) AS KEEP, 樣品訂單清單.寄出, 樣品訂單清單.流水號 FROM 樣品訂單清單 LEFT OUTER JOIN 樣品訂單控制表 ON 樣品訂單清單.SO = 樣品訂單控制表.SO AND 樣品訂單清單.版次 = 樣品訂單控制表.版次 WHERE (樣品訂單清單.數量 - CONVERT(money, 樣品訂單清單.KEEP) - 樣品訂單清單.寄出 > 0) AND (樣品訂單控制表.狀態 LIKE N'" & 樣品進度表分類4 & "') ORDER BY 樣品訂單控制表.型體號碼, 樣品訂單控制表.型體名稱, 樣品訂單清單.顏色" Set_DGV3載入後設定() End Sub Private Sub Set_grid4() DataGridView3.Columns(0).Width = 85 : DataGridView3.Columns(1).Width = 140 : DataGridView3.Columns(2).Width = 60 : DataGridView3.Columns(3).Width = 40 : DataGridView3.Columns(4).Width = 120 DataGridView3.Columns(5).Width = 140 : DataGridView3.Columns(6).Width = 120 : DataGridView3.Columns(7).Width = 40 : DataGridView3.Columns(8).Width = 40 : DataGridView3.Columns(9).Width = 40 DataGridView3.Columns(10).Visible = False DataGridView3.Columns(7).DefaultCellStyle.Format = "#,##0.0" : DataGridView3.Columns(8).DefaultCellStyle.Format = "#,##0.0" : DataGridView3.Columns(9).DefaultCellStyle.Format = "#,##0.0" DataGridView3.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView3.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView3.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView3.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView3.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView3.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight End Sub Private Sub ComboBox1下拉表單資料載入() conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT ATTN FROM INVOICE用客戶資料 ORDER BY ATTN" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader ComboBox1.Items.Clear() : While (dr.Read()) : ComboBox1.Items.Add(dr("ATTN")) : End While : conn.Close() End Sub Private Sub 樣品INVOICE_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 樣品訂單清單 SET KEEP = N'0' WHERE (KEEP LIKE N'')" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader : conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 樣品訂單清單 SET 寄出 = N'0' WHERE (寄出 IS NULL)" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader : conn.Close() ComboBox1下拉表單資料載入() Set_清單3() : Set_清單() ComboBox3.Text = "NA" : ComboBox2.Text = "NA" : ComboBox4.Text = "NA" Button8.Enabled = False : Button2.Enabled = False : Button6.Enabled = False : Button15.Enabled = False : Button4.Enabled = False Button3.Enabled = False : TextBox4.Enabled = False : TextBox3.Enabled = False DataGridView2.Visible = True : DataGridView3.Visible = False End Sub Private Sub 樣品INVOICE_Unload(sender As Object, e As EventArgs) Handles MyBase.Closing If Button8.Enabled = True Then If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "DELETE FROM INVOICE樣品單 WHERE (UPS = N'" & TextBox2.Text & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader : conn.Close() End If End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick If e.RowIndex = -1 Then : Else TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells("對應流水號").Value : TextBox5.Text = DataGridView1.Rows(e.RowIndex).Cells("PAIRS").Value End If End Sub Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick If e.RowIndex = -1 Then : Else TextBox2.Text = DataGridView2.Rows(e.RowIndex).Cells("UPS").Value ComboBox1.Text = DataGridView2.Rows(e.RowIndex).Cells("ATTN").Value ComboBox2.Text = DataGridView2.Rows(e.RowIndex).Cells("CARTON").Value TextBox6.Text = DataGridView2.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 DataGridView3.CellClick If e.RowIndex = -1 Then : Else TextBox3.Text = DataGridView3.Rows(e.RowIndex).Cells("流水號").Value TextBox4.Text = DataGridView3.Rows(e.RowIndex).Cells("數量").Value - DataGridView3.Rows(e.RowIndex).Cells("KEEP").Value - DataGridView3.Rows(e.RowIndex).Cells("寄出").Value TextBox4.Text = Strings.Format(Val(TextBox4.Text), "#,##0.0") End If End Sub Private Sub DataGridView3_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView3.RowPostPaint Dim linePen As New Pen(Color.Blue, 2) If e.RowIndex = DataGridView3.Rows.Count - 1 Then Exit Sub Else If DataGridView3(4, e.RowIndex).Value.ToString <> DataGridView3(4, e.RowIndex + 1).Value.ToString Then Dim startX As Integer = IIf(DataGridView3.RowHeadersVisible, DataGridView3.RowHeadersWidth, 0) Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1 Dim endX As Integer = startX + DataGridView3.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView3.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 TextBox5.TextChanged If TextBox5.Text = "" Then TextBox5.Text = "0" Else End If End Sub Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click 清單修改2.Close() : INVOICE用客戶資料 = True : 清單修改2.ShowDialog() : ComboBox1下拉表單資料載入() : INVOICE用客戶資料 = False End Sub Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT TEL FROM INVOICE用客戶資料 WHERE ATTN LIKE N'" & ComboBox1.Text & "' ORDER BY ATTN" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader If (dr.Read()) Then : TextBox1.Text = dr("TEL") : End If : conn.Close() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If TextBox2.Text = "" Or ComboBox1.Text = "" Or ComboBox2.Text = "NA" Then MsgBox("資料不齊全,請檢查UPS號、ATTN、CARTON等位置不可空白或NA") Else Button1.Enabled = False : TextBox2.Enabled = False : Button6.Enabled = True : Button15.Enabled = True Button18.Enabled = False : ComboBox1.Enabled = False : ComboBox2.Enabled = False : DataGridView2.Visible = False : DataGridView3.Visible = True conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT TOP(1) UPS FROM INVOICE樣品單 WHERE UPS LIKE N'" & TextBox2.Text & "' ORDER BY ATTN" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader If (dr.Read()) Then Button2.Enabled = True : conn.Close() Button6.Visible = False : Button15.Visible = False : Button6.Enabled = False : Button15.Enabled = False Button4.Visible = True : Button3.Visible = True : Button4.Enabled = True : Button3.Enabled = True Else Button8.Enabled = True : conn.Close() Button6.Visible = True : Button15.Visible = True : Button6.Enabled = True : Button15.Enabled = True Button4.Visible = False : Button3.Visible = False : Button4.Enabled = False : Button3.Enabled = False DataGridView1.DataSource = Nothing : ds.Clear() End If Set_清單3() End If End Sub Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click Button1.Enabled = True : Button8.Enabled = False : TextBox2.Enabled = True : Button6.Enabled = False : Button15.Enabled = False : Button4.Enabled = False : Button3.Enabled = False Button18.Enabled = True : ComboBox1.Enabled = True : ComboBox2.Enabled = True : DataGridView2.Visible = True : DataGridView3.Visible = False For i As Integer = 0 To DataGridView1.Rows.Count - 1 資料數 = DataGridView1.Rows.Count : MyModule1.進度條() conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 寄出 FROM 樣品訂單清單 WHERE 流水號 LIKE N'" & DataGridView1.Rows(i).Cells("對應流水號").Value & "'" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader If (dr.Read()) Then KKOO = dr("寄出") End If : conn.Close() KKOO = KKOO + DataGridView1.Rows(i).Cells("PAIRS").Value If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 樣品訂單清單 SET 寄出 = N'" & KKOO & "' WHERE (流水號 LIKE N'" & DataGridView1.Rows(i).Cells("對應流水號").Value & "')" cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 Set_清單() TextBox2.Text = "" : ComboBox1下拉表單資料載入() : ComboBox3.Text = "NA" : ComboBox2.Text = "NA" : ComboBox4.Text = "NA" : DataGridView1.DataSource = Nothing : ds.Clear() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Button1.Enabled = True : Button2.Enabled = False : TextBox2.Enabled = True : Button6.Enabled = False : Button15.Enabled = False : Button4.Enabled = False : Button3.Enabled = False Button18.Enabled = True : ComboBox1.Enabled = True : ComboBox2.Enabled = True : DataGridView2.Visible = True : DataGridView3.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 Button6.Click If ComboBox3.Text = "NA" Then MsgBox("材質不可為NA") ElseIf ComboBox4.Text = "NA" Then MsgBox("size不可為NA") Else If Val(TextBox4.Text) < Val(TextBox5.Text) Then MsgBox("寄出數不可大於可寄數,哪來的鞋子?") ElseIf Val(TextBox5.Text) = 0 Then MsgBox("寄出數不可為零,快遞公司無法寄幽靈?") Else Set_日期格式轉換() conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT UPS FROM INVOICE樣品單 WHERE UPS LIKE N'" & TextBox2.Text & "' AND 對應流水號 LIKE N'" & TextBox3.Text & "' ORDER BY ATTN" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader If (dr.Read()) Then MsgBox("本單號中已有新增過該資料,如有錯誤請刪除後從新添加。") conn.Close() Else If ComboBox3.Text = "皮" Then : GGHH = "6403990090" : ElseIf ComboBox3.Text = "PU" Then : GGHH = "6402992900" : ElseIf ComboBox3.Text = "布" Then : GGHH = "6404199000" : End If conn.Close() : dr.Close() : If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "INSERT INTO INVOICE樣品單 (UPS, ATTN, DATE, CARTON, G_S_F, PAIRS, UNIT, 對應流水號, HTS_CODE, 狀態) VALUES (N'" & TextBox2.Text & "', N'" & ComboBox1.Text & "', N'" & DTP & "', N'" & ComboBox2.Text & "', N'" & ComboBox4.Text & "', N'" & TextBox5.Text & "', N'2', N'" & TextBox3.Text & "', N'" & GGHH & "', N'" & 樣品進度表分類4 & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() Set_清單1() End If End If End If End Sub Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click If TextBox3.Text = "" Then MsgBox("沒有選擇要刪除的資料") Else If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "DELETE FROM INVOICE樣品單 WHERE (UPS = N'" & TextBox2.Text & "') AND (對應流水號 = N'" & TextBox3.Text & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader : conn.Close() Set_清單1() End If End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click If ComboBox3.Text = "NA" Then MsgBox("材質不可為NA") ElseIf ComboBox4.Text = "NA" Then MsgBox("size不可為NA") Else If Val(TextBox4.Text) < Val(TextBox5.Text) Then MsgBox("寄出數不可大於可寄數,哪來的鞋子?") ElseIf Val(TextBox5.Text) = 0 Then MsgBox("寄出數不可為零,快遞公司無法寄幽靈?") Else Set_日期格式轉換() conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT UPS FROM INVOICE樣品單 WHERE UPS LIKE N'" & TextBox2.Text & "' AND 對應流水號 LIKE N'" & TextBox3.Text & "' ORDER BY ATTN" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader If (dr.Read()) Then MsgBox("本單號中已有新增過該資料,如有錯誤請刪除後從新添加。") conn.Close() Else conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 寄出 FROM 樣品訂單清單 WHERE 流水號 LIKE N'" & TextBox3.Text & "'" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader If (dr.Read()) Then KKOO = dr("寄出") End If : conn.Close() KKOO = KKOO + Val(TextBox5.Text) If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 樣品訂單清單 SET 寄出 = N'" & KKOO & "' WHERE (流水號 LIKE N'" & TextBox3.Text & "')" cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() Set_清單3() If ComboBox3.Text = "皮" Then : GGHH = "6403990090" : ElseIf ComboBox3.Text = "PU" Then : GGHH = "6402992900" : ElseIf ComboBox3.Text = "布" Then : GGHH = "6404199000" : End If conn.Close() : dr.Close() : If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "INSERT INTO INVOICE樣品單 (UPS, ATTN, DATE, CARTON, G_S_F, PAIRS, UNIT, 對應流水號, HTS_CODE, 狀態) VALUES (N'" & TextBox2.Text & "', N'" & ComboBox1.Text & "', N'" & DTP & "', N'" & ComboBox2.Text & "', N'" & ComboBox4.Text & "', N'" & TextBox5.Text & "', N'2', N'" & TextBox3.Text & "', N'" & GGHH & "', N'" & 樣品進度表分類4 & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() Set_清單1() End If End If End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click If TextBox3.Text = "" Then MsgBox("沒有選擇要刪除的資料") Else conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 寄出 FROM 樣品訂單清單 WHERE 流水號 LIKE N'" & TextBox3.Text & "'" cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader If (dr.Read()) Then KKOO = dr("寄出") End If : conn.Close() KKOO = KKOO - Val(TextBox5.Text) If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 樣品訂單清單 SET 寄出 = N'" & KKOO & "' WHERE (流水號 LIKE N'" & TextBox3.Text & "')" cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() Set_清單3() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "DELETE FROM INVOICE樣品單 WHERE (UPS = N'" & TextBox2.Text & "') AND (對應流水號 = N'" & TextBox3.Text & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader : conn.Close() Set_清單1() End If End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.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) = ComboBox1.Text : xlSheet.Cells(7, 1) = "TEL : " : xlSheet.Cells(7, 2) = TextBox1.Text : xlSheet.Cells(8, 1) = "FAX : " xlSheet.Cells(9, 1) = "DATE : " : xlSheet.Cells(9, 2) = TextBox6.Text : xlSheet.Cells(7, 6) = "TEL : " : xlSheet.Cells(7, 7) = "0769-38937740" xlSheet.Cells(10, 1) = "INVOICE" : xlSheet.Cells(11, 1) = "Carton# : " & ComboBox2.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 DataGridView1.Rows.Count - 1 xlSheet.Cells(i + 13, 1) = DataGridView1.Rows(i).Cells("Customer").Value xlSheet.Cells(i + 13, 2) = DataGridView1.Rows(i).Cells("Sample type").Value xlSheet.Cells(i + 13, 3) = DataGridView1.Rows(i).Cells("Hts Code").Value xlSheet.Cells(i + 13, 4) = DataGridView1.Rows(i).Cells("Styie Number").Value xlSheet.Cells(i + 13, 5) = DataGridView1.Rows(i).Cells("Colorway").Value xlSheet.Cells(i + 13, 6) = DataGridView1.Rows(i).Cells("Upper Material").Value xlSheet.Cells(i + 13, 7) = DataGridView1.Rows(i).Cells("Outsole Material").Value xlSheet.Cells(i + 13, 8) = DataGridView1.Rows(i).Cells("G_S_F").Value xlSheet.Cells(i + 13, 9) = DataGridView1.Rows(i).Cells("PAIRS").Value xlSheet.Cells(i + 13, 10) = DataGridView1.Rows(i).Cells("UNIT").Value xlSheet.Cells(i + 13, 11) = DataGridView1.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 " & TextBox2.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 Button7.Click DataGridView2.Visible = True : DataGridView3.Visible = False End Sub Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click DataGridView2.Visible = False : DataGridView3.Visible = True End Sub End Class