Option Strict Off
Imports System.Data.SqlClient
Public Class 營運報表
    ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet : ReadOnly ds3 As New DataSet : ReadOnly ds4 As New DataSet : ReadOnly ds5 As New DataSet
    ReadOnly ds6 As New DataSet : ReadOnly ds7 As New DataSet : ReadOnly ds8 As New DataSet : ReadOnly ds9 As New DataSet : ReadOnly ds10 As New DataSet : ReadOnly ds11 As New DataSet
    ReadOnly ds12 As New DataSet
    Private Sub Set_DGV2開始()
        主表_dgv.DataSource = Nothing : ds2.Clear() : 主表_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        主表_dgv.ColumnHeadersHeight = 50 : 主表_dgv.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
    End Sub
    Private Sub Set_DGV2結束()
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds2) : 主表_dgv.DataSource = ds2.Tables(0) : conn.Close()

        主表_dgv.Columns(0).FillWeight = 40 : 主表_dgv.Columns(1).Visible = False : 主表_dgv.Columns(2).Visible = False : 主表_dgv.Columns(3).FillWeight = 90
        主表_dgv.Columns(4).FillWeight = 90 : 主表_dgv.Columns(5).FillWeight = 135 : 主表_dgv.Columns(6).FillWeight = 85 : 主表_dgv.Columns(7).FillWeight = 85
        主表_dgv.Columns(8).FillWeight = 85
        主表_dgv.Columns(6).DefaultCellStyle.Format = "#,##0" : 主表_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" : 主表_dgv.Columns(8).DefaultCellStyle.Format = "#,##0"
        主表_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 主表_dgv.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        主表_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 主表_dgv.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        主表_dgv.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 主表_dgv.Columns(8).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight

        主表_dgv.Columns(0).ReadOnly = True : 主表_dgv.Columns(1).ReadOnly = True : 主表_dgv.Columns(2).ReadOnly = True : 主表_dgv.Columns(3).ReadOnly = True
        主表_dgv.Columns(4).ReadOnly = True : 主表_dgv.Columns(5).ReadOnly = True : 主表_dgv.Columns(6).ReadOnly = True : 主表_dgv.Columns(7).ReadOnly = True
        主表_dgv.Columns(8).ReadOnly = True
        TextBox61.Text = "0" : TextBox62.Text = "0" : TextBox63.Text = "0" : TextBox64.Text = "0"
        For i As Integer = 0 To 主表_dgv.Rows.Count - 1

            If 主表_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 主表_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 主表_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 主表_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 主表_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 主表_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 主表_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 主表_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 主表_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 主表_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 主表_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 主表_dgv.Rows(i).Cells("子項").Value = "" : End If
            If 主表_dgv.Rows(i).Cells("層級").Value.ToString <> "3" Then : 主表_dgv.Rows(i).Cells("子細項").Value = "" : End If
            If 主表_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then
                主表_dgv.Rows(i).Cells("主項金額").Value = 0 : 主表_dgv.Rows(i).Cells("子項金額").Value = 0 : 主表_dgv.Rows(i).Cells("細項金額").Value = 0
            End If
            If i = 0 Then : Else
                If 主表_dgv.Rows(i).Cells("第一階").Value.ToString = 主表_dgv.Rows(i - 1).Cells("第一階").Value.ToString Then : 主表_dgv.Rows(i).Cells("主項").Value = "" : End If
                If 主表_dgv.Rows(i).Cells("第二階").Value.ToString = 主表_dgv.Rows(i - 1).Cells("第二階").Value.ToString Then : 主表_dgv.Rows(i).Cells("子項").Value = "" : End If
            End If

            If 主表_dgv("第一階", i).Value.ToString = "歲出合計" Then
                主表_dgv("主項金額", i).Value = Val(主表_dgv.Rows(i).Cells("主項金額").Value) * -1
                主表_dgv("子項金額", i).Value = Val(主表_dgv.Rows(i).Cells("子項金額").Value) * -1
                主表_dgv("細項金額", i).Value = Val(主表_dgv.Rows(i).Cells("細項金額").Value) * -1
            End If

            If 主表_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox61.Text = Val(TextBox61.Text) + 主表_dgv.Rows(i).Cells("主項金額").Value : End If
            If 主表_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox62.Text = Val(TextBox62.Text) + 主表_dgv.Rows(i).Cells("主項金額").Value : End If
            If 主表_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox63.Text = Val(TextBox63.Text) + 主表_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        TextBox64.Text = Val(TextBox62.Text) - Val(TextBox63.Text)
    End Sub
    Private Sub Set_清單()
        Set_DGV2開始()
        SQL_營運報表_查詢清單()
        Set_DGV2結束()
    End Sub
    Private Sub Set_清單1()
        月1_dgv.DataSource = Nothing : ds.Clear() : 月1_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月1_dgv.ColumnHeadersHeight = 50 : 月1_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢一月份清單() : da.Fill(ds) : 月1_dgv.DataSource = ds.Tables(0) : conn.Close()
        月1_dgv.Columns(0).FillWeight = 20 : 月1_dgv.Columns(1).Visible = False : 月1_dgv.Columns(2).Visible = False : 月1_dgv.Columns(3).Visible = False
        月1_dgv.Columns(4).Visible = False : 月1_dgv.Columns(5).Visible = False : 月1_dgv.Columns(6).Visible = False : 月1_dgv.Columns(7).Visible = False
        月1_dgv.Columns(8).Visible = False : 月1_dgv.Columns(9).FillWeight = 75
        月1_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月1_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月1_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月1_dgv.Columns(9).ReadOnly = True
        TextBox1.Text = "0" : TextBox2.Text = "0" : TextBox3.Text = "0" : TextBox4.Text = "0" : TextBox30.Text = "0" : TextBox76.Text = "0"
        For i As Integer = 0 To 月1_dgv.Rows.Count - 1
            If 月1_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月1_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月1_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月1_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月1_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月1_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月1_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月1_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月1_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月1_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月1_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月1_dgv.Rows(i).Cells("金額").Value = 月1_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月1_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月1_dgv.Rows(i).Cells("金額").Value = 月1_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月1_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月1_dgv.Rows(i).Cells("金額").Value = 月1_dgv.Rows(i).Cells("細項金額").Value
            Else : 月1_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月1_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月1_dgv("金額", i).Value = Val(月1_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月1_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox1.Text = Val(TextBox1.Text) + 月1_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月1_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox2.Text = Val(TextBox2.Text) + 月1_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月1_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox3.Text = Val(TextBox3.Text) + 月1_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月1_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox30.Text = Val(TextBox30.Text) + 月1_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        TextBox3.Text = Val(TextBox3.Text) * -1
        TextBox4.Text = Val(TextBox30.Text) + Val(TextBox1.Text) + Val(TextBox2.Text) - Val(TextBox3.Text) : TextBox76.Text = Val(TextBox2.Text) - Val(TextBox3.Text)
    End Sub
    Private Sub Set_清單2()
        月2_dgv.DataSource = Nothing : ds1.Clear() : 月2_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月2_dgv.ColumnHeadersHeight = 50 : 月2_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢二月份清單() : da.Fill(ds1) : 月2_dgv.DataSource = ds1.Tables(0) : conn.Close()
        月2_dgv.Columns(0).FillWeight = 20 : 月2_dgv.Columns(1).Visible = False : 月2_dgv.Columns(2).Visible = False : 月2_dgv.Columns(3).Visible = False
        月2_dgv.Columns(4).Visible = False : 月2_dgv.Columns(5).Visible = False : 月2_dgv.Columns(6).Visible = False : 月2_dgv.Columns(7).Visible = False
        月2_dgv.Columns(8).Visible = False : 月2_dgv.Columns(9).FillWeight = 75
        月2_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月2_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月2_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月2_dgv.Columns(9).ReadOnly = True
        TextBox5.Text = "0" : TextBox6.Text = "0" : TextBox7.Text = "0" : TextBox8.Text = "0" : TextBox29.Text = "0" : TextBox75.Text = "0"
        For i As Integer = 0 To 月2_dgv.Rows.Count - 1
            If 月2_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月2_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月2_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月2_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月2_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月2_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月2_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月2_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月2_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月2_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月2_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月2_dgv.Rows(i).Cells("金額").Value = 月2_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月2_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月2_dgv.Rows(i).Cells("金額").Value = 月2_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月2_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月2_dgv.Rows(i).Cells("金額").Value = 月2_dgv.Rows(i).Cells("細項金額").Value
            Else : 月2_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月2_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月2_dgv("金額", i).Value = Val(月2_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月2_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox5.Text = Val(TextBox5.Text) + 月2_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月2_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox6.Text = Val(TextBox6.Text) + 月2_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月2_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox7.Text = Val(TextBox7.Text) + 月2_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月2_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox29.Text = Val(TextBox29.Text) + 月2_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox29.Text) > 0 Then
            TextBox87.Text = Val(TextBox29.Text) - Val(TextBox4.Text)
        Else
            TextBox87.Text = 0
        End If

        TextBox7.Text = Val(TextBox7.Text) * -1
        TextBox8.Text = Val(TextBox29.Text) + Val(TextBox5.Text) + Val(TextBox6.Text) - Val(TextBox7.Text)
        TextBox75.Text = Val(TextBox6.Text) - Val(TextBox7.Text)
    End Sub
    Private Sub Set_清單3()
        月3_dgv.DataSource = Nothing : ds3.Clear() : 月3_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月3_dgv.ColumnHeadersHeight = 50 : 月3_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢三月份清單() : da.Fill(ds3) : 月3_dgv.DataSource = ds3.Tables(0) : conn.Close()
        月3_dgv.Columns(0).FillWeight = 20 : 月3_dgv.Columns(1).Visible = False : 月3_dgv.Columns(2).Visible = False : 月3_dgv.Columns(3).Visible = False
        月3_dgv.Columns(4).Visible = False : 月3_dgv.Columns(5).Visible = False : 月3_dgv.Columns(6).Visible = False : 月3_dgv.Columns(7).Visible = False
        月3_dgv.Columns(8).Visible = False : 月3_dgv.Columns(9).FillWeight = 75
        月3_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月3_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月3_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月3_dgv.Columns(9).ReadOnly = True
        TextBox9.Text = "0" : TextBox10.Text = "0" : TextBox11.Text = "0" : TextBox12.Text = "0" : TextBox28.Text = "0" : TextBox74.Text = "0"
        For i As Integer = 0 To 月3_dgv.Rows.Count - 1
            If 月3_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月3_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月3_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月3_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月3_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月3_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月3_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月3_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月3_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月3_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月3_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月3_dgv.Rows(i).Cells("金額").Value = 月3_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月3_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月3_dgv.Rows(i).Cells("金額").Value = 月3_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月3_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月3_dgv.Rows(i).Cells("金額").Value = 月3_dgv.Rows(i).Cells("細項金額").Value
            Else : 月3_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月3_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月3_dgv("金額", i).Value = Val(月3_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月3_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox9.Text = Val(TextBox9.Text) + 月3_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月3_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox10.Text = Val(TextBox10.Text) + 月3_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月3_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox11.Text = Val(TextBox11.Text) + 月3_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月3_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox28.Text = Val(TextBox28.Text) + 月3_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox28.Text) > 0 Then
            TextBox86.Text = Val(TextBox28.Text) - Val(TextBox8.Text)
        Else
            TextBox86.Text = 0
        End If

        TextBox11.Text = Val(TextBox11.Text) * -1
        TextBox12.Text = Val(TextBox28.Text) + Val(TextBox9.Text) + Val(TextBox10.Text) - Val(TextBox11.Text)
        TextBox74.Text = Val(TextBox10.Text) - Val(TextBox11.Text)
    End Sub
    Private Sub Set_清單4()
        月4_dgv.DataSource = Nothing : ds4.Clear() : 月4_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月4_dgv.ColumnHeadersHeight = 50 : 月4_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢四月份清單() : da.Fill(ds4) : 月4_dgv.DataSource = ds4.Tables(0) : conn.Close()
        月4_dgv.Columns(0).FillWeight = 20 : 月4_dgv.Columns(1).Visible = False : 月4_dgv.Columns(2).Visible = False : 月4_dgv.Columns(3).Visible = False
        月4_dgv.Columns(4).Visible = False : 月4_dgv.Columns(5).Visible = False : 月4_dgv.Columns(6).Visible = False : 月4_dgv.Columns(7).Visible = False
        月4_dgv.Columns(8).Visible = False : 月4_dgv.Columns(9).FillWeight = 75
        月4_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月4_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月4_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月4_dgv.Columns(9).ReadOnly = True
        TextBox13.Text = "0" : TextBox14.Text = "0" : TextBox15.Text = "0" : TextBox16.Text = "0" : TextBox27.Text = "0" : TextBox73.Text = "0"
        For i As Integer = 0 To 月4_dgv.Rows.Count - 1
            If 月4_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月4_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月4_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月4_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月4_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月4_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月4_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月4_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月4_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月4_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月4_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月4_dgv.Rows(i).Cells("金額").Value = 月4_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月4_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月4_dgv.Rows(i).Cells("金額").Value = 月4_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月4_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月4_dgv.Rows(i).Cells("金額").Value = 月4_dgv.Rows(i).Cells("細項金額").Value
            Else : 月4_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月4_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月4_dgv("金額", i).Value = Val(月4_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月4_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox13.Text = Val(TextBox13.Text) + 月4_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月4_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox14.Text = Val(TextBox14.Text) + 月4_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月4_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox15.Text = Val(TextBox15.Text) + 月4_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月4_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox27.Text = Val(TextBox27.Text) + 月4_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox27.Text) > 0 Then
            TextBox85.Text = Val(TextBox27.Text) - Val(TextBox12.Text)
        Else
            TextBox85.Text = 0
        End If

        TextBox15.Text = Val(TextBox15.Text) * -1
        TextBox16.Text = Val(TextBox27.Text) + Val(TextBox13.Text) + Val(TextBox14.Text) - Val(TextBox15.Text)
        TextBox73.Text = Val(TextBox14.Text) - Val(TextBox15.Text)
    End Sub
    Private Sub Set_清單5()
        月5_dgv.DataSource = Nothing : ds5.Clear() : 月5_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月5_dgv.ColumnHeadersHeight = 50 : 月5_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢五月份清單() : da.Fill(ds5) : 月5_dgv.DataSource = ds5.Tables(0) : conn.Close()
        月5_dgv.Columns(0).FillWeight = 20 : 月5_dgv.Columns(1).Visible = False : 月5_dgv.Columns(2).Visible = False : 月5_dgv.Columns(3).Visible = False
        月5_dgv.Columns(4).Visible = False : 月5_dgv.Columns(5).Visible = False : 月5_dgv.Columns(6).Visible = False : 月5_dgv.Columns(7).Visible = False
        月5_dgv.Columns(8).Visible = False : 月5_dgv.Columns(9).FillWeight = 75
        月5_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月5_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月5_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月5_dgv.Columns(9).ReadOnly = True
        TextBox17.Text = "0" : TextBox18.Text = "0" : TextBox19.Text = "0" : TextBox20.Text = "0" : TextBox26.Text = "0" : TextBox72.Text = "0"
        For i As Integer = 0 To 月5_dgv.Rows.Count - 1
            If 月5_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月5_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月5_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月5_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月5_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月5_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月5_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月5_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月5_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月5_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月5_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月5_dgv.Rows(i).Cells("金額").Value = 月5_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月5_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月5_dgv.Rows(i).Cells("金額").Value = 月5_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月5_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月5_dgv.Rows(i).Cells("金額").Value = 月5_dgv.Rows(i).Cells("細項金額").Value
            Else : 月5_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月5_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月5_dgv("金額", i).Value = Val(月5_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月5_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox17.Text = Val(TextBox17.Text) + 月5_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月5_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox18.Text = Val(TextBox18.Text) + 月5_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月5_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox19.Text = Val(TextBox19.Text) + 月5_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月5_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox26.Text = Val(TextBox26.Text) + 月5_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox26.Text) > 0 Then
            TextBox84.Text = Val(TextBox26.Text) - Val(TextBox16.Text)
        Else
            TextBox84.Text = 0
        End If

        TextBox19.Text = Val(TextBox19.Text) * -1
        TextBox20.Text = Val(TextBox17.Text) + Val(TextBox18.Text) - Val(TextBox19.Text) + Val(TextBox26.Text)
        TextBox72.Text = Val(TextBox18.Text) - Val(TextBox19.Text)
    End Sub
    Private Sub Set_清單6()
        月6_dgv.DataSource = Nothing : ds6.Clear() : 月6_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月6_dgv.ColumnHeadersHeight = 50 : 月6_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢六月份清單() : da.Fill(ds6) : 月6_dgv.DataSource = ds6.Tables(0) : conn.Close()
        月6_dgv.Columns(0).FillWeight = 20 : 月6_dgv.Columns(1).Visible = False : 月6_dgv.Columns(2).Visible = False : 月6_dgv.Columns(3).Visible = False
        月6_dgv.Columns(4).Visible = False : 月6_dgv.Columns(5).Visible = False : 月6_dgv.Columns(6).Visible = False : 月6_dgv.Columns(7).Visible = False
        月6_dgv.Columns(8).Visible = False : 月6_dgv.Columns(9).FillWeight = 75
        月6_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月6_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月6_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月6_dgv.Columns(9).ReadOnly = True
        TextBox21.Text = "0" : TextBox22.Text = "0" : TextBox23.Text = "0" : TextBox24.Text = "0" : TextBox25.Text = "0" : TextBox71.Text = "0"
        For i As Integer = 0 To 月6_dgv.Rows.Count - 1
            If 月6_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月6_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月6_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月6_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月6_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月6_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月6_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月6_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月6_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月6_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月6_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月6_dgv.Rows(i).Cells("金額").Value = 月6_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月6_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月6_dgv.Rows(i).Cells("金額").Value = 月6_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月6_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月6_dgv.Rows(i).Cells("金額").Value = 月6_dgv.Rows(i).Cells("細項金額").Value
            Else : 月6_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月6_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月6_dgv("金額", i).Value = Val(月6_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月6_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox21.Text = Val(TextBox21.Text) + 月6_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月6_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox22.Text = Val(TextBox22.Text) + 月6_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月6_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox23.Text = Val(TextBox23.Text) + 月6_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月6_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox25.Text = Val(TextBox25.Text) + 月6_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox25.Text) > 0 Then
            TextBox83.Text = Val(TextBox25.Text) - Val(TextBox20.Text)
        Else
            TextBox83.Text = 0
        End If

        TextBox23.Text = Val(TextBox23.Text) * -1
        TextBox24.Text = Val(TextBox21.Text) + Val(TextBox22.Text) - Val(TextBox23.Text) + Val(TextBox25.Text)
        TextBox71.Text = Val(TextBox22.Text) - Val(TextBox23.Text)
    End Sub
    Private Sub Set_清單7()
        月7_dgv.DataSource = Nothing : ds7.Clear() : 月7_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月7_dgv.ColumnHeadersHeight = 50 : 月7_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢七月份清單() : da.Fill(ds7) : 月7_dgv.DataSource = ds7.Tables(0) : conn.Close()
        月7_dgv.Columns(0).FillWeight = 20 : 月7_dgv.Columns(1).Visible = False : 月7_dgv.Columns(2).Visible = False : 月7_dgv.Columns(3).Visible = False
        月7_dgv.Columns(4).Visible = False : 月7_dgv.Columns(5).Visible = False : 月7_dgv.Columns(6).Visible = False : 月7_dgv.Columns(7).Visible = False
        月7_dgv.Columns(8).Visible = False : 月7_dgv.Columns(9).FillWeight = 75
        月7_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月7_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月7_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月7_dgv.Columns(9).ReadOnly = True
        TextBox31.Text = "0" : TextBox32.Text = "0" : TextBox33.Text = "0" : TextBox34.Text = "0" : TextBox35.Text = "0" : TextBox70.Text = "0"
        For i As Integer = 0 To 月7_dgv.Rows.Count - 1
            If 月7_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月7_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月7_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月7_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月7_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月7_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月7_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月7_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月7_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月7_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月7_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月7_dgv.Rows(i).Cells("金額").Value = 月7_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月7_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月7_dgv.Rows(i).Cells("金額").Value = 月7_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月7_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月7_dgv.Rows(i).Cells("金額").Value = 月7_dgv.Rows(i).Cells("細項金額").Value
            Else : 月7_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月7_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月7_dgv("金額", i).Value = Val(月7_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月7_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox35.Text = Val(TextBox35.Text) + 月7_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月7_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox34.Text = Val(TextBox34.Text) + 月7_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月7_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox33.Text = Val(TextBox33.Text) + 月7_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月7_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox31.Text = Val(TextBox31.Text) + 月7_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox31.Text) > 0 Then
            TextBox82.Text = Val(TextBox31.Text) - Val(TextBox24.Text)
        Else
            TextBox82.Text = 0
        End If

        TextBox33.Text = Val(TextBox33.Text) * -1
        TextBox32.Text = Val(TextBox35.Text) + Val(TextBox34.Text) - Val(TextBox33.Text) + Val(TextBox31.Text)
        TextBox70.Text = Val(TextBox34.Text) - Val(TextBox33.Text)
    End Sub
    Private Sub Set_清單8()
        月8_dgv.DataSource = Nothing : ds8.Clear() : 月8_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月8_dgv.ColumnHeadersHeight = 50 : 月8_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢八月份清單() : da.Fill(ds8) : 月8_dgv.DataSource = ds8.Tables(0) : conn.Close()
        月8_dgv.Columns(0).FillWeight = 20 : 月8_dgv.Columns(1).Visible = False : 月8_dgv.Columns(2).Visible = False : 月8_dgv.Columns(3).Visible = False
        月8_dgv.Columns(4).Visible = False : 月8_dgv.Columns(5).Visible = False : 月8_dgv.Columns(6).Visible = False : 月8_dgv.Columns(7).Visible = False
        月8_dgv.Columns(8).Visible = False : 月8_dgv.Columns(9).FillWeight = 75
        月8_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月8_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月8_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月8_dgv.Columns(9).ReadOnly = True
        TextBox36.Text = "0" : TextBox37.Text = "0" : TextBox38.Text = "0" : TextBox39.Text = "0" : TextBox40.Text = "0" : TextBox69.Text = "0"
        For i As Integer = 0 To 月8_dgv.Rows.Count - 1
            If 月8_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月8_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月8_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月8_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月8_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月8_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月8_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月8_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月8_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月8_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月8_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月8_dgv.Rows(i).Cells("金額").Value = 月8_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月8_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月8_dgv.Rows(i).Cells("金額").Value = 月8_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月8_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月8_dgv.Rows(i).Cells("金額").Value = 月8_dgv.Rows(i).Cells("細項金額").Value
            Else : 月8_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月8_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月8_dgv("金額", i).Value = Val(月8_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月8_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox40.Text = Val(TextBox40.Text) + 月8_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月8_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox39.Text = Val(TextBox39.Text) + 月8_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月8_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox38.Text = Val(TextBox38.Text) + 月8_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月8_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox36.Text = Val(TextBox36.Text) + 月8_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox36.Text) > 0 Then
            TextBox81.Text = Val(TextBox36.Text) - Val(TextBox32.Text)
        Else
            TextBox81.Text = 0
        End If

        TextBox38.Text = Val(TextBox38.Text) * -1
        TextBox37.Text = Val(TextBox40.Text) + Val(TextBox39.Text) - Val(TextBox38.Text) + Val(TextBox36.Text)
        TextBox69.Text = Val(TextBox39.Text) - Val(TextBox38.Text)
    End Sub
    Private Sub Set_清單9()
        月9_dgv.DataSource = Nothing : ds9.Clear() : 月9_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月9_dgv.ColumnHeadersHeight = 50 : 月9_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢九月份清單() : da.Fill(ds9) : 月9_dgv.DataSource = ds9.Tables(0) : conn.Close()
        月9_dgv.Columns(0).FillWeight = 20 : 月9_dgv.Columns(1).Visible = False : 月9_dgv.Columns(2).Visible = False : 月9_dgv.Columns(3).Visible = False
        月9_dgv.Columns(4).Visible = False : 月9_dgv.Columns(5).Visible = False : 月9_dgv.Columns(6).Visible = False : 月9_dgv.Columns(7).Visible = False
        月9_dgv.Columns(8).Visible = False : 月9_dgv.Columns(9).FillWeight = 75
        月9_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月9_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月9_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月9_dgv.Columns(9).ReadOnly = True
        TextBox41.Text = "0" : TextBox42.Text = "0" : TextBox43.Text = "0" : TextBox44.Text = "0" : TextBox45.Text = "0" : TextBox68.Text = "0"
        For i As Integer = 0 To 月9_dgv.Rows.Count - 1
            If 月9_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月9_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月9_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月9_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月9_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月9_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月9_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月9_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月9_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月9_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月9_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月9_dgv.Rows(i).Cells("金額").Value = 月9_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月9_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月9_dgv.Rows(i).Cells("金額").Value = 月9_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月9_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月9_dgv.Rows(i).Cells("金額").Value = 月9_dgv.Rows(i).Cells("細項金額").Value
            Else : 月9_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月9_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月9_dgv("金額", i).Value = Val(月9_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月9_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox45.Text = Val(TextBox45.Text) + 月9_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月9_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox44.Text = Val(TextBox44.Text) + 月9_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月9_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox43.Text = Val(TextBox43.Text) + 月9_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月9_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox41.Text = Val(TextBox41.Text) + 月9_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox41.Text) > 0 Then
            TextBox80.Text = Val(TextBox41.Text) - Val(TextBox37.Text)
        Else
            TextBox80.Text = 0
        End If

        TextBox43.Text = Val(TextBox43.Text) * -1
        TextBox42.Text = Val(TextBox45.Text) + Val(TextBox44.Text) - Val(TextBox43.Text) + Val(TextBox41.Text)
        TextBox68.Text = Val(TextBox44.Text) - Val(TextBox43.Text)
    End Sub
    Private Sub Set_清單10()
        月10_dgv.DataSource = Nothing : ds10.Clear() : 月10_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月10_dgv.ColumnHeadersHeight = 50 : 月10_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢十月份清單() : da.Fill(ds10) : 月10_dgv.DataSource = ds10.Tables(0) : conn.Close()
        月10_dgv.Columns(0).FillWeight = 20 : 月10_dgv.Columns(1).Visible = False : 月10_dgv.Columns(2).Visible = False : 月10_dgv.Columns(3).Visible = False
        月10_dgv.Columns(4).Visible = False : 月10_dgv.Columns(5).Visible = False : 月10_dgv.Columns(6).Visible = False : 月10_dgv.Columns(7).Visible = False
        月10_dgv.Columns(8).Visible = False : 月10_dgv.Columns(9).FillWeight = 75
        月10_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月10_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月10_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月10_dgv.Columns(9).ReadOnly = True
        TextBox46.Text = "0" : TextBox47.Text = "0" : TextBox48.Text = "0" : TextBox49.Text = "0" : TextBox50.Text = "0" : TextBox67.Text = "0"
        For i As Integer = 0 To 月10_dgv.Rows.Count - 1
            If 月10_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月10_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月10_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月10_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月10_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月10_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月10_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月10_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月10_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月10_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月10_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月10_dgv.Rows(i).Cells("金額").Value = 月10_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月10_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月10_dgv.Rows(i).Cells("金額").Value = 月10_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月10_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月10_dgv.Rows(i).Cells("金額").Value = 月10_dgv.Rows(i).Cells("細項金額").Value
            Else : 月10_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月10_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月10_dgv("金額", i).Value = Val(月10_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月10_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox50.Text = Val(TextBox50.Text) + 月10_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月10_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox49.Text = Val(TextBox49.Text) + 月10_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月10_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox48.Text = Val(TextBox48.Text) + 月10_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月10_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox46.Text = Val(TextBox46.Text) + 月10_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox46.Text) > 0 Then
            TextBox79.Text = Val(TextBox46.Text) - Val(TextBox42.Text)
        Else
            TextBox79.Text = 0
        End If

        TextBox48.Text = Val(TextBox48.Text) * -1
        TextBox47.Text = Val(TextBox50.Text) + Val(TextBox49.Text) - Val(TextBox48.Text) + Val(TextBox46.Text)
        TextBox67.Text = Val(TextBox49.Text) - Val(TextBox48.Text)
    End Sub
    Private Sub Set_清單11()
        月11_dgv.DataSource = Nothing : ds11.Clear() : 月11_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月11_dgv.ColumnHeadersHeight = 50 : 月11_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢十一月份清單() : da.Fill(ds11) : 月11_dgv.DataSource = ds11.Tables(0) : conn.Close()
        月11_dgv.Columns(0).FillWeight = 20 : 月11_dgv.Columns(1).Visible = False : 月11_dgv.Columns(2).Visible = False : 月11_dgv.Columns(3).Visible = False
        月11_dgv.Columns(4).Visible = False : 月11_dgv.Columns(5).Visible = False : 月11_dgv.Columns(6).Visible = False : 月11_dgv.Columns(7).Visible = False
        月11_dgv.Columns(8).Visible = False : 月11_dgv.Columns(9).FillWeight = 75
        月11_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月11_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月11_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月11_dgv.Columns(9).ReadOnly = True
        TextBox51.Text = "0" : TextBox52.Text = "0" : TextBox53.Text = "0" : TextBox54.Text = "0" : TextBox55.Text = "0" : TextBox66.Text = "0"
        For i As Integer = 0 To 月11_dgv.Rows.Count - 1
            If 月11_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月11_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月11_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月11_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月11_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月11_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月11_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月11_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月11_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月11_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月11_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月11_dgv.Rows(i).Cells("金額").Value = 月11_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月11_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月11_dgv.Rows(i).Cells("金額").Value = 月11_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月11_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月11_dgv.Rows(i).Cells("金額").Value = 月11_dgv.Rows(i).Cells("細項金額").Value
            Else : 月11_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月11_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月11_dgv("金額", i).Value = Val(月11_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月11_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox55.Text = Val(TextBox55.Text) + 月11_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月11_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox54.Text = Val(TextBox54.Text) + 月11_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月11_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox53.Text = Val(TextBox53.Text) + 月11_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月11_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox51.Text = Val(TextBox51.Text) + 月11_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox51.Text) > 0 Then
            TextBox78.Text = Val(TextBox51.Text) - Val(TextBox47.Text)
        Else
            TextBox78.Text = 0
        End If

        TextBox53.Text = Val(TextBox53.Text) * -1
        TextBox52.Text = Val(TextBox55.Text) + Val(TextBox54.Text) - Val(TextBox53.Text) + Val(TextBox51.Text)
        TextBox66.Text = Val(TextBox54.Text) - Val(TextBox53.Text)
    End Sub
    Private Sub Set_清單12()
        月12_dgv.DataSource = Nothing : ds12.Clear() : 月12_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        月12_dgv.ColumnHeadersHeight = 50 : 月12_dgv.AllowUserToAddRows = False
        SQL_營運報表_查詢十二月份清單() : da.Fill(ds12) : 月12_dgv.DataSource = ds12.Tables(0) : conn.Close()
        月12_dgv.Columns(0).FillWeight = 30 : 月12_dgv.Columns(1).Visible = False : 月12_dgv.Columns(2).Visible = False : 月12_dgv.Columns(3).Visible = False
        月12_dgv.Columns(4).Visible = False : 月12_dgv.Columns(5).Visible = False : 月12_dgv.Columns(6).Visible = False : 月12_dgv.Columns(7).Visible = False
        月12_dgv.Columns(8).Visible = False : 月12_dgv.Columns(9).FillWeight = 75
        月12_dgv.Columns(9).DefaultCellStyle.Format = "#,##0"
        月12_dgv.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : 月12_dgv.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        月12_dgv.Columns(9).ReadOnly = True
        TextBox56.Text = "0" : TextBox57.Text = "0" : TextBox58.Text = "0" : TextBox59.Text = "0" : TextBox60.Text = "0" : TextBox65.Text = "0"
        For i As Integer = 0 To 月12_dgv.Rows.Count - 1
            If 月12_dgv.Rows(i).Cells("主項金額").Value.ToString = "" Then : 月12_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月12_dgv.Rows(i).Cells("子項金額").Value.ToString = "" Then : 月12_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月12_dgv.Rows(i).Cells("細項金額").Value.ToString = "" Then : 月12_dgv.Rows(i).Cells("細項金額").Value = 0 : End If
            If 月12_dgv.Rows(i).Cells("層級").Value.ToString <> "1" Then : 月12_dgv.Rows(i).Cells("主項金額").Value = 0 : End If
            If 月12_dgv.Rows(i).Cells("層級").Value.ToString <> "2" Then : 月12_dgv.Rows(i).Cells("子項金額").Value = 0 : End If
            If 月12_dgv.Rows(i).Cells("主項金額").Value.ToString <> "0" Then : 月12_dgv.Rows(i).Cells("金額").Value = 月12_dgv.Rows(i).Cells("主項金額").Value
            ElseIf 月12_dgv.Rows(i).Cells("子項金額").Value.ToString <> "0" Then : 月12_dgv.Rows(i).Cells("金額").Value = 月12_dgv.Rows(i).Cells("子項金額").Value
            ElseIf 月12_dgv.Rows(i).Cells("細項金額").Value.ToString <> "0" Then : 月12_dgv.Rows(i).Cells("金額").Value = 月12_dgv.Rows(i).Cells("細項金額").Value
            Else : 月12_dgv.Rows(i).Cells("金額").Value = 0 : End If

            If 月12_dgv("第一階", i).Value.ToString = "歲出合計" Then
                月12_dgv("金額", i).Value = Val(月12_dgv.Rows(i).Cells("金額").Value) * -1
            End If

            If 月12_dgv.Rows(i).Cells("第一階").Value.ToString = "資本" Then : TextBox60.Text = Val(TextBox60.Text) + 月12_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月12_dgv.Rows(i).Cells("第一階").Value.ToString = "歲入合計" Then : TextBox59.Text = Val(TextBox59.Text) + 月12_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月12_dgv.Rows(i).Cells("第一階").Value.ToString = "歲出合計" Then : TextBox58.Text = Val(TextBox58.Text) + 月12_dgv.Rows(i).Cells("主項金額").Value : End If
            If 月12_dgv.Rows(i).Cells("第一階").Value.ToString = "上月結存" Then : TextBox56.Text = Val(TextBox56.Text) + 月12_dgv.Rows(i).Cells("主項金額").Value : End If
        Next
        If Val(TextBox56.Text) > 0 Then
            TextBox77.Text = Val(TextBox56.Text) - Val(TextBox52.Text)
        Else
            TextBox77.Text = 0
        End If

        TextBox58.Text = Val(TextBox58.Text) * -1
        TextBox57.Text = Val(TextBox60.Text) + Val(TextBox59.Text) - Val(TextBox58.Text) + Val(TextBox56.Text)
        TextBox65.Text = Val(TextBox59.Text) - Val(TextBox58.Text)
    End Sub
    Private Sub ComboBox1下拉表單資料載入()
        conn.Close()
        SQL_營運報表_年份查詢()
        年份_cb.Items.Clear()
        While (dr.Read()) : 年份_cb.Items.Add(dr("年份")) : End While
        conn.Close()
    End Sub
    Private Sub 格式設定()
        For no As Integer = 1 To 88
            Dim TextBoxOO As TextBox = CType(Me.Controls.Find("TextBox" + no.ToString(), True)(0), TextBox)
            TextBoxOO.Text = Format(Val(TextBoxOO.Text), "#,##0 ")
        Next
        For no As Integer = 64 To 88
            Dim TextBoxOO As TextBox = CType(Me.Controls.Find("TextBox" + no.ToString(), True)(0), TextBox)
            If Val(TextBoxOO.Text) > 0 Then : TextBoxOO.ForeColor = Color.Blue : ElseIf Val(TextBoxOO.Text) < 0 Then : TextBoxOO.ForeColor = Color.Red : End If
        Next
    End Sub
    Private Sub 營運報表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        YD_ERP_SYS.WindowState = 2 : 計算基礎_ch.SelectedIndex = 0
        Me.MdiParent = YD_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        Dim type0 As Type = 主表_dgv.GetType()
        Dim pi0 As Reflection.PropertyInfo = type0.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi0.SetValue(主表_dgv, True, Nothing)
        Dim type1 As Type = 月1_dgv.GetType()
        Dim pi1 As Reflection.PropertyInfo = type1.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi1.SetValue(月1_dgv, True, Nothing)
        Dim type2 As Type = 月2_dgv.GetType()
        Dim pi2 As Reflection.PropertyInfo = type2.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi2.SetValue(月2_dgv, True, Nothing)
        Dim type3 As Type = 月3_dgv.GetType()
        Dim pi3 As Reflection.PropertyInfo = type3.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi3.SetValue(月3_dgv, True, Nothing)
        Dim type4 As Type = 月4_dgv.GetType()
        Dim pi4 As Reflection.PropertyInfo = type4.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi4.SetValue(月4_dgv, True, Nothing)
        Dim type5 As Type = 月5_dgv.GetType()
        Dim pi5 As Reflection.PropertyInfo = type5.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi5.SetValue(月5_dgv, True, Nothing)
        Dim type6 As Type = 月6_dgv.GetType()
        Dim pi6 As Reflection.PropertyInfo = type6.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi6.SetValue(月6_dgv, True, Nothing)
        Dim type7 As Type = 月7_dgv.GetType()
        Dim pi7 As Reflection.PropertyInfo = type7.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi7.SetValue(月7_dgv, True, Nothing)
        Dim type8 As Type = 月8_dgv.GetType()
        Dim pi8 As Reflection.PropertyInfo = type8.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi8.SetValue(月8_dgv, True, Nothing)
        Dim type9 As Type = 月9_dgv.GetType()
        Dim pi9 As Reflection.PropertyInfo = type9.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi9.SetValue(月9_dgv, True, Nothing)
        Dim type10 As Type = 月10_dgv.GetType()
        Dim pi10 As Reflection.PropertyInfo = type10.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi10.SetValue(月10_dgv, True, Nothing)
        Dim type11 As Type = 月11_dgv.GetType()
        Dim pi11 As Reflection.PropertyInfo = type11.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi11.SetValue(月11_dgv, True, Nothing)
        Dim type12 As Type = 月12_dgv.GetType()
        Dim pi12 As Reflection.PropertyInfo = type12.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
        pi12.SetValue(月12_dgv, True, Nothing)

        ComboBox1下拉表單資料載入() : 年份_cb.Text = Year(Today)
        Set_清單() : Set_清單1() : Set_清單2() : Set_清單3() : Set_清單4() : Set_清單5() : Set_清單6() : Set_清單7()
        Set_清單8() : Set_清單9() : Set_清單10() : Set_清單11() : Set_清單12() : 格式設定()
        Dim FF As Integer = 21
        月1_dgv.RowTemplate.Height = FF : 月2_dgv.RowTemplate.Height = FF : 月3_dgv.RowTemplate.Height = FF
        月4_dgv.RowTemplate.Height = FF : 月5_dgv.RowTemplate.Height = FF : 月6_dgv.RowTemplate.Height = FF
        月7_dgv.RowTemplate.Height = FF : 月8_dgv.RowTemplate.Height = FF : 月9_dgv.RowTemplate.Height = FF
        月10_dgv.RowTemplate.Height = FF : 月11_dgv.RowTemplate.Height = FF : 月12_dgv.RowTemplate.Height = FF
        主表_dgv.RowTemplate.Height = FF
    End Sub
    Private Sub 計算基礎_ch_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 計算基礎_ch.Click
        Set_清單() : Set_清單1() : Set_清單2() : Set_清單3() : Set_清單4() : Set_清單5() : Set_清單6() : Set_清單7()
        Set_清單8() : Set_清單9() : Set_清單10() : Set_清單11() : Set_清單12() : 格式設定()
    End Sub
    Private Sub 營運報表_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
        YD_ERP_SYS.WindowState = 0
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 年份_cb.SelectedIndexChanged
        Set_清單() : Set_清單1() : Set_清單2() : Set_清單3() : Set_清單4() : Set_清單5() : Set_清單6() : Set_清單7()
        Set_清單8() : Set_清單9() : Set_清單10() : Set_清單11() : Set_清單12() : 格式設定()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles 重新整理_bt.Click
        Set_清單() : Set_清單1() : Set_清單2() : Set_清單3() : Set_清單4() : Set_清單5() : Set_清單6() : Set_清單7()
        Set_清單8() : Set_清單9() : Set_清單10() : Set_清單11() : Set_清單12() : 格式設定()
    End Sub
    Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
        月1_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月2_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月3_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月4_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月5_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月6_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月7_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月8_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月9_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月10_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月11_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        月12_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
        主表_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", 字體_NUD.Value)
    End Sub
    Private Sub 主表_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 主表_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 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
            If 主表_dgv(2, e.RowIndex).Value.ToString <> 主表_dgv(2, 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(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 主表_dgv.Rows.Count - 1
                If 主表_dgv("層級", i).Value = 1 Then : 主表_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 主表_dgv("層級", i).Value = 2 Then : 主表_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 主表_dgv("第一階", i).Value.ToString = "資本" Then : 主表_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 主表_dgv("第一階", i).Value.ToString = "上月結存" Then : 主表_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 主表_dgv("第一階", i).Value.ToString = "歲入合計" Then : 主表_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 主表_dgv("第一階", i).Value.ToString = "歲出合計" Then : 主表_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月1_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月1_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月1_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月1_dgv(1, e.RowIndex).Value.ToString <> 月1_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月1_dgv.RowHeadersVisible, 月1_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月1_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月1_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月1_dgv(2, e.RowIndex).Value.ToString <> 月1_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月1_dgv.RowHeadersVisible, 月1_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月1_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月1_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月1_dgv.Rows.Count - 1
                If 月1_dgv("層級", i).Value = 1 Then : 月1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月1_dgv("層級", i).Value = 2 Then : 月1_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月1_dgv("第一階", i).Value.ToString = "資本" Then : 月1_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月1_dgv("第一階", i).Value.ToString = "上月結存" Then : 月1_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月1_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月1_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月1_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月1_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月2_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月2_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月2_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月2_dgv(1, e.RowIndex).Value.ToString <> 月2_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月2_dgv.RowHeadersVisible, 月2_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月2_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月2_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月2_dgv(2, e.RowIndex).Value.ToString <> 月2_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月2_dgv.RowHeadersVisible, 月2_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月2_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月2_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月2_dgv.Rows.Count - 1
                If 月2_dgv("層級", i).Value = 1 Then : 月2_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月2_dgv("層級", i).Value = 2 Then : 月2_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月2_dgv("第一階", i).Value.ToString = "資本" Then : 月2_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月2_dgv("第一階", i).Value.ToString = "上月結存" Then : 月2_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月2_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月2_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月2_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月2_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月3_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月3_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月3_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月3_dgv(1, e.RowIndex).Value.ToString <> 月3_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月3_dgv.RowHeadersVisible, 月3_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月3_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月3_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月3_dgv(2, e.RowIndex).Value.ToString <> 月3_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月3_dgv.RowHeadersVisible, 月3_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月3_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月3_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月3_dgv.Rows.Count - 1
                If 月3_dgv("層級", i).Value = 1 Then : 月3_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月3_dgv("層級", i).Value = 2 Then : 月3_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月3_dgv("第一階", i).Value.ToString = "資本" Then : 月3_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月3_dgv("第一階", i).Value.ToString = "上月結存" Then : 月3_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月3_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月3_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月3_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月3_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月4_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月4_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月4_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月4_dgv(1, e.RowIndex).Value.ToString <> 月4_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月4_dgv.RowHeadersVisible, 月4_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月4_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月4_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月4_dgv(2, e.RowIndex).Value.ToString <> 月4_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月4_dgv.RowHeadersVisible, 月4_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月4_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月4_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月4_dgv.Rows.Count - 1
                If 月4_dgv("層級", i).Value = 1 Then : 月4_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月4_dgv("層級", i).Value = 2 Then : 月4_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月4_dgv("第一階", i).Value.ToString = "資本" Then : 月4_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月4_dgv("第一階", i).Value.ToString = "上月結存" Then : 月4_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月4_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月4_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月4_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月4_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月5_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月5_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月5_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月5_dgv(1, e.RowIndex).Value.ToString <> 月5_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月5_dgv.RowHeadersVisible, 月5_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月5_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月5_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月5_dgv(2, e.RowIndex).Value.ToString <> 月5_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月5_dgv.RowHeadersVisible, 月5_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月5_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月5_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月5_dgv.Rows.Count - 1
                If 月5_dgv("層級", i).Value = 1 Then : 月5_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月5_dgv("層級", i).Value = 2 Then : 月5_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月5_dgv("第一階", i).Value.ToString = "資本" Then : 月5_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月5_dgv("第一階", i).Value.ToString = "上月結存" Then : 月5_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月5_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月5_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月5_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月5_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月6_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月6_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月6_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月6_dgv(1, e.RowIndex).Value.ToString <> 月6_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月6_dgv.RowHeadersVisible, 月6_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月6_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月6_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月6_dgv(2, e.RowIndex).Value.ToString <> 月6_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月6_dgv.RowHeadersVisible, 月6_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月6_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月6_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月6_dgv.Rows.Count - 1
                If 月6_dgv("層級", i).Value = 1 Then : 月6_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月6_dgv("層級", i).Value = 2 Then : 月6_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月6_dgv("第一階", i).Value.ToString = "資本" Then : 月6_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月6_dgv("第一階", i).Value.ToString = "上月結存" Then : 月6_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月6_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月6_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月6_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月6_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月7_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月7_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月7_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月7_dgv(1, e.RowIndex).Value.ToString <> 月7_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月7_dgv.RowHeadersVisible, 月7_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月7_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月7_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月7_dgv(2, e.RowIndex).Value.ToString <> 月7_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月7_dgv.RowHeadersVisible, 月7_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月7_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月7_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月7_dgv.Rows.Count - 1
                If 月7_dgv("層級", i).Value = 1 Then : 月7_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月7_dgv("層級", i).Value = 2 Then : 月7_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月7_dgv("第一階", i).Value.ToString = "資本" Then : 月7_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月7_dgv("第一階", i).Value.ToString = "上月結存" Then : 月7_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月7_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月7_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月7_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月7_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月8_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月8_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月8_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月8_dgv(1, e.RowIndex).Value.ToString <> 月8_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月8_dgv.RowHeadersVisible, 月8_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月8_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月8_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月8_dgv(2, e.RowIndex).Value.ToString <> 月8_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月8_dgv.RowHeadersVisible, 月8_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月8_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月8_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月8_dgv.Rows.Count - 1
                If 月8_dgv("層級", i).Value = 1 Then : 月8_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月8_dgv("層級", i).Value = 2 Then : 月8_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月8_dgv("第一階", i).Value.ToString = "資本" Then : 月8_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月8_dgv("第一階", i).Value.ToString = "上月結存" Then : 月8_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月8_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月8_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月8_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月8_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月9_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月9_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月9_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月9_dgv(1, e.RowIndex).Value.ToString <> 月9_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月9_dgv.RowHeadersVisible, 月9_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月9_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月9_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月9_dgv(2, e.RowIndex).Value.ToString <> 月9_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月9_dgv.RowHeadersVisible, 月9_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月9_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月9_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月9_dgv.Rows.Count - 1
                If 月9_dgv("層級", i).Value = 1 Then : 月9_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月9_dgv("層級", i).Value = 2 Then : 月9_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月9_dgv("第一階", i).Value.ToString = "資本" Then : 月9_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月9_dgv("第一階", i).Value.ToString = "上月結存" Then : 月9_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月9_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月9_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月9_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月9_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月10_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月10_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月10_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月10_dgv(1, e.RowIndex).Value.ToString <> 月10_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月10_dgv.RowHeadersVisible, 月10_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月10_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月10_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月10_dgv(2, e.RowIndex).Value.ToString <> 月10_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月10_dgv.RowHeadersVisible, 月10_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月10_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月10_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月10_dgv.Rows.Count - 1
                If 月10_dgv("層級", i).Value = 1 Then : 月10_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月10_dgv("層級", i).Value = 2 Then : 月10_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月10_dgv("第一階", i).Value.ToString = "資本" Then : 月10_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月10_dgv("第一階", i).Value.ToString = "上月結存" Then : 月10_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月10_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月10_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月10_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月10_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月11_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月11_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月11_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月11_dgv(1, e.RowIndex).Value.ToString <> 月11_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月11_dgv.RowHeadersVisible, 月11_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月11_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月11_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月11_dgv(2, e.RowIndex).Value.ToString <> 月11_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月11_dgv.RowHeadersVisible, 月11_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月11_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月11_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月11_dgv.Rows.Count - 1
                If 月11_dgv("層級", i).Value = 1 Then : 月11_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月11_dgv("層級", i).Value = 2 Then : 月11_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月11_dgv("第一階", i).Value.ToString = "資本" Then : 月11_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月11_dgv("第一階", i).Value.ToString = "上月結存" Then : 月11_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月11_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月11_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月11_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月11_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 月12_dgv_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles 月12_dgv.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2) : Dim linePen1 As New Pen(Color.Red, 2)
        If e.RowIndex = 月12_dgv.Rows.Count - 1 Then : Exit Sub : Else
            If 月12_dgv(1, e.RowIndex).Value.ToString <> 月12_dgv(1, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月12_dgv.RowHeadersVisible, 月12_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月12_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月12_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub
            End If
            If 月12_dgv(2, e.RowIndex).Value.ToString <> 月12_dgv(2, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(月12_dgv.RowHeadersVisible, 月12_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + 月12_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 月12_dgv.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen1, startX, startY, endX, startY) : Exit Sub
            End If
            For i As Integer = 0 To 月12_dgv.Rows.Count - 1
                If 月12_dgv("層級", i).Value = 1 Then : 月12_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightPink
                ElseIf 月12_dgv("層級", i).Value = 2 Then : 月12_dgv.Rows(i).DefaultCellStyle.BackColor = Color.LightGoldenrodYellow
                End If
                If 月12_dgv("第一階", i).Value.ToString = "資本" Then : 月12_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Green
                ElseIf 月12_dgv("第一階", i).Value.ToString = "上月結存" Then : 月12_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Black
                ElseIf 月12_dgv("第一階", i).Value.ToString = "歲入合計" Then : 月12_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Blue
                ElseIf 月12_dgv("第一階", i).Value.ToString = "歲出合計" Then : 月12_dgv.Rows(i).DefaultCellStyle.ForeColor = Color.Red
                End If
            Next
        End If
    End Sub
    Private Sub 主表_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 主表_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 主表_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月1_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月1_dgv.Scroll
        主表_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月1_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月2_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月2_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex : 主表_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月2_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月3_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月3_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex
        主表_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月3_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月4_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月4_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex : 主表_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月4_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月5_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月5_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex
        主表_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月5_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月6_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月6_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex : 主表_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月6_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月7_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月7_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex
        主表_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月7_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月8_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月8_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex : 主表_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月8_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月9_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月9_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex
        主表_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月9_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月10_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月10_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex : 主表_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月10_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月11_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月11_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex
        主表_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex : 月12_dgv.FirstDisplayedScrollingRowIndex = 月11_dgv.FirstDisplayedScrollingRowIndex
    End Sub
    Private Sub 月12_dgv_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles 月12_dgv.Scroll
        月1_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex : 月2_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex
        月3_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex : 月4_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex
        月5_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex : 月6_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex
        月7_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex : 月8_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex
        月9_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex : 月10_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex
        月11_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex : 主表_dgv.FirstDisplayedScrollingRowIndex = 月12_dgv.FirstDisplayedScrollingRowIndex
    End Sub
End Class