Option Strict Off
Imports System.IO
Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
Imports Microsoft.Office.Interop.Excel.Constants
Imports Microsoft.Office.Interop.Excel.XlBordersIndex
Imports Microsoft.Office.Interop.Excel.XlLineStyle
Imports Microsoft.Office.Interop.Excel.XlBorderWeight
Imports Microsoft.Office.Interop.Excel.XlThemeFont
Imports Microsoft.Office.Interop.Excel.XlThemeColor
Imports Microsoft.Office.Interop.Excel.XlWindowState
Imports Microsoft.Office.Interop.Excel
Public Class 請購單核准
    ReadOnly ds8 As New DataSet
    Dim xlApp As Application : Dim xlBook As Workbook : Dim xlSheet As Worksheet : Dim N1, 選擇項 As Integer
    Dim 新項次, 對話框(13), 物料規格 As String
    Private Sub Set_請購單清單()
        Dim ds As New DataSet : 請購明細_dgv.DataSource = Nothing : ds.Clear()
        請購明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        請購明細_dgv.ColumnHeadersHeight = 25
        請購明細_dgv.AllowUserToAddRows = False

        If 小間距_ch.Checked = False And 中間距_ch.Checked = False And 大間距_ch.Checked = True Then : 請購明細_dgv.RowTemplate.Height = 65
        ElseIf 小間距_ch.Checked = False And 中間距_ch.Checked = True And 大間距_ch.Checked = False Then : 請購明細_dgv.RowTemplate.Height = 35
        ElseIf 小間距_ch.Checked = True And 中間距_ch.Checked = False And 大間距_ch.Checked = False Then : 請購明細_dgv.RowTemplate.Height = 25 : End If

        SQL_建築物料請購單核准_請購單清單()
        da.Fill(ds) : 請購明細_dgv.DataSource = ds.Tables(0) : 請購明細1_dgv.DataSource = ds.Tables(0) : conn.Close()

        請購明細_dgv.Columns(0).Visible = False : 請購明細_dgv.Columns(1).FillWeight = 80 : 請購明細_dgv.Columns(2).FillWeight = 250 : 請購明細_dgv.Columns(3).FillWeight = 250
        請購明細_dgv.Columns(4).FillWeight = 250 : 請購明細_dgv.Columns(5).FillWeight = 120 : 請購明細_dgv.Columns(6).FillWeight = 80 : 請購明細_dgv.Columns(7).FillWeight = 80
        請購明細_dgv.Columns(8).FillWeight = 120
        請購明細_dgv.Columns(9).Visible = False : 請購明細_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(19).Visible = False : 請購明細_dgv.Columns(20).Visible = False
        請購明細_dgv.Columns("已採購").FillWeight = 60
        請購明細_dgv.Columns(6).DefaultCellStyle.Format = "#,##0"
        請購明細_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        請購明細_dgv.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        請購明細_dgv.Columns(0).ReadOnly = True : 請購明細_dgv.Columns(1).ReadOnly = True : 請購明細_dgv.Columns(2).ReadOnly = True : 請購明細_dgv.Columns(3).ReadOnly = True
        請購明細_dgv.Columns(4).ReadOnly = False : 請購明細_dgv.Columns(7).ReadOnly = True : 請購明細_dgv.Columns("已採購").ReadOnly = True
        請購明細_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        If 低網速模式 = False Then
            請購明細_dgv.Columns(22).FillWeight = 80 : 請購明細_dgv.Columns(22).Visible = True
            Dim mycol As DataGridViewImageColumn = 請購明細_dgv.Columns("圖檔")
            mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
        Else
            If 請購明細_dgv.Columns.Count = 23 Then
                請購明細_dgv.Columns(21).Visible = False
            End If
        End If
        AAA1 = "" : AAA2 = "" : AAA3 = "" : AAA4 = "" : AAA5 = "" : AAA6 = "" : AAA7 = "" : AAA8 = ""
        For i As Integer = 0 To 請購明細_dgv.Rows.Count - 1
            '-------------------------規格合併呈現----------------------------------------------------------------------------------------------------------------------------------------
            If i = 0 Then
                PA3 = 請購明細_dgv.Rows(i).Cells("規格庫抬頭指定").Value
                SQL_規格庫抬頭讀取()
                If dr.Read() Then
                    AAA1 = dr("A1") : AAA2 = dr("A2") : AAA3 = dr("A3") : AAA4 = dr("A4") : AAA5 = dr("A5") : AAA6 = dr("A6") : AAA7 = dr("A7") : AAA8 = dr("A8")
                End If
                conn.Close()
            Else
                If 請購明細_dgv.Rows(i).Cells("規格庫抬頭指定").Value.ToString <> 請購明細_dgv.Rows(i - 1).Cells("規格庫抬頭指定").Value.ToString Then
                    PA3 = 請購明細_dgv.Rows(i).Cells("規格庫抬頭指定").Value
                    SQL_規格庫抬頭讀取()
                    If dr.Read() Then
                        AAA1 = dr("A1") : AAA2 = dr("A2") : AAA3 = dr("A3") : AAA4 = dr("A4") : AAA5 = dr("A5") : AAA6 = dr("A6") : AAA7 = dr("A7") : AAA8 = dr("A8")
                    End If
                    conn.Close()
                End If
            End If
            Dim ZA1, ZA2, ZA3, ZA4, ZA5, ZA6, ZA7, ZA8 As String : 物料規格 = ""
            If 詳細資料2_ch.Checked = True Then
                If 請購明細_dgv.Rows(i).Cells("規格").Value.ToString <> "" Then
                    ZA1 = AAA1 & "=" & 請購明細_dgv.Rows(i).Cells("規格").Value.ToString : 物料規格 = ZA1 : End If
                If 請購明細_dgv.Rows(i).Cells("A2").Value.ToString <> "" Then : ZA2 = AAA2 & "=" & 請購明細_dgv.Rows(i).Cells("A2").Value
                    If 物料規格 = "" Then : 物料規格 = ZA2 : Else : 物料規格 = 物料規格 + "、" + ZA2 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A3").Value.ToString <> "" Then : ZA3 = AAA3 & "=" & 請購明細_dgv.Rows(i).Cells("A3").Value
                    If 物料規格 = "" Then : 物料規格 = ZA3 : Else : 物料規格 = 物料規格 + "、" + ZA3 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A4").Value.ToString <> "" Then : ZA4 = AAA4 & "=" & 請購明細_dgv.Rows(i).Cells("A4").Value
                    If 物料規格 = "" Then : 物料規格 = ZA4 : Else : 物料規格 = 物料規格 + "、" + ZA4 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A5").Value.ToString <> "" Then : ZA5 = AAA5 & "=" & 請購明細_dgv.Rows(i).Cells("A5").Value
                    If 物料規格 = "" Then : 物料規格 = ZA5 : Else : 物料規格 = 物料規格 + "、" + ZA5 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A6").Value.ToString <> "" Then : ZA6 = AAA6 & "=" & 請購明細_dgv.Rows(i).Cells("A6").Value
                    If 物料規格 = "" Then : 物料規格 = ZA6 : Else : 物料規格 = 物料規格 + "、" + ZA6 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A7").Value.ToString <> "" Then : ZA7 = AAA7 & "=" & 請購明細_dgv.Rows(i).Cells("A7").Value
                    If 物料規格 = "" Then : 物料規格 = ZA7 : Else : 物料規格 = 物料規格 + "、" + ZA7 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A8").Value.ToString <> "" Then : ZA8 = AAA8 & "=" & 請購明細_dgv.Rows(i).Cells("A8").Value
                    If 物料規格 = "" Then : 物料規格 = ZA8 : Else : 物料規格 = 物料規格 + "、" + ZA8 : End If : End If
            Else
                If 請購明細_dgv.Rows(i).Cells("規格").Value.ToString <> "" Then : ZA1 = 請購明細_dgv.Rows(i).Cells("規格").Value.ToString : 物料規格 = ZA1 : End If
                If 請購明細_dgv.Rows(i).Cells("A2").Value.ToString <> "" Then
                    ZA2 = 請購明細_dgv.Rows(i).Cells("A2").Value : If 物料規格 = "" Then : 物料規格 = ZA2 : Else : 物料規格 = 物料規格 + "、" + ZA2 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A3").Value.ToString <> "" Then
                    ZA3 = 請購明細_dgv.Rows(i).Cells("A3").Value : If 物料規格 = "" Then : 物料規格 = ZA3 : Else : 物料規格 = 物料規格 + "、" + ZA3 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A4").Value.ToString <> "" Then
                    ZA4 = 請購明細_dgv.Rows(i).Cells("A4").Value : If 物料規格 = "" Then : 物料規格 = ZA4 : Else : 物料規格 = 物料規格 + "、" + ZA4 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A5").Value.ToString <> "" Then
                    ZA5 = 請購明細_dgv.Rows(i).Cells("A5").Value : If 物料規格 = "" Then : 物料規格 = ZA5 : Else : 物料規格 = 物料規格 + "、" + ZA5 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A6").Value.ToString <> "" Then
                    ZA6 = 請購明細_dgv.Rows(i).Cells("A6").Value : If 物料規格 = "" Then : 物料規格 = ZA6 : Else : 物料規格 = 物料規格 + "、" + ZA6 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A7").Value.ToString <> "" Then
                    ZA7 = 請購明細_dgv.Rows(i).Cells("A7").Value : If 物料規格 = "" Then : 物料規格 = ZA7 : Else : 物料規格 = 物料規格 + "、" + ZA7 : End If : End If
                If 請購明細_dgv.Rows(i).Cells("A8").Value.ToString <> "" Then
                    ZA8 = 請購明細_dgv.Rows(i).Cells("A8").Value : If 物料規格 = "" Then : 物料規格 = ZA8 : Else : 物料規格 = 物料規格 + "、" + ZA8 : End If : End If
            End If
            請購明細_dgv.Rows(i).Cells("規格").Value = 物料規格
        Next
        Set_請購單清單1()
    End Sub
    Private Sub Set_請購單清單1()
        Dim ds2 As New DataSet : 請購明細1_dgv.DataSource = Nothing : ds2.Clear()
        請購明細1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        請購明細1_dgv.ColumnHeadersHeight = 25
        請購明細1_dgv.AllowUserToAddRows = False
        請購明細1_dgv.RowTemplate.Height = 35

        SQL_建築物料請購單核准_請購單清單()
        da.Fill(ds2) : 請購明細1_dgv.DataSource = ds2.Tables(0) : conn.Close()

        If 低網速模式 = False Then
            請購明細1_dgv.Columns(20).FillWeight = 80 : 請購明細1_dgv.Columns(20).Visible = True
            Dim mycol As DataGridViewImageColumn = 請購明細1_dgv.Columns("圖檔")
            mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
        Else
            If 請購明細1_dgv.Columns.Count = 21 Then
                請購明細1_dgv.Columns(20).Visible = False
            End If
        End If

        AAA1 = "" : AAA2 = "" : AAA3 = "" : AAA4 = "" : AAA5 = "" : AAA6 = "" : AAA7 = "" : AAA8 = ""
        For i As Integer = 0 To 請購明細1_dgv.Rows.Count - 1
            '-------------------------規格合併呈現----------------------------------------------------------------------------------------------------------------------------------------
            If i = 0 Then
                PA3 = 請購明細1_dgv.Rows(i).Cells("規格庫抬頭指定").Value : PA20 = 系統語言_cb.Text
                SQL_規格庫抬頭讀取_列印用()
                If dr.Read() Then
                    AAA1 = dr("A1") : AAA2 = dr("A2") : AAA3 = dr("A3") : AAA4 = dr("A4") : AAA5 = dr("A5") : AAA6 = dr("A6") : AAA7 = dr("A7") : AAA8 = dr("A8")
                End If
                conn.Close()
            Else
                If 請購明細1_dgv.Rows(i).Cells("規格庫抬頭指定").Value.ToString <> 請購明細1_dgv.Rows(i - 1).Cells("規格庫抬頭指定").Value.ToString Then
                    PA3 = 請購明細1_dgv.Rows(i).Cells("規格庫抬頭指定").Value : PA20 = 系統語言_cb.Text
                    SQL_規格庫抬頭讀取_列印用()
                    If dr.Read() Then
                        AAA1 = dr("A1") : AAA2 = dr("A2") : AAA3 = dr("A3") : AAA4 = dr("A4") : AAA5 = dr("A5") : AAA6 = dr("A6") : AAA7 = dr("A7") : AAA8 = dr("A8")
                    End If
                    conn.Close()
                End If
            End If
            Dim ZA1, ZA2, ZA3, ZA4, ZA5, ZA6, ZA7, ZA8 As String : 物料規格 = ""
            If 詳細資料2_ch.Checked = True Then
                If 請購明細1_dgv.Rows(i).Cells("規格").Value.ToString <> "" Then
                    ZA1 = AAA1 & "=" & 請購明細1_dgv.Rows(i).Cells("規格").Value.ToString : 物料規格 = ZA1 : End If
                If 請購明細1_dgv.Rows(i).Cells("A2").Value.ToString <> "" Then : ZA2 = AAA2 & "=" & 請購明細1_dgv.Rows(i).Cells("A2").Value
                    If 物料規格 = "" Then : 物料規格 = ZA2 : Else : 物料規格 = 物料規格 + "、" + ZA2 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A3").Value.ToString <> "" Then : ZA3 = AAA3 & "=" & 請購明細1_dgv.Rows(i).Cells("A3").Value
                    If 物料規格 = "" Then : 物料規格 = ZA3 : Else : 物料規格 = 物料規格 + "、" + ZA3 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A4").Value.ToString <> "" Then : ZA4 = AAA4 & "=" & 請購明細1_dgv.Rows(i).Cells("A4").Value
                    If 物料規格 = "" Then : 物料規格 = ZA4 : Else : 物料規格 = 物料規格 + "、" + ZA4 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A5").Value.ToString <> "" Then : ZA5 = AAA5 & "=" & 請購明細1_dgv.Rows(i).Cells("A5").Value
                    If 物料規格 = "" Then : 物料規格 = ZA5 : Else : 物料規格 = 物料規格 + "、" + ZA5 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A6").Value.ToString <> "" Then : ZA6 = AAA6 & "=" & 請購明細1_dgv.Rows(i).Cells("A6").Value
                    If 物料規格 = "" Then : 物料規格 = ZA6 : Else : 物料規格 = 物料規格 + "、" + ZA6 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A7").Value.ToString <> "" Then : ZA7 = AAA7 & "=" & 請購明細1_dgv.Rows(i).Cells("A7").Value
                    If 物料規格 = "" Then : 物料規格 = ZA7 : Else : 物料規格 = 物料規格 + "、" + ZA7 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A8").Value.ToString <> "" Then : ZA8 = AAA8 & "=" & 請購明細1_dgv.Rows(i).Cells("A8").Value
                    If 物料規格 = "" Then : 物料規格 = ZA8 : Else : 物料規格 = 物料規格 + "、" + ZA8 : End If : End If
            Else
                If 請購明細1_dgv.Rows(i).Cells("規格").Value.ToString <> "" Then : ZA1 = 請購明細1_dgv.Rows(i).Cells("規格").Value.ToString : 物料規格 = ZA1 : End If
                If 請購明細1_dgv.Rows(i).Cells("A2").Value.ToString <> "" Then
                    ZA2 = 請購明細1_dgv.Rows(i).Cells("A2").Value : If 物料規格 = "" Then : 物料規格 = ZA2 : Else : 物料規格 = 物料規格 + "、" + ZA2 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A3").Value.ToString <> "" Then
                    ZA3 = 請購明細1_dgv.Rows(i).Cells("A3").Value : If 物料規格 = "" Then : 物料規格 = ZA3 : Else : 物料規格 = 物料規格 + "、" + ZA3 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A4").Value.ToString <> "" Then
                    ZA4 = 請購明細1_dgv.Rows(i).Cells("A4").Value : If 物料規格 = "" Then : 物料規格 = ZA4 : Else : 物料規格 = 物料規格 + "、" + ZA4 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A5").Value.ToString <> "" Then
                    ZA5 = 請購明細1_dgv.Rows(i).Cells("A5").Value : If 物料規格 = "" Then : 物料規格 = ZA5 : Else : 物料規格 = 物料規格 + "、" + ZA5 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A6").Value.ToString <> "" Then
                    ZA6 = 請購明細1_dgv.Rows(i).Cells("A6").Value : If 物料規格 = "" Then : 物料規格 = ZA6 : Else : 物料規格 = 物料規格 + "、" + ZA6 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A7").Value.ToString <> "" Then
                    ZA7 = 請購明細1_dgv.Rows(i).Cells("A7").Value : If 物料規格 = "" Then : 物料規格 = ZA7 : Else : 物料規格 = 物料規格 + "、" + ZA7 : End If : End If
                If 請購明細1_dgv.Rows(i).Cells("A8").Value.ToString <> "" Then
                    ZA8 = 請購明細1_dgv.Rows(i).Cells("A8").Value : If 物料規格 = "" Then : 物料規格 = ZA8 : Else : 物料規格 = 物料規格 + "、" + ZA8 : End If : End If
            End If
            請購明細1_dgv.Rows(i).Cells("規格").Value = 物料規格
        Next
    End Sub
    Private Sub Set_清單1()
        Dim ds1 As New DataSet : 未核准_dgv.DataSource = Nothing : ds1.Clear()
        未核准_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        未核准_dgv.ColumnHeadersHeight = 40
        未核准_dgv.AllowUserToAddRows = False
        SQL_建築物料請購單申請_未核准()
        da.Fill(ds1) : 未核准_dgv.DataSource = ds1.Tables(0) : conn.Close()
        未核准_dgv.Columns(0).FillWeight = 120 : 未核准_dgv.Columns(1).FillWeight = 160 : 未核准_dgv.Columns(2).FillWeight = 90 : 未核准_dgv.Columns(3).Visible = False
        未核准_dgv.Columns(4).Visible = False : 未核准_dgv.Columns(5).Visible = False : 未核准_dgv.Columns(7).Visible = False : 未核准_dgv.Columns(8).Visible = False
        未核准_dgv.Columns(9).Visible = False : 未核准_dgv.Columns(10).Visible = False : 未核准_dgv.Columns(11).Visible = False : 未核准_dgv.Columns(6).FillWeight = 120
        未核准_dgv.Columns("退單備註").Visible = False : 未核准_dgv.Columns("退單").FillWeight = 50
        For i As Integer = 0 To 未核准_dgv.Rows.Count - 1
            If IsDBNull(未核准_dgv.Rows(i).Cells("退單").Value) Then : 未核准_dgv.Rows(i).Cells("退單").Value = False : End If
        Next
    End Sub
    Private Sub Set_清單2()
        Dim ds6 As New DataSet : 已核准_dgv.DataSource = Nothing : ds6.Clear()
        已核准_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        已核准_dgv.ColumnHeadersHeight = 40
        已核准_dgv.AllowUserToAddRows = False
        SQL_建築物料請購單申請_已核准()
        da.Fill(ds6) : 已核准_dgv.DataSource = ds6.Tables(0) : conn.Close()
        已核准_dgv.Columns(0).FillWeight = 120 : 已核准_dgv.Columns(1).FillWeight = 160 : 已核准_dgv.Columns(2).FillWeight = 90 : 已核准_dgv.Columns(3).Visible = False
        已核准_dgv.Columns(4).Visible = False : 已核准_dgv.Columns(5).Visible = False : 已核准_dgv.Columns(7).Visible = False : 已核准_dgv.Columns(8).Visible = False
        已核准_dgv.Columns(9).Visible = False : 已核准_dgv.Columns(10).Visible = False : 已核准_dgv.Columns(11).Visible = False : 已核准_dgv.Columns(6).FillWeight = 120
        已核准_dgv.Columns("退單備註").Visible = False : 已核准_dgv.Columns("退單").FillWeight = 50
        For i As Integer = 0 To 已核准_dgv.Rows.Count - 1
            If IsDBNull(已核准_dgv.Rows(i).Cells("退單").Value) Then : 已核准_dgv.Rows(i).Cells("退單").Value = False : End If
        Next
    End Sub
    Private Sub Set_清單3()
        Dim ds3 As New DataSet : 作廢清單_dgv.DataSource = Nothing : ds3.Clear()
        作廢清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        作廢清單_dgv.ColumnHeadersHeight = 40
        作廢清單_dgv.AllowUserToAddRows = False
        SQL_建築物料請購單申請_作廢清單()
        da.Fill(ds3) : 作廢清單_dgv.DataSource = ds3.Tables(0) : conn.Close()
        作廢清單_dgv.Columns(0).FillWeight = 120 : 作廢清單_dgv.Columns(1).FillWeight = 160 : 作廢清單_dgv.Columns(2).FillWeight = 90 : 作廢清單_dgv.Columns(3).Visible = False
        作廢清單_dgv.Columns(4).Visible = False : 作廢清單_dgv.Columns(5).Visible = False : 作廢清單_dgv.Columns(7).Visible = False : 作廢清單_dgv.Columns(8).Visible = False
        作廢清單_dgv.Columns(9).Visible = False : 作廢清單_dgv.Columns(10).Visible = False : 作廢清單_dgv.Columns(11).Visible = False : 作廢清單_dgv.Columns(6).FillWeight = 120
        作廢清單_dgv.Columns("退單備註").Visible = False : 作廢清單_dgv.Columns("退單").FillWeight = 50
        For i As Integer = 0 To 作廢清單_dgv.Rows.Count - 1
            If IsDBNull(作廢清單_dgv.Rows(i).Cells("退單").Value) Then : 作廢清單_dgv.Rows(i).Cells("退單").Value = False : End If
        Next
    End Sub
    Private Sub 作業選擇()
        If 零用金選擇 = True Then
            請購單核准_bt.Enabled = True : 請購單作廢_bt.Enabled = True
        Else
            請購單核准_bt.Enabled = False : 請購單作廢_bt.Enabled = False
        End If
        請購單號_tb.Text = PA : 申請日期_dtp.Value = PA2 : 申請人_tb.Text = PA1 : Set_請購單清單()
    End Sub
    Private Sub Set_日期格式轉換()
        DTP = Strings.Format(Today(), "yyyy/MM/dd") & "-" & Strings.Format(TimeOfDay(), "HH:mm:ss") : DTP1 = Strings.Format(Today(), "yyyyMMdd")
    End Sub
    Private Sub ComboBox1下拉表單資料載入()
        SQL_倉名_下拉清單() : 指定倉庫_cb.Items.Clear()
        While (dr.Read()) : 指定倉庫_cb.Items.Add(dr("倉名")) : End While : conn.Close()
    End Sub
    Private Sub 請購單核准_bt_MouseEnter(sender As Object, e As EventArgs) Handles 請購單核准_bt.MouseEnter
        ToolTip1.SetToolTip(Me.請購單核准_bt, "請購單核准")
    End Sub
    Private Sub 請購單作廢_bt_MouseEnter(sender As Object, e As EventArgs) Handles 請購單作廢_bt.MouseEnter
        ToolTip1.SetToolTip(Me.請購單作廢_bt, "請購單作廢")
    End Sub
    Private Sub 存檔_bt_MouseEnter(sender As Object, e As EventArgs) Handles 存檔_bt.MouseEnter
        ToolTip1.SetToolTip(Me.存檔_bt, "存檔")
    End Sub
    Private Sub 確認列印_bt_MouseEnter(sender As Object, e As EventArgs) Handles 確認列印_bt.MouseEnter
        ToolTip1.SetToolTip(Me.確認列印_bt, "確認列印")
    End Sub
    Private Sub 加急件_bt_MouseEnter(sender As Object, e As EventArgs) Handles 加急件_bt.MouseEnter
        ToolTip1.SetToolTip(Me.加急件_bt, "加急件")
    End Sub
    Private Sub 請購單核准_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = FH_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        Panel1.SendToBack() : 未審核_rb.Checked = True : 未核准_dgv.Visible = True
        申請日期_dtp.Enabled = False : 確認列印_bt.Enabled = False : 需求日期_dtp.Format = DateTimePickerFormat.Custom
        需求日期_dtp.CustomFormat = " " : 系統語言_cb.Text = "繁體中文" : 作廢清單_dgv.Visible = False : 已核准_dgv.Visible = False
        小間距_ch.Checked = False : 中間距_ch.Checked = True : 大間距_ch.Checked = False : ToolTip1.ToolTipTitle = "系統說明"

        作廢清單_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", FH_ERP_SYS.字體_NUD.Value)
        未核准_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", FH_ERP_SYS.字體_NUD.Value)
        已核准_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", FH_ERP_SYS.字體_NUD.Value)
        請購明細_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", FH_ERP_SYS.字體_NUD.Value)
    End Sub
    Private Sub 請購單核准_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        ComboBox1下拉表單資料載入() : Set_清單1() : Set_清單2() : Set_清單3()
    End Sub
    Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
        timeNow = 0 : FH_ERP_SYS.Timer1.Enabled = False : FH_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
        timeNow = 0 : FH_ERP_SYS.Timer1.Enabled = False : FH_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 未核准_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 未核准_dgv.CellClick
        If e.RowIndex = -1 Then : Else : 選擇項 = e.RowIndex : 未核准讀取() : End If : 刪除請購單上點選資料_bt.Enabled = True
    End Sub
    Private Sub 未核准讀取()
        PA = 未核准_dgv(0, 選擇項).Value.ToString : PA1 = 未核准_dgv(1, 選擇項).Value.ToString : PA2 = 未核准_dgv(2, 選擇項).Value.ToString : 零用金選擇 = True
        審核_tb.Text = 未核准_dgv(3, 選擇項).Value.ToString : 合約號_tb.Text = 未核准_dgv(6, 選擇項).Value.ToString
        備註_tb.Text = 未核准_dgv("備註", 選擇項).Value.ToString : 作業選擇()

        '----------------------------讀取申請人資料-------------------------------------------------------------
        SQL_請購單審核_申請人資料()
        If dr.Read() Then
            申請人部門_tb.Text = dr("部門") : 申請人課別_tb.Text = dr("課別") : 申請人組別_tb.Text = dr("組別") : 申請人級別_tb.Text = dr("級別")
        End If
        '----------------------------判斷是否為申請人主管-------------------------------------------------------------
        If Val(登入人級別) <= 7 Then : 請購單核准_bt.Enabled = True : 請購單作廢_bt.Enabled = True
        Else : 請購單核准_bt.Enabled = False : 請購單作廢_bt.Enabled = False : End If

        If 請購明細_dgv.Rows.Count > 0 Then : 指定倉庫_cb.Text = 請購明細_dgv.Rows(0).Cells("備註").Value.ToString
        Else : ComboBox1下拉表單資料載入() : 倉庫編號_tb.Text = "" : 倉庫級別_tb.Text = "" : End If

        If 未核准_dgv(5, 選擇項).Value.ToString = "" Then : 需求日期_dtp.Format = DateTimePickerFormat.Custom : 需求日期_dtp.CustomFormat = " "
        Else : 需求日期_dtp.Format = DateTimePickerFormat.Short : 需求日期_dtp.Value = 未核准_dgv(5, 選擇項).Value.ToString : End If

        If 審核_tb.Text = "" Then : 確認列印_bt.Enabled = False : Else : 確認列印_bt.Enabled = True : End If
    End Sub
    Private Sub 已核准_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 已核准_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            PA = 已核准_dgv(0, e.RowIndex).Value.ToString : PA1 = 已核准_dgv(1, e.RowIndex).Value.ToString : PA2 = 已核准_dgv(2, e.RowIndex).Value.ToString : 零用金選擇 = True
            審核_tb.Text = 已核准_dgv(3, e.RowIndex).Value.ToString : 合約號_tb.Text = 已核准_dgv(6, e.RowIndex).Value.ToString
            備註_tb.Text = 已核准_dgv("備註", e.RowIndex).Value.ToString : 作業選擇()

            If 請購明細_dgv.Rows.Count > 0 Then : 指定倉庫_cb.Text = 請購明細_dgv.Rows(0).Cells("備註").Value.ToString
            Else : ComboBox1下拉表單資料載入() : 倉庫編號_tb.Text = "" : 倉庫級別_tb.Text = "" : End If

            If 已核准_dgv(5, e.RowIndex).Value.ToString = "" Then : 需求日期_dtp.Format = DateTimePickerFormat.Custom : 需求日期_dtp.CustomFormat = " "
            Else : 需求日期_dtp.Format = DateTimePickerFormat.Short : 需求日期_dtp.Value = 已核准_dgv(5, e.RowIndex).Value.ToString : End If
            If 已核准_dgv.Rows(e.RowIndex).Cells("退單").Value = True Then : MsgBox(已核准_dgv.Rows(e.RowIndex).Cells("退單備註").Value.ToString) : End If
            If 審核_tb.Text = "" Then : 確認列印_bt.Enabled = False : Else : 確認列印_bt.Enabled = True : End If
        End If : 請購單核准_bt.Enabled = False : 刪除請購單上點選資料_bt.Enabled = False
    End Sub
    Private Sub 作廢清單_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 作廢清單_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            PA = 作廢清單_dgv(0, e.RowIndex).Value.ToString : PA1 = 作廢清單_dgv(1, e.RowIndex).Value.ToString : PA2 = 作廢清單_dgv(2, e.RowIndex).Value.ToString : 零用金選擇 = False
            審核_tb.Text = 作廢清單_dgv(3, e.RowIndex).Value.ToString : 合約號_tb.Text = 作廢清單_dgv(6, e.RowIndex).Value.ToString
            備註_tb.Text = 作廢清單_dgv("備註", e.RowIndex).Value.ToString : 作業選擇()

            If 請購明細_dgv.Rows.Count > 0 Then : 指定倉庫_cb.Text = 請購明細_dgv.Rows(0).Cells("備註").Value.ToString
            Else : ComboBox1下拉表單資料載入() : 倉庫編號_tb.Text = "" : 倉庫級別_tb.Text = "" : End If

            If 作廢清單_dgv(5, e.RowIndex).Value.ToString = "" Then : 需求日期_dtp.Format = DateTimePickerFormat.Custom : 需求日期_dtp.CustomFormat = " "
            Else : 需求日期_dtp.Format = DateTimePickerFormat.Short : 需求日期_dtp.Value = 作廢清單_dgv(5, e.RowIndex).Value.ToString : End If
            If 作廢清單_dgv.Rows(e.RowIndex).Cells("退單").Value = True Then : MsgBox(作廢清單_dgv.Rows(e.RowIndex).Cells("退單備註").Value.ToString) : End If
            If 審核_tb.Text = "" Then : 確認列印_bt.Enabled = False : Else : 確認列印_bt.Enabled = True : End If
        End If : 刪除請購單上點選資料_bt.Enabled = False
    End Sub
    Private Sub 請購明細_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 請購明細_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            項次_tb.Text = 請購明細_dgv(1, e.RowIndex).Value.ToString : 指定倉庫_cb.Text = 請購明細_dgv.Rows(e.RowIndex).Cells("備註").Value
            PA1 = 請購明細_dgv.Rows(e.RowIndex).Cells("群組碼").Value : PA2 = 請購明細_dgv.Rows(e.RowIndex).Cells("群組原則").Value
            SQL_物料圖庫_圖檔讀取()
            While dr.Read() = True
                Dim unused As Byte() = New Byte(-1) {}
                Dim bytes As Byte() = DirectCast(dr.Item("圖檔"), Byte())
                Dim oStream As New MemoryStream(bytes)
                物料圖_pb.Image = Bitmap.FromStream(oStream)
            End While : conn.Close() : 物料圖_pb.SizeMode = 4
        End If
    End Sub
    Private Sub 需求日期_dtp_ValueChanged(sender As Object, e As EventArgs) Handles 需求日期_dtp.MouseDown
        需求日期_dtp.Format = DateTimePickerFormat.Short
    End Sub
    Private Sub 指定倉庫_cb_Click(sender As Object, e As EventArgs) Handles 指定倉庫_cb.Click
        CB選擇清單(指定倉庫_cb, 指定倉庫_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 未審核_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 未審核_rb.CheckedChanged
        If 未審核_rb.Checked = True Then
            未審核_rb.Checked = True : 已作廢_rb.Checked = False : 已審核_rb.Checked = False : 未核准_dgv.Visible = True
            作廢清單_dgv.Visible = False : 已核准_dgv.Visible = False
            請購明細_dgv.DataSource = Nothing : 請購單號_tb.Text = "" : 申請人_tb.Text = "" : 項次_tb.Text = ""
        End If
    End Sub
    Private Sub 已作廢_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 已作廢_rb.CheckedChanged
        If 已作廢_rb.Checked = True Then
            未審核_rb.Checked = False : 已作廢_rb.Checked = True : 已審核_rb.Checked = False : 未核准_dgv.Visible = False
            作廢清單_dgv.Visible = True : 已核准_dgv.Visible = False
            請購明細_dgv.DataSource = Nothing : 請購單號_tb.Text = "" : 申請人_tb.Text = "" : 項次_tb.Text = ""
        End If
    End Sub
    Private Sub 已審核_rb_CheckedChanged(sender As Object, e As EventArgs) Handles 已審核_rb.CheckedChanged
        If 已審核_rb.Checked = True Then
            未審核_rb.Checked = False : 已作廢_rb.Checked = False : 已審核_rb.Checked = True : 未核准_dgv.Visible = False
            作廢清單_dgv.Visible = False : 已核准_dgv.Visible = True
            請購明細_dgv.DataSource = Nothing : 請購單號_tb.Text = "" : 申請人_tb.Text = "" : 項次_tb.Text = ""
        End If
    End Sub
    Private Sub 請購單核准_bt_Click(sender As Object, e As EventArgs) Handles 請購單核准_bt.Click
        If 指定倉庫_cb.Text = "" Then : MsgBox("請選擇使用地點。") : Else
            If 需求日期_dtp.Text = "" Or 需求日期_dtp.Text = " " Then : MsgBox("沒有選擇需求日期。") : Else
                Set_日期格式轉換()
                If 請購單號_tb.Text = "" Then : MsgBox("沒有選擇單據。") : Else
                    PA = 請購單號_tb.Text : PA1 = gUserName : SQL_建築物料請購單核准_請購單核准() : conn.Close()
                    MsgBox("單據 [" & 請購單號_tb.Text & "] 核准完成。")
                    請購單號_tb.Text = "" : 申請人_tb.Text = "" : 請購明細_dgv.DataSource = Nothing
                    Set_清單1() : Set_清單2() : Set_清單3()
                End If
            End If
        End If
    End Sub
    Private Sub 加急件_bt_Click(sender As Object, e As EventArgs) Handles 加急件_bt.Click
        If 指定倉庫_cb.Text = "" Then : MsgBox("請選擇使用地點。") : Else
            If 需求日期_dtp.Text = "" Or 需求日期_dtp.Text = " " Then : MsgBox("沒有選擇需求日期。") : Else
                Set_日期格式轉換()
                If 請購單號_tb.Text = "" Then : MsgBox("沒有選擇單據。") : Else
                    PA = 請購單號_tb.Text : PA1 = gUserName : SQL_建築物料請購單核准_請購單核准() : conn.Close() : SQL_請購單核准_加急核准() : conn.Close()
                    PA4 = 請購單號_tb.Text : SQL_請購單申請_加急存檔() : conn.Close()
                    '---LINE_AUTO 部門主管------------------------------------------------------------------------------------------------------------------------------------------
                    LIN訊息通知("CC209", "FH-系統通知(通用)", ",", 請購單號_tb.Text) : LIN訊息通知("CC209", "FH-系統通知(主管)", ",", 請購單號_tb.Text)
                    '---完成加急核准------------------------------------------------------------------------------------------------------------------------------------------
                    MsgBox("單據 [" & 請購單號_tb.Text & "] 核准完成。") : 請購單號_tb.Text = "" : 申請人_tb.Text = "" : 請購明細_dgv.DataSource = Nothing
                    Set_清單1() : Set_清單2() : Set_清單3()
                End If
            End If
        End If
    End Sub
    Private Sub 請購單作廢_bt_Click(sender As Object, e As EventArgs) Handles 請購單作廢_bt.Click
        If 指定倉庫_cb.Text = "" Then : MsgBox("請選擇使用地點。") : Else
            If 需求日期_dtp.Text = "" Or 需求日期_dtp.Text = " " Then : MsgBox("沒有選擇需求日期。") : Else
                Set_日期格式轉換()
                If 請購單號_tb.Text = "" Then : MsgBox("沒有選擇單據。") : Else
                    Dim result As DialogResult = MessageBox.Show("確定要作廢該筆資料?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                    If result = DialogResult.Yes Then
                        PA = 請購單號_tb.Text : PA1 = "作廢-" & gUserName : SQL_建築物料請購單核准_請購單核准() : conn.Close()
                        MsgBox("單據 [" & 請購單號_tb.Text & "] 已作廢。")
                        請購單號_tb.Text = "" : 申請人_tb.Text = ""
                        請購明細_dgv.DataSource = Nothing
                    End If
                    Set_清單1() : Set_清單2() : Set_清單3()
                End If
            End If
        End If
    End Sub
    Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click
        存檔()
        Dim result As DialogResult = MessageBox.Show("保存完成，是否直接將單據完成核准?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = DialogResult.Yes Then : Me.請購單核准_bt.PerformClick() : End If
    End Sub
    Private Sub 存檔()
        For i As Integer = 0 To 請購明細_dgv.Rows.Count - 1
            資料數 = 請購明細_dgv.Rows.Count : MyMod.進度條()
            PA1 = 請購明細_dgv.Rows(i).Cells("備註").Value.ToString.Replace("'", "") : NU1 = 請購明細_dgv.Rows(i).Cells("數量").Value
            PA2 = 請購明細_dgv.Rows(i).Cells("單位").Value : PA3 = 倉庫編號_tb.Text : PA4 = 請購單號_tb.Text : PA5 = 請購明細_dgv.Rows(i).Cells("項次").Value
            SQL_建築物料請購單申請_存檔() : conn.Close()
        Next
        PA1 = 請購單號_tb.Text : If 需求日期_dtp.Text = "" Or 需求日期_dtp.Text = " " Then : DTP = "" : Else : DTP = Strings.Format(需求日期_dtp.Value, "yyyy/MM/dd") : End If
        SQL_請購單需求日其修改() : FH_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
    End Sub
    Private Sub 刪除請購單上點選資料_bt_Click(sender As Object, e As EventArgs) Handles 刪除請購單上點選資料_bt.Click
        If 請購單號_tb.Text = "" Then : MsgBox("沒有選擇單據。") : Else
            If 項次_tb.Text = "" Then : MsgBox("未選擇需要刪除的資料。") : Else
                Dim result As DialogResult = MessageBox.Show("確定要刪除該筆資料?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If result = DialogResult.Yes Then
                    存檔() : PA1 = 請購單號_tb.Text : PA2 = 項次_tb.Text : SQL_請購單明細表_指定刪除() : conn.Close()
                    Set_請購單清單() : Dim NUM1 As Integer = 0
                    For i As Integer = 0 To 請購明細_dgv.Rows.Count - 1
                        NUM1 += 1 : If NUM1 < 10 Then : 新項次 = "0" & NUM1 : ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = NUM1 : End If
                        PA = 新項次 : PA1 = 請購單號_tb.Text : PA2 = 請購明細_dgv.Rows(i).Cells("項次").Value
                        SQL_請購單明細表_項次修改() : conn.Close()
                    Next : Set_請購單清單()
                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 : Set_請購單清單()
    End Sub
    Private Sub 中間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 中間距_ch.Click
        小間距_ch.Checked = False : 中間距_ch.Checked = True : 大間距_ch.Checked = False : Set_請購單清單()
    End Sub
    Private Sub 大間距_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 大間距_ch.Click
        小間距_ch.Checked = False : 中間距_ch.Checked = False : 大間距_ch.Checked = True : Set_請購單清單()
    End Sub
    Private Sub 確認列印_bt_Click(sender As Object, e As EventArgs) Handles 確認列印_bt.Click
        xlApp = CType(CreateObject("Excel.Application"), Application)
        xlBook = xlApp.Workbooks.Add
        xlApp.DisplayAlerts = True
        xlBook.Activate()
        xlSheet = NewMethod(xlBook)
        xlSheet.Activate()
        xlApp.Visible = True
        xlApp.Application.WindowState = xlMaximized

        xlSheet.Cells(3, 1) = "請購單"
        xlSheet.Cells(5, 1) = "1、請購單編號 : " & 請購單號_tb.Text
        xlSheet.Cells(5, 4) = "2、申請人 : " & 申請人_tb.Text
        xlSheet.Cells(6, 1) = "3、指定倉庫 : " & 指定倉庫_cb.Text
        xlSheet.Cells(6, 4) = "4、需求日期 : " & 需求日期_dtp.Value
        xlSheet.Cells(7, 1) = "5、請購審核人 : " & 審核_tb.Text

        xlSheet.Cells(9, 1) = "No." : xlSheet.Cells(9, 2) = "圖號/料號" : xlSheet.Cells(9, 3) = "品名" : xlSheet.Cells(9, 4) = "規格" : xlSheet.Cells(9, 5) = "數量"
        xlSheet.Cells(9, 6) = "單位" : xlSheet.Cells(9, 7) = "備註"
        For i As Integer = 0 To 請購明細1_dgv.Rows.Count - 1
            xlSheet.Cells(i + 10, 1) = i + 1
            xlSheet.Cells(i + 10, 2) = 請購明細1_dgv.Rows(i).Cells("料號").Value : xlSheet.Cells(i + 10, 3) = 請購明細1_dgv.Rows(i).Cells("品名").Value
            xlSheet.Cells(i + 10, 4) = 請購明細1_dgv.Rows(i).Cells("規格").Value : xlSheet.Cells(i + 10, 5) = 請購明細1_dgv.Rows(i).Cells("數量").Value
            xlSheet.Cells(i + 10, 6) = 請購明細1_dgv.Rows(i).Cells("單位").Value : xlSheet.Cells(i + 10, 7) = 請購明細1_dgv.Rows(i).Cells("備註").Value
            N1 = i + 10
        Next i
        AA(xlApp, xlSheet) : CC(xlApp, xlSheet)
        '-------------轉換成PDF---------------------------------------------------------------------
        Dim SERT As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        xlBook.Sheets(1).ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, SERT & "\" & 請購單號_tb.Text & "_PP(請購單).pdf", XlFixedFormatQuality.xlQualityStandard, True)
        '-------------關閉EXCEL---------------------------------------------------------------------
        xlSheet.PageSetup.PrintArea = "" : xlApp.Cells.Select()
        xlApp.Application.WindowState = xlMinimized
        xlBook.Close(False)
        Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
        Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
        Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
        xlApp.Quit() : xlSheet = Nothing : xlBook = Nothing : xlApp = Nothing : GC.Collect()
        '-------------開啟PDF---------------------------------------------------------------------
        Dim pdfFilePath As String = SERT & "\" & 請購單號_tb.Text & "_PP(請購單).pdf"
        If IsChromeInstalled() Then
            Try
                Dim chromeProcess As New Process()
                chromeProcess.StartInfo.FileName = "chrome"
                chromeProcess.StartInfo.Arguments = """" & pdfFilePath & """"
                chromeProcess.Start()
            Catch ex As Exception
            End Try
        Else
            Try
                System.Diagnostics.Process.Start("""" & pdfFilePath & """")
            Catch ex As Exception
            End Try
        End If
        MsgBox("列印完成。")
    End Sub
    ' 檢查系統是否已安裝 Google Chrome
    Private Function IsChromeInstalled() As Boolean
        Dim key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
        If key IsNot Nothing Then
            For Each subkeyName As String In key.GetSubKeyNames()
                Dim subkey As Microsoft.Win32.RegistryKey = key.OpenSubKey(subkeyName)
                Dim displayName As Object = subkey.GetValue("DisplayName")

                If displayName IsNot Nothing AndAlso displayName.ToString().Contains("Google Chrome") Then
                    Return True
                End If
            Next
        End If
        Return False
    End Function
    Private Shared Function NewMethod(xlBook As Workbook) As Worksheet
        Return CType(xlBook.Worksheets.Add, Worksheet)
    End Function
    Private Sub AA(ByVal myExcel As Application, ByVal xlSheet As Worksheet)
        xlSheet.Cells.Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 12 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
        End With
        xlSheet.Range("1:3").Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 18 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
        End With
        xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 5
        xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 30
        xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 30
        xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 30
        xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 8
        xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("G:G").Select : myExcel.Selection.ColumnWidth = 20
        xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 85
        xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 25
        xlSheet.Rows("4:4").Select : myExcel.Selection.RowHeight = 5
        xlSheet.Rows("8:8").Select : myExcel.Selection.RowHeight = 5
        xlSheet.Rows("9:9").Select : myExcel.Selection.RowHeight = 25
        xlSheet.Rows("5:7").Select : myExcel.Selection.RowHeight = 25
        xlSheet.Rows("10:" & N1).Select : myExcel.Selection.RowHeight = 60

        xlSheet.Range("A10:G" & N1).Select()
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 10 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
        End With
        With myExcel.Selection : .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With

        xlSheet.Cells.Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With

        xlSheet.Range("D10:D" & N1).Select()
        myExcel.Selection.Style = "Comma"
        myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"

        xlSheet.Range("B10:C" & N1).Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = True : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With

        xlSheet.Range("A2:G2").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False
            .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With : myExcel.Selection.Merge
        With myExcel.Selection.Font : .Name = "微軟正黑體" : .Size = 18 : .Strikethrough = False : .Superscript = False : .Subscript = False : .OutlineFont = False : .Shadow = False
            .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
        End With

        xlSheet.Range("A3:G3").Select()
        With myExcel.Selection : .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
        End With : myExcel.Selection.Merge
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("A5:G7").Select()
        With myExcel.Selection : .HorizontalAlignment = xlLeft : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
            .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False : End With

        xlSheet.Range("A7:G7").Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        myExcel.Selection.Borders(xlEdgeLeft).LineStyle = xlNone : myExcel.Selection.Borders(xlEdgeTop).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        myExcel.Selection.Borders(xlEdgeRight).LineStyle = xlNone : myExcel.Selection.Borders(xlInsideVertical).LineStyle = xlNone
        myExcel.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

        xlSheet.Range("A9:G" & N1).Select()
        myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone : myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With myExcel.Selection.Borders(xlEdgeLeft) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeTop) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeBottom) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlEdgeRight) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideVertical) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With
        With myExcel.Selection.Borders(xlInsideHorizontal) : .LineStyle = xlContinuous : .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin : End With

        xlSheet.Range("A9:G9").Select()
        With myExcel.Selection.Interior : .Pattern = xlSolid : .PatternColorIndex = xlAutomatic : .ThemeColor = xlThemeColorAccent2
            .TintAndShade = 0.799981688894314 : .PatternTintAndShade = 0
        End With

        xlSheet.Range("A1").Select() : myExcel.ActiveWindow.DisplayGridlines = False
        Dim 攔寬 As Single
        xlSheet.Rows("9:" & N1).Select : xlSheet.Rows("9:" & N1).EntireRow.AutoFit
        For i As Integer = 9 To N1
            xlSheet.Rows(i & ":" & i).Select
            攔寬 = xlSheet.Rows(i & ":" & i).RowHeight
            xlSheet.Rows(i & ":" & i).Select : myExcel.Selection.RowHeight = 攔寬 + 20
        Next
        myExcel.ActiveSheet.PageSetup.CenterHeaderPicture.Filename =
            Str01 & "\FHBWLOG.png"

        myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "$1:$9" : .PrintTitleColumns = "" : End With
        myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "$A:$G" : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .LeftHeader = ""
            .CenterHeader = "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "&G"
            .RightHeader = "" : .LeftFooter = "" : .CenterFooter = "第 &P 頁，共 &N 頁" : .RightFooter = ""
            .LeftMargin = myExcel.Application.InchesToPoints(0.236220472440945) : .RightMargin = myExcel.Application.InchesToPoints(0.236220472440945)
            .TopMargin = myExcel.Application.InchesToPoints(0.748031496062992) : .BottomMargin = myExcel.Application.InchesToPoints(0.748031496062992)
            .HeaderMargin = myExcel.Application.InchesToPoints(0.31496062992126) : .FooterMargin = myExcel.Application.InchesToPoints(0.31496062992126)
            .PrintHeadings = False : .PrintGridlines = False : .CenterHorizontally = False : .CenterVertically = False : .Draft = False
            .FirstPageNumber = xlAutomatic : .BlackAndWhite = False : .Zoom = False : .FitToPagesWide = 1 : .FitToPagesTall = False : .OddAndEvenPagesHeaderFooter = False
            .DifferentFirstPageHeaderFooter = False : .ScaleWithDocHeaderFooter = True : .AlignMarginsHeaderFooter = True : .EvenPage.LeftHeader.Text = ""
            .EvenPage.CenterHeader.Text = "" : .EvenPage.RightHeader.Text = "" : .EvenPage.LeftFooter.Text = "" : .EvenPage.CenterFooter.Text = ""
            .EvenPage.RightFooter.Text = "" : .FirstPage.LeftHeader.Text = "" : .FirstPage.CenterHeader.Text = "" : .FirstPage.RightHeader.Text = ""
            .FirstPage.LeftFooter.Text = "" : .FirstPage.CenterFooter.Text = "" : .FirstPage.RightFooter.Text = ""
        End With : myExcel.Application.PrintCommunication = True
    End Sub
    Private Sub CC(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Worksheet)
        Clipboard.SetDataObject(PB1.Image)
        xlSheet.Range("A1").Select()
        myExcel.ActiveSheet.Pictures.Paste.Select
        myExcel.Selection.ShapeRange.Height = 93
        myExcel.Selection.ShapeRange.IncrementLeft(20)
        myExcel.Selection.ShapeRange.IncrementTop(0)
    End Sub
    Private Sub 物料圖_pb_Click(sender As Object, e As EventArgs) Handles 物料圖_pb.Click
        If IsNothing(物料圖_pb.Image) = False Then
            圖片傳遞 = 物料圖_pb.Image : 圖片放大視窗.ShowDialog()
        End If
    End Sub
    Private Sub 詳細資料2_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 詳細資料2_ch.Click
        If 詳細資料2_ch.Checked = True Then : 詳細資料2_ch.Checked = True : Else : 詳細資料2_ch.Checked = False : End If : Set_請購單清單()
    End Sub

    '-----------------------------滑鼠右鍵--------------------------------------------------------------------------------------------------------------------------------------
    Private Sub 重新整理ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 重新整理_tsm.Click
        Set_清單1() : Set_清單3()
    End Sub
    Private Sub 請購單核准SetujuiToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 請購單核准_tsm.Click
        Me.請購單核准_bt.PerformClick()
    End Sub
    Private Sub 請購單作廢BatalToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 請購單作廢_tsm.Click
        Me.請購單作廢_bt.PerformClick()
    End Sub
    Private Sub 刪除請購單上點選資料ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 刪除請購單上點選資料_tsm.Click
        刪除請購單上點選資料_bt.PerformClick()
    End Sub
    Private Sub 存檔SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 存檔_tsm.Click
        Me.存檔_bt.PerformClick()
    End Sub
End Class