Option Strict Off
Imports System.Net
Imports System.IO
Imports System.Windows.Forms.VisualStyles.VisualStyleElement
Public Class 物料資料庫
    Public Property Credentials As ICredentials
    Dim Str As String = Application.StartupPath
    Dim EDR As Integer = 0
    Dim ESTR, KKK1, KKK2, KKK3, KKK4 As String
    Dim 對話框(64) As String : Dim 群組碼(4), 原則說明異動 As String
    Dim 是否有資料, 群組圖片, 只讀一次, 查詢 As Boolean
    Private initialPanel1Width As Integer
    Private Sub Set_新群組清單()
        Dim ds1 As New DataSet : 新群組_dgv.DataSource = Nothing : ds1.Clear()
        新群組_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        新群組_dgv.ColumnHeadersHeight = 25 : 新群組_dgv.AllowUserToAddRows = False : 新群組_dgv.RowTemplate.Height = 25
        SQL_新物料群組()
        da.Fill(ds1) : 新群組_dgv.DataSource = ds1.Tables(0) : conn.Close()
        新群組_dgv.Columns(0).FillWeight = 50 : 新群組_dgv.Columns(1).Visible = False : 新群組_dgv.Columns(7).FillWeight = 40
        For I As Integer = 0 To 新群組_dgv.Columns.Count - 1 : 新群組_dgv.Columns(I).ReadOnly = True : Next
    End Sub
    Private Sub Set_新群組清單_物料()
        Dim ds1 As New DataSet : 新群組_物料_dgv.DataSource = Nothing : ds1.Clear()
        新群組_物料_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        新群組_物料_dgv.ColumnHeadersHeight = 25 : 新群組_物料_dgv.AllowUserToAddRows = False : 新群組_物料_dgv.RowTemplate.Height = 25
        If 一般模式_cb.Checked = True Then
            SQL2 = " WHERE  (物料編碼庫.新群組碼 LIKE '" & PA48 & "')  AND (物料編碼庫轉語言.語言 LIKE '" & 系統語言 & "') "
        ElseIf 一般模式_cb.Checked = False Then
            SQL2 = " WHERE  (物料編碼庫.新群組碼 LIKE '' OR 物料編碼庫.新群組碼 IS NULL)  AND (物料編碼庫轉語言.語言 LIKE '" & 系統語言 & "') "
        End If
        SQL_物料資料庫_物料資訊控制表_新群組()
        da.Fill(ds1) : 新群組_物料_dgv.DataSource = ds1.Tables(0) : conn.Close()
        新群組_物料_dgv.Columns(0).FillWeight = 60 : 新群組_物料_dgv.Columns(1).FillWeight = 80 : 新群組_物料_dgv.Columns(2).FillWeight = 166
        新群組_物料_dgv.Columns(3).FillWeight = 30
        新群組_物料_dgv.Columns(4).Visible = False : 新群組_物料_dgv.Columns(5).Visible = False : 新群組_物料_dgv.Columns(6).Visible = False
        新群組_物料_dgv.Columns(0).ReadOnly = True : 新群組_物料_dgv.Columns(1).ReadOnly = True : 新群組_物料_dgv.Columns(2).ReadOnly = True
        新群組_物料_dgv.Columns(3).ReadOnly = True : 新群組_物料_dgv.Columns(4).ReadOnly = True : 新群組_物料_dgv.Columns(5).ReadOnly = True

        If 低網速模式 = False Then
            新群組_物料_dgv.Columns(7).FillWeight = 50 : 新群組_物料_dgv.Columns(7).Visible = True
            Dim mycol As DataGridViewImageColumn = 新群組_物料_dgv.Columns("Image")
            mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
        Else : If 新群組_物料_dgv.Columns.Count = 8 Then : 新群組_物料_dgv.Columns(7).Visible = False : End If : End If

        For I As Integer = 0 To 新群組_物料_dgv.Rows.Count - 1
            新群組_物料_dgv.Rows(I).DefaultCellStyle.BackColor = Color.White
        Next
    End Sub
    Private Sub Set_群組清單()
        Dim ds1 As New DataSet : 群組分類_dgv.DataSource = Nothing : ds1.Clear()
        群組分類_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        群組分類_dgv.ColumnHeadersHeight = 25 : 群組分類_dgv.AllowUserToAddRows = False : 群組分類_dgv.RowTemplate.Height = 45
        SQL_物料群組_倉儲()
        da.Fill(ds1) : 群組分類_dgv.DataSource = ds1.Tables(0) : conn.Close()
        '群組分類_dgv.Columns(2).FillWeight = 30
        'Dim mycol As DataGridViewImageColumn = 群組分類_dgv.Columns("圖片")
        'mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
    End Sub
    Private Sub Set_物料群組()
        Dim ds5, ds6, ds7, ds8, ds9, ds14 As New DataSet
        物料群組_dgv.DataSource = Nothing : ds5.Clear()
        群組碼2_dgv.DataSource = Nothing : ds8.Clear() : 群組碼3_dgv.DataSource = Nothing : ds9.Clear()
        群組碼4_dgv.DataSource = Nothing : ds14.Clear() : 群組碼5_dgv.DataSource = Nothing : ds6.Clear()
        物料群組_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        群組碼2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        群組碼3_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        群組碼4_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        群組碼5_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料群組_dgv.ColumnHeadersHeight = 25 : 群組碼2_dgv.ColumnHeadersHeight = 25 : 群組碼3_dgv.ColumnHeadersHeight = 25
        群組碼4_dgv.ColumnHeadersHeight = 25 : 群組碼5_dgv.ColumnHeadersHeight = 25
        物料群組_dgv.AllowUserToAddRows = False : 群組碼2_dgv.AllowUserToAddRows = False : 群組碼3_dgv.AllowUserToAddRows = False
        群組碼4_dgv.AllowUserToAddRows = False : 群組碼5_dgv.AllowUserToAddRows = False
        If 主項目1_cb.SelectedIndex = 0 Then : PA49 = "" : ElseIf 主項目1_cb.SelectedIndex = 1 Then : PA49 = 物料主項(0)
        ElseIf 主項目1_cb.SelectedIndex = 2 Then : PA49 = 物料主項(1) : ElseIf 主項目1_cb.SelectedIndex = 3 Then : PA49 = 物料主項(2)
        ElseIf 主項目1_cb.SelectedIndex = 4 Then : PA49 = 物料主項(3) : ElseIf 主項目1_cb.SelectedIndex = 5 Then : PA49 = 物料主項(4)
        ElseIf 主項目1_cb.SelectedIndex = 6 Then : PA49 = 物料主項(5) : ElseIf 主項目1_cb.SelectedIndex = 6 Then : PA49 = 物料主項(6)
        ElseIf 主項目1_cb.SelectedIndex = 6 Then : PA49 = 物料主項(7) : ElseIf 主項目1_cb.SelectedIndex = 6 Then : PA49 = 物料主項(8)
        ElseIf 主項目1_cb.SelectedIndex = 6 Then : PA49 = 物料主項(9) : End If
        SQL_物料資料庫_群組碼清單1()
        da.Fill(ds5) : 物料群組_dgv.DataSource = ds5.Tables(0) : conn.Close() : da.Fill(ds8) : 群組碼2_dgv.DataSource = ds8.Tables(0) : conn.Close()
        da.Fill(ds9) : 群組碼3_dgv.DataSource = ds9.Tables(0) : conn.Close()
        da.Fill(ds14) : 群組碼4_dgv.DataSource = ds14.Tables(0) : conn.Close() : da.Fill(ds6) : 群組碼5_dgv.DataSource = ds6.Tables(0) : conn.Close()

        物料群組_dgv.Columns(0).ReadOnly = True : 群組碼2_dgv.Columns(0).ReadOnly = True : 群組碼3_dgv.Columns(0).ReadOnly = True
        群組碼4_dgv.Columns(0).ReadOnly = True : 群組碼5_dgv.Columns(0).ReadOnly = True
    End Sub
    Private Sub Set_物料群組_語轉()
        Dim ds5, ds6, ds7, ds8, ds9, ds14 As New DataSet
        物料群組_語言_dgv.DataSource = Nothing : ds5.Clear()
        物料群組_語言2_dgv.DataSource = Nothing : ds8.Clear() : 物料群組_語言3_dgv.DataSource = Nothing : ds9.Clear()
        物料群組_語言4_dgv.DataSource = Nothing : ds14.Clear() : 物料群組_語言5_dgv.DataSource = Nothing : ds6.Clear()
        物料群組_語言_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料群組_語言2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料群組_語言3_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料群組_語言4_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料群組_語言5_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料群組_語言_dgv.ColumnHeadersHeight = 25 : 物料群組_語言2_dgv.ColumnHeadersHeight = 25 : 物料群組_語言3_dgv.ColumnHeadersHeight = 25
        物料群組_語言4_dgv.ColumnHeadersHeight = 25 : 物料群組_語言5_dgv.ColumnHeadersHeight = 25
        物料群組_語言_dgv.AllowUserToAddRows = False : 物料群組_語言2_dgv.AllowUserToAddRows = False : 物料群組_語言3_dgv.AllowUserToAddRows = False
        物料群組_語言4_dgv.AllowUserToAddRows = False : 物料群組_語言5_dgv.AllowUserToAddRows = False
        If 主項目1_cb.SelectedIndex = 0 Then : PA49 = "" : ElseIf 主項目1_cb.SelectedIndex = 1 Then : PA49 = 物料主項(0)
        ElseIf 主項目1_cb.SelectedIndex = 2 Then : PA49 = 物料主項(1) : ElseIf 主項目1_cb.SelectedIndex = 3 Then : PA49 = 物料主項(2)
        ElseIf 主項目1_cb.SelectedIndex = 4 Then : PA49 = 物料主項(3) : ElseIf 主項目1_cb.SelectedIndex = 5 Then : PA49 = 物料主項(4)
        ElseIf 主項目1_cb.SelectedIndex = 6 Then : PA49 = 物料主項(5) : ElseIf 主項目1_cb.SelectedIndex = 6 Then : PA49 = 物料主項(6)
        ElseIf 主項目1_cb.SelectedIndex = 6 Then : PA49 = 物料主項(7) : ElseIf 主項目1_cb.SelectedIndex = 6 Then : PA49 = 物料主項(8)
        ElseIf 主項目1_cb.SelectedIndex = 6 Then : PA49 = 物料主項(9) : End If
        SQL_物料資料庫_群組碼清單_含語言1()
        da.Fill(ds5) : 物料群組_語言_dgv.DataSource = ds5.Tables(0) : conn.Close() : da.Fill(ds8) : 物料群組_語言2_dgv.DataSource = ds8.Tables(0) : conn.Close()
        da.Fill(ds9) : 物料群組_語言3_dgv.DataSource = ds9.Tables(0) : conn.Close()
        da.Fill(ds14) : 物料群組_語言4_dgv.DataSource = ds14.Tables(0) : conn.Close() : da.Fill(ds6) : 物料群組_語言5_dgv.DataSource = ds6.Tables(0) : conn.Close()
        物料群組_語言_dgv.Columns(0).Visible = False : 物料群組_語言_dgv.Columns(1).ReadOnly = True : 物料群組_語言_dgv.Columns(2).Visible = False
        物料群組_語言2_dgv.Columns(0).Visible = False : 物料群組_語言2_dgv.Columns(1).ReadOnly = True : 物料群組_語言2_dgv.Columns(2).Visible = False
        物料群組_語言3_dgv.Columns(0).Visible = False : 物料群組_語言3_dgv.Columns(1).ReadOnly = True : 物料群組_語言3_dgv.Columns(2).Visible = False
        物料群組_語言4_dgv.Columns(0).Visible = False : 物料群組_語言4_dgv.Columns(1).ReadOnly = True : 物料群組_語言4_dgv.Columns(2).Visible = False
        物料群組_語言5_dgv.Columns(0).Visible = False : 物料群組_語言5_dgv.Columns(1).ReadOnly = True : 物料群組_語言5_dgv.Columns(2).Visible = False
    End Sub
    Private Sub Set_比對1()
        Dim ds16 As New DataSet : 比對1_dgv.DataSource = Nothing : ds16.Clear()
        比對1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        比對1_dgv.ColumnHeadersHeight = 25 : 比對1_dgv.AllowUserToAddRows = False : 比對1_dgv.RowTemplate.Height = 25
        SQL_比對1()
        da.Fill(ds16) : 比對1_dgv.DataSource = ds16.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_比對2()
        Dim ds17 As New DataSet : 比對2_dgv.DataSource = Nothing : ds17.Clear()
        比對2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        比對2_dgv.ColumnHeadersHeight = 25 : 比對2_dgv.AllowUserToAddRows = False : 比對2_dgv.RowTemplate.Height = 25
        SQL_比對2()
        da.Fill(ds17) : 比對2_dgv.DataSource = ds17.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_比對3()
        Dim ds18 As New DataSet : 比對3_dgv.DataSource = Nothing : ds18.Clear()
        比對3_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        比對3_dgv.ColumnHeadersHeight = 25 : 比對3_dgv.AllowUserToAddRows = False : 比對3_dgv.RowTemplate.Height = 25
        SQL_比對3()
        da.Fill(ds18) : 比對3_dgv.DataSource = ds18.Tables(0) : conn.Close()
        比對3_dgv.Columns(2).FillWeight = 250
    End Sub
    Private Sub Set_比對4()
        Dim ds18 As New DataSet : 比對4_dgv.DataSource = Nothing : ds18.Clear()
        比對4_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        比對4_dgv.ColumnHeadersHeight = 25 : 比對4_dgv.AllowUserToAddRows = False : 比對4_dgv.RowTemplate.Height = 25
        SQL_比對4()
        da.Fill(ds18) : 比對4_dgv.DataSource = ds18.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_比對5()
        Dim ds18 As New DataSet : 比對5_dgv.DataSource = Nothing : ds18.Clear()
        比對5_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        比對5_dgv.ColumnHeadersHeight = 25 : 比對5_dgv.AllowUserToAddRows = False : 比對5_dgv.RowTemplate.Height = 25
        SQL_比對5()
        da.Fill(ds18) : 比對5_dgv.DataSource = ds18.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_比對6()
        Dim ds18 As New DataSet : 比對6_dgv.DataSource = Nothing : ds18.Clear()
        比對6_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        比對6_dgv.ColumnHeadersHeight = 25 : 比對6_dgv.AllowUserToAddRows = False : 比對6_dgv.RowTemplate.Height = 25
        SQL_比對6()
        da.Fill(ds18) : 比對6_dgv.DataSource = ds18.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_比對7()
        Dim ds18 As New DataSet : 比對7_dgv.DataSource = Nothing : ds18.Clear()
        比對7_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        比對7_dgv.ColumnHeadersHeight = 25 : 比對7_dgv.AllowUserToAddRows = False : 比對7_dgv.RowTemplate.Height = 25
        SQL_比對7()
        da.Fill(ds18) : 比對7_dgv.DataSource = ds18.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_比對8()
        Dim ds18 As New DataSet : 比對8_dgv.DataSource = Nothing : ds18.Clear()
        比對8_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        比對8_dgv.ColumnHeadersHeight = 25 : 比對8_dgv.AllowUserToAddRows = False : 比對8_dgv.RowTemplate.Height = 25
        SQL_比對8()
        da.Fill(ds18) : 比對8_dgv.DataSource = ds18.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_比對9()
        Dim ds18 As New DataSet : 比對9_dgv.DataSource = Nothing : ds18.Clear()
        比對9_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        比對9_dgv.ColumnHeadersHeight = 25 : 比對9_dgv.AllowUserToAddRows = False : 比對9_dgv.RowTemplate.Height = 25
        SQL_比對9()
        da.Fill(ds18) : 比對9_dgv.DataSource = ds18.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_料號使用()
        Dim ds18 As New DataSet : 料號使用_dgv.DataSource = Nothing : ds18.Clear()
        料號使用_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        料號使用_dgv.ColumnHeadersHeight = 25 : 料號使用_dgv.AllowUserToAddRows = False : 料號使用_dgv.RowTemplate.Height = 25
        SQL_料號使用()
        da.Fill(ds18) : 料號使用_dgv.DataSource = ds18.Tables(0) : conn.Close()
        NUD1.Value = 料號使用_dgv.Rows.Count : NUD2.Value = 0 : NUD3.Value = 0 : NUD4.Value = 0 : NUD5.Value = 0
        For i As Integer = 0 To 料號使用_dgv.Rows.Count - 1
            料號使用_dgv(5, i).Value = ""
            If 料號使用_dgv(1, i).Value.ToString <> "" Or 料號使用_dgv(2, i).Value.ToString <> "" Or
               料號使用_dgv(3, i).Value.ToString <> "" Or 料號使用_dgv(4, i).Value.ToString <> "" Then
                If 料號使用_dgv(1, i).Value.ToString <> "" Then : 料號使用_dgv(5, i).Value = 料號使用_dgv(0, i).Value.ToString
                ElseIf 料號使用_dgv(2, i).Value.ToString <> "" Then : 料號使用_dgv(5, i).Value = 料號使用_dgv(0, i).Value.ToString
                ElseIf 料號使用_dgv(3, i).Value.ToString <> "" Then : 料號使用_dgv(5, i).Value = 料號使用_dgv(0, i).Value.ToString
                ElseIf 料號使用_dgv(4, i).Value.ToString <> "" Then : 料號使用_dgv(5, i).Value = 料號使用_dgv(0, i).Value.ToString : End If
            End If
            If 料號使用_dgv(1, i).Value.ToString <> "" Then : NUD2.Value += 1 : End If
            If 料號使用_dgv(2, i).Value.ToString <> "" Then : NUD3.Value += 1 : End If
            If 料號使用_dgv(3, i).Value.ToString <> "" Then : NUD4.Value += 1 : End If
            If 料號使用_dgv(4, i).Value.ToString <> "" Then : NUD5.Value += 1 : End If
        Next
        If NUD1.Value = 0 Then : PN1.Text = "0 %" : PN2.Text = "0 %" : PN3.Text = "0 %" : PN4.Text = "0 %" : Else
            PN1.Text = CInt(NUD2.Value / NUD1.Value * 100) & " %" : PN2.Text = CInt(NUD3.Value / NUD1.Value * 100) & " %"
            PN3.Text = CInt(NUD4.Value / NUD1.Value * 100) & " %" : PN4.Text = CInt(NUD5.Value / NUD1.Value * 100) & " %"
        End If
    End Sub
    Private Sub Set_清單1()
        Dim ds4, ds5 As New DataSet
        物料編碼_dgv.DataSource = Nothing : ds4.Clear()
        物料編碼_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料編碼_dgv.ColumnHeadersHeight = 25 : 物料編碼_dgv.AllowUserToAddRows = False

        物料編碼_存_dgv.DataSource = Nothing : ds5.Clear()
        物料編碼_存_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料編碼_存_dgv.ColumnHeadersHeight = 25 : 物料編碼_存_dgv.AllowUserToAddRows = False

        If 小間距_ch.Checked = False And 中間距_ch.Checked = False And 大間距_ch.Checked = True Then : 物料編碼_dgv.RowTemplate.Height = 95
        ElseIf 小間距_ch.Checked = False And 中間距_ch.Checked = True And 大間距_ch.Checked = False Then : 物料編碼_dgv.RowTemplate.Height = 75
        ElseIf 小間距_ch.Checked = True And 中間距_ch.Checked = False And 大間距_ch.Checked = False Then : 物料編碼_dgv.RowTemplate.Height = 55 : End If
        If 查詢 = True Then : PA = "%%" : Else : PA = 群組碼1_tb.Text : End If : SQL_物料資料庫_物料編碼庫() : 查詢 = False

        da.Fill(ds4) : 物料編碼_dgv.DataSource = ds4.Tables(0)
        da.Fill(ds5) : 物料編碼_存_dgv.DataSource = ds5.Tables(0) : conn.Close()
        物料編碼_dgv.Columns(0).FillWeight = 50 : 物料編碼_dgv.Columns(1).FillWeight = 160 : 物料編碼_dgv.Columns(2).FillWeight = 350 : 物料編碼_dgv.Columns(7).Visible = False
        物料編碼_dgv.Columns(3).FillWeight = 50 : 物料編碼_dgv.Columns(4).FillWeight = 50 : 物料編碼_dgv.Columns(5).FillWeight = 100 : 物料編碼_dgv.Columns(6).FillWeight = 100
        物料編碼_dgv.Columns("存檔").Visible = False : 物料編碼_dgv.Columns("規格庫編號").Visible = False : 物料編碼_dgv.Columns("規格庫抬頭指定").Visible = False
        物料編碼_dgv.Columns("群組碼").Visible = False
        物料編碼_dgv.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料編碼_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料編碼_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料編碼_dgv.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料編碼_dgv.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料編碼_dgv.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料編碼_dgv.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料編碼_dgv.Columns(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        物料編碼_dgv.Columns(0).ReadOnly = True : 物料編碼_dgv.Columns(1).ReadOnly = True : 物料編碼_dgv.Columns(2).ReadOnly = True
        物料編碼_dgv.Columns(4).ReadOnly = True : 物料編碼_dgv.Columns(4).ReadOnly = True : 物料編碼_dgv.Columns(5).ReadOnly = True
        物料編碼_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        'Dim mycol As DataGridViewImageColumn = 物料編碼_dgv.Columns("Image")
        'mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
        For i As Integer = 0 To 物料編碼_dgv.Rows.Count - 1 : 物料編碼_dgv(0, i).Value = i + 1 : 物料編碼_dgv(4, i).Value = False : 物料編碼_dgv("存檔", i).Value = False : Next
        BL1 = False : Set_清單1_語轉()
    End Sub
    Private Sub Set_清單1_語轉()
        Dim ds4 As New DataSet
        物料品名_語轉_dgv.DataSource = Nothing : ds4.Clear()
        物料品名_語轉_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料品名_語轉_dgv.ColumnHeadersHeight = 25 : 物料品名_語轉_dgv.AllowUserToAddRows = False : 物料品名_語轉_dgv.RowTemplate.Height = 25

        PA = 群組碼1_tb.Text : SQL_物料資料庫_物料編碼庫_語轉()
        da.Fill(ds4) : 物料品名_語轉_dgv.DataSource = ds4.Tables(0) : conn.Close()

        物料品名_語轉_dgv.Columns(0).Visible = False : 物料品名_語轉_dgv.Columns(1).FillWeight = 150
        物料品名_語轉_dgv.Columns(2).FillWeight = 100 : 物料品名_語轉_dgv.Columns(3).FillWeight = 450

        物料品名_語轉_dgv.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

        物料品名_語轉_dgv.Columns(0).ReadOnly = True : 物料品名_語轉_dgv.Columns(1).ReadOnly = True : 物料品名_語轉_dgv.Columns(2).ReadOnly = True
        物料品名_語轉_dgv.Columns(3).ReadOnly = True
    End Sub
    Private Sub Set_物料規格庫()
        Dim ds3 As New DataSet : 規格表頭_dgv.DataSource = Nothing : ds3.Clear()
        規格表頭_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        規格表頭_dgv.ColumnHeadersHeight = 25 : 規格表頭_dgv.AllowUserToAddRows = False

        SQL_規格庫抬頭讀取三()
        da.Fill(ds3) : 規格表頭_dgv.DataSource = ds3.Tables(0) : conn.Close()
        規格表頭_dgv.Columns(0).FillWeight = 150 : 規格表頭_dgv.Columns(1).FillWeight = 143.75 : 規格表頭_dgv.Columns(2).FillWeight = 143.75 : 規格表頭_dgv.Columns(3).FillWeight = 143.75
        規格表頭_dgv.Columns(4).FillWeight = 143.75 : 規格表頭_dgv.Columns(5).FillWeight = 143.75 : 規格表頭_dgv.Columns(6).FillWeight = 143.75 : 規格表頭_dgv.Columns(7).FillWeight = 143.75
        規格表頭_dgv.Columns(8).FillWeight = 143.75 : 規格表頭_dgv.Columns(9).FillWeight = 130

        規格表頭_dgv.Columns(0).ReadOnly = True : 規格表頭_dgv.Columns(1).ReadOnly = True : 規格表頭_dgv.Columns(2).ReadOnly = True
        規格表頭_dgv.Columns(3).ReadOnly = True : 規格表頭_dgv.Columns(4).ReadOnly = True : 規格表頭_dgv.Columns(5).ReadOnly = True
        規格表頭_dgv.Columns(6).ReadOnly = True : 規格表頭_dgv.Columns(7).ReadOnly = True : 規格表頭_dgv.Columns(8).ReadOnly = True
    End Sub
    Private Sub 物料資訊控制表1()
        Dim ds2 As New DataSet : 物料資訊1_dgv.DataSource = Nothing : ds2.Clear()
        物料資訊1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料資訊1_dgv.ColumnHeadersHeight = 25 : 物料資訊1_dgv.AllowUserToAddRows = False

        If 小間距2_ch.Checked = False And 中間距2_ch.Checked = False And 大間距2_ch.Checked = True Then : 物料資訊1_dgv.RowTemplate.Height = 55
        ElseIf 小間距2_ch.Checked = False And 中間距2_ch.Checked = True And 大間距2_ch.Checked = False Then : 物料資訊1_dgv.RowTemplate.Height = 40
        ElseIf 小間距2_ch.Checked = True And 中間距2_ch.Checked = False And 大間距2_ch.Checked = False Then : 物料資訊1_dgv.RowTemplate.Height = 25 : End If

        PA = 規格庫抬頭指定_tb.Text : SQL_物料資料庫_物料資訊控制表() : PA = ""
        da.Fill(ds2) : 物料資訊1_dgv.DataSource = ds2.Tables(0) : conn.Close()
        物料資訊1_dgv.Columns(0).Visible = False : 物料資訊1_dgv.Columns(1).FillWeight = 80 : 物料資訊1_dgv.Columns(2).FillWeight = 166
        物料資訊1_dgv.Columns(3).FillWeight = 60 : 物料資訊1_dgv.Columns(4).FillWeight = 60 : 物料資訊1_dgv.Columns(7).FillWeight = 60
        物料資訊1_dgv.Columns(5).Visible = False : 物料資訊1_dgv.Columns(6).Visible = False
        物料資訊1_dgv.Columns(0).ReadOnly = True : 物料資訊1_dgv.Columns(1).ReadOnly = True : 物料資訊1_dgv.Columns(2).ReadOnly = True
        物料資訊1_dgv.Columns(3).ReadOnly = True : 物料資訊1_dgv.Columns(4).ReadOnly = True : 物料資訊1_dgv.Columns(5).ReadOnly = True

        Dim mycol As DataGridViewImageColumn = 物料資訊1_dgv.Columns("Image")
        mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
    End Sub
    Private Sub 物料資訊控制表2()
        Dim ds6 As New DataSet : 物料資訊2_dgv.DataSource = Nothing : ds6.Clear()
        物料資訊2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料資訊2_dgv.ColumnHeadersHeight = 25 : 物料資訊2_dgv.AllowUserToAddRows = False

        If 小間距3_ch.Checked = False And 中間距3_ch.Checked = False And 大間距3_ch.Checked = True Then : 物料資訊2_dgv.RowTemplate.Height = 55
        ElseIf 小間距3_ch.Checked = False And 中間距3_ch.Checked = True And 大間距3_ch.Checked = False Then : 物料資訊2_dgv.RowTemplate.Height = 40
        ElseIf 小間距3_ch.Checked = True And 中間距3_ch.Checked = False And 大間距3_ch.Checked = False Then : 物料資訊2_dgv.RowTemplate.Height = 25 : End If

        PA = 規格庫抬頭指定_tb.Text : SQL_物料資料庫_物料資訊控制表() : PA = ""
        da.Fill(ds6) : 物料資訊2_dgv.DataSource = ds6.Tables(0) : conn.Close()
        物料資訊2_dgv.Columns(0).Visible = False : 物料資訊2_dgv.Columns(1).FillWeight = 80 : 物料資訊2_dgv.Columns(2).FillWeight = 166
        物料資訊2_dgv.Columns(3).FillWeight = 60 : 物料資訊2_dgv.Columns(4).FillWeight = 60 : 物料資訊2_dgv.Columns(7).FillWeight = 60
        物料資訊2_dgv.Columns(5).Visible = False : 物料資訊2_dgv.Columns(6).Visible = False
        物料資訊2_dgv.Columns(0).ReadOnly = True : 物料資訊2_dgv.Columns(1).ReadOnly = True : 物料資訊2_dgv.Columns(2).ReadOnly = True
        物料資訊2_dgv.Columns(3).ReadOnly = True : 物料資訊2_dgv.Columns(4).ReadOnly = True : 物料資訊2_dgv.Columns(5).ReadOnly = True

        Dim mycol As DataGridViewImageColumn = 物料資訊2_dgv.Columns("Image")
        mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
    End Sub
    Private Sub 物料資訊控制表3()
        Dim ds15 As New DataSet : 物料資訊3_dgv.DataSource = Nothing : ds15.Clear()
        物料資訊3_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料資訊3_dgv.ColumnHeadersHeight = 25 : 物料資訊3_dgv.AllowUserToAddRows = False

        If 小間距4_ch.Checked = False And 中間距4_ch.Checked = False And 大間距4_ch.Checked = True Then : 物料資訊3_dgv.RowTemplate.Height = 55
        ElseIf 小間距4_ch.Checked = False And 中間距4_ch.Checked = True And 大間距4_ch.Checked = False Then : 物料資訊3_dgv.RowTemplate.Height = 40
        ElseIf 小間距4_ch.Checked = True And 中間距4_ch.Checked = False And 大間距4_ch.Checked = False Then : 物料資訊3_dgv.RowTemplate.Height = 25 : End If

        PA = 規格庫抬頭指定_tb.Text : SQL_物料資料庫_物料資訊控制表() : PA = ""
        da.Fill(ds15) : 物料資訊3_dgv.DataSource = ds15.Tables(0) : conn.Close()
        物料資訊3_dgv.Columns(0).Visible = False : 物料資訊3_dgv.Columns(1).FillWeight = 80 : 物料資訊3_dgv.Columns(2).FillWeight = 166
        物料資訊3_dgv.Columns(3).FillWeight = 60 : 物料資訊3_dgv.Columns(4).FillWeight = 60 : 物料資訊3_dgv.Columns(7).FillWeight = 60
        物料資訊3_dgv.Columns(5).FillWeight = 40 : 物料資訊3_dgv.Columns(6).FillWeight = 80
        物料資訊3_dgv.Columns(0).ReadOnly = True : 物料資訊3_dgv.Columns(1).ReadOnly = True : 物料資訊3_dgv.Columns(2).ReadOnly = True
        物料資訊3_dgv.Columns(3).ReadOnly = True : 物料資訊3_dgv.Columns(4).ReadOnly = True : 物料資訊3_dgv.Columns(5).ReadOnly = True

        Dim mycol As DataGridViewImageColumn = 物料資訊3_dgv.Columns("Image")
        mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
    End Sub
    Private Sub 物料資訊控制表4()
        Dim ds15 As New DataSet : 物料資訊4_dgv.DataSource = Nothing : ds15.Clear()
        物料資訊4_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料資訊4_dgv.ColumnHeadersHeight = 25 : 物料資訊4_dgv.AllowUserToAddRows = False

        If 小間距5_ch.Checked = False And 中間距5_ch.Checked = False And 大間距5_ch.Checked = True Then : 物料資訊4_dgv.RowTemplate.Height = 55
        ElseIf 小間距5_ch.Checked = False And 中間距5_ch.Checked = True And 大間距5_ch.Checked = False Then : 物料資訊4_dgv.RowTemplate.Height = 40
        ElseIf 小間距5_ch.Checked = True And 中間距5_ch.Checked = False And 大間距5_ch.Checked = False Then : 物料資訊4_dgv.RowTemplate.Height = 25 : End If

        PA = 規格庫抬頭指定_tb.Text : SQL_物料資料庫_物料資訊控制表() : PA = ""
        da.Fill(ds15) : 物料資訊4_dgv.DataSource = ds15.Tables(0) : conn.Close()
        物料資訊4_dgv.Columns(0).Visible = False : 物料資訊4_dgv.Columns(1).FillWeight = 80 : 物料資訊4_dgv.Columns(2).FillWeight = 166
        物料資訊4_dgv.Columns(3).FillWeight = 60 : 物料資訊4_dgv.Columns(4).FillWeight = 60 : 物料資訊4_dgv.Columns(7).FillWeight = 60
        物料資訊4_dgv.Columns(5).FillWeight = 40 : 物料資訊4_dgv.Columns(6).FillWeight = 80
        物料資訊4_dgv.Columns(0).ReadOnly = True : 物料資訊4_dgv.Columns(1).ReadOnly = True : 物料資訊4_dgv.Columns(2).ReadOnly = True
        物料資訊4_dgv.Columns(3).ReadOnly = True : 物料資訊4_dgv.Columns(4).ReadOnly = True : 物料資訊4_dgv.Columns(5).ReadOnly = True

        Dim mycol As DataGridViewImageColumn = 物料資訊4_dgv.Columns("Image")
        mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
    End Sub
    Private Sub Set_物料資訊控制表未新增()
        Dim ds10 As New DataSet : 未指定表頭_dgv.DataSource = Nothing : ds10.Clear()
        未指定表頭_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        未指定表頭_dgv.ColumnHeadersHeight = 25 : 未指定表頭_dgv.AllowUserToAddRows = False

        SQL_物料資料庫_物料資訊控制表未新增()
        da.Fill(ds10) : 未指定表頭_dgv.DataSource = ds10.Tables(0) : conn.Close()
        未指定表頭_dgv.Columns(0).FillWeight = 150 : 未指定表頭_dgv.Columns(1).FillWeight = 150 : 未指定表頭_dgv.Columns(2).FillWeight = 450
        未指定表頭_dgv.Columns(3).Visible = False : 未指定表頭_dgv.Columns(4).Visible = False

        未指定表頭_dgv.Columns(0).ReadOnly = True : 未指定表頭_dgv.Columns(1).ReadOnly = True : 未指定表頭_dgv.Columns(2).ReadOnly = True
    End Sub
    Private Sub 語言轉換讀取()
        ToolTip1.ToolTipTitle = "功能說明"
    End Sub
    Private Sub 修改物料資訊_bt_MouseEnter(sender As Object, e As EventArgs) Handles 修改物料資訊_bt.MouseEnter
        ToolTip1.SetToolTip(Me.修改物料資訊_bt, "修改物料資訊")
    End Sub
    Private Sub 圖片修改1_bt_MouseEnter(sender As Object, e As EventArgs) Handles 圖片修改1_bt.MouseEnter
        ToolTip1.SetToolTip(Me.圖片修改1_bt, "圖片修改")
    End Sub
    Private Sub 圖片修改_bt_MouseEnter(sender As Object, e As EventArgs) Handles 圖片修改_bt.MouseEnter
        ToolTip1.SetToolTip(Me.圖片修改_bt, "圖片修改")
    End Sub
    Private Sub 讀取料夾路徑1_bt_MouseEnter(sender As Object, e As EventArgs) Handles 讀取料夾路徑1_bt.MouseEnter
        ToolTip1.SetToolTip(Me.讀取料夾路徑1_bt, "讀取料夾路徑")
    End Sub
    Private Sub 讀取料夾路徑_bt_MouseEnter(sender As Object, e As EventArgs) Handles 讀取料夾路徑_bt.MouseEnter
        ToolTip1.SetToolTip(Me.讀取料夾路徑_bt, "讀取料夾路徑")
    End Sub
    Private Sub 下載圖片_bt_MouseEnter(sender As Object, e As EventArgs) Handles 下載圖片_bt.MouseEnter
        ToolTip1.SetToolTip(Me.下載圖片_bt, "下載圖片")
    End Sub
    Private Sub 下載圖片1_bt_MouseEnter(sender As Object, e As EventArgs) Handles 下載圖片1_bt.MouseEnter
        ToolTip1.SetToolTip(Me.下載圖片1_bt, "下載圖片")
    End Sub
    Private Sub 刪除物料資訊_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除物料資訊_bt.MouseEnter
        ToolTip1.SetToolTip(Me.刪除物料資訊_bt, "刪除物料資訊")
    End Sub
    Private Sub 刪除料號_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除料號_bt.MouseEnter
        ToolTip1.SetToolTip(Me.刪除料號_bt, "刪除料號")
    End Sub
    Private Sub 刪除圖檔_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除圖檔_bt.MouseEnter
        ToolTip1.SetToolTip(Me.刪除圖檔_bt, "刪除圖檔")
    End Sub
    Private Sub 物料原則刪除_tb_MouseEnter(sender As Object, e As EventArgs) Handles 物料原則刪除_tb.MouseEnter
        ToolTip1.SetToolTip(Me.物料原則刪除_tb, "物料原則刪除")
    End Sub
    Private Sub 物料原則新增_tb_MouseEnter(sender As Object, e As EventArgs) Handles 物料原則新增_tb.MouseEnter
        ToolTip1.SetToolTip(Me.物料原則新增_tb, "物料原則新增")
    End Sub
    Private Sub 修改物料規格_存量存檔_bt_MouseEnter(sender As Object, e As EventArgs) Handles 修改物料規格_存量存檔_bt.MouseEnter
        ToolTip1.SetToolTip(Me.修改物料規格_存量存檔_bt, "修改物料規格批量存檔")
    End Sub
    Private Sub 修改品名後存檔_bt_MouseEnter(sender As Object, e As EventArgs) Handles 修改品名後存檔_bt.MouseEnter
        ToolTip1.SetToolTip(Me.修改品名後存檔_bt, "修改品名後存檔")
    End Sub
    Private Sub 規格表頭刪除_tb_MouseEnter(sender As Object, e As EventArgs) Handles 規格表頭刪除_tb.MouseEnter
        ToolTip1.SetToolTip(Me.規格表頭刪除_tb, "規格表頭刪除")
    End Sub
    Private Sub 規格表頭修改_tb_MouseEnter(sender As Object, e As EventArgs) Handles 規格表頭修改_tb.MouseEnter
        ToolTip1.SetToolTip(Me.規格表頭修改_tb, "規格表頭修改")
    End Sub
    Private Sub 規格表頭新增_tb_MouseEnter(sender As Object, e As EventArgs) Handles 規格表頭新增_tb.MouseEnter
        ToolTip1.SetToolTip(Me.規格表頭新增_tb, "規格表頭新增")
    End Sub
    Private Sub 新增物料料號_bt_MouseEnter(sender As Object, e As EventArgs) Handles 新增物料料號_bt.MouseEnter
        ToolTip1.SetToolTip(Me.新增物料料號_bt, "新增物料料號")
    End Sub
    Private Sub 新增物料資訊_bt_MouseEnter(sender As Object, e As EventArgs) Handles 新增物料資訊_bt.MouseEnter
        ToolTip1.SetToolTip(Me.新增物料資訊_bt, "新增物料資訊")
    End Sub
    Private Sub 群組刪除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 群組刪除_bt.MouseEnter
        ToolTip1.SetToolTip(Me.群組刪除_bt, "群組刪除")
    End Sub
    Private Sub 群組修改_bt_MouseEnter(sender As Object, e As EventArgs) Handles 群組修改_bt.MouseEnter
        ToolTip1.SetToolTip(Me.群組修改_bt, "群組修改")
    End Sub
    Private Sub 群組新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 群組新增_bt.MouseEnter
        ToolTip1.SetToolTip(Me.群組新增_bt, "群組新增")
    End Sub
    Private Sub 圖檔入系統_bt_MouseEnter(sender As Object, e As EventArgs) Handles 圖檔入系統_bt.MouseEnter
        ToolTip1.SetToolTip(Me.圖檔入系統_bt, "圖檔入系統")
    End Sub
    Private Sub 圖檔入系統1_bt_MouseEnter(sender As Object, e As EventArgs) Handles 圖檔入系統1_bt.MouseEnter
        ToolTip1.SetToolTip(Me.圖檔入系統1_bt, "圖檔入系統")
    End Sub
    Private Sub 轉換_bt_MouseEnter(sender As Object, e As EventArgs) Handles 關鍵字查詢_bt.MouseEnter
        ToolTip1.SetToolTip(Me.關鍵字查詢_bt, "關鍵字查詢")
    End Sub
    Private Sub 翻譯_bt_MouseEnter(sender As Object, e As EventArgs) Handles 翻譯_bt.MouseEnter
        ToolTip1.SetToolTip(Me.翻譯_bt, "翻譯")
    End Sub
    Private Sub 規格庫抬頭指定_cb_下拉表單資料載入()
        SQL_物料資訊控制表_規格庫抬頭指定() : 規格庫抬頭指定_cb.Items.Clear() : 規格庫抬頭指定1_cb.Items.Clear() : 規格庫抬頭指定2_cb.Items.Clear()
        規格庫抬頭指定3_cb.Items.Clear() : 規格庫抬頭指定4_cb.Items.Clear() : 規格庫抬頭指定5_cb.Items.Clear()
        While (dr.Read())
            規格庫抬頭指定_cb.Items.Add(dr("規格庫抬頭指定")) : 規格庫抬頭指定2_cb.Items.Add(dr("規格庫抬頭指定")) : 規格庫抬頭指定1_cb.Items.Add(dr("規格庫抬頭指定"))
            規格庫抬頭指定3_cb.Items.Add(dr("規格庫抬頭指定")) : 規格庫抬頭指定4_cb.Items.Add(dr("規格庫抬頭指定")) : 規格庫抬頭指定5_cb.Items.Add(dr("規格庫抬頭指定"))
        End While : conn.Close()
    End Sub
    Private Sub 群組碼_cb_下拉表單資料載入()
        SQL_群組碼_下拉清單() : 舊群組_cb.Items.Clear() : 新群組_cb.Items.Clear()
        While (dr.Read()) : 舊群組_cb.Items.Add(dr("群組碼")) : 新群組_cb.Items.Add(dr("群組碼")) : End While : conn.Close()
    End Sub
    Private Sub 群組碼_cb_語轉_下拉表單資料載入()
        SQL_群組碼_語轉_下拉清單() : 舊群組1_cb.Items.Clear() : 新群組1_cb.Items.Clear()
        While (dr.Read()) : 舊群組1_cb.Items.Add(dr("群組")) : 新群組1_cb.Items.Add(dr("群組")) : End While : conn.Close()
    End Sub
    Private Sub 新群組碼1()
        DA_1.Items.Clear() : DB_1.Items.Clear() : DC_1.Items.Clear()
        PA30 = "繁體中文" : SQL_新物料群組下拉1() : While (dr.Read()) : DA_1.Items.Add(dr("第一層")) : End While : conn.Close()
        PA30 = "English" : SQL_新物料群組下拉1() : While (dr.Read()) : DB_1.Items.Add(dr("第一層")) : End While : conn.Close()
        PA30 = "Indonesian" : SQL_新物料群組下拉1() : While (dr.Read()) : DC_1.Items.Add(dr("第一層")) : End While : conn.Close()
    End Sub
    Private Sub 新群組碼2()
        DA_2.Items.Clear() : DB_2.Items.Clear() : DC_2.Items.Clear() : DA_2.Text = "" : DB_2.Text = "" : DC_2.Text = ""
        PA30 = "繁體中文"
        If CA_1.Text <> "" Then : PA31 = CA_1.Text : Else : PA31 = DA_1.Text : End If
        SQL_新物料群組下拉2() : While (dr.Read()) : DA_2.Items.Add(dr("第二層")) : End While : conn.Close()
        PA30 = "English"
        If CB_1.Text <> "" Then : PA31 = CB_1.Text : Else : PA31 = DB_1.Text : End If
        SQL_新物料群組下拉2() : While (dr.Read()) : DB_2.Items.Add(dr("第二層")) : End While : conn.Close()
        PA30 = "Indonesian"
        If CC_1.Text <> "" Then : PA31 = CC_1.Text : Else : PA31 = DC_1.Text : End If
        SQL_新物料群組下拉2() : While (dr.Read()) : DC_2.Items.Add(dr("第二層")) : End While : conn.Close()
    End Sub
    Private Sub 新群組碼3()
        DA_3.Items.Clear() : DB_3.Items.Clear() : DC_3.Items.Clear() : DA_3.Text = "" : DB_3.Text = "" : DC_3.Text = ""
        PA30 = "繁體中文"
        If CA_1.Text <> "" Then : PA31 = CA_1.Text : Else : PA31 = DA_1.Text : End If : If CA_2.Text <> "" Then : PA32 = CA_2.Text : Else : PA32 = DA_2.Text : End If
        SQL_新物料群組下拉3() : While (dr.Read()) : DA_3.Items.Add(dr("第三層")) : End While : conn.Close()
        PA30 = "English"
        If CB_1.Text <> "" Then : PA31 = CB_1.Text : Else : PA31 = DB_1.Text : End If : If CB_2.Text <> "" Then : PA32 = CB_2.Text : Else : PA32 = DB_2.Text : End If
        SQL_新物料群組下拉3() : While (dr.Read()) : DB_3.Items.Add(dr("第三層")) : End While : conn.Close()
        PA30 = "Indonesian"
        If CC_1.Text <> "" Then : PA31 = CC_1.Text : Else : PA31 = DC_1.Text : End If : If CC_2.Text <> "" Then : PA32 = CC_2.Text : Else : PA32 = DC_2.Text : End If
        SQL_新物料群組下拉3() : While (dr.Read()) : DC_3.Items.Add(dr("第三層")) : End While : conn.Close()
    End Sub
    Private Sub 新群組碼4()
        DA_4.Items.Clear() : DB_4.Items.Clear() : DC_4.Items.Clear() : DA_4.Text = "" : DB_4.Text = "" : DC_4.Text = ""
        PA30 = "繁體中文"
        If CA_1.Text <> "" Then : PA31 = CA_1.Text : Else : PA31 = DA_1.Text : End If : If CA_2.Text <> "" Then : PA32 = CA_2.Text : Else : PA32 = DA_2.Text : End If
        If CA_3.Text <> "" Then : PA33 = CA_3.Text : Else : PA33 = DA_3.Text : End If
        SQL_新物料群組下拉4() : While (dr.Read()) : DA_4.Items.Add(dr("第四層")) : End While : conn.Close()
        PA30 = "English"
        If CB_1.Text <> "" Then : PA31 = CB_1.Text : Else : PA31 = DB_1.Text : End If : If CB_2.Text <> "" Then : PA32 = CB_2.Text : Else : PA32 = DB_2.Text : End If
        If CB_3.Text <> "" Then : PA33 = CB_3.Text : Else : PA33 = DB_3.Text : End If
        SQL_新物料群組下拉4() : While (dr.Read()) : DB_4.Items.Add(dr("第四層")) : End While : conn.Close()
        PA30 = "Indonesian"
        If CC_1.Text <> "" Then : PA31 = CC_1.Text : Else : PA31 = DC_1.Text : End If : If CC_2.Text <> "" Then : PA32 = CC_2.Text : Else : PA32 = DC_2.Text : End If
        If CC_3.Text <> "" Then : PA33 = CC_3.Text : Else : PA33 = DC_3.Text : End If
        SQL_新物料群組下拉4() : While (dr.Read()) : DC_4.Items.Add(dr("第四層")) : End While : conn.Close()
    End Sub
    Private Sub 新群組碼5()
        DA_5.Items.Clear() : DB_5.Items.Clear() : DC_5.Items.Clear() : DA_5.Text = "" : DB_5.Text = "" : DC_5.Text = ""
        PA30 = "繁體中文"
        If CA_1.Text <> "" Then : PA31 = CA_1.Text : Else : PA31 = DA_1.Text : End If : If CA_2.Text <> "" Then : PA32 = CA_2.Text : Else : PA32 = DA_2.Text : End If
        If CA_3.Text <> "" Then : PA33 = CA_3.Text : Else : PA33 = DA_3.Text : End If : If CA_4.Text <> "" Then : PA34 = CA_4.Text : Else : PA34 = DA_4.Text : End If
        SQL_新物料群組下拉5() : While (dr.Read()) : DA_5.Items.Add(dr("第五層")) : End While : conn.Close()
        PA30 = "English"
        If CB_1.Text <> "" Then : PA31 = CB_1.Text : Else : PA31 = DB_1.Text : End If : If CB_2.Text <> "" Then : PA32 = CB_2.Text : Else : PA32 = DB_2.Text : End If
        If CB_3.Text <> "" Then : PA33 = CB_3.Text : Else : PA33 = DB_3.Text : End If : If CB_4.Text <> "" Then : PA34 = CB_4.Text : Else : PA34 = DB_4.Text : End If
        SQL_新物料群組下拉5() : While (dr.Read()) : DB_5.Items.Add(dr("第五層")) : End While : conn.Close()
        PA30 = "Indonesian"
        If CC_1.Text <> "" Then : PA31 = CC_1.Text : Else : PA31 = DC_1.Text : End If : If CC_2.Text <> "" Then : PA32 = CC_2.Text : Else : PA32 = DC_2.Text : End If
        If CC_3.Text <> "" Then : PA33 = CC_3.Text : Else : PA33 = DC_3.Text : End If : If CC_4.Text <> "" Then : PA34 = CC_4.Text : Else : PA34 = DC_4.Text : End If
        SQL_新物料群組下拉5() : While (dr.Read()) : DC_5.Items.Add(dr("第五層")) : End While : conn.Close()
    End Sub
    Private Sub 物料資料庫_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FH_ERP_SYS.WindowState = 2 : Me.MdiParent = FH_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        小間距_ch.Checked = True : 中間距2_ch.Checked = True : 中間距3_ch.Checked = True : 中間距4_ch.Checked = True : 物料群組1_P.Visible = False : 物料群組2_P.Visible = False
        物料品名_語轉_dgv.Visible = False : 中間距5_ch.Checked = True : 群組碼_tb.Enabled = False : 首次開啟 = True : Panel3.SendToBack() : 語言轉換讀取()
        規格表頭_P.Visible = False : Panel1.SendToBack()

        物料群組_語言_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 物料群組_語言2_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        物料群組_語言3_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 物料群組_語言4_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        物料群組_語言5_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 物料品名_語轉_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        物料編碼_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 規格表頭_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        未指定表頭_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)

        物料資訊1_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 物料資訊4_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        物料資訊2_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 物料資訊3_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)

        物料明細1_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 物料明細2_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        物料明細3_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 物料資訊3_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        物料明細4_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 物料明細5_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)

        比對1_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 比對2_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        比對3_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 比對4_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        比對5_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 比對6_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        比對7_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 比對8_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
        比對9_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6) : 料號使用_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 7.6)
    End Sub
    Private Sub 物料資料庫_Size()
        If 首次開啟 = False Then
            Dim currentSize As Size = Me.Size : Dim width As Integer = currentSize.Width : Dim height As Integer = currentSize.Height
            If currentSize.Width < 1900 And currentSize.Height < 950 Then
                檔案區_P.Visible = False : 變更群組_P.Visible = False : 物料新群駔_P.Visible = False : 物料規格批量複製_P.Visible = False : SYSTEM_P.Visible = False
                報價用規格呈現控制_P.Visible = False : 物料檔案快速拷貝_P.Visible = False
            Else
                檔案區_P.Visible = True : 變更群組_P.Visible = True : 物料新群駔_P.Visible = True : 物料規格批量複製_P.Visible = True : SYSTEM_P.Visible = True
                報價用規格呈現控制_P.Visible = True : 物料檔案快速拷貝_P.Visible = True
            End If
            ' 調整 SplitContainer4 的分割位置以保持比例
            SplitContainer4.SplitterDistance = CInt(SplitContainer4.Width * (SplitContainer4.SplitterDistance / (SplitContainer4.Width - SplitContainer4.SplitterWidth)))
            ' 確保 SplitContainer5 的第一個面板保持初始寬度
            SplitContainer5.SplitterDistance = initialPanel1Width
        End If
    End Sub
    Private Sub 物料資料庫_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        物料資料庫_Size()
    End Sub
    Private Sub 物料資料庫_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        計算分流.Enabled = True
        If 登入人級別 = "00" Then : 修改料號權限_ch.Checked = True : 編碼_tb.Enabled = True
        Else : 修改料號權限_ch.Checked = False : 編碼_tb.Enabled = False : End If
        本機_wb.Navigate(My.Computer.FileSystem.SpecialDirectories.Desktop)
        本機1_wb.Navigate(My.Computer.FileSystem.SpecialDirectories.Desktop)
        initialPanel1Width = SplitContainer5.Panel1.Width : 首次開啟 = False : 物料資料庫_Size()
    End Sub
    Private Sub 計算分流_Tick(sender As Object, e As EventArgs) Handles 計算分流.Tick
        計算分流.Enabled = False
        Set_比對1() : Set_比對2() : Set_比對3() : Set_比對4() : Set_比對5() : Set_比對6() : Set_比對7() : Set_比對8() : Set_比對9() : Set_料號使用()
        規格庫抬頭指定_cb_下拉表單資料載入() : Set_群組清單() : Set_新群組清單() : 新群組碼1() : Set_物料規格庫() : Set_物料資訊控制表未新增() : 群組碼_cb_語轉_下拉表單資料載入()
    End Sub
    Private Sub 物料資料庫_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
        SQL_物料資料庫_修正1()
    End Sub
    Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
        timeNow = 0 : FH_ERP_SYS.Timer1.Enabled = False : FH_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
        timeNow = 0 : FH_ERP_SYS.Timer1.Enabled = False : FH_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 讀取料號規格_01()
        SQL_物料資訊控制表_原則查詢()
        If dr.Read() Then
            KKK2 = dr("規格庫編號") : PA = KKK2 : KKK3 = dr("規格庫抬頭指定") : PA3 = KKK3 : KKK4 = dr("群組碼") : PA1 = KKK4
        End If : conn.Close()

        SQL_規格庫抬頭讀取()
        If dr.Read() Then
            AAA1 = dr("A1") : PA4 = dr("A1") : AAA2 = dr("A2") : PA5 = dr("A2") : AAA3 = dr("A3") : PA6 = dr("A3") : AAA4 = dr("A4") : PA7 = dr("A4")
            AAA5 = dr("A5") : PA8 = dr("A5") : AAA6 = dr("A6") : PA9 = dr("A6") : AAA7 = dr("A7") : PA10 = dr("A7") : AAA8 = dr("A8") : PA11 = dr("A8")
        End If : conn.Close()
    End Sub
    Private Sub 讀取料號規格_02()
        Dim ds3 As New DataSet
        物料明細1_dgv.DataSource = Nothing : ds3.Clear()
        物料明細1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料明細1_dgv.ColumnHeadersHeight = 25 : 物料明細1_dgv.AllowUserToAddRows = False

        If 小間距1_ch.Checked = False And 中間距1_ch.Checked = False And 大間距1_ch.Checked = True Then : 物料明細1_dgv.RowTemplate.Height = 75
        ElseIf 小間距1_ch.Checked = False And 中間距1_ch.Checked = True And 大間距1_ch.Checked = False Then : 物料明細1_dgv.RowTemplate.Height = 50
        ElseIf 小間距1_ch.Checked = True And 中間距1_ch.Checked = False And 大間距1_ch.Checked = False Then : 物料明細1_dgv.RowTemplate.Height = 30 : End If

        SQL_物料規格表_物料清單()
        da.Fill(ds3) : 物料明細1_dgv.DataSource = ds3.Tables(0) : conn.Close()

        If PartNo_ch.Checked = False Then : 物料明細1_dgv.Columns(2).Visible = False : Else : 物料明細1_dgv.Columns(2).Visible = True : End If
        If 兩碼_ch.Checked = True Then : 物料明細1_dgv.Columns(2).Width = 90 : Else : 物料明細1_dgv.Columns(2).Width = 40 : End If

        物料明細1_dgv.Columns(0).Visible = False : 物料明細1_dgv.Columns(1).Visible = False : 物料明細1_dgv.Columns(3).Visible = False : 物料明細1_dgv.Columns(23).Visible = False
        物料明細1_dgv.Columns(12).FillWeight = 70 : 物料明細1_dgv.Columns(13).Visible = False : 物料明細1_dgv.Columns(14).FillWeight = 70 : 物料明細1_dgv.Columns(22).Visible = False
        物料明細1_dgv.Columns(15).FillWeight = 40 : 物料明細1_dgv.Columns(16).Visible = False : 物料明細1_dgv.Columns(17).Visible = False : 物料明細1_dgv.Columns(18).Visible = False
        物料明細1_dgv.Columns(19).Visible = False : 物料明細1_dgv.Columns(20).Visible = False : 物料明細1_dgv.Columns(21).Visible = False

        物料明細1_dgv.EditMode = DataGridViewEditMode.EditOnEnter : 物料明細1_dgv.Columns(2).ReadOnly = True

        物料明細1_dgv.Columns(12).DefaultCellStyle.Format = "#,##0" : 物料明細1_dgv.Columns(14).DefaultCellStyle.Format = "#,##0"
        物料明細1_dgv.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細1_dgv.Columns(14).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細1_dgv.Columns(12).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細1_dgv.Columns(14).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        If KKK2 = "SQLB03" Then
            物料明細1_dgv.Columns(7).Visible = False : 物料明細1_dgv.Columns(8).Visible = False : 物料明細1_dgv.Columns(9).Visible = False : 物料明細1_dgv.Columns(10).Visible = False
            物料明細1_dgv.Columns(11).Visible = False
            物料明細1_dgv.Columns(4).FillWeight = 213 : 物料明細1_dgv.Columns(5).FillWeight = 213 : 物料明細1_dgv.Columns(6).FillWeight = 214
        ElseIf KKK2 = "SQLB04" Then
            物料明細1_dgv.Columns(7).Visible = True : 物料明細1_dgv.Columns(8).Visible = False : 物料明細1_dgv.Columns(9).Visible = False : 物料明細1_dgv.Columns(10).Visible = False
            物料明細1_dgv.Columns(11).Visible = False
            物料明細1_dgv.Columns(4).FillWeight = 160 : 物料明細1_dgv.Columns(5).FillWeight = 160 : 物料明細1_dgv.Columns(6).FillWeight = 160 : 物料明細1_dgv.Columns(7).FillWeight = 160
        ElseIf KKK2 = "SQLB05" Then
            物料明細1_dgv.Columns(7).Visible = True : 物料明細1_dgv.Columns(8).Visible = True : 物料明細1_dgv.Columns(9).Visible = False : 物料明細1_dgv.Columns(10).Visible = False
            物料明細1_dgv.Columns(11).Visible = False
            物料明細1_dgv.Columns(4).FillWeight = 128 : 物料明細1_dgv.Columns(5).FillWeight = 128 : 物料明細1_dgv.Columns(6).FillWeight = 128 : 物料明細1_dgv.Columns(7).FillWeight = 128
            物料明細1_dgv.Columns(8).FillWeight = 128
        ElseIf KKK2 = "SQLB06" Then
            If 規格庫抬頭指定2_cb.Text = "HE06-03" Then
                物料明細1_dgv.Columns(7).Visible = True : 物料明細1_dgv.Columns(8).Visible = True : 物料明細1_dgv.Columns(9).Visible = True : 物料明細1_dgv.Columns(10).Visible = False
                物料明細1_dgv.Columns(11).Visible = False
                物料明細1_dgv.Columns(4).FillWeight = 106 : 物料明細1_dgv.Columns(5).FillWeight = 107 : 物料明細1_dgv.Columns(6).FillWeight = 106 : 物料明細1_dgv.Columns(7).FillWeight = 107
                物料明細1_dgv.Columns(8).FillWeight = 300 : 物料明細1_dgv.Columns(9).FillWeight = 108
            Else
                物料明細1_dgv.Columns(7).Visible = True : 物料明細1_dgv.Columns(8).Visible = True : 物料明細1_dgv.Columns(9).Visible = True : 物料明細1_dgv.Columns(10).Visible = False
                物料明細1_dgv.Columns(11).Visible = False
                物料明細1_dgv.Columns(4).FillWeight = 106 : 物料明細1_dgv.Columns(5).FillWeight = 107 : 物料明細1_dgv.Columns(6).FillWeight = 106 : 物料明細1_dgv.Columns(7).FillWeight = 107
                物料明細1_dgv.Columns(8).FillWeight = 106 : 物料明細1_dgv.Columns(9).FillWeight = 108
            End If
        ElseIf KKK2 = "SQLB07" Then
            物料明細1_dgv.Columns(7).Visible = True : 物料明細1_dgv.Columns(8).Visible = True : 物料明細1_dgv.Columns(9).Visible = True : 物料明細1_dgv.Columns(10).Visible = True
            物料明細1_dgv.Columns(11).Visible = False
            物料明細1_dgv.Columns(4).FillWeight = 91 : 物料明細1_dgv.Columns(5).FillWeight = 92 : 物料明細1_dgv.Columns(6).FillWeight = 91 : 物料明細1_dgv.Columns(7).FillWeight = 92
            物料明細1_dgv.Columns(8).FillWeight = 91 : 物料明細1_dgv.Columns(9).FillWeight = 92 : 物料明細1_dgv.Columns(10).FillWeight = 91
        ElseIf KKK2 = "SQLB08" Then
            物料明細1_dgv.Columns(7).Visible = True : 物料明細1_dgv.Columns(8).Visible = True : 物料明細1_dgv.Columns(9).Visible = True : 物料明細1_dgv.Columns(10).Visible = True
            物料明細1_dgv.Columns(11).Visible = True
            物料明細1_dgv.Columns(4).FillWeight = 80 : 物料明細1_dgv.Columns(5).FillWeight = 80 : 物料明細1_dgv.Columns(6).FillWeight = 80 : 物料明細1_dgv.Columns(7).FillWeight = 80
            物料明細1_dgv.Columns(8).FillWeight = 80 : 物料明細1_dgv.Columns(9).FillWeight = 80 : 物料明細1_dgv.Columns(10).FillWeight = 80 : 物料明細1_dgv.Columns(11).FillWeight = 80
        End If
        For I As Integer = 0 To 物料明細1_dgv.Rows.Count - 1 : 物料明細1_dgv(15, I).Value = I + 1 : Next
    End Sub
    Private Sub 讀取料號規格_03()
        If 物料明細3_dgv.Columns.Count.ToString > 16 Then : 物料明細3_dgv.Columns.Remove("選擇") : End If

        Dim ds3 As New DataSet
        物料明細3_dgv.DataSource = Nothing : ds3.Clear()
        物料明細3_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料明細3_dgv.ColumnHeadersHeight = 25 : 物料明細3_dgv.AllowUserToAddRows = False

        SQL_物料規格表_物料清單()
        da.Fill(ds3) : 物料明細3_dgv.DataSource = ds3.Tables(0) : conn.Close()

        Dim Col As New DataGridViewCheckBoxColumn With {
            .FillWeight = 50
        }
        Col.HeaderText = "選擇" : Col.Name = "選擇"
        物料明細3_dgv.Columns.Insert(24, Col)

        物料明細3_dgv.Columns(0).Visible = False : 物料明細3_dgv.Columns(1).Visible = False : 物料明細3_dgv.Columns(2).Visible = False : 物料明細3_dgv.Columns(3).Visible = False
        物料明細3_dgv.Columns(12).FillWeight = 70 : 物料明細3_dgv.Columns(2).FillWeight = 135 : 物料明細3_dgv.Columns(13).Visible = False : 物料明細3_dgv.Columns(14).FillWeight = 70
        物料明細3_dgv.Columns(15).FillWeight = 40 : 物料明細3_dgv.Columns(16).Visible = False : 物料明細3_dgv.Columns(17).Visible = False : 物料明細3_dgv.Columns(18).Visible = False
        物料明細3_dgv.Columns(19).Visible = False : 物料明細3_dgv.Columns(20).Visible = False : 物料明細3_dgv.Columns(21).Visible = False : 物料明細3_dgv.Columns(22).Visible = False
        物料明細3_dgv.Columns(23).Visible = False

        物料明細3_dgv.EditMode = DataGridViewEditMode.EditOnEnter : 物料明細3_dgv.Columns(2).ReadOnly = True

        物料明細3_dgv.Columns(12).DefaultCellStyle.Format = "#,##0" : 物料明細3_dgv.Columns(14).DefaultCellStyle.Format = "#,##0"
        物料明細3_dgv.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細3_dgv.Columns(14).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細3_dgv.Columns(12).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細3_dgv.Columns(14).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        If KKK2 = "SQLB03" Then
            物料明細3_dgv.Columns(7).Visible = False : 物料明細3_dgv.Columns(8).Visible = False : 物料明細3_dgv.Columns(9).Visible = False : 物料明細3_dgv.Columns(10).Visible = False
            物料明細3_dgv.Columns(11).Visible = False
            物料明細3_dgv.Columns(4).FillWeight = 213 : 物料明細3_dgv.Columns(5).FillWeight = 213 : 物料明細3_dgv.Columns(6).FillWeight = 214
        ElseIf KKK2 = "SQLB04" Then
            物料明細3_dgv.Columns(7).Visible = True : 物料明細3_dgv.Columns(8).Visible = False : 物料明細3_dgv.Columns(9).Visible = False : 物料明細3_dgv.Columns(10).Visible = False
            物料明細3_dgv.Columns(11).Visible = False
            物料明細3_dgv.Columns(4).FillWeight = 160 : 物料明細3_dgv.Columns(5).FillWeight = 160 : 物料明細3_dgv.Columns(6).FillWeight = 160 : 物料明細3_dgv.Columns(7).FillWeight = 160
        ElseIf KKK2 = "SQLB05" Then
            物料明細3_dgv.Columns(7).Visible = True : 物料明細3_dgv.Columns(8).Visible = True : 物料明細3_dgv.Columns(9).Visible = False : 物料明細3_dgv.Columns(10).Visible = False
            物料明細3_dgv.Columns(11).Visible = False
            物料明細3_dgv.Columns(4).FillWeight = 128 : 物料明細3_dgv.Columns(5).FillWeight = 128 : 物料明細3_dgv.Columns(6).FillWeight = 128 : 物料明細3_dgv.Columns(7).FillWeight = 128
            物料明細3_dgv.Columns(8).FillWeight = 128
        ElseIf KKK2 = "SQLB06" Then
            物料明細3_dgv.Columns(7).Visible = True : 物料明細3_dgv.Columns(8).Visible = True : 物料明細3_dgv.Columns(9).Visible = True : 物料明細3_dgv.Columns(10).Visible = False
            物料明細3_dgv.Columns(11).Visible = False
            物料明細3_dgv.Columns(4).FillWeight = 106 : 物料明細3_dgv.Columns(5).FillWeight = 107 : 物料明細3_dgv.Columns(6).FillWeight = 106 : 物料明細3_dgv.Columns(7).FillWeight = 107
            物料明細3_dgv.Columns(8).FillWeight = 106 : 物料明細3_dgv.Columns(9).FillWeight = 108
        ElseIf KKK2 = "SQLB07" Then
            物料明細3_dgv.Columns(7).Visible = True : 物料明細3_dgv.Columns(8).Visible = True : 物料明細3_dgv.Columns(9).Visible = True : 物料明細3_dgv.Columns(10).Visible = True
            物料明細3_dgv.Columns(11).Visible = False
            物料明細3_dgv.Columns(4).FillWeight = 91 : 物料明細3_dgv.Columns(5).FillWeight = 92 : 物料明細3_dgv.Columns(6).FillWeight = 91 : 物料明細3_dgv.Columns(7).FillWeight = 92
            物料明細3_dgv.Columns(8).FillWeight = 91 : 物料明細3_dgv.Columns(9).FillWeight = 92 : 物料明細3_dgv.Columns(10).FillWeight = 91
        ElseIf KKK2 = "SQLB08" Then
            物料明細3_dgv.Columns(7).Visible = True : 物料明細3_dgv.Columns(8).Visible = True : 物料明細3_dgv.Columns(9).Visible = True : 物料明細3_dgv.Columns(10).Visible = True
            物料明細3_dgv.Columns(11).Visible = True
            物料明細3_dgv.Columns(4).FillWeight = 80 : 物料明細3_dgv.Columns(5).FillWeight = 80 : 物料明細3_dgv.Columns(6).FillWeight = 80 : 物料明細3_dgv.Columns(7).FillWeight = 80
            物料明細3_dgv.Columns(8).FillWeight = 80 : 物料明細3_dgv.Columns(9).FillWeight = 80 : 物料明細3_dgv.Columns(10).FillWeight = 80 : 物料明細3_dgv.Columns(11).FillWeight = 80
        End If
        For i As Integer = 0 To 物料明細3_dgv.Rows.Count - 1 : 物料明細3_dgv("選擇", i).Value = False : 物料明細3_dgv(15, i).Value = i + 1 : Next
    End Sub
    Private Sub 讀取料號規格_04()
        Dim ds3 As New DataSet
        物料明細4_dgv.DataSource = Nothing : ds3.Clear()
        物料明細4_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料明細4_dgv.ColumnHeadersHeight = 25 : 物料明細4_dgv.AllowUserToAddRows = False

        SQL_物料規格表_物料清單()
        da.Fill(ds3) : 物料明細4_dgv.DataSource = ds3.Tables(0) : conn.Close()

        物料明細4_dgv.Columns(0).Visible = False : 物料明細4_dgv.Columns(1).Visible = False : 物料明細4_dgv.Columns(2).Visible = False : 物料明細4_dgv.Columns(3).Visible = False
        物料明細4_dgv.Columns(12).FillWeight = 70 : 物料明細4_dgv.Columns(2).FillWeight = 135 : 物料明細4_dgv.Columns(13).Visible = False : 物料明細4_dgv.Columns(14).FillWeight = 70
        物料明細4_dgv.Columns(15).FillWeight = 40 : 物料明細4_dgv.Columns(16).Visible = False : 物料明細4_dgv.Columns(17).Visible = False : 物料明細4_dgv.Columns(18).Visible = False
        物料明細4_dgv.Columns(19).Visible = False : 物料明細4_dgv.Columns(20).Visible = False : 物料明細4_dgv.Columns(21).Visible = False : 物料明細4_dgv.Columns(22).Visible = False
        物料明細4_dgv.Columns(23).Visible = False

        物料明細4_dgv.EditMode = DataGridViewEditMode.EditOnEnter : 物料明細4_dgv.Columns(2).ReadOnly = True

        物料明細4_dgv.Columns(12).DefaultCellStyle.Format = "#,##0" : 物料明細4_dgv.Columns(14).DefaultCellStyle.Format = "#,##0"
        物料明細4_dgv.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細4_dgv.Columns(14).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細4_dgv.Columns(12).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細4_dgv.Columns(14).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        If KKK2 = "SQLB03" Then
            物料明細4_dgv.Columns(7).Visible = False : 物料明細4_dgv.Columns(8).Visible = False : 物料明細4_dgv.Columns(9).Visible = False : 物料明細4_dgv.Columns(10).Visible = False
            物料明細4_dgv.Columns(11).Visible = False
            物料明細4_dgv.Columns(4).FillWeight = 213 : 物料明細4_dgv.Columns(5).FillWeight = 213 : 物料明細4_dgv.Columns(6).FillWeight = 214
        ElseIf KKK2 = "SQLB04" Then
            物料明細4_dgv.Columns(7).Visible = True : 物料明細4_dgv.Columns(8).Visible = False : 物料明細4_dgv.Columns(9).Visible = False : 物料明細4_dgv.Columns(10).Visible = False
            物料明細4_dgv.Columns(11).Visible = False
            物料明細4_dgv.Columns(4).FillWeight = 160 : 物料明細4_dgv.Columns(5).FillWeight = 160 : 物料明細4_dgv.Columns(6).FillWeight = 160 : 物料明細4_dgv.Columns(7).FillWeight = 160
        ElseIf KKK2 = "SQLB05" Then
            物料明細4_dgv.Columns(7).Visible = True : 物料明細4_dgv.Columns(8).Visible = True : 物料明細4_dgv.Columns(9).Visible = False : 物料明細4_dgv.Columns(10).Visible = False
            物料明細4_dgv.Columns(11).Visible = False
            物料明細4_dgv.Columns(4).FillWeight = 128 : 物料明細4_dgv.Columns(5).FillWeight = 128 : 物料明細4_dgv.Columns(6).FillWeight = 128 : 物料明細4_dgv.Columns(7).FillWeight = 128
            物料明細4_dgv.Columns(8).FillWeight = 128
        ElseIf KKK2 = "SQLB06" Then
            物料明細4_dgv.Columns(7).Visible = True : 物料明細4_dgv.Columns(8).Visible = True : 物料明細4_dgv.Columns(9).Visible = True : 物料明細4_dgv.Columns(10).Visible = False
            物料明細4_dgv.Columns(11).Visible = False
            物料明細4_dgv.Columns(4).FillWeight = 106 : 物料明細4_dgv.Columns(5).FillWeight = 107 : 物料明細4_dgv.Columns(6).FillWeight = 106 : 物料明細4_dgv.Columns(7).FillWeight = 107
            物料明細4_dgv.Columns(8).FillWeight = 106 : 物料明細4_dgv.Columns(9).FillWeight = 108
        ElseIf KKK2 = "SQLB07" Then
            物料明細4_dgv.Columns(7).Visible = True : 物料明細4_dgv.Columns(8).Visible = True : 物料明細4_dgv.Columns(9).Visible = True : 物料明細4_dgv.Columns(10).Visible = True
            物料明細4_dgv.Columns(11).Visible = False
            物料明細4_dgv.Columns(4).FillWeight = 91 : 物料明細4_dgv.Columns(5).FillWeight = 92 : 物料明細4_dgv.Columns(6).FillWeight = 91 : 物料明細4_dgv.Columns(7).FillWeight = 92
            物料明細4_dgv.Columns(8).FillWeight = 91 : 物料明細4_dgv.Columns(9).FillWeight = 92 : 物料明細4_dgv.Columns(10).FillWeight = 91
        ElseIf KKK2 = "SQLB08" Then
            物料明細4_dgv.Columns(7).Visible = True : 物料明細4_dgv.Columns(8).Visible = True : 物料明細4_dgv.Columns(9).Visible = True : 物料明細4_dgv.Columns(10).Visible = True
            物料明細4_dgv.Columns(11).Visible = True
            物料明細4_dgv.Columns(4).FillWeight = 80 : 物料明細4_dgv.Columns(5).FillWeight = 80 : 物料明細4_dgv.Columns(6).FillWeight = 80 : 物料明細4_dgv.Columns(7).FillWeight = 80
            物料明細4_dgv.Columns(8).FillWeight = 80 : 物料明細4_dgv.Columns(9).FillWeight = 80 : 物料明細4_dgv.Columns(10).FillWeight = 80 : 物料明細4_dgv.Columns(11).FillWeight = 80
        End If
        For I As Integer = 0 To 物料明細4_dgv.Rows.Count - 1 : 物料明細4_dgv(15, I).Value = I + 1 : Next
    End Sub
    Private Sub 讀取料號規格_05()
        Dim ds3 As New DataSet
        物料明細5_dgv.DataSource = Nothing : ds3.Clear()
        物料明細5_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料明細5_dgv.ColumnHeadersHeight = 25 : 物料明細5_dgv.AllowUserToAddRows = False

        SQL_物料規格表_物料清單()
        da.Fill(ds3) : 物料明細5_dgv.DataSource = ds3.Tables(0) : conn.Close()

        物料明細5_dgv.Columns(0).Visible = False : 物料明細5_dgv.Columns(1).Visible = False : 物料明細5_dgv.Columns(2).Visible = False : 物料明細5_dgv.Columns(3).Visible = False
        物料明細5_dgv.Columns(12).FillWeight = 70 : 物料明細5_dgv.Columns(2).FillWeight = 135 : 物料明細5_dgv.Columns(13).Visible = False : 物料明細5_dgv.Columns(14).Visible = False
        物料明細5_dgv.Columns(15).Visible = False : 物料明細5_dgv.Columns(12).Visible = False : 物料明細5_dgv.Columns(16).FillWeight = 25 : 物料明細5_dgv.Columns(17).FillWeight = 25
        物料明細5_dgv.Columns(19).FillWeight = 25 : 物料明細5_dgv.Columns(20).FillWeight = 25 : 物料明細5_dgv.Columns(21).FillWeight = 25 : 物料明細5_dgv.Columns(22).FillWeight = 25
        物料明細5_dgv.Columns(23).FillWeight = 25 : 物料明細5_dgv.Columns(18).FillWeight = 25

        物料明細5_dgv.EditMode = DataGridViewEditMode.EditOnEnter : 物料明細5_dgv.Columns(2).ReadOnly = True

        物料明細5_dgv.Columns(12).DefaultCellStyle.Format = "#,##0" : 物料明細5_dgv.Columns(14).DefaultCellStyle.Format = "#,##0"
        物料明細5_dgv.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細5_dgv.Columns(14).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細5_dgv.Columns(12).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料明細5_dgv.Columns(14).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        If KKK2 = "SQLB03" Then
            物料明細5_dgv.Columns(7).Visible = False : 物料明細5_dgv.Columns(8).Visible = False : 物料明細5_dgv.Columns(9).Visible = False : 物料明細5_dgv.Columns(10).Visible = False
            物料明細5_dgv.Columns(11).Visible = False
            物料明細5_dgv.Columns(4).FillWeight = 213 : 物料明細5_dgv.Columns(5).FillWeight = 213 : 物料明細5_dgv.Columns(6).FillWeight = 214
        ElseIf KKK2 = "SQLB04" Then
            物料明細5_dgv.Columns(7).Visible = True : 物料明細5_dgv.Columns(8).Visible = False : 物料明細5_dgv.Columns(9).Visible = False : 物料明細5_dgv.Columns(10).Visible = False
            物料明細5_dgv.Columns(11).Visible = False
            物料明細5_dgv.Columns(4).FillWeight = 160 : 物料明細5_dgv.Columns(5).FillWeight = 160 : 物料明細5_dgv.Columns(6).FillWeight = 160 : 物料明細5_dgv.Columns(7).FillWeight = 160
        ElseIf KKK2 = "SQLB05" Then
            物料明細5_dgv.Columns(7).Visible = True : 物料明細5_dgv.Columns(8).Visible = True : 物料明細5_dgv.Columns(9).Visible = False : 物料明細5_dgv.Columns(10).Visible = False
            物料明細5_dgv.Columns(11).Visible = False
            物料明細5_dgv.Columns(4).FillWeight = 128 : 物料明細5_dgv.Columns(5).FillWeight = 128 : 物料明細5_dgv.Columns(6).FillWeight = 128 : 物料明細5_dgv.Columns(7).FillWeight = 128
            物料明細5_dgv.Columns(8).FillWeight = 128
        ElseIf KKK2 = "SQLB06" Then
            物料明細5_dgv.Columns(7).Visible = True : 物料明細5_dgv.Columns(8).Visible = True : 物料明細5_dgv.Columns(9).Visible = True : 物料明細5_dgv.Columns(10).Visible = False
            物料明細5_dgv.Columns(11).Visible = False
            物料明細5_dgv.Columns(4).FillWeight = 106 : 物料明細5_dgv.Columns(5).FillWeight = 107 : 物料明細5_dgv.Columns(6).FillWeight = 106 : 物料明細5_dgv.Columns(7).FillWeight = 107
            物料明細5_dgv.Columns(8).FillWeight = 106 : 物料明細5_dgv.Columns(9).FillWeight = 108
        ElseIf KKK2 = "SQLB07" Then
            物料明細5_dgv.Columns(7).Visible = True : 物料明細5_dgv.Columns(8).Visible = True : 物料明細5_dgv.Columns(9).Visible = True : 物料明細5_dgv.Columns(10).Visible = True
            物料明細5_dgv.Columns(11).Visible = False
            物料明細5_dgv.Columns(4).FillWeight = 91 : 物料明細5_dgv.Columns(5).FillWeight = 92 : 物料明細5_dgv.Columns(6).FillWeight = 91 : 物料明細5_dgv.Columns(7).FillWeight = 92
            物料明細5_dgv.Columns(8).FillWeight = 91 : 物料明細5_dgv.Columns(9).FillWeight = 92 : 物料明細5_dgv.Columns(10).FillWeight = 91
        ElseIf KKK2 = "SQLB08" Then
            物料明細5_dgv.Columns(7).Visible = True : 物料明細5_dgv.Columns(8).Visible = True : 物料明細5_dgv.Columns(9).Visible = True : 物料明細5_dgv.Columns(10).Visible = True
            物料明細5_dgv.Columns(11).Visible = True
            物料明細5_dgv.Columns(4).FillWeight = 80 : 物料明細5_dgv.Columns(5).FillWeight = 80 : 物料明細5_dgv.Columns(6).FillWeight = 80 : 物料明細5_dgv.Columns(7).FillWeight = 80
            物料明細5_dgv.Columns(8).FillWeight = 80 : 物料明細5_dgv.Columns(9).FillWeight = 80 : 物料明細5_dgv.Columns(10).FillWeight = 80 : 物料明細5_dgv.Columns(11).FillWeight = 80
        End If
    End Sub
    Private Sub 新群組_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 新群組_dgv.CellClick
        If e.RowIndex = -1 Then : Else : 新群組編號_tb.Text = 新群組_dgv.Rows(e.RowIndex).Cells(0).Value.ToString : PA48 = 新群組編號_tb.Text
            SQL_新物料群組_讀取_中()
            If dr.Read Then : CA_1.Text = dr("第一層").ToString : CA_2.Text = dr("第二層").ToString : CA_3.Text = dr("第三層").ToString
                CA_4.Text = dr("第四層").ToString : CA_5.Text = dr("第五層").ToString : End If
            SQL_新物料群組_讀取_英()
            If dr.Read Then : CB_1.Text = dr("第一層").ToString : CB_2.Text = dr("第二層").ToString : CB_3.Text = dr("第三層").ToString
                CB_4.Text = dr("第四層").ToString : CB_5.Text = dr("第五層").ToString : End If
            SQL_新物料群組_讀取_印()
            If dr.Read Then : CC_1.Text = dr("第一層").ToString : CC_2.Text = dr("第二層").ToString : CC_3.Text = dr("第三層").ToString
                CC_4.Text = dr("第四層").ToString : CC_5.Text = dr("第五層").ToString : End If
            只讀一次 = False : DA_1.Text = CA_1.Text : 只讀一次 = False : DA_2.Text = CA_2.Text : 只讀一次 = False : DA_3.Text = CA_3.Text
            只讀一次 = False : DA_4.Text = CA_4.Text : 只讀一次 = False : DA_5.Text = CA_5.Text
            If 一般模式_cb.Checked = True Then : Set_新群組清單_物料() : End If
        End If
    End Sub
    Private Sub DA_1_Click(sender As Object, e As EventArgs) Handles DA_1.Click
        只讀一次 = False
    End Sub
    Private Sub DB_1_Click(sender As Object, e As EventArgs) Handles DB_1.Click
        只讀一次 = False
    End Sub
    Private Sub DC_1_Click(sender As Object, e As EventArgs) Handles DC_1.Click
        只讀一次 = False
    End Sub
    Private Sub DA_2_Click(sender As Object, e As EventArgs) Handles DA_2.Click
        只讀一次 = False
    End Sub
    Private Sub DB_2_Click(sender As Object, e As EventArgs) Handles DB_2.Click
        只讀一次 = False
    End Sub
    Private Sub DC_2_Click(sender As Object, e As EventArgs) Handles DC_2.Click
        只讀一次 = False
    End Sub
    Private Sub DA_3_Click(sender As Object, e As EventArgs) Handles DA_3.Click
        只讀一次 = False
    End Sub
    Private Sub DB_3_Click(sender As Object, e As EventArgs) Handles DB_3.Click
        只讀一次 = False
    End Sub
    Private Sub DC_3_Click(sender As Object, e As EventArgs) Handles DC_3.Click
        只讀一次 = False
    End Sub
    Private Sub DA_4_Click(sender As Object, e As EventArgs) Handles DA_4.Click
        只讀一次 = False
    End Sub
    Private Sub DB_4_Click(sender As Object, e As EventArgs) Handles DB_4.Click
        只讀一次 = False
    End Sub
    Private Sub DC_4_Click(sender As Object, e As EventArgs) Handles DC_4.Click
        只讀一次 = False
    End Sub
    Private Sub DA_5_Click(sender As Object, e As EventArgs) Handles DA_5.Click
        只讀一次 = False
    End Sub
    Private Sub DB_5_Click(sender As Object, e As EventArgs) Handles DB_5.Click
        只讀一次 = False
    End Sub
    Private Sub DC_5_Click(sender As Object, e As EventArgs) Handles DC_5.Click
        只讀一次 = False
    End Sub
    Private Sub DA_1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DA_1.SelectedIndexChanged
        CA_1.Text = DA_1.Text : CB_1.Text = DB_1.Items(DA_1.SelectedIndex).ToString() : CC_1.Text = DC_1.Items(DA_1.SelectedIndex).ToString()
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼2() : End If
        DB_1.SelectedIndex = DA_1.SelectedIndex : DC_1.SelectedIndex = DA_1.SelectedIndex
    End Sub
    Private Sub DB_1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DB_1.SelectedIndexChanged
        CA_1.Text = DA_1.Items(DB_1.SelectedIndex).ToString() : CB_1.Text = DB_1.Text : CC_1.Text = DC_1.Items(DB_1.SelectedIndex).ToString()
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼2() : End If
        DA_1.SelectedIndex = DB_1.SelectedIndex : DC_1.SelectedIndex = DB_1.SelectedIndex
    End Sub
    Private Sub DC_1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DC_1.SelectedIndexChanged
        CA_1.Text = DA_1.Items(DC_1.SelectedIndex).ToString() : CB_1.Text = DB_1.Items(DC_1.SelectedIndex).ToString() : CC_1.Text = DC_1.Text
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼2() : End If
        DA_1.SelectedIndex = DC_1.SelectedIndex : DB_1.SelectedIndex = DC_1.SelectedIndex
    End Sub
    Private Sub DA_2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DA_2.SelectedIndexChanged
        CA_2.Text = DA_2.Text : CB_2.Text = DB_2.Items(DA_2.SelectedIndex).ToString() : CC_2.Text = DC_2.Items(DA_2.SelectedIndex).ToString()
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼3() : End If
        DB_2.SelectedIndex = DA_2.SelectedIndex : DC_2.SelectedIndex = DA_2.SelectedIndex
    End Sub
    Private Sub DB_2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DB_2.SelectedIndexChanged
        CA_2.Text = DA_2.Items(DB_2.SelectedIndex).ToString() : CB_2.Text = DB_2.Text : CC_2.Text = DC_2.Items(DB_2.SelectedIndex).ToString()
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼3() : End If
        DA_2.SelectedIndex = DB_2.SelectedIndex : DC_2.SelectedIndex = DB_2.SelectedIndex
    End Sub
    Private Sub DC_2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DC_2.SelectedIndexChanged
        CA_2.Text = DA_2.Items(DC_2.SelectedIndex).ToString() : CB_2.Text = DB_2.Items(DC_2.SelectedIndex).ToString() : CC_2.Text = DC_2.Text
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼3() : End If
        DA_2.SelectedIndex = DC_2.SelectedIndex : DB_2.SelectedIndex = DC_2.SelectedIndex
    End Sub
    Private Sub DA_3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DA_3.SelectedIndexChanged
        CA_3.Text = DA_3.Text : CB_3.Text = DB_3.Items(DA_3.SelectedIndex).ToString() : CC_3.Text = DC_3.Items(DA_3.SelectedIndex).ToString()
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼4() : End If
        DB_3.SelectedIndex = DA_3.SelectedIndex : DC_3.SelectedIndex = DA_3.SelectedIndex
    End Sub
    Private Sub DB_3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DB_3.SelectedIndexChanged
        CA_3.Text = DA_3.Items(DB_3.SelectedIndex).ToString() : CB_3.Text = DB_3.Text : CC_3.Text = DC_3.Items(DB_3.SelectedIndex).ToString()
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼4() : End If
        DA_3.SelectedIndex = DB_3.SelectedIndex : DC_3.SelectedIndex = DB_3.SelectedIndex
    End Sub
    Private Sub DC_3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DC_3.SelectedIndexChanged
        CA_3.Text = DA_3.Items(DC_3.SelectedIndex).ToString() : CB_3.Text = DB_3.Items(DC_3.SelectedIndex).ToString() : CC_3.Text = DC_3.Text
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼4() : End If
        DA_3.SelectedIndex = DC_3.SelectedIndex : DB_3.SelectedIndex = DC_3.SelectedIndex
    End Sub
    Private Sub DA_4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DA_4.SelectedIndexChanged
        CA_4.Text = DA_4.Text : CB_4.Text = DB_4.Items(DA_4.SelectedIndex).ToString() : CC_4.Text = DC_4.Items(DA_4.SelectedIndex).ToString()
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼5() : End If
        DB_4.SelectedIndex = DA_4.SelectedIndex : DC_4.SelectedIndex = DA_4.SelectedIndex
    End Sub
    Private Sub DB_4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DB_4.SelectedIndexChanged
        CA_4.Text = DA_4.Items(DB_4.SelectedIndex).ToString() : CB_4.Text = DB_4.Text : CC_4.Text = DC_4.Items(DB_4.SelectedIndex).ToString()
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼5() : End If
        DA_4.SelectedIndex = DB_4.SelectedIndex : DC_4.SelectedIndex = DB_4.SelectedIndex
    End Sub
    Private Sub DC_4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DC_4.SelectedIndexChanged
        CA_4.Text = DA_4.Items(DC_4.SelectedIndex).ToString() : CB_4.Text = DB_4.Items(DC_4.SelectedIndex).ToString() : CC_4.Text = DC_4.Text
        If 只讀一次 = False Then : 只讀一次 = True : 新群組碼5() : End If
        DA_4.SelectedIndex = DC_4.SelectedIndex : DB_4.SelectedIndex = DC_4.SelectedIndex
    End Sub
    Private Sub DA_5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DA_5.SelectedIndexChanged
        CA_5.Text = DA_5.Text : CB_5.Text = DB_5.Items(DA_5.SelectedIndex).ToString() : CC_5.Text = DC_5.Items(DA_5.SelectedIndex).ToString()
        DB_5.SelectedIndex = DA_5.SelectedIndex : DC_5.SelectedIndex = DA_5.SelectedIndex
    End Sub
    Private Sub DB_5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DB_5.SelectedIndexChanged
        CA_5.Text = DA_5.Items(DB_5.SelectedIndex).ToString() : CB_5.Text = DB_5.Text : CC_5.Text = DC_5.Items(DB_5.SelectedIndex).ToString()
        DA_5.SelectedIndex = DB_5.SelectedIndex : DC_5.SelectedIndex = DB_5.SelectedIndex
    End Sub
    Private Sub DC_5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DC_5.SelectedIndexChanged
        CA_5.Text = DA_5.Text : CB_5.Text = DB_5.Items(DA_5.SelectedIndex).ToString() : CC_5.Text = DC_5.Items(DA_5.SelectedIndex).ToString()
        DB_5.SelectedIndex = DA_5.SelectedIndex : DC_5.SelectedIndex = DA_5.SelectedIndex
    End Sub
    Private Sub 新群組_物料_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 新群組_物料_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            PA1 = 新群組_物料_dgv.Rows(e.RowIndex).Cells("群組碼").Value : PA2 = 新群組_物料_dgv.Rows(e.RowIndex).Cells("料號原則").Value
            SQL_物料圖庫_圖檔讀取()
            While dr.Read() = True
                Dim unused As Byte() = New Byte(-1) {}
                Dim bytes As Byte() = DirectCast(dr.Item("圖檔"), Byte())
                Dim oStream As New MemoryStream(bytes)
                物料圖2_pb.Image = Bitmap.FromStream(oStream)
            End While : conn.Close() : 物料圖2_pb.SizeMode = 4 : 物料圖2_pb.SizeMode = 4
            If 編輯狀態_ch.Checked = True Then
                新群組_物料_dgv.Rows(e.RowIndex).Cells("Keyword").Value = 新群組編號_tb.Text
                新群組_物料_dgv.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.LightGreen
            End If
        End If
    End Sub
    Private Sub 物料明細1_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料明細1_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            If 兩碼_ch.Checked = True And 四碼_ch.Checked = False Then
                原始料號_tb.Text = Strings.Right(物料明細1_dgv.Rows(e.RowIndex).Cells("原始料號").Value.ToString, 2)
            Else
                原始料號_tb.Text = Strings.Right(物料明細1_dgv.Rows(e.RowIndex).Cells("原始料號").Value.ToString, 4)
            End If
            料號tb.Text = 物料明細1_dgv.Rows(e.RowIndex).Cells("料號").Value.ToString
            AA1_tb.Text = 物料明細1_dgv.Rows(e.RowIndex).Cells(4).Value.ToString : AA2_tb.Text = 物料明細1_dgv.Rows(e.RowIndex).Cells(5).Value.ToString
            AA3_tb.Text = 物料明細1_dgv.Rows(e.RowIndex).Cells(6).Value.ToString : AA4_tb.Text = 物料明細1_dgv.Rows(e.RowIndex).Cells(7).Value.ToString
            AA5_tb.Text = 物料明細1_dgv.Rows(e.RowIndex).Cells(8).Value.ToString : AA6_tb.Text = 物料明細1_dgv.Rows(e.RowIndex).Cells(9).Value.ToString
            AA7_tb.Text = 物料明細1_dgv.Rows(e.RowIndex).Cells(10).Value.ToString : AA8_tb.Text = 物料明細1_dgv.Rows(e.RowIndex).Cells(11).Value.ToString
            Dim 料號 As String = 料號tb.Text
            For Each 行 As DataGridViewRow In 料號使用_dgv.Rows  ' 檢查該行的第5列是否包含與料號相同的資料
                If 行.Cells(5).Value IsNot Nothing AndAlso 行.Cells(5).Value.ToString() = 料號 Then
                    被使用_ch.Checked = True : Exit Sub
                End If
            Next
            被使用_ch.Checked = False
        End If
    End Sub
    Private Sub 物料資訊1_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料資訊1_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            If 物料明細2_dgv.Columns.Count.ToString > 16 Then : 物料明細2_dgv.Columns.Remove("選擇") : End If

            料號原則2_tb.Text = 物料資訊1_dgv(1, e.RowIndex).Value.ToString
            規格庫編號3_cb.Text = 物料資訊1_dgv(3, e.RowIndex).Value.ToString : 規格庫抬頭指定3_cb.Text = 物料資訊1_dgv(4, e.RowIndex).Value.ToString

            KKK1 = 物料資訊1_dgv("料號原則", e.RowIndex).Value.ToString : PA2 = KKK1
            讀取料號規格_01()

            Dim ds3 As New DataSet
            物料明細2_dgv.DataSource = Nothing : ds3.Clear()
            物料明細2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
            物料明細2_dgv.ColumnHeadersHeight = 25 : 物料明細2_dgv.AllowUserToAddRows = False

            SQL_物料規格表_物料清單()
            da.Fill(ds3) : 物料明細2_dgv.DataSource = ds3.Tables(0) : conn.Close()

            Dim Col As New DataGridViewCheckBoxColumn With {
            .FillWeight = 50
        }
            Col.HeaderText = "選擇" : Col.Name = "選擇"
            物料明細2_dgv.Columns.Insert(24, Col)

            物料明細2_dgv.Columns(0).Visible = False : 物料明細2_dgv.Columns(1).Visible = False : 物料明細2_dgv.Columns(2).Visible = False : 物料明細2_dgv.Columns(3).Visible = False
            物料明細2_dgv.Columns(12).FillWeight = 70 : 物料明細2_dgv.Columns(2).FillWeight = 135 : 物料明細2_dgv.Columns(13).Visible = False : 物料明細2_dgv.Columns(14).FillWeight = 70
            物料明細2_dgv.Columns(15).FillWeight = 40 : 物料明細2_dgv.Columns(16).Visible = False : 物料明細2_dgv.Columns(17).Visible = False : 物料明細2_dgv.Columns(18).Visible = False
            物料明細2_dgv.Columns(19).Visible = False : 物料明細2_dgv.Columns(20).Visible = False : 物料明細2_dgv.Columns(21).Visible = False : 物料明細2_dgv.Columns(22).Visible = False
            物料明細2_dgv.Columns(23).Visible = False

            物料明細2_dgv.EditMode = DataGridViewEditMode.EditOnEnter : 物料明細2_dgv.Columns(2).ReadOnly = True

            物料明細2_dgv.Columns(12).DefaultCellStyle.Format = "#,##0" : 物料明細2_dgv.Columns(14).DefaultCellStyle.Format = "#,##0"
            物料明細2_dgv.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            物料明細2_dgv.Columns(14).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            物料明細2_dgv.Columns(12).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
            物料明細2_dgv.Columns(14).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

            If KKK2 = "SQLB03" Then
                物料明細2_dgv.Columns(7).Visible = False : 物料明細2_dgv.Columns(8).Visible = False : 物料明細2_dgv.Columns(9).Visible = False : 物料明細2_dgv.Columns(10).Visible = False
                物料明細2_dgv.Columns(11).Visible = False
                物料明細2_dgv.Columns(4).FillWeight = 213 : 物料明細2_dgv.Columns(5).FillWeight = 213 : 物料明細2_dgv.Columns(6).FillWeight = 214
            ElseIf KKK2 = "SQLB04" Then
                物料明細2_dgv.Columns(7).Visible = True : 物料明細2_dgv.Columns(8).Visible = False : 物料明細2_dgv.Columns(9).Visible = False : 物料明細2_dgv.Columns(10).Visible = False
                物料明細2_dgv.Columns(11).Visible = False
                物料明細2_dgv.Columns(4).FillWeight = 160 : 物料明細2_dgv.Columns(5).FillWeight = 160 : 物料明細2_dgv.Columns(6).FillWeight = 160 : 物料明細2_dgv.Columns(7).FillWeight = 160
            ElseIf KKK2 = "SQLB05" Then
                物料明細2_dgv.Columns(7).Visible = True : 物料明細2_dgv.Columns(8).Visible = True : 物料明細2_dgv.Columns(9).Visible = False : 物料明細2_dgv.Columns(10).Visible = False
                物料明細2_dgv.Columns(11).Visible = False
                物料明細2_dgv.Columns(4).FillWeight = 128 : 物料明細2_dgv.Columns(5).FillWeight = 128 : 物料明細2_dgv.Columns(6).FillWeight = 128 : 物料明細2_dgv.Columns(7).FillWeight = 128
                物料明細2_dgv.Columns(8).FillWeight = 128
            ElseIf KKK2 = "SQLB06" Then
                物料明細2_dgv.Columns(7).Visible = True : 物料明細2_dgv.Columns(8).Visible = True : 物料明細2_dgv.Columns(9).Visible = True : 物料明細2_dgv.Columns(10).Visible = False
                物料明細2_dgv.Columns(11).Visible = False
                物料明細2_dgv.Columns(4).FillWeight = 106 : 物料明細2_dgv.Columns(5).FillWeight = 107 : 物料明細2_dgv.Columns(6).FillWeight = 106 : 物料明細2_dgv.Columns(7).FillWeight = 107
                物料明細2_dgv.Columns(8).FillWeight = 106 : 物料明細2_dgv.Columns(9).FillWeight = 108
            ElseIf KKK2 = "SQLB07" Then
                物料明細2_dgv.Columns(7).Visible = True : 物料明細2_dgv.Columns(8).Visible = True : 物料明細2_dgv.Columns(9).Visible = True : 物料明細2_dgv.Columns(10).Visible = True
                物料明細2_dgv.Columns(11).Visible = False
                物料明細2_dgv.Columns(4).FillWeight = 91 : 物料明細2_dgv.Columns(5).FillWeight = 92 : 物料明細2_dgv.Columns(6).FillWeight = 91 : 物料明細2_dgv.Columns(7).FillWeight = 92
                物料明細2_dgv.Columns(8).FillWeight = 91 : 物料明細2_dgv.Columns(9).FillWeight = 92 : 物料明細2_dgv.Columns(10).FillWeight = 91
            ElseIf KKK2 = "SQLB08" Then
                物料明細2_dgv.Columns(7).Visible = True : 物料明細2_dgv.Columns(8).Visible = True : 物料明細2_dgv.Columns(9).Visible = True : 物料明細2_dgv.Columns(10).Visible = True
                物料明細2_dgv.Columns(11).Visible = True
                物料明細2_dgv.Columns(4).FillWeight = 80 : 物料明細2_dgv.Columns(5).FillWeight = 80 : 物料明細2_dgv.Columns(6).FillWeight = 80 : 物料明細2_dgv.Columns(7).FillWeight = 80
                物料明細2_dgv.Columns(8).FillWeight = 80 : 物料明細2_dgv.Columns(9).FillWeight = 80 : 物料明細2_dgv.Columns(10).FillWeight = 80 : 物料明細2_dgv.Columns(11).FillWeight = 80
            End If
            For i As Integer = 0 To 物料明細2_dgv.Rows.Count - 1 : 物料明細2_dgv("選擇", i).Value = False : 物料明細2_dgv(15, i).Value = i + 1 : Next
        End If
    End Sub
    Private Sub 物料資訊2_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料資訊2_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            群組碼5_tb.Text = 物料資訊2_dgv(0, e.RowIndex).Value.ToString : 料號原則3_tb.Text = 物料資訊2_dgv(1, e.RowIndex).Value.ToString
            規格庫編號4_cb.Text = 物料資訊2_dgv(3, e.RowIndex).Value.ToString : 規格庫抬頭指定4_cb.Text = 物料資訊2_dgv(4, e.RowIndex).Value.ToString

            KKK1 = 物料資訊2_dgv("料號原則", e.RowIndex).Value.ToString : PA2 = KKK1 : 讀取料號規格_01() : 讀取料號規格_03()
        End If
    End Sub
    Private Sub 物料資訊3_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料資訊3_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            群組碼6_tb.Text = 物料資訊3_dgv(0, e.RowIndex).Value.ToString : 料號原則4_tb.Text = 物料資訊3_dgv(1, e.RowIndex).Value.ToString
            規格庫編號5_cb.Text = 物料資訊3_dgv(3, e.RowIndex).Value.ToString : 料號原則5_tb.Text = 物料資訊3_dgv(1, e.RowIndex).Value.ToString
            規格庫抬頭指定5_cb.Text = 物料資訊3_dgv(4, e.RowIndex).Value.ToString : 物料品名2_tb.Text = 物料資訊3_dgv("品名", e.RowIndex).Value.ToString
            物料品名1_tb.Text = 物料資訊3_dgv("品名", e.RowIndex).Value.ToString : 圖檔編號1_tb.Text = 物料資訊3_dgv(6, e.RowIndex).Value.ToString
            單位_tb.Text = 物料資訊3_dgv("單位", e.RowIndex).Value.ToString

            KKK1 = 物料資訊3_dgv("料號原則", e.RowIndex).Value.ToString : PA2 = KKK1 : 讀取料號規格_01() : 讀取料號規格_04()

            If 物料明細4_dgv.Rows.Count = 0 Then : 資料複製1_bt.Enabled = False : Else : 資料複製1_bt.Enabled = True : End If
        End If
    End Sub
    Private Sub 物料資訊4_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料資訊4_dgv.CellClick
        KKK1 = 物料資訊4_dgv("料號原則", e.RowIndex).Value.ToString : PA2 = KKK1
        讀取料號規格_01() : 讀取料號規格_05()
        If 物料資訊4_dgv("Keyword", e.RowIndex).Value.ToString = "SQLB03" Then
            S1_ch.Checked = True : S2_ch.Checked = True : S3_ch.Checked = True : S4_ch.Checked = False
            S5_ch.Checked = False : S6_ch.Checked = False : S7_ch.Checked = False : S8_ch.Checked = False
        ElseIf 物料資訊4_dgv("Keyword", e.RowIndex).Value.ToString = "SQLB04" Then
            S1_ch.Checked = True : S2_ch.Checked = True : S3_ch.Checked = True : S4_ch.Checked = True
            S5_ch.Checked = False : S6_ch.Checked = False : S7_ch.Checked = False : S8_ch.Checked = False
        ElseIf 物料資訊4_dgv("Keyword", e.RowIndex).Value.ToString = "SQLB05" Then
            S1_ch.Checked = True : S2_ch.Checked = True : S3_ch.Checked = True : S4_ch.Checked = True
            S5_ch.Checked = True : S6_ch.Checked = False : S7_ch.Checked = False : S8_ch.Checked = False
        ElseIf 物料資訊4_dgv("Keyword", e.RowIndex).Value.ToString = "SQLB06" Then
            S1_ch.Checked = True : S2_ch.Checked = True : S3_ch.Checked = True : S4_ch.Checked = True
            S5_ch.Checked = True : S6_ch.Checked = True : S7_ch.Checked = False : S8_ch.Checked = False
        ElseIf 物料資訊4_dgv("Keyword", e.RowIndex).Value.ToString = "SQLB07" Then
            S1_ch.Checked = True : S2_ch.Checked = True : S3_ch.Checked = True : S4_ch.Checked = True
            S5_ch.Checked = True : S6_ch.Checked = True : S7_ch.Checked = True : S8_ch.Checked = False
        ElseIf 物料資訊4_dgv("Keyword", e.RowIndex).Value.ToString = "SQLB08" Then
            S1_ch.Checked = True : S2_ch.Checked = True : S3_ch.Checked = True : S4_ch.Checked = True
            S5_ch.Checked = True : S6_ch.Checked = True : S7_ch.Checked = True : S8_ch.Checked = True
        End If
    End Sub
    Private Sub 物料群組_語言_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料群組_語言_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            群組碼_tb.Text = 物料群組_dgv(0, e.RowIndex).Value.ToString : 群組碼1_tb.Text = 物料群組_dgv(0, e.RowIndex).Value.ToString : PA1 = "" : 精準 = False
            主項目_cb.Text = 物料群組_語言_dgv(2, e.RowIndex).Value.ToString : 物料原則_tb.Text = "" : 物料品名_tb.Text = "" : 查詢_tb.Text = "" : Set_清單1()
            SQL_物料資料庫語言選定()
            For i As Integer = 1 To 3
                If dr.Read() Then
                    If dr("語言").ToString = "繁體中文" Then : 類別1_tb.Text = dr("群組") : 群組碼10_tb.Text = dr("群組")
                    ElseIf dr("語言").ToString = "Indonesian" Then : 類別3_tb.Text = dr("群組") : 群組碼10_tb.Text = dr("群組")
                    ElseIf dr("語言").ToString = "English" Then : 類別2_tb.Text = dr("群組") : 群組碼10_tb.Text = dr("群組") : End If
                End If
            Next
            PA49 = 群組碼_tb.Text : SQL_物料圖庫_群組圖檔() : 群組圖片 = False
            If dr.Read() Then
                If IsDBNull(dr("圖片")) = True Then : 群組圖_pb.Image = Nothing : Else
                    SQL_物料圖庫_群組圖檔()
                    While dr.Read() = True
                        Dim unused As Byte() = New Byte(-1) {}
                        Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
                        Dim oStream As New MemoryStream(bytes)
                        群組圖_pb.Image = Bitmap.FromStream(oStream)
                    End While : conn.Close() : 群組圖_pb.SizeMode = 4 : 群組圖片 = True
                End If
            End If
        End If
    End Sub
    Private Sub 物料編碼_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料編碼_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            AA1_tb.Text = "" : AA2_tb.Text = "" : AA3_tb.Text = "" : AA4_tb.Text = "" : AA5_tb.Text = "" : AA6_tb.Text = "" : AA7_tb.Text = "" : AA8_tb.Text = ""

            物料原則_tb.Text = 物料編碼_dgv("料號原則", e.RowIndex).Value.ToString : 料號原則_tb.Text = 物料編碼_dgv("料號原則", e.RowIndex).Value.ToString
            物料品名_tb.Text = 物料編碼_dgv("物料品名", e.RowIndex).Value.ToString : 圖檔編號_tb.Text = 物料編碼_dgv("Image No", e.RowIndex).Value.ToString
            群組碼1_tb.Text = 物料編碼_dgv("群組碼", e.RowIndex).Value.ToString : 原則說明異動 = 物料編碼_dgv("物料品名", e.RowIndex).Value.ToString
            舊群組_cb.Text = 群組碼1_tb.Text

            群組碼2_tb.Text = 物料編碼_dgv("群組碼", e.RowIndex).Value.ToString : 群組碼4_tb.Text = 物料編碼_dgv("群組碼", e.RowIndex).Value.ToString
            物料原則2_tb.Text = 物料編碼_dgv("料號原則", e.RowIndex).Value.ToString : 料號原則2_tb.Text = 物料編碼_dgv("料號原則", e.RowIndex).Value.ToString
            原則說明_tb.Text = 物料編碼_dgv("物料品名", e.RowIndex).Value.ToString : 品名_tb.Text = 物料編碼_dgv("物料品名", e.RowIndex).Value.ToString
            規格庫編號_cb.Text = 物料編碼_dgv("規格庫編號", e.RowIndex).Value.ToString : 規格庫編號2_ch.Text = 物料編碼_dgv("規格庫編號", e.RowIndex).Value.ToString
            規格庫抬頭指定_cb.Text = 物料編碼_dgv("規格庫抬頭指定", e.RowIndex).Value.ToString : 規格庫抬頭指定2_cb.Text = 物料編碼_dgv("規格庫抬頭指定", e.RowIndex).Value.ToString
            If 規格庫編號_cb.Text <> "" Then : KKK1 = 物料編碼_dgv("料號原則", e.RowIndex).Value.ToString : PA2 = KKK1 : 讀取料號規格_01() : 讀取料號規格_02() : End If

            If 批量選擇_ts.Checked = True Then
                If 物料編碼_dgv(4, e.RowIndex).Value = False Then : 物料編碼_dgv(4, e.RowIndex).Value = True
                ElseIf 物料編碼_dgv(4, e.RowIndex).Value = True Then : 物料編碼_dgv(4, e.RowIndex).Value = False : End If
            End If
            是否有資料 = False
            For i As Integer = 0 To 物料品名_語轉_dgv.Rows.Count - 1
                If 物料品名_語轉_dgv(1, i).Value.ToString = 物料原則_tb.Text Then
                    If 物料品名_語轉_dgv(1, i).Value.ToString = 物料原則_tb.Text And 物料品名_語轉_dgv(2, i).Value.ToString = "繁體中文" Then
                        品名1_tb.Text = 物料品名_語轉_dgv(3, i).Value.ToString()
                    ElseIf 物料品名_語轉_dgv(1, i).Value.ToString = 物料原則_tb.Text And 物料品名_語轉_dgv(2, i).Value.ToString = "English" Then
                        品名2_tb.Text = 物料品名_語轉_dgv(3, i).Value.ToString()
                    ElseIf 物料品名_語轉_dgv(1, i).Value.ToString = 物料原則_tb.Text And 物料品名_語轉_dgv(2, i).Value.ToString = "Indonesian" Then
                        品名3_tb.Text = 物料品名_語轉_dgv(3, i).Value.ToString()
                    End If : 是否有資料 = True
                End If
            Next
            If 是否有資料 = False Then : 品名1_tb.Text = 物料品名_tb.Text : 品名2_tb.Text = 物料品名_tb.Text : 品名3_tb.Text = 物料品名_tb.Text : End If
            If 查詢_tb.Text <> "" Then : lastFoundRowIndex = -1 : lastFoundColIndex = -1 : 查詢DGV中的關鍵字_自動(物料明細1_dgv, 查詢_tb) : End If
        End If
    End Sub
    Private Sub 物料品名_語轉_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料品名_語轉_dgv.CellClick
        If e.RowIndex = -1 Then : Else : 物料原則_tb.Text = 物料品名_語轉_dgv(1, e.RowIndex).Value.ToString
            For i As Integer = 0 To 物料品名_語轉_dgv.Rows.Count - 1
                If 物料品名_語轉_dgv(1, i).Value.ToString = 物料原則_tb.Text Then
                    If 物料品名_語轉_dgv(1, i).Value.ToString = 物料原則_tb.Text And 物料品名_語轉_dgv(2, i).Value.ToString = "繁體中文" Then
                        品名1_tb.Text = 物料品名_語轉_dgv(3, i).Value.ToString()
                    ElseIf 物料品名_語轉_dgv(1, i).Value.ToString = 物料原則_tb.Text And 物料品名_語轉_dgv(2, i).Value.ToString = "English" Then
                        品名2_tb.Text = 物料品名_語轉_dgv(3, i).Value.ToString()
                    ElseIf 物料品名_語轉_dgv(1, i).Value.ToString = 物料原則_tb.Text And 物料品名_語轉_dgv(2, i).Value.ToString = "Indonesian" Then
                        品名3_tb.Text = 物料品名_語轉_dgv(3, i).Value.ToString()
                    End If
                End If
            Next
            For i As Integer = 0 To 物料編碼_dgv.Rows.Count - 1
                If 物料編碼_dgv(1, i).Value.ToString = 物料原則_tb.Text Then : 物料品名_tb.Text = 物料編碼_dgv(2, i).Value.ToString : End If
            Next
        End If
    End Sub
    Private Sub 物料群組_語言2_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料群組_語言2_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            BL1 = True : PA1 = 群組碼2_dgv(0, e.RowIndex).Value.ToString : 群組碼(1) = 群組碼2_dgv(0, e.RowIndex).Value.ToString : 物料資訊控制表1() : PA1 = "" : BL1 = False
        End If
    End Sub
    Private Sub 物料群組_語言3_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料群組_語言3_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            BL1 = True : PA1 = 群組碼3_dgv(0, e.RowIndex).Value.ToString : 群組碼(2) = 群組碼3_dgv(0, e.RowIndex).Value.ToString : 物料資訊控制表2() : PA1 = "" : BL1 = False
        End If
    End Sub
    Private Sub 物料群組_語言4_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料群組_語言4_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            BL1 = True : PA1 = 群組碼4_dgv(0, e.RowIndex).Value.ToString : 群組碼(3) = 群組碼4_dgv(0, e.RowIndex).Value.ToString : 物料資訊控制表3() : PA1 = "" : BL1 = False
        End If
    End Sub
    Private Sub 物料群組_語言5_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料群組_語言5_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            BL1 = True : PA1 = 群組碼5_dgv(0, e.RowIndex).Value.ToString : 群組碼(4) = 群組碼5_dgv(0, e.RowIndex).Value.ToString : 物料資訊控制表4() : PA1 = "" : BL1 = False
        End If
    End Sub
    Private Sub 規格表頭_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 規格表頭_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            規格庫抬頭指定_tb.Text = 規格表頭_dgv(0, e.RowIndex).Value.ToString : A1_tb.Text = 規格表頭_dgv(1, e.RowIndex).Value.ToString
            A2_tb.Text = 規格表頭_dgv(2, e.RowIndex).Value.ToString : A3_tb.Text = 規格表頭_dgv(3, e.RowIndex).Value.ToString
            A4_tb.Text = 規格表頭_dgv(4, e.RowIndex).Value.ToString : A5_tb.Text = 規格表頭_dgv(5, e.RowIndex).Value.ToString
            A6_tb.Text = 規格表頭_dgv(6, e.RowIndex).Value.ToString : A7_tb.Text = 規格表頭_dgv(7, e.RowIndex).Value.ToString
            A8_tb.Text = 規格表頭_dgv(8, e.RowIndex).Value.ToString : 系統語言_cb.Text = 規格表頭_dgv(9, e.RowIndex).Value.ToString
            If Strings.Mid(規格表頭_dgv(0, e.RowIndex).Value.ToString, 3, 2) = "03" Then
                規格庫編號1_cb.Text = "SQLB03" : 規格庫抬頭指定1_cb.Text = 規格表頭_dgv(0, e.RowIndex).Value.ToString
            ElseIf Strings.Mid(規格表頭_dgv(0, e.RowIndex).Value.ToString, 3, 2) = "04" Then
                規格庫編號1_cb.Text = "SQLB04" : 規格庫抬頭指定1_cb.Text = 規格表頭_dgv(0, e.RowIndex).Value.ToString
            ElseIf Strings.Mid(規格表頭_dgv(0, e.RowIndex).Value.ToString, 3, 2) = "05" Then
                規格庫編號1_cb.Text = "SQLB05" : 規格庫抬頭指定1_cb.Text = 規格表頭_dgv(0, e.RowIndex).Value.ToString
            ElseIf Strings.Mid(規格表頭_dgv(0, e.RowIndex).Value.ToString, 3, 2) = "06" Then
                規格庫編號1_cb.Text = "SQLB06" : 規格庫抬頭指定1_cb.Text = 規格表頭_dgv(0, e.RowIndex).Value.ToString
            ElseIf Strings.Mid(規格表頭_dgv(0, e.RowIndex).Value.ToString, 3, 2) = "07" Then
                規格庫編號1_cb.Text = "SQLB07" : 規格庫抬頭指定1_cb.Text = 規格表頭_dgv(0, e.RowIndex).Value.ToString
            ElseIf Strings.Mid(規格表頭_dgv(0, e.RowIndex).Value.ToString, 3, 2) = "08" Then
                規格庫編號1_cb.Text = "SQLB08" : 規格庫抬頭指定1_cb.Text = 規格表頭_dgv(0, e.RowIndex).Value.ToString
            End If : BL1 = False
        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(2, e.RowIndex).Value.ToString <> 新群組_dgv(2, 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
        End If
        Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 新群組_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 新群組_dgv(3, e.RowIndex).Value.ToString <> 新群組_dgv(3, 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(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
        End If
        Dim linePen2 As New Pen(Color.Green, 2)
        If e.RowIndex = 新群組_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 新群組_dgv(4, e.RowIndex).Value.ToString <> 新群組_dgv(4, 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(linePen2, startX, startY, endX, startY) : Exit Sub
            End If
        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(0, e.RowIndex).Value.ToString <> 規格表頭_dgv(0, 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
        End If
    End Sub
    Private Sub 未指定表頭_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 未指定表頭_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            群組碼2_tb.Text = 未指定表頭_dgv(0, e.RowIndex).Value.ToString : 物料原則2_tb.Text = 未指定表頭_dgv(1, e.RowIndex).Value.ToString
            原則說明_tb.Text = 未指定表頭_dgv(2, e.RowIndex).Value.ToString : BL1 = True : PA1 = 未指定表頭_dgv(0, e.RowIndex).Value.ToString
            PA1 = "" : BL1 = False
        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(1, e.RowIndex).Value.ToString <> 物料品名_語轉_dgv(1, 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
        End If
    End Sub
    '------------------------------------------------------------------------------------------------------------------------------------
    Private Sub 新群組1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 新群組1_cb.Click
        CB選擇清單(新群組1_cb, 新群組1_cb.Text)
        PA = 新群組1_cb.Text : SQL_群組碼_語轉_選擇() : If dr.Read Then : 新群組_cb.Text = dr("群組碼").ToString : End If : PA = ""
    End Sub
    Private Sub 舊群組1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 舊群組1_cb.Click
        CB選擇清單(舊群組1_cb, 舊群組1_cb.Text)
        PA = 舊群組1_cb.Text : SQL_群組碼_語轉_選擇() : If dr.Read Then : 舊群組_cb.Text = dr("群組碼") : End If : PA = ""
    End Sub
    Private Sub 讀取料夾路徑_bt_Click(sender As Object, e As EventArgs) Handles 讀取料夾路徑_bt.Click
        If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then : 本機_wb.Navigate(FolderBrowserDialog1.SelectedPath) : End If
    End Sub
    Private Sub 讀取料夾路徑1_bt_Click(sender As Object, e As EventArgs) Handles 讀取料夾路徑1_bt.Click
        If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then : 本機1_wb.Navigate(FolderBrowserDialog1.SelectedPath) : End If
    End Sub
    Private Sub 改料號原則_ts_ValueChanged(sender As Object, e As EventArgs) Handles 改料號原則_ts.Click
        If 首次開啟 = True Then : Else : If 改料號原則_ts.Checked = False Then : 物料原則_tb.Enabled = False : Else : 物料原則_tb.Enabled = True : End If : End If
    End Sub
    Private Sub 規格庫抬頭指定2_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 規格庫抬頭指定2_cb.SelectedIndexChanged
        AAA1 = "" : AAA2 = "" : AAA3 = "" : AAA4 = "" : AAA5 = "" : AAA6 = "" : AAA7 = "" : AAA8 = "" : PA3 = 規格庫抬頭指定2_cb.Text
        SQL_規格庫抬頭讀取()
        If dr.Read() Then
            AAA1 = dr("A1") : AAA2 = dr("A2") : AAA3 = dr("A3") : AAA4 = dr("A4") : AAA5 = dr("A5") : AAA6 = dr("A6") : AAA7 = dr("A7") : AAA8 = dr("A8")
        End If : conn.Close()

        If AAA1 = "" Then : Label70.Text = "A1" : Else : Label70.Text = AAA1 : End If : If AAA2 = "" Then : Label69.Text = "A2" : Else : Label69.Text = AAA2 : End If
        If AAA3 = "" Then : Label68.Text = "A3" : Else : Label68.Text = AAA3 : End If : If AAA4 = "" Then : Label67.Text = "A4" : Else : Label67.Text = AAA4 : End If
        If AAA5 = "" Then : Label66.Text = "A5" : Else : Label66.Text = AAA5 : End If : If AAA6 = "" Then : Label65.Text = "A6" : Else : Label65.Text = AAA6 : End If
        If AAA7 = "" Then : Label64.Text = "A7" : Else : Label64.Text = AAA7 : End If : If AAA8 = "" Then : Label63.Text = "A8" : Else : Label63.Text = AAA8 : End If
    End Sub
    Private Sub 規格庫編號2_ch_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 規格庫編號2_ch.SelectedIndexChanged
        If 規格庫編號2_ch.Text = "SQLB03" Then
            AA1_tb.Enabled = True : AA2_tb.Enabled = True : AA3_tb.Enabled = True : AA4_tb.Enabled = False
            AA5_tb.Enabled = False : AA6_tb.Enabled = False : AA7_tb.Enabled = False : AA8_tb.Enabled = False
        ElseIf 規格庫編號2_ch.Text = "SQLB04" Then
            AA1_tb.Enabled = True : AA2_tb.Enabled = True : AA3_tb.Enabled = True : AA4_tb.Enabled = True
            AA5_tb.Enabled = False : AA6_tb.Enabled = False : AA7_tb.Enabled = False : AA8_tb.Enabled = False
        ElseIf 規格庫編號2_ch.Text = "SQLB05" Then
            AA1_tb.Enabled = True : AA2_tb.Enabled = True : AA3_tb.Enabled = True : AA4_tb.Enabled = True
            AA5_tb.Enabled = True : AA6_tb.Enabled = False : AA7_tb.Enabled = False : AA8_tb.Enabled = False
        ElseIf 規格庫編號2_ch.Text = "SQLB06" Then
            AA1_tb.Enabled = True : AA2_tb.Enabled = True : AA3_tb.Enabled = True : AA4_tb.Enabled = True
            AA5_tb.Enabled = True : AA6_tb.Enabled = True : AA7_tb.Enabled = False : AA8_tb.Enabled = False
        ElseIf 規格庫編號2_ch.Text = "SQLB07" Then
            AA1_tb.Enabled = True : AA2_tb.Enabled = True : AA3_tb.Enabled = True : AA4_tb.Enabled = True
            AA5_tb.Enabled = True : AA6_tb.Enabled = True : AA7_tb.Enabled = True : AA8_tb.Enabled = False
        ElseIf 規格庫編號2_ch.Text = "SQLB08" Then
            AA1_tb.Enabled = True : AA2_tb.Enabled = True : AA3_tb.Enabled = True : AA4_tb.Enabled = True
            AA5_tb.Enabled = True : AA6_tb.Enabled = True : AA7_tb.Enabled = True : AA8_tb.Enabled = True
        End If
    End Sub
    Private Sub 規格庫抬頭指定_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 規格庫抬頭指定_cb.SelectedIndexChanged
        規格庫編號_cb.Text = "SQLB" & Mid(規格庫抬頭指定_cb.Text, 3, 2)
    End Sub
    Private Sub 規格庫抬頭指定1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 規格庫抬頭指定1_cb.SelectedIndexChanged
        規格庫編號1_cb.Text = "SQLB" & Mid(規格庫抬頭指定1_cb.Text, 3, 2)
    End Sub
    Private Sub 規格庫抬頭指定3_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 規格庫抬頭指定3_cb.SelectedIndexChanged
        規格庫編號3_cb.Text = "SQLB" & Mid(規格庫抬頭指定3_cb.Text, 3, 2)
    End Sub
    Private Sub 規格庫抬頭指定4_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 規格庫抬頭指定4_cb.SelectedIndexChanged
        規格庫編號4_cb.Text = "SQLB" & Mid(規格庫抬頭指定4_cb.Text, 3, 2)
    End Sub
    '------------------------------------------------------------------------------------------------------------------------------------
    Private Sub 檔案名稱_tb_DragEnter(sender As Object, e As DragEventArgs) Handles 檔案名稱_tb.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then : Dim files As String()
            Try : files = CType(e.Data.GetData(DataFormats.FileDrop), String()) : 檔案名稱_tb.Text = files(files.Length - 1)
            Catch ex As Exception : MessageBox.Show(ex.Message) : Return : End Try
        End If
        Dim STR2 As Integer = 0 : 檔案路徑_be.Text = 檔案名稱_tb.Text
        If 檔案名稱_tb.Text = "" Then : Else
            For i As Integer = 0 To 9999 : Dim STR1 As Integer = Strings.Len(檔案路徑_be.Text)
                If Strings.Right((檔案路徑_be.Text), 1) <> "\" Then : STR1 -= 1 : STR2 += 1
                    If STR1 = 0 Then : 檔案路徑_be.Text = "" : 檔案名稱_tb.Text = "" : i = 9999
                    Else : 檔案路徑_be.Text = Strings.Left((檔案路徑_be.Text), STR1) : End If
                Else
                    檔案路徑_be.Text = Strings.Right((檔案名稱_tb.Text), STR2)
                    檔案名稱_tb.Text = 檔案路徑_be.Text : i = 9999
                End If
            Next
            Dim files As String() : files = CType(e.Data.GetData(DataFormats.FileDrop), String())
            檔案路徑_be.Text = files(files.Length - 1)
        End If
    End Sub
    Private Sub 檔案名稱_tb_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles 檔案名稱_tb.DragDrop
        Dim files As Array = e.Data.GetData(DataFormats.FileDrop) : For Each file As String In files : 檔案名稱_tb.AppendText(file + Environment.NewLine) : Next
    End Sub
    Private Sub 檔案名稱1_tb_DragEnter(sender As Object, e As DragEventArgs) Handles 檔案名稱1_tb.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim files As String()
            Try
                files = CType(e.Data.GetData(DataFormats.FileDrop), String()) : 檔案名稱1_tb.Text = files(files.Length - 1)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                Return
            End Try
        End If

        '-------確認檔案是圖片---------------------------------------------------------------------------------------------------------------
        Dim 驗證 As String = "" : Dim 取變數 As String : 取變數 = Strings.StrReverse(檔案名稱1_tb.Text)
        For i As Integer = 1 To 10
            If i = 1 Then : 驗證 = Strings.Left(取變數, i) : Else
                If Strings.Mid(取變數, i, 1) = "." Then : 驗證 = Strings.StrReverse(驗證) : Exit For : Else : 驗證 &= Strings.Mid(取變數, i, 1) : End If
            End If
        Next
        If 驗證 = "PNG" Or 驗證 = "png" Or 驗證 = "GIF" Or 驗證 = "gif" Or 驗證 = "BMP" Or 驗證 = "bmp" Or 驗證 = "JPG" Or 驗證 = "jpg" Or 驗證 = "JPEG" Or 驗證 = "jpeg" Then
            群組圖_pb.Image = System.Drawing.Image.FromFile(檔案名稱1_tb.Text)
        End If

        Dim STR2 As Integer = 0 : 檔案路徑_tb.Text = 檔案名稱1_tb.Text
        If 檔案名稱1_tb.Text = "" Then : Else
            For i As Integer = 0 To 9999 : Dim STR1 As Integer = Strings.Len(檔案路徑_tb.Text)
                If Strings.Right((檔案路徑_tb.Text), 1) <> "\" Then : STR1 -= 1 : STR2 += 1
                    If STR1 = 0 Then : 檔案路徑_tb.Text = "" : 檔案名稱1_tb.Text = "" : i = 9999
                    Else : 檔案路徑_tb.Text = Strings.Left((檔案路徑_tb.Text), STR1) : End If
                Else : 檔案路徑_tb.Text = Strings.Right((檔案名稱1_tb.Text), STR2) : 檔案名稱1_tb.Text = 檔案路徑_tb.Text : i = 9999 : End If
                Dim files As String() : files = CType(e.Data.GetData(DataFormats.FileDrop), String())
                檔案路徑_be.Text = files(files.Length - 1)
            Next
        End If
    End Sub
    Private Sub 檔案名稱1_tb_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles 檔案名稱1_tb.DragDrop
        Dim files As Array = e.Data.GetData(DataFormats.FileDrop) : For Each file As String In files : 檔案名稱1_tb.AppendText(file + Environment.NewLine) : Next
    End Sub
    Private Sub SET_新增按鈕程式共用3()
        cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() : dr.Close()
    End Sub
    Private Sub SET_新增按鈕程式共用2()
        cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : MsgBox("存檔完成!!") : conn.Close() : dr.Close()
    End Sub
    Private Sub SET_修改按鈕程式共用1()
        cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : MsgBox("存檔完成!!") : conn.Close()
    End Sub
    Private Sub SET_刪除按鈕程式共用1()
        訊息回應 = InputBox("確定要刪除該筆資料?、請輸入大寫 [YES] 來繼續後續動作!!") : If 訊息回應 = "YES" Then : ConnOpen() : CmdSet_For_dr() : MsgBox("刪除完成!!") : End If : conn.Close()
    End Sub
    Private Sub SET_刪除按鈕程式共用2()
        訊息回應 = InputBox("確定要刪除該筆資料?、請輸入大寫 [YES] 來繼續後續動作!!") : If 訊息回應 = "YES" Then : ConnOpen() : CmdSet_For_dr() : MsgBox("刪除完成!!") : End If : conn.Close()
        式共用1()
    End Sub
    Private Sub 式共用1()
        Set_物料群組_語轉() : Set_物料群組() : 精準 = False : Set_清單1() : Set_物料規格庫() : 物料資訊控制表1() : 物料資訊控制表2() : 物料資訊控制表3() : Set_物料資訊控制表未新增()
        群組碼_cb_語轉_下拉表單資料載入() : 群組碼_cb_下拉表單資料載入() : If 物料品名_tb.Text <> 原則說明異動 Then : 精準 = False : Set_清單1() : Else : Set_清單1_語轉() : End If
    End Sub
    Private Sub 式共用2()
        conn.Close() : dr.Close() : ConnOpen()
    End Sub
    Private Sub 式共用3()
        ConnOpen()
    End Sub
    '------------------------------------------------------------------------------------------------------------------------------------
    Private Sub 群組新增_bt_Click(sender As Object, e As EventArgs) Handles 群組新增_bt.Click
        If 主項目_cb.Text = "" Then : MsgBox("主項目沒有選擇!!") : Else
            If 群組碼_tb.Text = "" Or 類別1_tb.Text = "" Or 類別2_tb.Text = "" Or 類別3_tb.Text = "" Then : MsgBox("資料有缺或有誤，請重新檢查!!")
            Else : 式共用3() : SQL_物料資料庫_群組碼重複查詢() : CmdSet_For_dr()
                If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else : 式共用3() : SQL_物料資料庫_群組碼重複查詢_語轉1() : CmdSet_For_dr()
                    If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else : 式共用3() : SQL_物料資料庫_群組碼重複查詢_語轉2() : CmdSet_For_dr()
                        If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else : 式共用3() : SQL_物料資料庫_群組碼重複查詢_語轉3() : CmdSet_For_dr()
                            If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else
                                If 主項目_cb.SelectedIndex = 0 Then : PA49 = "" : ElseIf 主項目_cb.SelectedIndex = 1 Then : PA49 = 物料主項(0)
                                ElseIf 主項目_cb.SelectedIndex = 2 Then : PA49 = 物料主項(1) : ElseIf 主項目_cb.SelectedIndex = 3 Then : PA49 = 物料主項(2)
                                ElseIf 主項目_cb.SelectedIndex = 4 Then : PA49 = 物料主項(3) : ElseIf 主項目_cb.SelectedIndex = 5 Then : PA49 = 物料主項(4)
                                ElseIf 主項目_cb.SelectedIndex = 6 Then : PA49 = 物料主項(5) : ElseIf 主項目_cb.SelectedIndex = 6 Then : PA49 = 物料主項(6)
                                ElseIf 主項目_cb.SelectedIndex = 6 Then : PA49 = 物料主項(7) : ElseIf 主項目_cb.SelectedIndex = 6 Then : PA49 = 物料主項(8)
                                ElseIf 主項目_cb.SelectedIndex = 6 Then : PA49 = 物料主項(9) : End If
                                式共用2() : SQL_物料資料庫_新增群組碼() : SET_新增按鈕程式共用3()
                                式共用2() : SQL_物料資料庫_新增群組碼_語轉1() : SET_新增按鈕程式共用3()
                                式共用2() : SQL_物料資料庫_新增群組碼_語轉2() : SET_新增按鈕程式共用3()
                                式共用2() : SQL_物料資料庫_新增群組碼_語轉3() : SET_新增按鈕程式共用2() : 新增群組_ts.Checked = True
                            End If
                        End If
                    End If
                End If
            End If : 式共用1() : Set_群組清單()
        End If
    End Sub
    Private Sub 群組修改_bt_Click(sender As Object, e As EventArgs) Handles 群組修改_bt.Click
        If 主項目_cb.Text = "" Then : MsgBox("主項目沒有選擇!!") : Else
            If 群組碼_tb.Text = "" Or 類別1_tb.Text = "" Or 類別2_tb.Text = "" Or 類別3_tb.Text = "" Then : MsgBox("資料有缺或有誤，請重新檢查!!") : Else
                式共用3() : SQL_物料資料庫_群組碼重複查詢_語轉反1() : CmdSet_For_dr()
                If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else : 式共用3() : SQL_物料資料庫_群組碼重複查詢_語轉反2() : CmdSet_For_dr()
                    If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else : 式共用3() : SQL_物料資料庫_群組碼重複查詢_語轉反3() : CmdSet_For_dr()
                        If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else
                            If 修改群組_ts.Checked = True Then : PA = InputBox("請輸入要修改的內容!!", "修改資料", 群組碼_tb.Text)
                            Else : PA = 群組碼_tb.Text : End If
                            If PA = "" Then : MsgBox("沒有輸入修改內容!!") : Else
                                If 主項目_cb.SelectedIndex = 0 Then : PA49 = "" : ElseIf 主項目_cb.SelectedIndex = 1 Then : PA49 = 物料主項(0)
                                ElseIf 主項目_cb.SelectedIndex = 2 Then : PA49 = 物料主項(1) : ElseIf 主項目_cb.SelectedIndex = 3 Then : PA49 = 物料主項(2)
                                ElseIf 主項目_cb.SelectedIndex = 4 Then : PA49 = 物料主項(3) : ElseIf 主項目_cb.SelectedIndex = 5 Then : PA49 = 物料主項(4)
                                ElseIf 主項目_cb.SelectedIndex = 6 Then : PA49 = 物料主項(5) : ElseIf 主項目_cb.SelectedIndex = 6 Then : PA49 = 物料主項(6)
                                ElseIf 主項目_cb.SelectedIndex = 6 Then : PA49 = 物料主項(7) : ElseIf 主項目_cb.SelectedIndex = 6 Then : PA49 = 物料主項(8)
                                ElseIf 主項目_cb.SelectedIndex = 6 Then : PA49 = 物料主項(9) : End If
                                式共用3() : SQL_物料資料庫_群組碼修改0_1() : CmdSet_For_dr() : 式共用3() : SQL_物料資料庫_群組碼修改0_2() : CmdSet_For_dr()
                                式共用3() : SQL_物料資料庫_群組碼修改0_3() : CmdSet_For_dr() : 式共用3() : SQL_物料資料庫_群組碼修改1() : CmdSet_For_dr()
                                式共用3() : SQL_物料資料庫_群組碼修改2() : CmdSet_For_dr() : 式共用3() : SQL_物料資料庫_群組碼修改3() : CmdSet_For_dr()
                                式共用3() : SQL_物料資料庫_群組碼修改4() : CmdSet_For_dr() : 式共用3() : SQL_物料資料庫_群組碼修改5() : CmdSet_For_dr()
                                式共用3() : SQL_物料資料庫_群組碼修改6() : CmdSet_For_dr() : 式共用3() : SQL_物料資料庫_群組碼修改7() : CmdSet_For_dr()
                                式共用3() : SQL_物料資料庫_群組碼修改8() : CmdSet_For_dr()
                                conn.Close() : MsgBox("存檔完成!!")
                            End If
                        End If
                    End If
                End If
            End If : 式共用1() : Set_群組清單()
        End If
    End Sub
    Private Sub 群組刪除_bt_Click(sender As Object, e As EventArgs) Handles 群組刪除_bt.Click
        輸入密碼.ShowDialog()
        If PA = "0003065795" Then : SQL_物料資料庫_群組碼刪除() : SET_刪除按鈕程式共用2() : SQL_物料資料庫_群組碼刪除_語轉() : SET_刪除按鈕程式共用1() : 式共用1() : Set_群組清單()
        Else : MsgBox("你沒有權限刪除群組!!") : End If
    End Sub
    '------------------------------------------------------------------------------------------------------------------------------------
    Private Sub 下載圖片_bt_Click(sender As Object, e As EventArgs) Handles 下載圖片_bt.Click
        If 圖檔編號_tb.Text = "" Then : MsgBox("選擇要下載的圖片!!") : Else
            With SaveFileDialog1 : .Filter = "所有文件(*.jpg)|*.jpg" : End With
            SaveFileDialog1.FileName = 品名2_tb.Text & "-" & Format(Today(), "yyyyMMdd") & ".jpg"
            SaveFileDialog1.ShowDialog() : 檔案路徑_tb.Text = SaveFileDialog1.FileName
            Dim ds1 As New DataSet : ds1.Clear() : PA3 = 圖檔編號_tb.Text : SQL_物料圖庫_圖檔讀取三() : da.Fill(ds1)
            If ds1.Tables(0).Rows.Count > 0 Then
                Dim imgData() As Byte
                imgData = ds1.Tables(0).Rows(0).Item("圖檔")
                Dim fs As FileStream
                fs = File.Create(檔案路徑_tb.Text, imgData.Length - 1)
                fs.Write(imgData, 0, imgData.Length - 1)
                fs.Close()
            End If : conn.Close() : MsgBox("下載完成!!")
        End If
    End Sub
    Private Sub 下載圖片1_bt_Click(sender As Object, e As EventArgs) Handles 下載圖片1_bt.Click
        If 群組圖片 = False Then : MsgBox("選擇要下載的圖片!!") : Else
            With SaveFileDialog1 : .Filter = "所有文件(*.jpg)|*.jpg" : End With
            SaveFileDialog1.FileName = 類別2_tb.Text & "-" & Format(Today(), "yyyyMMdd") & ".jpg"
            SaveFileDialog1.ShowDialog() : 檔案路徑_tb.Text = SaveFileDialog1.FileName
            Dim ds1 As New DataSet : ds1.Clear() : PA3 = 群組碼_tb.Text : SQL_物料圖庫_圖檔讀取四() : da.Fill(ds1)
            If ds1.Tables(0).Rows.Count > 0 Then
                Dim imgData() As Byte
                imgData = ds1.Tables(0).Rows(0).Item("圖片")
                Dim fs As FileStream
                fs = File.Create(檔案路徑_tb.Text, imgData.Length - 1)
                fs.Write(imgData, 0, imgData.Length - 1)
                fs.Close()
            End If : conn.Close() : MsgBox("下載完成!!")
        End If
    End Sub
    Private Sub 群組轉換_bt_Click(sender As Object, e As EventArgs) Handles 群組轉換_bt.Click
        Dim DF As Boolean = False
        For i As Integer = 0 To 物料編碼_dgv.Rows.Count - 1
            If 物料編碼_dgv("選擇", i).Value = True Then
                DF = True
            End If
        Next
        If DF = True Then
            If 新群組_cb.Text = "" Or 舊群組_cb.Text = "" Then : MsgBox("新舊群組都要選擇!!") : Else : 資料數 = 物料編碼_dgv.Rows.Count
                For i As Integer = 0 To 物料編碼_dgv.Rows.Count - 1 : MyMod.進度條()
                    If 物料編碼_dgv("選擇", i).Value = True Then
                        conn.Close() : dr.Close() : PA1 = 新群組_cb.Text : PA2 = 舊群組_cb.Text : PA3 = 物料編碼_dgv(1, i).Value.ToString
                        SQL_物料資料庫_群組碼批量修改1() : SQL_物料資料庫_群組碼批量修改2() : SQL_物料資料庫_群組碼批量修改3()
                        SQL_物料資料庫_群組碼批量修改4() : SQL_物料資料庫_群組碼批量修改5() : SQL_物料資料庫_群組碼批量修改6()
                        SQL_物料資料庫_群組碼批量修改_語轉1()
                    End If
                Next : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : 精準 = True : Set_清單1() : MsgBox("存檔完成!!") : 精準 = False
            End If
        Else : MsgBox("清單中沒有勾選要轉換群組的物料!!") : End If
    End Sub
    Private Sub 全部選擇_bt_Click(sender As Object, e As EventArgs) Handles 全部選擇_bt.Click
        If 批量選擇_ts.Checked = True Then : For i As Integer = 0 To 物料編碼_dgv.Rows.Count - 1 : 物料編碼_dgv.Rows(i).Cells(4).Value = True : Next i : End If
    End Sub
    Private Sub 全部取消_bt_Click(sender As Object, e As EventArgs) Handles 全部取消_bt.Click
        If 批量選擇_ts.Checked = True Then : For i As Integer = 0 To 物料編碼_dgv.Rows.Count - 1 : 物料編碼_dgv.Rows(i).Cells(4).Value = False : Next i : End If
    End Sub
    Private Sub 全部選擇1_bt_Click(sender As Object, e As EventArgs) Handles 全部選擇1_bt.Click
        For i As Integer = 0 To 物料明細2_dgv.Rows.Count - 1 : 物料明細2_dgv.Rows(i).Cells("選擇").Value = True : Next i
    End Sub
    Private Sub 全部取消1_bt_Click(sender As Object, e As EventArgs) Handles 全部取消1_bt.Click
        For i As Integer = 0 To 物料明細2_dgv.Rows.Count - 1 : 物料明細2_dgv.Rows(i).Cells("選擇").Value = False : Next i
    End Sub
    Private Sub 全部選擇2_bt_Click(sender As Object, e As EventArgs) Handles 全部選擇2_bt.Click
        For i As Integer = 0 To 物料明細3_dgv.Rows.Count - 1 : 物料明細3_dgv.Rows(i).Cells("選擇").Value = True : Next i
    End Sub
    Private Sub 全部取消2_bt_Click(sender As Object, e As EventArgs) Handles 全部取消2_bt.Click
        For i As Integer = 0 To 物料明細3_dgv.Rows.Count - 1 : 物料明細3_dgv.Rows(i).Cells("選擇").Value = False : Next i
    End Sub
    Private Sub 讀取無圖片資料_bt_Click(sender As Object, e As EventArgs) Handles 讀取無圖片資料_bt.Click
        BL1 = True : 精準 = True : Set_清單1() : 精準 = False
    End Sub
    Private Sub 物料原則新增_tb_Click(sender As Object, e As EventArgs) Handles 物料原則新增_tb.Click
        If 群組碼1_tb.Text = "" Or 物料原則_tb.Text = "" Or 品名1_tb.Text = "" Or 品名2_tb.Text = "" Or 品名3_tb.Text = "" Then : MsgBox("資料有缺或有誤，請重新檢查!!") : Else
            PA = 物料原則_tb.Text : SQL_物料資料庫_物料編碼庫重複確認()
            If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else : conn.Close() : dr.Close()
                PA1 = 群組碼1_tb.Text : PA2 = 物料原則_tb.Text : PA3 = 物料品名_tb.Text : PA4 = "PCS" : SQL_物料資料庫_物料編碼庫新增()
                PA = 物料原則_tb.Text : SQL_物料資料庫_物料編碼庫語轉重複確認()
                If dr.Read() Then : Else : SQL_物料資料庫_物料編碼庫新增_語轉1() : SQL_物料資料庫_物料編碼庫新增_語轉2() : SQL_物料資料庫_物料編碼庫新增_語轉3()
                    SQL_物料資料庫_物料圖片流水號最後一筆()
                    If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("圖片流水號").ToString, 8)) : Else : EDR = 0 : End If
                    conn.Close() : EDR += 1
                    If EDR < 10 Then : ESTR = "PG" & "0000000" & EDR : ElseIf EDR > 9 And EDR < 100 Then : ESTR = "PG" & "000000" & EDR
                    ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "PG" & "00000" & EDR : ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "PG" & "0000" & EDR
                    ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "PG" & "000" & EDR : ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "PG" & "00" & EDR
                    ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "PG" & "0" & EDR : ElseIf EDR > 9999999 Then : ESTR = "PG" & EDR : End If
                    圖檔編號_tb.Text = ESTR
                    PA49 = Str + "\LOGG.jpg" : SQL_物料資料庫_圖檔入系統() : conn.Close()
                End If : MsgBox("新增完成!!")
                規格表頭設定_bt.PerformClick()
            End If : 改料號原則_ts.Checked = False
        End If : Set_物料資訊控制表未新增()
    End Sub
    Private Sub 物料原則修改_tb_Click(sender As Object, e As EventArgs) Handles 修改品名後存檔_bt.Click
        If 群組碼1_tb.Text = "" Or 物料原則_tb.Text = "" Or 品名1_tb.Text = "" Or 品名2_tb.Text = "" Or 品名3_tb.Text = "" Then : MsgBox("資料有缺或有誤，請重新檢查!!") : Else
            If 改料號原則_ts.Checked = True Then : PA = 物料原則_tb.Text : SQL_物料資料庫_物料編碼庫重複確認()
                If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else
                    輸入密碼.ShowDialog()
                    If PA = "0003065795" Then
                        conn.Close() : dr.Close() : PA1 = 物料原則_tb.Text : PA2 = 物料品名_tb.Text : PA3 = 群組碼1_tb.Text : PA4 = 料號原則_tb.Text
                        SQL_物料資料庫_修改品名後存檔1() : SQL_物料資料庫_修改品名後存檔2() : SQL_物料資料庫_修改品名後存檔3()
                        SQL_物料資料庫_修改品名後存檔4() : SQL_物料資料庫_修改品名後存檔5() : SQL_物料資料庫_修改品名後存檔6()
                        PA = 物料原則_tb.Text : PA1 = 群組碼1_tb.Text : PA2 = 物料原則_tb.Text : SQL_物料資料庫_物料編碼庫語轉重複確認()
                        If dr.Read() Then : PA = 物料原則_tb.Text : PA3 = 群組碼1_tb.Text : PA4 = 物料原則_tb.Text
                            SQL_物料資料庫_修改品名後存檔_語轉1() : SQL_物料資料庫_修改品名後存檔_語轉2() : SQL_物料資料庫_修改品名後存檔_語轉3()
                        Else
                            SQL_物料資料庫_物料編碼庫新增_語轉1() : SQL_物料資料庫_物料編碼庫新增_語轉2() : SQL_物料資料庫_物料編碼庫新增_語轉3()
                        End If : Set_清單1() : MsgBox("存檔完成!!")
                    End If
                End If
            Else
                PA2 = 物料品名_tb.Text : PA3 = 群組碼1_tb.Text : PA4 = 料號原則_tb.Text
                SQL_物料編碼庫_品名修改() : conn.Close() : SQL_物料資訊控制表_品名修改() : conn.Close()
                PA = 物料原則_tb.Text : PA1 = 群組碼1_tb.Text : PA2 = 物料原則_tb.Text : SQL_物料資料庫_物料編碼庫語轉重複確認()
                If dr.Read() Then : PA = 物料原則_tb.Text : PA3 = 群組碼1_tb.Text : PA4 = 物料原則_tb.Text
                    SQL_物料資料庫_修改品名後存檔_語轉1() : SQL_物料資料庫_修改品名後存檔_語轉2() : SQL_物料資料庫_修改品名後存檔_語轉3()
                Else
                    SQL_物料資料庫_物料編碼庫新增_語轉1() : SQL_物料資料庫_物料編碼庫新增_語轉2() : SQL_物料資料庫_物料編碼庫新增_語轉3()
                End If

                For i As Integer = 0 To 物料編碼_dgv.Rows.Count - 1
                    If 物料編碼_dgv.Rows(i).Cells("單位").Value.ToString <> 物料編碼_存_dgv.Rows(i).Cells("單位").Value.ToString Then
                        物料編碼_dgv.Rows(i).Cells("存檔").Value = True
                    End If
                Next
                For i As Integer = 0 To 物料編碼_dgv.Rows.Count - 1 : 資料數 = 物料編碼_dgv.Rows.Count : MyMod.進度條()
                    If 物料編碼_dgv.Rows(i).Cells("存檔").Value = True Then
                        PA1 = 物料編碼_dgv.Rows(i).Cells("單位").Value.ToString : PA2 = 物料編碼_dgv.Rows(i).Cells("群組碼").Value.ToString
                        PA3 = 物料編碼_dgv.Rows(i).Cells("" & "料號原則" & "").Value.ToString
                        SQL_物料編碼庫_單位修改() : conn.Close()
                    End If
                    If 物料編碼_dgv("選擇", i).Value = True Then
                        PA2 = 物料編碼_dgv.Rows(i).Cells("" & "品名" & "").Value.ToString : PA3 = 物料編碼_dgv.Rows(i).Cells("群組碼").Value.ToString
                        PA4 = 物料編碼_dgv.Rows(i).Cells("" & "料號原則" & "").Value.ToString
                        SQL_物料編碼庫_品名修改() : conn.Close() : SQL_物料資訊控制表_品名修改() : conn.Close()
                    End If
                Next : 式共用1() : Set_清單1() : MsgBox("存檔完成!!") : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : 批量選擇_ts.Checked = False
            End If
        End If
    End Sub
    Private Sub 物料原則刪除_tb_Click(sender As Object, e As EventArgs) Handles 物料原則刪除_tb.Click
        輸入密碼.ShowDialog()
        If PA = "0003065795" Then
            訊息回應 = InputBox("確定要刪除該筆資料?、請輸入大寫 [YES] 來繼續後續動作!!")
            If 訊息回應 = "YES" Then : PA1 = 群組碼1_tb.Text : PA2 = 物料原則_tb.Text
                SQL_物料資料庫_物料編碼庫刪除() : SQL_物料資料庫_物料資訊控制表刪除3() : SQL_物料資料庫_物料規格表刪除()
                SQL_物料資料庫_物料圖庫刪除() : SQL_物料資料庫_物料規格表刪除_語轉() : MsgBox("刪除完成!!")
            End If : conn.Close() : 精準 = True : PA1 = 物料原則_tb.Text : Set_清單1() : 精準 = False
            群組碼10_tb.Text = "" : 物料原則_tb.Text = "" : B1_tb.Text = "" : B2_tb.Text = "" : B3_tb.Text = "" : B4_tb.Text = ""
            品名1_tb.Text = "" : 品名2_tb.Text = "" : 品名3_tb.Text = ""
        Else : MsgBox("你沒有權限刪除物料!!") : End If
    End Sub
    '------------------------------------------------------------------------------------------------------------------------------------
    Private Sub 圖檔入系統_bt_Click_1(sender As Object, e As EventArgs) Handles 圖檔入系統_bt.Click
        If 批量導入預設圖片_ch.Checked = False Then
            If 圖檔編號_tb.Text = "" Then
                SQL_物料資料庫_物料圖片流水號最後一筆()
                If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("圖片流水號").ToString, 8)) : Else : EDR = 0 : End If
                conn.Close() : EDR += 1
                If EDR < 10 Then : ESTR = "PG" & "0000000" & EDR : ElseIf EDR > 9 And EDR < 100 Then : ESTR = "PG" & "000000" & EDR
                ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "PG" & "00000" & EDR : ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "PG" & "0000" & EDR
                ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "PG" & "000" & EDR : ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "PG" & "00" & EDR
                ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "PG" & "0" & EDR : ElseIf EDR > 9999999 Then : ESTR = "PG" & EDR : End If
                圖檔編號_tb.Text = ESTR

                If 檔案名稱_tb.Text = "" Then : MsgBox("請先確定圖片資料已準備完畢!!") : Else
                    Dim 驗證 As String = "" : Dim 取變數 As String : 取變數 = Strings.StrReverse(檔案名稱_tb.Text)
                    For i As Integer = 1 To 10
                        If i = 1 Then : 驗證 = Strings.Left(取變數, i) : Else
                            If Strings.Mid(取變數, i, 1) = "." Then : 驗證 = Strings.StrReverse(驗證) : Exit For : Else : 驗證 &= Strings.Mid(取變數, i, 1) : End If
                        End If
                    Next
                    If 驗證 = "PNG" Or 驗證 = "png" Or 驗證 = "GIF" Or 驗證 = "gif" Or 驗證 = "BMP" Or 驗證 = "bmp" Or 驗證 = "JPG" Or 驗證 = "jpg" Or 驗證 = "JPEG" Or 驗證 = "jpeg" Then
                        PA49 = 檔案路徑_be.Text : SQL_物料資料庫_圖檔入系統() : conn.Close() : MsgBox("上傳完畢!!")
                    Else : MsgBox("上傳文件並非常用圖片格式，文件已自動刪除，請專換成常用圖片檔案再行操作!!") : End If : 檔案名稱_tb.Text = "" : Set_清單1() : 圖檔編號_tb.Text = ""
                End If
            Else : MsgBox("該欄位已經有物料圖片無法再加入圖片!!") : End If
        Else
            If 檔案名稱_tb.Text = "" Then : MsgBox("請先確定圖片資料已準備完畢!!") : Else
                Dim 驗證 As String = "" : Dim 取變數 As String : 取變數 = Strings.StrReverse(檔案名稱_tb.Text)
                For II As Integer = 1 To 10
                    If II = 1 Then : 驗證 = Strings.Left(取變數, II) : Else
                        If Strings.Mid(取變數, II, 1) = "." Then : 驗證 = Strings.StrReverse(驗證) : Exit For : Else : 驗證 &= Strings.Mid(取變數, II, 1) : End If
                    End If
                Next
                If 驗證 = "PNG" Or 驗證 = "png" Or 驗證 = "GIF" Or 驗證 = "gif" Or 驗證 = "BMP" Or 驗證 = "bmp" Or 驗證 = "JPG" Or 驗證 = "jpg" Or 驗證 = "JPEG" Or 驗證 = "jpeg" Then
                    For I As Integer = 0 To 物料編碼_dgv.Rows.Count - 1
                        If 物料編碼_dgv("Image No", I).Value.ToString = "" Then
                            SQL_物料資料庫_物料圖片流水號最後一筆()
                            If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("圖片流水號").ToString, 8)) : Else : EDR = 0 : End If
                            conn.Close() : EDR += 1
                            If EDR < 10 Then : ESTR = "PG" & "0000000" & EDR : ElseIf EDR > 9 And EDR < 100 Then : ESTR = "PG" & "000000" & EDR
                            ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "PG" & "00000" & EDR : ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "PG" & "0000" & EDR
                            ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "PG" & "000" & EDR : ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "PG" & "00" & EDR
                            ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "PG" & "0" & EDR : ElseIf EDR > 9999999 Then : ESTR = "PG" & EDR : End If
                            圖檔編號_tb.Text = ESTR
                            PA49 = 檔案路徑_be.Text : PA20 = 圖檔編號_tb.Text : PA21 = 物料編碼_dgv("群組碼", I).Value.ToString : PA22 = 物料編碼_dgv("料號原則", I).Value.ToString
                            SQL_物料資料庫_圖檔入系統1() : conn.Close() : 圖檔編號_tb.Text = ""
                        End If
                    Next : MsgBox("上傳完畢!!") : Set_清單1()
                Else : MsgBox("上傳文件並非常用圖片格式，文件已自動刪除，請專換成常用圖片檔案再行操作!!") : End If
            End If
        End If
    End Sub
    Private Sub 圖檔入系統1_bt_Click(sender As Object, e As EventArgs) Handles 圖檔入系統1_bt.Click
        圖片修改1_bt.PerformClick()
    End Sub
    Private Sub 圖片修改_bt_Click(sender As Object, e As EventArgs) Handles 圖片修改_bt.Click
        If 圖檔編號_tb.Text = "" Then : MsgBox("請先將要入系統的編號準備好!!") : Else
            If 檔案名稱_tb.Text = "" Then : MsgBox("請先確定圖片資料已準備完畢!!") : Else
                Dim 驗證 As String = "" : Dim 取變數 As String : 取變數 = Strings.StrReverse(檔案名稱_tb.Text)
                For i As Integer = 1 To 10
                    If i = 1 Then : 驗證 = Strings.Left(取變數, i) : Else
                        If Strings.Mid(取變數, i, 1) = "." Then : 驗證 = Strings.StrReverse(驗證) : Exit For : Else : 驗證 &= Strings.Mid(取變數, i, 1) : End If
                    End If
                Next

                If 驗證 = "PNG" Or 驗證 = "png" Or 驗證 = "GIF" Or 驗證 = "gif" Or 驗證 = "BMP" Or 驗證 = "bmp" Or 驗證 = "JPG" Or 驗證 = "jpg" Or 驗證 = "JPEG" Or 驗證 = "jpeg" Then
                    Dim FG As Integer : SQL_物料圖庫_圖片版本() : If dr.Read Then : FG = Strings.Mid(dr("版本").ToString, 2, 2) + 1 : End If
                    If FG < 10 Then : PA48 = "V0" & FG : Else : PA48 = "V" & FG : End If
                    PA49 = 檔案路徑_be.Text : SQL_物料圖庫_圖片修改() : conn.Close() : MsgBox("存檔完成!!")
                Else : MsgBox("上傳文件並非常用圖片格式，文件已自動刪除，請專換成常用圖片檔案再行操作!!") : End If : 檔案名稱_tb.Text = "" : Set_清單1() : 圖檔編號_tb.Text = ""
            End If
        End If
    End Sub
    Private Sub 圖片修改1_bt_Click(sender As Object, e As EventArgs) Handles 圖片修改1_bt.Click
        If 群組碼_tb.Text = "" Then : MsgBox("請先將要入系統的編號準備好!!") : Else
            If 檔案名稱1_tb.Text = "" Then : MsgBox("請先確定圖片資料已準備完畢!!") : Else
                Dim 驗證 As String = "" : Dim 取變數 As String : 取變數 = Strings.StrReverse(檔案名稱1_tb.Text)
                For i As Integer = 1 To 10
                    If i = 1 Then : 驗證 = Strings.Left(取變數, i) : Else
                        If Strings.Mid(取變數, i, 1) = "." Then : 驗證 = Strings.StrReverse(驗證) : Exit For : Else : 驗證 &= Strings.Mid(取變數, i, 1) : End If
                    End If
                Next
                If 驗證 = "PNG" Or 驗證 = "png" Or 驗證 = "GIF" Or 驗證 = "gif" Or 驗證 = "BMP" Or 驗證 = "bmp" Or 驗證 = "JPG" Or 驗證 = "jpg" Or 驗證 = "JPEG" Or 驗證 = "jpeg" Then
                    Dim FG As Integer : SQL_物料圖庫_群組圖片版本()
                    If dr.Read Then
                        If dr("版本").ToString = "" Then : FG = 0 : Else : FG = Strings.Mid(dr("版本").ToString, 2, 2) + 1 : End If
                    End If
                    If FG < 10 Then : PA48 = "V0" & FG : Else : PA48 = "V" & FG : End If
                    PA49 = 檔案路徑_be.Text : SQL_物料圖庫_群組圖片修改() : conn.Close() : 檔案名稱1_tb.Text = "" : MsgBox("存檔完成!!") : Set_群組清單()
                Else : MsgBox("上傳文件並非常用圖片格式，文件已自動刪除，請專換成常用圖片檔案再行操作!!") : End If
            End If
        End If
    End Sub
    Private Sub 刪除圖檔_bt_Click(sender As Object, e As EventArgs) Handles 刪除圖檔_bt.Click
        輸入密碼.ShowDialog()
        If PA = "0003065795" Then : 訊息回應 = InputBox("確定要刪除該筆資料?、請輸入大寫 [YES] 來繼續後續動作!!")
            If 訊息回應 = "YES" Then : SQL_物料資料庫_物料圖庫() : Set_清單1() : 圖檔編號_tb.Text = "" : End If
        Else : MsgBox("你沒有權限刪除圖片!!") : End If
    End Sub
    '------------------------------------------------------------------------------------------------------------------------------------
    Private Sub 規格表頭新增_tb_Click(sender As Object, e As EventArgs) Handles 規格表頭新增_tb.Click
        If 規格庫抬頭指定_tb.Text = "" Or A1_tb.Text = "" Or A2_tb.Text = "" Or A3_tb.Text = "" Then : MsgBox("資料有缺或有誤，請重新檢查!!") : Else
            SQL_物料資料庫_規格庫抬頭指定重複查詢()
            If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else : conn.Close() : dr.Close()
                For I As Integer = 1 To 3
                    If I = 1 Then : PA = "繁體中文" : ElseIf I = 2 Then : PA = "English" : ElseIf I = 3 Then : PA = "Indonesian" : End If : SQL_物料資料庫_規格庫抬頭指定新增()
                Next : conn.Close() : dr.Close() : MsgBox("新增完成!!")
            End If
        End If : Set_物料規格庫() : 規格庫抬頭指定_cb_下拉表單資料載入()
    End Sub
    Private Sub 規格表頭修改_tb_Click(sender As Object, e As EventArgs) Handles 規格表頭修改_tb.Click
        If 規格庫抬頭指定_tb.Text = "" Or A1_tb.Text = "" Or A2_tb.Text = "" Or A3_tb.Text = "" Then : MsgBox("資料有缺或有誤，請重新檢查!!") : Else
            SQL_物料資料庫_規格庫抬頭指定修改() : conn.Close() : MsgBox("存檔完成!!")
        End If : Set_物料規格庫() : 規格庫抬頭指定_cb_下拉表單資料載入()
    End Sub
    Private Sub 規格表頭刪除_tb_Click(sender As Object, e As EventArgs) Handles 規格表頭刪除_tb.Click
        輸入密碼.ShowDialog()
        If PA = "0003065795" Then
            If 物料編碼_dgv.Rows.Count <> 0 Then : MsgBox("料號修改對於整個物料系統是很重要的決定，為確保系統運作不崩潰，請聯繫老闆或是系統開發人員!!") : Else
                訊息回應 = InputBox("確定要刪除該筆資料?、請輸入大寫 [YES] 來繼續後續動作!!")
                If 訊息回應 = "YES" Then : SQL_物料資料庫_規格庫抬頭指定刪除() : MsgBox("刪除完成!!") : End If
                conn.Close() : Set_物料規格庫() : 規格庫抬頭指定_cb_下拉表單資料載入()
            End If
        Else : MsgBox("你沒有權限刪除規格表頭!!") : End If
    End Sub
    '------------------------------------------------------------------------------------------------------------------------------------
    Private Sub 新增物料資訊_bt_Click(sender As Object, e As EventArgs) Handles 新增物料資訊_bt.Click
        If 群組碼2_tb.Text = "" Or 物料原則2_tb.Text = "" Or 原則說明_tb.Text = "" Or 規格庫編號1_cb.Text = "" Or 規格庫抬頭指定1_cb.Text = "" Then : MsgBox("資料有缺或有誤，請重新檢查!!") : Else
            式共用3() : SQL_物料資料庫_物料資訊控制表重複查詢() : CmdSet_For_dr()
            If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查!!") : conn.Close() : dr.Close() : Else
                式共用2() : PA6 = 原則說明_tb.Text : PA7 = 群組碼2_tb.Text : PA8 = 物料原則2_tb.Text : PA9 = 規格庫編號1_cb.Text : PA10 = 規格庫抬頭指定1_cb.Text
                SQL_物料資料庫_物料資訊控制表新增() : SET_新增按鈕程式共用2()
            End If
        End If : Set_物料資訊控制表未新增() : 精準 = True : PA1 = 物料原則_tb.Text : Set_清單1() : Cancel1_bt.PerformClick() : 精準 = False
    End Sub
    Private Sub 修改物料資訊_bt_Click(sender As Object, e As EventArgs) Handles 修改物料資訊_bt.Click
        If 群組碼2_tb.Text = "" Or 物料原則2_tb.Text = "" Or 原則說明_tb.Text = "" Or 規格庫編號1_cb.Text = "" Or
            規格庫抬頭指定_cb.Text = "" Or 規格庫編號_cb.Text = "" Or 規格庫抬頭指定1_cb.Text = "" Then : MsgBox("資料有缺或有誤，請重新檢查!!")
        Else
            訊息回應 = InputBox("確定要修改這筆資料?、請輸入大寫 [YES] 來繼續後續動作!!")
            If 訊息回應 = "YES" Then : SQL_物料資訊控制表_資訊修改() : conn.Close() : MsgBox("存檔完成!!") : End If : 式共用1()
        End If
    End Sub
    Private Sub 刪除物料資訊_bt_Click(sender As Object, e As EventArgs) Handles 刪除物料資訊_bt.Click
        If Val(登入人級別) = 0 Then : SQL_物料資料庫_物料資訊控制表刪除() : SET_刪除按鈕程式共用1() : Else : MsgBox("請聯繫系統開發商!!") : End If
    End Sub
    '------------------------------------------------------------------------------------------------------------------------------------
    Private Sub 修改物料規格_存量存檔_bt_Click(sender As Object, e As EventArgs) Handles 修改物料規格_存量存檔_bt.Click
        For i As Integer = 0 To 物料明細1_dgv.Rows.Count - 1
            資料數 = 物料明細1_dgv.Rows.Count : MyMod.進度條()
            PA1 = 物料明細1_dgv(4, i).Value.ToString : PA2 = 物料明細1_dgv(5, i).Value.ToString : PA3 = 物料明細1_dgv(6, i).Value.ToString
            PA4 = 物料明細1_dgv(7, i).Value.ToString : PA5 = 物料明細1_dgv(8, i).Value.ToString : PA6 = 物料明細1_dgv(9, i).Value.ToString
            PA7 = 物料明細1_dgv(10, i).Value.ToString : PA8 = 物料明細1_dgv(11, i).Value.ToString : PA9 = 物料明細1_dgv.Rows(i).Cells("最低庫存量").Value
            PA10 = 物料明細1_dgv.Rows(i).Cells("最高庫存量").Value : PA11 = 物料明細1_dgv.Rows(i).Cells("料號").Value
            PA12 = 物料明細1_dgv.Rows(i).Cells("No").Value : SQL_物料規格表_修改() : conn.Close()
        Next : MsgBox("存檔完成!!") : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
    End Sub
    Private Sub 新增物料料號_bt_Click(sender As Object, e As EventArgs) Handles 新增物料料號_bt.Click
        If 料號原則2_tb.Text = "" Then : MsgBox("請先選擇物料，確定物料原則之後才能自動生成編號!!") : Else
            If 兩碼_ch.Checked = True And 四碼_ch.Checked = False Then
                Dim 進位 As Integer : PA = 料號原則2_tb.Text : SQL_物料規格表_後兩碼()
                If dr.Read() Then : 進位 = Val(dr("後兩碼")) + 1
                    If 進位 < 10 Then : 原始料號_tb.Text = "0" & 進位
                    ElseIf 進位 > 9 And 進位 < 100 Then : 原始料號_tb.Text = 進位 : End If
                Else : 原始料號_tb.Text = "00" : End If : conn.Close()
            Else
                Dim 進位 As Integer : PA = 料號原則2_tb.Text : SQL_物料規格表_後四碼()
                If dr.Read() Then : 進位 = Val(dr("後四碼")) + 1
                    If 進位 < 10 Then : 原始料號_tb.Text = "000" & 進位
                    ElseIf 進位 > 9 And 進位 < 100 Then : 原始料號_tb.Text = "00" & 進位
                    ElseIf 進位 > 99 And 進位 < 1000 Then : 原始料號_tb.Text = "0" & 進位
                    ElseIf 進位 > 999 Then : 原始料號_tb.Text = 進位 : End If
                Else : 原始料號_tb.Text = "0001" : End If : conn.Close()
            End If

            PA1 = 料號原則2_tb.Text : PA2 = 原始料號_tb.Text : PA3 = 群組碼4_tb.Text : PA4 = 料號原則2_tb.Text
            PA5 = AA1_tb.Text : PA6 = AA2_tb.Text : PA7 = AA3_tb.Text : PA8 = AA4_tb.Text : PA9 = AA5_tb.Text : PA10 = AA6_tb.Text : PA11 = AA7_tb.Text : PA12 = AA8_tb.Text
            If 兩碼_ch.Checked = True And 四碼_ch.Checked = False Then : PA50 = PA1 & "-" & PA2 : Else : PA50 = PA1 & PA2 : End If

            SQL_物料規格表_料號查詢()
            If dr.Read() Then : conn.Close() : MsgBox("請注意，料號重複，無法存檔!!") : Else
                SQL_物料規格表_新增() : conn.Close() : MsgBox("存檔完成!!")
                PA2 = 料號原則2_tb.Text : PA3 = 規格庫抬頭指定2_cb.Text : 讀取料號規格_01() : 讀取料號規格_02()
            End If : AA1_tb.Text = "" : AA2_tb.Text = "" : AA3_tb.Text = "" : AA4_tb.Text = "" : AA5_tb.Text = "" : AA6_tb.Text = "" : AA7_tb.Text = "" : AA8_tb.Text = ""
        End If
    End Sub
    Private Sub 刪除料號_bt_Click(sender As Object, e As EventArgs) Handles 刪除料號_bt.Click
        If Val(登入人級別) = 1 Or Val(登入人級別) = 0 Then
            Dim 料號 As String = 料號tb.Text
            For Each 行 As DataGridViewRow In 料號使用_dgv.Rows  ' 檢查該行的第5列是否包含與料號相同的資料
                If 行.Cells(5).Value IsNot Nothing AndAlso 行.Cells(5).Value.ToString() = 料號 Then
                    MsgBox("該料號已被使用，無法刪除!!") : Exit Sub
                End If
            Next
            PA1 = 料號tb.Text : SQL_物料規格表_刪除() : conn.Close() : MsgBox("刪除完成!!")
            PA2 = 料號原則2_tb.Text : PA3 = 規格庫抬頭指定2_cb.Text : 讀取料號規格_01() : 讀取料號規格_02()
        Else : MsgBox("料號修改對於整個物料系統是很重要的決定，為確保系統運作不崩潰，請聯繫老闆或是系統開發人員!!") : End If
    End Sub
    Private Sub 料號修改_bt_Click(sender As Object, e As EventArgs) Handles 料號修改_bt.Click
        EDR = Val(編碼_tb.Text)
        If Val(登入人級別) = 1 Or Val(登入人級別) = 0 Then
            For i As Integer = 0 To 物料明細1_dgv.Rows.Count - 1 : EDR += 1
                If EDR < 10 Then : ESTR = "000" & EDR : ElseIf EDR > 9 And EDR < 100 Then : ESTR = "00" & EDR
                ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "0" & EDR : ElseIf EDR > 999 Then : ESTR = EDR : End If
                物料明細1_dgv.Rows(i).Cells("料號").Value = 料號原則2_tb.Text & "-" & ESTR
            Next
        Else : MsgBox("料號修改對於整個物料系統是很重要的決定，為確保系統運作不崩潰，請聯繫老闆或是系統開發人員!!") : End If
    End Sub
    Private Sub 料號修改存檔_bt_Click(sender As Object, e As EventArgs) Handles 料號修改存檔_bt.Click
        If Val(登入人級別) = 1 Or Val(登入人級別) = 0 Then : 資料數 = 物料明細1_dgv.Rows.Count
            For i As Integer = 0 To 物料明細1_dgv.Rows.Count - 1 : MyMod.進度條()
                PA10 = 物料明細1_dgv.Rows(i).Cells("料號").Value : PA11 = 物料明細1_dgv.Rows(i).Cells("原始料號").Value
                SQL_合約試算明細表_料號修改() : SQL_物料規格表_料號修改() : SQL_倉儲明細表_料號修改() : SQL_請購單明細表_料號修改() : SQL_採購單明細表_料號修改() : conn.Close()
            Next : MsgBox("存檔完成!!") : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
        Else : MsgBox("料號修改對於整個物料系統是很重要的決定，為確保系統運作不崩潰，請聯繫老闆或是系統開發人員!!") : End If
    End Sub
    Private Sub 資料複製_bt_Click(sender As Object, e As EventArgs) Handles 資料複製_bt.Click
        If 料號原則3_tb.Text = "" Then : MsgBox("請先選擇物料，確定物料原則之後才能自動生成編號!!") : Else
            Dim 進位 As Integer : PA = 料號原則3_tb.Text : PA1 = 料號原則3_tb.Text : PA3 = 群組碼5_tb.Text : PA4 = 料號原則3_tb.Text
            For I As Integer = 0 To 物料明細2_dgv.Rows.Count - 1
                資料數 = 物料明細2_dgv.Rows.Count : MyMod.進度條()
                If 物料明細2_dgv(15, I).Value = True Then : SQL_物料規格表_後四碼()
                    If dr.Read() Then : 進位 = Val(dr("後四碼")) + 1
                        If 進位 < 10 Then : 原始料號1_tb.Text = "000" & 進位 : ElseIf 進位 > 9 And 進位 < 100 Then : 原始料號1_tb.Text = "00" & 進位
                        ElseIf 進位 > 99 And 進位 < 1000 Then : 原始料號1_tb.Text = "0" & 進位 : ElseIf 進位 > 999 Then : 原始料號1_tb.Text = 進位 : End If
                    Else : 原始料號1_tb.Text = "0001" : End If : conn.Close()
                    PA2 = 原始料號1_tb.Text
                    PA5 = 物料明細2_dgv(4, I).Value.ToString : PA6 = 物料明細2_dgv(5, I).Value.ToString : PA7 = 物料明細2_dgv(6, I).Value.ToString : PA8 = 物料明細2_dgv(7, I).Value.ToString
                    PA9 = 物料明細2_dgv(8, I).Value.ToString : PA10 = 物料明細2_dgv(9, I).Value.ToString : PA11 = 物料明細2_dgv(10, I).Value.ToString : PA12 = 物料明細2_dgv(11, I).Value.ToString
                    If 兩碼_ch.Checked = True And 四碼_ch.Checked = False Then : PA50 = PA1 & "-" & PA2 : Else : PA50 = PA1 & PA2 : End If
                    SQL_物料規格表_料號查詢() : If dr.Read() Then : conn.Close() : Else : SQL_物料規格表_新增() : conn.Close() : End If
                End If
            Next : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
            PA2 = 料號原則3_tb.Text : PA3 = 規格庫抬頭指定4_cb.Text : 讀取料號規格_01() : 讀取料號規格_03() : MsgBox("存檔完成!!")
        End If
    End Sub
    Private Sub 批量刪除_bt_Click(sender As Object, e As EventArgs) Handles 批量刪除_bt.Click
        If 料號原則3_tb.Text = "" Then : MsgBox("沒有選擇物料!!") : Else
            訊息回應 = InputBox("確定要刪除該筆資料?、請輸入大寫 [YES] 來繼續後續動作!!")
            If 訊息回應 = "YES" Then
                For i As Integer = 0 To 物料明細3_dgv.Rows.Count - 1
                    If 物料明細3_dgv("選擇", i).Value = True Then : PA = 物料明細3_dgv("料號", i).Value.ToString : SQL_物料資料庫_物料資訊控制表刪除1() : End If
                Next : MsgBox("刪除完成!!")
            End If : conn.Close() : PA2 = 料號原則3_tb.Text : PA3 = 規格庫抬頭指定4_cb.Text : 讀取料號規格_01() : 讀取料號規格_03() : MsgBox("存檔完成!!")
        End If
    End Sub
    Private Sub 資料複製1_bt_Click(sender As Object, e As EventArgs) Handles 資料複製1_bt.Click
        If 料號原則5_tb.Text = "" Or 物料品名2_tb.Text = "" Then : MsgBox("資料有缺或有誤，請重新檢查!!") : Else
            PA = 料號原則5_tb.Text : SQL_物料資料庫_物料編碼庫重複確認()
            If dr.Read() Then : MsgBox("資料重複，請從新輸入或檢查?") : conn.Close() : dr.Close() : Else
                conn.Close() : dr.Close() : PA1 = 群組碼6_tb.Text : PA2 = 料號原則5_tb.Text : PA3 = 物料品名2_tb.Text : PA4 = "PCS" : SQL_物料資料庫_物料編碼庫新增()
                PA1 = 單位_tb.Text : PA2 = 群組碼6_tb.Text : PA3 = 料號原則5_tb.Text : SQL_物料編碼庫_單位修改()

                Dim 舊圖檔 As String = 圖檔編號1_tb.Text : SQL_物料資料庫_物料圖片流水號最後一筆()
                If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("圖片流水號").ToString, 8)) : Else : EDR = 0 : End If : conn.Close() : EDR += 1
                If EDR < 10 Then : ESTR = "PG" & "0000000" & EDR : ElseIf EDR > 9 And EDR < 100 Then : ESTR = "PG" & "000000" & EDR
                ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "PG" & "00000" & EDR : ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "PG" & "0000" & EDR
                ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "PG" & "000" & EDR : ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "PG" & "00" & EDR
                ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "PG" & "0" & EDR : ElseIf EDR > 9999999 Then : ESTR = "PG" & EDR : End If
                圖檔編號1_tb.Text = ESTR

                PA4 = 舊圖檔 : PA5 = 圖檔編號1_tb.Text : PA2 = 料號原則5_tb.Text : SQL_物料資料庫_複製圖檔()
                PA6 = 物料品名2_tb.Text : PA7 = 群組碼6_tb.Text : PA8 = 料號原則5_tb.Text : PA9 = 規格庫編號5_cb.Text : PA10 = 規格庫抬頭指定5_cb.Text
                式共用2() : SQL_物料資料庫_物料資訊控制表新增() : SET_新增按鈕程式共用3()

                Dim 進位 As Integer : PA = 料號原則5_tb.Text : PA1 = 料號原則5_tb.Text : PA3 = 群組碼6_tb.Text : PA4 = 料號原則5_tb.Text : 資料數 = 物料明細4_dgv.Rows.Count
                For I As Integer = 0 To 物料明細4_dgv.Rows.Count - 1 : MyMod.進度條()
                    SQL_物料規格表_後四碼()
                    If dr.Read() Then : 進位 = Val(dr("後四碼")) + 1
                        If 進位 < 10 Then : 原始料號2_tb.Text = "000" & 進位 : ElseIf 進位 > 9 And 進位 < 100 Then : 原始料號2_tb.Text = "00" & 進位
                        ElseIf 進位 > 99 And 進位 < 1000 Then : 原始料號2_tb.Text = "0" & 進位 : ElseIf 進位 > 999 Then : 原始料號2_tb.Text = 進位 : End If
                    Else : 原始料號2_tb.Text = "0001" : End If : conn.Close()

                    PA2 = 原始料號2_tb.Text
                    PA5 = 物料明細4_dgv(4, I).Value.ToString : PA6 = 物料明細4_dgv(5, I).Value.ToString : PA7 = 物料明細4_dgv(6, I).Value.ToString : PA8 = 物料明細4_dgv(7, I).Value.ToString
                    PA9 = 物料明細4_dgv(8, I).Value.ToString : PA10 = 物料明細4_dgv(9, I).Value.ToString : PA11 = 物料明細4_dgv(10, I).Value.ToString : PA12 = 物料明細4_dgv(11, I).Value.ToString
                    If 兩碼_ch.Checked = True And 四碼_ch.Checked = False Then : PA50 = PA1 & "-" & PA2 : Else : PA50 = PA1 & PA2 : End If
                    SQL_物料規格表_料號查詢() : If dr.Read() Then : conn.Close() : Else : SQL_物料規格表_新增() : conn.Close() : End If
                Next : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : MsgBox("存檔完成!!") : conn.Close() : dr.Close()
                BL1 = True : PA1 = 群組碼6_tb.Text : 物料資訊控制表3() : PA1 = "" : BL1 = False
            End If
        End If
    End Sub
    Private Sub 小間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 小間距_ch.Click
        小間距_ch.Checked = True : 中間距_ch.Checked = False : 大間距_ch.Checked = False : Set_清單1()
    End Sub
    Private Sub 中間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 中間距_ch.Click
        小間距_ch.Checked = False : 中間距_ch.Checked = True : 大間距_ch.Checked = False : Set_清單1()
    End Sub
    Private Sub 大間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 大間距_ch.Click
        小間距_ch.Checked = False : 中間距_ch.Checked = False : 大間距_ch.Checked = True : Set_清單1()
    End Sub
    Private Sub 小間距1_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 小間距1_ch.Click
        小間距1_ch.Checked = True : 中間距1_ch.Checked = False : 大間距1_ch.Checked = False : PA2 = 料號原則2_tb.Text : PA3 = 規格庫抬頭指定2_cb.Text : 讀取料號規格_01() : 讀取料號規格_02()
    End Sub
    Private Sub 中間距1_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 中間距1_ch.Click
        小間距1_ch.Checked = False : 中間距1_ch.Checked = True : 大間距1_ch.Checked = False : PA2 = 料號原則2_tb.Text : PA3 = 規格庫抬頭指定2_cb.Text : 讀取料號規格_01() : 讀取料號規格_02()
    End Sub
    Private Sub 大間距1_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 大間距1_ch.Click
        小間距1_ch.Checked = False : 中間距1_ch.Checked = False : 大間距1_ch.Checked = True : PA2 = 料號原則2_tb.Text : PA3 = 規格庫抬頭指定2_cb.Text : 讀取料號規格_01() : 讀取料號規格_02()
    End Sub
    Private Sub 小間距2_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 小間距2_ch.Click
        小間距2_ch.Checked = True : 中間距2_ch.Checked = False : 大間距2_ch.Checked = False : BL1 = True : PA1 = 群組碼(1) : 物料資訊控制表1() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 中間距2_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 中間距2_ch.Click
        小間距2_ch.Checked = False : 中間距2_ch.Checked = True : 大間距2_ch.Checked = False : BL1 = True : PA1 = 群組碼(1) : 物料資訊控制表1() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 大間距2_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 大間距2_ch.Click
        小間距2_ch.Checked = False : 中間距2_ch.Checked = False : 大間距2_ch.Checked = True : BL1 = True : PA1 = 群組碼(1) : 物料資訊控制表1() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 小間距3_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 小間距3_ch.Click
        小間距3_ch.Checked = True : 中間距3_ch.Checked = False : 大間距3_ch.Checked = False : BL1 = True : PA1 = 群組碼(2) : 物料資訊控制表2() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 中間距3_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 中間距3_ch.Click
        小間距3_ch.Checked = False : 中間距3_ch.Checked = True : 大間距3_ch.Checked = False : BL1 = True : PA1 = 群組碼(2) : 物料資訊控制表2() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 大間距3_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 大間距3_ch.Click
        小間距3_ch.Checked = False : 中間距3_ch.Checked = False : 大間距3_ch.Checked = True : BL1 = True : PA1 = 群組碼(2) : 物料資訊控制表2() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 小間距4_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 小間距4_ch.Click
        小間距4_ch.Checked = True : 中間距4_ch.Checked = False : 大間距4_ch.Checked = False : BL1 = True : PA1 = 群組碼(3) : 物料資訊控制表3() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 中間距4_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 中間距4_ch.Click
        小間距4_ch.Checked = False : 中間距4_ch.Checked = True : 大間距4_ch.Checked = False : BL1 = True : PA1 = 群組碼(3) : 物料資訊控制表3() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 大間距4_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 大間距4_ch.Click
        小間距4_ch.Checked = False : 中間距4_ch.Checked = False : 大間距4_ch.Checked = True : BL1 = True : PA1 = 群組碼(3) : 物料資訊控制表3() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 小間距5_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 小間距5_ch.Click
        小間距5_ch.Checked = True : 中間距5_ch.Checked = False : 大間距5_ch.Checked = False : BL1 = True : PA1 = 群組碼(4) : 物料資訊控制表4() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 中間距5_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 中間距5_ch.Click
        小間距5_ch.Checked = False : 中間距5_ch.Checked = True : 大間距5_ch.Checked = False : BL1 = True : PA1 = 群組碼(4) : 物料資訊控制表4() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 大間距5_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 大間距5_ch.Click
        小間距5_ch.Checked = False : 中間距5_ch.Checked = False : 大間距5_ch.Checked = True : BL1 = True : PA1 = 群組碼(4) : 物料資訊控制表4() : PA1 = "" : BL1 = False
    End Sub
    Private Sub 批量選擇_ts_ValueChanged(sender As Object, e As EventArgs) Handles 批量選擇_ts.Click
        If 首次開啟 = True Then : Else
            If 批量選擇_ts.Checked = False Then : 物料編碼_dgv.Columns(1).ReadOnly = True : 物料編碼_dgv.Columns(2).ReadOnly = True
            Else : 物料編碼_dgv.Columns(1).ReadOnly = False : 物料編碼_dgv.Columns(2).ReadOnly = False : End If
        End If
    End Sub
    Private Sub Reset_bt_Click(sender As Object, e As EventArgs) Handles Reset_bt.Click
        Set_比對1() : Set_比對2() : Set_比對3() : Set_比對4() : Set_比對5() : Set_比對6() : Set_比對7() : Set_比對8() : Set_比對9() : Set_料號使用()
    End Sub
    Private Sub 修改群組_bt_Click(sender As Object, e As EventArgs) Handles 修改群組_bt.Click
        If 物料群組1_P.Visible = False Then : 物料群組1_P.Visible = True : 物料群組1_P.BringToFront()
            物料群組1_P.Location = New System.Drawing.Point((Panel8.Size.Width - 物料群組1_P.Size.Width) / 2, (Panel8.Size.Height - 物料群組1_P.Size.Height) / 2)
        Else : 物料群組1_P.Visible = False : End If
    End Sub
    Private Sub Cancel_bt_Click(sender As Object, e As EventArgs) Handles Cancel_bt.Click
        If 物料群組1_P.Visible = False Then : 物料群組1_P.Visible = True : 物料群組1_P.BringToFront() : Else : 物料群組1_P.Visible = False : End If
    End Sub
    Private Sub 新增圖號群組_bt_Click(sender As Object, e As EventArgs) Handles 新增圖號群組_bt.Click
        If 物料群組2_P.Visible = False Then
            PA21 = InputBox("請輸入9碼的設備群組編號 例如 : FH-024001")
            If Len(PA21) = 9 Then
                物料群組2_P.Visible = True : 物料群組2_P.BringToFront()
                物料群組2_P.Location = New System.Drawing.Point((Panel8.Size.Width - 物料群組2_P.Size.Width) / 2, (Panel8.Size.Height - 物料群組2_P.Size.Height) / 2)
                主項目2_cb.Text = 物料主項(0) : 主項目3_cb.Text = 物料主項(1) : 主項目4_cb.Text = 物料主項(2) : 主項目5_cb.Text = 物料主項(3)
                群組碼A_tb.Text = Strings.Right(主項目2_cb.Text, 3) & "-" & PA21 & "系列"
                群組碼B_tb.Text = Strings.Right(主項目3_cb.Text, 3) & "-" & PA21 & "系列"
                群組碼C_tb.Text = Strings.Right(主項目4_cb.Text, 3) & "-" & PA21 & "系列"
                群組碼D_tb.Text = Strings.Right(主項目5_cb.Text, 3) & "-" & PA21 & "系列"
            End If
        Else : 物料群組2_P.Visible = False : End If
    End Sub
    Private Sub Cancel2_bt_Click(sender As Object, e As EventArgs) Handles Cancel2_bt.Click
        If 物料群組2_P.Visible = False Then : 物料群組2_P.Visible = True : 物料群組2_P.BringToFront() : Else : 物料群組2_P.Visible = False : End If
    End Sub
    Private Sub 轉換_bt_Click(sender As Object, e As EventArgs) Handles 關鍵字查詢_bt.Click
        PA1 = InputBox("請輸入物料關鍵字") : 查詢_tb.Text = PA1 : 查詢 = True : Set_清單1() : 精準 = False
    End Sub
    Private Sub 關鍵字_bt_Click(sender As Object, e As EventArgs) Handles 關鍵字_bt.Click
        查詢 = True : Set_清單1()
    End Sub
    Private Sub S1_ch_CheckedChanged(sender As Object, e As EventArgs) Handles S1_ch.CheckedChanged
        For I As Integer = 0 To 物料明細5_dgv.Rows.Count - 1
            If 物料明細5_dgv(16, I).Value = True And 物料明細5_dgv(17, I).Value = True And 物料明細5_dgv(18, I).Value = True And 物料明細5_dgv(19, I).Value = True And
               物料明細5_dgv(20, I).Value = True And 物料明細5_dgv(21, I).Value = True And 物料明細5_dgv(22, I).Value = True And 物料明細5_dgv(23, I).Value = True Then
                物料明細5_dgv(16, I).Value = S1_ch.Checked
            End If
        Next
    End Sub
    Private Sub S2_ch_CheckedChanged(sender As Object, e As EventArgs) Handles S2_ch.CheckedChanged
        For I As Integer = 0 To 物料明細5_dgv.Rows.Count - 1
            If 物料明細5_dgv(16, I).Value = True And 物料明細5_dgv(17, I).Value = True And 物料明細5_dgv(18, I).Value = True And 物料明細5_dgv(19, I).Value = True And
               物料明細5_dgv(20, I).Value = True And 物料明細5_dgv(21, I).Value = True And 物料明細5_dgv(22, I).Value = True And 物料明細5_dgv(23, I).Value = True Then
                物料明細5_dgv(17, I).Value = S2_ch.Checked
            End If
        Next
    End Sub
    Private Sub S3_ch_CheckedChanged(sender As Object, e As EventArgs) Handles S3_ch.CheckedChanged
        For I As Integer = 0 To 物料明細5_dgv.Rows.Count - 1
            If 物料明細5_dgv(16, I).Value = True And 物料明細5_dgv(17, I).Value = True And 物料明細5_dgv(18, I).Value = True And 物料明細5_dgv(19, I).Value = True And
               物料明細5_dgv(20, I).Value = True And 物料明細5_dgv(21, I).Value = True And 物料明細5_dgv(22, I).Value = True And 物料明細5_dgv(23, I).Value = True Then
                物料明細5_dgv(18, I).Value = S3_ch.Checked
            End If
        Next
    End Sub
    Private Sub S4_ch_CheckedChanged(sender As Object, e As EventArgs) Handles S4_ch.CheckedChanged
        For I As Integer = 0 To 物料明細5_dgv.Rows.Count - 1
            If 物料明細5_dgv(16, I).Value = True And 物料明細5_dgv(17, I).Value = True And 物料明細5_dgv(18, I).Value = True And 物料明細5_dgv(19, I).Value = True And
               物料明細5_dgv(20, I).Value = True And 物料明細5_dgv(21, I).Value = True And 物料明細5_dgv(22, I).Value = True And 物料明細5_dgv(23, I).Value = True Then
                物料明細5_dgv(19, I).Value = S4_ch.Checked
            End If
        Next
    End Sub
    Private Sub S5_ch_CheckedChanged(sender As Object, e As EventArgs) Handles S5_ch.CheckedChanged
        For I As Integer = 0 To 物料明細5_dgv.Rows.Count - 1
            If 物料明細5_dgv(16, I).Value = True And 物料明細5_dgv(17, I).Value = True And 物料明細5_dgv(18, I).Value = True And 物料明細5_dgv(19, I).Value = True And
               物料明細5_dgv(20, I).Value = True And 物料明細5_dgv(21, I).Value = True And 物料明細5_dgv(22, I).Value = True And 物料明細5_dgv(23, I).Value = True Then
                物料明細5_dgv(20, I).Value = S5_ch.Checked
            End If
        Next
    End Sub
    Private Sub S6_ch_CheckedChanged(sender As Object, e As EventArgs) Handles S6_ch.CheckedChanged
        For I As Integer = 0 To 物料明細5_dgv.Rows.Count - 1
            If 物料明細5_dgv(16, I).Value = True And 物料明細5_dgv(17, I).Value = True And 物料明細5_dgv(18, I).Value = True And 物料明細5_dgv(19, I).Value = True And
               物料明細5_dgv(20, I).Value = True And 物料明細5_dgv(21, I).Value = True And 物料明細5_dgv(22, I).Value = True And 物料明細5_dgv(23, I).Value = True Then
                物料明細5_dgv(21, I).Value = S6_ch.Checked
            End If
        Next
    End Sub
    Private Sub S7_ch_CheckedChanged(sender As Object, e As EventArgs) Handles S7_ch.CheckedChanged
        For I As Integer = 0 To 物料明細5_dgv.Rows.Count - 1
            If 物料明細5_dgv(16, I).Value = True And 物料明細5_dgv(17, I).Value = True And 物料明細5_dgv(18, I).Value = True And 物料明細5_dgv(19, I).Value = True And
               物料明細5_dgv(20, I).Value = True And 物料明細5_dgv(21, I).Value = True And 物料明細5_dgv(22, I).Value = True And 物料明細5_dgv(23, I).Value = True Then
                物料明細5_dgv(22, I).Value = S7_ch.Checked
            End If
        Next
    End Sub
    Private Sub S8_ch_CheckedChanged(sender As Object, e As EventArgs) Handles S8_ch.CheckedChanged
        For I As Integer = 0 To 物料明細5_dgv.Rows.Count - 1
            If 物料明細5_dgv(16, I).Value = True And 物料明細5_dgv(17, I).Value = True And 物料明細5_dgv(18, I).Value = True And 物料明細5_dgv(19, I).Value = True And
               物料明細5_dgv(20, I).Value = True And 物料明細5_dgv(21, I).Value = True And 物料明細5_dgv(22, I).Value = True And 物料明細5_dgv(23, I).Value = True Then
                物料明細5_dgv(23, I).Value = S8_ch.Checked
            End If
        Next
    End Sub
    Private Sub SAVE_bt_Click(sender As Object, e As EventArgs) Handles SAVE_bt.Click
        資料數 = 物料明細5_dgv.Rows.Count
        For i As Integer = 0 To 物料明細5_dgv.Rows.Count - 1 : MyMod.進度條()
            PA1 = 物料明細5_dgv(16, i).Value.ToString : PA2 = 物料明細5_dgv(17, i).Value.ToString : PA3 = 物料明細5_dgv(18, i).Value.ToString
            PA4 = 物料明細5_dgv(19, i).Value.ToString : PA5 = 物料明細5_dgv(20, i).Value.ToString : PA6 = 物料明細5_dgv(21, i).Value.ToString
            PA7 = 物料明細5_dgv(22, i).Value.ToString : PA8 = 物料明細5_dgv(23, i).Value.ToString : PA11 = 物料明細5_dgv.Rows(i).Cells("料號").Value
            SQL_物料規格表_修改1() : conn.Close()
        Next : MsgBox("存檔完成!!") : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
    End Sub
    Private Sub 設定_bt_Click(sender As Object, e As EventArgs) Handles 設定_bt.Click
        For I As Integer = 0 To 物料明細5_dgv.Rows.Count - 1
            物料明細5_dgv(16, I).Value = S1_ch.Checked : 物料明細5_dgv(17, I).Value = S2_ch.Checked : 物料明細5_dgv(18, I).Value = S3_ch.Checked
            物料明細5_dgv(19, I).Value = S4_ch.Checked : 物料明細5_dgv(20, I).Value = S5_ch.Checked : 物料明細5_dgv(21, I).Value = S6_ch.Checked
            物料明細5_dgv(22, I).Value = S7_ch.Checked : 物料明細5_dgv(23, I).Value = S8_ch.Checked
        Next
    End Sub
    Private Sub 新增群組_ts_ValueChanged(sender As Object, e As EventArgs) Handles 新增群組_ts.Click
        If 首次開啟 = True Then : Else : If 新增群組_ts.Checked = True Then : 群組碼_tb.Enabled = True : Else : 群組碼_tb.Enabled = False : End If : End If
    End Sub
    Private Sub 修改群組_ts_CheckedChanged(sender As Object, e As EventArgs) Handles 修改群組_ts.Click
        If 首次開啟 = True Then : Else : If 修改群組_ts.Checked = True Then : 群組碼_tb.Enabled = True : Else : 群組碼_tb.Enabled = False : End If : End If
    End Sub
    Private Sub 規格庫編號_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 規格庫編號_cb.SelectedIndexChanged
        PA25 = Strings.Right(規格庫編號_cb.Text, 2) : SQL_物料資訊控制表_規格庫抬頭指定1() : 規格庫抬頭指定_cb.Items.Clear()
        While (dr.Read()) : 規格庫抬頭指定_cb.Items.Add(dr("規格庫抬頭指定")) : End While : conn.Close()
    End Sub
    Private Sub 規格庫編號1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 規格庫編號1_cb.SelectedIndexChanged
        PA25 = Strings.Right(規格庫編號1_cb.Text, 2) : SQL_物料資訊控制表_規格庫抬頭指定1() : 規格庫抬頭指定1_cb.Items.Clear()
        While (dr.Read()) : 規格庫抬頭指定1_cb.Items.Add(dr("規格庫抬頭指定")) : End While : conn.Close()
    End Sub
    Private Sub 賦歸_bt_Click(sender As Object, e As EventArgs) Handles 賦歸_bt.Click
        物料原則_tb.Text = "" : 物料品名_tb.Text = "" : 品名1_tb.Text = "" : 品名2_tb.Text = "" : 品名3_tb.Text = ""
    End Sub
    Private Sub 重讀_bt_Click(sender As Object, e As EventArgs) Handles 重讀_bt.Click
        CA_1.Text = "" : CA_2.Text = "" : CA_3.Text = "" : CA_4.Text = "" : CA_5.Text = "" : CB_1.Text = "" : CB_2.Text = "" : CB_3.Text = "" : CB_4.Text = "" : CB_5.Text = ""
        CC_1.Text = "" : CC_2.Text = "" : CC_3.Text = "" : CC_4.Text = "" : CC_5.Text = "" : 新群組編號_tb.Text = "" : Set_新群組清單()
    End Sub
    Private Sub 比對關鍵字_bt_Click(sender As Object, e As EventArgs) Handles 比對關鍵字_bt.Click
        If 重新計算 = True Then : lastFoundRowIndex = -1 : lastFoundColIndex = -1 : End If
        查詢DGV中的關鍵字_手動(規格表頭_dgv, 關鍵字_tb)
    End Sub
    Private Sub 一般模式_cb_Click(sender As Object, e As EventArgs) Handles 一般模式_cb.Click
        一般模式_cb.Checked = True : 編輯模式_cb.Checked = False
        If 新群組編號_tb.Text <> "" Then : Set_新群組清單_物料() : End If
    End Sub
    Private Sub 編輯模式_cb_Click(sender As Object, e As EventArgs) Handles 編輯模式_cb.Click
        一般模式_cb.Checked = False : 編輯模式_cb.Checked = True : Set_新群組清單_物料()
    End Sub
    Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        If 一般模式_cb.Checked = False Then : MsgBox("請將模式改回一般模式，才能進行編輯動作!!") : Else
            If 新群組_物料_dgv.Rows.Count > 0 Then : MsgBox("該資料已經有指定資料不可刪除!!") : Else
                If 新群組編號_tb.Text = "" Then : MsgBox("沒有選擇必要資料，請重新確認!!") : Else
                    輸入密碼.ShowDialog()
                    If PA = "0003065795" Then
                        訊息回應 = InputBox("確定要刪除該筆資料?、請輸入大寫 [YES] 來繼續後續動作!!")
                        If 訊息回應 = "YES" Then
                            PA10 = 新群組編號_tb.Text : SQL_新物料群組_刪除() : MsgBox("刪除完成!!") : Set_新群組清單()
                        End If
                    End If
                End If
            End If
        End If
    End Sub
    Private Sub 修改_bt_Click(sender As Object, e As EventArgs) Handles 修改_bt.Click
        If 新群組編號_tb.Text = "" Then : MsgBox("沒有選擇必要資料，請重新確認!!") : Else
            訊息回應 = InputBox("請確認是否要進行資料修正，如果要執行請輸入 [YES]")
            If 訊息回應 = "YES" Then
                PA10 = 新群組編號_tb.Text : PA20 = DA_1.Text : PA21 = DA_2.Text : PA22 = DA_3.Text : PA23 = DA_4.Text : PA24 = DA_5.Text : SQL_新物料群組_修改_中()
                PA10 = 新群組編號_tb.Text : PA20 = DB_1.Text : PA21 = DB_2.Text : PA22 = DB_3.Text : PA23 = DB_4.Text : PA24 = DB_5.Text : SQL_新物料群組_修改_英()
                PA10 = 新群組編號_tb.Text : PA20 = DC_1.Text : PA21 = DC_2.Text : PA22 = DC_3.Text : PA23 = DC_4.Text : PA24 = DC_5.Text : SQL_新物料群組_修改_印()
                MsgBox("修改完成!!") : Set_新群組清單()
            End If
        End If
    End Sub
    Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        If CA_1.Text = "" Or CA_2.Text = "" Or CA_3.Text = "" Or CA_4.Text = "" Or CA_5.Text = "" Or CB_1.Text = "" Or CB_2.Text = "" Or CB_3.Text = "" Or CB_4.Text = "" Or CB_5.Text = "" Or
           CC_1.Text = "" Or CC_2.Text = "" Or CC_3.Text = "" Or CC_4.Text = "" Or CC_5.Text = "" Then : MsgBox("資料有遺漏，請注意補齊，如果有空白的層級請填入 [NA]!!") : Else
            SQL_新物料群組_流水號()
            If dr.Read() Then : PA1 = dr("編號") : Else : PA1 = "HP001" : End If : conn.Close()
            Dim NUM1 As Integer = Strings.Right(PA1, 3) + 1
            If NUM1 < 10 Then : PA1 = "HP00" & NUM1
            ElseIf NUM1 > 9 And NUM1 < 100 Then : PA1 = "HP0" & NUM1
            ElseIf NUM1 > 99 And NUM1 < 1000 Then : PA1 = "HP" & NUM1 : End If
            新群組編號_tb.Text = PA1
            PA10 = 新群組編號_tb.Text : PA20 = DA_1.Text : PA21 = DA_2.Text : PA22 = DA_3.Text : PA23 = DA_4.Text : PA24 = DA_5.Text : PA11 = "繁體中文" : SQL_新物料群組_新增()
            PA10 = 新群組編號_tb.Text : PA20 = DB_1.Text : PA21 = DB_2.Text : PA22 = DB_3.Text : PA23 = DB_4.Text : PA24 = DB_5.Text : PA11 = "English" : SQL_新物料群組_新增()
            PA10 = 新群組編號_tb.Text : PA20 = DC_1.Text : PA21 = DC_2.Text : PA22 = DC_3.Text : PA23 = DC_4.Text : PA24 = DC_5.Text : PA11 = "Indonesian" : SQL_新物料群組_新增()
            MsgBox("新增完成!!") : Set_新群組清單()
        End If
    End Sub
    Private Sub 存檔_新群_bt_Click(sender As Object, e As EventArgs) Handles 存檔_新群_bt.Click
        資料數 = 新群組_物料_dgv.Rows.Count
        For I As Integer = 0 To 新群組_物料_dgv.Rows.Count - 1 : MyMod.進度條()
            If 新群組_物料_dgv("Keyword", I).Value.ToString = "" Then : Else
                PA10 = 新群組_物料_dgv("料號原則", I).Value.ToString : PA20 = 新群組_物料_dgv("Keyword", I).Value.ToString : SQL_新物料群組_指定修改()
            End If
        Next : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : MsgBox("修改完成!!") : Set_新群組清單_物料()
    End Sub
    Private Sub 品名1_tb_TextChanged(sender As Object, e As EventArgs) Handles 品名1_tb.TextChanged
        品名3_tb.Text = 品名1_tb.Text : 品名2_tb.Text = 品名1_tb.Text : 物料品名_tb.Text = 品名1_tb.Text
    End Sub
    Private Sub 類別1_tb_TextChanged(sender As Object, e As EventArgs) Handles 類別1_tb.TextChanged
        類別2_tb.Text = 類別1_tb.Text : 類別3_tb.Text = 類別1_tb.Text
    End Sub
    Private Sub 料號原則2_tb_TextChanged(sender As Object, e As EventArgs) Handles 料號原則2_tb.TextChanged
        Dim textLength As Integer = 料號原則2_tb.Text.Length
        If textLength <= 4 Then : 兩碼_ch.Checked = False : 四碼_ch.Checked = True : Else : 兩碼_ch.Checked = True : 四碼_ch.Checked = False : End If
    End Sub
    Private Sub 兩碼_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 兩碼_ch.Click
        兩碼_ch.Checked = True : 四碼_ch.Checked = False
    End Sub
    Private Sub 規格表頭設定_bt_Click(sender As Object, e As EventArgs) Handles 規格表頭設定_bt.Click
        If 規格表頭_P.Visible = False Then
            群組碼2_tb.Text = "" : 物料原則2_tb.Text = "" : 原則說明_tb.Text = "" : 規格表頭_P.Visible = True : 規格表頭_P.BringToFront()
            規格表頭_P.Location = New System.Drawing.Point((Panel8.Size.Width - 規格表頭_P.Size.Width) / 2, (Panel8.Size.Height - 規格表頭_P.Size.Height) / 2)
        Else : 規格表頭_P.Visible = False : End If
    End Sub
    Private Sub Cancel1_bt_Click(sender As Object, e As EventArgs) Handles Cancel1_bt.Click
        If 規格表頭_P.Visible = False Then : 規格表頭_P.Visible = True : 規格表頭_P.BringToFront() : Else : 規格表頭_P.Visible = False : End If
    End Sub
    Private Sub 四碼_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 四碼_ch.Click
        兩碼_ch.Checked = False : 四碼_ch.Checked = True
    End Sub
    Private Sub 主項目1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 主項目1_cb.SelectedIndexChanged
        Set_物料群組() : Set_物料群組_語轉()
    End Sub
    Private Sub 刷新_bt_Click(sender As Object, e As EventArgs) Handles 刷新_bt.Click
        CA_1.Text = "NA" : CA_2.Text = "NA" : CA_3.Text = "NA" : CA_4.Text = "NA" : CA_5.Text = "NA" : CB_1.Text = "NA" : CB_2.Text = "NA" : CB_3.Text = "NA"
        CB_4.Text = "NA" : CB_5.Text = "NA" : CC_1.Text = "NA" : CC_2.Text = "NA" : CC_3.Text = "NA" : CC_4.Text = "NA" : CC_5.Text = "NA"

        DA_1.Text = "NA" : DA_2.Text = "NA" : DA_3.Text = "NA" : DA_4.Text = "NA" : DA_5.Text = "NA" : DB_1.Text = "NA" : DB_2.Text = "NA" : DB_3.Text = "NA"
        DB_4.Text = "NA" : DB_5.Text = "NA" : DC_1.Text = "NA" : DC_2.Text = "NA" : DC_3.Text = "NA" : DC_4.Text = "NA" : DC_5.Text = "NA"
    End Sub
    Private Sub 查詢_bt_Click(sender As Object, e As EventArgs) Handles 查詢_bt.Click
        查詢DGV中的關鍵字_手動(物料明細1_dgv, 查詢_tb)
    End Sub
    Private Sub 市構件_bt_Click(sender As Object, e As EventArgs) Handles 市構件_bt.Click
        市構件分類.ShowDialog()
    End Sub
    Private Sub 市購新增_bt_Click(sender As Object, e As EventArgs) Handles 市購新增_bt.Click
        主項目1_cb.Text = 物料主項(4) : Set_物料群組() : Set_物料群組_語轉() : 群組碼_cb_語轉_下拉表單資料載入()
    End Sub
    Private Sub 物料原則_tb_TextChanged(sender As Object, e As EventArgs) Handles 物料原則_tb.TextChanged
        If Len(物料原則_tb.Text) = 4 Then
            PA20 = Strings.Left(物料原則_tb.Text, 1) : SQL_物料資料庫_舊群組() : If dr.Read Then : B1_tb.Text = dr("項目").ToString : End If
            PA20 = Strings.Left(物料原則_tb.Text, 2) : SQL_物料資料庫_舊群組() : If dr.Read Then : B2_tb.Text = dr("項目").ToString : End If
            PA20 = Strings.Left(物料原則_tb.Text, 3) : SQL_物料資料庫_舊群組() : If dr.Read Then : B3_tb.Text = dr("項目").ToString : End If
            PA20 = Strings.Left(物料原則_tb.Text, 4) : SQL_物料資料庫_舊群組() : If dr.Read Then : B4_tb.Text = dr("項目").ToString : End If
        Else : B1_tb.Text = "" : B2_tb.Text = "" : B3_tb.Text = "" : B4_tb.Text = "" : End If
    End Sub
    Private Sub 新增圖號群組A_bt_Click(sender As Object, e As EventArgs) Handles 新增圖號群組A_bt.Click
        Dim GH As Integer = 0
        PA20 = 群組碼A_tb.Text : 式共用3() : SQL_物料資料庫_群組碼重複查詢1() : CmdSet_For_dr()
        If dr.Read Then : Else : PA49 = 主項目2_cb.Text
            式共用2() : SQL_物料資料庫_新增群組碼1() : SET_新增按鈕程式共用3() : 式共用2() : SQL_物料資料庫_新增群組碼_語轉11() : SET_新增按鈕程式共用3()
            式共用2() : SQL_物料資料庫_新增群組碼_語轉21() : SET_新增按鈕程式共用3() : 式共用2() : SQL_物料資料庫_新增群組碼_語轉31() : SET_新增按鈕程式共用3() : GH += 1
        End If
        PA20 = 群組碼B_tb.Text : 式共用3() : SQL_物料資料庫_群組碼重複查詢1() : CmdSet_For_dr()
        If dr.Read Then : Else : PA49 = 主項目3_cb.Text
            式共用2() : SQL_物料資料庫_新增群組碼1() : SET_新增按鈕程式共用3() : 式共用2() : SQL_物料資料庫_新增群組碼_語轉11() : SET_新增按鈕程式共用3()
            式共用2() : SQL_物料資料庫_新增群組碼_語轉21() : SET_新增按鈕程式共用3() : 式共用2() : SQL_物料資料庫_新增群組碼_語轉31() : SET_新增按鈕程式共用3() : GH += 1
        End If
        PA20 = 群組碼C_tb.Text : 式共用3() : SQL_物料資料庫_群組碼重複查詢1() : CmdSet_For_dr()
        If dr.Read Then : Else : PA49 = 主項目4_cb.Text
            式共用2() : SQL_物料資料庫_新增群組碼1() : SET_新增按鈕程式共用3() : 式共用2() : SQL_物料資料庫_新增群組碼_語轉11() : SET_新增按鈕程式共用3()
            式共用2() : SQL_物料資料庫_新增群組碼_語轉21() : SET_新增按鈕程式共用3() : 式共用2() : SQL_物料資料庫_新增群組碼_語轉31() : SET_新增按鈕程式共用3() : GH += 1
        End If
        PA20 = 群組碼D_tb.Text : 式共用3() : SQL_物料資料庫_群組碼重複查詢1() : CmdSet_For_dr()
        If dr.Read Then : Else : PA49 = 主項目5_cb.Text
            式共用2() : SQL_物料資料庫_新增群組碼1() : SET_新增按鈕程式共用3() : 式共用2() : SQL_物料資料庫_新增群組碼_語轉11() : SET_新增按鈕程式共用3()
            式共用2() : SQL_物料資料庫_新增群組碼_語轉21() : SET_新增按鈕程式共用3() : 式共用2() : SQL_物料資料庫_新增群組碼_語轉31() : SET_新增按鈕程式共用3() : GH += 1
        End If : MsgBox("新增程式執行完畢，共新增 [" & GH & "] 筆群組資料!!")
    End Sub


    '----------------------自創視窗滑鼠拖曳功能---------------------------------------------------------------------------------------------------------
    Dim OldX, OldY As Long
    Dim drag As Boolean
    Private Sub 物料群組1_Panel_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 物料群組1_P.MouseDown
        If e.Button = MouseButtons.Left Then : OldX = e.X : OldY = e.Y : drag = True : End If
    End Sub
    Private Sub 物料群組1_Panel_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 物料群組1_P.MouseMove
        If drag Then : 物料群組1_P.Left = 物料群組1_P.Left + e.X - OldX : 物料群組1_P.Top = 物料群組1_P.Top + e.Y - OldY : End If
    End Sub
    Private Sub 物料群組1_Panel_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 物料群組1_P.MouseUp
        drag = False
    End Sub
    Private Sub 規格表頭_Panel_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 規格表頭_P.MouseDown
        If e.Button = MouseButtons.Left Then : OldX = e.X : OldY = e.Y : drag = True : End If
    End Sub
    Private Sub 規格表頭_Panel_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 規格表頭_P.MouseMove
        If drag Then : 規格表頭_P.Left = 規格表頭_P.Left + e.X - OldX : 規格表頭_P.Top = 規格表頭_P.Top + e.Y - OldY : End If
    End Sub
    Private Sub 規格表頭_Panel_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 規格表頭_P.MouseUp
        drag = False
    End Sub
End Class