Option Strict Off Public Class 會計科目管理 ReadOnly ds3 As New DataSet Dim EDR As Integer = 0 : Dim ESTR As String Private Sub Set_會計科目() DataGridView7.DataSource = Nothing : ds3.Clear() : DataGridView7.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView7.ColumnHeadersHeight = 25 : DataGridView7.AllowUserToAddRows = False ConnOpen() SQL1 = "SELECT 第一階, 第二階, 會計科目, 編號, 層級, 英文名稱, 統制科目, 抵銷科目, 停用, 附註, 顯示 FROM 會計科目 WHERE 編號 LIKE N'" & ComboBox2.Text & "%' ORDER BY 編號" CmdSet_For_DGV() : da.Fill(ds3) : DataGridView7.DataSource = ds3.Tables(0) : conn.Close() DataGridView7.Columns(0).FillWeight = 8 : DataGridView7.Columns(1).FillWeight = 8 : DataGridView7.Columns(2).FillWeight = 12 : DataGridView7.Columns(3).FillWeight = 6 DataGridView7.Columns(4).FillWeight = 3 : DataGridView7.Columns(5).FillWeight = 15 : DataGridView7.Columns(6).FillWeight = 3 : DataGridView7.Columns(7).FillWeight = 3 DataGridView7.Columns(8).FillWeight = 3 : DataGridView7.Columns(9).FillWeight = 28 : DataGridView7.Columns(10).FillWeight = 3 End Sub Private Sub ComboBox1下拉表單資料載入() conn.Close() ConnOpen() SQL1 = "SELECT 第一階, LEFT(編號, 4) AS 編號 FROM 會計科目 GROUP BY 第一階, LEFT(編號, 4) ORDER BY 編號" CmdSet_For_dr() : ComboBox1.Items.Clear() : ComboBox2.Items.Clear() : ComboBox1.Text = "" : ComboBox2.Text = "" While (dr.Read()) : ComboBox1.Items.Add(dr("第一階")) : ComboBox2.Items.Add(dr("編號")) : End While : conn.Close() End Sub Private Sub ComboBox3下拉表單資料載入() conn.Close() ConnOpen() SQL1 = "SELECT LEFT(編號, 7) AS 編號, 第二階, 層級 FROM 會計科目 WHERE (LEFT(編號, 4) LIKE N'" & ComboBox2.Text & "') AND (層級 LIKE '" & ComboBox5.Text & "') GROUP BY LEFT(編號, 7), 第二階, 層級 ORDER BY 編號" CmdSet_For_dr() : ComboBox3.Items.Clear() : ComboBox4.Items.Clear() : ComboBox3.Text = "" : ComboBox4.Text = "" While (dr.Read()) : ComboBox3.Items.Add(dr("第二階")) : ComboBox4.Items.Add(dr("編號")) : End While : conn.Close() End Sub Private Sub ComboBox6變化() If ComboBox6.Text = "1" Then : ComboBox5.Text = "1" ElseIf ComboBox6.Text = "2" Then : ComboBox5.Text = "2" ElseIf ComboBox6.Text = "3" Then : ComboBox5.Text = "2" End If If CheckBox5.Checked = True Then : Else If ComboBox2.Text = "" Then : Else If ComboBox6.Text = "1" Then TextBox16.Text = "" ElseIf ComboBox6.Text = "2" Then If ComboBox4.Text = "" Then : Else '----------------------自动生成流水号------------------------------------------------------------------------- ConnOpen() SQL1 = "SELECT TOP (1) LEFT(編號, 7) AS 編號 FROM 會計科目 WHERE (LEFT(編號, 4) LIKE '" & ComboBox2.Text & "') AND (層級 LIKE '2') GROUP BY LEFT(編號, 7) ORDER BY 編號 DESC" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("編號").ToString, 2)) : Else : EDR = 0 : End If conn.Close() : EDR += 1 If EDR < 10 Then : ESTR = ComboBox2.Text & "-" & "0" & EDR & "-00" ElseIf EDR > 9 And EDR < 100 Then : ESTR = ComboBox2.Text & "-" & "" & EDR & "-00" End If TextBox16.Text = ESTR End If ElseIf ComboBox6.Text = "3" Then If ComboBox4.Text = "" Then : Else '----------------------自动生成流水号------------------------------------------------------------------------- ConnOpen() SQL1 = "SELECT TOP (1) LEFT(編號, 10) AS 編號 FROM 會計科目 WHERE (LEFT(編號, 7) LIKE '" & ComboBox4.Text & "') AND (層級 LIKE '3') GROUP BY LEFT(編號, 10) ORDER BY 編號 DESC" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("編號").ToString, 2)) : Else : EDR = 0 : End If conn.Close() : EDR += 1 If EDR < 10 Then : ESTR = ComboBox4.Text & "-" & "0" & EDR ElseIf EDR > 9 And EDR < 100 Then : ESTR = ComboBox4.Text & "-" & "" & EDR End If TextBox16.Text = ESTR End If End If End If End If End Sub Private Sub 會計科目管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.MdiParent = GCM_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True TextBox15.Enabled = False : CheckBox5.Checked = True : TextBox16.Enabled = False Set_會計科目() : ComboBox1下拉表單資料載入() End Sub Private Sub DataGridView7_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView7.CellClick Dim SSXX As String If e.RowIndex = -1 Then : Else ComboBox6.Text = DataGridView7(4, e.RowIndex).Value.ToString : SSXX = DataGridView7(1, e.RowIndex).Value.ToString ComboBox3.Text = SSXX If CheckBox5.Checked = True Then TextBox8.Text = DataGridView7(2, e.RowIndex).Value.ToString : TextBox16.Text = DataGridView7(3, e.RowIndex).Value.ToString TextBox17.Text = DataGridView7(5, e.RowIndex).Value.ToString : TextBox18.Text = DataGridView7(9, e.RowIndex).Value.ToString CheckBox1.Checked = DataGridView7(6, e.RowIndex).Value : CheckBox2.Checked = DataGridView7(7, e.RowIndex).Value CheckBox3.Checked = DataGridView7(8, e.RowIndex).Value Else ComboBox6變化() End If ComboBox1.Text = DataGridView7(0, e.RowIndex).Value.ToString End If End Sub Private Sub DataGridView7_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView7.RowPostPaint Dim linePen As New Pen(Color.Blue, 2) If e.RowIndex = DataGridView7.Rows.Count - 1 Then Exit Sub Else If DataGridView7(1, e.RowIndex).Value.ToString <> DataGridView7(1, e.RowIndex + 1).Value.ToString Then Dim startX As Integer = IIf(DataGridView7.RowHeadersVisible, DataGridView7.RowHeadersWidth, 0) Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1 Dim endX As Integer = startX + DataGridView7.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView7.HorizontalScrollingOffset e.Graphics.DrawLine(linePen, startX, startY, endX, startY) Exit Sub End If End If End Sub Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged ComboBox2.SelectedIndex = ComboBox1.SelectedIndex : ComboBox3下拉表單資料載入() End Sub Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.TextChanged ComboBox1.SelectedIndex = ComboBox2.SelectedIndex : Set_會計科目() : ComboBox3下拉表單資料載入() End Sub Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.TextChanged ComboBox4.SelectedIndex = ComboBox3.SelectedIndex End Sub Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.TextChanged ComboBox3.SelectedIndex = ComboBox4.SelectedIndex End Sub Private Sub ComboBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox5.TextChanged ComboBox3下拉表單資料載入() End Sub Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox4.Click CheckBox4.Checked = True : CheckBox5.Checked = False : TextBox16.Enabled = True TextBox8.Text = "" : TextBox17.Text = "" : TextBox18.Text = "" : CheckBox1.Checked = False : CheckBox2.Checked = False : CheckBox3.Checked = False End Sub Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox5.Click CheckBox4.Checked = False : CheckBox5.Checked = True : TextBox16.Enabled = False End Sub Private Sub ComboBox6_TextChanged(sender As Object, e As EventArgs) Handles ComboBox6.TextChanged ComboBox6變化() End Sub Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click If TextBox8.Text = "" Then MsgBox("資料有缺或有誤,請重新檢查") Else conn.Close() : dr.Close() ConnOpen() SQL1 = "UPDATE 會計科目 SET 會計科目 = N'" & TextBox8.Text & "', 層級 = N'" & ComboBox6.Text & "', 英文名稱 = N'" & TextBox17.Text & "', 統制科目 = N'" & CheckBox1.Checked & "', 抵銷科目 = N'" & CheckBox2.Checked & "', 停用 = N'" & CheckBox3.Checked & "', 附註 = N'" & TextBox18.Text & "', 第一階 = N'" & ComboBox1.Text & "', 第二階 = N'" & ComboBox3.Text & "' , 顯示 = N'" & CheckBox6.Checked & "' WHERE 編號 LIKE N'" & TextBox16.Text & "'" cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() MsgBox("修改完成") End If : Set_會計科目() End Sub Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click For i As Integer = 0 To DataGridView7.Rows.Count - 1 資料數 = DataGridView7.Rows.Count : MyMoule.進度條() : ProgressBar1.Value = 最終數 ConnOpen() SQL1 = "UPDATE 會計科目 SET 會計科目 = N'" & DataGridView7.Rows(i).Cells("會計科目").Value & "', 層級 = N'" & DataGridView7.Rows(i).Cells("層級").Value & "', 英文名稱 = N'" & DataGridView7.Rows(i).Cells("英文名稱").Value & "', 統制科目 = N'" & DataGridView7.Rows(i).Cells("統制科目").Value & "', 抵銷科目 = N'" & DataGridView7.Rows(i).Cells("抵銷科目").Value & "', 停用 = N'" & DataGridView7.Rows(i).Cells("停用").Value & "', 附註 = N'" & DataGridView7.Rows(i).Cells("附註").Value & "', 第一階 = N'" & DataGridView7.Rows(i).Cells("第一階").Value & "', 第二階 = N'" & DataGridView7.Rows(i).Cells("第二階").Value & "' , 顯示 = N'" & DataGridView7.Rows(i).Cells("顯示").Value & "' WHERE 編號 LIKE N'" & DataGridView7.Rows(i).Cells("編號").Value & "'" cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() Next : ProgressBar1.Value = 0 : 最終數 = 0 : MsgBox("修改完成") End Sub Private Sub Button21_Click(sender As Object, e As EventArgs) Handles Button21.Click Dim aa As MsgBoxResult aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel) If aa = MsgBoxResult.Ok Then ConnOpen() SQL1 = "DELETE FROM 會計科目 WHERE (編號 = N'" & TextBox16.Text & "')" cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : conn.Close() MsgBox("刪除完成") End If Set_會計科目() End Sub Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click If TextBox8.Text = "" Or ComboBox6.Text = "" Then MsgBox("資料有缺或有誤,請重新檢查") Else ConnOpen() SQL1 = "SELECT 編號 FROM 會計科目 WHERE 編號 LIKE '" & TextBox16.Text & "'" : cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader If dr.Read() Then MsgBox("資料重複,請從新輸入或檢查") : conn.Close() : dr.Close() Else conn.Close() : dr.Close() ConnOpen() If ComboBox6.Text = "1" Then SQL1 = "INSERT INTO 會計科目 (會計科目, 編號, 層級, 英文名稱, 統制科目, 抵銷科目, 停用, 附註, 第一階, 第二階, 顯示) VALUES (N'" & TextBox8.Text & "', N'" & TextBox16.Text & "', N'" & ComboBox6.Text & "', N'" & TextBox17.Text & "', N'" & CheckBox1.Checked & "', N'" & CheckBox2.Checked & "', N'" & CheckBox3.Checked & "', N'" & TextBox18.Text & "', N'" & TextBox8.Text & "', N'" & TextBox8.Text & "', N'" & CheckBox6.Checked & "')" ElseIf ComboBox6.Text = "2" Then SQL1 = "INSERT INTO 會計科目 (會計科目, 編號, 層級, 英文名稱, 統制科目, 抵銷科目, 停用, 附註, 第一階, 第二階, 顯示) VALUES (N'" & TextBox8.Text & "', N'" & TextBox16.Text & "', N'" & ComboBox6.Text & "', N'" & TextBox17.Text & "', N'" & CheckBox1.Checked & "', N'" & CheckBox2.Checked & "', N'" & CheckBox3.Checked & "', N'" & TextBox18.Text & "', N'" & ComboBox1.Text & "', N'" & TextBox8.Text & "', N'" & CheckBox6.Checked & "')" Else SQL1 = "INSERT INTO 會計科目 (會計科目, 編號, 層級, 英文名稱, 統制科目, 抵銷科目, 停用, 附註, 第一階, 第二階, 顯示) VALUES (N'" & TextBox8.Text & "', N'" & TextBox16.Text & "', N'" & ComboBox6.Text & "', N'" & TextBox17.Text & "', N'" & CheckBox1.Checked & "', N'" & CheckBox2.Checked & "', N'" & CheckBox3.Checked & "', N'" & TextBox18.Text & "', N'" & ComboBox1.Text & "', N'" & ComboBox3.Text & "', N'" & CheckBox6.Checked & "')" End If CmdSet_For_dr() MsgBox("新增完成") conn.Close() : dr.Close() End If End If : Set_會計科目() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Set_會計科目() : ComboBox1下拉表單資料載入() End Sub End Class