// 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);
                }
            }
        }
示例#2
0
 // Methods
 private void FormMainLoad(object sender, EventArgs e)
 {
     CurrentBill = new Bill();
     _textBoxProduct.Focus();
 }
示例#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);
        }