/// <summary> /// When a new prescription is selected in the drop down /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PrescriptionList_SelectedIndexChanged(object sender, EventArgs e) { ListViewItem listviewitem; // Used for creating listview items. PrescriptionItemView.Items.Clear(); //Reset old items if (PrescriptionList.SelectedIndex > -1) //if something is selected { Prescription loadprescript = ToDoPrescriptList[PrescriptionList.SelectedIndex]; //load prescription class for (int totalitems = 0; totalitems < loadprescript.ItemName.Count; totalitems++) //for every item { listviewitem = new ListViewItem(loadprescript.ItemName[totalitems]); //add item to list view listviewitem.SubItems.Add(loadprescript.Quantity[totalitems]); //add quantity string price = DodgyBobStockControl.StockControl.ASK("'" + loadprescript.ItemName[totalitems] + "' cost please"); //get items price listviewitem.SubItems.Add(price); //add price to list view string expiry = DodgyBobStockControl.StockControl.ASK("'" + loadprescript.ItemName[totalitems] + "' expiry please"); //get expiry date listviewitem.SubItems.Add(expiry); //add expiry date to list view PatientName = loadprescript.GetPatientName(); //These are used later on for saving completed prescriptions DoctorName = loadprescript.GetDoctorName(); //** this.PrescriptionItemView.Items.Add(listviewitem); //add to list view } UpdateColumnSize(); //update column size txtInstructions.Text = loadprescript.GetInstruction(); //set instructions } }
/// <summary> /// Finish button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Complete_Click(object sender, EventArgs e) { double TotalPrice = 0; //Prescription total if (PrescriptionItemView.Items.Count > 0 && PharmaCombo.Text != null) //If Fields are filledin { for (int i = 0; i < PrescriptionItemView.Items.Count; i++) //for each of the items { #region Total Price string pricestring = PrescriptionItemView.Items[i].SubItems[2].Text.Substring(1); //get items price string quantitystring = PrescriptionItemView.Items[i].SubItems[1].Text; //get items quantity double price = double.Parse(pricestring); //Items Price int quantity = int.Parse(quantitystring); //Items Quantity price = price * quantity; //price is quantity times items price TotalPrice += price; //add the price to the total price #endregion DodgyBobStockControl.StockControl.DO("'" + PrescriptionItemView.Items[i].Text + "' consume " + quantity + " please"); //remove from stock } DodgyBobStockControl.StockControl.SAVE(); //Saves the stock update #region Saving the data to a class Prescription tempprescrip = new Prescription(PatientName); //create class if (Collecting.Checked == true) //if patient is collecting now { tempprescrip.SetCompleted("Completed"); //set status to completed } else { tempprescrip.SetCompleted("Not Completed"); //this means they are waiting } tempprescrip.SetDoctorName(DoctorName); //set doc name tempprescrip.SetPharmacistName(PharmaCombo.Text); //set pharmacist name tempprescrip.SetDateExpiry(DateExpiry.Text); //set date expiry tempprescrip.SetDateIssued(DateIssue.Text); //set date issued tempprescrip.SetPrice(TotalPrice.ToString()); //set price for (int i = 0; i < PrescriptionItemView.Items.Count; i++) //for every single item { string itemnamestring = PrescriptionItemView.Items[i].Text; //get item name string quantitystring = PrescriptionItemView.Items[i].SubItems[1].Text; //get quantity tempprescrip.ItemName.Add(itemnamestring); //add item name tempprescrip.Quantity.Add(quantitystring); //add quantity } ParentListHolder.FinalPrescriptionList.Add(tempprescrip); //add class to class list #endregion UpdatePrescriptionsToCollect(); // updates prescriptions XML file #region Tidying Up for (int i = 0; i < ToDoPrescriptList.Count; i++) //Removes the completed prescription from the old list { Prescription node = ToDoPrescriptList[i]; //get prescription class if (node.GetPatientName() == PatientName && node.GetDoctorName() == DoctorName && node.GetInstruction() == txtInstructions.Text) //check its the right one { ToDoPrescriptList.Remove(node); //remove it break; //leave loop } } WriteToDoPrescription(); //Re-Writes To Do Prescriptions without ToDoPrescriptList.Clear(); //Cleans the List PrescriptionList.Items.Clear(); //Reset items in list ReadToDoPrescriptionsFile(); //Reads the Prescriptions Back PrescriptionItemView.Items.Clear(); //Reset items in list txtInstructions.Text = ""; //set instruction to blank Collecting.Checked = false; //reset collecting variable SetPrice = 0.1; //Reset Fixed or Free #endregion if (File.Exists("CompletedPrescription.xml") == true) //if completed file exist { ReadPrescriptionsFile(); //read old one first } WritePrescription(); //write it out if (SetPrice != 0.1) //if price is a set one { TotalPrice = SetPrice; //set total price } ToPay Newform = new ToPay("£" + string.Format("{0:0.00}", TotalPrice)); //formats the price with two decimal places Newform.Show(); } else //if no prescription is selected { MessageBox.Show("No Prescription Selected"); //show error message } }