Option Strict Off
Imports System.Data.SqlClient
Public Class 樣品單資料庫除錯_1
    Dim conn As New SqlConnection
    Dim da As New SqlDataAdapter
    Dim cmd As New SqlCommand
    Dim ds As New DataSet
    Dim dr As SqlDataReader
    Private Sub Set_DGV1載入前設定()
        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_DGV1載入後設定()
        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_清單()
        Set_DGV1載入前設定()
        SQL1 = "SELECT 樣品訂單部件表.SO, 樣品訂單部件表.流水號, 樣品訂單清單.流水號 AS 流水號2, 樣品訂單清單.SO AS SO2
                FROM 樣品訂單部件表 LEFT OUTER JOIN 樣品訂單清單 ON 樣品訂單部件表.流水號 = 樣品訂單清單.流水號 AND 樣品訂單部件表.版次 = 樣品訂單清單.版次 AND 樣品訂單部件表.SO = 樣品訂單清單.SO
                WHERE (樣品訂單清單.SO IS NULL) ORDER BY   SO2"
        Set_DGV1載入後設定()
    End Sub
    Private Sub Set_grid()
        DataGridView1.Columns(0).Width = 120 : DataGridView1.Columns(1).Width = 120 : DataGridView1.Columns(2).Width = 120 : DataGridView1.Columns(3).Width = 120
    End Sub
    Private Sub 樣品單資料庫除錯_1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Set_清單()
    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(0, e.RowIndex).Value.ToString
            TextBox2.Text = DataGridView1(1, e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("沒有選擇要刪除的資料")
        Else
            Dim aa As MsgBoxResult
            aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
            If aa = MsgBoxResult.Ok Then
                If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                SQL1 = "DELETE FROM 樣品訂單部件表 WHERE (SO LIKE N'" & TextBox1.Text & "' AND 流水號 LIKE N'" & TextBox2.Text & "')"
                cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
                MsgBox("刪除完成") : Set_清單()
            End If
        End If
    End Sub
End Class