Option Strict Off
Public Class 製鞋技術資料庫狀態
    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
    ReadOnly ds5 As New DataSet : ReadOnly ds6 As New DataSet : ReadOnly ds7 As New DataSet : ReadOnly ds8 As New DataSet : ReadOnly ds9 As New DataSet
    ReadOnly ds10 As New DataSet : ReadOnly ds11 As New DataSet : ReadOnly ds12 As New DataSet : ReadOnly ds13 As New DataSet : ReadOnly ds14 As New DataSet
    Private Sub Set_清單()
        楦頭規格_dgv.DataSource = Nothing : ds.Clear()
        楦頭規格_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        楦頭規格_dgv.ColumnHeadersHeight = 40
        楦頭規格_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 資料流水號, 楦頭編號, 楦頭圖號碼, 鞋圖號碼, 楦頭名, 楦頭名 AS 模具資料, 楦頭名 AS 素描圖片, 楦頭名 AS [MINI WALL], 楦頭名 AS 樣品單 FROM 楦頭規格控制表 ORDER BY 楦頭編號"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : 楦頭規格_dgv.DataSource = ds.Tables(0) : conn.Close()

        楦頭規格_dgv.Columns(0).FillWeight = 100 : 楦頭規格_dgv.Columns(1).FillWeight = 100 : 楦頭規格_dgv.Columns(2).FillWeight = 100 : 楦頭規格_dgv.Columns(3).FillWeight = 100
        楦頭規格_dgv.Columns(4).FillWeight = 150 : 楦頭規格_dgv.Columns(5).FillWeight = 60 : 楦頭規格_dgv.Columns(6).FillWeight = 60 : 楦頭規格_dgv.Columns(7).FillWeight = 60
        楦頭規格_dgv.Columns(8).FillWeight = 60

        楦頭編號_tb.Text = "%%"
        Set_清單1() : Set_清單2() : Set_清單3() : Set_清單4()
        For i As Integer = 0 To 楦頭規格_dgv.Rows.Count - 1
            楦頭規格_dgv("模具資料", i).Value = 0 : 楦頭規格_dgv("素描圖片", i).Value = 0 : 楦頭規格_dgv("MINI WALL", i).Value = 0 : 楦頭規格_dgv("樣品單", i).Value = 0
        Next

        For i As Integer = 0 To 楦頭規格_dgv.Rows.Count - 1
            資料數 = 楦頭規格_dgv.Rows.Count : MyModule1.進度條()
            For ii As Integer = 0 To 模具開發_dgv.Rows.Count - 1
                If 楦頭規格_dgv("楦頭編號", i).Value.ToString = 模具開發_dgv("楦頭編號", ii).Value.ToString Then
                    楦頭規格_dgv("模具資料", i).Value = Val(楦頭規格_dgv("模具資料", i).Value.ToString) + 1
                End If
            Next
            For ii As Integer = 0 To 鞋樣素描_dgv.Rows.Count - 1
                If 楦頭規格_dgv("楦頭編號", i).Value.ToString = 鞋樣素描_dgv("楦頭編號", ii).Value.ToString Then
                    楦頭規格_dgv("素描圖片", i).Value = Val(楦頭規格_dgv("素描圖片", i).Value.ToString) + 1
                End If
            Next
            For ii As Integer = 0 To MINI_WAL_dgv.Rows.Count - 1
                If 楦頭規格_dgv("楦頭編號", i).Value.ToString = MINI_WAL_dgv("楦頭編號", ii).Value.ToString Then
                    楦頭規格_dgv("MINI WALL", i).Value = Val(楦頭規格_dgv("MINI WALL", i).Value.ToString) + 1
                End If
            Next
            For ii As Integer = 0 To 樣品訂單_dgv.Rows.Count - 1
                If 楦頭規格_dgv("楦頭編號", i).Value.ToString = 樣品訂單_dgv("楦頭編號", ii).Value.ToString Then
                    楦頭規格_dgv("樣品單", i).Value = Val(楦頭規格_dgv("樣品單", i).Value.ToString) + 1
                End If
            Next
        Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
        模具開發_dgv.DataSource = Nothing : ds1.Clear() : 鞋樣素描_dgv.DataSource = Nothing : ds2.Clear()
        MINI_WAL_dgv.DataSource = Nothing : ds3.Clear() : 樣品訂單_dgv.DataSource = Nothing : ds4.Clear()
        楦頭編號_tb.Text = ""
        筆數1_tb.Text = 楦頭規格_dgv.Rows.Count
    End Sub
    Private Sub Set_清單1()
        模具開發_dgv.DataSource = Nothing : ds1.Clear()
        模具開發_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        模具開發_dgv.ColumnHeadersHeight = 25
        模具開發_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 楦頭編號, 模具開發單號, 結構, 材質, 模具編號, 品牌 FROM 模具開發控制表 WHERE (楦頭編號 LIKE '" & 楦頭編號_tb.Text & "')"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : 模具開發_dgv.DataSource = ds1.Tables(0) : conn.Close()
        模具開發_dgv.Columns(0).Visible = False
    End Sub
    Private Sub Set_清單2()
        鞋樣素描_dgv.DataSource = Nothing : ds2.Clear()
        鞋樣素描_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        鞋樣素描_dgv.ColumnHeadersHeight = 25
        鞋樣素描_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 楦頭編號, 鞋樣素描圖編號,模具編號,型體編號,型體名稱,品牌 FROM 鞋樣素描圖控制表 WHERE (楦頭編號 LIKE '" & 楦頭編號_tb.Text & "')"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds2) : 鞋樣素描_dgv.DataSource = ds2.Tables(0) : conn.Close()
        鞋樣素描_dgv.Columns(0).Visible = False
    End Sub
    Private Sub Set_清單3()
        MINI_WAL_dgv.DataSource = Nothing : ds3.Clear()
        MINI_WAL_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        MINI_WAL_dgv.ColumnHeadersHeight = 25
        MINI_WAL_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT      MINI_WALL_明細表.楦頭編號, MINI_WALL_明細表.MW編號, MINI_WALL_明細表.製造, MINI_WALL_控制表.季節, MINI_WALL_控制表.品牌, MINI_WALL_明細表.楦頭編號
                FROM        MINI_WALL_明細表 LEFT OUTER JOIN MINI_WALL_控制表 ON MINI_WALL_明細表.MW編號 = MINI_WALL_控制表.MW編號
                WHERE      (MINI_WALL_明細表.楦頭編號 LIKE '" & 楦頭編號_tb.Text & "')
                GROUP BY    MINI_WALL_明細表.MW編號, MINI_WALL_明細表.製造, MINI_WALL_控制表.季節, MINI_WALL_控制表.品牌, MINI_WALL_明細表.楦頭編號
                ORDER BY    MINI_WALL_明細表.MW編號"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds3) : MINI_WAL_dgv.DataSource = ds3.Tables(0) : conn.Close()
        MINI_WAL_dgv.Columns(0).Visible = False
    End Sub
    Private Sub Set_清單4()
        樣品訂單_dgv.DataSource = Nothing : ds4.Clear()
        樣品訂單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        樣品訂單_dgv.ColumnHeadersHeight = 25
        樣品訂單_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 楦頭編號, SO, 季節, 客戶, 型體號碼, 型體名稱 FROM 樣品訂單控制表 WHERE (楦頭編號 LIKE '" & 楦頭編號_tb.Text & "') ORDER BY SO"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds4) : 樣品訂單_dgv.DataSource = ds4.Tables(0) : conn.Close()
        樣品訂單_dgv.Columns(0).Visible = False
    End Sub
    Private Sub Set_清單5()
        模具規格_dgv.DataSource = Nothing : ds5.Clear()
        模具規格_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        模具規格_dgv.ColumnHeadersHeight = 40
        模具規格_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 模具開發單號, 結構, 材質, 楦頭編號, 模具編號, 品牌, 大底廠, 尺寸, 季節, 制表, 制表日期, 模具廠, 模具廠 AS 鞋樣素描 FROM 模具開發控制表 ORDER BY 模具編號"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds5) : 模具規格_dgv.DataSource = ds5.Tables(0) : conn.Close()

        模具規格_dgv.Columns(0).FillWeight = 100 : 模具規格_dgv.Columns(1).FillWeight = 100 : 模具規格_dgv.Columns(2).FillWeight = 100 : 模具規格_dgv.Columns(3).FillWeight = 100
        模具規格_dgv.Columns(4).FillWeight = 100 : 模具規格_dgv.Columns(5).FillWeight = 100 : 模具規格_dgv.Columns(6).FillWeight = 100 : 模具規格_dgv.Columns(7).FillWeight = 50
        模具規格_dgv.Columns(8).FillWeight = 100 : 模具規格_dgv.Columns(9).FillWeight = 80 : 模具規格_dgv.Columns(10).FillWeight = 90 : 模具規格_dgv.Columns(11).FillWeight = 60
        模具規格_dgv.Columns(12).FillWeight = 60

        For i As Integer = 0 To 模具規格_dgv.Rows.Count - 1
            資料數 = 模具規格_dgv.Rows.Count : MyModule1.進度條()
            模具規格_tb.Text = 模具規格_dgv("模具編號", i).Value.ToString
            Set_清單6()
            模具規格_dgv("鞋樣素描", i).Value = 鞋樣素描1_dgv.Rows.Count
        Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
        模具規格_tb.Text = ""
        筆數2_tb.Text = 模具規格_dgv.Rows.Count
    End Sub
    Private Sub Set_清單6()
        鞋樣素描1_dgv.DataSource = Nothing : ds6.Clear()
        鞋樣素描1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        鞋樣素描1_dgv.ColumnHeadersHeight = 25
        鞋樣素描1_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 鞋樣素描圖編號, 型體編號, 型體名稱, 品牌 FROM 鞋樣素描圖控制表 WHERE (模具編號 LIKE '" & 模具規格_tb.Text & "')"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds6) : 鞋樣素描1_dgv.DataSource = ds6.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_清單7()
        型體資訊_dgv.DataSource = Nothing : ds7.Clear()
        型體資訊_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        型體資訊_dgv.ColumnHeadersHeight = 40
        型體資訊_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 客戶簡稱, 型體號碼, 型體名稱, 型體名稱 AS 鞋樣素描, 型體名稱 AS 鞋型圖片, 型體名稱 AS 樣品訂單, 型體名稱 AS 量產控制, 型體名稱 AS 量產明細, 型體名稱 AS 出貨明細
                FROM 型體控制表 ORDER BY 客戶簡稱, 型體號碼, 型體名稱"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds7) : 型體資訊_dgv.DataSource = ds7.Tables(0) : conn.Close()

        型體資訊_dgv.Columns(0).FillWeight = 100 : 型體資訊_dgv.Columns(1).FillWeight = 100 : 型體資訊_dgv.Columns(2).FillWeight = 100 : 型體資訊_dgv.Columns(3).FillWeight = 60
        型體資訊_dgv.Columns(4).FillWeight = 60 : 型體資訊_dgv.Columns(5).FillWeight = 60 : 型體資訊_dgv.Columns(6).FillWeight = 60 : 型體資訊_dgv.Columns(7).FillWeight = 60
        型體資訊_dgv.Columns(8).FillWeight = 60

        客戶_tb.Text = "%%" : 編號_tb.Text = "%%" : 名稱_tb.Text = "%%"
        For i As Integer = 0 To 型體資訊_dgv.Rows.Count - 1
            型體資訊_dgv("鞋樣素描", i).Value = 0 : 型體資訊_dgv("鞋型圖片", i).Value = 0 : 型體資訊_dgv("樣品訂單", i).Value = 0
            型體資訊_dgv("量產控制", i).Value = 0 : 型體資訊_dgv("量產明細", i).Value = 0 : 型體資訊_dgv("出貨明細", i).Value = 0
        Next

        Set_清單8() : Set_清單9() : Set_清單10() : Set_清單11() : Set_清單12() : Set_清單13()
        For i As Integer = 0 To 型體資訊_dgv.Rows.Count - 1
            資料數 = 型體資訊_dgv.Rows.Count : MyModule1.進度條()
            For ii As Integer = 0 To 鞋樣素描2_dgv.Rows.Count - 1
                If 型體資訊_dgv("型體號碼", i).Value.ToString = 鞋樣素描2_dgv("型體編號", ii).Value.ToString And
                    型體資訊_dgv("型體名稱", i).Value.ToString = 鞋樣素描2_dgv("型體名稱", ii).Value.ToString Then
                    型體資訊_dgv("鞋樣素描", i).Value = Val(型體資訊_dgv("鞋樣素描", i).Value.ToString) + 1
                End If
            Next
            For ii As Integer = 0 To 鞋型圖片_dgv.Rows.Count - 1
                If 型體資訊_dgv("客戶簡稱", i).Value.ToString = 鞋型圖片_dgv("客戶", ii).Value.ToString And
                    型體資訊_dgv("型體號碼", i).Value.ToString = 鞋型圖片_dgv("形體號", ii).Value.ToString And
                    型體資訊_dgv("型體名稱", i).Value.ToString = 鞋型圖片_dgv("形體名", ii).Value.ToString Then
                    型體資訊_dgv("鞋型圖片", i).Value = Val(型體資訊_dgv("鞋型圖片", i).Value.ToString) + 1
                End If
            Next
            For ii As Integer = 0 To 樣品訂單1_dgv.Rows.Count - 1
                If 型體資訊_dgv("型體號碼", i).Value.ToString = 樣品訂單1_dgv("型體號碼", ii).Value.ToString And
                    型體資訊_dgv("型體名稱", i).Value.ToString = 樣品訂單1_dgv("型體名稱", ii).Value.ToString Then
                    型體資訊_dgv("樣品訂單", i).Value = Val(型體資訊_dgv("樣品訂單", i).Value.ToString) + 1
                End If
            Next
            For ii As Integer = 0 To 量產控制_dgv.Rows.Count - 1
                If 型體資訊_dgv("型體號碼", i).Value.ToString = 量產控制_dgv("型體號碼", ii).Value.ToString And
                    型體資訊_dgv("型體名稱", i).Value.ToString = 量產控制_dgv("GOODBOX", ii).Value.ToString Then
                    型體資訊_dgv("量產控制", i).Value = Val(型體資訊_dgv("量產控制", i).Value.ToString) + 1
                End If
            Next
            For ii As Integer = 0 To 量產明細_dgv.Rows.Count - 1
                If 型體資訊_dgv("型體號碼", i).Value.ToString = 量產明細_dgv("ItemNumber", ii).Value.ToString And
                    型體資訊_dgv("型體名稱", i).Value.ToString = 量產明細_dgv("ProductName", ii).Value.ToString Then
                    型體資訊_dgv("量產明細", i).Value = Val(型體資訊_dgv("量產明細", i).Value.ToString) + 1
                End If
            Next
            For ii As Integer = 0 To 出貨明細_dgv.Rows.Count - 1
                If 型體資訊_dgv("型體名稱", i).Value.ToString = 出貨明細_dgv("形體號", ii).Value.ToString Then
                    型體資訊_dgv("出貨明細", i).Value = Val(型體資訊_dgv("出貨明細", i).Value.ToString) + 1
                End If
            Next
        Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
        鞋樣素描2_dgv.DataSource = Nothing : ds8.Clear() : 鞋型圖片_dgv.DataSource = Nothing : ds9.Clear()
        樣品訂單1_dgv.DataSource = Nothing : ds10.Clear() : 量產控制_dgv.DataSource = Nothing : ds11.Clear()
        量產明細_dgv.DataSource = Nothing : ds12.Clear() : 出貨明細_dgv.DataSource = Nothing : ds13.Clear()
        客戶_tb.Text = "" : 編號_tb.Text = "" : 名稱_tb.Text = ""
        筆數3_tb.Text = 型體資訊_dgv.Rows.Count
    End Sub
    Private Sub Set_清單8()
        鞋樣素描2_dgv.DataSource = Nothing : ds8.Clear()
        鞋樣素描2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        鞋樣素描2_dgv.ColumnHeadersHeight = 25
        鞋樣素描2_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 型體名稱, 型體編號, 鞋樣素描圖編號, 楦頭編號, 模具編號, 品牌 FROM 鞋樣素描圖控制表 WHERE 型體編號 LIKE '" & 編號_tb.Text & "' AND 型體名稱 LIKE '" & 名稱_tb.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds8) : 鞋樣素描2_dgv.DataSource = ds8.Tables(0) : conn.Close()
        鞋樣素描2_dgv.Columns(0).Visible = False : 鞋樣素描2_dgv.Columns(1).Visible = False
    End Sub
    Private Sub Set_清單9()
        鞋型圖片_dgv.DataSource = Nothing : ds9.Clear()
        鞋型圖片_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        鞋型圖片_dgv.ColumnHeadersHeight = 25
        鞋型圖片_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 客戶, 形體號, 形體名, 顏色, 類別, 入圖者, 圖片編號 FROM 鞋型圖片資料庫 
                WHERE 客戶 LIKE '" & 客戶_tb.Text & "' AND 形體號 LIKE '" & 編號_tb.Text & "' AND 形體名 LIKE '" & 名稱_tb.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds9) : 鞋型圖片_dgv.DataSource = ds9.Tables(0) : conn.Close()
        鞋型圖片_dgv.Columns(0).Visible = False : 鞋型圖片_dgv.Columns(1).Visible = False : 鞋型圖片_dgv.Columns(2).Visible = False
    End Sub
    Private Sub Set_清單10()
        樣品訂單1_dgv.DataSource = Nothing : ds10.Clear()
        樣品訂單1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        樣品訂單1_dgv.ColumnHeadersHeight = 25
        樣品訂單1_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 型體號碼, 型體名稱, SO, 季節, 型體號碼, 型體名稱, 制單人, 版次 FROM  樣品訂單控制表 
                WHERE  型體號碼 LIKE '" & 編號_tb.Text & "' AND 型體名稱 LIKE '" & 名稱_tb.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds10) : 樣品訂單1_dgv.DataSource = ds10.Tables(0) : conn.Close()
        樣品訂單1_dgv.Columns(0).Visible = False : 樣品訂單1_dgv.Columns(1).Visible = False
    End Sub
    Private Sub Set_清單11()
        量產控制_dgv.DataSource = Nothing : ds11.Clear()
        量產控制_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        量產控制_dgv.ColumnHeadersHeight = 25
        量產控制_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 型體號碼, GOODBOX, 訂單流水號, 年份季度, 客戶訂單號, 型體號碼, GOODBOX AS 形體名稱, APMA確認 AS 顏色 FROM 訂單控制表
                WHERE (型體號碼 LIKE '" & 編號_tb.Text & "') AND (GOODBOX LIKE '" & 名稱_tb.Text & "')"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds11) : 量產控制_dgv.DataSource = ds11.Tables(0) : conn.Close()
        量產控制_dgv.Columns(0).Visible = False : 量產控制_dgv.Columns(1).Visible = False
    End Sub
    Private Sub Set_清單12()
        量產明細_dgv.DataSource = Nothing : ds12.Clear()
        量產明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        量產明細_dgv.ColumnHeadersHeight = 25
        量產明細_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT ItemNumber, ProductName, 訂單流水號, 客戶訂單號, Color AS 顏色, 資料流水號 FROM 訂單明細表 
                WHERE  ItemNumber LIKE '" & 編號_tb.Text & "' AND ProductName LIKE '" & 名稱_tb.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds12) : 量產明細_dgv.DataSource = ds12.Tables(0) : conn.Close()
        量產明細_dgv.Columns(0).Visible = False : 量產明細_dgv.Columns(1).Visible = False
    End Sub
    Private Sub Set_清單13()
        出貨明細_dgv.DataSource = Nothing : ds13.Clear()
        出貨明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        出貨明細_dgv.ColumnHeadersHeight = 25
        出貨明細_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 形體號, 貨款流水號, 資料流水號, 訂單流水號, 年份季度, 客戶訂單號 FROM 貨款匯入出款明細表 WHERE 形體號 LIKE '" & 名稱_tb.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds13) : 出貨明細_dgv.DataSource = ds13.Tables(0) : conn.Close()
        出貨明細_dgv.Columns(0).Visible = False
    End Sub
    Private Sub Set_清單14()
        楦模轉換_dgv.DataSource = Nothing : ds14.Clear()
        楦模轉換_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        楦模轉換_dgv.ColumnHeadersHeight = 25
        楦模轉換_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT   模具開發控制表.模具開發單號, 模具開發控制表.模具編號, 模具開發控制表.楦頭編號 AS 模具對應楦頭, 模具開發控制表.CN AS NCN, 楦頭規格控制表.楦頭編號, 
                         楦頭規格控制表.楦頭名 AS OCN, 楦頭規格控制表.資料流水號, METOO選擇按鈕.選擇
                FROM     模具開發控制表 LEFT OUTER JOIN METOO選擇按鈕 ON 模具開發控制表.楦頭編號 = METOO選擇按鈕.對應 FULL OUTER JOIN 楦頭規格控制表 ON 模具開發控制表.楦頭編號 = 
                         楦頭規格控制表.楦頭編號
                ORDER BY 模具開發控制表.模具編號 DESC"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds14) : 楦模轉換_dgv.DataSource = ds14.Tables(0) : conn.Close()
        For i As Integer = 0 To 楦模轉換_dgv.Rows.Count - 1
            楦模轉換_dgv("選擇", i).Value = False
        Next
    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
        Set_清單() : Set_清單5() : Set_清單7() : Set_清單14()
    End Sub
    Private Sub 楦模轉換_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 楦模轉換_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 楦模轉換_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 楦模轉換_dgv("模具編號", e.RowIndex).Value.ToString <> 楦模轉換_dgv("模具編號", e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(楦模轉換_dgv.RowHeadersVisible, 楦模轉換_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 楦模轉換_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 楦模轉換_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 楦模轉換_dgv.Rows.Count - 1
                If 楦模轉換_dgv("選擇", i).Value = True Then
                    楦模轉換_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                End If
            Next
        End If
    End Sub
    Private Sub 型體資訊_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 型體資訊_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 型體資訊_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 型體資訊_dgv("客戶簡稱", e.RowIndex).Value.ToString <> 型體資訊_dgv("客戶簡稱", e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(型體資訊_dgv.RowHeadersVisible, 型體資訊_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 型體資訊_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 型體資訊_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 型體資訊_dgv.Rows.Count - 1
                If 型體資訊_dgv("鞋樣素描", i).Value.ToString = "0" And 型體資訊_dgv("鞋型圖片", i).Value.ToString = "0" And
                型體資訊_dgv("樣品訂單", i).Value.ToString = "0" And 型體資訊_dgv("量產控制", i).Value.ToString = "0" And
                型體資訊_dgv("量產明細", i).Value.ToString = "0" And 型體資訊_dgv("出貨明細", i).Value.ToString = "0" Then
                    型體資訊_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                End If
                If 型體資訊_dgv("鞋樣素描", i).Value.ToString <> "0" And 型體資訊_dgv("鞋型圖片", i).Value.ToString <> "0" And
                型體資訊_dgv("樣品訂單", i).Value.ToString <> "0" And 型體資訊_dgv("量產控制", i).Value.ToString <> "0" And
                型體資訊_dgv("量產明細", i).Value.ToString <> "0" And 型體資訊_dgv("出貨明細", i).Value.ToString <> "0" Then
                    型體資訊_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue
                End If
            Next
        End If
    End Sub
    Private Sub 物料清單_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 模具規格_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 模具規格_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 模具規格_dgv("模具編號", e.RowIndex).Value.ToString <> 模具規格_dgv("模具編號", e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(模具規格_dgv.RowHeadersVisible, 模具規格_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 模具規格_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 模具規格_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 模具規格_dgv.Rows.Count - 1
                If 模具規格_dgv("鞋樣素描", i).Value.ToString = "0" Then : 模具規格_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink : End If
                If 模具規格_dgv("鞋樣素描", i).Value.ToString <> "0" Then : 模具規格_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue : End If
            Next
        End If
    End Sub
    Private Sub 楦頭規格_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 楦頭規格_dgv.RowPostPaint
        If e.RowIndex = 楦頭規格_dgv.Rows.Count - 1 Then : Exit Sub : Else
            For i As Integer = 0 To 楦頭規格_dgv.Rows.Count - 1
                If 楦頭規格_dgv("模具資料", i).Value.ToString = "0" And 楦頭規格_dgv("素描圖片", i).Value.ToString = "0" And
                楦頭規格_dgv("MINI WALL", i).Value.ToString = "0" And 楦頭規格_dgv("樣品單", i).Value.ToString = "0" Then
                    楦頭規格_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                End If
                If 楦頭規格_dgv("模具資料", i).Value.ToString <> "0" And 楦頭規格_dgv("素描圖片", i).Value.ToString <> "0" And
                楦頭規格_dgv("MINI WALL", i).Value.ToString <> "0" And 楦頭規格_dgv("樣品單", i).Value.ToString <> "0" Then
                    楦頭規格_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightBlue
                End If
            Next
        End If
    End Sub
    Private Sub 楦模轉換_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 楦模轉換_dgv.CellClick
        If 楦模轉換_dgv("模具開發單號", e.RowIndex).Value.ToString = "" Then
            楦模轉換_dgv("選擇", e.RowIndex).Value = False
        Else
            If 楦模轉換_dgv("資料流水號", e.RowIndex).Value.ToString = "" Then
                楦模轉換_dgv("選擇", e.RowIndex).Value = False
            Else
                If 楦模轉換_dgv("OCN", e.RowIndex).Value.ToString = "" Then
                    楦模轉換_dgv("選擇", e.RowIndex).Value = False
                Else
                    楦模轉換_dgv("選擇", e.RowIndex).Value = True
                    楦模轉換_dgv("NCN", e.RowIndex).Value = 楦模轉換_dgv("OCN", e.RowIndex).Value.ToString
                End If
            End If
        End If
    End Sub
    Private Sub 型體資訊_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 型體資訊_dgv.CellClick
        客戶_tb.Text = 型體資訊_dgv("客戶簡稱", e.RowIndex).Value.ToString : 編號_tb.Text = 型體資訊_dgv("型體號碼", e.RowIndex).Value.ToString
        名稱_tb.Text = 型體資訊_dgv("型體名稱", e.RowIndex).Value.ToString
        Set_清單8() : Set_清單9() : Set_清單10() : Set_清單11() : Set_清單12() : Set_清單13()
    End Sub
    Private Sub 模具規格_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 模具規格_dgv.CellClick
        模具規格_tb.Text = 模具規格_dgv("模具編號", e.RowIndex).Value.ToString
        Set_清單6()
    End Sub
    Private Sub 楦頭規格_dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles 楦頭規格_dgv.CellClick
        楦頭編號_tb.Text = 楦頭規格_dgv("楦頭編號", e.RowIndex).Value.ToString
        Set_清單1() : Set_清單2() : Set_清單3() : Set_清單4()
    End Sub
    Private Sub 自動比對_bt_Click(sender As Object, e As EventArgs) Handles 自動比對_bt.Click
        For i As Integer = 0 To 楦模轉換_dgv.Rows.Count - 1
            If 楦模轉換_dgv("模具開發單號", i).Value.ToString = "" Then
                楦模轉換_dgv("選擇", i).Value = False
            Else
                If 楦模轉換_dgv("資料流水號", i).Value.ToString = "" Then
                    楦模轉換_dgv("選擇", i).Value = False
                Else
                    If 楦模轉換_dgv("OCN", i).Value.ToString = "" Then
                        楦模轉換_dgv("選擇", i).Value = False
                    Else
                        楦模轉換_dgv("選擇", i).Value = True
                        楦模轉換_dgv("NCN", i).Value = 楦模轉換_dgv("OCN", i).Value.ToString
                    End If
                End If
            End If
        Next
    End Sub
    Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
        For i As Integer = 0 To 楦模轉換_dgv.Rows.Count - 1
            資料數 = 楦模轉換_dgv.Rows.Count : MyModule1.進度條()
            If 楦模轉換_dgv("模具開發單號", i).Value.ToString = "" Then : Else
                If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                SQL1 = "UPDATE 模具開發控制表 SET CN = N'" & 楦模轉換_dgv("NCN", i).Value.ToString & "' WHERE 模具開發單號 LIKE N'" & 楦模轉換_dgv("模具開發單號", i).Value.ToString & "'"
                cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
            End If
        Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
        Set_清單14()
    End Sub
End Class