Option Strict Off
Imports System.Data.SqlClient
Public Class 清單修改
    ReadOnly conn As New SqlConnection
    ReadOnly da As New SqlDataAdapter
    ReadOnly cmd As New SqlCommand
    ReadOnly 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()
    End Sub
    Private Sub Set_資料清單()
        Set_DGV1載入前設定()
        If 部門清單修改 = True Then : SQL1 = "SELECT 部門 FROM METOO部門清單 ORDER BY 部門"
        ElseIf 職稱清單修改 = True Then : SQL1 = "SELECT 職稱 FROM METOO職稱清單 ORDER BY 職稱"
        ElseIf 客戶清單修改 = True Then : SQL1 = "SELECT 客戶簡稱 FROM 客戶控制表 ORDER BY 客戶簡稱"
        ElseIf 工廠清單修改 = True Then : SQL1 = "SELECT 工廠 FROM 工廠控制表 ORDER BY 工廠"
        ElseIf 顏色清單修改 = True Then : SQL1 = "SELECT 顏色 FROM 顏色清單 ORDER BY 顏色"
        ElseIf 港口清單修改 = True Then : SQL1 = "SELECT FOB FROM 港口清單 ORDER BY FOB"
        ElseIf 季節清單修改 = True Then : SQL1 = "SELECT SEASON FROM 季節清單 ORDER BY SEASON"
        ElseIf 供應商清單修改 = True Then : SQL1 = "SELECT 廠商 FROM 供應商清單 ORDER BY 廠商"
        ElseIf 國家清單修改 = True Then : SQL1 = "SELECT 國家 FROM 國家清單 ORDER BY 國家"
        ElseIf PURPOSE清單修改 = True Then : SQL1 = "SELECT  狀態 FROM PURPOSE清單 ORDER BY 狀態"
        ElseIf 部件清單修改 = True Then : SQL1 = "SELECT 部件 FROM 部件清單 ORDER BY 部件"
        ElseIf 交貨條件修改 = True Then : SQL1 = "SELECT DELIVERYTERMS FROM DELIVERYTERMS ORDER BY DELIVERYTERMS"
        ElseIf 到港清單修改 = True Then : SQL1 = "SELECT TOPORT FROM TOPORT ORDER BY TOPORT"
        ElseIf 交貨管道修改 = True Then : SQL1 = "SELECT MODEOFDELIVERY FROM MODEOFDELIVERY ORDER BY MODEOFDELIVERY"
        ElseIf 模具用結構 = True Then : SQL1 = "SELECT  結構 FROM 模具開發用結構清單"
        ElseIf 模具用材質 = True Then : SQL1 = "SELECT  材質 FROM 模具開發用材質清單"
        ElseIf 行政物料 = True Then : SQL1 = "SELECT 行政物料 FROM 人員行政物料表"
        ElseIf 訂單顏色修改 = True Then : SQL1 = "SELECT 顏色 FROM 訂單顏色清單 ORDER BY 顏色"
        ElseIf 楦頭編碼修改 = True Then : SQL1 = "SELECT 縮寫 FROM 楦頭縮寫管理 ORDER BY 縮寫"
        ElseIf 廠商類別修改 = True Then : SQL1 = "SELECT 廠商類別 FROM 廠商類別 ORDER BY 廠商類別"
        End If
        Set_DGV1載入後設定()
    End Sub
    Private Sub Set_grid()
        DataGridView1.Columns(0).Width = 375
    End Sub
    Private Sub 清單修改_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FormBorderStyle = FormBorderStyle.SizableToolWindow
        Set_資料清單() : Set_grid()
    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(0, e.RowIndex).Value.ToString
        End If
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If TextBox1.Text = "" Then
            MsgBox("資料有缺或有誤，請重新檢查")
        Else
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            If 部門清單修改 = True Then : SQL1 = "SELECT 部門 FROM METOO部門清單 WHERE 部門 LIKE N'" & TextBox1.Text & "'"
            ElseIf 職稱清單修改 = True Then : SQL1 = "SELECT 職稱 FROM METOO職稱清單 WHERE 職稱 LIKE N'" & TextBox1.Text & "'"
            ElseIf 客戶清單修改 = True Then : SQL1 = "SELECT 客戶簡稱 FROM 客戶控制表 WHERE 客戶簡稱 LIKE N'" & TextBox1.Text & "'"
            ElseIf 工廠清單修改 = True Then : SQL1 = "SELECT 工廠 FROM 工廠控制表 WHERE 工廠 LIKE N'" & TextBox1.Text & "'"
            ElseIf 顏色清單修改 = True Then : SQL1 = "SELECT 顏色 FROM 顏色清單 WHERE 顏色 LIKE N'" & TextBox1.Text & "'"
            ElseIf 港口清單修改 = True Then : SQL1 = "SELECT FOB FROM 港口清單 WHERE FOB LIKE N'" & TextBox1.Text & "'"
            ElseIf 季節清單修改 = True Then : SQL1 = "SELECT SEASON FROM 季節清單 WHERE SEASON LIKE N'" & TextBox1.Text & "'"
            ElseIf 供應商清單修改 = True Then : SQL1 = "SELECT 廠商 FROM 供應商清單 WHERE 廠商 LIKE N'" & TextBox1.Text & "'"
            ElseIf 國家清單修改 = True Then : SQL1 = "SELECT 國家 FROM 國家清單 WHERE 國家 LIKE N'" & TextBox1.Text & "'"
            ElseIf PURPOSE清單修改 = True Then : SQL1 = "SELECT 狀態 FROM PURPOSE清單 WHERE 狀態 LIKE N'" & TextBox1.Text & "'"
            ElseIf 部件清單修改 = True Then : SQL1 = "SELECT 部件 FROM 部件清單 WHERE 部件 LIKE N'" & TextBox1.Text & "'"
            ElseIf 交貨條件修改 = True Then : SQL1 = "SELECT DELIVERYTERMS FROM DELIVERYTERMS WHERE DELIVERYTERMS LIKE N'" & TextBox1.Text & "'"
            ElseIf 到港清單修改 = True Then : SQL1 = "SELECT TOPORT FROM TOPORT WHERE TOPORT LIKE N'" & TextBox1.Text & "'"
            ElseIf 交貨管道修改 = True Then : SQL1 = "SELECT MODEOFDELIVERY FROM MODEOFDELIVERY WHERE MODEOFDELIVERY LIKE N'" & TextBox1.Text & "'"
            ElseIf 模具用結構 = True Then : SQL1 = "SELECT 結構 FROM 模具開發用結構清單 WHERE 結構 LIKE N'" & TextBox1.Text & "'"
            ElseIf 模具用材質 = True Then : SQL1 = "SELECT 材質 FROM 模具開發用材質清單 WHERE 材質 LIKE N'" & TextBox1.Text & "'"
            ElseIf 行政物料 = True Then : SQL1 = "SELECT 行政物料 FROM 人員行政物料表 WHERE 行政物料 LIKE N'" & TextBox1.Text & "'"
            ElseIf 訂單顏色修改 = True Then : SQL1 = "SELECT 顏色 FROM 訂單顏色清單 WHERE 顏色 LIKE N'" & TextBox1.Text & "'"
            ElseIf 楦頭編碼修改 = True Then : SQL1 = "SELECT 縮寫 FROM 楦頭縮寫管理 WHERE 縮寫 LIKE N'" & TextBox1.Text & "'"
            ElseIf 廠商類別修改 = True Then : SQL1 = "SELECT 廠商類別 FROM 廠商類別 WHERE 廠商類別 LIKE N'" & TextBox1.Text & "'"
            End If
            cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
            If dr.Read() Then
                MsgBox("資料重複，請從新輸入或檢查")
                conn.Close() : dr.Close()
            Else
                conn.Close() : dr.Close()
                If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
                If 部門清單修改 = True Then : SQL1 = "INSERT INTO METOO部門清單 (部門) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 職稱清單修改 = True Then : SQL1 = "INSERT INTO METOO職稱清單 (職稱) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 客戶清單修改 = True Then : SQL1 = "INSERT INTO 客戶控制表 (客戶簡稱) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 工廠清單修改 = True Then : SQL1 = "INSERT INTO 工廠控制表 (工廠) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 顏色清單修改 = True Then : SQL1 = "INSERT INTO 顏色清單 (顏色) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 港口清單修改 = True Then : SQL1 = "INSERT INTO 港口清單 (FOB) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 季節清單修改 = True Then : SQL1 = "INSERT INTO 季節清單 (SEASON) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 供應商清單修改 = True Then : SQL1 = "INSERT INTO 供應商清單 (廠商) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 國家清單修改 = True Then : SQL1 = "INSERT INTO 國家清單 (國家) VALUES (N'" & TextBox1.Text & "')"
                ElseIf PURPOSE清單修改 = True Then : SQL1 = "INSERT INTO PURPOSE清單 (狀態) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 部件清單修改 = True Then : SQL1 = "INSERT INTO 部件清單 (部件) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 交貨條件修改 = True Then : SQL1 = "INSERT INTO DELIVERYTERMS (DELIVERYTERMS) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 到港清單修改 = True Then : SQL1 = "INSERT INTO TOPORT (TOPORT) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 交貨管道修改 = True Then : SQL1 = "INSERT INTO MODEOFDELIVERY (MODEOFDELIVERY) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 模具用結構 = True Then : SQL1 = "INSERT INTO 模具開發用結構清單 (結構) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 模具用材質 = True Then : SQL1 = "INSERT INTO 模具開發用材質清單 (材質) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 行政物料 = True Then : SQL1 = "INSERT INTO 人員行政物料表 (行政物料) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 訂單顏色修改 = True Then : SQL1 = "INSERT INTO 訂單顏色清單 (顏色) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 楦頭編碼修改 = True Then : SQL1 = "INSERT INTO 楦頭縮寫管理 (縮寫) VALUES (N'" & TextBox1.Text & "')"
                ElseIf 廠商類別修改 = True Then : SQL1 = "INSERT INTO 廠商類別 (廠商類別) VALUES (N'" & TextBox1.Text & "')"
                End If
                cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
                MsgBox("新增完成")
                conn.Close() : dr.Close()
            End If
        End If
        Set_資料清單() : Set_grid()
    End Sub
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If TextBox1.Text = "" Then
            MsgBox("資料有缺或有誤，請重新檢查")
        Else
            If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
            If 部門清單修改 = True Then : SQL1 = "UPDATE METOO部門清單 SET 部門 = N'" & TextBox1.Text & "' WHERE 部門 LIKE N'" & TextBox2.Text & "'"
            ElseIf 職稱清單修改 = True Then : SQL1 = "UPDATE METOO職稱清單 SET 職稱 = N'" & TextBox1.Text & "' WHERE 職稱 LIKE N'" & TextBox2.Text & "'"
            ElseIf 客戶清單修改 = True Then : SQL1 = "UPDATE 客戶控制表 SET 客戶簡稱 = N'" & TextBox1.Text & "' WHERE 客戶簡稱 LIKE N'" & TextBox2.Text & "'"
            ElseIf 工廠清單修改 = True Then : SQL1 = "UPDATE 工廠控制表 SET 工廠 = N'" & TextBox1.Text & "' WHERE 工廠 LIKE N'" & TextBox2.Text & "'"
            ElseIf 顏色清單修改 = True Then : SQL1 = "UPDATE 顏色清單 SET 顏色 = N'" & TextBox1.Text & "' WHERE 顏色 LIKE N'" & TextBox2.Text & "'"
            ElseIf 港口清單修改 = True Then : SQL1 = "UPDATE 港口清單 SET FOB = N'" & TextBox1.Text & "' WHERE FOB LIKE N'" & TextBox2.Text & "'"
            ElseIf 季節清單修改 = True Then : SQL1 = "UPDATE 季節清單 SET SEASON = N'" & TextBox1.Text & "' WHERE SEASON LIKE N'" & TextBox2.Text & "'"
            ElseIf 供應商清單修改 = True Then : SQL1 = "UPDATE 供應商清單 SET 廠商 = N'" & TextBox1.Text & "' WHERE 廠商 LIKE N'" & TextBox2.Text & "'"
            ElseIf 國家清單修改 = True Then : SQL1 = "UPDATE 國家清單 SET 國家 = N'" & TextBox1.Text & "' WHERE 國家 LIKE N'" & TextBox2.Text & "'"
            ElseIf PURPOSE清單修改 = True Then : SQL1 = "UPDATE PURPOSE清單 SET 狀態 = N'" & TextBox1.Text & "' WHERE 狀態 LIKE N'" & TextBox2.Text & "'"
            ElseIf 部件清單修改 = True Then : SQL1 = "UPDATE 部件清單 SET 部件 = N'" & TextBox1.Text & "' WHERE 部件 LIKE N'" & TextBox2.Text & "'"
            ElseIf 交貨條件修改 = True Then : SQL1 = "UPDATE DELIVERYTERMS SET DELIVERYTERMS = N'" & TextBox1.Text & "' WHERE DELIVERYTERMS LIKE N'" & TextBox2.Text & "'"
            ElseIf 到港清單修改 = True Then : SQL1 = "UPDATE TOPORT SET TOPORT = N'" & TextBox1.Text & "' WHERE TOPORT LIKE N'" & TextBox2.Text & "'"
            ElseIf 交貨管道修改 = True Then : SQL1 = "UPDATE MODEOFDELIVERY SET MODEOFDELIVERY = N'" & TextBox1.Text & "' WHERE MODEOFDELIVERY LIKE N'" & TextBox2.Text & "'"
            ElseIf 模具用結構 = True Then : SQL1 = "UPDATE 模具開發用結構清單 SET 結構 = N'" & TextBox1.Text & "' WHERE 結構 LIKE N'" & TextBox2.Text & "'"
            ElseIf 模具用材質 = True Then : SQL1 = "UPDATE 模具開發用材質清單 SET 材質 = N'" & TextBox1.Text & "' WHERE 材質 LIKE N'" & TextBox2.Text & "'"
            ElseIf 行政物料 = True Then : SQL1 = "UPDATE 人員行政物料表 SET 行政物料 = N'" & TextBox1.Text & "' WHERE 行政物料 LIKE N'" & TextBox2.Text & "'"
            ElseIf 訂單顏色修改 = True Then : SQL1 = "UPDATE 訂單顏色清單 SET 顏色 = N'" & TextBox1.Text & "' WHERE 顏色 LIKE N'" & TextBox2.Text & "'"
            ElseIf 楦頭編碼修改 = True Then : SQL1 = "UPDATE 楦頭縮寫管理 SET 縮寫 = N'" & TextBox1.Text & "' WHERE 縮寫 LIKE N'" & TextBox2.Text & "'"
            ElseIf 廠商類別修改 = True Then : SQL1 = "UPDATE 廠商類別 SET 廠商類別 = N'" & TextBox1.Text & "' WHERE 廠商類別 LIKE N'" & TextBox2.Text & "'"
            End If
            cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
            MsgBox("修改完成")
            conn.Close()
        End If
        Set_資料清單() : Set_grid()
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If 部門清單修改 = True Then : SQL1 = "DELETE FROM METOO部門清單 WHERE (部門 = N'" & TextBox1.Text & "')"
        ElseIf 職稱清單修改 = True Then : SQL1 = "DELETE FROM METOO職稱清單 WHERE (職稱 = N'" & TextBox1.Text & "')"
        ElseIf 客戶清單修改 = True Then : SQL1 = "DELETE FROM 客戶控制表 WHERE (客戶簡稱 = N'" & TextBox1.Text & "')"
        ElseIf 工廠清單修改 = True Then : SQL1 = "DELETE FROM 工廠控制表 WHERE (工廠 = N'" & TextBox1.Text & "')"
        ElseIf 顏色清單修改 = True Then : SQL1 = "DELETE FROM 顏色清單 WHERE (顏色 = N'" & TextBox1.Text & "')"
        ElseIf 港口清單修改 = True Then : SQL1 = "DELETE FROM 港口清單 WHERE (FOB = N'" & TextBox1.Text & "')"
        ElseIf 季節清單修改 = True Then : SQL1 = "DELETE FROM 季節清單 WHERE (SEASON = N'" & TextBox1.Text & "')"
        ElseIf 供應商清單修改 = True Then : SQL1 = "DELETE FROM 供應商清單 WHERE (廠商 = N'" & TextBox1.Text & "')"
        ElseIf 國家清單修改 = True Then : SQL1 = "DELETE FROM 國家清單 WHERE (國家 = N'" & TextBox1.Text & "')"
        ElseIf PURPOSE清單修改 = True Then : SQL1 = "DELETE FROM PURPOSE清單 WHERE (狀態 = N'" & TextBox1.Text & "')"
        ElseIf 部件清單修改 = True Then : SQL1 = "DELETE FROM 部件清單 WHERE (部件 = N'" & TextBox1.Text & "')"
        ElseIf 交貨條件修改 = True Then : SQL1 = "DELETE FROM DELIVERYTERMS WHERE (DELIVERYTERMS = N'" & TextBox1.Text & "')"
        ElseIf 到港清單修改 = True Then : SQL1 = "DELETE FROM TOPORT WHERE (TOPORT = N'" & TextBox1.Text & "')"
        ElseIf 交貨管道修改 = True Then : SQL1 = "DELETE FROM MODEOFDELIVERY WHERE (MODEOFDELIVERY = N'" & TextBox1.Text & "')"
        ElseIf 模具用結構 = True Then : SQL1 = "DELETE FROM 模具開發用結構清單 WHERE (結構 = N'" & TextBox1.Text & "')"
        ElseIf 模具用材質 = True Then : SQL1 = "DELETE FROM 模具開發用材質清單 WHERE (材質 = N'" & TextBox1.Text & "')"
        ElseIf 行政物料 = True Then : SQL1 = "DELETE FROM 人員行政物料表 WHERE (行政物料 = N'" & TextBox1.Text & "')"
        ElseIf 訂單顏色修改 = True Then : SQL1 = "DELETE FROM 訂單顏色清單 WHERE (顏色 = N'" & TextBox1.Text & "')"
        ElseIf 楦頭編碼修改 = True Then : SQL1 = "DELETE FROM 楦頭縮寫管理 WHERE (縮寫 = N'" & TextBox1.Text & "')"
        ElseIf 廠商類別修改 = True Then : SQL1 = "DELETE FROM 廠商類別 WHERE (廠商類別 = N'" & TextBox1.Text & "')"
        End If
        cmd.CommandText = SQL1 : cmd.Connection = conn
        If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
        Dim aa As MsgBoxResult
        aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
        If aa = MsgBoxResult.Ok Then : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : MsgBox("刪除完成") : End If
        conn.Close()
        Set_資料清單() : Set_grid()
    End Sub
End Class