Public Class Frm_retan_cost Dim colorArray(10) As Color Private Sub Frm_retan_cost_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.MdiParent = FrmMDI : Me.WindowState = 2 : Me.AutoScroll = True SQL_染色領料日期清單() : While dr.Read : 日期清單_lb.Items.Add(dr("year") & "/" & dr("month")) : End While : dr.Close() colorArray(0) = Color.FromName("Aquamarine") : colorArray(1) = Color.FromName("azure") : colorArray(2) = Color.FromName("beige") colorArray(3) = Color.FromName("gainsboro") : colorArray(4) = Color.FromName("LightBlue") : colorArray(5) = Color.FromName("LightSalmon") Panel1.SendToBack() End Sub Private Sub ListBox1_Click(sender As Object, e As EventArgs) Handles 日期清單_lb.Click If 日期清單_lb.SelectedIndex = -1 Then : Else Dim ds1 As New DataSet 領料清單_dgv.DataSource = Nothing : ds1.Clear() 領料清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 領料清單_dgv.ColumnHeadersHeight = 30 : 領料清單_dgv.AllowUserToAddRows = False : 領料清單_dgv.RowTemplate.Height = 20 領料清單_dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect Dim p() As String p = Split(日期清單_lb.Items(日期清單_lb.SelectedIndex).ToString, "/") SQL_染色處方清單(p(0).ToString, p(1).ToString) da.Fill(ds1) : 領料清單_dgv.DataSource = ds1.Tables(0) : conn.Close() 領料清單設定() End If End Sub Private Sub 領料清單設定() 領料清單_dgv.Columns("重量").DefaultCellStyle.Format = "#,##0" 領料清單_dgv.Columns("重量").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 領料清單_dgv.Columns(0).FillWeight = 70 : 領料清單_dgv.Columns(1).FillWeight = 100 : 領料清單_dgv.Columns(2).FillWeight = 250 領料清單_dgv.Columns(3).FillWeight = 130 : 領料清單_dgv.Columns(4).FillWeight = 50 : 領料清單_dgv.Columns(5).FillWeight = 150 領料清單_dgv.ClearSelection() '--------指定顏色-------------------------------------------------------------- If 領料清單_dgv.Rows.Count < 2 Then Exit Sub ' 若資料筆數過少則不執行 Dim pp(領料清單_dgv.Rows.Count - 1) As Integer : Dim c As Integer = 0 : pp(0) = 0 For x = 1 To 領料清單_dgv.Rows.Count - 1 ' 修正範圍,避免 -2 的問題 If Not 領料清單_dgv.Rows(x).Cells(0).Value Is Nothing AndAlso Not 領料清單_dgv.Rows(x - 1).Cells(0).Value Is Nothing AndAlso 領料清單_dgv.Rows(x).Cells(0).Value.ToString <> 領料清單_dgv.Rows(x - 1).Cells(0).Value.ToString Then : c += 1 : pp(c) = x End If Next : c += 1 : pp(c) = 領料清單_dgv.Rows.Count : ReDim Preserve pp(c) ' 確保最後一組範圍正確 If c = 1 Then : For z As Integer = 0 To 領料清單_dgv.Rows.Count - 1 : 領料清單_dgv.Rows(z).DefaultCellStyle.BackColor = colorArray(1) : Next : Else For cc As Integer = 0 To c - 1 ' 修正範圍 Dim startIdx As Integer = pp(cc) : Dim endIdx As Integer = If(cc + 1 < c, pp(cc + 1) - 1, 領料清單_dgv.Rows.Count - 1) For z As Integer = startIdx To endIdx : 領料清單_dgv.Rows(z).DefaultCellStyle.BackColor = colorArray(cc Mod 5) : Next Next End If End Sub Private Sub 領料清單_dgv_CellMouseUp(sender As Object, e As DataGridViewCellMouseEventArgs) Handles 領料清單_dgv.CellMouseUp Dim ds1 As New DataSet 領料明細_dgv.DataSource = Nothing : ds1.Clear() 領料明細_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 領料明細_dgv.ColumnHeadersHeight = 30 : 領料明細_dgv.AllowUserToAddRows = False : 領料明細_dgv.RowTemplate.Height = 20 領料明細_dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect SQL_染色處方領料清單(領料清單_dgv.Rows(領料清單_dgv.CurrentRow.Index).Cells("流程卡号").Value) da.Fill(ds1) : 領料明細_dgv.DataSource = ds1.Tables(0) : conn.Close() 領料明細_dgv.Columns(0).FillWeight = 70 : 領料明細_dgv.Columns(2).FillWeight = 150 : 領料明細_dgv.Columns(3).FillWeight = 150 領料明細_dgv.Columns(4).FillWeight = 70 : 領料明細_dgv.Columns(5).FillWeight = 70 : 領料明細_dgv.Columns(6).FillWeight = 70 領料明細_dgv.Columns(7).FillWeight = 70 : 領料明細_dgv.Columns(8).FillWeight = 80 領料明細_dgv.Columns(6).DefaultCellStyle.Format = "#,##0" : 領料明細_dgv.Columns(7).DefaultCellStyle.Format = "#,##0" 領料明細_dgv.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 領料明細_dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 領料明細_dgv.ClearSelection() Dim ds2 As New DataSet 合計_dgv.DataSource = Nothing : ds2.Clear() 合計_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 合計_dgv.ColumnHeadersHeight = 30 : 合計_dgv.AllowUserToAddRows = False : 合計_dgv.RowTemplate.Height = 20 合計_dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect SQL_染色處方領料明細(領料清單_dgv.Rows(領料清單_dgv.CurrentRow.Index).Cells("流程卡号").Value) da.Fill(ds2) : 合計_dgv.DataSource = ds2.Tables(0) : conn.Close() Dim dt As DataTable = CType(合計_dgv.DataSource, DataTable) If dt IsNot Nothing Then If Not dt.Columns.Contains("排序") Then : dt.Columns.Add("排序", GetType(String)) : End If For i As Integer = 0 To dt.Rows.Count - 1 If i < 9 Then : dt.Rows(i)("排序") = "0" & (i + 1).ToString() : Else : dt.Rows(i)("排序") = (i + 1).ToString() : End If Next : dt.DefaultView.Sort = "排序 DESC" : 合計_dgv.DataSource = dt End If 合計_dgv.Columns(1).DefaultCellStyle.Format = "#,##0" : 合計_dgv.Columns(2).DefaultCellStyle.Format = "#,##0" 合計_dgv.Columns(3).DefaultCellStyle.Format = "#,##0.0" : 合計_dgv.Columns(4).DefaultCellStyle.Format = "#,##0" 合計_dgv.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 合計_dgv.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 合計_dgv.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 合計_dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 合計_dgv.Columns("排序").Visible = False : 合計_dgv.ClearSelection() Dim 位置 As Integer = 合計_dgv.Rows.Count - 1 合計_dgv.Rows(位置).Cells(0).Style.ForeColor = Color.Red : 合計_dgv.Rows(位置).Cells(1).Style.ForeColor = Color.Red 合計_dgv.Rows(位置).Cells(2).Style.ForeColor = Color.Red : 合計_dgv.Rows(位置).Cells(3).Style.ForeColor = Color.Red 合計_dgv.Rows(位置).Cells(4).Style.ForeColor = Color.Red End Sub Private Sub 領料明細_dgv_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles 領料明細_dgv.RowPostPaint If (Microsoft.VisualBasic.Trim(領料明細_dgv.Rows(e.RowIndex).Cells("zdhc代码").Value.ToString) = "" Or 領料明細_dgv.Rows(e.RowIndex).Cells("zdhc代码").Value.ToString = "无") And 領料明細_dgv.Rows(e.RowIndex).Cells("类型").Value.ToString <> "基础材料" Then 領料明細_dgv.Rows(e.RowIndex).Cells("化工名称").Style.BackColor = Color.LightBlue 領料明細_dgv.Rows(e.RowIndex).Visible = False End If Dim linePen As New Pen(Color.Blue, 2) If e.RowIndex = 領料明細_dgv.Rows.Count - 1 Then : Exit Sub : Else If 領料明細_dgv("类型", e.RowIndex).Value.ToString <> 領料明細_dgv("类型", e.RowIndex + 1).Value.ToString Then Dim startX As Integer = IIf(領料明細_dgv.RowHeadersVisible, 領料明細_dgv.RowHeadersWidth, 0) : Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1 Dim endX As Integer = startX + 領料明細_dgv.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - 領料明細_dgv.HorizontalScrollingOffset e.Graphics.DrawLine(linePen, startX, startY, endX, startY) : Exit Sub End If End If End Sub Private Sub 流程卡查询_bt_Click(sender As Object, e As EventArgs) Handles 流程卡查询_bt.Click 查詢_tb.Text = InputBox("请输入要查询的客户简称或是关键字!!") : Dim 條件 As String 條件 = "no like '%" & 查詢_tb.Text & "%'" Dim ds1 As New DataSet : 領料清單_dgv.DataSource = Nothing : ds1.Clear() 領料清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 領料清單_dgv.ColumnHeadersHeight = 30 : 領料清單_dgv.AllowUserToAddRows = False : 領料清單_dgv.RowTemplate.Height = 20 領料清單_dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect SQL_染色處方清單1(條件) da.Fill(ds1) : 領料清單_dgv.DataSource = ds1.Tables(0) : conn.Close() 領料清單設定() End Sub Private Sub 客户查询_bt_Click(sender As Object, e As EventArgs) Handles 客户查询_bt.Click 查詢_tb.Text = InputBox("请输入要查询的客户简称或是关键字!!") : Dim 條件 As String If 查詢_tb.Text = "HD" Then 條件 = "(no LIKE '%20240224035%') OR (no LIKE '%20240508135%') OR (no LIKE '%20240703035%') OR (no LIKE '%20240725055%') OR (no LIKE '%20240731065%') OR (no LIKE '%20241006235%') OR (no LIKE '%20241010185%') OR (no LIKE '%20241010195%') OR (no LIKE '%20241012115%') OR (no LIKE '%20241024015%') OR (no LIKE '%20241024025%') OR (no LIKE '%20241024045%') OR (no LIKE '%20241024055%') OR (no LIKE '%20241024065%') OR (no LIKE '%20241029105%') OR (no LIKE '%20241030035%') OR (no LIKE '%202411001085%') OR (no LIKE '%20241107015%') OR (no LIKE '%20241107025%') OR (no LIKE '%20241107035%') OR (no LIKE '%20241113055%') OR (no LIKE '%20241113065%') OR (no LIKE '%20241113117%') OR (no LIKE '%20241118025%') OR (no LIKE '%20241119075%') OR (no LIKE '%20241119085%') OR (no LIKE '%20241125035%') OR (no LIKE '%20241210117%') OR (no LIKE '%20241217117%') OR (no LIKE '%20241217127%') OR (no LIKE '%WGSTR20241107%')" Else : 條件 = "name LIKE N'%" & 查詢_tb.Text & "%'" : End If Dim ds1 As New DataSet : 領料清單_dgv.DataSource = Nothing : ds1.Clear() 領料清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 領料清單_dgv.ColumnHeadersHeight = 30 : 領料清單_dgv.AllowUserToAddRows = False : 領料清單_dgv.RowTemplate.Height = 20 領料清單_dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect SQL_染色處方清單1(條件) da.Fill(ds1) : 領料清單_dgv.DataSource = ds1.Tables(0) : conn.Close() 領料清單設定() End Sub End Class