Option Strict Off
Imports System.Data.SqlClient
Imports System.IO
Public Class 量產出貨明細表
    Dim conn As New SqlConnection : Dim conn1 As New SqlConnection
    Dim da As New SqlDataAdapter
    Dim cmd As New SqlCommand : Dim cmd1 As New SqlCommand
    Dim ds As New DataSet
    Dim dr As SqlDataReader : Dim dr1 As SqlDataReader
    Dim kkk1 As String : Dim kkk2 As String : Dim kkk3 As String : Dim kkk4 As String : Dim kkk5 As String : Dim kkk6 As String
    Private Sub Set_DGV1載入前設定()
        DataGridView1.DataSource = Nothing : ds.Clear()
        DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView1.ColumnHeadersHeight = 25
        DataGridView1.AllowUserToAddRows = False
        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_grid()
    End Sub
    Private Sub Set_訂單清單()
        Set_DGV1載入前設定()
        If PA = "" Then
            SQL1 = "SELECT  貨款匯入出款明細表.貨款流水號, 貨款匯入出款明細表.訂單流水號, 貨款匯入出款明細表.年份季度, 
                            貨款匯入出款明細表.客戶訂單號, 貨款匯入出款明細表.形體號, 貨款匯入出款明細表.顏色, 
                            貨款匯入出款明細表.楦型, 貨款匯入出款明細表.訂單數量, 貨款匯入出款明細表.出貨數量, 訂單控制表.備註, 
                            訂單控制表.生產工廠, 訂單控制表.訂單種類, 訂單控制表.工廠回復交期, 訂單控制表.客戶交期 AS 交期開始, 
                            訂單控制表.客戶交期1 AS 交期結束, 貨款匯入出款明細表.實際離廠日, 訂單控制表.明細建檔, 
                            訂單控制表.驗貨報告圖片, 貨款匯入出款明細表.資料流水號 
                    FROM    貨款匯入出款明細表 LEFT OUTER JOIN 訂單控制表 ON 貨款匯入出款明細表.資料流水號 = 訂單控制表.資料流水號 
                   " & kkk1 & kkk2 & kkk3 & kkk4 & kkk5 & kkk6 & "  " &
                   "ORDER BY 貨款匯入出款明細表.訂單流水號 DESC, 貨款匯入出款明細表.形體號, 貨款匯入出款明細表.顏色, 貨款匯入出款明細表.楦型"
        Else
            SQL1 = "SELECT  貨款匯入出款明細表.貨款流水號, 貨款匯入出款明細表.訂單流水號, 貨款匯入出款明細表.年份季度, 
                            貨款匯入出款明細表.客戶訂單號, 貨款匯入出款明細表.形體號, 貨款匯入出款明細表.顏色, 
                            貨款匯入出款明細表.楦型, 貨款匯入出款明細表.訂單數量, 貨款匯入出款明細表.出貨數量, 訂單控制表.備註, 
                            訂單控制表.生產工廠, 訂單控制表.訂單種類, 訂單控制表.工廠回復交期, 訂單控制表.客戶交期 AS 交期開始, 
                            訂單控制表.客戶交期1 AS 交期結束, 貨款匯入出款明細表.實際離廠日, 訂單控制表.明細建檔, 
                            訂單控制表.驗貨報告圖片, 貨款匯入出款明細表.資料流水號 
                    FROM    貨款匯入出款明細表 LEFT OUTER JOIN 訂單控制表 ON 貨款匯入出款明細表.資料流水號 = 訂單控制表.資料流水號
                   " & kkk1 & kkk2 & kkk3 & kkk4 & kkk5 & kkk6 & "
                     AND (貨款匯入出款明細表.訂單流水號 LIKE '%" & PA & "%' OR 貨款匯入出款明細表.客戶訂單號 LIKE '%" & PA & "%' OR 貨款匯入出款明細表.形體號 LIKE '%" & PA & "%' 
                          OR 貨款匯入出款明細表.顏色 LIKE '%" & PA & "%' OR 貨款匯入出款明細表.楦型 LIKE '%" & PA & "%' OR 訂單控制表.備註 LIKE '%" & PA & "%') " &
                   "ORDER BY 貨款匯入出款明細表.訂單流水號 DESC, 貨款匯入出款明細表.形體號, 貨款匯入出款明細表.顏色, 貨款匯入出款明細表.楦型"
        End If
        列印用SQL = SQL1
        Set_DGV1載入後設定()
    End Sub
    Private Sub Set_grid()
        DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).FillWeight = 155 : DataGridView1.Columns(2).FillWeight = 60 : DataGridView1.Columns(3).FillWeight = 120
        DataGridView1.Columns(4).FillWeight = 200 : DataGridView1.Columns(5).FillWeight = 130 : DataGridView1.Columns(6).FillWeight = 60 : DataGridView1.Columns(7).FillWeight = 80
        DataGridView1.Columns(8).FillWeight = 80 : DataGridView1.Columns(9).FillWeight = 235 : DataGridView1.Columns(10).Visible = False : DataGridView1.Columns(11).FillWeight = 80
        DataGridView1.Columns(12).FillWeight = 80 : DataGridView1.Columns(13).FillWeight = 80 : DataGridView1.Columns(14).FillWeight = 80 : DataGridView1.Columns(15).FillWeight = 90
        DataGridView1.Columns(16).FillWeight = 90 : DataGridView1.Columns(17).Visible = False : DataGridView1.Columns(18).Visible = False

        DataGridView1.Columns(7).DefaultCellStyle.Format = "#,##0"
        DataGridView1.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        DataGridView1.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        DataGridView1.Columns(8).DefaultCellStyle.Format = "#,##0"
        DataGridView1.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        DataGridView1.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
    End Sub
    Private Sub ComboBox1下拉表單資料載入()
        conn1.Close()
        If conn1.State = ConnectionState.Closed Then : conn1.ConnectionString = ConString : conn1.Open() : End If
        SQL1 = "SELECT SEASON FROM 季節清單 ORDER BY SEASON DESC"
        cmd1.CommandText = SQL1 : cmd1.Connection = conn1 : dr1 = cmd1.ExecuteReader
        ComboBox1.Items.Clear()
        While (dr1.Read())
            ComboBox1.Items.Add(dr1("SEASON"))
        End While
        conn1.Close()
    End Sub
    Private Sub ComboBox5下拉表單資料載入()
        conn1.Close()
        If conn1.State = ConnectionState.Closed Then : conn1.ConnectionString = ConString : conn1.Open() : End If
        SQL1 = "SELECT 工廠 FROM 工廠控制表 GROUP BY 工廠 ORDER BY 工廠"
        cmd1.CommandText = SQL1 : cmd1.Connection = conn1 : dr1 = cmd1.ExecuteReader
        ComboBox5.Items.Clear()
        While (dr1.Read())
            ComboBox5.Items.Add(dr1("工廠"))
        End While
        conn1.Close()
    End Sub
    Private Sub ComboBox6下拉表單資料載入()
        'conn1.Close()
        'If conn1.State = ConnectionState.Closed Then : conn1.ConnectionString = ConString : conn1.Open() : End If
        'SQL1 = "SELECT 訂單種類 FROM  訂單控制表訂單種類清單 GROUP BY 訂單種類 ORDER BY 訂單種類"
        'cmd1.CommandText = SQL1 : cmd1.Connection = conn1 : dr1 = cmd1.ExecuteReader
        'ComboBox6.Items.Clear()
        'While (dr1.Read())
        '    ComboBox6.Items.Add(dr1("訂單種類"))
        'End While
        'conn1.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
        TextBox1.Enabled = False : CheckBox1.Enabled = False : Button30.Enabled = False
        ComboBox1下拉表單資料載入() : ComboBox5下拉表單資料載入() : ComboBox6下拉表單資料載入()
        kkk1 = "WHERE (訂單控制表.CXL IS NULL or 訂單控制表.CXL = 0)"
        Set_訂單清單()
    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        If e.RowIndex = -1 Then : Else
            TextBox1.Text = DataGridView1(1, e.RowIndex).Value.ToString : 資料流水號_tb.Text = DataGridView1("資料流水號", e.RowIndex).Value.ToString
            CheckBox1.Checked = DataGridView1(16, e.RowIndex).Value.ToString : 實際離場_dtp.Value = DataGridView1("實際離廠日", e.RowIndex).Value
            If CheckBox1.Checked = False Then : Button30.Enabled = False : Else : Button30.Enabled = True : End If

            PictureBox1.Image = Nothing : 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(e.RowIndex).Cells("形體號").Value & "'  AND 類別 LIKE N'設計圖'"
            cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
            If dr.Read() Then
                PictureBox1.Image = Nothing : 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(e.RowIndex).Cells("形體號").Value & "'  AND 類別 LIKE N'設計圖'"
                cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
                While dr.Read() = True
                    Dim bytes As Byte() = New Byte(-1) {} : bytes = DirectCast(dr.Item("圖片"), Byte()) : Dim oStream As New MemoryStream(bytes) : PictureBox1.Image = Bitmap.FromStream(oStream)
                End While
                conn.Close()
            Else
                PictureBox1.Image = Nothing : 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(e.RowIndex).Cells("形體號").Value & "'"
                cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
                If dr.Read() Then
                    PictureBox1.Image = Nothing : 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(e.RowIndex).Cells("形體號").Value & "'"
                    cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
                    While dr.Read() = True
                        Dim bytes As Byte() = New Byte(-1) {} : bytes = DirectCast(dr.Item("圖片"), Byte()) : Dim oStream As New MemoryStream(bytes) : PictureBox1.Image = Bitmap.FromStream(oStream)
                    End While
                    conn.Close()
                Else
                    PictureBox1.Image = Nothing : conn.Close()
                    If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                    SQL1 = "SELECT 圖片 FROM 鞋樣素描圖控制表 WHERE 型體編號 LIKE N'" & DataGridView1.Rows(e.RowIndex).Cells("形體號").Value & "'"
                    cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
                    If dr.Read() Then
                        PictureBox1.Image = Nothing : conn.Close()
                        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                        SQL1 = "SELECT 圖片 FROM 鞋樣素描圖控制表 WHERE 型體編號 LIKE N'" & DataGridView1.Rows(e.RowIndex).Cells("形體號").Value & "'"
                        cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
                        While dr.Read() = True
                            Dim bytes As Byte() = New Byte(-1) {} : bytes = DirectCast(dr.Item("圖片"), Byte()) : Dim oStream As New MemoryStream(bytes) : PictureBox1.Image = Bitmap.FromStream(oStream)
                        End While
                        conn.Close()
                    Else
                        conn.Close()
                    End If
                End If
            End If : PictureBox1.SizeMode = 4

            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "SELECT TOP(1) 驗貨報告 FROM 驗貨報告圖庫 WHERE 驗貨報告編號 LIKE '" & DataGridView1.Rows(e.RowIndex).Cells("驗貨報告圖片").Value & "'"
            cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
            PictureBox2.Image = Nothing
            While dr.Read() = True
                Dim bytes As Byte() = New Byte(-1) {} : bytes = DirectCast(dr.Item("驗貨報告"), Byte()) : Dim oStream As New MemoryStream(bytes) : PictureBox2.Image = Bitmap.FromStream(oStream)
            End While
            conn.Close() : PictureBox2.SizeMode = 4
            驗貨報告 = DataGridView1.Rows(e.RowIndex).Cells("驗貨報告圖片").Value
        End If
    End Sub
    Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = DataGridView1.Rows.Count - 1 Then
            Exit Sub
        Else
            If DataGridView1(1, e.RowIndex).Value.ToString <> DataGridView1(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
                Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
                Exit Sub
            End If
        End If
    End Sub
    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        PA = InputBox("請輸入要查詢的資料") : Set_訂單清單() : PA = ""
    End Sub
    Private Sub Button30_Click(sender As Object, e As EventArgs) Handles Button30.Click
        If TextBox1.Text = "" Then
            MsgBox("請先選擇訂單資料")
        Else
            PA = TextBox1.Text
            量產訂單明細表.Show() : 量產訂單明細表.WindowState = 2
        End If
    End Sub
    Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click
        驗貨報告大圖.ShowDialog()
    End Sub
    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        PictureBox2.Image.RotateFlip(RotateFlipType.Rotate90FlipNone) : PictureBox2.Refresh() : PictureBox2.SizeMode = 4
    End Sub
    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        PictureBox2.Image.RotateFlip(RotateFlipType.Rotate270FlipNone) : PictureBox2.Refresh() : PictureBox2.SizeMode = 4
    End Sub
    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        PictureBox2.Image.RotateFlip(RotateFlipType.Rotate180FlipY) : PictureBox2.Refresh() : PictureBox2.SizeMode = 4
    End Sub
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        PictureBox2.Image.RotateFlip(RotateFlipType.Rotate180FlipX) : PictureBox2.Refresh() : PictureBox2.SizeMode = 4
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If CheckBox2.Checked = True Then
            kkk1 = "WHERE (訂單控制表.CXL IS NULL or 訂單控制表.CXL = 0) AND 貨款匯入出款明細表.年份季度 LIKE '" & ComboBox1.Text & "' "
        Else : kkk1 = "WHERE ((訂單控制表.CXL IS NULL or 訂單控制表.CXL = 0)) " : End If
    End Sub
    Private Sub ComboBox6_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox6.SelectedIndexChanged
        If CheckBox8.Checked = True Then
            kkk2 = "AND 訂單控制表.訂單種類 LIKE '" & ComboBox6.Text & "' "
        Else : kkk2 = "" : End If
    End Sub
    Private Sub ComboBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox5.SelectedIndexChanged
        If CheckBox7.Checked = True Then
            kkk3 = " AND 訂單控制表.生產工廠 LIKE '" & ComboBox5.Text & "' "
        Else : kkk3 = "" : End If
    End Sub
    Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.Click
        If CheckBox2.Checked = True Then
            kkk1 = "WHERE (訂單控制表.CXL IS NULL or 訂單控制表.CXL = 0) AND 貨款匯入出款明細表.年份季度 LIKE '" & ComboBox1.Text & "' "
        Else : kkk1 = "WHERE ((訂單控制表.CXL IS NULL or 訂單控制表.CXL = 0)) " : End If
    End Sub
    Private Sub CheckBox8_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox8.Click
        If CheckBox8.Checked = True Then
            kkk2 = "AND 訂單控制表.訂單種類 LIKE '" & ComboBox6.Text & "' "
        Else : kkk2 = "" : End If
    End Sub
    Private Sub CheckBox7_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox7.Click
        If CheckBox7.Checked = True Then
            kkk3 = " AND 訂單控制表.生產工廠 LIKE '" & ComboBox5.Text & "' "
        Else : kkk3 = "" : End If
    End Sub
    Private Sub CheckBox6_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox6.Click
        If CheckBox6.Checked = True Then
            kkk4 = " AND 訂單控制表.客戶交期 BETWEEN '" & Format(DateTimePicker1.Value, "yyyy/MM/dd") & "' AND '" & Format(DateTimePicker2.Value, "yyyy/MM/dd") & "' "
        Else : kkk4 = "" : End If
    End Sub
    Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.Click
        If CheckBox3.Checked = True Then
            kkk5 = " AND 訂單控制表.工廠回復交期 BETWEEN '" & Format(DateTimePicker3.Value, "yyyy/MM/dd") & "' AND '" & Format(DateTimePicker4.Value, "yyyy/MM/dd") & "' "
        Else : kkk5 = "" : End If
    End Sub
    Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox4.Click
        If CheckBox4.Checked = True Then
            kkk6 = " AND 貨款匯入出款明細表.實際離廠日 BETWEEN '" & Format(DateTimePicker5.Value, "yyyy/MM/dd") & "' AND '" & Format(DateTimePicker6.Value, "yyyy/MM/dd") & "' "
        Else : kkk6 = "" : End If
    End Sub
    Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
        If CheckBox6.Checked = True Then
            kkk4 = " AND 訂單控制表.客戶交期 BETWEEN '" & Format(DateTimePicker1.Value, "yyyy/MM/dd") & "' AND '" & Format(DateTimePicker2.Value, "yyyy/MM/dd") & "' "
        Else : kkk4 = "" : End If
    End Sub
    Private Sub DateTimePicker2_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker2.ValueChanged
        If CheckBox6.Checked = True Then
            kkk4 = " AND 訂單控制表.客戶交期 BETWEEN '" & Format(DateTimePicker1.Value, "yyyy/MM/dd") & "' AND '" & Format(DateTimePicker2.Value, "yyyy/MM/dd") & "' "
        Else : kkk4 = "" : End If
    End Sub
    Private Sub DateTimePicker3_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker3.ValueChanged
        If CheckBox3.Checked = True Then
            kkk5 = " AND 訂單控制表.工廠回復交期 BETWEEN '" & Format(DateTimePicker3.Value, "yyyy/MM/dd") & "' AND '" & Format(DateTimePicker4.Value, "yyyy/MM/dd") & "' "
        Else : kkk5 = "" : End If
    End Sub
    Private Sub DateTimePicker4_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker4.ValueChanged
        If CheckBox3.Checked = True Then
            kkk5 = " AND 訂單控制表.工廠回復交期 BETWEEN '" & Format(DateTimePicker3.Value, "yyyy/MM/dd") & "' AND '" & Format(DateTimePicker4.Value, "yyyy/MM/dd") & "' "
        Else : kkk5 = "" : End If
    End Sub
    Private Sub DateTimePicker5_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker5.ValueChanged
        If CheckBox4.Checked = True Then
            kkk6 = " AND 貨款匯入出款明細表.實際離廠日 BETWEEN '" & Format(DateTimePicker5.Value, "yyyy/MM/dd") & "' AND '" & Format(DateTimePicker6.Value, "yyyy/MM/dd") & "' "
        Else : kkk6 = "" : End If
    End Sub
    Private Sub DateTimePicker6_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker6.ValueChanged
        If CheckBox4.Checked = True Then
            kkk6 = " AND 貨款匯入出款明細表.實際離廠日 BETWEEN '" & Format(DateTimePicker5.Value, "yyyy/MM/dd") & "' AND '" & Format(DateTimePicker6.Value, "yyyy/MM/dd") & "' "
        Else : kkk6 = "" : End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MsgBox("下次開發。")
        '列印_出貨明細表.ShowDialog()
    End Sub
    Private Sub 實際離場日修改_bt_Click(sender As Object, e As EventArgs) Handles 實際離場日修改_bt.Click
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "UPDATE 訂單控制表 SET 實際離廠日 = N'" & Format(實際離場_dtp.Value, "yyyy/MM/dd") & "' WHERE 資料流水號 LIKE N'" & 資料流水號_tb.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 = "UPDATE 貨款匯入出款明細表 SET 實際離廠日 = N'" & Format(實際離場_dtp.Value, "yyyy/MM/dd") & "' WHERE 資料流水號 LIKE N'" & 資料流水號_tb.Text & "'"
        cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
        Set_訂單清單()
    End Sub
End Class