123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 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 : ReadOnly ds1 As New DataSet
- Dim dr As SqlDataReader
- 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 中皮, 中皮 AS 結構, 結構 AS 作法 FROM 中皮結構 ORDER BY 底台"
- cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
- DataGridView1.Columns(0).FillWeight = 150 : DataGridView1.Columns(1).Visible = False : DataGridView1.Columns(2).Visible = False
- End Sub
- Private Sub Set_清單1()
- DataGridView2.DataSource = Nothing : ds1.Clear()
- DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
- DataGridView2.ColumnHeadersHeight = 25
- DataGridView2.AllowUserToAddRows = False
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- SQL1 = "SELECT 中底, 做法 FROM 中底做法 ORDER BY 中底"
- cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close()
- DataGridView2.Columns(0).FillWeight = 150 : DataGridView2.Columns(1).Visible = False
- End Sub
- Private Sub 中皮結構_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Set_清單() : Set_清單1()
- 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 : TextBox3.Text = DataGridView1(2, e.RowIndex).Value.ToString
- End If
- End Sub
- Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView2.CellClick
- If e.RowIndex = -1 Then : Else
- TextBox5.Text = DataGridView2(0, e.RowIndex).Value.ToString : TextBox4.Text = DataGridView2(1, e.RowIndex).Value.ToString
- End If
- End Sub
- Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
- If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
- MsgBox("資料有缺或有誤,請重新檢查")
- Else
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- SQL1 = "SELECT 底台 FROM 中皮結構 WHERE 底台 LIKE N'" & TextBox1.Text & "'"
- 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
- SQL1 = "INSERT INTO 中皮結構 (底台, 中皮, 結構) VALUES (N'" & TextBox1.Text & "', N'" & TextBox2.Text & "', N'" & TextBox3.Text & "')"
- cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
- MsgBox("新增完成")
- conn.Close() : dr.Close()
- End If
- Set_清單()
- End If
- End Sub
- Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
- If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
- MsgBox("資料有缺或有誤,請重新檢查")
- Else
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- SQL1 = "UPDATE 中皮結構 SET 中皮 = N'" & TextBox2.Text & "', 結構 = N'" & TextBox3.Text & "' " &
- "WHERE 底台 LIKE N'" & TextBox1.Text & "'"
- cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
- MsgBox("修改完成") : conn.Close() : Set_清單()
- End If
- End Sub
- Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
- 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 底台 LIKE N'" & TextBox1.Text & "'"
- cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : conn.Close()
- MsgBox("刪除完成")
- Set_清單()
- End If
- End Sub
- '-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- If TextBox5.Text = "" Or TextBox4.Text = "" Then
- MsgBox("資料有缺或有誤,請重新檢查")
- Else
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- SQL1 = "SELECT 中底 FROM 中底做法 WHERE 中底 LIKE N'" & TextBox1.Text & "'"
- 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
- SQL1 = "INSERT INTO 中底做法 (中底, 做法) VALUES (N'" & TextBox5.Text & "', N'" & TextBox4.Text & "')"
- cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
- MsgBox("新增完成")
- conn.Close() : dr.Close()
- End If
- Set_清單1()
- End If
- End Sub
- Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
- If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
- MsgBox("資料有缺或有誤,請重新檢查")
- Else
- If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
- SQL1 = "UPDATE 中底做法 SET 做法 = N'" & TextBox4.Text & "' WHERE 中底 LIKE N'" & TextBox5.Text & "'"
- cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
- MsgBox("修改完成") : conn.Close() : Set_清單1()
- End If
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- 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 中底 LIKE N'" & TextBox5.Text & "'"
- cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : cmd.ExecuteNonQuery() : conn.Close()
- MsgBox("刪除完成")
- Set_清單1()
- End If
- End Sub
- End Class
|