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 新項次 As String : Private ReadOnly 對話框(13) As String : Dim 物料規格 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 = 120 : 請購明細_dgv.Columns(5).FillWeight = 80 : 請購明細_dgv.Columns(6).FillWeight = 80 : 請購明細_dgv.Columns(7).FillWeight = 120
        請購明細_dgv.Columns(8).Visible = False : 請購明細_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(5).DefaultCellStyle.Format = "#,##0"
        請購明細_dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        請購明細_dgv.Columns(5).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(6).ReadOnly = True
        請購明細_dgv.EditMode = DataGridViewEditMode.EditOnEnter
        If 低網速模式 = False Then
            請購明細_dgv.Columns(20).FillWeight = 80 : 請購明細_dgv.Columns(20).Visible = True
            Dim mycol As DataGridViewImageColumn = 請購明細_dgv.Columns("圖檔")
            mycol.ImageLayout = DataGridViewImageCellLayout.Zoom
        Else
            If 請購明細_dgv.Columns.Count = 21 Then
                請購明細_dgv.Columns(20).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(表頭(13)).Value.ToString <> "" Then
                    ZA1 = AAA1 & "=" & 請購明細_dgv.Rows(i).Cells(表頭(13)).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(表頭(13)).Value.ToString <> "" Then : ZA1 = 請購明細_dgv.Rows(i).Cells(表頭(13)).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(表頭(13)).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(表頭(13)).Value.ToString <> "" Then
                    ZA1 = AAA1 & "=" & 請購明細1_dgv.Rows(i).Cells(表頭(13)).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(表頭(13)).Value.ToString <> "" Then : ZA1 = 請購明細1_dgv.Rows(i).Cells(表頭(13)).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(表頭(13)).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
    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
    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
    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 語言轉換讀取()
        If 系統語言 = "繁體中文" Then : 語言 = "CH" : ElseIf 系統語言 = "English" Then : 語言 = "EN" : ElseIf 系統語言 = "Indonesian" Then : 語言 = "IN" : End If
        Me.Text = 系統語言字典("H001-175-" & 語言) : ToolTip1.ToolTipTitle = 系統語言字典("G000-108-" & 語言)
        已作廢_lb.Text = 系統語言字典("H202-100-" & 語言) : 已作廢_rb.Text = 系統語言字典("H202-101-" & 語言) : 已審核_lb.Text = 系統語言字典("H202-102-" & 語言)
        已審核_rb.Text = 系統語言字典("H202-103-" & 語言) : 未審核_lb.Text = 系統語言字典("H202-104-" & 語言) : 未審核_rb.Text = 系統語言字典("H202-105-" & 語言)
        申請人_lb.Text = 系統語言字典("H202-106-" & 語言) : 申請日期_lb.Text = 系統語言字典("H202-107-" & 語言) : 表頭(19) = 系統語言字典("H202-113-" & 語言)
        合約號_lb.Text = 系統語言字典("H202-108-" & 語言) : 表頭(134) = 系統語言字典("H202-108-" & 語言) : 存檔_tsm.Text = 系統語言字典("H202-109-" & 語言)
        刪除請購單上點選資料_bt.Text = 系統語言字典("H202-110-" & 語言) : 刪除請購單上點選資料_tsm.Text = 系統語言字典("H202-110-" & 語言)
        指定倉庫_lb.Text = 系統語言字典("H202-111-" & 語言) : 重新整理_tsm.Text = 系統語言字典("H202-112-" & 語言) : 表頭(20) = 系統語言字典("H202-114-" & 語言)
        表頭(21) = 系統語言字典("H202-115-" & 語言) : 表頭(22) = 系統語言字典("H202-116-" & 語言) : 表頭(18) = 系統語言字典("H202-117-" & 語言)
        項次_lb.Text = 系統語言字典("H202-118-" & 語言) : 對話框(0) = 系統語言字典("H202-119-" & 語言) : 對話框(1) = 系統語言字典("H202-120-" & 語言)
        對話框(2) = 系統語言字典("H202-121-" & 語言) : 對話框(3) = 系統語言字典("H202-122-" & 語言) : 對話框(4) = 系統語言字典("H202-123-" & 語言)
        對話框(5) = 系統語言字典("H202-124-" & 語言) : 對話框(6) = 系統語言字典("H202-125-" & 語言) : 對話框(7) = 系統語言字典("H202-126-" & 語言)
        對話框(8) = 系統語言字典("H202-127-" & 語言) : 需求日期_lb.Text = 系統語言字典("H202-128-" & 語言) : 表頭(17) = 系統語言字典("H202-129-" & 語言)
        表頭(12) = 系統語言字典("H202-130-" & 語言) : 表頭(13) = 系統語言字典("H202-131-" & 語言) : 表頭(14) = 系統語言字典("H202-132-" & 語言)
        表頭(16) = 系統語言字典("H202-133-" & 語言) : 表頭(11) = 系統語言字典("H202-134-" & 語言) : 表頭(15) = 系統語言字典("H202-135-" & 語言)
        請購單作廢_tsm.Text = 系統語言字典("H202-136-" & 語言) : 請購單核准_tsm.Text = 系統語言字典("H202-137-" & 語言) : 請購單號_lb.Text = 系統語言字典("H202-138-" & 語言)
        選擇_lb.Text = 系統語言字典("H202-139-" & 語言) : 詳細資料2_ch.Text = 系統語言字典("H211-100-" & 語言) : 對話框(9) = 系統語言字典("H207-138-" & 語言)
        對話框(10) = 系統語言字典("H207-139-" & 語言) : 對話框(11) = 系統語言字典("G000-110-" & 語言) : 對話框(12) = 系統語言字典("G000-114-" & 語言)
        對話框(13) = 系統語言字典("H202-153-" & 語言)
    End Sub
    Private Sub 請購單核准_bt_MouseEnter(sender As Object, e As EventArgs) Handles 請購單核准_bt.MouseEnter
        ToolTip1.SetToolTip(Me.請購單核准_bt, 對話框(9))
    End Sub
    Private Sub 請購單作廢_bt_MouseEnter(sender As Object, e As EventArgs) Handles 請購單作廢_bt.MouseEnter
        ToolTip1.SetToolTip(Me.請購單作廢_bt, 對話框(10))
    End Sub
    Private Sub 存檔_bt_MouseEnter(sender As Object, e As EventArgs) Handles 存檔_bt.MouseEnter
        ToolTip1.SetToolTip(Me.存檔_bt, 對話框(11))
    End Sub
    Private Sub 確認列印_bt_MouseEnter(sender As Object, e As EventArgs) Handles 確認列印_bt.MouseEnter
        ToolTip1.SetToolTip(Me.確認列印_bt, 對話框(12))
    End Sub
    Private Sub 加急件_bt_MouseEnter(sender As Object, e As EventArgs) Handles 加急件_bt.MouseEnter
        ToolTip1.SetToolTip(Me.加急件_bt, 對話框(13))
    End Sub
    Private Sub 請購單核准_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = HX_PGS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        H(202) = True : 介面 = "H202" : 語言轉換讀取() : 顯示說明(999, False)

        Panel1.SendToBack() : 申請日期_dtp.Enabled = False : 確認列印_bt.Enabled = False

        未審核_rb.Checked = False : 已作廢_rb.Checked = False : 已審核_rb.Checked = True : 未審核_lb.Visible = False : 未核准_dgv.Visible = False
        已作廢_lb.Visible = False : 作廢清單_dgv.Visible = False : 已核准_dgv.Visible = True : 已審核_lb.Visible = True

        需求日期_dtp.Format = DateTimePickerFormat.Custom
        需求日期_dtp.CustomFormat = " " : 系統語言_cb.Text = "Indonesian"
        小間距_ch.Checked = False : 中間距_ch.Checked = True : 大間距_ch.Checked = False

        ComboBox1下拉表單資料載入() : Set_清單1() : Set_清單2() : Set_清單3()
        MyMod.清單字體大小調整()
        作廢清單_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        未核准_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        已核准_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        請購明細_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
    End Sub
    Private Sub 請購單核准_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
        H(202) = False : MyMod.虛擬桌面開啟()
    End Sub
    Private Sub 請購單核准_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        MyMod.清單字體大小調整()
        作廢清單_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        未核准_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        已核准_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
        請購明細_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", HX_PGS_ERP_SYS.字體_NUD.Value)
    End Sub
    Private Sub 系統說明_bt_Click(sender As Object, e As EventArgs) Handles 系統說明_bt.Click
        介面 = "H202" ': WEB說明頁面.Show()
    End Sub
    Private Sub 語轉扭_bt_Click(sender As Object, e As EventArgs) Handles 語轉扭_bt.Click
        介面 = "H202" : 語言轉換讀取()
        Set_請購單清單() : Set_請購單清單1() : Set_清單1() : Set_清單2() : Set_清單3()
    End Sub
    Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
        timeNow = 0 : HX_PGS_ERP_SYS.Timer1.Enabled = False : HX_PGS_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
        timeNow = 0 : HX_PGS_ERP_SYS.Timer1.Enabled = False : HX_PGS_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
            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 : 作業選擇()

            '----------------------------讀取申請人資料-------------------------------------------------------------
            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(表頭(17)).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 審核_tb.Text = "" Then : 確認列印_bt.Enabled = False : Else : 確認列印_bt.Enabled = True : End If
        End If : 刪除請購單上點選資料_bt.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
            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(表頭(17)).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 審核_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(表頭(17)).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 審核_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(表頭(17)).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 : 未審核_lb.Visible = True : 未核准_dgv.Visible = True
            已作廢_lb.Visible = False : 作廢清單_dgv.Visible = False : 已核准_dgv.Visible = False : 已審核_lb.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 : 未審核_lb.Visible = False : 未核准_dgv.Visible = False
            已作廢_lb.Visible = True : 作廢清單_dgv.Visible = True : 已核准_dgv.Visible = False : 已審核_lb.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 : 未審核_lb.Visible = False : 未核准_dgv.Visible = False
            已作廢_lb.Visible = False : 作廢清單_dgv.Visible = False : 已核准_dgv.Visible = True : 已審核_lb.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 : MGB(系統語言字典("H201-153-" & 語言), 1) : Else
            If 需求日期_dtp.Text = "" Or 需求日期_dtp.Text = " " Then : MGB(系統語言字典("H201-137-" & 語言), 1) : Else
                Set_日期格式轉換()
                If 請購單號_tb.Text = "" Then : MGB(對話框(0), 1) : Else
                    PA = 請購單號_tb.Text : PA1 = gUserName : SQL_建築物料請購單核准_請購單核准() : conn.Close()
                    通知訊息 = 對話框(1) & 請購單號_tb.Text & 對話框(2) : 訊息類型 = "1" : 通知視窗.ShowDialog()
                    請購單號_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 : MGB(系統語言字典("H201-153-" & 語言), 1) : Else
            If 需求日期_dtp.Text = "" Or 需求日期_dtp.Text = " " Then : MGB(系統語言字典("H201-137-" & 語言), 1) : Else
                Set_日期格式轉換()
                If 請購單號_tb.Text = "" Then : MGB(對話框(0), 1) : Else
                    PA = 請購單號_tb.Text : PA1 = gUserName : SQL_建築物料請購單核准_請購單核准() : conn.Close() : SQL_請購單核准_加急核准() : conn.Close()
                    PA4 = 請購單號_tb.Text : SQL_請購單申請_加急存檔() : conn.Close()
                    '---LINE_AUTO 部門主管------------------------------------------------------------------------------------------------------------------------------------------
                    If 登入人IP = 測試IP Then : Else
                        LIN訊息通知("CC208", "李協叡", 合約號_tb.Text, 請購單號_tb.Text)
                        LIN訊息通知("CC208", "KERIH", 合約號_tb.Text, 請購單號_tb.Text)
                        LIN訊息通知("CC208", "LIN HSING HAO", 合約號_tb.Text, 請購單號_tb.Text)
                        LIN訊息通知("CC208", gUserName, 合約號_tb.Text, 請購單號_tb.Text)
                    End If
                    '---完成加急核准------------------------------------------------------------------------------------------------------------------------------------------
                    通知訊息 = 對話框(1) & 請購單號_tb.Text & 對話框(2) : 訊息類型 = "1" : 通知視窗.ShowDialog() : 請購單號_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 : MGB(系統語言字典("H201-153-" & 語言), 1) : Else
            If 需求日期_dtp.Text = "" Or 需求日期_dtp.Text = " " Then : MGB(系統語言字典("H201-137-" & 語言), 1) : Else
                Set_日期格式轉換()
                If 請購單號_tb.Text = "" Then : MGB(對話框(0), 1) : Else
                    MGB(對話框(3), 2)
                    If 訊息回應 = "YES" Then
                        PA = 請購單號_tb.Text : PA1 = "作廢-" & gUserName : SQL_建築物料請購單核准_請購單核准() : conn.Close()
                        通知訊息 = 對話框(1) & 請購單號_tb.Text & 對話框(4) : 訊息類型 = "1" : 通知視窗.ShowDialog()
                        請購單號_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
        存檔() : MGB(對話框(5), 2) : If 訊息回應 = "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(表頭(14)).Value.ToString.Replace("'", "") : NU1 = 請購明細_dgv.Rows(i).Cells(表頭(15)).Value
            PA2 = 請購明細_dgv.Rows(i).Cells(表頭(16)).Value : PA3 = 倉庫編號_tb.Text : PA4 = 請購單號_tb.Text : PA5 = 請購明細_dgv.Rows(i).Cells(表頭(11)).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_請購單需求日其修改() : HX_PGS_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 : MGB(對話框(0), 1) : Else
            If 項次_tb.Text = "" Then : MGB(對話框(6), 1) : Else
                MGB(對話框(7), 2)
                If 訊息回應 = "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(表頭(11)).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(2, 1) = "Pembelian Permintaan" : xlSheet.Cells(3, 1) = "請購單"

        xlSheet.Cells(5, 1) = "1、" : xlSheet.Cells(6, 1) = "2、" : xlSheet.Cells(7, 1) = "3、" : xlSheet.Cells(8, 1) = "4、" : xlSheet.Cells(9, 1) = "5、"

        xlSheet.Cells(5, 2) = "   Nomor                                        :" : xlSheet.Cells(6, 2) = "   Pemohon                                   :"
        xlSheet.Cells(7, 2) = "   Gudang Yang Ditunjuk          :" : xlSheet.Cells(8, 2) = "   Perlu Tanggal                           :"
        xlSheet.Cells(9, 2) = "   Setuju                                         :"

        xlSheet.Cells(5, 3) = 請購單號_tb.Text : xlSheet.Cells(6, 3) = 申請人_tb.Text : xlSheet.Cells(7, 3) = 指定倉庫_cb.Text
        xlSheet.Cells(8, 3) = 需求日期_dtp.Value : xlSheet.Cells(9, 3) = 審核_tb.Text

        xlSheet.Cells(11, 1) = "No." : xlSheet.Cells(11, 2) = "Nama produk" : xlSheet.Cells(11, 3) = "Spesifikasi" : xlSheet.Cells(11, 4) = "QTY" : xlSheet.Cells(11, 5) = "SATUAN"
        xlSheet.Cells(11, 6) = "Komentar"
        For i As Integer = 0 To 請購明細1_dgv.Rows.Count - 1
            xlSheet.Cells(i + 12, 1) = i + 1
            xlSheet.Cells(i + 12, 2) = 請購明細1_dgv.Rows(i).Cells(表頭(12)).Value
            xlSheet.Cells(i + 12, 3) = 請購明細1_dgv.Rows(i).Cells(表頭(13)).Value
            xlSheet.Cells(i + 12, 4) = 請購明細1_dgv.Rows(i).Cells(表頭(15)).Value
            xlSheet.Cells(i + 12, 5) = 請購明細1_dgv.Rows(i).Cells(表頭(16)).Value
            xlSheet.Cells(i + 12, 6) = 請購明細1_dgv.Rows(i).Cells(表頭(14)).Value
            N1 = i + 12
        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()
        MGB(對話框(8), 1)
    End Sub
    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.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 5
        xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 40
        xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 40
        xlSheet.Columns("D:D").Select : myExcel.Selection.ColumnWidth = 8
        xlSheet.Columns("E:E").Select : myExcel.Selection.ColumnWidth = 10
        xlSheet.Columns("F:F").Select : myExcel.Selection.ColumnWidth = 40
        xlSheet.Rows("1:1").Select : myExcel.Selection.RowHeight = 85
        xlSheet.Rows("2:2").Select : myExcel.Selection.RowHeight = 35
        xlSheet.Rows("4:4").Select : myExcel.Selection.RowHeight = 5
        xlSheet.Rows("10:10").Select : myExcel.Selection.RowHeight = 5
        xlSheet.Rows("11:11").Select : myExcel.Selection.RowHeight = 25
        xlSheet.Rows("12:" & N1).Select : myExcel.Selection.RowHeight = 60

        xlSheet.Range("A12:F" & 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("D12:D" & N1).Select()
        myExcel.Selection.Style = "Comma"
        myExcel.Selection.NumberFormatLocal = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"

        xlSheet.Range("B12: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:F2").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:F3").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("C5:C9").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("A9:F9").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("A11:F" & 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("A11:F11").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

        myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .PrintTitleRows = "$1:$11" : .PrintTitleColumns = "" : End With
        myExcel.Application.PrintCommunication = True : myExcel.ActiveSheet.PageSetup.PrintArea = "" : myExcel.Application.PrintCommunication = False
        With myExcel.ActiveSheet.PageSetup : .LeftHeader = "" : .CenterHeader = "" : .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 : .PrintQuality = 600 : .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(PictureBox1.Image)
        xlSheet.Range("A1").Select()
        myExcel.ActiveSheet.Pictures.Paste.Select
        myExcel.Selection.ShapeRange.Height = 93
        myExcel.Selection.ShapeRange.IncrementLeft(50)
        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