If sqlcon.State = ConnectionState.Closed Then
sqlcon.Open()
End If
If txtFirstname_e.Text = "" Then
MessageBox.Show("กรุณาเลือกพนักงาน")
Else
Dim emp As String
emp = txtFirstname_e.Text
EmployeeBox.Items.Add(emp)
Dim com As New SqlCommand("SELECT * FROM product WHERE ID = 'MT001'", sqlcon)
Dim dr As SqlDataReader = com.ExecuteReader
Dim i As Integer = 0
If dr.HasRows Then
While dr.Read()
dg2.Rows.Add()
dg2.Rows(i).Cells(0).Value = dr.Item(1) 'ชื่อสินค้า
dg2.Rows(i).Cells(1).Value = dr.Item(3) 'ราคา
dg2.Rows(i).Cells(3).Value = dr.Item(2) 'เวลารับบริการ
dg2.Rows(i).Cells(2).Value = txtFirstname_e.Text
dg2.Rows(i).Cells(4).Value = Lbtime.Text
dg2.Rows(i).Cells(5).Value = Lbdate.Text
i = i + 1
End While
dr.Close()
End If
Dim totalValue As Integer
For Each dgvRow As DataGridViewRow In dg2.Rows
If Not dgvRow.IsNewRow Then
totalValue += CInt(dgvRow.Cells(3).Value)
End If
Next
TextBoxprice.Text = totalValue
End If
Dim com As New SqlCommand("SELECT * FROM product WHERE ID = 'MT001'", sqlcon)
Dim dr As SqlDataReader = com.ExecuteReader
Dim i As Integer = 0
If dr.HasRows Then
While dr.Read()
dg2.Rows.Add()
dg2.Rows(i).Cells(0).Value = dr.Item(1) 'ชื่อสินค้า
dg2.Rows(i).Cells(1).Value = dr.Item(3) 'ราคา
dg2.Rows(i).Cells(3).Value = dr.Item(2) 'เวลารับบริการ
dg2.Rows(i).Cells(2).Value = txtFirstname_e.Text
dg2.Rows(i).Cells(4).Value = Lbtime.Text
dg2.Rows(i).Cells(5).Value = Lbdate.Text
i = i + 1
End While
dr.Close()
End If
Dim com As New SqlCommand("SELECT * FROM product WHERE ID = 'MT001'", sqlcon)
Dim dr As SqlDataReader = com.ExecuteReader
Dim i As Integer = dg2.Rows.Count - 0
If dr.HasRows Then
Dim sql As String = ""
sql = "INSERT INTO po (NAME,PRICE,Timeproduct,Date,Time,EMPID,Firstname_e,Lastname_e,MEMID,Firstname_m,Lastname_m,PO_ID) VALUES (@NAME,@PRICE,@Timeproduct,@Date,@Time,@EMPID,@Firstname_e,@Lastname_e,@MEMID,@Firstname_m,@Lastname_m,@PO_ID)"
dc = New SqlCommand(sql, sqlcon)
For r As Integer = 0 To dg2.RowCount - 1
With dc
.Parameters.AddWithValue("NAME", (dg2.Rows(r).Cells(0).Value))
.Parameters.AddWithValue("Timeproduct", (dg2.Rows(r).Cells(1).Value))
.Parameters.AddWithValue("Firstname_e", (dg2.Rows(r).Cells(2).Value))
.Parameters.AddWithValue("PRICE", (dg2.Rows(r).Cells(3).Value))
.Parameters.AddWithValue("Time", (dg2.Rows(r).Cells(4).Value))
.Parameters.AddWithValue("Date", (dg2.Rows(r).Cells(5).Value))
.Parameters.AddWithValue("EMPID", (txtEMPID.Text))
.Parameters.AddWithValue("Lastname_e", (txtLastname_e.Text))
.Parameters.AddWithValue("MEMID", (txtMEMID.Text))
.Parameters.AddWithValue("Firstname_m", (txtFirstname_m.Text))
.Parameters.AddWithValue("Lastname_m", (txtLastname_m.Text))
.Parameters.AddWithValue("PO_ID", (txtpo_id.Text))
MessageBox.Show("บันทึกข้อมูลสำเร็จ", "ร้านเฮอบัลสปา", MessageBoxButtons.OK, MessageBoxIcon.None)
End With
dc.ExecuteNonQuery()
dc.Parameters.Clear()
clearData()
dg2.Rows.Clear()
Next
Call poid()
sqlcon.Close()