Option Strict Off
Public Class 會計科目管理
    ReadOnly ds3 As New DataSet
    Dim EDR As Integer = 0 : Dim ESTR As String
    Private Sub Set_會計科目()
        會計科目清單_dgv.DataSource = Nothing : ds3.Clear() : 會計科目清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        會計科目清單_dgv.ColumnHeadersHeight = 25 : 會計科目清單_dgv.AllowUserToAddRows = False
        SQL_會計科目管理_查詢會計科目() : da.Fill(ds3) : 會計科目清單_dgv.DataSource = ds3.Tables(0) : conn.Close()
        會計科目清單_dgv.Columns(0).FillWeight = 8 : 會計科目清單_dgv.Columns(1).FillWeight = 8 : 會計科目清單_dgv.Columns(2).FillWeight = 12 : 會計科目清單_dgv.Columns(3).FillWeight = 6
        會計科目清單_dgv.Columns(4).FillWeight = 3 : 會計科目清單_dgv.Columns(5).FillWeight = 15 : 會計科目清單_dgv.Columns(6).FillWeight = 3 : 會計科目清單_dgv.Columns(7).FillWeight = 3
        會計科目清單_dgv.Columns(8).FillWeight = 3 : 會計科目清單_dgv.Columns(9).FillWeight = 28 : 會計科目清單_dgv.Columns(10).FillWeight = 3
        會計科目清單_dgv.RowTemplate.Height = 25
    End Sub
    Private Sub ComboBox1下拉表單資料載入()
        conn.Close()
        SQL_會計科目管理_查詢第一階編號() : ComboBox1.Items.Clear() : ComboBox2.Items.Clear() : ComboBox1.Text = "" : ComboBox2.Text = ""
        While (dr.Read()) : ComboBox1.Items.Add(dr("第一階")) : ComboBox2.Items.Add(dr("編號")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox3下拉表單資料載入()
        conn.Close()
        SQL_會計科目管理_查詢第二階編號() : ComboBox3.Items.Clear() : ComboBox4.Items.Clear() : ComboBox3.Items.Clear() : ComboBox4.Items.Clear() : ComboBox3.Text = "" : ComboBox4.Text = ""
        While (dr.Read()) : ComboBox3.Items.Add(dr("第二階")) : ComboBox4.Items.Add(dr("編號")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox6變化()
        If ComboBox6.Text = "1" Then : ComboBox5.Text = "1"
        ElseIf ComboBox6.Text = "2" Then : ComboBox5.Text = "2"
        ElseIf ComboBox6.Text = "3" Then : ComboBox5.Text = "2"
        End If
        If 修改刪除_cb.Checked = True Then : Else
            If ComboBox2.Text = "" Then : Else
                If ComboBox6.Text = "1" Then
                    TextBox16.Text = ""
                ElseIf ComboBox6.Text = "2" Then
                    If ComboBox4.Text = "" Then : Else
                        '----------------------自动生成流水号-------------------------------------------------------------------------
                        SQL_會計科目管理_查詢最後一筆編號1()
                        If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("編號").ToString, 2)) : Else : EDR = 0 : End If
                        conn.Close() : EDR += 1
                        If EDR < 10 Then : ESTR = ComboBox2.Text & "-" & "0" & EDR & "-00"
                        ElseIf EDR > 9 And EDR < 100 Then : ESTR = ComboBox2.Text & "-" & "" & EDR & "-00"
                        End If
                        TextBox16.Text = ESTR
                    End If
                ElseIf ComboBox6.Text = "3" Then
                    If ComboBox4.Text = "" Then : Else
                        '----------------------自动生成流水号-------------------------------------------------------------------------
                        SQL_會計科目管理_查詢最後一筆編號2()
                        If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("編號").ToString, 2)) : Else : EDR = 0 : End If
                        conn.Close() : EDR += 1
                        If EDR < 10 Then : ESTR = ComboBox4.Text & "-" & "0" & EDR
                        ElseIf EDR > 9 And EDR < 100 Then : ESTR = ComboBox4.Text & "-" & "" & EDR
                        End If
                        TextBox16.Text = ESTR
                    End If
                End If
            End If
        End If
    End Sub
    Private Sub 會計科目管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = YD_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        TextBox15.Enabled = False : 修改刪除_cb.Checked = True : 新增_bt.Enabled = False : TextBox16.Enabled = False
        Set_會計科目() : ComboBox1下拉表單資料載入()
    End Sub
    Private Sub DataGridView7_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 會計科目清單_dgv.CellClick
        Dim SSXX As String
        If e.RowIndex = -1 Then : Else
            ComboBox6.Text = 會計科目清單_dgv(4, e.RowIndex).Value.ToString : SSXX = 會計科目清單_dgv(1, e.RowIndex).Value.ToString
            ComboBox3.Text = SSXX
            If 修改刪除_cb.Checked = True Then
                TextBox8.Text = 會計科目清單_dgv(2, e.RowIndex).Value.ToString : TextBox16.Text = 會計科目清單_dgv(3, e.RowIndex).Value.ToString
                英文名稱_tb.Text = 會計科目清單_dgv(5, e.RowIndex).Value.ToString : TextBox18.Text = 會計科目清單_dgv(9, e.RowIndex).Value.ToString
                統制科目_cb.Checked = 會計科目清單_dgv(6, e.RowIndex).Value : 抵銷科目_cb.Checked = 會計科目清單_dgv(7, e.RowIndex).Value
                停用_cb.Checked = 會計科目清單_dgv(8, e.RowIndex).Value
            Else
                ComboBox6變化()
            End If
            ComboBox1.Text = 會計科目清單_dgv(0, e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub DataGridView7_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 會計科目清單_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = 會計科目清單_dgv.Rows.Count - 1 Then
            Exit Sub
        Else
            If 會計科目清單_dgv(1, e.RowIndex).Value.ToString <> 會計科目清單_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(會計科目清單_dgv.RowHeadersVisible, 會計科目清單_dgv.RowHeadersWidth, 0)
                Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 會計科目清單_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 會計科目清單_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
                Exit Sub
            End If
        End If
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged
        ComboBox2.SelectedIndex = ComboBox1.SelectedIndex : ComboBox3下拉表單資料載入()
    End Sub
    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.TextChanged
        ComboBox1.SelectedIndex = ComboBox2.SelectedIndex : Set_會計科目() : ComboBox3下拉表單資料載入()
    End Sub
    Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.TextChanged
        ComboBox4.SelectedIndex = ComboBox3.SelectedIndex
    End Sub
    Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.TextChanged
        ComboBox3.SelectedIndex = ComboBox4.SelectedIndex
    End Sub
    Private Sub ComboBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox5.TextChanged
        ComboBox3下拉表單資料載入()
    End Sub
    Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles 新增模式_cb.Click
        新增模式_cb.Checked = True : 修改刪除_cb.Checked = False : TextBox16.Enabled = True
        TextBox8.Text = "" : 英文名稱_tb.Text = "" : TextBox18.Text = "" : 統制科目_cb.Checked = False : 抵銷科目_cb.Checked = False : 停用_cb.Checked = False
    End Sub
    Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles 修改刪除_cb.Click
        新增模式_cb.Checked = False : 修改刪除_cb.Checked = True : TextBox16.Enabled = False
    End Sub
    Private Sub ComboBox6_TextChanged(sender As Object, e As EventArgs) Handles ComboBox6.TextChanged
        ComboBox6變化()
    End Sub
    Private Sub Button19_Click(sender As Object, e As EventArgs) Handles 修改_bt.Click
        If TextBox8.Text = "" Then
            MsgBox("資料有缺或有誤,請重新檢查")
        Else
            conn.Close() : dr.Close()
            SQL_會計科目管理_修改會計科目() : conn.Close()
            MsgBox("修改完成")
        End If : Set_會計科目()
    End Sub
    Private Sub Button16_Click(sender As Object, e As EventArgs) Handles 批量存檔_bt.Click
        For i As Integer = 0 To 會計科目清單_dgv.Rows.Count - 1
            資料數 = 會計科目清單_dgv.Rows.Count : MyModule1.進度條() : YD_ERP_SYS.ToolStripProgressBar1.Value = 最終數
            PA1 = 會計科目清單_dgv.Rows(i).Cells("會計科目").Value : PA2 = 會計科目清單_dgv.Rows(i).Cells("層級").Value : PA3 = 會計科目清單_dgv.Rows(i).Cells("英文名稱").Value.ToString
            PA4 = 會計科目清單_dgv.Rows(i).Cells("統制科目").Value : PA5 = 會計科目清單_dgv.Rows(i).Cells("抵銷科目").Value : PA6 = 會計科目清單_dgv.Rows(i).Cells("停用").Value
            PA7 = 會計科目清單_dgv.Rows(i).Cells("附註").Value.ToString : PA8 = 會計科目清單_dgv.Rows(i).Cells("第一階").Value : PA9 = 會計科目清單_dgv.Rows(i).Cells("第二階").Value
            PA10 = 會計科目清單_dgv.Rows(i).Cells("顯示").Value : PA11 = 會計科目清單_dgv.Rows(i).Cells("編號").Value
            SQL_會計科目管理_快速修改會計科目() : conn.Close()
        Next : YD_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0 : MsgBox("修改完成")
    End Sub
    Private Sub Button21_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        Dim aa As MsgBoxResult
        aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
        If aa = MsgBoxResult.Ok Then
            SQL_會計科目管理_刪除會計科目() : conn.Close()
            MsgBox("刪除完成")
        End If
        Set_會計科目()
    End Sub
    Private Sub Button20_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        If TextBox8.Text = "" Or ComboBox6.Text = "" Then
            MsgBox("資料有缺或有誤,請重新檢查")
        Else
            SQL_會計科目管理_查詢會計科目編號()
            If dr.Read() Then
                MsgBox("資料重複,請從新輸入或檢查") : conn.Close() : dr.Close()
            Else
                conn.Close() : dr.Close()
                If ComboBox6.Text = "1" Then
                    SQL_會計科目管理_新增會計科目編號1()
                ElseIf ComboBox6.Text = "2" Then
                    SQL_會計科目管理_新增會計科目編號2()
                Else
                    SQL_會計科目管理_新增會計科目編號3()
                End If
                MsgBox("新增完成")
                conn.Close() : dr.Close()
            End If
        End If : Set_會計科目()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 重新整理_bt.Click
        ComboBox1下拉表單資料載入() : ComboBox3下拉表單資料載入() : ComboBox6變化() : Set_會計科目()
    End Sub
    Private Sub 新增模式_cb_CheckedChanged(sender As Object, e As EventArgs) Handles 新增模式_cb.CheckedChanged
        If 新增模式_cb.Checked = True Then
            新增_bt.Enabled = True : 修改_bt.Enabled = False : 批量存檔_bt.Enabled = False : 刪除_bt.Enabled = False : 重新整理_bt.Enabled = False
        Else
            新增_bt.Enabled = False : 修改_bt.Enabled = True : 批量存檔_bt.Enabled = True : 刪除_bt.Enabled = True : 重新整理_bt.Enabled = True
        End If
    End Sub
    Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
        會計科目清單_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
    End Sub
End Class