Option Strict Off
Imports System.Data.SqlClient
Imports System.IO
Public Class 楦頭規格表
    ReadOnly conn As New SqlConnection
    ReadOnly da As New SqlDataAdapter
    ReadOnly cmd As New SqlCommand
    ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet : ReadOnly ds3 As New DataSet
    Dim dr As SqlDataReader
    Dim WWD1 As String : Dim WWD2 As String : Dim WWD3 As String : Dim DTP As String : Dim EDFR As String
    Dim aa As MsgBoxResult
    Dim AA1 As Integer = 0 : Dim AA2 As Integer = 0 : Dim AA3 As Integer = 0 : Dim AA4 As Integer = 0 : ReadOnly AA6(21) As Integer : Dim HH As Integer
    Dim BB1 As Integer : Dim BB2 As Integer : Dim BB3 As Integer : ReadOnly BB4(21) As Boolean
    Private Sub Set_DGV1載入前設定()
        DataGridView1.DataSource = Nothing : ds.Clear()
        DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView1.ColumnHeadersHeight = 25
        DataGridView1.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
    End Sub
    Private Sub Set_DGV1載入後設定()
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_楦頭規格表清單()
        Set_DGV1載入前設定()
        If PA = "" Then
            SQL1 = "SELECT  資料流水號, 楦頭編號, 日期, 組別與尺碼, 後卡編號, 前卡編號, 楦底板編號, 涼鞋腳床, 活動中底編號, 鞋墊厚度, 中皮軟墊厚度, 後楦體寬度, 楦後跟高度, 鞋頭翹度, 鞋頭厚度, 第四趾圍,
                    第五指圍, 著地奌圍度, 腰圍, 腳背圍, 長跟周長, 楦底長度, 前掌寬度1, 前掌寬度2, 著地點寬度, 跟座寬度, 備註, 意見, 男鞋女鞋, 楦頭圖號碼, 鞋圖號碼, 楦頭名, 級放基準碼數, 楦頭直量長度 
                    FROM 楦頭規格控制表 ORDER BY 楦頭編號"
        Else
            SQL1 = "SELECT  資料流水號, 楦頭編號, 日期, 組別與尺碼, 後卡編號, 前卡編號, 楦底板編號, 涼鞋腳床, 活動中底編號, 鞋墊厚度, 中皮軟墊厚度, 後楦體寬度, 楦後跟高度, 鞋頭翹度, 鞋頭厚度, 第四趾圍,
                    第五指圍, 著地奌圍度, 腰圍, 腳背圍, 長跟周長, 楦底長度, 前掌寬度1, 前掌寬度2, 著地點寬度, 跟座寬度, 備註, 意見, 男鞋女鞋, 楦頭圖號碼, 鞋圖號碼, 楦頭名, 級放基準碼數, 楦頭直量長度 
                    FROM 楦頭規格控制表 WHERE 楦頭編號 LIKE N'%" & PA & "%' ORDER BY 楦頭編號"
        End If
        Set_DGV1載入後設定() : Set_grid()
    End Sub
    Private Sub Set_grid()
        DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).Width = 120 : DataGridView1.Columns(2).Visible = False : DataGridView1.Columns(3).Visible = False
        DataGridView1.Columns(4).Visible = False : DataGridView1.Columns(5).Visible = False : DataGridView1.Columns(6).Visible = False : DataGridView1.Columns(7).Visible = False
        DataGridView1.Columns(8).Visible = False : DataGridView1.Columns(9).Visible = False : DataGridView1.Columns(10).Visible = False : DataGridView1.Columns(11).Visible = False
        DataGridView1.Columns(12).Visible = False : DataGridView1.Columns(13).Visible = False : DataGridView1.Columns(14).Visible = False : DataGridView1.Columns(15).Visible = False
        DataGridView1.Columns(16).Visible = False : DataGridView1.Columns(17).Visible = False : DataGridView1.Columns(18).Visible = False : DataGridView1.Columns(19).Visible = False
        DataGridView1.Columns(20).Visible = False : DataGridView1.Columns(21).Visible = False : DataGridView1.Columns(22).Visible = False : DataGridView1.Columns(23).Visible = False
        DataGridView1.Columns(24).Visible = False : DataGridView1.Columns(25).Visible = False : DataGridView1.Columns(26).Visible = False : DataGridView1.Columns(27).Visible = False
        DataGridView1.Columns(28).Visible = False : DataGridView1.Columns(29).Visible = False : DataGridView1.Columns(30).Visible = False : DataGridView1.Columns(31).Visible = False
        DataGridView1.Columns(32).Visible = False : DataGridView1.Columns(33).Visible = False
    End Sub
    Private Sub Set_DGV3載入前設定()
        DataGridView3.DataSource = Nothing : ds2.Clear()
        DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView3.ColumnHeadersHeight = 25
        DataGridView3.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
    End Sub
    Private Sub Set_DGV3載入後設定()
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close()
    End Sub
    Private Sub Set_規格表清單()
        Set_DGV3載入前設定()
        SQL1 = "SELECT 資料流水號, Size, 楦頭直量長度, 楦底板長度, 楦底掌寬度, 掌圍, 腰圍, 背圍 FROM 楦頭規格表清單 WHERE (資料流水號 LIKE N'" & TextBox1.Text & "') ORDER BY   Size"
        Set_DGV3載入後設定() : Set_grid2()
    End Sub
    Private Sub Set_grid2()
        DataGridView3.Columns(0).Visible = False : DataGridView3.Columns(1).Width = 60 : DataGridView3.Columns(2).Width = 153 : DataGridView3.Columns(3).Width = 153
        DataGridView3.Columns(4).Width = 153 : DataGridView3.Columns(5).Width = 152 : DataGridView3.Columns(6).Width = 152 : DataGridView3.Columns(7).Width = 152
        DataGridView3.EditMode = DataGridViewEditMode.EditOnEnter
    End Sub
    Private Sub 標頭轉換()
        If RadioButton1.Checked = False Then
            Label11.Text = "(at 36 mm on size 7B) Cuboid width後楦體寬度：" : Label14.Text = "(at 235 mm) Toe Thickness鞋頭厚度：" : Label15.Text = "(at 196 mm) Fourth Toe Girth第四趾圍："
            Label16.Text = "(at 184 mm) Fifth Toe Girth第五指圍：" : Label17.Text = "(at 165 mm) Ball Tread Girth著地奌圍度：" : Label22.Text = "Forepart width 前掌寬度 (at 196 mm)："
            Label23.Text = "Forepart width 前掌寬度 (at 184 mm)：" : Label24.Text = "Ball tread width  著地點寬度 (at 165 mm)：" : Label25.Text = "Heel seat width  跟座寬度 (at 36 mm)："
            WWD1 = "SP00000004" : WWD2 = "SP00000005" : WWD3 = "SP00000006"
        Else
            Label11.Text = "(at 40 mm on size 7B) Cuboid width后楦体寬度：" : Label14.Text = "(at 263 mm) Toe Thickness鞋頭厚度：" : Label15.Text = "(at 218 mm) Fourth Toe Girth第四趾圍："
            Label16.Text = "(at 204 mm) Fifth Toe Girth第五指圍：" : Label17.Text = "(at 183 mm) Ball Tread Girth著地奌圍度：" : Label22.Text = "Forepart width 前掌寬度 (at 218 mm)："
            Label23.Text = "Forepart width 前掌寬度 (at 204 mm)：" : Label24.Text = "Ball tread width  著地點寬度 (at 183 mm)：" : Label25.Text = "Heel seat width  跟座寬度 (at 40 mm)："
            WWD1 = "SP00000001" : WWD2 = "SP00000002" : WWD3 = "SP00000003"
        End If
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 楦頭圖片 FROM 楦頭圖片庫 WHERE 楦頭圖片編號 LIKE N'" & WWD1 & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
        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)
            PictureBox3.Image = Bitmap.FromStream(oStream)
        End While
        conn.Close()
        PictureBox3.SizeMode = 4

        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 楦頭圖片 FROM 楦頭圖片庫 WHERE 楦頭圖片編號 LIKE N'" & WWD2 & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
        While dr.Read() = True
            Dim unused2 As Byte() = New Byte(-1) {}
            Dim bytes As Byte() = DirectCast(dr.Item("楦頭圖片"), Byte())
            Dim oStream As New MemoryStream(bytes)
            PictureBox4.Image = Bitmap.FromStream(oStream)
        End While
        conn.Close()
        PictureBox4.SizeMode = 4

        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 楦頭圖片 FROM 楦頭圖片庫 WHERE 楦頭圖片編號 LIKE N'" & WWD3 & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
        While dr.Read() = True
            Dim unused1 As Byte() = New Byte(-1) {}
            Dim bytes As Byte() = DirectCast(dr.Item("楦頭圖片"), Byte())
            Dim oStream As New MemoryStream(bytes)
            PictureBox5.Image = Bitmap.FromStream(oStream)
        End While
        conn.Close()
        PictureBox5.SizeMode = 4
    End Sub
    Private Sub 格式設定()
        TextBox1.Visible = False : TextBox28.Visible = False : TextBox29.Visible = False : TextBox30.Visible = False : TextBox31.Visible = False : TextBox32.Visible = False : ComboBox3.Visible = False
        GroupBox1.Visible = False
        If CC(41) = False Then : Button8.Enabled = False : Button9.Enabled = False : Button12.Enabled = False : End If
        If CC(36) = False Then : Button13.Enabled = False : End If
        If CC(10) = False Then : Button16.Enabled = False : End If
        RadioButton1.Enabled = False : RadioButton2.Enabled = False : ComboBox1.Enabled = False : ComboBox2.Enabled = False : Button1.Enabled = False : Button2.Enabled = False : Button3.Enabled = False
        Button10.Enabled = False : Button11.Enabled = False : Button17.Enabled = False : Button18.Enabled = False : Button32.Enabled = False
        TextBox2.Enabled = False
        DataGridView1.Enabled = True
    End Sub
    Private Sub ComboBox1下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        If PA = "" Then
            SQL1 = "SELECT 楦頭編號 FROM 楦頭圖片庫 WHERE (楦頭編號 NOT LIKE N'ML001') AND (楦頭編號 NOT LIKE N'ML002') AND (楦頭編號 NOT LIKE N'ML003') AND (楦頭編號 NOT LIKE N'WL001') " &
                   "AND (楦頭編號 NOT LIKE N'WL002') AND (楦頭編號 NOT LIKE N'WL003') ORDER BY 楦頭圖片編號"
        Else
            SQL1 = "SELECT 楦頭編號 FROM 楦頭圖片庫 WHERE (楦頭編號 LIKE N'" & PA & "%') AND (楦頭編號 NOT LIKE N'ML001') AND (楦頭編號 NOT LIKE N'ML002') AND (楦頭編號 NOT LIKE N'ML003') " &
                   "AND (楦頭編號 NOT LIKE N'WL001') AND (楦頭編號 NOT LIKE N'WL002') AND (楦頭編號 NOT LIKE N'WL003') ORDER BY 楦頭圖片編號"
        End If
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox1.Items.Clear()
        While (dr.Read())
            ComboBox1.Items.Add(dr("楦頭編號"))
        End While
        conn.Close()
        PA = ""
    End Sub
    Private Sub ComboBox2下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        If PA = "" Then
            SQL1 = "SELECT 形體號, 形體名, 顏色, 圖片編號 FROM 鞋型圖片資料庫 WHERE (類別 LIKE N'%彩圖%') ORDER BY 形體號"
        Else
            SQL1 = "SELECT 形體號, 形體名, 顏色, 圖片編號 FROM 鞋型圖片資料庫 
                    WHERE ((客戶 LIKE N'%" & PA & "%') OR (形體號 LIKE N'%" & PA & "%') OR (形體名 LIKE N'%" & PA & "%') OR (顏色 LIKE N'%" & PA & "%')) ORDER BY 形體號"
        End If
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox2.Items.Clear() : ComboBox3.Items.Clear()
        While (dr.Read())
            ComboBox2.Items.Add(dr("形體名") & "-" & dr("形體號") & "-" & dr("顏色"))
            ComboBox3.Items.Add(dr("圖片編號"))
        End While
        conn.Close()
        PA = ""
    End Sub
    Private Sub ComboBox5下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 縮寫 FROM 楦頭縮寫管理"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox5.Items.Clear() : While (dr.Read()) : ComboBox5.Items.Add(dr("縮寫")) : End While : conn.Close() : PA = ""
    End Sub
    Private Sub Set_日期格式轉換()
        DTP = Format(DateTimePicker1.Value, "yyyy/MM/dd")
    End Sub
    Private Sub 楦頭規格表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        PA = "" : GroupBox2.Visible = False : TextBox40.Enabled = False
        Set_楦頭規格表清單()
        ComboBox1下拉表單資料載入() : ComboBox2下拉表單資料載入() : ComboBox5下拉表單資料載入()
        格式設定()
    End Sub
    Private Sub 楦頭規格表_Unload(sender As Object, e As EventArgs) Handles MyBase.Closing
        If Button10.Enabled = True Then
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "DELETE FROM 楦頭規格控制表 WHERE (資料流水號 = '" & TextBox1.Text & "')"
            cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "DELETE FROM 楦頭規格表清單 WHERE (資料流水號 = '" & TextBox1.Text & "')"
            cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
        End If
    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        If e.RowIndex = -1 Then : Else
            RadioButton1.Checked = DataGridView1(28, e.RowIndex).Value.ToString
            If RadioButton1.Checked = True Then : RadioButton2.Checked = False : Else : RadioButton2.Checked = True : End If
            標頭轉換()
            TextBox1.Text = DataGridView1(0, e.RowIndex).Value.ToString : TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString : DateTimePicker1.Text = DataGridView1(2, e.RowIndex).Value.ToString
            TextBox3.Text = DataGridView1(3, e.RowIndex).Value.ToString : TextBox4.Text = DataGridView1(4, e.RowIndex).Value.ToString : TextBox5.Text = DataGridView1(5, e.RowIndex).Value.ToString
            TextBox6.Text = DataGridView1(6, e.RowIndex).Value.ToString : TextBox7.Text = DataGridView1(7, e.RowIndex).Value.ToString : TextBox8.Text = DataGridView1(8, e.RowIndex).Value.ToString
            TextBox9.Text = DataGridView1(9, e.RowIndex).Value.ToString : TextBox10.Text = DataGridView1(10, e.RowIndex).Value.ToString : TextBox11.Text = DataGridView1(26, e.RowIndex).Value.ToString
            TextBox12.Text = DataGridView1(11, e.RowIndex).Value.ToString : TextBox13.Text = DataGridView1(12, e.RowIndex).Value.ToString : TextBox14.Text = DataGridView1(13, e.RowIndex).Value.ToString
            TextBox15.Text = DataGridView1(14, e.RowIndex).Value.ToString : TextBox16.Text = DataGridView1(15, e.RowIndex).Value.ToString : TextBox17.Text = DataGridView1(16, e.RowIndex).Value.ToString
            TextBox18.Text = DataGridView1(17, e.RowIndex).Value.ToString : TextBox19.Text = DataGridView1(18, e.RowIndex).Value.ToString : TextBox20.Text = DataGridView1(19, e.RowIndex).Value.ToString
            TextBox21.Text = DataGridView1(20, e.RowIndex).Value.ToString : TextBox22.Text = DataGridView1(21, e.RowIndex).Value.ToString : TextBox23.Text = DataGridView1(22, e.RowIndex).Value.ToString
            TextBox24.Text = DataGridView1(23, e.RowIndex).Value.ToString : TextBox25.Text = DataGridView1(24, e.RowIndex).Value.ToString : TextBox26.Text = DataGridView1(25, e.RowIndex).Value.ToString
            TextBox27.Text = DataGridView1(27, e.RowIndex).Value.ToString : TextBox28.Text = DataGridView1(29, e.RowIndex).Value.ToString : TextBox29.Text = DataGridView1(30, e.RowIndex).Value.ToString
            TextBox39.Text = DataGridView1(31, e.RowIndex).Value.ToString : ComboBox4.Text = DataGridView1(32, e.RowIndex).Value.ToString : TextBox33.Text = DataGridView1(33, e.RowIndex).Value.ToString

            Set_規格表清單()
            PictureBox1.Image = Nothing : PictureBox2.Image = Nothing
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "SELECT 楦頭圖片 FROM 楦頭圖片庫 WHERE 楦頭圖片編號 LIKE N'" & TextBox28.Text & "'"
            cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
            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)
                PictureBox1.Image = Bitmap.FromStream(oStream)
            End While
            conn.Close()
            PictureBox1.SizeMode = 4

            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "SELECT 圖片, 圖片編號 FROM 鞋型圖片資料庫 WHERE 圖片編號 LIKE N'" & TextBox29.Text & "'"
            cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
            While dr.Read() = True
                TextBox29.Text = dr("圖片編號")
                Dim unused1 As Byte() = New Byte(-1) {}
                Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
                Dim oStream As New MemoryStream(bytes)
                PictureBox2.Image = Bitmap.FromStream(oStream)
            End While
            conn.Close()
            PictureBox2.SizeMode = 4
        End If
    End Sub
    Private Sub DataGridView3_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView3.CellClick
        If e.RowIndex = -1 Then : Else
            If GroupBox1.Visible = True Then
                TextBox33.Text = DataGridView3(2, e.RowIndex).Value.ToString : TextBox34.Text = DataGridView3(3, e.RowIndex).Value.ToString
                TextBox35.Text = DataGridView3(4, e.RowIndex).Value.ToString : TextBox36.Text = DataGridView3(5, e.RowIndex).Value.ToString
                TextBox37.Text = DataGridView3(6, e.RowIndex).Value.ToString : TextBox38.Text = DataGridView3(7, e.RowIndex).Value.ToString
            End If
        End If
    End Sub
    Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.Click
        If RadioButton1.Checked = True Then : RadioButton1.Checked = True : RadioButton2.Checked = False : End If : 標頭轉換()
    End Sub
    Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.Click
        If RadioButton2.Checked = True Then : RadioButton2.Checked = True : RadioButton1.Checked = False : End If : 標頭轉換()
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 楦頭圖片, 楦頭圖片編號 FROM 楦頭圖片庫 WHERE 楦頭編號 LIKE N'" & ComboBox1.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
        While dr.Read() = True
            TextBox28.Text = dr("楦頭圖片編號")
            Dim unused As Byte() = New Byte(-1) {}
            Dim bytes As Byte() = DirectCast(dr.Item("楦頭圖片"), Byte())
            Dim oStream As New MemoryStream(bytes)
            PictureBox1.Image = Bitmap.FromStream(oStream)
        End While
        conn.Close()
        PictureBox1.SizeMode = 4
    End Sub
    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
        ComboBox3.SelectedIndex = ComboBox2.SelectedIndex
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 圖片, 圖片編號 FROM 鞋型圖片資料庫 WHERE 圖片編號 LIKE N'" & ComboBox3.Text & "'"
        cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
        While dr.Read() = True
            TextBox29.Text = dr("圖片編號")
            Dim unused As Byte() = New Byte(-1) {}
            Dim bytes As Byte() = DirectCast(dr.Item("圖片"), Byte())
            Dim oStream As New MemoryStream(bytes)
            PictureBox2.Image = Bitmap.FromStream(oStream)
        End While
        conn.Close()
        PictureBox2.SizeMode = 4
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        PA = InputBox("請輸入要查詢的楦頭編號") : ComboBox1下拉表單資料載入() : MsgBox("查詢完成，請重新選擇下拉清單")
    End Sub
    Private Sub Button32_Click(sender As Object, e As EventArgs) Handles Button32.Click
        ComboBox1下拉表單資料載入()
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        PA = InputBox("請輸入要查詢的楦頭編號") : ComboBox2下拉表單資料載入() : MsgBox("查詢完成，請重新選擇下拉清單")
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        ComboBox2下拉表單資料載入()
    End Sub
    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        PA = InputBox("請輸入要查詢的楦頭編號") : Set_楦頭規格表清單() : PA = ""
    End Sub
    Private Sub 更新()
        Set_日期格式轉換()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "UPDATE 楦頭規格控制表 SET 日期 = '" & DTP & "', 組別與尺碼 = '" & TextBox3.Text & "', 後卡編號 = '" & TextBox4.Text & "', 前卡編號 = '" & TextBox5.Text & "', " &
               "楦底板編號 = '" & TextBox6.Text & "', 涼鞋腳床 = '" & TextBox7.Text & "', 活動中底編號 = '" & TextBox8.Text & "', 鞋墊厚度 = '" & TextBox9.Text & "', " &
               "中皮軟墊厚度 = '" & TextBox10.Text & "', 後楦體寬度 = '" & TextBox12.Text & "', 楦後跟高度 = '" & TextBox13.Text & "', 鞋頭翹度 = '" & TextBox14.Text & "', " &
               "鞋頭厚度 = '" & TextBox15.Text & "', 第四趾圍 = '" & TextBox16.Text & "', 第五指圍 = '" & TextBox17.Text & "', 著地奌圍度 = '" & TextBox18.Text & "', 腰圍 = '" & TextBox19.Text & "', " &
               "腳背圍 = '" & TextBox20.Text & "', 長跟周長 = '" & TextBox21.Text & "', 楦底長度 = '" & TextBox22.Text & "', 前掌寬度1 = '" & TextBox23.Text & "', 前掌寬度2 = '" & TextBox24.Text & "', " &
               "著地點寬度 = '" & TextBox25.Text & "', 跟座寬度 = '" & TextBox26.Text & "', 備註 = '" & TextBox11.Text & "', 意見 = '" & TextBox27.Text & "', 男鞋女鞋 = '" & RadioButton1.Checked & "', " &
               "楦頭圖號碼 = '" & TextBox28.Text & "', 鞋圖號碼 = '" & TextBox29.Text & "', 楦頭名 = '" & TextBox39.Text & "', 級放基準碼數 = '" & ComboBox4.Text & "', 楦頭直量長度 = '" & TextBox33.Text & "' 
               WHERE (資料流水號 = '" & TextBox1.Text & "')"
        cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()

        For i As Integer = 0 To DataGridView3.Rows.Count - 1
            資料數 = DataGridView3.Rows.Count : MyModule1.進度條()
            If i = 0 Then : EDFR = "4.5" : ElseIf i = 1 Then : EDFR = "5.0" : ElseIf i = 2 Then : EDFR = "5.5" : ElseIf i = 3 Then : EDFR = "6.0"
            ElseIf i = 4 Then : EDFR = "6.5" : ElseIf i = 5 Then : EDFR = "7.0" : ElseIf i = 6 Then : EDFR = "7.5" : ElseIf i = 7 Then : EDFR = "8.0"
            ElseIf i = 8 Then : EDFR = "8.5" : ElseIf i = 9 Then : EDFR = "9.0" : ElseIf i = 10 Then : EDFR = "9.5" : ElseIf i = 11 Then : EDFR = "10.0"
            ElseIf i = 12 Then : EDFR = "10.5" : ElseIf i = 13 Then : EDFR = "11.0" : ElseIf i = 14 Then : EDFR = "11.5" : ElseIf i = 15 Then : EDFR = "12.0"
            ElseIf i = 16 Then : EDFR = "12.5" : ElseIf i = 17 Then : EDFR = "13.0" : ElseIf i = 18 Then : EDFR = "13.5" : ElseIf i = 19 Then : EDFR = "14.0"
            ElseIf i = 20 Then : EDFR = "14.5" : ElseIf i = 21 Then : EDFR = "15.0" : End If

            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "UPDATE 楦頭規格表清單 SET  楦頭直量長度 = '" & DataGridView3.Rows(i).Cells("楦頭直量長度").Value & "', 楦底板長度 = '" & DataGridView3.Rows(i).Cells("楦底板長度").Value & "', " &
                                                "楦底掌寬度 = '" & DataGridView3.Rows(i).Cells("楦底掌寬度").Value & "', 掌圍 = '" & DataGridView3.Rows(i).Cells("掌圍").Value & "', " &
                                                      "腰圍 = '" & DataGridView3.Rows(i).Cells("腰圍").Value & "', 背圍 = '" & DataGridView3.Rows(i).Cells("背圍").Value & "' " &
                   "WHERE (資料流水號 LIKE N'" & TextBox1.Text & "' AND Size LIKE N'" & EDFR & "')"
            cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
        Next : WINPROFIT_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
    End Sub
    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
        If TextBox1.Text = "" Then
            MsgBox("沒有選擇要刪除的楦頭規格表")
        Else
            aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
            If aa = MsgBoxResult.Ok Then
                If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                SQL1 = "DELETE FROM 楦頭規格控制表 WHERE (資料流水號 = '" & TextBox1.Text & "')"
                cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
                If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                SQL1 = "DELETE FROM 楦頭規格表清單 WHERE (資料流水號 = '" & TextBox1.Text & "')"
                cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
                If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                SQL1 = "DELETE FROM 楦頭圖片庫 WHERE (楦頭編號 = '" & TextBox2.Text & "')"
                cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()

                TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = "" : TextBox4.Text = "" : TextBox5.Text = "" : TextBox6.Text = "" : TextBox7.Text = "" : TextBox8.Text = ""
                TextBox9.Text = "" : TextBox10.Text = "" : TextBox11.Text = "" : TextBox12.Text = "" : TextBox13.Text = "" : TextBox14.Text = "" : TextBox15.Text = "" : TextBox16.Text = ""
                TextBox17.Text = "" : TextBox18.Text = "" : TextBox19.Text = "" : TextBox20.Text = "" : TextBox21.Text = "" : TextBox22.Text = "" : TextBox23.Text = "" : TextBox24.Text = ""
                TextBox25.Text = "" : TextBox26.Text = "" : TextBox27.Text = "" : TextBox28.Text = "" : TextBox29.Text = "" : TextBox30.Text = "" : TextBox31.Text = "" : TextBox32.Text = ""
                TextBox39.Text = "" : TextBox33.Text = ""
                DateTimePicker1.Text = Today() : RadioButton1.Checked = False
                RadioButton2.Checked = False : PictureBox1.Image = Nothing : PictureBox2.Image = Nothing : PictureBox3.Image = Nothing : PictureBox4.Image = Nothing : PictureBox5.Image = Nothing
                Set_楦頭規格表清單()
                DataGridView3.DataSource = Nothing
                MsgBox("刪除完成")
            End If
        End If
    End Sub
    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        If TextBox1.Text = "" Then
            MsgBox("沒有選擇要修改的楦頭規格表")
        Else
            RadioButton1.Enabled = True : RadioButton2.Enabled = True : ComboBox1.Enabled = True : ComboBox2.Enabled = True : Button1.Enabled = True : Button2.Enabled = True : Button3.Enabled = True
            Button11.Enabled = True : Button17.Enabled = True : Button32.Enabled = True
            DataGridView1.Enabled = False
            Button8.Enabled = False : Button9.Enabled = False : Button12.Enabled = False
        End If
    End Sub
    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        RadioButton1.Enabled = False : RadioButton2.Enabled = False : ComboBox1.Enabled = False : ComboBox2.Enabled = False : Button1.Enabled = False : Button2.Enabled = False : Button3.Enabled = False
        Button11.Enabled = False : Button17.Enabled = False : Button32.Enabled = False : GroupBox1.Visible = False
        DataGridView1.Enabled = True
        更新() : Set_楦頭規格表清單() : MsgBox("修改完成")
        Button8.Enabled = True : Button9.Enabled = True : Button12.Enabled = True
    End Sub
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If ComboBox5.Text = " " Then
            MsgBox("客戶指定編碼一定要選擇")
        Else
            If (ComboBox6.Text = "" Or ComboBox6.Text = " ") And TextBox41.Text = "" Then
                TextBox2.Text = ComboBox5.Text & TextBox40.Text
            ElseIf (ComboBox6.Text <> "" Or ComboBox6.Text <> " ") And TextBox41.Text = "" Then
                TextBox2.Text = ComboBox5.Text & TextBox40.Text & "-" & ComboBox6.Text
            ElseIf (ComboBox6.Text = "" Or ComboBox6.Text = " ") And TextBox41.Text <> "" Then
                TextBox2.Text = ComboBox5.Text & TextBox40.Text & "-" & TextBox41.Text
            ElseIf (ComboBox6.Text <> "" Or ComboBox6.Text <> " ") And TextBox41.Text <> "" Then
                TextBox2.Text = ComboBox5.Text & TextBox40.Text & "-" & ComboBox6.Text & "-" & TextBox41.Text
            End If

            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "SELECT TOP (1) 資料流水號 FROM 楦頭規格控制表 ORDER BY 資料流水號 DESC"
            cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
            If dr.Read() Then : TextBox1.Text = dr("資料流水號").ToString : Else : TextBox1.Text = "SS00000000" : End If
            conn.Close()
            Dim NUM1 As Integer
            NUM1 = Double.Parse(Strings.Right(TextBox1.Text, 8)) + 1
            If NUM1 < 10 Then : TextBox1.Text = "SS" & "0000000" & NUM1
            ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox1.Text = "SS" & "000000" & NUM1
            ElseIf NUM1 > 99 And NUM1 < 1000 Then : TextBox1.Text = "SS" & "00000" & NUM1
            ElseIf NUM1 > 999 And NUM1 < 10000 Then : TextBox1.Text = "SS" & "0000" & NUM1
            ElseIf NUM1 > 9999 And NUM1 < 100000 Then : TextBox1.Text = "SS" & "000" & NUM1
            ElseIf NUM1 > 99999 And NUM1 < 100000 Then : TextBox1.Text = "SS" & "00" & NUM1
            ElseIf NUM1 > 999999 And NUM1 < 1000000 Then : TextBox1.Text = "SS" & "0" & NUM1
            ElseIf NUM1 > 9999999 Then : TextBox1.Text = "SS" & NUM1
            End If

            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "SELECT 楦頭編號 FROM 楦頭規格控制表 WHERE 楦頭編號 LIKE N'" & TextBox2.Text & "'"
            cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
            If dr.Read() Then
                conn.Close()
                MsgBox("楦頭編號重複")
            Else
                conn.Close()
                If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                SQL1 = "INSERT INTO 楦頭規格控制表 (資料流水號, 楦頭編號, 日期, 組別與尺碼, 後卡編號, 前卡編號, 楦底板編號, 涼鞋腳床, 活動中底編號, 
                            鞋墊厚度, 中皮軟墊厚度, 後楦體寬度, 楦後跟高度, 鞋頭翹度, 鞋頭厚度, 第四趾圍, 第五指圍, 著地奌圍度, 腰圍, 
                            腳背圍, 長跟周長, 楦底長度, 前掌寬度1, 前掌寬度2, 著地點寬度, 跟座寬度, 備註, 意見, 男鞋女鞋, 楦頭圖號碼, 
                            鞋圖號碼, 楦頭名, 級放基準碼數) " &
                   "VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "','','','','','','','','','','','','','','','','','','','','','','','','','','','" & RadioButton1.Checked & "','','','','')"
                cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()

                For i As Integer = 0 To 21
                    If i = 0 Then : EDFR = "4.5" : ElseIf i = 1 Then : EDFR = "5.0" : ElseIf i = 2 Then : EDFR = "5.5" : ElseIf i = 3 Then : EDFR = "6.0"
                    ElseIf i = 4 Then : EDFR = "6.5" : ElseIf i = 5 Then : EDFR = "7.0" : ElseIf i = 6 Then : EDFR = "7.5" : ElseIf i = 7 Then : EDFR = "8.0"
                    ElseIf i = 8 Then : EDFR = "8.5" : ElseIf i = 9 Then : EDFR = "9.0" : ElseIf i = 10 Then : EDFR = "9.5" : ElseIf i = 11 Then : EDFR = "10.0"
                    ElseIf i = 12 Then : EDFR = "10.5" : ElseIf i = 13 Then : EDFR = "11.0" : ElseIf i = 14 Then : EDFR = "11.5" : ElseIf i = 15 Then : EDFR = "12.0"
                    ElseIf i = 16 Then : EDFR = "12.5" : ElseIf i = 17 Then : EDFR = "13.0" : ElseIf i = 18 Then : EDFR = "13.5" : ElseIf i = 19 Then : EDFR = "14.0"
                    ElseIf i = 20 Then : EDFR = "14.5" : ElseIf i = 21 Then : EDFR = "15.0" : End If

                    If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                    SQL1 = "INSERT INTO 楦頭規格表清單 (資料流水號, Size, 楦頭直量長度, 楦底板長度, 楦底掌寬度, 掌圍, 腰圍, 背圍) " &
                       "VALUES ('" & TextBox1.Text & "','" & EDFR & "','0.000','0.000','0.000','0.000','0.000','0.000')"
                    cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
                Next
                Set_規格表清單()
                GroupBox2.Visible = False
            End If
        End If
    End Sub
    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        RadioButton1.Enabled = True : RadioButton2.Enabled = True : ComboBox1.Enabled = True : ComboBox2.Enabled = True : Button1.Enabled = True : Button2.Enabled = True : Button3.Enabled = True
        Button10.Enabled = True : Button17.Enabled = True : Button32.Enabled = True
        DataGridView1.Enabled = False

        TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = "" : TextBox4.Text = "" : TextBox5.Text = "" : TextBox6.Text = "" : TextBox7.Text = "" : TextBox8.Text = ""
        TextBox9.Text = "" : TextBox10.Text = "" : TextBox11.Text = "" : TextBox12.Text = "" : TextBox13.Text = "" : TextBox14.Text = "" : TextBox15.Text = "" : TextBox16.Text = ""
        TextBox17.Text = "" : TextBox18.Text = "" : TextBox19.Text = "" : TextBox20.Text = "" : TextBox21.Text = "" : TextBox22.Text = "" : TextBox23.Text = "" : TextBox24.Text = ""
        TextBox25.Text = "" : TextBox26.Text = "" : TextBox27.Text = "" : TextBox28.Text = "" : TextBox29.Text = "" : TextBox30.Text = "" : TextBox31.Text = "" : TextBox32.Text = ""
        TextBox39.Text = ""
        DateTimePicker1.Text = Today() : RadioButton1.Checked = False : RadioButton2.Checked = False : PictureBox1.Image = Nothing : PictureBox2.Image = Nothing

        'If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        'SQL1 = "SELECT TOP (1) 楦頭編號 FROM 楦頭規格控制表 ORDER BY 資料流水號 DESC"
        'cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
        'If dr.Read() Then : TextBox40.Text = Strings.Mid(dr("楦頭編號"), 3, 4).ToString : Else : TextBox40.Text = "2000" : End If
        'conn.Close()
        'TextBox40.Text = Val(TextBox40.Text) + 1

        GroupBox2.Visible = True
        Button8.Enabled = False : Button9.Enabled = False : Button12.Enabled = False
    End Sub
    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        RadioButton1.Enabled = False : RadioButton2.Enabled = False : ComboBox1.Enabled = False : ComboBox2.Enabled = False : Button1.Enabled = False : Button2.Enabled = False : Button3.Enabled = False
        Button10.Enabled = False : Button17.Enabled = False : Button32.Enabled = False : GroupBox1.Visible = False
        DataGridView1.Enabled = True
        更新() : Set_楦頭規格表清單() : MsgBox("新增完成")
        Button8.Enabled = True : Button9.Enabled = True : Button12.Enabled = True
    End Sub
    Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
        楦頭圖片導入資料庫.Show() : 楦頭圖片導入資料庫.BringToFront()
    End Sub
    Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
        楦頭圖片資料庫.Show() : 楦頭圖片導入資料庫.BringToFront()
    End Sub
    Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
        鞋型圖片導入資料庫.Show() : 鞋型圖片導入資料庫.BringToFront()
    End Sub
    Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
        鞋型圖片資料庫.Show() : 鞋型圖片資料庫.BringToFront()
    End Sub
    Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
        TextBox34.Text = TextBox22.Text : TextBox35.Text = TextBox25.Text : TextBox36.Text = TextBox18.Text : TextBox37.Text = TextBox19.Text : TextBox38.Text = TextBox20.Text
        CheckBox1.Checked = True : CheckBox5.Checked = True : CheckBox9.Checked = True : CheckBox13.Checked = True : CheckBox17.Checked = True : CheckBox20.Checked = True
        CheckBox2.Checked = True : CheckBox6.Checked = True : CheckBox10.Checked = True : CheckBox14.Checked = True : CheckBox18.Checked = True : CheckBox21.Checked = True
        CheckBox3.Checked = True : CheckBox7.Checked = True : CheckBox11.Checked = True : CheckBox15.Checked = True : CheckBox19.Checked = True : CheckBox22.Checked = True
        CheckBox4.Checked = True : CheckBox8.Checked = True : CheckBox12.Checked = True : CheckBox16.Checked = True

        If ComboBox4.Text = "" Then
            MsgBox("級放標準碼數沒有選擇")
        Else
            If TextBox33.Text = "" Or TextBox34.Text = "" Or TextBox35.Text = "" Or TextBox36.Text = "" Or TextBox37.Text = "" Or TextBox38.Text = "" Then
                MsgBox("計算數值不可空白")
            Else
                GroupBox1.Visible = False
                If ComboBox4.Text = "4.5" Then : BB1 = 22 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "5.0" Then : BB1 = 21 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "5.5" Then : BB1 = 20 : BB2 = 22 - BB1
                ElseIf ComboBox4.Text = "6.0" Then : BB1 = 19 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "6.5" Then : BB1 = 18 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "7.0" Then : BB1 = 17 : BB2 = 22 - BB1
                ElseIf ComboBox4.Text = "7.5" Then : BB1 = 16 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "8.0" Then : BB1 = 15 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "8.5" Then : BB1 = 14 : BB2 = 22 - BB1
                ElseIf ComboBox4.Text = "9.0" Then : BB1 = 13 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "9.5" Then : BB1 = 12 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "10.0" Then : BB1 = 11 : BB2 = 22 - BB1
                ElseIf ComboBox4.Text = "10.5" Then : BB1 = 10 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "11.0" Then : BB1 = 9 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "11.5" Then : BB1 = 8 : BB2 = 22 - BB1
                ElseIf ComboBox4.Text = "12.0" Then : BB1 = 7 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "12.5" Then : BB1 = 6 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "13.0" Then : BB1 = 5 : BB2 = 22 - BB1
                ElseIf ComboBox4.Text = "13.5" Then : BB1 = 4 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "14.0" Then : BB1 = 3 : BB2 = 22 - BB1 : ElseIf ComboBox4.Text = "14.5" Then : BB1 = 2 : BB2 = 22 - BB1
                ElseIf ComboBox4.Text = "15.0" Then : BB1 = 1 : BB2 = 22 - BB1
                End If
                BB4(0) = CheckBox1.Checked : BB4(1) = CheckBox2.Checked : BB4(2) = CheckBox3.Checked : BB4(3) = CheckBox4.Checked : BB4(4) = CheckBox5.Checked : BB4(5) = CheckBox6.Checked
                BB4(6) = CheckBox7.Checked : BB4(7) = CheckBox8.Checked : BB4(8) = CheckBox9.Checked : BB4(9) = CheckBox10.Checked : BB4(10) = CheckBox11.Checked : BB4(11) = CheckBox12.Checked
                BB4(12) = CheckBox13.Checked : BB4(13) = CheckBox14.Checked : BB4(14) = CheckBox15.Checked : BB4(15) = CheckBox16.Checked : BB4(16) = CheckBox17.Checked : BB4(17) = CheckBox18.Checked
                BB4(18) = CheckBox19.Checked : BB4(19) = CheckBox20.Checked : BB4(20) = CheckBox21.Checked : BB4(21) = CheckBox22.Checked

                DataGridView3.Rows(BB2).Cells(2).Value = TextBox33.Text : DataGridView3.Rows(BB2).Cells(3).Value = TextBox34.Text : DataGridView3.Rows(BB2).Cells(4).Value = TextBox35.Text
                DataGridView3.Rows(BB2).Cells(5).Value = TextBox36.Text : DataGridView3.Rows(BB2).Cells(6).Value = TextBox37.Text : DataGridView3.Rows(BB2).Cells(7).Value = TextBox38.Text
                For I As Integer = BB2 To 20
                    If BB4(I + 1) = True Then
                        DataGridView3.Rows(I + 1).Cells(2).Value = Format(Double.Parse(DataGridView3(2, I).Value.ToString) + 4.23, "##0.000")
                        DataGridView3.Rows(I + 1).Cells(3).Value = Format(Double.Parse(DataGridView3(3, I).Value.ToString) + 4.23, "##0.000")
                        DataGridView3.Rows(I + 1).Cells(4).Value = Format(Double.Parse(DataGridView3(4, I).Value.ToString) + 1.06, "##0.000")
                        DataGridView3.Rows(I + 1).Cells(5).Value = Format(Double.Parse(DataGridView3(5, I).Value.ToString) + 3.175, "##0.000")
                        DataGridView3.Rows(I + 1).Cells(6).Value = Format(Double.Parse(DataGridView3(6, I).Value.ToString) + 3.175, "##0.000")
                        DataGridView3.Rows(I + 1).Cells(7).Value = Format(Double.Parse(DataGridView3(7, I).Value.ToString) + 3.175, "##0.000")
                    Else
                        DataGridView3.Rows(I + 1).Cells(2).Value = "0.000" : DataGridView3.Rows(I + 1).Cells(3).Value = "0.000" : DataGridView3.Rows(I + 1).Cells(4).Value = "0.000"
                        DataGridView3.Rows(I + 1).Cells(5).Value = "0.000" : DataGridView3.Rows(I + 1).Cells(6).Value = "0.000" : DataGridView3.Rows(I + 1).Cells(7).Value = "0.000"
                    End If
                Next
                BB3 = BB2
                For I As Integer = 0 To BB2
                    If BB4(BB3) = True Then
                        DataGridView3.Rows(BB3).Cells(2).Value = Format(Double.Parse(DataGridView3(2, BB3 + 1).Value.ToString) - 4.23, "##0.000")
                        DataGridView3.Rows(BB3).Cells(3).Value = Format(Double.Parse(DataGridView3(3, BB3 + 1).Value.ToString) - 4.23, "##0.000")
                        DataGridView3.Rows(BB3).Cells(4).Value = Format(Double.Parse(DataGridView3(4, BB3 + 1).Value.ToString) - 1.06, "##0.000")
                        DataGridView3.Rows(BB3).Cells(5).Value = Format(Double.Parse(DataGridView3(5, BB3 + 1).Value.ToString) - 3.175, "##0.000")
                        DataGridView3.Rows(BB3).Cells(6).Value = Format(Double.Parse(DataGridView3(6, BB3 + 1).Value.ToString) - 3.175, "##0.000")
                        DataGridView3.Rows(BB3).Cells(7).Value = Format(Double.Parse(DataGridView3(7, BB3 + 1).Value.ToString) - 3.175, "##0.000")
                    Else
                        DataGridView3.Rows(BB3).Cells(2).Value = "0.000" : DataGridView3.Rows(BB3).Cells(3).Value = "0.000" : DataGridView3.Rows(BB3).Cells(4).Value = "0.000"
                        DataGridView3.Rows(BB3).Cells(5).Value = "0.000" : DataGridView3.Rows(BB3).Cells(6).Value = "0.000" : DataGridView3.Rows(BB3).Cells(7).Value = "0.000"
                    End If
                    BB3 -= 1
                Next
                TextBox34.Text = "" : TextBox35.Text = "" : TextBox36.Text = "" : TextBox37.Text = "" : TextBox38.Text = ""
                MsgBox("計算完畢")
            End If
        End If
        'If GroupBox1.Visible = True Then
        '    GroupBox1.Visible = False
        'Else
        '    GroupBox1.Visible = True
        'End If
    End Sub
    Private Sub 級放範圍選擇邏輯()
        If AA1 <> 0 And AA2 <> 0 Then
            If AA1 < AA2 Then : AA3 = AA1 : AA4 = AA2 : ElseIf AA2 < AA1 Then : AA3 = AA2 : AA4 = AA1 : End If
            For HH = AA3 To AA4 : AA6(HH - 1) = HH : Next
            If AA6(0) = 1 Then : CheckBox1.Checked = True : Else : CheckBox1.Checked = False : End If : If AA6(1) = 2 Then : CheckBox2.Checked = True : Else : CheckBox2.Checked = False : End If
            If AA6(2) = 3 Then : CheckBox3.Checked = True : Else : CheckBox3.Checked = False : End If : If AA6(3) = 4 Then : CheckBox4.Checked = True : Else : CheckBox4.Checked = False : End If
            If AA6(4) = 5 Then : CheckBox5.Checked = True : Else : CheckBox5.Checked = False : End If : If AA6(5) = 6 Then : CheckBox6.Checked = True : Else : CheckBox6.Checked = False : End If
            If AA6(6) = 7 Then : CheckBox7.Checked = True : Else : CheckBox7.Checked = False : End If : If AA6(7) = 8 Then : CheckBox8.Checked = True : Else : CheckBox8.Checked = False : End If
            If AA6(8) = 9 Then : CheckBox9.Checked = True : Else : CheckBox9.Checked = False : End If : If AA6(9) = 10 Then : CheckBox10.Checked = True : Else : CheckBox10.Checked = False : End If
            If AA6(10) = 11 Then : CheckBox11.Checked = True : Else : CheckBox11.Checked = False : End If : If AA6(11) = 12 Then : CheckBox12.Checked = True : Else : CheckBox12.Checked = False : End If
            If AA6(12) = 13 Then : CheckBox13.Checked = True : Else : CheckBox13.Checked = False : End If : If AA6(13) = 14 Then : CheckBox14.Checked = True : Else : CheckBox14.Checked = False : End If
            If AA6(14) = 15 Then : CheckBox15.Checked = True : Else : CheckBox15.Checked = False : End If : If AA6(15) = 16 Then : CheckBox16.Checked = True : Else : CheckBox16.Checked = False : End If
            If AA6(16) = 17 Then : CheckBox17.Checked = True : Else : CheckBox17.Checked = False : End If : If AA6(17) = 18 Then : CheckBox18.Checked = True : Else : CheckBox18.Checked = False : End If
            If AA6(18) = 19 Then : CheckBox19.Checked = True : Else : CheckBox19.Checked = False : End If : If AA6(19) = 20 Then : CheckBox20.Checked = True : Else : CheckBox20.Checked = False : End If
            If AA6(20) = 21 Then : CheckBox21.Checked = True : Else : CheckBox21.Checked = False : End If : If AA6(21) = 22 Then : CheckBox22.Checked = True : Else : CheckBox22.Checked = False : End If
            AA6(0) = 0 : AA6(1) = 0 : AA6(2) = 0 : AA6(3) = 0 : AA6(4) = 0 : AA6(5) = 0 : AA6(6) = 0 : AA6(7) = 0 : AA6(8) = 0 : AA6(9) = 0 : AA6(10) = 0 : AA6(11) = 0 : AA6(12) = 0 : AA6(13) = 0
            AA6(14) = 0 : AA6(15) = 0 : AA6(16) = 0 : AA6(17) = 0 : AA6(18) = 0 : AA6(19) = 0 : AA6(20) = 0 : AA6(21) = 0 : HH = 0
            CheckBox1.Enabled = False : CheckBox2.Enabled = False : CheckBox3.Enabled = False : CheckBox4.Enabled = False : CheckBox5.Enabled = False : CheckBox6.Enabled = False : CheckBox7.Enabled = False
            CheckBox8.Enabled = False : CheckBox9.Enabled = False : CheckBox10.Enabled = False : CheckBox11.Enabled = False : CheckBox12.Enabled = False : CheckBox13.Enabled = False : CheckBox14.Enabled = False
            CheckBox15.Enabled = False : CheckBox16.Enabled = False : CheckBox17.Enabled = False : CheckBox18.Enabled = False : CheckBox19.Enabled = False : CheckBox20.Enabled = False : CheckBox21.Enabled = False
            CheckBox22.Enabled = False
            Button18.Enabled = True
        End If
    End Sub
    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.Click
        If CheckBox1.Checked = True Then
            If AA1 = 0 Then : AA1 = 1 : CheckBox1.Checked = True : ElseIf AA2 = 0 Then : AA2 = 1 : CheckBox1.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox1.Checked = False : End If
        ElseIf CheckBox1.Checked = False Then
            If AA1 = 1 Then : AA1 = 0 : CheckBox1.Checked = False : ElseIf AA2 = 1 Then : AA2 = 0 : CheckBox1.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox1.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.Click
        If CheckBox2.Checked = True Then
            If AA1 = 0 Then : AA1 = 2 : CheckBox2.Checked = True : ElseIf AA2 = 0 Then : AA2 = 2 : CheckBox2.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox2.Checked = False : End If
        ElseIf CheckBox2.Checked = False Then
            If AA1 = 2 Then : AA1 = 0 : CheckBox2.Checked = False : ElseIf AA2 = 2 Then : AA2 = 0 : CheckBox2.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox2.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.Click
        If CheckBox3.Checked = True Then
            If AA1 = 0 Then : AA1 = 3 : CheckBox3.Checked = True : ElseIf AA2 = 0 Then : AA2 = 3 : CheckBox3.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox3.Checked = False : End If
        ElseIf CheckBox3.Checked = False Then
            If AA1 = 3 Then : AA1 = 0 : CheckBox3.Checked = False : ElseIf AA2 = 3 Then : AA2 = 0 : CheckBox3.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox3.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox4.Click
        If CheckBox4.Checked = True Then
            If AA1 = 0 Then : AA1 = 4 : CheckBox4.Checked = True : ElseIf AA2 = 0 Then : AA2 = 4 : CheckBox4.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox4.Checked = False : End If
        ElseIf CheckBox4.Checked = False Then
            If AA1 = 4 Then : AA1 = 0 : CheckBox4.Checked = False : ElseIf AA2 = 4 Then : AA2 = 0 : CheckBox4.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox4.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox5.Click
        If CheckBox5.Checked = True Then
            If AA1 = 0 Then : AA1 = 5 : CheckBox5.Checked = True : ElseIf AA2 = 0 Then : AA2 = 5 : CheckBox5.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox5.Checked = False : End If
        ElseIf CheckBox5.Checked = False Then
            If AA1 = 5 Then : AA1 = 0 : CheckBox5.Checked = False : ElseIf AA2 = 5 Then : AA2 = 0 : CheckBox5.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox5.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox6_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox6.Click
        If CheckBox6.Checked = True Then
            If AA1 = 0 Then : AA1 = 6 : CheckBox6.Checked = True : ElseIf AA2 = 0 Then : AA2 = 6 : CheckBox6.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox6.Checked = False : End If
        ElseIf CheckBox6.Checked = False Then
            If AA1 = 6 Then : AA1 = 0 : CheckBox6.Checked = False : ElseIf AA2 = 6 Then : AA2 = 0 : CheckBox6.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox6.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox7_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox7.Click
        If CheckBox7.Checked = True Then
            If AA1 = 0 Then : AA1 = 7 : CheckBox7.Checked = True : ElseIf AA2 = 0 Then : AA2 = 7 : CheckBox7.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox7.Checked = False : End If
        ElseIf CheckBox7.Checked = False Then
            If AA1 = 7 Then : AA1 = 0 : CheckBox7.Checked = False : ElseIf AA2 = 7 Then : AA2 = 0 : CheckBox7.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox7.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox8_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox8.Click
        If CheckBox8.Checked = True Then
            If AA1 = 0 Then : AA1 = 8 : CheckBox8.Checked = True : ElseIf AA2 = 0 Then : AA2 = 8 : CheckBox8.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox8.Checked = False : End If
        ElseIf CheckBox8.Checked = False Then
            If AA1 = 8 Then : AA1 = 0 : CheckBox8.Checked = False : ElseIf AA2 = 8 Then : AA2 = 0 : CheckBox8.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox8.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox9_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox9.Click
        If CheckBox9.Checked = True Then
            If AA1 = 0 Then : AA1 = 9 : CheckBox9.Checked = True : ElseIf AA2 = 0 Then : AA2 = 9 : CheckBox9.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox9.Checked = False : End If
        ElseIf CheckBox9.Checked = False Then
            If AA1 = 9 Then : AA1 = 0 : CheckBox9.Checked = False : ElseIf AA2 = 9 Then : AA2 = 0 : CheckBox9.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox9.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox10_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox10.Click
        If CheckBox10.Checked = True Then
            If AA1 = 0 Then : AA1 = 10 : CheckBox10.Checked = True : ElseIf AA2 = 0 Then : AA2 = 10 : CheckBox10.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox10.Checked = False : End If
        ElseIf CheckBox10.Checked = False Then
            If AA1 = 10 Then : AA1 = 0 : CheckBox10.Checked = False : ElseIf AA2 = 10 Then : AA2 = 0 : CheckBox10.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox10.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox11_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox11.Click
        If CheckBox11.Checked = True Then
            If AA1 = 0 Then : AA1 = 11 : CheckBox11.Checked = True : ElseIf AA2 = 0 Then : AA2 = 11 : CheckBox11.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox11.Checked = False : End If
        ElseIf CheckBox11.Checked = False Then
            If AA1 = 11 Then : AA1 = 0 : CheckBox11.Checked = False : ElseIf AA2 = 11 Then : AA2 = 0 : CheckBox11.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox11.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox12_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox12.Click
        If CheckBox12.Checked = True Then
            If AA1 = 0 Then : AA1 = 12 : CheckBox12.Checked = True : ElseIf AA2 = 0 Then : AA2 = 12 : CheckBox12.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox12.Checked = False : End If
        ElseIf CheckBox12.Checked = False Then
            If AA1 = 12 Then : AA1 = 0 : CheckBox12.Checked = False : ElseIf AA2 = 12 Then : AA2 = 0 : CheckBox12.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox12.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox13_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox13.Click
        If CheckBox13.Checked = True Then
            If AA1 = 0 Then : AA1 = 13 : CheckBox13.Checked = True : ElseIf AA2 = 0 Then : AA2 = 13 : CheckBox13.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox13.Checked = False : End If
        ElseIf CheckBox13.Checked = False Then
            If AA1 = 13 Then : AA1 = 0 : CheckBox13.Checked = False : ElseIf AA2 = 13 Then : AA2 = 0 : CheckBox13.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox13.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox14_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox14.Click
        If CheckBox14.Checked = True Then
            If AA1 = 0 Then : AA1 = 14 : CheckBox14.Checked = True : ElseIf AA2 = 0 Then : AA2 = 14 : CheckBox14.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox14.Checked = False : End If
        ElseIf CheckBox14.Checked = False Then
            If AA1 = 14 Then : AA1 = 0 : CheckBox14.Checked = False : ElseIf AA2 = 14 Then : AA2 = 0 : CheckBox14.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox14.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox15_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox15.Click
        If CheckBox15.Checked = True Then
            If AA1 = 0 Then : AA1 = 15 : CheckBox15.Checked = True : ElseIf AA2 = 0 Then : AA2 = 15 : CheckBox15.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox15.Checked = False : End If
        ElseIf CheckBox15.Checked = False Then
            If AA1 = 15 Then : AA1 = 0 : CheckBox15.Checked = False : ElseIf AA2 = 15 Then : AA2 = 0 : CheckBox15.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox15.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox16_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox16.Click
        If CheckBox16.Checked = True Then
            If AA1 = 0 Then : AA1 = 16 : CheckBox16.Checked = True : ElseIf AA2 = 0 Then : AA2 = 16 : CheckBox16.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox16.Checked = False : End If
        ElseIf CheckBox16.Checked = False Then
            If AA1 = 16 Then : AA1 = 0 : CheckBox16.Checked = False : ElseIf AA2 = 16 Then : AA2 = 0 : CheckBox16.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox16.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox17_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox17.Click
        If CheckBox17.Checked = True Then
            If AA1 = 0 Then : AA1 = 17 : CheckBox17.Checked = True : ElseIf AA2 = 0 Then : AA2 = 17 : CheckBox17.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox17.Checked = False : End If
        ElseIf CheckBox17.Checked = False Then
            If AA1 = 17 Then : AA1 = 0 : CheckBox17.Checked = False : ElseIf AA2 = 17 Then : AA2 = 0 : CheckBox17.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox17.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox18_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox18.Click
        If CheckBox18.Checked = True Then
            If AA1 = 0 Then : AA1 = 18 : CheckBox18.Checked = True : ElseIf AA2 = 0 Then : AA2 = 18 : CheckBox18.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox18.Checked = False : End If
        ElseIf CheckBox18.Checked = False Then
            If AA1 = 18 Then : AA1 = 0 : CheckBox18.Checked = False : ElseIf AA2 = 18 Then : AA2 = 0 : CheckBox18.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox18.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox19_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox19.Click
        If CheckBox19.Checked = True Then
            If AA1 = 0 Then : AA1 = 19 : CheckBox19.Checked = True : ElseIf AA2 = 0 Then : AA2 = 19 : CheckBox19.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox19.Checked = False : End If
        ElseIf CheckBox19.Checked = False Then
            If AA1 = 19 Then : AA1 = 0 : CheckBox19.Checked = False : ElseIf AA2 = 19 Then : AA2 = 0 : CheckBox19.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox19.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox20_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox20.Click
        If CheckBox20.Checked = True Then
            If AA1 = 0 Then : AA1 = 20 : CheckBox20.Checked = True : ElseIf AA2 = 0 Then : AA2 = 20 : CheckBox20.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox20.Checked = False : End If
        ElseIf CheckBox20.Checked = False Then
            If AA1 = 20 Then : AA1 = 0 : CheckBox20.Checked = False : ElseIf AA2 = 20 Then : AA2 = 0 : CheckBox20.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox20.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox21_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox21.Click
        If CheckBox21.Checked = True Then
            If AA1 = 0 Then : AA1 = 21 : CheckBox21.Checked = True : ElseIf AA2 = 0 Then : AA2 = 21 : CheckBox21.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox21.Checked = False : End If
        ElseIf CheckBox21.Checked = False Then
            If AA1 = 21 Then : AA1 = 0 : CheckBox21.Checked = False : ElseIf AA2 = 21 Then : AA2 = 0 : CheckBox21.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox21.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub CheckBox22_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox22.Click
        If CheckBox22.Checked = True Then
            If AA1 = 0 Then : AA1 = 22 : CheckBox22.Checked = True : ElseIf AA2 = 0 Then : AA2 = 22 : CheckBox22.Checked = True : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox22.Checked = False : End If
        ElseIf CheckBox22.Checked = False Then
            If AA1 = 22 Then : AA1 = 0 : CheckBox22.Checked = False : ElseIf AA2 = 22 Then : AA2 = 0 : CheckBox22.Checked = False : ElseIf AA1 <> 0 And AA2 <> 0 Then : CheckBox22.Checked = True : End If
        End If : 級放範圍選擇邏輯()
    End Sub
    Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
        Button18.Enabled = False
        CheckBox1.Enabled = True : CheckBox2.Enabled = True : CheckBox3.Enabled = True : CheckBox4.Enabled = True : CheckBox5.Enabled = True : CheckBox6.Enabled = True : CheckBox7.Enabled = True
        CheckBox8.Enabled = True : CheckBox9.Enabled = True : CheckBox10.Enabled = True : CheckBox11.Enabled = True : CheckBox12.Enabled = True : CheckBox13.Enabled = True : CheckBox14.Enabled = True
        CheckBox15.Enabled = True : CheckBox16.Enabled = True : CheckBox17.Enabled = True : CheckBox18.Enabled = True : CheckBox19.Enabled = True : CheckBox20.Enabled = True : CheckBox21.Enabled = True
        CheckBox22.Enabled = True
        CheckBox1.Checked = False : CheckBox2.Checked = False : CheckBox3.Checked = False : CheckBox4.Checked = False : CheckBox5.Checked = False : CheckBox6.Checked = False : CheckBox7.Checked = False
        CheckBox8.Checked = False : CheckBox9.Checked = False : CheckBox10.Checked = False : CheckBox11.Checked = False : CheckBox12.Checked = False : CheckBox13.Checked = False : CheckBox14.Checked = False
        CheckBox15.Checked = False : CheckBox16.Checked = False : CheckBox17.Checked = False : CheckBox18.Checked = False : CheckBox19.Checked = False : CheckBox20.Checked = False : CheckBox21.Checked = False
        CheckBox22.Checked = False
        AA1 = 0 : AA2 = 0 : AA3 = 0 : AA4 = 0
    End Sub
    Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click
        If CheckBox1.Checked = False And CheckBox5.Checked = False And CheckBox9.Checked = False And CheckBox13.Checked = False And CheckBox17.Checked = False And CheckBox20.Checked = False And
            CheckBox2.Checked = False And CheckBox6.Checked = False And CheckBox10.Checked = False And CheckBox14.Checked = False And CheckBox18.Checked = False And CheckBox21.Checked = False And
            CheckBox3.Checked = False And CheckBox7.Checked = False And CheckBox11.Checked = False And CheckBox15.Checked = False And CheckBox19.Checked = False And CheckBox22.Checked = False And
            CheckBox4.Checked = False And CheckBox8.Checked = False And CheckBox12.Checked = False And CheckBox16.Checked = False Then
            MsgBox("級放範圍沒有選擇")
        Else
        End If
    End Sub
    Dim m_MousePosX As Integer
    Dim m_MousePosY As Integer
    '@#当鼠标按下时，将鼠标变成手形，并且记录下当前鼠标的位置 
    Private Sub GroupBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
        If GroupBox1.Visible = True Then
            m_MousePosX = e.X
            m_MousePosY = e.Y
            GroupBox1.Location = New Point(m_MousePosX, m_MousePosY)
        End If
    End Sub
    Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click
        GroupBox1.Visible = False
        GroupBox1.Location = New Point(428, 498)
    End Sub
    Private Sub CheckBox23_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox23.Click
        If CheckBox23.Checked = False Then
            CheckBox23.Checked = False : TextBox40.Enabled = False
        Else
            CheckBox23.Checked = True : TextBox40.Enabled = True
        End If
    End Sub
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        GroupBox2.Visible = False
        RadioButton1.Enabled = False : RadioButton2.Enabled = False : ComboBox1.Enabled = False : ComboBox2.Enabled = False : Button1.Enabled = False : Button2.Enabled = False : Button3.Enabled = False
        Button10.Enabled = False : Button17.Enabled = False : Button32.Enabled = False : GroupBox1.Visible = False
        DataGridView1.Enabled = True : Button8.Enabled = True : Button9.Enabled = True : Button12.Enabled = True
    End Sub
    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        清單修改.Close() : 楦頭編碼修改 = True : 清單修改.ShowDialog() : ComboBox5下拉表單資料載入() : 楦頭編碼修改 = False
    End Sub
End Class