Public Class AddChemForm
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.Close()
End Sub
Private Sub AddChemForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call GetData()
End Sub
Sub GetData()
strSql = "Select Chemical.ChemId AS รหัสสารเคมี, Chemical.ChemName AS ชื่อสารเคมี, " & _
"Chemical.ChemUnit AS หน่วยนับ, Chemical.Chemtotal AS จำนวนคงคลัง From Chemical"
DA.SelectCommand.CommandText = strSql
DA.Fill(DS, "Getchem")
DS.Tables("Getchem").Clear()
DA.Fill(DS, "Getchem")
DataGridView1.DataSource = DS.Tables("Getchem")
DataGridView1.ReadOnly = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
strSql = "Insert Into Chemical (ChemId, ChemName, ChemUnit, Chemtotal) Values ('" & _
TextBox1.Text & "','" & TextBox2.Text & "','" & _
TextBox3.Text & "','" & NumericUpDown1.Text & "')"
Try
With Comm
.CommandText = strSql
.CommandType = CommandType.Text
.Connection = Conn
.ExecuteNonQuery()
End With
Call GetData()
MessageBox.Show("เพิ่มข้อมูลสำเร็จ", "สำเร็จ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show("มีสารเคมีชนิดนี้อยู่แล้วในฐานข้อมูล", "พบข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning) ' & vbCrLf & Err.Description
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
strSql = "Update Chemical set ChemId = '" & TextBox1.Text & "', ChemName = '" & _
TextBox2.Text & "', ChemUnit = '" & TextBox3.Text & ", Chemtotal = '" & _
NumericUpDown1.Text & "'"
Try
With Comm
.CommandText = strSql
.CommandType = CommandType.Text
.Connection = Conn
.ExecuteNonQuery()
End With
MessageBox.Show("แก้ไขข้อมูลเสร็จสิ้น", "สำเร็จ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show("การแก้ไขข้อมูลผิดพลาด", "", MessageBoxButtons.OK, MessageBoxIcon.Warning) ' & vbCrLf & Err.Description
End Try
Call GetData()
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value
TextBox2.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value
NumericUpDown1.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value
Button1.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
strSql = "Delete * From Chemical where ChemId = '" & TextBox1.Text & "'"
Try
With Comm
.CommandText = strSql
.CommandType = CommandType.Text
.Connection = Conn
.ExecuteNonQuery()
End With
MessageBox.Show("ลบข้อมูลเสร็จสิ้น", "สำเร็จ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show("การลบข้อมูลผิดพลาด", "", MessageBoxButtons.OK, MessageBoxIcon.Warning) ' & vbCrLf & Err.Description
End Try
Call GetData()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
NumericUpDown1.Text = ""
Button1.Enabled = True
End Sub
End Class