Option Strict Off Imports System.Data.SqlClient Public Class 出庫紀錄表 Dim conn1 As New SqlConnection Dim cmd1 As New SqlCommand Dim dr1 As SqlDataReader Dim da As New SqlDataAdapter Dim ds As New DataSet : Dim ds1 As New DataSet Private Sub DGV2讀取前設定() DataGridView2.DataSource = Nothing : ds1.Clear() DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing DataGridView2.ColumnHeadersHeight = 25 DataGridView2.AllowUserToAddRows = False If conn1.State = ConnectionState.Closed Then : conn1.ConnectionString = ConString : conn1.Open() : End If End Sub Private Sub DGV2讀取後設定() cmd1.Connection = conn1 : cmd1.CommandText = SQL1 : da.SelectCommand = cmd1 : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn1.Close() End Sub Private Sub 讀取出庫紀錄表() If PA = "" Then DGV2讀取前設定() SQL1 = "SELECT 零件出庫紀錄.零件編號, 零件出庫紀錄.結單日期, 零件出庫紀錄.出貨數量, 零件成本紀錄表.品名, 零件成本紀錄表.型號及備註, 零件出庫紀錄.進貨成本, " & "零件出庫紀錄.出貨金額, 零件出庫紀錄.利潤, 零件出庫紀錄.台幣利潤 FROM 零件出庫紀錄 INNER JOIN 零件成本紀錄表 ON 零件出庫紀錄.零件編號 = 零件成本紀錄表.流水碼 " & "ORDER BY 零件出庫紀錄.結單日期 DESC" 列印用SQL = SQL1 : DGV2讀取後設定() : Set_自動彙總1() Else DGV2讀取前設定() SQL1 = "SELECT 零件出庫紀錄.零件編號, 零件出庫紀錄.結單日期, 零件出庫紀錄.出貨數量, 零件成本紀錄表.品名, 零件成本紀錄表.型號及備註, 零件出庫紀錄.進貨成本, " & "零件出庫紀錄.出貨金額, 零件出庫紀錄.利潤, 零件出庫紀錄.台幣利潤 FROM 零件出庫紀錄 INNER JOIN 零件成本紀錄表 ON 零件出庫紀錄.零件編號 = 零件成本紀錄表.流水碼 " & "WHERE (零件出庫紀錄.零件編號 LIKE '%" & PA & "%') OR (零件出庫紀錄.結單日期 LIKE '%" & PA & "%') OR (零件出庫紀錄.出貨數量 LIKE '%" & PA & "%') OR " & "(零件成本紀錄表.品名 LIKE '%" & PA & "%') OR (零件成本紀錄表.型號及備註 LIKE '%" & PA & "%')ORDER BY 零件出庫紀錄.結單日期 DESC" 列印用SQL = SQL1 : DGV2讀取後設定() : Set_自動彙總1() End If End Sub Private Sub Set_自動彙總1() Dim 數量加總 As Double = 0 : Dim 金額加總1 As Double = 0 : Dim 金額加總2 As Double = 0 : Dim 金額加總3 As Double = 0 : Dim 金額加總4 As Double = 0 For i As Integer = 0 To DataGridView2.Rows.Count - 1 If DataGridView2.RowCount = 0 Then : TextBox13.Text = "0" : Else : 數量加總 += DataGridView2.Rows(i).Cells("出貨數量").Value : End If Next i For i As Integer = 0 To DataGridView2.Rows.Count - 1 If DataGridView2.RowCount = 0 Then : TextBox16.Text = "0.00" : Else : 金額加總1 += DataGridView2.Rows(i).Cells("進貨成本").Value : End If Next i For i As Integer = 0 To DataGridView2.Rows.Count - 1 If DataGridView2.RowCount = 0 Then : TextBox1.Text = "0.00" : Else : 金額加總2 += DataGridView2.Rows(i).Cells("出貨金額").Value : End If Next i For i As Integer = 0 To DataGridView2.Rows.Count - 1 If DataGridView2.RowCount = 0 Then : TextBox17.Text = "0.00" : Else : 金額加總3 += DataGridView2.Rows(i).Cells("利潤").Value : End If Next i For i As Integer = 0 To DataGridView2.Rows.Count - 1 If DataGridView2.RowCount = 0 Then : TextBox2.Text = "0.00" : Else : 金額加總4 += DataGridView2.Rows(i).Cells("台幣利潤").Value : End If Next i TextBox13.Text = Format(Val(數量加總), "#,##0") TextBox16.Text = Format(Val(金額加總1), "#,##0.00") TextBox1.Text = Format(Val(金額加總2), "#,##0.00") TextBox17.Text = Format(Val(金額加總3), "#,##0.00") TextBox2.Text = Format(Val(金額加總4), "#,##0.00") If 金額加總3 = 0 Then TextBox3.Text = "0.00%" Else TextBox3.Text = Format(Val(金額加總2 / 金額加總3), "#,##0.00") & "%" End If End Sub Private Sub Set_grid2() DataGridView2.Columns(0).Width = 70 : DataGridView2.Columns(1).Width = 70 : DataGridView2.Columns(2).Width = 70 : DataGridView2.Columns(3).Width = 150 DataGridView2.Columns(4).Width = 150 : DataGridView2.Columns(5).Width = 70 : DataGridView2.Columns(6).Width = 70 : DataGridView2.Columns(7).Width = 70 DataGridView2.Columns(8).Width = 70 DataGridView2.Columns(2).DefaultCellStyle.Format = "#,##0" : DataGridView2.Columns(5).DefaultCellStyle.Format = "#,##0.00" DataGridView2.Columns(6).DefaultCellStyle.Format = "#,##0.00" : DataGridView2.Columns(7).DefaultCellStyle.Format = "#,##0.00" DataGridView2.Columns(8).DefaultCellStyle.Format = "#,##0.00" End Sub Private Sub 出庫紀錄表_Load(sender As Object, e As EventArgs) Handles MyBase.Load FormBorderStyle = FormBorderStyle.SizableToolWindow 讀取出庫紀錄表() : Set_grid2() End Sub Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove timeNow = 0 GCM_ERP_SYS.Timer1.Enabled = False GCM_ERP_SYS.Timer1.Enabled = True End Sub Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress timeNow = 0 GCM_ERP_SYS.Timer1.Enabled = False GCM_ERP_SYS.Timer1.Enabled = True End Sub Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click PA = InputBox("請輸入要查詢零件的資料") 讀取出庫紀錄表() : Set_grid2() PA = "" End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 列印(1) = True 列印清單.Show() End Sub End Class