Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
btnEdit.Enabled = False
btnDelete.Enabled = False
If txtIDEmployee.Text = "" Or txtNameEmployee.Text = "" Or txtAddress.Text = "" Or txtTel.Text = "" Or txtSalary.Text = "" Or txtemail.Text = "" Then
MessageBox.Show("กรุณากรอกข้อมุลพนักงานให้ครบ", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Dim SqlConnection As New SqlConnection(ConnectionString)
Dim SqlCommand As New SqlCommand(SqlInsert, SqlConnection)
SqlConnection.Open() SqlCommand.ExecuteNonQuery
MessageBox.Show("เพิ่มข้อมูลเรียบร้อยแล้ว", "ผลการทำงาน")
SqlConnection.Close()
btnEdit.Enabled = True
btnDelete.Enabled = True
ClearControl()
RefreshDataGrid()
End Sub
Private Sub ClearControl()
txtIDEmployee.Text = ""
Name_Pafix.Text = ""
txtNameEmployee.Text = ""
Sex.Text = ""
txtAddress.Text = ""
txtTel.Text = ""
txtSalary.Text = ""
txtPID.Text = ""
txtemail.Text = ""
End Sub
Private Sub RefreshDataGrid()
Dim SqlRestaurant As String
SqlRestaurant = "SELECT Employee_ID, "
SqlRestaurant &= " Name_Pafix, Name, "
SqlRestaurant &= "Sex, Address, "
SqlRestaurant &= "Tel, Password, "
SqlRestaurant &= "Salary "
SqlRestaurant &= "FROM Employee "
If IsFine = True Then
RestaurantDataSet4.Tables("Employee").Clear()
End If
da = New SqlDataAdapter(SqlRestaurant, ConnectionString)
da.Fill(RestaurantDataSet4, "Employee")
If RestaurantDataSet4.Tables("Employee").Rows.Count <> 0 Then
IsFine = True
With DataGridView1
.ReadOnly = True
.DataSource = RestaurantDataSet4.Tables("Employee")
Public Class Employee
'มาจากไฟ config
Private ConnectionString As String = "Data Source=BAMEE-00F2E6637\SQLEXPRESS;Initial Catalog=Restaurant;Integrated Security=True"
Dim SqlConnection As New SqlConnection(ConnectionString)
Dim SqlCommand As New SqlCommand
Dim da As New SqlDataAdapter
Dim IsFine As Boolean = False
Private Sub อาหารและเครองดมToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles อาหารและเครองดมToolStripMenuItem.Click
Food_Menu.Show()
End Sub
Private Sub วตถดบToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles วตถดบToolStripMenuItem.Click
Composition.Show()
End Sub
Private Sub หองครวToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles หองครวToolStripMenuItem.Click
Ck.Show()
End Sub
Private Sub บลToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles บลToolStripMenuItem.Click
Cb.Show()
End Sub
Private Sub รายงานToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles รายงานToolStripMenuItem.Click
FrmR.Show()
End Sub
Private Sub สมาชกToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles สมาชกToolStripMenuItem.Click
Customer.Show()
End Sub
Private Sub เทาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.BackColor = Color.IndianRed
End Sub
'ปุ่ม Save
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If txtIDEmployee.Text = "" Or txtNameEmployee.Text = "" Or txtAddress.Text = "" Or txtTel.Text = "" Or txtSalary.Text = "" Or txtemail.Text = "" Then
MessageBox.Show("กรุณากรอกข้อมุลพนักงานให้ครบ", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Try
'Dim SqlInsert As String = "INSERT INTO Employee(Employee_ID, Name_Pafix, Name, Sex, Address, Tel, Password, Salary, email, Position_ID) VALUES('" & txtIDEmployee.Text & "','" & Name_Pafix.SelectedValue & "','" & txtNameEmployee.Text & "','" & Sex.SelectedValue & "','" & txtAddress.Text & "','" & CInt(txtTel.Text) & "','" & txtPass.Text & "','" & CInt(txtSalary.Text) & "','" & txtemail.Text & "','" & txtPID.SelectedValue & "')"
Dim SqlInsert As String = "INSERT INTO Employee(Employee_ID, Name_Pafix, Name, Sex, Address, Tel, Password, Salary, Position_ID, email) VALUES('txtIDEmployee.Text', 'Name_Pafix.SelectedValue', 'txtNameEmployee.Text', 'Sex.SelectedValue', 'txtAddress.Text', 'txtTel.Text', 'txtPass.Text', 'txtSalary.Text', 'txtemail.Text', 'txtPID.SelectedValue')"
Dim SqlConnection As New SqlConnection(ConnectionString)
SqlConnection.Open()
Dim SqlCommand As New SqlCommand(SqlInsert, SqlConnection)
[font=Verdana] SqlCommand.ExecuteNonQuery()[/font]
MessageBox.Show("เพิ่มข้อมูลเรียบร้อยแล้ว", "ผลการทำงาน")
SqlConnection.Close()
btnEdit.Enabled = True
btnDelete.Enabled = True
ClearControl()
RefreshDataGrid()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub RefreshDataGrid()
Dim SqlRestaurant As String
SqlRestaurant = "SELECT Employee_ID, "
SqlRestaurant &= "Name_Pafix, Name, "
SqlRestaurant &= "Sex, Address, "
SqlRestaurant &= "Tel, Password, "
SqlRestaurant &= "Salary, email, "
SqlRestaurant &= "Position_ID "
SqlRestaurant &= "FROM Employee "
If IsFine = True Then
RestaurantDataSet4.Tables("Employee").Clear()
End If
da = New SqlDataAdapter(SqlRestaurant, ConnectionString)
da.Fill(RestaurantDataSet4, "Employee")
If RestaurantDataSet4.Tables("Employee").Rows.Count <> 0 Then
IsFine = True
With DataGridView1
.ReadOnly = True
.DataSource = RestaurantDataSet4.Tables("Employee")
End With
Else
IsFine = False
End If
End Sub
'ปุ่มClearControl
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
End With
SqlConnection.Close()
MessageBox.Show("ลบข้อมูลเรียบร้อยแล้ว", "ผลกาารทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ClearControl()
RefreshDataGrid()
End If
End Sub
Private Sub Employee_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'RestaurantDataSet4.Position' table. You can move, or remove it, as needed.
Me.PositionTableAdapter.Fill(Me.RestaurantDataSet4.Position)
'TODO: This line of code loads data into the 'RestaurantDataSet4.Employee' table. You can move, or remove it, as needed.
Me.EmployeeTableAdapter.Fill(Me.RestaurantDataSet4.Employee)
'TODO: This line of code loads data into the 'RestaurantDataSet4.DataTable1' table. You can move, or remove it, as needed.
Me.DataTable1TableAdapter.Fill(Me.RestaurantDataSet4.DataTable1)