public static ObservableCollection<cls_Invoice> GetData() { ObservableCollection<cls_Invoice> list = new ObservableCollection<cls_Invoice>(); cls_Customer customer = new cls_Customer("Bob", 27); cls_Product product = new cls_Product(14, "Bike", 85.63); DateTime date = new DateTime(2015,12,1); cls_Invoice invoice = new cls_Invoice(1,customer, product, date); list.Add(invoice); customer = new cls_Customer("Tom", 85); product = new cls_Product(10, "Snowboard", 105.99); date = new DateTime(2015, 11, 30); invoice = new cls_Invoice(2, customer, product, date); list.Add(invoice); customer = new cls_Customer("Jared", 10); product = new cls_Product(17, "Kyak", 242.13); date = new DateTime(2015, 11, 22); invoice = new cls_Invoice(3, customer, product, date); list.Add(invoice); return list; }
/// <summary> /// Constructs an invoice with just one item /// </summary> /// <param name="cust">Customer</param> /// <param name="prod">Product Purchased</param> public cls_Invoice(int id, cls_Customer cust, cls_Product prod, DateTime d) { try { i_invId = id; customer = cust; productList = new List<cls_Product>(); productList.Add(prod); date = d; } catch (Exception ex) { //Just throw the exception throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
/// <summary> /// Removes a product from the invoice /// </summary> /// <param name="prod">Product to be removed</param> public void RemoveProduct(cls_Product prod) { try { //Check to see if that product is actually in the invoice foreach (cls_Product item in productList) { if (item.Equals(prod)) { productList.Remove(item); PropertyChanged(this, new PropertyChangedEventArgs("TotalCost")); return; } } } catch (Exception ex) { //Just throw the exception throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
/// <summary> /// Add an individual product to the invoice /// </summary> /// <param name="prod">Product to be added</param> public void AddProduct(cls_Product prod) { try { productList.Add(prod); //to notify the databinding of a change PropertyChanged(this, new PropertyChangedEventArgs("TotalCost")); } catch (Exception ex) { //Just throw the exception throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }