Option Strict Off
Public Class 一般申請_採購單
    ReadOnly ds, ds1, ds2, ds3, ds4 As New DataSet
    Dim NUM1, EDR As Integer
    Dim ESTR As String
    Dim 首次開啟, 關鍵字 As Boolean
    Private Sub Set_清單()
        物料清單_dgv.DataSource = Nothing : ds.Clear()
        物料清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        物料清單_dgv.ColumnHeadersHeight = 40
        物料清單_dgv.AllowUserToAddRows = False
        物料清單_dgv.RowTemplate.Height = 25

        PA1 = "" : PA2 = "" : PA2 = 供應商編碼_cb.Text : PA1 = 查詢_tb.Text
        SQL_盤盈盤損申請_物料清單()
        da.Fill(ds) : 物料清單_dgv.DataSource = ds.Tables(0) : conn.Close()

        物料清單_dgv.Columns(0).FillWeight = 90 : 物料清單_dgv.Columns(1).FillWeight = 100 : 物料清單_dgv.Columns(2).FillWeight = 250
        物料清單_dgv.Columns(3).FillWeight = 60 : 物料清單_dgv.Columns(4).Visible = False
        物料清單_dgv.Columns(5).FillWeight = 40 : 物料清單_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

        物料清單_dgv.Columns("庫存").DefaultCellStyle.Format = "#,##0"
        物料清單_dgv.Columns("庫存").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        物料清單_dgv.Columns("庫存").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        資料筆數_tb.Text = 物料清單_dgv.Rows.Count
        For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
            資料數 = 物料清單_dgv.Rows.Count : MyModule1.進度條()
            If 物料清單_dgv("庫存", i).Value.ToString = "" Then : 物料清單_dgv("庫存", i).Value = 0 : End If
            If 物料清單_dgv("未出庫", i).Value.ToString = "" Then : 物料清單_dgv("未出庫", i).Value = 0 : End If
        Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
    End Sub
    Private Sub Set_清單1()
        採購清單_dgv.DataSource = Nothing : ds1.Clear()
        採購清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        採購清單_dgv.ColumnHeadersHeight = 40
        採購清單_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 = 60
        ElseIf 小間距_ch.Checked = True And 中間距_ch.Checked = False And 大間距_ch.Checked = False Then
            採購清單_dgv.RowTemplate.Height = 25
        End If

        If 關鍵字 = True Then : Else : PA = 供應商編碼1_cb.Text : End If
        PA20 = 業務1_cb.Text
        If 未核准_ch.Checked = True Then : SQL_採購控制表_一般採購_未出庫() : Else : SQL_採購控制表_一般採購_已出庫() : End If

        da.Fill(ds1) : 採購清單_dgv.DataSource = ds1.Tables(0) : conn.Close()
        Set_採購清單_dgv_下拉式清單1() : Set_採購清單_dgv_下拉式清單2() : Set_採購清單_dgv_下拉式清單3()

        採購清單_dgv.Columns(0).Visible = False : 採購清單_dgv.Columns(1).FillWeight = 70 : 採購清單_dgv.Columns(2).Visible = False : 採購清單_dgv.Columns(3).FillWeight = 80
        採購清單_dgv.Columns(4).FillWeight = 65 : 採購清單_dgv.Columns(5).FillWeight = 170 : 採購清單_dgv.Columns(6).Visible = False : 採購清單_dgv.Columns(7).Visible = False
        採購清單_dgv.Columns(8).FillWeight = 70 : 採購清單_dgv.Columns(9).Visible = False : 採購清單_dgv.Columns(10).Visible = False : 採購清單_dgv.Columns(11).FillWeight = 160
        採購清單_dgv.Columns(12).Visible = False : 採購清單_dgv.Columns(13).Visible = False : 採購清單_dgv.Columns(14).FillWeight = 70 : 採購清單_dgv.Columns(15).FillWeight = 125
        採購清單_dgv.Columns(16).Visible = False : 採購清單_dgv.Columns(17).FillWeight = 45 : 採購清單_dgv.Columns(18).FillWeight = 60 : 採購清單_dgv.Columns(19).FillWeight = 60
        採購清單_dgv.Columns(20).FillWeight = 60 : 採購清單_dgv.Columns(21).FillWeight = 70 : 採購清單_dgv.Columns(22).FillWeight = 70 : 採購清單_dgv.Columns(23).FillWeight = 70
        採購清單_dgv.Columns(24).Visible = False : 採購清單_dgv.Columns(25).Visible = False : 採購清單_dgv.Columns(26).FillWeight = 45

        採購清單_dgv.Columns("數量").DefaultCellStyle.Format = "#,##0" : 採購清單_dgv.Columns("成本").DefaultCellStyle.Format = "#,##0"
        採購清單_dgv.Columns("金額").DefaultCellStyle.Format = "#,##0"
        採購清單_dgv.Columns("數量").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        採購清單_dgv.Columns("數量").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        採購清單_dgv.Columns("成本").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        採購清單_dgv.Columns("成本").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        採購清單_dgv.Columns("金額").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        採購清單_dgv.Columns("金額").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        採購清單_dgv.Columns(3).ReadOnly = True : 採購清單_dgv.Columns(4).ReadOnly = True : 採購清單_dgv.Columns(5).ReadOnly = True : 採購清單_dgv.Columns(20).ReadOnly = True
        採購清單_dgv.Columns(21).ReadOnly = True : 採購清單_dgv.Columns(16).ReadOnly = True : 採購清單_dgv.Columns(19).ReadOnly = True

        採購清單_dgv.EditMode = DataGridViewEditMode.EditOnEnter : 資料筆數1_tb.Text = 採購清單_dgv.Rows.Count
        關鍵字 = False
        Set_銷售單號隱藏() : Set_成本與金額隱藏() : Set_狀態列隱藏() : Set_供應商抬頭隱藏() : Set_申請人抬頭隱藏() : Set_合記計算()
    End Sub
    Private Sub Set_銷售單號隱藏()
        If 銷售單號_ch.Checked = False Then : 採購清單_dgv.Columns("銷售單號").Visible = False : Else : 採購清單_dgv.Columns("銷售單號").Visible = True : End If
    End Sub
    Private Sub Set_成本與金額隱藏()
        If 成本與總額_ch.Checked = False Then : 採購清單_dgv.Columns("成本").Visible = False : 採購清單_dgv.Columns("金額").Visible = False
        Else : 採購清單_dgv.Columns("成本").Visible = True : 採購清單_dgv.Columns("金額").Visible = True : End If
    End Sub
    Private Sub Set_狀態列隱藏()
        If 狀態列_ch.Checked = False Then : 採購清單_dgv.Columns("已審核").Visible = False : Else : 採購清單_dgv.Columns("已審核").Visible = True : End If
    End Sub
    Private Sub Set_供應商抬頭隱藏()
        If 供應商資料_ch.Checked = False Then : 採購清單_dgv.Columns("供應商").Visible = False : Else : 採購清單_dgv.Columns("供應商").Visible = True : End If
    End Sub
    Private Sub Set_申請人抬頭隱藏()
        If 申請人與申請日期_ch.Checked = False Then : 採購清單_dgv.Columns("申請人").Visible = False : 採購清單_dgv.Columns("申請日期").Visible = False
        Else : 採購清單_dgv.Columns("申請人").Visible = True : 採購清單_dgv.Columns("申請日期").Visible = True : End If
    End Sub
    Private Sub Set_採購清單_dgv_下拉式清單1()
        Dim Col As New DataGridViewComboBoxColumn With {
            .FillWeight = 130,
            .DataPropertyName = "倉名"
        }
        SQL_倉名_下拉清單()
        Col.Items.Clear()
        While (dr.Read()) : Col.Items.Add(dr("倉名")) : End While : conn.Close()
        Col.HeaderText = "倉名" : Col.Name = "倉名"
        採購清單_dgv.Columns.Insert(8, Col)
    End Sub
    Private Sub Set_採購清單_dgv_下拉式清單2()
        Dim Col As New DataGridViewComboBoxColumn With {
            .FillWeight = 130,
            .DataPropertyName = "訂製"
        }
        SQL_訂製狀態_下拉清單()
        Col.Items.Clear()
        While (dr.Read()) : Col.Items.Add(dr("訂製")) : End While : conn.Close()
        Col.HeaderText = "訂製" : Col.Name = "訂製"
        採購清單_dgv.Columns.Insert(11, Col)
    End Sub
    Private Sub Set_採購清單_dgv_下拉式清單3()
        Dim Col As New DataGridViewComboBoxColumn With {
            .FillWeight = 130,
            .DataPropertyName = "狀態"
        }
        SQL_倉儲狀態_下拉清單()
        Col.Items.Clear()
        While (dr.Read()) : Col.Items.Add(dr("狀態")) : End While : conn.Close()
        Col.HeaderText = "狀態" : Col.Name = "狀態"
        採購清單_dgv.Columns.Insert(14, Col)
    End Sub
    Private Sub Set_清單3()
        區域庫存_dgv.DataSource = Nothing : ds3.Clear()
        區域庫存_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        區域庫存_dgv.ColumnHeadersHeight = 25
        區域庫存_dgv.AllowUserToAddRows = False
        區域庫存_dgv.RowTemplate.Height = 25

        PA20 = 料號_tb.Text : SQL_倉名_物料分配查詢()
        da.Fill(ds3) : 區域庫存_dgv.DataSource = ds3.Tables(0) : conn.Close()

        區域庫存_dgv.Columns(0).FillWeight = 200 : 區域庫存_dgv.Columns(1).FillWeight = 80
        區域庫存_dgv.Columns(0).ReadOnly = True : 區域庫存_dgv.Columns(1).ReadOnly = True
        區域庫存_dgv.Columns("可用").DefaultCellStyle.Format = "#,##0"
        區域庫存_dgv.Columns("可用").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        區域庫存_dgv.Columns("可用").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
    End Sub
    Private Sub Set_清單4()
        銷售明細_dgv.DataSource = Nothing : ds4.Clear()
        銷售明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        銷售明細_dgv.ColumnHeadersHeight = 40
        銷售明細_dgv.AllowUserToAddRows = False
        銷售明細_dgv.RowTemplate.Height = 45

        PA2 = 業務_cb.Text
        SQL_銷售明細表_轉採購_一般用()
        da.Fill(ds4) : 銷售明細_dgv.DataSource = ds4.Tables(0) : conn.Close()

        銷售明細_dgv.Columns(0).FillWeight = 100 : 銷售明細_dgv.Columns(1).Visible = False : 銷售明細_dgv.Columns(2).Visible = False : 銷售明細_dgv.Columns(3).FillWeight = 100
        銷售明細_dgv.Columns(4).FillWeight = 200 : 銷售明細_dgv.Columns(5).Visible = False : 銷售明細_dgv.Columns(6).Visible = False : 銷售明細_dgv.Columns(7).Visible = False
        銷售明細_dgv.Columns(8).FillWeight = 200 : 銷售明細_dgv.Columns(9).FillWeight = 50 : 銷售明細_dgv.Columns(10).Visible = False : 銷售明細_dgv.Columns(11).Visible = False
        銷售明細_dgv.Columns(12).Visible = False : 銷售明細_dgv.Columns(13).Visible = False : 銷售明細_dgv.Columns(14).Visible = False : 銷售明細_dgv.Columns(15).Visible = False
        銷售明細_dgv.Columns(16).Visible = False : 銷售明細_dgv.Columns(17).Visible = False : 銷售明細_dgv.Columns(18).Visible = False
        銷售明細_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(8).ReadOnly = True : 銷售明細_dgv.Columns(12).ReadOnly = True
        銷售明細_dgv.Columns(13).ReadOnly = True

        銷售明細_dgv.Columns("數量").DefaultCellStyle.Format = "#,##0" : 銷售明細_dgv.Columns("成本").DefaultCellStyle.Format = "#,##0"
        銷售明細_dgv.Columns("單價").DefaultCellStyle.Format = "#,##0.0" : 銷售明細_dgv.Columns("金額").DefaultCellStyle.Format = "#,##0"
        銷售明細_dgv.Columns("數量").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("數量").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("成本").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("成本").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("單價").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("單價").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("金額").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("金額").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("項次").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("項次").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("倉儲情況").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("倉儲情況").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("料號").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        銷售明細_dgv.Columns("料號").HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter

        For i As Integer = 0 To 銷售明細_dgv.Rows.Count - 1
            銷售明細_dgv("金額", i).Value = 銷售明細_dgv("數量", i).Value * 銷售明細_dgv("成本", i).Value : 銷售明細_dgv("項次", i).Value = i + 1
        Next
        銷售明細_dgv.EditMode = DataGridViewEditMode.EditOnEnter
    End Sub
    Private Sub Set_清單5()
        訂製圖檔_dgv.DataSource = Nothing : ds2.Clear()
        訂製圖檔_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        訂製圖檔_dgv.ColumnHeadersHeight = 25
        訂製圖檔_dgv.AllowUserToAddRows = False
        訂製圖檔_dgv.RowTemplate.Height = 25

        SQL_採購控制表_訂製圖檔清單()
        da.Fill(ds2) : 訂製圖檔_dgv.DataSource = ds2.Tables(0) : conn.Close()
        訂製圖檔_dgv.Columns(0).Visible = False : 訂製圖檔_dgv.Columns(1).Visible = False : 訂製圖檔_dgv.Columns(2).FillWeight = 100
    End Sub
    Private Sub 供應商_下拉表單資料載入()
        BL1 = False : PA3 = "" : PA4 = ""
        If 地區_cb.Text = "" Then : PA3 = ""
        ElseIf 地區_cb.Text = "北部" Then : PA3 = "2"
        ElseIf 地區_cb.Text = "南部" Then : PA3 = "3"
        ElseIf 地區_cb.Text = "材料" Then : PA3 = "9"
        ElseIf 地區_cb.Text = "調貨" Then : PA3 = "Y"
        End If
        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 供應商1_下拉表單資料載入()
        BL1 = False : PA3 = "" : PA4 = ""
        If 地區1_cb.Text = "" Then : PA3 = ""
        ElseIf 地區1_cb.Text = "北部" Then : PA3 = "2"
        ElseIf 地區1_cb.Text = "南部" Then : PA3 = "3"
        ElseIf 地區1_cb.Text = "材料" Then : PA3 = "9"
        ElseIf 地區1_cb.Text = "調貨" Then : PA3 = "Y"
        End If
        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 Set_合記計算()
        採購金額_tb.Text = "0" : 採購金額1_tb.Text = "0"
        For i As Integer = 0 To 採購清單_dgv.Rows.Count - 1
            採購清單_dgv("金額", i).Value = 採購清單_dgv("數量", i).Value * 採購清單_dgv("成本", i).Value
            採購金額_tb.Text = Val(採購金額_tb.Text) + 採購清單_dgv("金額", i).Value

            If 供應商_tb.Text = 採購清單_dgv("供應商", i).Value.ToString Then
                採購金額1_tb.Text = Val(採購金額1_tb.Text) + 採購清單_dgv("金額", i).Value
            End If
        Next
        採購金額_tb.Text = Format(Val(採購金額_tb.Text), "#,##0") : 採購金額1_tb.Text = Format(Val(採購金額1_tb.Text), "#,##0")
    End Sub
    Private Sub 業務_cb_下拉表單資料載入()
        SQL_業務編號_下拉清單() : 業務_cb.Items.Clear() : 業務1_cb.Items.Clear()
        While (dr.Read()) : 業務_cb.Items.Add(dr("業務號")) : 業務1_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_訂製狀態_下拉清單() : 訂製狀態_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_下拉表單資料載入()
        If 需要全部庫存區域清單_ch.Checked = True Then
            SQL_倉名_下拉清單()
        Else
            If 料號_tb.Text = "" Then
                SQL_倉名_下拉清單()
            Else
                PA20 = 料號_tb.Text : SQL_倉名_下拉清單_有條件()
            End If
        End If
        指定倉庫_cb.Items.Clear()
        While (dr.Read()) : 指定倉庫_cb.Items.Add(dr("倉名")) : End While : conn.Close()
        If 指定倉庫_cb.Items.Count = 0 Then
            SQL_倉名_下拉清單()
            While (dr.Read()) : 指定倉庫_cb.Items.Add(dr("倉名")) : End While : conn.Close()
        End If
    End Sub
    Private Sub 一般性申請採購單_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = YD_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        '--------------------控件隱藏、操作許可設定與其他基本顯示設定------------------------------------------------------------
        料號_tb.Enabled = False : 中間距_ch.Checked = True
        指定倉庫_cb_下拉表單資料載入() : 訂製狀態_cb_下拉表單資料載入() : 倉儲狀態_cb_下拉表單資料載入() : 業務_cb_下拉表單資料載入()
        Set_清單4()
        '--------------------資料讀取--------------------------------------------------------------------------------------------
        首次開啟 = False : Set_清單() : Set_清單1()

        '--------------------指定伺服器ftp資料夾位置-----------------------------------------------------------------------------
        Target1 = Target & AA(1) & "/" : FTP資料夾_wb.Url = New Uri(Target1)

        If YD_ERP_SYS.Size.Width > 1440 And YD_ERP_SYS.Size.Height > 900 Then
            字體_NUD.Value = 9
            狀態列_ch.Checked = True : 銷售單號_ch.Checked = True : 成本與總額_ch.Checked = True : 供應商資料_ch.Checked = True : 申請人與申請日期_ch.Checked = True
            Set_銷售單號隱藏() : Set_成本與金額隱藏() : Set_狀態列隱藏() : Set_供應商抬頭隱藏() : Set_申請人抬頭隱藏()
        ElseIf YD_ERP_SYS.Size.Width <= 1440 And YD_ERP_SYS.Size.Height <= 900 Then
            字體_NUD.Value = 7.6
            狀態列_ch.Checked = False : 銷售單號_ch.Checked = False : 成本與總額_ch.Checked = False : 供應商資料_ch.Checked = False : 申請人與申請日期_ch.Checked = False
            Set_銷售單號隱藏() : Set_成本與金額隱藏() : Set_狀態列隱藏() : Set_供應商抬頭隱藏() : Set_申請人抬頭隱藏()
        End If
        首次開啟 = True
    End Sub
    Private Sub 一般性申請採購單_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        If 首次開啟 = True Then
            If Me.Size.Width > 1220 Then
                物料圖1_pb.Visible = True
            Else
                物料圖1_pb.Visible = False
            End If
            If YD_ERP_SYS.Size.Width > 1440 And YD_ERP_SYS.Size.Height > 900 Then
                字體_NUD.Value = 9
                狀態列_ch.Checked = True : 銷售單號_ch.Checked = True : 成本與總額_ch.Checked = True : 供應商資料_ch.Checked = True : 申請人與申請日期_ch.Checked = True
                Set_銷售單號隱藏() : Set_成本與金額隱藏() : Set_狀態列隱藏() : Set_供應商抬頭隱藏() : Set_申請人抬頭隱藏()
            ElseIf YD_ERP_SYS.Size.Width <= 1440 And YD_ERP_SYS.Size.Height <= 900 Then
                字體_NUD.Value = 7.6
                狀態列_ch.Checked = False : 銷售單號_ch.Checked = False : 成本與總額_ch.Checked = False : 供應商資料_ch.Checked = False : 申請人與申請日期_ch.Checked = False
                Set_銷售單號隱藏() : Set_成本與金額隱藏() : Set_狀態列隱藏() : Set_供應商抬頭隱藏() : Set_申請人抬頭隱藏()
            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
            指定倉庫_cb.Text = 區域庫存_dgv.Rows(e.RowIndex).Cells("倉名").Value
        End If
    End Sub
    Private Sub 採購清單_dgv_CellEndEdit(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 採購清單_dgv.CellEndEdit
        Set_合記計算()
        PA20 = 採購清單_dgv(8, e.RowIndex).Value : SQL_銷售明細_改倉名()
        If dr.Read() Then : 採購清單_dgv("倉儲狀態", e.RowIndex).Value = dr("倉名編號") : End If
        PA19 = 採購清單_dgv(11, e.RowIndex).Value : SQL_銷售明細_改物料訂製狀態()
        If dr.Read() Then : 採購清單_dgv("訂製狀態", e.RowIndex).Value = dr("編碼") : End If
        PA18 = 採購清單_dgv(14, e.RowIndex).Value : SQL_銷售明細_倉儲狀態()
        If dr.Read() Then : 採購清單_dgv("物料狀態", e.RowIndex).Value = dr("編碼") : End If : conn.Close()

        Dim EU(1) As String
        EU(0) = 採購清單_dgv("採購日期", e.RowIndex).Value.ToString
        If EU(0) = "" Then : Else
            日期1_dtp.Text = EU(0) : 採購清單_dgv.Rows(e.RowIndex).Cells("採購日期").Value = Format(日期1_dtp.Value, "yyyy/MM/dd")
        End If
        EU(1) = 採購清單_dgv("預計進廠日", e.RowIndex).Value.ToString
        If EU(1) = "" Then : Else
            日期2_dtp.Text = EU(1) : 採購清單_dgv.Rows(e.RowIndex).Cells("預計進廠日").Value = Format(日期2_dtp.Value, "yyyy/MM/dd")
        End If
    End Sub
    Private Sub 採購清單_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 採購清單_dgv.RowPostPaint
        For i As Integer = 0 To 採購清單_dgv.Rows.Count - 1
            If 採購清單_dgv.Rows(i).Cells("已審核").Value = True Then
                採購清單_dgv.Rows(i).DefaultCellStyle.BackColor = Color.White
            Else
                採購清單_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightYellow
            End If
        Next
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 採購清單_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 採購清單_dgv("供應商", e.RowIndex).Value.ToString <> 採購清單_dgv("供應商", e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(採購清單_dgv.RowHeadersVisible, 採購清單_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 採購清單_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 採購清單_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
        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 : 申請人_tb.Text = 採購清單_dgv("申請人", e.RowIndex).Value.ToString
            版次_tb.Text = 採購清單_dgv("訂製圖號", e.RowIndex).Value.ToString : 單號1_tb.Text = 採購清單_dgv("銷售單號", e.RowIndex).Value.ToString
            料號_tb.Text = 採購清單_dgv("料號", e.RowIndex).Value.ToString : 供應商_tb.Text = 採購清單_dgv("供應商", e.RowIndex).Value.ToString

            Set_合記計算() : PA15 = 採購清單_dgv(0, e.RowIndex).Value.ToString : Set_清單5()
            物料圖1_pb.Image = Nothing : PA1 = 採購清單_dgv.Rows(e.RowIndex).Cells("料號").Value : SQL_物料檔案_是否有圖()
            If dr.Read() Then
                If dr("是否有圖") = True Then
                    物料圖1_pb.BackgroundImage = Nothing
                    PA = 採購清單_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)
                        物料圖1_pb.Image = Bitmap.FromStream(oStream)
                    End While
                    conn.Close()
                    物料圖1_pb.SizeMode = 4
                Else
                    物料圖1_pb.BackgroundImage = My.Resources.底圖1 : 物料圖1_pb.BackgroundImageLayout = 3
                    物料圖1_pb.Image = Nothing
                End If
            End If : conn.Close()
        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("版次").Value
            '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            物料圖2_pb.Image = Nothing : PA15 = 項次_tb.Text : PA16 = 版次_tb.Text : 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
        End If
    End Sub
    Private Sub 物料清單_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 物料清單_dgv.CellClick
        If 首次開啟 = True Then
            If e.RowIndex = -1 Then : Else
                料號_tb.Text = 物料清單_dgv("料號", e.RowIndex).Value.ToString : 供應商編碼_tb.Text = 物料清單_dgv("供應商", e.RowIndex).Value.ToString
                品名_tb.Text = 物料清單_dgv("品名", e.RowIndex).Value.ToString : 最大庫存量_tb.Text = 物料清單_dgv("最低庫存量", e.RowIndex).Value.ToString
                庫存量_tb.Text = Val(物料清單_dgv("庫存", e.RowIndex).Value.ToString) : 供應商編碼_cb.Text = Strings.Left(物料清單_dgv("料號", e.RowIndex).Value.ToString, 4)
                可申請_tb.Text = Val(物料清單_dgv("庫存", e.RowIndex).Value.ToString) - Val(物料清單_dgv("未出庫", e.RowIndex).Value.ToString)

                物料圖_pb.Image = Nothing : PA1 = 料號_tb.Text : SQL_物料檔案_是否有圖()
                If dr.Read() Then
                    If dr("是否有圖") = True Then
                        物料圖_pb.BackgroundImage = Nothing
                        PA = 料號_tb.Text : 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
                    Else
                        物料圖_pb.BackgroundImage = My.Resources.底圖1 : 物料圖_pb.BackgroundImageLayout = 3
                        物料圖_pb.Image = Nothing
                    End If
                End If : conn.Close()

                指定倉庫_cb_下拉表單資料載入()
                訂製狀態_cb_下拉表單資料載入() : 倉儲狀態_cb_下拉表單資料載入()
            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("單號", e.RowIndex).Value.ToString : 供應商編碼_cb.Text = Strings.Left(銷售明細_dgv.Rows(e.RowIndex).Cells("料號").Value.ToString, 4)
            料號_tb.Text = 銷售明細_dgv.Rows(e.RowIndex).Cells("料號").Value.ToString : 儲態編號1_cb.Text = 銷售明細_dgv.Rows(e.RowIndex).Cells("物料狀態").Value.ToString
            訂製編碼1_cb.Text = 銷售明細_dgv.Rows(e.RowIndex).Cells("訂製狀態").Value.ToString : 倉庫編號1_tb.Text = 銷售明細_dgv.Rows(e.RowIndex).Cells("倉儲狀態").Value.ToString
            備註1_tb.Text = 銷售明細_dgv.Rows(e.RowIndex).Cells("備註").Value.ToString : 採購數量1_nud.Value = 銷售明細_dgv.Rows(e.RowIndex).Cells("數量").Value.ToString
            採購單價1_nud.Value = 銷售明細_dgv.Rows(e.RowIndex).Cells("成本").Value.ToString : 流水號_tb.Text = 銷售明細_dgv.Rows(e.RowIndex).Cells("資料流水號").Value.ToString
            儲態編號2_cb.Text = 銷售明細_dgv.Rows(e.RowIndex).Cells("狀態").Value.ToString : 倉庫編號2_tb.Text = 銷售明細_dgv.Rows(e.RowIndex).Cells("倉名").Value.ToString
            訂製編碼2_cb.Text = 銷售明細_dgv.Rows(e.RowIndex).Cells("訂製").Value.ToString
        End If
    End Sub
    Private Sub 物料清單_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 物料清單_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 物料清單_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 物料清單_dgv("供應商", e.RowIndex).Value.ToString <> 物料清單_dgv("供應商", e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(物料清單_dgv.RowHeadersVisible, 物料清單_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 物料清單_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 物料清單_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
        End If
    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()
            files = CType(e.Data.GetData(DataFormats.FileDrop), String())
            檔案名稱_tb.Text = files(files.Length - 1)
        End If
        Dim STR2 As Integer = 0
        檔名讀取_tb.Text = 檔案名稱_tb.Text
        If 檔案名稱_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 = ""
                        檔案名稱_tb.Text = ""
                        i = 9999
                    Else
                        檔名讀取_tb.Text = Strings.Left((檔名讀取_tb.Text), STR1)
                    End If
                Else
                    檔名讀取_tb.Text = Strings.Right((檔案名稱_tb.Text), STR2)
                    檔案名稱_tb.Text = 檔名讀取_tb.Text
                    i = 9999
                End If
            Next
        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_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 業務1_cb.SelectedIndexChanged
        Set_清單1()
    End Sub
    Private Sub 地區_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 地區_cb.SelectedIndexChanged
        If 地區_cb.Text = "" And 查詢_tb.Text = "" Then : 供應商_cb.Items.Clear() : 供應商編碼_cb.Items.Clear() : Set_清單()
        ElseIf 地區_cb.Text = "" Then : 查詢_tb.Text = "" : 供應商_cb.Items.Clear() : 供應商編碼_cb.Items.Clear()
        ElseIf 地區_cb.Text <> "" Then : 查詢_tb.Text = "" : 供應商_下拉表單資料載入() : End If
    End Sub
    Private Sub 地區1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 地區1_cb.SelectedIndexChanged
        If 地區1_cb.Text = "" And 查詢1_tb.Text = "" Then : 供應商1_cb.Items.Clear() : 供應商編碼1_cb.Items.Clear() : Set_清單1()
        ElseIf 地區1_cb.Text = "" Then : 查詢1_tb.Text = "" : 供應商1_cb.Items.Clear() : 供應商編碼1_cb.Items.Clear()
        ElseIf 地區1_cb.Text <> "" Then : 查詢1_tb.Text = "" : 供應商1_下拉表單資料載入() : End If
    End Sub
    Private Sub 供應商_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 供應商_cb.SelectedIndexChanged
        If 地區_cb.Text <> "" Then : 查詢_tb.Text = "" : 供應商編碼_cb.SelectedIndex = 供應商_cb.SelectedIndex : End If
    End Sub
    Private Sub 供應商1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 供應商1_cb.SelectedIndexChanged
        If 地區1_cb.Text <> "" Then : 查詢1_tb.Text = "" : 供應商編碼1_cb.SelectedIndex = 供應商1_cb.SelectedIndex : End If
    End Sub
    Private Sub 供應商編碼_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 供應商編碼_cb.SelectedIndexChanged
        If 地區_cb.Text <> "" Then : 查詢_tb.Text = "" : 供應商_cb.SelectedIndex = 供應商編碼_cb.SelectedIndex : 供應商編碼_tb.Text = 供應商編碼_cb.Text : Set_清單() : End If
    End Sub
    Private Sub 供應商編碼1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 供應商編碼1_cb.SelectedIndexChanged
        If 地區1_cb.Text <> "" Then : 查詢1_tb.Text = "" : 供應商1_cb.SelectedIndex = 供應商編碼1_cb.SelectedIndex : 供應商編碼1_tb.Text = 供應商編碼1_cb.Text : Set_清單1() : End If
    End Sub
    Private Sub 查詢_tb_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 查詢_tb.KeyPress
        If e.KeyChar = Chr(13) Then
            供應商_cb.Items.Clear() : 供應商編碼_cb.Items.Clear()
            PA = 查詢_tb.Text : Set_清單() : 地區_cb.Text = ""
        End If
    End Sub
    Private Sub 查詢1_tb_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 查詢1_tb.KeyPress
        If e.KeyChar = Chr(13) Then
            供應商1_cb.Items.Clear() : 供應商編碼1_cb.Items.Clear()
            關鍵字 = True : PA = 查詢1_tb.Text : Set_清單1() : 地區1_cb.Text = ""
        End If
    End Sub
    Private Sub 清空_bt_Click(sender As Object, e As EventArgs) Handles 清空_bt.Click
        查詢_tb.Text = "" : 地區_cb.Text = ""
    End Sub
    Private Sub 清空1_bt_Click(sender As Object, e As EventArgs) Handles 清空1_bt.Click
        業務1_cb.Text = "" : 查詢1_tb.Text = "" : 地區1_cb.Text = ""
    End Sub
    Private Sub 指定倉庫_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 指定倉庫_cb.SelectedIndexChanged
        PA6 = 指定倉庫_cb.Text : SQL_指定倉儲_資料讀取()
        If dr.Read() Then : 倉庫級別_tb.Text = dr("倉級") : 倉庫編號_tb.Text = dr("倉名編號") : End If : conn.Close()
    End Sub
    Private Sub 倉儲狀態_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 倉儲狀態_cb.SelectedIndexChanged
        儲態編號_cb.SelectedIndex = 倉儲狀態_cb.SelectedIndex
    End Sub
    Private Sub 儲態編號_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 儲態編號_cb.SelectedIndexChanged
        倉儲狀態_cb.SelectedIndex = 儲態編號_cb.SelectedIndex
    End Sub
    Private Sub 訂製狀態_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 訂製狀態_cb.SelectedIndexChanged
        訂製編碼_cb.SelectedIndex = 訂製狀態_cb.SelectedIndex
        If 訂製編碼_cb.Text = "MA0001" Then
            PA12 = 料號_tb.Text
            SQL_銷售明細表_成本讀取()
            If dr.Read() Then : 採購單價_nud.Value = dr("成本")
            Else : 採購單價_nud.Value = 0
            End If : conn.Close()
        Else
            採購單價_nud.Value = 0
        End If
    End Sub
    Private Sub 訂製編碼_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 訂製編碼_cb.SelectedIndexChanged
        訂製狀態_cb.SelectedIndex = 訂製編碼_cb.SelectedIndex
    End Sub
    Private Sub Set_日期格式轉換()
        DTP = Format(Today(), "yyyy/MM/dd") : DTP1 = Format(Today(), "yyyyMMdd")
    End Sub
    Private Sub 選定內容加入庫存調整申請單_bt_Click(sender As Object, e As EventArgs) Handles 選定內容加入庫存調整申請單_bt.Click
        If 料號_tb.Text = "" Then
            MsgBox("請選擇物料，調整庫存需要指定物料!!")
        Else
            If 儲態編號_cb.Text = "" Then
                MsgBox("倉儲狀態是一定要選擇的!!")
            Else
                If 指定倉庫_cb.Text = "" Then
                    MsgBox("指定倉庫是一定要選擇的!!")
                Else
                    If 訂製狀態_cb.Text = "" Then
                        MsgBox("物品的訂製狀態也是一定要選擇的!!")
                    Else
                        SQL_採購控制表_最後一筆資料()
                        If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("資料流水號").ToString, 9)) : Else : EDR = 0 : End If
                        conn.Close() : EDR += 1
                        If EDR < 10 Then : ESTR = "PU" & "00000000" & EDR
                        ElseIf EDR > 9 And EDR < 100 Then : ESTR = "PU" & "0000000" & EDR
                        ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "PU" & "000000" & EDR
                        ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "PU" & "00000" & EDR
                        ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "PU" & "0000" & EDR
                        ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "PU" & "000" & EDR
                        ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "PU" & "00" & EDR
                        ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "PU" & "0" & EDR
                        ElseIf EDR > 99999999 Then : ESTR = "PU" & EDR : End If

                        訂製編碼_cb.SelectedIndex = 訂製狀態_cb.SelectedIndex
                        If 訂製編碼_cb.Text = "MA0001" Then
                            PA12 = 料號_tb.Text
                            SQL_銷售明細表_成本讀取()
                            If dr.Read() Then : 採購單價_nud.Value = dr("成本")
                            Else : 採購單價_nud.Value = 0
                            End If : conn.Close()
                        Else
                            採購單價_nud.Value = 0
                        End If

                        PA1 = ESTR : PA2 = "" : PA3 = 供應商編碼_cb.Text : PA4 = 料號_tb.Text : PA5 = 儲態編號_cb.Text : PA6 = 訂製編碼_cb.Text : PA7 = 倉庫編號_tb.Text : PA8 = ""
                        NU1 = 採購數量_nud.Value : NU2 = 採購單價_nud.Value : NU3 = NU1 * NU2 : PA9 = gUserName : PA10 = Format(Today(), "yyyy/MM/dd") : PA11 = "" : PA12 = ""
                        BL1 = False
                        SQL_採購控制表_新增() : Set_清單1()
                    End If
                End If
            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
        存檔1() : 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
        存檔1() : 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
        存檔1() : Set_清單1()
    End Sub
    Private Sub 存檔1()
        For i As Integer = 0 To 採購清單_dgv.Rows.Count - 1
            資料數 = 採購清單_dgv.Rows.Count : MyModule1.進度條()
            If gUserName <> 採購清單_dgv("申請人", i).Value And Val(登入人級別) >= 3 Then
            Else
                PA = 採購清單_dgv("資料流水號", i).Value : PA1 = 採購清單_dgv("物料狀態", i).Value : PA2 = 採購清單_dgv("訂製狀態", i).Value : PA3 = 採購清單_dgv("倉儲狀態", i).Value
                PA4 = 採購清單_dgv("備註", i).Value.ToString : PA5 = 採購清單_dgv("採購日期", i).Value.ToString : PA6 = 採購清單_dgv("預計進廠日", i).Value.ToString
                NU1 = 採購清單_dgv("數量", i).Value : NU2 = 採購清單_dgv("成本", i).Value : NU3 = NU1 * NU2
                SQL_採購控制表_存檔()
            End If
        Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
    End Sub
    Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
        存檔1() : MsgBox("修改完成。")
    End Sub
    Private Sub 刪除單據上點選的資料_bt_Click(sender As Object, e As EventArgs) Handles 刪除單據上點選的資料_bt.Click
        If gUserName <> 申請人_tb.Text And Val(登入人級別) >= 3 Then
            MsgBox("不能修改其他申請人的資料")
        Else
            PA = 項次_tb.Text : SQL_採購控制表_刪除()
        End If
        Set_清單1() : MsgBox("已刪除選中的資料")
    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 圖檔入系統_bt_Click(sender As Object, e As EventArgs) Handles 圖檔入系統_bt.Click
        If 項次_tb.Text = "" Then : MsgBox("請先選擇要指定訂製圖檔的採購資料!!")
        Else
            If 檔案名稱_tb.Text <> "" Then
                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 進版 As Integer
                    If 版次_tb.Text = "" Then
                        版次_tb.Text = "V01"
                    Else
                        進版 = Strings.Right(版次_tb.Text, 2) : 進版 += 1
                        If 進版 < 10 Then : 版次_tb.Text = "V" & "0" & 進版
                        Else : 版次_tb.Text = "V" & EDR : End If
                    End If

                    PA1 = 項次_tb.Text : PA2 = 單號1_tb.Text : PA3 = 版次_tb.Text : PA4 = 檔案名稱_tb.Text
                    SQL_採購控制表_圖片新增() : SQL_採購控制表_修改() : conn.Close()
                    '---FTP方式刪除檔案----------------------------------------------------------------------------------------------------------------------------------------------------------------------
                    Dim frq As FtpWebRequest, frp As FtpWebResponse, fcr As NetworkCredential
                    frq = CType(WebRequest.Create(New Uri(Target1 & 檔案名稱_tb.Text)), FtpWebRequest)
                    fcr = New NetworkCredential(FTP帳號, FTP密碼)
                    frq.Credentials = fcr
                    frq.Method = WebRequestMethods.Ftp.DeleteFile
                    frq.UseBinary = True
                    frp = CType(frq.GetResponse, FtpWebResponse)
                    frp.Close()
                    FTP資料夾_wb.Refresh()
                    '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                    物料圖2_pb.Image = Nothing : PA15 = 項次_tb.Text : PA16 = 版次_tb.Text : 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
                    '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                    存檔1() : Set_清單5() : Set_清單1() : 檔案名稱_tb.Text = ""
                Else
                    MsgBox("上傳文件並非常用圖片格式，文件已自動刪除，請專換成常用圖片檔案再行操作。")
                    '---FTP方式刪除檔案----------------------------------------------------------------------------------------------------------------------------------------------------------------------
                    Dim frq As FtpWebRequest, frp As FtpWebResponse, fcr As NetworkCredential
                    frq = CType(WebRequest.Create(New Uri(Target1 & 檔案名稱_tb.Text)), FtpWebRequest)
                    fcr = New NetworkCredential(FTP帳號, FTP密碼)
                    frq.Credentials = fcr
                    frq.Method = WebRequestMethods.Ftp.DeleteFile
                    frq.UseBinary = True
                    frp = CType(frq.GetResponse, FtpWebResponse)
                    frp.Close()
                    FTP資料夾_wb.Refresh()
                    檔案名稱_tb.Text = ""
                End If
            End If
        End If
    End Sub
    Private Sub 下載圖檔_bt_Click(sender As Object, e As EventArgs) Handles 下載圖檔_bt.Click
        If 物料圖1_pb.Image Is Nothing Then : MsgBox("所選擇的資料沒有圖片檔案，無法下載。")
        Else
            With SaveFileDialog1 : .Filter = "所有文件(*.jpg)|*.jpg" : End With
            SaveFileDialog1.FileName = 單號1_tb.Text & "-" & 料號_tb.Text & "-" & 版次_tb.Text & ".jpg"
            Dim result As DialogResult = SaveFileDialog1.ShowDialog()
            下載檔名_tb.Text = SaveFileDialog1.FileName
            If result = System.Windows.Forms.DialogResult.Cancel Then
                Exit Sub
            End If

            PA15 = 項次_tb.Text : PA16 = 版次_tb.Text
            ds3.Clear() : SQL_採購控制表_訂製圖片下載() : da.Fill(ds3)
            If ds3.Tables(0).Rows.Count > 0 Then
                Dim imgData() As Byte
                imgData = ds3.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
        If 項次_tb.Text = "" Or 版次_tb.Text = "" Then
            MsgBox("沒有訂製圖或是沒有決哲訂製圖")
        Else
            採購訂製大圖.ShowDialog()
        End If
    End Sub
    Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
        採購清單_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
        區域庫存_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
        物料清單_dgv.RowsDefaultCellStyle.Font = New Font("微軟正黑體", 字體_NUD.Value)
    End Sub
    Private Sub 轉採購_bt_Click(sender As Object, e As EventArgs) Handles 轉採購_bt.Click
        If 單號_tb.Text = "" Then : MsgBox("請選擇單號!!") : Else
            PA = 單號_tb.Text ': SQL_銷售控制表_轉採購修改()
            SQL_採購控制表_最後一筆資料()
            If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("資料流水號").ToString, 9)) : Else : EDR = 0 : End If
            conn.Close() : EDR += 1
            If EDR < 10 Then : ESTR = "PU" & "00000000" & EDR
            ElseIf EDR > 9 And EDR < 100 Then : ESTR = "PU" & "0000000" & EDR
            ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "PU" & "000000" & EDR
            ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "PU" & "00000" & EDR
            ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "PU" & "0000" & EDR
            ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "PU" & "000" & EDR
            ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "PU" & "00" & EDR
            ElseIf EDR > 9999999 And EDR < 10000000 Then : ESTR = "PU" & "0" & EDR
            ElseIf EDR > 99999999 Then : ESTR = "PU" & EDR : End If

            PA1 = ESTR : PA2 = 單號_tb.Text : PA3 = 供應商編碼_cb.Text : PA4 = 料號_tb.Text : PA5 = 儲態編號1_cb.Text : PA6 = 訂製編碼1_cb.Text
            PA7 = 倉庫編號1_tb.Text : PA8 = 備註1_tb.Text : NU1 = 採購數量1_nud.Value : NU2 = 採購單價1_nud.Value : NU3 = NU1 * NU2 : PA9 = gUserName
            PA10 = Strings.Format(Today(), "yyyy/MM/dd") : PA11 = Strings.Format(採購日期_dtp.Value, "yyyy/MM/dd") : PA13 = 流水號_tb.Text : BL1 = True
            PA12 = Strings.Format(交貨日期_dtp.Value, "yyyy/MM/dd")
            SQL_採購控制表_新增() : 未核准_ch.Checked = False : 已核准_ch.Checked = True : Set_清單1() : Set_清單4()
        End If
    End Sub
    Private Sub 未核准_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 未核准_ch.Click
        未核准_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 = True : Set_清單1()
    End Sub
    Private Sub 供應商資料_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 供應商資料_ch.Click
        Set_供應商抬頭隱藏()
    End Sub
    Private Sub 申請人與申請日期_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 申請人與申請日期_ch.Click
        Set_申請人抬頭隱藏()
    End Sub
    Private Sub 狀態列_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 成本與總額_ch.Click
        Set_成本與金額隱藏()
    End Sub
    Private Sub 狀態列_ch_CheckedChanged_1(sender As Object, e As EventArgs) Handles 狀態列_ch.Click
        Set_狀態列隱藏()
    End Sub
    Private Sub 銷售單號_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 銷售單號_ch.Click
        Set_銷售單號隱藏()
    End Sub
    Private Sub 業務_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 業務_cb.SelectedIndexChanged
        Set_清單4()
    End Sub
End Class