Option Strict Off Imports System.Data.SqlClient Imports System.IO Public Class 營運成本收支單審核 ReadOnly conn As New SqlConnection ReadOnly da As New SqlDataAdapter ReadOnly cmd As New SqlCommand ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet Dim dr As SqlDataReader Private ReadOnly QQW(11) As String Dim DTP As String : Dim WWEE As String : Private II As Integer Private Sub Set_清單1() DataGridView2.DataSource = Nothing : ds1.Clear() DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView2.ColumnHeadersHeight = 25 DataGridView2.AllowUserToAddRows = False If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If If RadioButton1.Checked = True And RadioButton2.Checked = False Then WWEE = "WHERE (審核人 LIKE '') " ElseIf RadioButton1.Checked = False And RadioButton2.Checked = True Then WWEE = "WHERE (審核人 LIKE '作廢%') " End If SQL1 = "SELECT 支付單號 AS 收支單號, 申請日期, 審核日期, 申請人 FROM 公帳控制表 " & WWEE & " ORDER BY 支付單號 DESC" cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close() DataGridView2.Columns(0).FillWeight = 160 : DataGridView2.Columns(1).FillWeight = 100 : DataGridView2.Columns(2).FillWeight = 100 : DataGridView2.Columns(3).Visible = False End Sub Private Sub Set_費用清單() DataGridView1.DataSource = Nothing : ds.Clear() DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView1.ColumnHeadersHeight = 25 DataGridView1.AllowUserToAddRows = False DataGridView1.RowTemplate.Height = 35 If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 公帳流水帳.支付單號, 公帳流水帳.項次, 會計科目.會計科目, 公帳流水帳.明細 AS 用途, Cast(公帳流水帳.零用金 AS money) AS 零用金, Cast(公帳流水帳.支票數 AS money) AS 支票, Cast(公帳流水帳.收入 AS money) AS 現金, Cast(公帳流水帳.支出 AS money) AS 支出, 公帳流水帳.備註 AS 票期, 公帳流水帳.匯率, 公帳流水帳.銀行 AS 幣別, 公帳流水帳.類別, 公帳流水帳.流水號 FROM 公帳流水帳 INNER JOIN 會計科目 ON 公帳流水帳.類別 = 會計科目.編號 WHERE (公帳流水帳.支付單號 LIKE '" & TextBox1.Text & "') ORDER BY 公帳流水帳.項次" cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).FillWeight = 80 : DataGridView1.Columns(2).FillWeight = 300 : DataGridView1.Columns(3).FillWeight = 500 DataGridView1.Columns(4).FillWeight = 140 : DataGridView1.Columns(5).FillWeight = 140 : DataGridView1.Columns(6).FillWeight = 140 : DataGridView1.Columns(7).FillWeight = 140 DataGridView1.Columns(8).FillWeight = 140 : DataGridView1.Columns(9).FillWeight = 140 : DataGridView1.Columns(10).FillWeight = 140 : DataGridView1.Columns(11).Visible = False DataGridView1.Columns(12).Visible = False DataGridView1.Columns(1).ReadOnly = True : DataGridView1.Columns(2).ReadOnly = True : DataGridView1.Columns(9).ReadOnly = True : DataGridView1.Columns(10).ReadOnly = True DataGridView1.Columns(4).DefaultCellStyle.Format = "#,##0.00" : DataGridView1.Columns(5).DefaultCellStyle.Format = "#,##0.00" : DataGridView1.Columns(6).DefaultCellStyle.Format = "#,##0.00" DataGridView1.Columns(7).DefaultCellStyle.Format = "#,##0.00" : DataGridView1.Columns(8).DefaultCellStyle.Format = "#,##0.00" DataGridView1.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView1.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView1.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView1.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight DataGridView1.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView1.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView1.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter TextBox5.Text = "0" : TextBox2.Text = "0" : TextBox6.Text = "0" : TextBox7.Text = "0" : TextBox8.Text = "0" For i As Integer = 0 To DataGridView1.Rows.Count - 1 TextBox5.Text = Val(TextBox5.Text) + DataGridView1.Rows(i).Cells("現金").Value : TextBox2.Text = Val(TextBox2.Text) + DataGridView1.Rows(i).Cells("支出").Value TextBox7.Text = Val(TextBox7.Text) + DataGridView1.Rows(i).Cells("零用金").Value : TextBox8.Text = Val(TextBox8.Text) + DataGridView1.Rows(i).Cells("支票").Value Next i TextBox6.Text = Val(TextBox7.Text) + Val(TextBox5.Text) - Val(TextBox2.Text) If Val(TextBox6.Text) > 0 Then : TextBox6.ForeColor = Color.Blue : Else : TextBox6.ForeColor = Color.Red : End If TextBox5.Text = Format(Val(TextBox5.Text), "#,##0.00") : TextBox2.Text = Format(Val(TextBox2.Text), "#,##0.00") : TextBox6.Text = Format(Val(TextBox6.Text), "#,##0.00") TextBox7.Text = Format(Val(TextBox7.Text), "#,##0.00") : TextBox8.Text = Format(Val(TextBox8.Text), "#,##0.00") End Sub Private Sub Set_清單() DataGridView3.DataSource = Nothing : ds2.Clear() DataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView3.ColumnHeadersHeight = 25 DataGridView3.AllowUserToAddRows = False If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 圖片流水號 AS 圖檔編碼, 簽名檔人名 FROM GCM主管簽名檔管理 ORDER BY 圖片流水號 DESC" cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds2) : DataGridView3.DataSource = ds2.Tables(0) : conn.Close() DataGridView3.Columns(0).FillWeight = 173 : DataGridView3.Columns(1).Visible = False If DataGridView3.Rows.Count = 0 Then : Else TextBox14.Text = DataGridView3(0, 0).Value.ToString If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 簽名檔圖片 FROM GCM主管簽名檔管理 WHERE 圖片流水號 LIKE '" & TextBox14.Text & "'" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader While dr.Read() = True Dim unused As Byte() = New Byte(-1) {} Dim bytes As Byte() = DirectCast(dr.Item("簽名檔圖片"), Byte()) Dim oStream As New MemoryStream(bytes) PictureBox1.Image = Bitmap.FromStream(oStream) End While conn.Close() PictureBox1.SizeMode = 4 For QAZ = 0 To 999 QQW(0) = Strings.Right(DataGridView3(0, 0).Value.ToString, 2) : QQW(1) = Strings.Right(Year(Today), 2) : QQW(2) = Strings.Left(Year(Today), 2) : QQW(3) = Month(Today) + 9 QQW(4) = Strings.Right(QQW(0), 1) : QQW(5) = Strings.Left(QQW(0), 1) : QQW(6) = Strings.Right(QQW(1), 1) : QQW(7) = Strings.Left(QQW(1), 1) : QQW(8) = Strings.Right(QQW(2), 1) QQW(9) = Strings.Left(QQW(2), 1) : QQW(10) = Strings.Right(QQW(3), 1) : QQW(11) = Strings.Left(QQW(3), 1) For RT = 4 To 11 Delay(3) Dim ran = New Random(DateTime.Now.Millisecond) : Dim NUM1 As Integer = ran.Next(1, 4096) For I = 0 To 4096 : If NUM1 > 9 Then : NUM1 -= 9 : ElseIf NUM1 < 9 Then : I = 4096 : End If : Next If NUM1 = 1 Then : II = RT : 轉換() : ElseIf NUM1 = 2 Then : II = RT : 轉換() : ElseIf NUM1 = 3 Then : ElseIf NUM1 = 4 Then : II = RT : 轉換() : ElseIf NUM1 = 5 Then ElseIf NUM1 = 6 Then : II = RT : 轉換() : ElseIf NUM1 = 7 Then : ElseIf NUM1 = 8 Then : II = RT : 轉換() : ElseIf NUM1 = 9 Then : II = RT : 轉換() : End If Next Dim ran1 = New Random(DateTime.Now.Millisecond) : Dim NUM2 As Integer = ran1.Next(1, 4096) For I = 0 To 4096 : If NUM2 > 99 Then : NUM2 -= 49 : ElseIf NUM2 < 99 Then : I = 4096 : End If : Next TextBox13.Text = QQW(11) & "2" & QQW(9) & "7" & QQW(7) & "0" & QQW(5) & QQW(4) & "1" & QQW(6) & "3" & QQW(8) & "9" & QQW(10) & NUM2 If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 簽名編碼 FROM 公帳控制表 WHERE 簽名編碼 LIKE '" & TextBox13.Text & "'" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader If dr.Read() = True Then : Else : QAZ = 999 : End If : conn.Close() Next End If End Sub Private Sub 轉換() If QQW(II) = "1" Then : QQW(II) = "A" : ElseIf QQW(II) = "2" Then : QQW(II) = "B" : ElseIf QQW(II) = "3" Then : QQW(II) = "C" : ElseIf QQW(II) = "4" Then : QQW(II) = "D" ElseIf QQW(II) = "5" Then : QQW(II) = "E" : ElseIf QQW(II) = "6" Then : QQW(II) = "F" : ElseIf QQW(II) = "7" Then : QQW(II) = "G" : ElseIf QQW(II) = "8" Then : QQW(II) = "H" ElseIf QQW(II) = "9" Then : QQW(II) = "I" : ElseIf QQW(II) = "0" Then : QQW(II) = "J" End If End Sub Public Sub Delay(ByRef Interval As Double) 'Interval单位为毫秒 Dim time As DateTime = DateTime.Now : Dim Span As Double = Interval * 1234 : While ((DateTime.Now.Ticks - time.Ticks) < Span) : Application.DoEvents() : End While 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 RadioButton1.Checked = True : DataGridView2.Visible = True Set_清單1() : Set_清單() End Sub Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellClick If e.RowIndex = -1 Then : Else TextBox1.Text = DataGridView2(0, e.RowIndex).Value.ToString : DateTimePicker1.Value = DataGridView2(1, e.RowIndex).Value.ToString : Set_費用清單() TextBox3.Text = DataGridView2(3, e.RowIndex).Value.ToString End If End Sub Private Sub DataGridView3_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView3.CellClick If e.RowIndex = -1 Then : Else TextBox14.Text = DataGridView3(0, e.RowIndex).Value.ToString If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 簽名檔圖片 FROM GCM主管簽名檔管理 WHERE 圖片流水號 LIKE '" & TextBox14.Text & "'" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader While dr.Read() = True Dim unused As Byte() = New Byte(-1) {} Dim bytes As Byte() = DirectCast(dr.Item("簽名檔圖片"), Byte()) Dim oStream As New MemoryStream(bytes) PictureBox1.Image = Bitmap.FromStream(oStream) End While conn.Close() PictureBox1.SizeMode = 4 For QAZ = 0 To 999 QQW(0) = Strings.Right(DataGridView3(0, e.RowIndex).Value.ToString, 2) : QQW(1) = Strings.Right(Year(Today), 2) : QQW(2) = Strings.Left(Year(Today), 2) : QQW(3) = Month(Today) + 9 QQW(4) = Strings.Right(QQW(0), 1) : QQW(5) = Strings.Left(QQW(0), 1) : QQW(6) = Strings.Right(QQW(1), 1) : QQW(7) = Strings.Left(QQW(1), 1) : QQW(8) = Strings.Right(QQW(2), 1) QQW(9) = Strings.Left(QQW(2), 1) : QQW(10) = Strings.Right(QQW(3), 1) : QQW(11) = Strings.Left(QQW(3), 1) For RT = 4 To 11 Delay(3) Dim ran = New Random(DateTime.Now.Millisecond) : Dim NUM1 As Integer = ran.Next(1, 4096) For I = 0 To 4096 : If NUM1 > 9 Then : NUM1 -= 9 : ElseIf NUM1 < 9 Then : I = 4096 : End If : Next If NUM1 = 1 Then : II = RT : 轉換() : ElseIf NUM1 = 2 Then : II = RT : 轉換() : ElseIf NUM1 = 3 Then : ElseIf NUM1 = 4 Then : II = RT : 轉換() : ElseIf NUM1 = 5 Then ElseIf NUM1 = 6 Then : II = RT : 轉換() : ElseIf NUM1 = 7 Then : ElseIf NUM1 = 8 Then : II = RT : 轉換() : ElseIf NUM1 = 9 Then : II = RT : 轉換() : End If Next Dim ran1 = New Random(DateTime.Now.Millisecond) : Dim NUM2 As Integer = ran1.Next(1, 4096) For I = 0 To 4096 : If NUM2 > 99 Then : NUM2 -= 49 : ElseIf NUM2 < 99 Then : I = 4096 : End If : Next TextBox13.Text = QQW(11) & "2" & QQW(9) & "7" & QQW(7) & "0" & QQW(5) & QQW(4) & "1" & QQW(6) & "3" & QQW(8) & "9" & QQW(10) & NUM2 If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "SELECT 簽名編碼 FROM 公帳控制表 WHERE 簽名編碼 LIKE '" & TextBox13.Text & "'" cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader If dr.Read() = True Then : Else : QAZ = 999 : End If : conn.Close() Next End If End Sub Private Sub Set_切換格式() DataGridView1.DataSource = Nothing : ds.Clear() : TextBox1.Text = "" : TextBox3.Text = "" : TextBox5.Text = "" : TextBox2.Text = "" : TextBox6.Text = "" TextBox7.Text = "" : TextBox8.Text = "" : Set_清單1() End Sub Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.Click RadioButton1.Checked = True : RadioButton2.Checked = False DataGridView1.DataSource = Nothing : ds.Clear() : TextBox1.Text = "" : TextBox3.Text = "" : TextBox5.Text = "" : TextBox2.Text = "" : TextBox6.Text = "" Button1.Enabled = True : Button2.Enabled = True : 審核通過ToolStripMenuItem.Enabled = True : 單據作廢ToolStripMenuItem.Enabled = True : Set_切換格式() End Sub Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.Click RadioButton1.Checked = False : RadioButton2.Checked = True DataGridView1.DataSource = Nothing : ds.Clear() : TextBox1.Text = "" : TextBox3.Text = "" : TextBox5.Text = "" : TextBox2.Text = "" : TextBox6.Text = "" Button1.Enabled = False : Button2.Enabled = False : 審核通過ToolStripMenuItem.Enabled = False : 單據作廢ToolStripMenuItem.Enabled = False : Set_切換格式() End Sub Private Sub Set_日期格式轉換() DTP = Format(Today(), "yyyy/MM/dd") End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If TextBox1.Text = "" Then MsgBox("請選擇需要審核的單據。") Else If CheckBox1.Checked = False Then Set_日期格式轉換() Else DTP = Format(DateTimePicker1.Value, "yyyy/MM/dd") End If conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 公帳控制表 SET 審核人 = N'" & gUserName & "', 審核日期 = N'" & DTP & "', 核准圖檔 = N'" & TextBox14.Text & "', 簽名編碼 = N'" & TextBox13.Text & "', 出納 = '" & gUserName & "', 出納日期 = N'" & DTP & "' WHERE (支付單號 = N'" & TextBox1.Text & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 公帳流水帳 SET 出納 = '1', 出納日期 = N'" & DTP & "' WHERE (支付單號 LIKE '" & TextBox1.Text & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() For i As Integer = 0 To DataGridView1.Rows.Count - 1 If DataGridView1.Rows(i).Cells("零用金").Value <> 0 Then If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 公帳流水帳 SET 備用金 = N'1' WHERE (支付單號 LIKE '" & TextBox1.Text & "' AND 項次 LIKE '" & DataGridView1.Rows(i).Cells("項次").Value & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() ElseIf DataGridView1.Rows(i).Cells("現金").Value <> 0 Then If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 公帳流水帳 SET 現金 = N'1' WHERE (支付單號 LIKE '" & TextBox1.Text & "' AND 項次 LIKE '" & DataGridView1.Rows(i).Cells("項次").Value & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() ElseIf DataGridView1.Rows(i).Cells("支出").Value <> 0 Then If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 公帳流水帳 SET 公帳 = N'1' WHERE (支付單號 LIKE '" & TextBox1.Text & "' AND 項次 LIKE '" & DataGridView1.Rows(i).Cells("項次").Value & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close() End If Next MsgBox("審核完畢。") TextBox1.Text = "" : TextBox3.Text = "" DataGridView1.DataSource = Nothing : ds.Clear() Set_清單1() : Set_清單() End If End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If TextBox1.Text = "" Then MsgBox("請選擇需要審核的單據。") Else PA = InputBox("請輸入作廢原因。") If PA = "" Then MsgBox("請輸入作廢原因,不可空白。") Else If CheckBox1.Checked = False Then Set_日期格式轉換() Else DTP = Format(DateTimePicker1.Value, "yyyy/MM/dd") End If conn.Close() If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If SQL1 = "UPDATE 公帳控制表 SET 審核人 = N'作廢-" & gUserName & "', 審核日期 = N'" & DTP & "', 備註 = N'" & PA & "' WHERE (支付單號 = N'" & TextBox1.Text & "')" cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() conn.Close() MsgBox("審核完畢。") : PA = "" TextBox1.Text = "" : TextBox3.Text = "" DataGridView1.DataSource = Nothing : ds.Clear() Set_清單1() End If End If End Sub '----------------------滑鼠右鍵-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Private Sub 重新讀取ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 重新讀取ToolStripMenuItem.Click Set_清單1() End Sub Private Sub 審核通過ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 審核通過ToolStripMenuItem.Click Me.Button1.PerformClick() End Sub Private Sub 單據作廢ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 單據作廢ToolStripMenuItem.Click Me.Button2.PerformClick() End Sub End Class