Option Strict Off
Imports System.Data.SqlClient
Public Class CXL訂單紀錄表
    ReadOnly conn As New SqlConnection
    ReadOnly da As New SqlDataAdapter
    ReadOnly cmd As New SqlCommand
    ReadOnly ds As New DataSet
    Private Sub Set_DGV3載入前設定()
        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
    End Sub
    Private Sub Set_DGV3載入後設定()
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close() : Set_grid4()
    End Sub
    Private Sub Set_清單3()
        Set_DGV3載入前設定()
        If PA = "" Then
            SQL1 = "SELECT TOP(500) 訂單流水號, 年份季度, 客戶訂單號, 型體號碼, GOODBOX AS 型體名稱, APMA確認 AS 顏色, TVW AS 楦型, 訂單數量, 客戶交期 AS 交期開始, 客戶交期1 AS 交期結束, 單價, 總金額, 備註, 生產工廠, 
                       訂單種類, BUYER, CFMSPEC AS 訂單種類, CFMSAMPLE, TRIAL1, TRIAL2, TRIAL3, TRIAL4, 包裝確認時間, 貼標時間, 裁斷時間, 針車時間, 成型時間, 驗貨時間, 實際離廠日, 資料流水號, 明細建檔, LEATHER, LEA_Note, 
                       CXL, CXLTime, 出貨數量, PO_S_Date, Requested_XF, Confirm_XF, Revised_XF, Special_Packaging, Remarks, 出貨地, 楦頭號, 材質, 長期試穿, 面料, 副料, 中底, 鞋墊, 大底, 跟, 工廠進度表備註1, 
                       七號模具, 工廠進度表備註2, 國標測試, 客戶包裝確認, 東莞業務備註, 驗貨報告圖片
                    FROM 訂單控制表  
                    WHERE  CXL = '1'
                    ORDER BY 訂單流水號, 型體號碼, APMA確認, TVW"
        Else
            SQL1 = "SELECT 訂單流水號, 年份季度, 客戶訂單號, 型體號碼, GOODBOX AS 型體名稱, APMA確認 AS 顏色, TVW AS 楦型, 訂單數量, 客戶交期 AS 交期開始, 客戶交期1 AS 交期結束, 單價, 總金額, 備註, 生產工廠, 
                       訂單種類, BUYER, CFMSPEC AS 訂單種類, CFMSAMPLE, TRIAL1, TRIAL2, TRIAL3, TRIAL4, 包裝確認時間, 貼標時間, 裁斷時間, 針車時間, 成型時間, 驗貨時間, 實際離廠日, 資料流水號, 明細建檔, LEATHER, LEA_Note, 
                       CXL, CXLTime, 出貨數量, PO_S_Date, Requested_XF, Confirm_XF, Revised_XF, Special_Packaging, Remarks, 出貨地, 楦頭號, 材質, 長期試穿, 面料, 副料, 中底, 鞋墊, 大底, 跟, 工廠進度表備註1, 
                       七號模具, 工廠進度表備註2, 國標測試, 客戶包裝確認, 東莞業務備註, 驗貨報告圖片
                    FROM 訂單控制表
                    WHERE (CXL = '1') AND 
                         (訂單流水號 LIKE N'" & PA & "' OR 年份季度 LIKE N'" & PA & "' OR 客戶訂單號 LIKE N'" & PA & "' OR 型體號碼 LIKE N'" & PA & "' OR GOODBOX LIKE N'" & PA & "' OR APMA確認 LIKE N'" & PA &
                       "' OR TVW LIKE N'" & PA & "' OR 訂單數量 LIKE N'" & PA & "' OR 客戶交期 LIKE N'" & PA & "' OR 客戶交期1 LIKE N'" & PA & "' OR 備註 LIKE N'" & PA & "' OR 生產工廠 LIKE N'" & PA &
                       "' OR 訂單種類 LIKE N'" & PA & "' OR BUYER LIKE N'" & PA & "' OR CFMSPEC LIKE N'" & PA & "')
                    ORDER BY 訂單流水號, 型體號碼, APMA確認, TVW"
        End If
        Set_DGV3載入後設定()
    End Sub
    Private Sub Set_grid4()
        DataGridView1.Columns(0).Width = 140 : DataGridView1.Columns(1).Width = 80 : DataGridView1.Columns(2).Width = 140 : DataGridView1.Columns(3).Width = 130 : DataGridView1.Columns(4).Width = 140
        DataGridView1.Columns(5).Width = 90 : DataGridView1.Columns(6).Width = 60 : DataGridView1.Columns(7).Width = 90 : DataGridView1.Columns(8).Width = 100 : DataGridView1.Columns(9).Width = 100
        DataGridView1.Columns(10).Width = 90 : DataGridView1.Columns(11).Width = 90 : DataGridView1.Columns(12).Width = 140 : DataGridView1.Columns(13).Width = 90 : DataGridView1.Columns(14).Width = 130
        DataGridView1.Columns(15).Width = 140 : DataGridView1.Columns(16).Width = 120
        DataGridView1.Columns(17).Visible = False : DataGridView1.Columns(18).Visible = False
        DataGridView1.Columns(19).Visible = False : DataGridView1.Columns(20).Visible = False : DataGridView1.Columns(21).Visible = False : DataGridView1.Columns(22).Visible = False
        DataGridView1.Columns(23).Visible = False : DataGridView1.Columns(24).Visible = False : DataGridView1.Columns(25).Visible = False : DataGridView1.Columns(26).Visible = False
        DataGridView1.Columns(27).Visible = False : DataGridView1.Columns(28).Visible = False : DataGridView1.Columns(29).Visible = False : DataGridView1.Columns(30).Visible = False
        DataGridView1.Columns(31).Visible = False : DataGridView1.Columns(32).Visible = False : DataGridView1.Columns(33).Visible = False : DataGridView1.Columns(34).Visible = False
        DataGridView1.Columns(35).Visible = False : DataGridView1.Columns(36).Visible = False : DataGridView1.Columns(37).Visible = False : DataGridView1.Columns(38).Visible = False
        DataGridView1.Columns(39).Visible = False : DataGridView1.Columns(40).Visible = False : DataGridView1.Columns(41).Visible = False : DataGridView1.Columns(42).Visible = False
        DataGridView1.Columns(43).Visible = False : DataGridView1.Columns(44).Visible = False : DataGridView1.Columns(45).Visible = False : DataGridView1.Columns(46).Visible = False
        DataGridView1.Columns(47).Visible = False : DataGridView1.Columns(48).Visible = False : DataGridView1.Columns(49).Visible = False : DataGridView1.Columns(50).Visible = False
        DataGridView1.Columns(51).Visible = False : DataGridView1.Columns(52).Visible = False : DataGridView1.Columns(53).Visible = False : DataGridView1.Columns(54).Visible = False
        DataGridView1.Columns(55).Visible = False : DataGridView1.Columns(56).Visible = False : DataGridView1.Columns(57).Visible = False : DataGridView1.Columns(58).Visible = False
        DataGridView1.Columns(7).DefaultCellStyle.Format = "#,##0" : DataGridView1.Columns(10).DefaultCellStyle.Format = "#,##0.00" : DataGridView1.Columns(11).DefaultCellStyle.Format = "#,##0.00"
        DataGridView1.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        DataGridView1.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        DataGridView1.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
        DataGridView1.Columns(11).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
    End Sub
    Private Sub CXL訂單紀錄表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = WINPROFIT_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        Set_清單3()
    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(0, e.RowIndex).Value.ToString <> DataGridView1(0, 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 DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        If e.RowIndex = -1 Then : Else
            TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells("訂單流水號").Value
        End If
    End Sub
    Private Sub Button30_Click(sender As Object, e As EventArgs) Handles Button30.Click
        If TextBox1.Text = "" Then
            MsgBox("請先選擇訂單資料")
        Else
            PA = TextBox1.Text
            量產訂單明細表.Show() : 量產訂單明細表.WindowState = 2
        End If
    End Sub
    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        PA = InputBox("請輸入要查詢的關鍵字") : Set_清單3() : PA = ""
    End Sub
End Class