Option Strict Off
Imports System.Data.SqlClient
Public Class 量產訂單輸入
    ReadOnly conn As New SqlConnection
    ReadOnly da As New SqlDataAdapter
    ReadOnly cmd As New SqlCommand
    ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet : ReadOnly ds3 As New DataSet : ReadOnly ds4 As New DataSet
    Dim dr As SqlDataReader
    Dim DTP As String : Dim DTP1 As String : Dim DDFF As String
    Private Sub Set_清單2()
        DataGridView4.DataSource = Nothing : ds2.Clear()
        DataGridView4.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView4.ColumnHeadersHeight = 25
        DataGridView4.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        If PA = "" Then : DDFF = "" : Else
            DDFF = " WHERE 訂單流水號 LIKE N'%" & PA & "%' OR 客戶訂單號 LIKE N'%" & PA & "%' OR ConstructionName LIKE N'%" & PA & "%' OR ModeOfDelivery LIKE N'%" & PA & "%' OR 
                           DeliveryTerms LIKE N'%" & PA & "%' OR OrgShipDate LIKE N'%" & PA & "%' OR FromPort LIKE N'%" & PA & "%' OR ToPort LIKE N'%" & PA & "%' OR 
                           ShippingCarrier LIKE N'%" & PA & "%' OR VendorReference LIKE N'%" & PA & "%' OR ModifiedDate LIKE N'%" & PA & "%' OR CustomerName LIKE N'%" & PA & "%' OR 
                           ShipDate LIKE N'%" & PA & "%' OR SalesOrder LIKE N'%" & PA & "%' OR DeliveryAddress LIKE N'%" & PA & "%' OR 下單日 LIKE N'%" & PA & "%' OR 交期 LIKE N'%" & PA & "%' OR 
                           ETADate LIKE N'%" & PA & "%' OR CreatedDate LIKE N'%" & PA & "%' OR Brand LIKE N'%" & PA & "%' OR CustomerRequisition LIKE N'%" & PA & "%' OR 工廠 LIKE N'%" & PA & "%' "
        End If
        SQL1 = "SELECT 訂單流水號, 客戶訂單號, ConstructionName, ModeOfDelivery, DeliveryTerms, OrgShipDate, FromPort, ToPort, 
                       ShippingCarrier, VendorReference, ModifiedDate, CustomerName, ShipDate, SalesOrder, DeliveryAddress, 下單日, 
                       交期, ETADate, CreatedDate, Brand, CustomerRequisition, 工廠
                FROM 訂單明細表抬頭  " & DDFF & " ORDER BY 訂單流水號 DESC"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds2) : DataGridView4.DataSource = ds2.Tables(0) : conn.Close()

        DataGridView4.Columns(0).FillWeight = 120 : DataGridView4.Columns(1).FillWeight = 150 : DataGridView4.Columns(2).Visible = False : DataGridView4.Columns(3).Visible = False
        DataGridView4.Columns(4).Visible = False : DataGridView4.Columns(5).Visible = False : DataGridView4.Columns(6).Visible = False : DataGridView4.Columns(7).Visible = False
        DataGridView4.Columns(8).Visible = False : DataGridView4.Columns(9).Visible = False : DataGridView4.Columns(10).Visible = False : DataGridView4.Columns(11).Visible = False
        DataGridView4.Columns(12).Visible = False : DataGridView4.Columns(13).Visible = False : DataGridView4.Columns(14).Visible = False : DataGridView4.Columns(15).FillWeight = 90
        DataGridView4.Columns(16).FillWeight = 90 : DataGridView4.Columns(17).Visible = False : DataGridView4.Columns(18).Visible = False : DataGridView4.Columns(19).Visible = False
        DataGridView4.Columns(20).Visible = False : DataGridView4.Columns(21).Visible = False
    End Sub
    Private Sub Set_清單1()
        DataGridView2.DataSource = Nothing : ds1.Clear()
        DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView2.ColumnHeadersHeight = 25
        DataGridView2.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT     訂單顏色清單.顏色, METOO選擇按鈕.選擇 FROM  訂單顏色清單 LEFT OUTER JOIN  METOO選擇按鈕 ON 訂單顏色清單.顏色 = METOO選擇按鈕.對應
                WHERE      訂單顏色清單.顏色 LIKE N'%" & TextBox1.Text & "%'
                ORDER BY   訂單顏色清單.顏色"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close()

        DataGridView2.Columns(0).FillWeight = 110 : DataGridView2.Columns(1).FillWeight = 40
        For i As Integer = 0 To DataGridView2.Rows.Count - 1
            DataGridView2.Rows(i).Cells("選擇").Value = False
        Next i
    End Sub
    Private Sub Set_清單3()
        DataGridView3.DataSource = Nothing : ds3.Clear()
        DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView3.ColumnHeadersHeight = 40
        DataGridView3.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 資料流水號, 年份季度, 客戶訂單號, 型體號碼, GOODBOX AS 型體名稱, APMA確認 AS 顏色, TVW AS 楦型, 訂單數量, 工廠回復交期 AS  工廠交期, 客戶交期 AS 交期開始, 客戶交期1 AS 交期結束, 
                       單價, 總金額, 備註, 生產工廠, 訂單種類, BUYER, CFMSPEC AS 訂單屬性, CFMSAMPLE, TRIAL1, TRIAL2, TRIAL3, TRIAL4, 包裝確認時間, 貼標時間, 裁斷時間, 針車時間, 成型時間, 驗貨時間, 
                       實際離廠日, 訂單流水號, 明細建檔, LEATHER, LEA_Note, CXL, CXLTime, 出貨數量, PO_S_Date, Requested_XF, Confirm_XF, Revised_XF, Special_Packaging, Remarks, 出貨地, 
                       楦頭號, 材質, 長期試穿, 面料, 副料, 中底, 鞋墊, 大底, 跟, 工廠進度表備註1, 七號模具, 工廠進度表備註2, 國標測試, 客戶包裝確認, 東莞業務備註, 驗貨報告圖片
                FROM 訂單控制表 WHERE 訂單流水號 LIKE N'" & TextBox12.Text & "' ORDER BY GOODBOX, APMA確認, TVW"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds3) : DataGridView3.DataSource = ds3.Tables(0) : conn.Close()

        DataGridView3.Columns(0).FillWeight = 85 : DataGridView3.Columns(1).FillWeight = 70 : DataGridView3.Columns(2).FillWeight = 130 : DataGridView3.Columns(3).FillWeight = 120
        DataGridView3.Columns(4).FillWeight = 130 : DataGridView3.Columns(5).FillWeight = 80 : DataGridView3.Columns(6).FillWeight = 50 : DataGridView3.Columns(7).FillWeight = 80
        DataGridView3.Columns(8).FillWeight = 90 : DataGridView3.Columns(9).FillWeight = 90 : DataGridView3.Columns(10).FillWeight = 90
        DataGridView3.Columns(11).Visible = False : DataGridView3.Columns(12).Visible = False
        DataGridView3.Columns(13).FillWeight = 130 : DataGridView3.Columns(14).FillWeight = 80 : DataGridView3.Columns(15).FillWeight = 120 : DataGridView3.Columns(16).FillWeight = 130
        DataGridView3.Columns(17).Visible = False : DataGridView3.Columns(18).Visible = False : DataGridView3.Columns(19).Visible = False : DataGridView3.Columns(20).Visible = False
        DataGridView3.Columns(21).Visible = False : DataGridView3.Columns(22).Visible = False : DataGridView3.Columns(23).Visible = False : DataGridView3.Columns(24).Visible = False
        DataGridView3.Columns(25).Visible = False : DataGridView3.Columns(26).Visible = False : DataGridView3.Columns(27).Visible = False : DataGridView3.Columns(28).Visible = False
        DataGridView3.Columns(29).Visible = False : DataGridView3.Columns(30).Visible = False : DataGridView3.Columns(31).Visible = False : DataGridView3.Columns(32).Visible = False
        DataGridView3.Columns(33).Visible = False : DataGridView3.Columns(34).Visible = False : DataGridView3.Columns(35).Visible = False : DataGridView3.Columns(36).Visible = False
        DataGridView3.Columns(37).Visible = False : DataGridView3.Columns(38).Visible = False : DataGridView3.Columns(39).Visible = False : DataGridView3.Columns(40).Visible = False
        DataGridView3.Columns(41).Visible = False : DataGridView3.Columns(42).Visible = False : DataGridView3.Columns(43).Visible = False : DataGridView3.Columns(44).Visible = False
        DataGridView3.Columns(45).Visible = False : DataGridView3.Columns(46).Visible = False : DataGridView3.Columns(47).Visible = False : DataGridView3.Columns(48).Visible = False
        DataGridView3.Columns(49).Visible = False : DataGridView3.Columns(50).Visible = False : DataGridView3.Columns(51).Visible = False : DataGridView3.Columns(52).Visible = False
        DataGridView3.Columns(53).Visible = False : DataGridView3.Columns(54).Visible = False : DataGridView3.Columns(55).Visible = False : DataGridView3.Columns(56).Visible = False
        DataGridView3.Columns(57).Visible = False : DataGridView3.Columns(58).Visible = False : DataGridView3.Columns(59).Visible = False

        DataGridView3.Columns(7).DefaultCellStyle.Format = "#,##0"
        DataGridView3.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        DataGridView3.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        DataGridView3.EditMode = DataGridViewEditMode.EditOnEnter
    End Sub
    Private Sub Set_清單4()
        DataGridView5.DataSource = Nothing : ds4.Clear()
        DataGridView5.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView5.ColumnHeadersHeight = 25
        DataGridView5.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 資料流水號, 客戶訂單號, ItemNumber, ProductName, Color, DM, [4], [4.5], [5], [5.5], [6], [6.5], [7], [7.5], [8], [8.5], [9], [9.5], [10], [10.5], [11], [11.5], [12], [12.5], 
                       [13], [14], 訂單流水號
                FROM 訂單明細表 WHERE 訂單流水號 LIKE N'" & TextBox12.Text & "' ORDER BY ProductName, Color, DM"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds4) : DataGridView5.DataSource = ds4.Tables(0) : conn.Close()

        DataGridView5.Columns(0).FillWeight = 85 : DataGridView5.Columns(1).FillWeight = 150 : DataGridView5.Columns(2).FillWeight = 120 : DataGridView5.Columns(3).FillWeight = 150
        DataGridView5.Columns(4).FillWeight = 80 : DataGridView5.Columns(5).FillWeight = 50 : DataGridView5.Columns(6).FillWeight = 38 : DataGridView5.Columns(7).FillWeight = 37
        DataGridView5.Columns(8).FillWeight = 38 : DataGridView5.Columns(9).FillWeight = 37 : DataGridView5.Columns(10).FillWeight = 38 : DataGridView5.Columns(11).FillWeight = 37
        DataGridView5.Columns(12).FillWeight = 38 : DataGridView5.Columns(13).FillWeight = 37 : DataGridView5.Columns(14).FillWeight = 38 : DataGridView5.Columns(15).FillWeight = 37
        DataGridView5.Columns(16).FillWeight = 38 : DataGridView5.Columns(17).FillWeight = 37 : DataGridView5.Columns(18).FillWeight = 38 : DataGridView5.Columns(19).FillWeight = 37
        DataGridView5.Columns(20).FillWeight = 38 : DataGridView5.Columns(21).FillWeight = 37 : DataGridView5.Columns(22).FillWeight = 38 : DataGridView5.Columns(23).FillWeight = 37
        DataGridView5.Columns(24).FillWeight = 38 : DataGridView5.Columns(25).FillWeight = 37 : DataGridView5.Columns(26).Visible = False
        DataGridView5.EditMode = DataGridViewEditMode.EditOnEnter
    End Sub
    Private Sub ComboBox1下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 楦型 FROM 訂單控制表楦型清單 ORDER BY 楦型"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox1.Items.Clear()
        While (dr.Read()) : ComboBox1.Items.Add(dr("楦型")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox2下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 客戶簡稱 FROM 客戶控制表 ORDER BY 客戶簡稱"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox2.Items.Clear() : While (dr.Read()) : ComboBox2.Items.Add(dr("客戶簡稱")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox3下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT SEASON FROM 季節清單 ORDER BY SEASON"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox3.Items.Clear() : While (dr.Read()) : ComboBox3.Items.Add(dr("SEASON")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox4下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT MODEOFDELIVERY FROM MODEOFDELIVERY"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox4.Items.Clear()
        While (dr.Read()) : ComboBox4.Items.Add(dr("MODEOFDELIVERY")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox5下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT DELIVERYTERMS FROM DELIVERYTERMS"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox5.Items.Clear()
        While (dr.Read()) : ComboBox5.Items.Add(dr("DELIVERYTERMS")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox6下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT FOB FROM 港口清單"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox6.Items.Clear()
        While (dr.Read()) : ComboBox6.Items.Add(dr("FOB")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox7下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT TOPORT FROM TOPORT ORDER BY TOPORT"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox7.Items.Clear()
        While (dr.Read()) : ComboBox7.Items.Add(dr("TOPORT")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox8下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT REMARK FROM DELIVERYADDRESS  ORDER BY REMARK"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox8.Items.Clear()
        While (dr.Read()) : ComboBox8.Items.Add(dr("REMARK")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox9下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 工廠 FROM 工廠控制表 GROUP BY 工廠 ORDER BY 工廠"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox9.Items.Clear()
        While (dr.Read()) : ComboBox9.Items.Add(dr("工廠")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox11下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 型體號碼 FROM 型體控制表 WHERE 客戶簡稱 LIKE N'" & ComboBox2.Text & "' GROUP BY 型體號碼 ORDER BY 型體號碼"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox11.Items.Clear() : While (dr.Read()) : ComboBox11.Items.Add(dr("型體號碼")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox12下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 型體名稱 FROM 型體控制表 WHERE 型體號碼 LIKE N'" & ComboBox11.Text & "' GROUP BY 型體名稱 ORDER BY 型體名稱"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox12.Items.Clear() : While (dr.Read()) : ComboBox12.Items.Add(dr("型體名稱")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox13下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT CN FROM 模具開發控制表 WHERE (CN NOT LIKE '') GROUP BY CN ORDER BY   CN"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox13.Items.Clear() : While (dr.Read()) : ComboBox13.Items.Add(dr("CN")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox14下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT  CUST FROM MTTOOCUST清單 ORDER BY CUST"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox14.Items.Clear() : While (dr.Read()) : ComboBox14.Items.Add(dr("CUST")) : End While : conn.Close()
    End Sub
    Private Sub 量產訂單輸入_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        TextBox12.Enabled = False : TextBox14.Enabled = False : TextBox15.Enabled = False
        Button4.Enabled = False : Button3.Enabled = False : Button17.Enabled = False : Button12.Enabled = False : DateTimePicker1.Visible = False
        ComboBox4下拉表單資料載入() : ComboBox5下拉表單資料載入() : ComboBox6下拉表單資料載入() : ComboBox7下拉表單資料載入() : ComboBox8下拉表單資料載入() : ComboBox9下拉表單資料載入()
        ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : ComboBox3下拉表單資料載入() : ComboBox13下拉表單資料載入() : ComboBox14下拉表單資料載入()
        Set_清單2() : Set_清單1()
    End Sub
    Private Sub DataGridView4_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView4.CellClick
        If e.RowIndex = -1 Then : Else
            ComboBox4下拉表單資料載入() : ComboBox5下拉表單資料載入() : ComboBox6下拉表單資料載入() : ComboBox7下拉表單資料載入() : ComboBox8下拉表單資料載入() : ComboBox9下拉表單資料載入()
            ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : ComboBox3下拉表單資料載入() : ComboBox13下拉表單資料載入() : ComboBox14下拉表單資料載入()

            ComboBox7.Text = DataGridView4.Rows(e.RowIndex).Cells("ToPort").Value : ComboBox4.Text = DataGridView4.Rows(e.RowIndex).Cells("ModeOfDelivery").Value
            ComboBox5.Text = DataGridView4.Rows(e.RowIndex).Cells("DeliveryTerms").Value : ComboBox6.Text = DataGridView4.Rows(e.RowIndex).Cells("FromPort").Value
            TextBox13.Text = DataGridView4.Rows(e.RowIndex).Cells("客戶訂單號").Value : TextBox16.Text = DataGridView4.Rows(e.RowIndex).Cells("DeliveryAddress").Value
            ComboBox9.Text = DataGridView4.Rows(e.RowIndex).Cells("工廠").Value : ComboBox6.Text = DataGridView4.Rows(e.RowIndex).Cells("FromPort").Value
            ComboBox13.Text = DataGridView4.Rows(e.RowIndex).Cells("ConstructionName").Value : TextBox12.Text = DataGridView4.Rows(e.RowIndex).Cells("訂單流水號").Value
            ComboBox2.Text = DataGridView4.Rows(e.RowIndex).Cells("Brand").Value
            ComboBox14.Text = DataGridView4.Rows(e.RowIndex).Cells("CustomerName").Value.ToString()

            If DataGridView4.Rows(e.RowIndex).Cells("交期").Value.ToString = "" Then : Else : DateTimePicker5.Value = DataGridView4.Rows(e.RowIndex).Cells("交期").Value : End If
            If DataGridView4.Rows(e.RowIndex).Cells("下單日").Value.ToString = "" Then : Else : DateTimePicker6.Value = DataGridView4.Rows(e.RowIndex).Cells("下單日").Value : End If

            conn.Close()
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "SELECT REMARK FROM DELIVERYADDRESS WHERE DELIVERYADDRESS LIKE '" & TextBox16.Text & "'"
            cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
            If dr.Read() Then : ComboBox8.Text = dr("REMARK").ToString : End If : conn.Close()

            Set_清單3() : Set_清單4()
            TextBox14.Text = "0.00"
            For i As Integer = 0 To DataGridView5.Rows.Count - 1
                DataGridView3.Rows(i).Cells("訂單數量").Value = DataGridView5.Rows(i).Cells("4").Value + DataGridView5.Rows(i).Cells("4.5").Value + DataGridView5.Rows(i).Cells("5").Value +
                DataGridView5.Rows(i).Cells("5.5").Value + DataGridView5.Rows(i).Cells("6").Value + DataGridView5.Rows(i).Cells("6.5").Value + DataGridView5.Rows(i).Cells("7").Value +
                DataGridView5.Rows(i).Cells("7.5").Value + DataGridView5.Rows(i).Cells("8").Value + DataGridView5.Rows(i).Cells("8.5").Value + DataGridView5.Rows(i).Cells("9").Value +
                DataGridView5.Rows(i).Cells("9.5").Value + DataGridView5.Rows(i).Cells("10").Value + DataGridView5.Rows(i).Cells("10.5").Value + DataGridView5.Rows(i).Cells("11").Value +
                DataGridView5.Rows(i).Cells("11.5").Value + DataGridView5.Rows(i).Cells("12").Value + DataGridView5.Rows(i).Cells("12.5").Value + DataGridView5.Rows(i).Cells("13").Value +
                DataGridView5.Rows(i).Cells("14").Value
            Next i
            For i As Integer = 0 To DataGridView3.Rows.Count - 1
                TextBox14.Text = Val(TextBox14.Text) + DataGridView3.Rows(i).Cells("訂單數量").Value
            Next i
            TextBox14.Text = Format(Val(TextBox14.Text), "#,##0.00")

            ComboBox3.Text = DataGridView3.Rows(0).Cells("年份季度").Value : ComboBox10.Text = DataGridView3.Rows(0).Cells("訂單屬性").Value
        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
            TextBox15.Text = DataGridView3.Rows(e.RowIndex).Cells("資料流水號").Value : ComboBox10.Text = DataGridView3.Rows(e.RowIndex).Cells("訂單屬性").Value
            ComboBox11.Text = DataGridView3.Rows(e.RowIndex).Cells("型體號碼").Value : ComboBox12.Text = DataGridView3.Rows(e.RowIndex).Cells("型體名稱").Value
            ComboBox1.Text = DataGridView3.Rows(e.RowIndex).Cells("楦型").Value
        End If
    End Sub
    Private Sub DataGridView5_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView5.CellClick
        If e.RowIndex = -1 Then : Else
            TextBox15.Text = DataGridView5.Rows(e.RowIndex).Cells("資料流水號").Value : ComboBox11.Text = DataGridView5.Rows(e.RowIndex).Cells("ItemNumber").Value
            ComboBox12.Text = DataGridView5.Rows(e.RowIndex).Cells("ProductName").Value : ComboBox1.Text = DataGridView5.Rows(e.RowIndex).Cells("DM").Value
        End If
    End Sub
    Private Sub DataGridView3_CellEndEdit(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView3.CellEndEdit
        Dim EU(2) As String
        EU(0) = DataGridView3("交期開始", e.RowIndex).Value.ToString
        If EU(0) = "" Then
        Else
            DateTimePicker1.Text = EU(0)
            DataGridView3.Rows(e.RowIndex).Cells("交期開始").Value = Format(DateTimePicker1.Value, "yyyy/MM/dd")
        End If
        EU(1) = DataGridView3("交期結束", e.RowIndex).Value.ToString
        If EU(1) = "" Then
        Else
            DateTimePicker1.Text = EU(1)
            DataGridView3.Rows(e.RowIndex).Cells("交期結束").Value = Format(DateTimePicker1.Value, "yyyy/MM/dd")
        End If
        EU(2) = DataGridView3("工廠交期", e.RowIndex).Value.ToString
        If EU(2) = "" Then
        Else
            DateTimePicker1.Text = EU(2)
            DataGridView3.Rows(e.RowIndex).Cells("工廠交期").Value = Format(DateTimePicker1.Value, "yyyy/MM/dd")
        End If
    End Sub
    Private Sub DataGridView5_CellContentClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView5.CellEndEdit
        TextBox14.Text = "0"
        For i As Integer = 0 To DataGridView5.Rows.Count - 1
            DataGridView3.Rows(i).Cells("訂單數量").Value = DataGridView5.Rows(i).Cells("4").Value + DataGridView5.Rows(i).Cells("4.5").Value + DataGridView5.Rows(i).Cells("5").Value +
                DataGridView5.Rows(i).Cells("5.5").Value + DataGridView5.Rows(i).Cells("6").Value + DataGridView5.Rows(i).Cells("6.5").Value + DataGridView5.Rows(i).Cells("7").Value +
                DataGridView5.Rows(i).Cells("7.5").Value + DataGridView5.Rows(i).Cells("8").Value + DataGridView5.Rows(i).Cells("8.5").Value + DataGridView5.Rows(i).Cells("9").Value +
                DataGridView5.Rows(i).Cells("9.5").Value + DataGridView5.Rows(i).Cells("10").Value + DataGridView5.Rows(i).Cells("10.5").Value + DataGridView5.Rows(i).Cells("11").Value +
                DataGridView5.Rows(i).Cells("11.5").Value + DataGridView5.Rows(i).Cells("12").Value + DataGridView5.Rows(i).Cells("12.5").Value + DataGridView5.Rows(i).Cells("13").Value +
                DataGridView5.Rows(i).Cells("14").Value
        Next i
        For i As Integer = 0 To DataGridView3.Rows.Count - 1
            TextBox14.Text = Val(TextBox14.Text) + DataGridView3.Rows(i).Cells("訂單數量").Value
        Next i
        TextBox14.Text = Format(Val(TextBox14.Text), "#,##0")
    End Sub
    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.TextChanged
        ComboBox11下拉表單資料載入()
    End Sub
    Private Sub ComboBox11_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox11.TextChanged
        ComboBox12下拉表單資料載入()
    End Sub
    Private Sub ComboBox8_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox8.TextChanged
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT DELIVERYADDRESS FROM DELIVERYADDRESS WHERE REMARK LIKE '" & ComboBox8.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
        If dr.Read() Then : TextBox16.Text = dr("DELIVERYADDRESS").ToString : End If : conn.Close()
    End Sub
    Private Sub ComboBox9_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox9.TextChanged
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 工廠, 供應商資料, 供應商地址 FROM 工廠控制表 WHERE 工廠 LIKE '" & ComboBox9.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
        If dr.Read() Then : TextBox18.Text = dr("供應商資料").ToString : TextBox17.Text = dr("供應商地址").ToString : End If : conn.Close()
    End Sub
    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        Set_清單1()
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        PA = InputBox("請輸入要查詢的關鍵字") : Set_清單2() : PA = ""
    End Sub
    Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
        FACTORY_資料管理.ShowDialog() :: ComboBox9下拉表單資料載入()
    End Sub
    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        DELIVERY_ADDRESS__資料管理.ShowDialog() : ComboBox8下拉表單資料載入()
    End Sub
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        清單修改.Close() : 交貨條件修改 = True : 清單修改.ShowDialog() : ComboBox5下拉表單資料載入() : 交貨條件修改 = False
    End Sub
    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        清單修改.Close() : 港口清單修改 = True : 清單修改.ShowDialog() : ComboBox6下拉表單資料載入() : 港口清單修改 = False
    End Sub
    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        清單修改.Close() : 到港清單修改 = True : 清單修改.ShowDialog() : ComboBox7下拉表單資料載入() : 到港清單修改 = False
    End Sub
    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        清單修改.Close() : 交貨管道修改 = True : 清單修改.ShowDialog() : ComboBox4下拉表單資料載入() : 交貨管道修改 = False
    End Sub
    Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
        For i As Integer = 0 To DataGridView2.Rows.Count - 1
            DataGridView2.Rows(i).Cells("選擇").Value = False
        Next i
    End Sub
    Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
        For i As Integer = 0 To DataGridView2.Rows.Count - 1
            DataGridView2.Rows(i).Cells("選擇").Value = True
        Next i
    End Sub
    Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
        If TextBox15.Text = "" Then
            MsgBox("未選擇需要刪除的資料")
        Else
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "DELETE FROM 訂單控制表 WHERE (資料流水號 LIKE N'" & TextBox15.Text & "')"
            cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "DELETE FROM 訂單明細表 WHERE (資料流水號 LIKE N'" & TextBox15.Text & "')"
            cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
            Set_清單3() : Set_清單4()
        End If
    End Sub
    Private Sub Set_日期格式轉換()
        DTP = Format(Today(), "yyyy/MM/dd") : DTP1 = Format(Today(), "yyyyMMdd")
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim aa1 As MsgBoxResult
        aa1 = MsgBox("確定要生成--新的--量產訂單號碼?", MsgBoxStyle.OkCancel)
        If aa1 = MsgBoxResult.Ok Then
            Button1.Enabled = False : Button11.Enabled = False : Button4.Enabled = True : Button3.Enabled = False : Button17.Enabled = False
            Dim NUM0 As Integer
            Set_日期格式轉換()
            For i As Integer = 1 To 999
                NUM0 = 0 + i
                If NUM0 < 10 Then : TextBox12.Text = "WP-" & DTP1 & "-00" & NUM0
                ElseIf NUM0 > 9 And NUM0 < 100 Then : TextBox12.Text = "WP-" & DTP1 & "-0" & NUM0
                ElseIf NUM0 > 99 Then : TextBox12.Text = "WP-" & DTP1 & "-" & NUM0
                End If
                conn.Close()
                If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                SQL1 = "SELECT TOP (1)  訂單流水號 FROM 訂單控制表 WHERE ( 訂單流水號 LIKE '" & TextBox12.Text & "')"
                cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
                If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
            Next
        End If
    End Sub
    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        If TextBox12.Text = "" Then
            MsgBox("請先選擇量產訂單號")
        Else
            Button1.Enabled = False : Button11.Enabled = False : Button12.Enabled = True : Button3.Enabled = True : Button17.Enabled = True
        End If
    End Sub
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If ComboBox2.Text = "" Or TextBox13.Text = "" Or ComboBox4.Text = "" Or ComboBox5.Text = "" Or ComboBox6.Text = "" Or
            ComboBox7.Text = "" Or ComboBox8.Text = "" Or ComboBox9.Text = "" Or ComboBox14.Text = "" Or ComboBox3.Text = "" Then
            MsgBox("生成量產訂單抬頭之前，請注意紅色字體部分資料不可有誤。")
        Else
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "INSERT INTO 訂單明細表抬頭 (客戶訂單號, 訂單流水號, ConstructionName, ModeOfDelivery, DeliveryTerms, OrgShipDate, FromPort, ToPort, 
                            ShippingCarrier, VendorReference, ModifiedDate, CustomerName, ShipDate, SalesOrder, DeliveryAddress, 下單日, 
                            交期, ETADate, CreatedDate, Brand, CustomerRequisition, 工廠) 
                    VALUES (N'" & TextBox13.Text & "', N'" & TextBox12.Text & "', N'" & ComboBox13.Text & "', N'" & ComboBox4.Text & "', N'" & ComboBox5.Text &
                        "', N'" & Format(DateTimePicker5.Value, "yyyy/MM/dd") &
                        "', N'" & ComboBox6.Text & "', N'" & ComboBox7.Text & "', N'', N'', N'" & Format(DateTimePicker6.Value, "yyyy/MM/dd") & "', N'" & ComboBox14.Text &
                        "', N'" & Format(DateTimePicker5.Value, "yyyy/MM/dd") & "', N'', N'" & TextBox16.Text &
                        "', N'" & Format(DateTimePicker6.Value, "yyyy/MM/dd") & "', N'" & Format(DateTimePicker5.Value, "yyyy/MM/dd") & "', N'', N'" & Format(DateTimePicker6.Value, "yyyy/MM/dd") &
                        "', N'" & ComboBox2.Text & "', N'', N'" & ComboBox9.Text & "')"
            cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
            Button1.Enabled = False : Button11.Enabled = False : Button4.Enabled = False : Button12.Enabled = True
        End If
    End Sub
    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
        If ComboBox1.Text = "" Then
            MsgBox("沒有選擇楦型。")
        Else
            For i As Integer = 0 To DataGridView2.Rows.Count - 1
                資料數 = DataGridView2.Rows.Count : MyModule1.進度條()
                If DataGridView2.Rows(i).Cells("選擇").Value = True Then
                    If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                    SQL1 = "SELECT TOP (1) 資料流水號 FROM 訂單控制表 GROUP BY 資料流水號 ORDER BY 資料流水號 DESC"
                    cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
                    If dr.Read() Then : TextBox15.Text = dr("資料流水號").ToString : Else : TextBox15.Text = "PO00000000" : End If
                    conn.Close()
                    Dim NUM1 As Integer
                    NUM1 = Double.Parse(Strings.Right(TextBox15.Text, 8)) + 1
                    If NUM1 < 10 Then : TextBox15.Text = "PO" & "0000000" & NUM1
                    ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox15.Text = "PO" & "000000" & NUM1
                    ElseIf NUM1 > 99 And NUM1 < 1000 Then : TextBox15.Text = "PO" & "00000" & NUM1
                    ElseIf NUM1 > 999 And NUM1 < 10000 Then : TextBox15.Text = "PO" & "0000" & NUM1
                    ElseIf NUM1 > 9999 And NUM1 < 100000 Then : TextBox15.Text = "PO" & "000" & NUM1
                    ElseIf NUM1 > 99999 And NUM1 < 100000 Then : TextBox15.Text = "PO" & "00" & NUM1
                    ElseIf NUM1 > 999999 And NUM1 < 1000000 Then : TextBox15.Text = "PO" & "0" & NUM1
                    ElseIf NUM1 > 9999999 Then : TextBox15.Text = "PO" & NUM1 + 1
                    End If

                    If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                    SQL1 = "INSERT INTO 訂單控制表 (訂單流水號, 年份季度, 客戶訂單號, 型體號碼, GOODBOX, 訂單數量, 客戶交期, 客戶交期1, 單價, 總金額, 備註, 生產工廠, 訂單種類, BUYER, CFMSPEC, 
                                                    CFMSAMPLE, TRIAL1, TRIAL2, TRIAL3, TRIAL4, 包裝確認時間, 貼標時間, 裁斷時間, 針車時間, 成型時間, 驗貨時間, 實際離廠日, 資料流水號, 明細建檔, 
                                                    LEATHER, LEA_Note, CXL, CXLTime, 出貨數量, PO_S_Date, Requested_XF, Confirm_XF, Revised_XF, Special_Packaging, Remarks, 出貨地, TVW, 楦頭號, 
                                                    材質, 長期試穿, 面料, 副料, 中底, 鞋墊, 大底, 跟, 工廠進度表備註1, 七號模具, 工廠進度表備註2, 國標測試, 客戶包裝確認, 東莞業務備註, APMA確認, 
                                                    驗貨報告圖片, 工廠回復交期) 
                        VALUES (N'" & TextBox12.Text & "', N'" & ComboBox3.Text & "', N'" & TextBox13.Text & "', N'" & ComboBox11.Text & "', N'" & ComboBox12.Text &
                            "', N'0', N'" & Format(DateTimePicker3.Value, "yyyy/MM/dd") & "', N'" & Format(DateTimePicker4.Value, "yyyy/MM/dd") &
                            "', N'0', N'0', N'', N'" & ComboBox9.Text & "', N'', N'" & ComboBox2.Text & "', N'" & ComboBox10.Text &
                            "', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'" & TextBox15.Text & "', N'1', N'', N'', N'0', N'', N'0', N'', N'', N'', N'', N'', N'', N'" &
                            "', N'" & ComboBox1.Text & "', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'0', N'', N'', N'" & DataGridView2.Rows(i).Cells("顏色").Value &
                            "', N'', N'" & Format(DateTimePicker2.Value, "yyyy/MM/dd") & "')"
                    cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()

                    If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                    SQL1 = "INSERT INTO 訂單明細表 (訂單流水號, 客戶訂單號, ItemNumber, ProductName, Color, DM, [4], [4.5], [5], [5.5], [6], [6.5], [7], [7.5], [8], [8.5], [9], 
                            [9.5], [10], [10.5], [11], [11.5], [12], [12.5], [13], [14], 資料流水號)
                        VALUES (N'" & TextBox12.Text & "', N'" & TextBox13.Text & "', N'" & ComboBox11.Text & "', N'" & ComboBox12.Text & "', N'" & DataGridView2.Rows(i).Cells("顏色").Value &
                                "', N'" & ComboBox1.Text & "', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0', N'0" &
                                "', N'" & TextBox15.Text & "')"
                    cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
                End If
            Next i : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
            Set_清單3() : Set_清單4() : ComboBox1下拉表單資料載入()
            Button3.Enabled = True : Button17.Enabled = True
        End If
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "UPDATE 訂單明細表抬頭 SET ModeOfDelivery = N'" & ComboBox4.Text & "', DeliveryTerms = N'" & ComboBox5.Text & "', FromPort = N'" & ComboBox6.Text & "', 
                                          ToPort = N'" & ComboBox7.Text & "', 工廠 = N'" & ComboBox9.Text & "', DeliveryAddress = N'" & TextBox16.Text & "', 
                                          交期 = N'" & Format(DateTimePicker5.Value, "yyyy/MM/dd") & "', ShipDate =  N'" & Format(DateTimePicker5.Value, "yyyy/MM/dd") & "', 
                                          OrgShipDate =  N'" & Format(DateTimePicker5.Value, "yyyy/MM/dd") & "', Brand = N'" & ComboBox2.Text & "'
                WHERE (訂單流水號 LIKE N'" & TextBox12.Text & "')"
        cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()

        For i As Integer = 0 To DataGridView3.Rows.Count - 1
            資料數 = DataGridView3.Rows.Count : MyModule1.進度條()
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "UPDATE 訂單控制表 SET 訂單數量 = N'" & DataGridView3.Rows(i).Cells("訂單數量").Value & "', 客戶交期 = N'" & DataGridView3.Rows(i).Cells("交期開始").Value &
                                     "', 客戶交期1 = N'" & DataGridView3.Rows(i).Cells("交期結束").Value & "', 備註 = N'" & DataGridView3.Rows(i).Cells("備註").Value &
                                     "', 工廠回復交期 = N'" & DataGridView3.Rows(i).Cells("工廠交期").Value & "', BUYER = N'" & DataGridView3.Rows(i).Cells("BUYER").Value &
                                     "', CFMSPEC = N'" & ComboBox10.Text & "', APMA確認 = N'" & DataGridView3.Rows(i).Cells("顏色").Value & "' 
                    WHERE (資料流水號 LIKE N'" & DataGridView3.Rows(i).Cells("資料流水號").Value & "')"
            cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
        Next i : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
        For i As Integer = 0 To DataGridView5.Rows.Count - 1
            資料數 = DataGridView5.Rows.Count : MyModule1.進度條()
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "UPDATE 訂單明細表 SET [4] = N'" & DataGridView5.Rows(i).Cells("4").Value & "', [4.5] = N'" & DataGridView5.Rows(i).Cells("4.5").Value &
                                      "', [5] = N'" & DataGridView5.Rows(i).Cells("5").Value & "', [5.5] = N'" & DataGridView5.Rows(i).Cells("5.5").Value &
                                      "', [6] = N'" & DataGridView5.Rows(i).Cells("6").Value & "', [6.5] = N'" & DataGridView5.Rows(i).Cells("6.5").Value &
                                      "', [7] = N'" & DataGridView5.Rows(i).Cells("7").Value & "', [7.5] = N'" & DataGridView5.Rows(i).Cells("7.5").Value &
                                      "', [8] = N'" & DataGridView5.Rows(i).Cells("8").Value & "', [8.5] = N'" & DataGridView5.Rows(i).Cells("8.5").Value &
                                      "', [9] = N'" & DataGridView5.Rows(i).Cells("9").Value & "', [9.5] = N'" & DataGridView5.Rows(i).Cells("9.5").Value &
                                      "', [10] = N'" & DataGridView5.Rows(i).Cells("10").Value & "', [10.5] = N'" & DataGridView5.Rows(i).Cells("10.5").Value &
                                      "', [11] = N'" & DataGridView5.Rows(i).Cells("11").Value & "', [11.5] = N'" & DataGridView5.Rows(i).Cells("11.5").Value &
                                      "', [12] = N'" & DataGridView5.Rows(i).Cells("12").Value & "', [12.5] = N'" & DataGridView5.Rows(i).Cells("12.5").Value &
                                      "', [13] = N'" & DataGridView5.Rows(i).Cells("13").Value & "', [14] = N'" & DataGridView5.Rows(i).Cells("14").Value &
                                      "', Color = N'" & DataGridView5.Rows(i).Cells("Color").Value & "'
                    WHERE (資料流水號 LIKE N'" & DataGridView5.Rows(i).Cells("資料流水號").Value & "')"
            cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
        Next i : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
        MsgBox("存檔完成。") : Set_清單2() : Set_清單2()
        Button1.Enabled = True : Button11.Enabled = True : Button4.Enabled = False : Button12.Enabled = False : Button3.Enabled = False : Button17.Enabled = False
    End Sub
    Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
        For i As Integer = 0 To DataGridView3.Rows.Count - 1
            DataGridView3.Rows(i).Cells("BUYER").Value = ComboBox2.Text
        Next
        MsgBox("注意還未存檔喔")
    End Sub
    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        清單修改.Close() : 訂單顏色修改 = True : 清單修改.ShowDialog() : Set_清單1() : 訂單顏色修改 = False
    End Sub
    Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "UPDATE 訂單控制表 SET 型體號碼 = N'" & ComboBox11.Text & "', GOODBOX = N'" & ComboBox12.Text & "' WHERE 資料流水號 LIKE '" & TextBox15.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "UPDATE 訂單明細表 SET ItemNumber = N'" & ComboBox11.Text & "', ProductName = N'" & ComboBox12.Text & "' WHERE 資料流水號 LIKE '" & TextBox15.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
        Set_清單3() : Set_清單4()
    End Sub
    Private Sub ComboBox2_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
        For i As Integer = 0 To DataGridView3.Rows.Count - 1
            DataGridView3.Rows(i).Cells("BUYER").Value = ComboBox2.Text
        Next
    End Sub
End Class