// below is the method that is used when user click the save button, the if loop calls the ISValidData method that calls the IsPresent method from the validator class // to check to see if data entered is valid and if valid new code, description and price are saved. private void btnSave_Click(object sender, System.EventArgs e) { if (IsValidData()) { sale = new Sale(txtCode.Text,txtDescription.Text, Convert.ToDecimal(txtPrice.Text)); this.Close(); } }
public static List<Sale> GetSales() { // create the list List<Sale> sales = new List<Sale>(); // create the XmlReaderSettings object XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; settings.IgnoreComments = true; // create the XmlReader object XmlReader xmlIn = XmlReader.Create(Path, settings); // read past all nodes to the first Sale node if (xmlIn.ReadToDescendant("Sale")) { // create one Sale object for each Sale node do { Sale sale = new Sale(); xmlIn.ReadStartElement("Sale"); sale.Code = xmlIn.ReadElementContentAsString(); sale.Description = xmlIn.ReadElementContentAsString(); sale.Price = xmlIn.ReadElementContentAsDecimal(); sales.Add(sale); } while (xmlIn.ReadToNextSibling("Sale")); } // close the XmlReader object xmlIn.Close(); return sales; }