hi guys i have a form that calculates the medicine charges of a patient then display the data in listview, i want when i add a new medicine charge the total charge of the medicine to be added in to the previous total charge so i will get the new total charge
this is my code
Public Class medicaltreatment
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim str As String
Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
SearchPatients.MdiParent = MAIN
SearchPatients.WindowState = FormWindowState.Maximized
SearchPatients.Show()
End Sub
Private Sub cboMedicineName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboMedicineName.SelectedIndexChanged
If Me.cboMedicineName.SelectedItem.ToString.Equals("Iron") Then
txtunitprice.Text = 15
End If
End Sub
Public Sub load_list()
On Error Resume Next
ListView1.Clear()
ListView1.Items.Clear()
Dim rs1 As New ADODB.Recordset
ListView1.Items.Clear()
rs1.Open("Select * from patientTreatments", con, 1, 2)
ListView1.View = Windows.Forms.View.Details
ListView1.Columns.Add("MedicineName", 130, HorizontalAlignment.Left)
ListView1.Columns.Add("Unitprice", 95, HorizontalAlignment.Left)
ListView1.Columns.Add("PrescriptionDate", 90, HorizontalAlignment.Left)
ListView1.Columns.Add("Quantity", 130, HorizontalAlignment.Left)
ListView1.Columns.Add("TotalCharge", 140, HorizontalAlignment.Left)
ListView1.Columns.Add("PatientName", 100, HorizontalAlignment.Left)
Dim intcount As Integer
While Not rs1.EOF
ListView1.Items.Add(Trim(rs1.Fields(0).Value)) 'col no. 1
ListView1.Items(CInt(intcount)).SubItems.Add(Trim(rs1.Fields(1).Value))
ListView1.Items(CInt(intcount)).SubItems.Add(Trim(rs1.Fields(2).Value))
ListView1.Items(CInt(intcount)).SubItems.Add(Trim(rs1.Fields(3).Value))
ListView1.Items(CInt(intcount)).SubItems.Add(Trim(rs1.Fields(4).Value))
ListView1.Items(CInt(intcount)).SubItems.Add(Trim(rs1.Fields(5).Value))
intcount = intcount + 1
rs1.MoveNext()
End While
rs1.Close()
End Sub
Private Sub medicaltreatment_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Jimale\Documents\Visual Studio 2010\Projects\Mumtaz Hospital IP Mgt System\Mumtaz Hospital IP Mgt System\mumtazDB.mdb"
con.Open()
load_list()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If txtPatientID.Text = "" Then
MessageBox.Show("Patient ID can not be empty", "Mumtaz hospital management system", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
rs = New ADODB.Recordset
rs.Open("Select * from patientTreatments", con, 1, 2)
rs.AddNew()
rs.Fields(0).Value = cboMedicineName.Text
rs.Fields(1).Value = txtunitprice.Text
rs.Fields(2).Value = DateTimePicker1.Text
rs.Fields(3).Value = txtQuantity.Text
rs.Fields(4).Value = txtTotal.Text
rs.Fields(5).Value = txtname.Text
rs.Update()
MessageBox.Show("A new record has been added in to the database", "Mumtaz hospital management system", MessageBoxButtons.OK, MessageBoxIcon.Information)
rs.Close()
Call load_list()
End Sub
Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalculate.Click
Dim unitprice As Decimal
Dim quantity As Decimal
unitprice = Val(txtunitprice.Text)
quantity = Val(txtQuantity.Text)
txtTotal.Text = (unitprice * quantity)
End Sub
End Class