Option Strict Off
Public Class 零用金支付審核
    Dim ds As New DataSet : Dim ds1 As New DataSet : Dim ds2 As New DataSet
    Dim DTP As String
    Private Sub Set_財務單清單()
        明細_dgv.DataSource = Nothing : ds.Clear()
        明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        明細_dgv.ColumnHeadersHeight = 25
        明細_dgv.AllowUserToAddRows = False
        明細_dgv.RowTemplate.Height = 35

        PA1 = TextBox1.Text : SQL_財務帳清單()
        da.Fill(ds) : 明細_dgv.DataSource = ds.Tables(0) : conn.Close()

        明細_dgv.Columns(0).Visible = False : 明細_dgv.Columns(1).Width = 80 : 明細_dgv.Columns(2).Width = 342 : 明細_dgv.Columns(3).Width = 140 : 明細_dgv.Columns(4).Width = 350
        明細_dgv.Columns(3).DefaultCellStyle.Format = "#,##0.00"
        明細_dgv.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        明細_dgv.Columns(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        明細_dgv.EditMode = DataGridViewEditMode.EditOnEnter

        TextBox5.Text = "0.00"
        For i As Integer = 0 To 明細_dgv.Rows.Count - 1
            TextBox5.Text = Val(TextBox5.Text) + 明細_dgv.Rows(i).Cells("金額").Value
        Next i
        TextBox5.Text = Format(Val(TextBox5.Text), "#,##0.00")
    End Sub
    Private Sub Set_清單1()
        一級未審核_dgv.DataSource = Nothing : ds1.Clear()
        一級未審核_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        一級未審核_dgv.ColumnHeadersHeight = 25
        一級未審核_dgv.AllowUserToAddRows = False

        PA = "審核介面_一級未審核" : SQL_財務單據()
        da.Fill(ds1) : 一級未審核_dgv.DataSource = ds1.Tables(0) : conn.Close()

        一級未審核_dgv.Columns(0).Width = 120 : 一級未審核_dgv.Columns(1).Width = 114 : 一級未審核_dgv.Columns(2).Width = 114 : 一級未審核_dgv.Columns(3).Width = 115
        一級未審核_dgv.Columns(4).Width = 115 : 一級未審核_dgv.Columns(5).Width = 115 : 一級未審核_dgv.Columns(6).Width = 115 : 一級未審核_dgv.Columns(7).Width = 115
        一級未審核_dgv.Columns(8).Visible = False : 一級未審核_dgv.Columns(9).Visible = False
    End Sub
    Private Sub Set_清單2()
        一級作廢_dgv.DataSource = Nothing : ds2.Clear()
        一級作廢_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        一級作廢_dgv.ColumnHeadersHeight = 25
        一級作廢_dgv.AllowUserToAddRows = False

        PA = "審核介面_一級作廢" : SQL_財務單據()
        da.Fill(ds2) : 一級作廢_dgv.DataSource = ds2.Tables(0) : conn.Close()

        一級作廢_dgv.Columns(0).Width = 120 : 一級作廢_dgv.Columns(1).Width = 114 : 一級作廢_dgv.Columns(2).Width = 114 : 一級作廢_dgv.Columns(3).Width = 115
        一級作廢_dgv.Columns(4).Width = 115 : 一級作廢_dgv.Columns(5).Width = 115 : 一級作廢_dgv.Columns(6).Visible = False : 一級作廢_dgv.Columns(7).Visible = False
        一級作廢_dgv.Columns(8).Width = 230 : 一級作廢_dgv.Columns(9).Visible = False
    End Sub
    Private Sub ComboBox1下拉表單資料載入()
        SQL_帳本下拉清單()
        帳本名稱_cb.Items.Clear() : 帳本編號_cb.Items.Clear() : While (dr.Read()) : 帳本名稱_cb.Items.Add(dr("帳本名稱")) : 帳本編號_cb.Items.Add(dr("編號")) : End While : conn.Close()
    End Sub
    Private Sub 零用金支付審核_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        帳本編號_cb.Visible = False
        ComboBox1下拉表單資料載入() : 帳本名稱_cb.SelectedIndex = 0 : PA19 = 帳本編號_cb.Text
        Set_清單1() : Set_清單2()
    End Sub
    Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 一級未審核_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            TextBox1.Text = 一級未審核_dgv(0, e.RowIndex).Value.ToString : TextBox2.Text = 一級未審核_dgv(1, e.RowIndex).Value.ToString : TextBox3.Text = 一級未審核_dgv(2, e.RowIndex).Value.ToString
            Set_財務單清單() : Button1.Enabled = True : Button2.Enabled = True
        End If
    End Sub
    Private Sub DataGridView3_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 一級作廢_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            TextBox1.Text = 一級作廢_dgv(0, e.RowIndex).Value.ToString : TextBox2.Text = 一級作廢_dgv(1, e.RowIndex).Value.ToString : TextBox3.Text = 一級作廢_dgv(2, e.RowIndex).Value.ToString
            Set_財務單清單() : Button1.Enabled = False : Button2.Enabled = False
        End If
    End Sub
    Private Sub Set_日期格式轉換()
        DTP = Format(Today(), "yyyy/MM/dd") & "-" & Format(TimeOfDay(), "hh:mm:ss")
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("請選擇需要審核的單據")
        Else
            Set_日期格式轉換()
            conn.Close()
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            SQL1 = "UPDATE 零用金支付表 SET 審核人 = N'" & gUserName & "', 審核日期 = N'" & DTP & "' WHERE (流水號 = N'" & TextBox1.Text & "')"
            cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
            conn.Close()
            MsgBox("審核完畢")
            Set_清單1() : Set_清單2()
            TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = ""
            明細_dgv.DataSource = Nothing : ds.Clear()
        End If
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If TextBox1.Text = "" Then
            MsgBox("請選擇需要審核的單據")
        Else
            PA = InputBox("請輸入作廢原因")
            If PA = "" Then
                MsgBox("請輸入作廢原因，不可空白")
            Else
                Set_日期格式轉換()
                conn.Close()
                If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                SQL1 = "UPDATE 零用金支付表 SET 審核人 = N'作廢-" & gUserName & "', 審核日期 = N'" & DTP & "', 備註 = N'" & PA & "' WHERE (流水號 = N'" & TextBox1.Text & "')"
                cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
                conn.Close()
                MsgBox("審核完畢") : PA = ""
                Set_清單1() : Set_清單2()
                TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = ""
                明細_dgv.DataSource = Nothing : ds.Clear()
            End If
        End If
    End Sub
    Private Sub 帳本名稱_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 帳本名稱_cb.SelectedIndexChanged
        帳本編號_cb.SelectedIndex = 帳本名稱_cb.SelectedIndex : PA19 = 帳本編號_cb.Text : Set_清單1() : Set_清單2()
        TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = "" : Set_財務單清單()
    End Sub
    Private Sub 帳本編號_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 帳本編號_cb.SelectedIndexChanged
        帳本名稱_cb.SelectedIndex = 帳本編號_cb.SelectedIndex : PA19 = 帳本編號_cb.Text : Set_清單1() : Set_清單2()
        TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = "" : Set_財務單清單()
    End Sub
End Class