Option Strict Off
Imports System.Data.SqlClient
Public Class 樣品進度表FOR_METOO_PAG導入
    Dim conn As New SqlConnection
    Dim da As New SqlDataAdapter
    Dim cmd As New SqlCommand
    Dim ds As New DataSet : Dim ds1 As New DataSet : Dim ds2 As New DataSet : Dim ds4 As New DataSet : Dim ds5 As New DataSet : Dim ds6 As New DataSet
    Dim dr As SqlDataReader
    Dim N1 As Integer = 0
    Private Sub Set_清單()
        DataGridView1.DataSource = Nothing : ds.Clear()
        DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        DataGridView1.ColumnHeadersHeight = 25
        DataGridView1.AllowUserToAddRows = False
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 流水號 AS 序號, 流水號, 季節, 客戶, S_N AS Style, C_N, COLOR_NO AS Col_No, COLOR, LOTS, 檔案名稱
                FROM 樣品進度控制表METOO專用 WHERE 季節 LIKE N'" & ComboBox7.Text & "' AND 客戶 LIKE N'" & ComboBox2.Text & "' ORDER BY S_N, COLOR_NO"
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid()
    End Sub
    Private Sub Set_grid()
        DataGridView1.Columns(0).Width = 40 : DataGridView1.Columns(1).Visible = False : DataGridView1.Columns(2).Visible = False : DataGridView1.Columns(3).Visible = False
        DataGridView1.Columns(4).Width = 150 : DataGridView1.Columns(5).Width = 80 : DataGridView1.Columns(6).Width = 70 : DataGridView1.Columns(7).Width = 320
        DataGridView1.Columns(8).Width = 320
        DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter
        N1 = 1
        For i As Integer = 0 To DataGridView1.Rows.Count - 1
            If i = DataGridView1.Rows.Count - 1 Then
                DataGridView1.Rows(i).Cells("序號").Value = N1.ToString
                Exit For
            Else
                If DataGridView1(4, i).Value.ToString <> DataGridView1(4, i + 1).Value.ToString Then
                    DataGridView1.Rows(i).Cells("序號").Value = N1.ToString
                    N1 = N1 + 1
                Else
                    DataGridView1.Rows(i).Cells("序號").Value = N1.ToString
                End If
            End If
        Next
    End Sub
    Private Sub ComboBox7下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT SEASON FROM 季節清單 ORDER BY SEASON"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox7.Items.Clear() : While (dr.Read()) : ComboBox7.Items.Add(dr("SEASON")) : End While : conn.Close()
    End Sub
    Private Sub ComboBox2下拉表單資料載入()
        conn.Close()
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        SQL1 = "SELECT 客戶簡稱 FROM 客戶控制表 ORDER BY 客戶簡稱"
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
        ComboBox2.Items.Clear() : While (dr.Read()) : ComboBox2.Items.Add(dr("客戶簡稱")) : End While : conn.Close()
    End Sub
    Private Sub 樣品進度表FOR_METOO_PAG導入_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        ComboBox7下拉表單資料載入() : ComboBox2下拉表單資料載入()
    End Sub
    Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
        Dim linePen As New Pen(Color.Blue, 2)
        If e.RowIndex = DataGridView1.Rows.Count - 1 Then
            Exit Sub
        Else
            If DataGridView1(4, e.RowIndex).Value.ToString <> DataGridView1(4, e.RowIndex + 1).Value.ToString Then
                Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
                Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
                Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset
                e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
                Exit Sub
            End If
        End If
    End Sub
    Private Sub ComboBox7_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox7.SelectedIndexChanged
        If ComboBox7.Text = "" Or ComboBox2.Text = "" Then : Else : Set_清單() : End If
    End Sub
    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
        If ComboBox7.Text = "" Or ComboBox2.Text = "" Then : Else : Set_清單() : End If
    End Sub
End Class