0

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
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by lolafuertes
0

Maybe you need to do some changes:

1) In the patientTreatments table, be sure to include a PatiendId field in order to identify the treatements by patien Id. (this field is not shown in your coding). From now on, I'll assume that PatienId is numeric.

2) On the load_list() sub, validate that the user has entered something in the txtPatienId.text textbox and add a WHERE clause to the select statements to load only those corresponding to this Patiend Id.

rs.Open("Select  *  from  patientTreatments WHERE PatientID = " & txtPatientId.Text, con, 1, 2)

3) I will remove the btncalculate and include the logic of calculating the total on the load_list() sub, replacing the loop of reading records by something like:

Dim intcount As Integer
        Dim Total As Decimal = 0D
        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
            Total += Ctype(rs1.Fields(1).value, Decimal) * Ctype(rs1.Fields(3).value,Decimal)
            rs1.MoveNext()
        End While
        txtTotal.Text = Total.ToString

4) On the btnAdd_Click, be sure to include the patient Id field while inserting.

I suppouse that you aready have a medicaltreatement_close sub, handling the Me.Close event where you will close the connection to the db.

Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.