Ejemplo n.º 1
0
        // Methods
        public void Load(string path)
        {
            if (!System.IO.File.Exists(path))
            {
                //MessageBox.Show("Billing history file not found - " + path);
                return;
            }

            var document = XDocument.Load(path);

            if (document.Root.Attribute("Version").Value != BillingHistoryFileVersion)
            {
                MessageBox.Show("Billing history file version is invalid - " + path);
                return;
            }

            Bills.Clear();

            foreach (XElement element in document.Root.Descendants())
            {
                if (element.Name == "Bill")
                {
                    var bill = new Bill
                    (
                         DateTime.Parse(element.Attribute("Date").Value)
                    )
                    {
                        Total = element.Attribute("Total").Value.AsMoney()
                    };

                    var products = element.Element("Products");
                    foreach (var sub in products.Elements())
                    {
                        var product = new Product
                        (
                            sub.Attribute("ID").Value.AsInteger(),
                            sub.Attribute("Name").Value,
                            sub.Attribute("Price").Value.AsDecimal()
                        );

                        bill.AddProduct(product, sub.Attribute("Amount").Value.AsInteger());
                    }

                    Bills.Add(bill);
                }
            }
        }
Ejemplo n.º 2
0
 // Methods
 private void FormMainLoad(object sender, EventArgs e)
 {
     CurrentBill = new Bill();
     _textBoxProduct.Focus();
 }
Ejemplo n.º 3
0
        private void BuyProduct(Product product)
        {
            Sum += product.Price;

            InsertNewOrder(product);

            if (CurrentBill == null)
            {
                CurrentBill = new Bill();
            }
            CurrentBill.Date = DateTime.Now;
            CurrentBill.AddProduct(product);
        }