/// <summary> /// Read Prescriptions to Complete XML /// </summary> public void ReadToDoPrescriptionsFile() { XmlDocument PrescriptionFile = new XmlDocument(); PrescriptionFile.Load("Prescriptions.xml"); //Read XML file XmlNodeList Prescript = PrescriptionFile.GetElementsByTagName("Prescription"); //Get a List of Prescriptions int index = 0; foreach (XmlNode node in Prescript) //For Every Prescription { string Name = node["Name"].InnerText; //Get Patient Name string Doctor = node["Doctor"].InnerText; //Get Doctor Name string instructions = node["Instructions"].InnerText; //Get Instructions XmlNodeList Items = node.SelectNodes("Item"); //Make a list of Items Prescription CurrentPrescript = new Prescription(Name); //Create New CLass CurrentPrescript.SetDoctorName(Doctor); //Set Doc Name CurrentPrescript.SetInstructions(instructions); //Set Instructions foreach (XmlNode node2 in Items) //For each item in prescription { string NameItem = node2.InnerText; //Get Item Name CurrentPrescript.AddItemNameList(NameItem); //Add to Class string Number = node2.Attributes["Quantity"].InnerText; //Get Quantity CurrentPrescript.AddQuantity(Number); //Add to CLass } ToDoPrescriptList.Add(CurrentPrescript); //Add Class to Class list PrescriptionList.Items.Add(CurrentPrescript.GetPatientName()); //Add to Complete List index++; //Next prescription } }
/// <summary> /// Reads the Prescription Files and Loads them into classes /// </summary> public void ReadOldFile() { XmlDocument PrescriptionFile = new XmlDocument(); PrescriptionFile.Load("Prescriptions.xml"); //Load Prescription File XmlNodeList Prescript = PrescriptionFile.GetElementsByTagName("Prescription"); //Get a List of Prescriptions foreach (XmlNode node in Prescript) //For Each Prescription in the list { string Name = node["Name"].InnerText; //Get Patient Name string Doctor = node["Doctor"].InnerText; //Get Doctor Name string instructions = node["Instructions"].InnerText; //Get Instructions XmlNodeList Items = node.SelectNodes("Item"); //Creates a List of Items Prescription CurrentPrescript = new Prescription(Name); //Creates a New Class CurrentPrescript.SetDoctorName(Doctor); //Sets Doctor name to the value read in CurrentPrescript.SetInstructions(instructions); //Sets Instructions to the value read in foreach (XmlNode node2 in Items) //For each Item in the list { string NameItem = node2.InnerText; //Read Item Name CurrentPrescript.AddItemNameList(NameItem); //Set Item Name string Number = node2.Attributes["Quantity"].InnerText; //Read Quantity CurrentPrescript.AddQuantity(Number); //Set Quantity } PrescriptList.Add(CurrentPrescript); //Add Class to Class List } }
/// <summary> /// Saves New Prescription File, Updates Stock and Cleans For a New Prescription /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Save_Click(object sender, EventArgs e) { if (txtPatientName.Text.Equals("")) //If there is Nothing in Patient Name Box { MessageBox.Show("Please Enter a Patient Name"); //Show Error Message } else if (DoctorsCombo.Text.Equals("")) //If there is Nothing in Doctor Drop Down { MessageBox.Show("Please Select a Doctor"); //Show Error Message } else if (ItemView.Items.Count == 0) //If there is Nothing in Items View { MessageBox.Show("No Items Have Been Selected"); //Show Error Message } else if (txtInstructions.Text.Equals("")) //If there is Nothing in Instructions { MessageBox.Show("No Instructions have been typed"); //Show Error Message } else { bool allitemsinstock = true; //Flag for Items in Stock for (int i = 0; i < ItemView.Items.Count; i++) //For Every Item { string quan = DodgyBobStockControl.StockControl.ASK("'" + ItemView.Items[i].SubItems[0].Text + "' stockcheck please"); //Check the Stock Available quan = quan.Substring(8); // Gets rid of "We Have " string[] tempvalues = quan.Split(' '); //Splits the string at " "'s int quaninstock = int.Parse(tempvalues[0]); //Gets the values before the space int quantocheck = int.Parse(ItemView.Items[i].SubItems[1].Text); //Gets the amount of Items in the prescription if (quaninstock < quantocheck) //If we dont have enough items in stock { MessageBox.Show("Pharmacy has not got enough items in stock"); //Show Error Message allitemsinstock = false; //Set the Flag } } if (allitemsinstock) //If we have enough items in stock { Prescription TempPrescriptionClass = new Prescription(txtPatientName.Text); //Create a New Prescription Class TempPrescriptionClass.SetDoctorName(DoctorsCombo.Text); //Set Doctor Name TempPrescriptionClass.SetInstructions(txtInstructions.Text); //Set Instructions for (int i = 0; i < ItemView.Items.Count; i++) //For Each Item { TempPrescriptionClass.AddItemNameList(ItemView.Items[i].SubItems[0].Text); //Add Item Name to List TempPrescriptionClass.AddQuantity(ItemView.Items[i].SubItems[1].Text); //Add Quantity to List } PrescriptList.Add(TempPrescriptionClass); //Add Class to Class List if (File.Exists(@"Prescriptions.xml") == true) //Check If prescription file already exists { ReadOldFile(); //If So Read Old Values First } WritePrescription(); //Write Out Everything MessageBox.Show("Prescription Saved"); //Tell User Prescription has been saved ResetForm(); } } }
/// <summary> /// Reads Prescription that have still gotta be collected /// </summary> public void ReadPrescriptionsFile() { ParentListHolder.FinalPrescriptionList.Clear(); //Resets XmlDocument PrescriptionFile = new XmlDocument(); PrescriptionFile.Load("CompletedPrescriptions.xml"); //Read XML file XmlNodeList Prescript = PrescriptionFile.GetElementsByTagName("Prescription"); //Creates a list of prescriptions int index = 0; foreach (XmlNode node in Prescript) //For every prescription in the list { string Name = node["Name"].InnerText; //get patient name string Doctor = node["Doctor"].InnerText; //get doc name string DateIssue = node["DateIssue"].InnerText; //get date issued string DateExpiry = node["DateExpiry"].InnerText; //get date expiry string ReadPrice = node["Price"].InnerText; //Get price string PharaName = node["Pharmacist"].InnerText; //Get pharmacist name string PresStatus = node["Completed"].InnerText; //get whether it has been completed XmlNodeList Items = node.SelectNodes("Item"); //make a list of items Prescription CurrentPrescript = new Prescription(Name); //create new class CurrentPrescript.SetDoctorName(Doctor); //set doc name CurrentPrescript.SetPharmacistName(PharaName); //set pharmacist name CurrentPrescript.SetPrice(ReadPrice); //set price CurrentPrescript.SetDateIssued(DateIssue); //set date issued CurrentPrescript.SetDateExpiry(DateExpiry); //set date expiry CurrentPrescript.SetCompleted(PresStatus); //set collected status foreach (XmlNode node2 in Items) //for all of the items { string NameItem = node2.InnerText; //get item name CurrentPrescript.AddItemNameList(NameItem); //add item to class string Number = node2.Attributes["Quantity"].InnerText; //get quantity CurrentPrescript.AddQuantity(Number); //add quantity to class } ParentListHolder.FinalPrescriptionList.Add(CurrentPrescript); //add class to class list index++; //next item } }
/// <summary> /// Read Prescriptions File XML /// </summary> public void ReadPrescriptionsFile() { XmlDocument PrescriptionFile = new XmlDocument(); PrescriptionFile.Load("CompletedPrescriptions.xml"); //Opens Prescriptions XML File XmlNodeList Prescript = PrescriptionFile.GetElementsByTagName("Prescription"); //Gets a List of Prescriptions int index = 0; //Prescription List Counter foreach (XmlNode node in Prescript) //For each prescription in the list { string Name = node["Name"].InnerText; //Get Patient Name string Doctor = node["Doctor"].InnerText; //Get Doctor Name string Price = node["Price"].InnerText; //Get Price string DateIssue = node["DateIssue"].InnerText; //Get Date Issued string DateExpiry = node["DateExpiry"].InnerText; //Get Expiry Date string PharaName = node["Pharmacist"].InnerText; //Get Pharmacist Name string PresStatus = node["Completed"].InnerText; //Get Whether it was collect or not XmlNodeList Items = node.SelectNodes("Item"); //Create a List of Items Prescription CurrentPrescript = new Prescription(Name); //Create a New Class CurrentPrescript.SetDoctorName(Doctor); CurrentPrescript.SetPrice(Price); CurrentPrescript.SetPharmacistName(PharaName); CurrentPrescript.SetDateIssued(DateIssue); CurrentPrescript.SetDateExpiry(DateExpiry); CurrentPrescript.SetCompleted(PresStatus); foreach (XmlNode node2 in Items) //For Every Item in the list { string NameItem = node2.InnerText; //get Item Name CurrentPrescript.AddItemNameList(NameItem); string Number = node2.Attributes["Quantity"].InnerText; //Get Quantity CurrentPrescript.AddQuantity(Number); } PrescriptionsList.Add(CurrentPrescript); //Add Class to Class List index++; //Move to Next Prescription } }
/// <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 } }