Function Get_MsByType() As DataTable
If (lb_TypePet.Text = "สุนัข") Then
lb_TypePet.Text = "D"
ElseIf (lb_TypePet.Text = "แมว") Then
lb_TypePet.Text = "C"
End If
Dim da As SqlDataAdapter = New SqlDataAdapter 'ใช้ดึงข้อมูลจากฐานข้อมูลเก็บไว้ใน ds
Dim ds As DataSet = New DataSet
Dim st As String = "select MsID,MsName,SellPrice,UName from Medical_Supplies,Unit_Medicine where Gfor like '%" & lb_TypePet.Text & "%' and TypeCode = '" & cBox_SupType.SelectedValue.ToString & "' and UCode = UID "
Dim strcon As String = "Data Source=LT-OCTOBERNO196\SQLEXPRESS;Initial Catalog=DogandCat;Integrated Security=True"
Dim myCon As New SqlConnection(strcon)
Dim myCommand As New SqlCommand(st, myCon)
myCommand.Connection = myCon
myCon.Open()
Dim dataTable2 As DataTable = New DataTable
da.SelectCommand = New SqlCommand(st, myCon)
da.Fill(dataTable2)
If (lb_TypePet.Text = "D") Then
lb_TypePet.Text = "สุนัข"
ElseIf (lb_TypePet.Text = "C") Then
lb_TypePet.Text = "แมว"
End If
If (lb_Sex.Text = "F") Then
lb_Sex.Text = "เมีย"
ElseIf (lb_Sex.Text = "M") Then
lb_Sex.Text = "ผู้"
End If
Return dataTable2
End Function 'ข้อมูลยาเลือกตามประเภท
Code การเลือกค่าจาก Grid1 to Grid2
Code (VB.NET)
Private Sub DataGrid_Ms_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGrid_Ms.CellMouseClick
Dim k As Integer = 0
For k = 0 To DataGrid_Prescription.Rows.Count - 1
Dim temp_ID As String = ""
temp_ID = DataGrid_Prescription.Rows(k).Cells(1).Value
If temp_ID = Me.DataGrid_Ms.CurrentRow.Cells(0).Value Then
MessageBox.Show("ข้อมูลที่ทำการเลือก ในขณะนี้ ได้ทำการเลือกไปแล้วค่ะ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
Next
Grid_Presciption_Data.ImportRow(Grid_Ms_Data.Rows(e.RowIndex)) ' import ข้อมูลไปยัง datagird ของ TReated
DataGrid_Prescription.DataSource = Grid_Presciption_Data
Set_GridPrescription()
Grid_Ms_Data.Rows(e.RowIndex).Delete() ' ลบ row ที่เลือกไป
Grid_Ms_Data.AcceptChanges()
DataGrid_Ms.DataSource = Grid_Ms_Data 'bind ข้อมูล
Set_GridMs()
End Sub
Grid2 back to Grid1
Code (VB.NET)
Private Sub DataGrid_Prescription_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGrid_Prescription.CellMouseDoubleClick
Grid_Ms_Data.ImportRow(Grid_Presciption_Data.Rows(e.RowIndex))
' Grid_Ms_Data.DefaultView.Sort = "MsID"
DataGrid_Ms.DataSource = Grid_Ms_Data
' DataGrid_Service.RowsDefaultCellStyle.WrapMode = True
Set_GridMs()
Grid_Presciption_Data.Rows(e.RowIndex).Delete()
Grid_Presciption_Data.AcceptChanges()
DataGrid_Prescription.DataSource = Grid_Presciption_Data
' DataGrid_Treated.RowsDefaultCellStyle.WrapMode = True
Set_GridPrescription()
Cal_Ms()
End Sub
่ส่วนนี่เป็น Code ของ Grid3 ค่ะ
Code (VB.NET)
Sub Get_Column_2GetNum()
DataGrid_getNum.Columns.Add("Qms", "จำนวน")
DataGrid_getNum.Columns.Add("ServID", "รหัส")
End Sub
Sub Get_Num()
Get_Column_2GetNum()
Dim r As Integer = DataGrid_getNum.Rows.Count() ' = 1 Header
r = DataGrid_Prescription.Rows.Count()
DataGrid_getNum.Rows.Add()
DataGrid_getNum.Rows(r - 1).Cells(0).Value = DataGrid_Prescription.Rows(r - 1).Cells(0).Value
DataGrid_getNum.Rows(r - 1).Cells(1).Value = DataGrid_Prescription.Rows(r - 1).Cells(1).Value
End Sub
เรียกให้ Get_Num ทำงาน ค่ะ
Code (VB.NET)
Private Sub DataGrid_Prescription_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGrid_Prescription.CellEndEdit
Get_Num()
Cal_Ms()
End Sub ' กรอกจำนวนที่จ่าย แล้วทำการคำนวณค่ายา
Private Sub DataGrid_Prescription_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGrid_Prescription.CellMouseDoubleClick
Private Sub Cal_Ms() 'คำนวณค่ายา
Dim total As Integer
For i As Integer = 0 To DataGrid_Prescription.RowCount - 1
If (DataGrid_Prescription.Rows(i).Cells(0).Value) = "" Then
MessageBox.Show("กรุณาใส่จำนวนที่ต้องจ่ายให้แก่ลูกค้าด้วยค่ะ !!")
Exit Sub
End If
If (DataGrid_Prescription.Rows(i).Cells(0).Value) <> "" Then
If Not IsNumeric(DataGrid_Prescription.Rows(i).Cells(0).Value) Then
MessageBox.Show("กรุณากรอกจำนวนตัวเลขด้วยครับ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
End If
total = total + (CDbl(DataGrid_Prescription.Rows(i).Cells(0).Value.ToString * DataGrid_Prescription.Rows(i).Cells(3).Value.ToString))
Next
MsAmount.Text = total.ToString
End Sub 'คำนวณค่ายา