Example #1
0
        private void Save_Button_Click(object sender, RoutedEventArgs e)
        {
            this.totalbill_bill.IsEnabled = true;
            if (patname_bill.SelectedIndex == -1)
            {
                return;
            }
            String patientname = patname_bill.SelectedValue.ToString();

            Console.WriteLine(patientname);
            if (patientname == null || pat_docchrg.Text == "")
            {
                return;
            }
            String ptype = patient_type.Text;
            String pname = patname_bill.Text;

            Console.WriteLine(pname);
            Console.WriteLine(ptype);
            //String pdocchg = pat_docchrg.Text;
            //Console.WriteLine(pdocchg);
            double medprice = double.Parse(medchrge_bill.Text);

            double dochrge = double.Parse(pat_docchrg.Text);

            Console.WriteLine(dochrge);
            int    nod         = int.Parse(noofday_bill.Text);
            int    pid         = int.Parse(patientname);
            var    dateofadmit = indpatList.Where(x => x.pat_id == pid).Select(x => x.admit_date).FirstOrDefault();
            var    docid       = patientList.Where(x => x.pat_id == pid).Select(x => x.doc_id).FirstOrDefault();
            var    docname     = doctorList.Where(x => x.doc_id == docid).Select(x => x.Employee.emp_firstname).FirstOrDefault();
            double totalbill;
            Bill   bill = new Bill();

            if (ptype.Equals("outdoor"))
            {
                bill.pat_id        = pid;
                bill.pat_name      = pname;
                bill.pat_type      = ptype;
                bill.med_charge    = medprice;
                bill.doctor_charge = dochrge;
                bill.room_charge   = null;
                bill.no_of_days    = null;
                totalbill          = medprice + dochrge;
                bill.total_bill    = totalbill;
                bill.doc_name      = docname;
                bill.admit_date    = null;
                hmsfac.addBill(bill);
                billpatlist.Add(bill);
                dataGrid_Patients_Bill.Items.Refresh();
                new PatientBills(bill, patname_bill.Text).ShowDialog();
                hmsfac.removePatientById(pid);
                patientList = hmsfac.getPatient();
                patname_bill.ItemsSource     = patientList;
                dataGrid_Patient.ItemsSource = patientList;
                dataGrid_Patient.Items.Refresh();
                //indpatList = hmsfac.getIndoorPatient();
                //dataGrid_IndoorPatients.Items.Refresh();
            }
            else if (ptype.Equals("indoor"))
            {
                double roomchrge = double.Parse(roomchrg_bill.Text);
                bill.pat_id        = pid;
                bill.pat_type      = ptype;
                bill.pat_name      = pname;
                bill.med_charge    = medprice;
                bill.room_charge   = roomchrge;
                bill.no_of_days    = nod;
                bill.doctor_charge = dochrge;
                totalbill          = medprice + dochrge + (roomchrge * nod);
                bill.admit_date    = dateofadmit;
                bill.leave_date    = DateTime.Today;
                bill.doc_name      = docname;
                bill.total_bill    = totalbill;
                hmsfac.addBill(bill);
                billpatlist.Add(bill);
                dataGrid_Patients_Bill.Items.Refresh();
                new PatientBills(bill, patname_bill.Text).ShowDialog();
                hmsfac.removePatientById(pid);
                patientList = hmsfac.getPatient();
                dataGrid_Patient.Items.Refresh();
                patname_bill.ItemsSource     = patientList;
                dataGrid_Patient.ItemsSource = patientList;
                indpatList = hmsfac.getIndoorPatient();
                dataGrid_IndoorPatients.Items.Refresh();
            }
            else
            {
                Console.WriteLine("i am here");
                return;
            }
            this.patname_bill.Text  = "";
            this.patient_type.Text  = "";
            this.pat_docchrg.Text   = "";
            this.medchrge_bill.Text = "";
            this.roomchrg_bill.Text = "";
            this.noofday_bill.Text  = "";
        }