// Methods public static void Load(string path) { if (!System.IO.File.Exists(path)) { return; } var document = XDocument.Load(path); if (document.Root.Attribute("Version").Value != DataReaderFileVersion) { MessageBox.Show("Data file version is invalid - " + path); return; } Program.Environment.Products.Clear(); foreach (XElement element in document.Root.Descendants()) { if (element.Name == "Product") { var product = new Product ( element.Attribute("ID").Value.AsInteger(), element.Attribute("Name").Value, element.Attribute("Price").Value.AsDecimal() ); product.Description = element.Element("Description").Value; Program.Environment.Products.Add(product); } } }
public BillEntry(Product product, int count) { Index = product.Index; Name = product.Name; Description = product.Description; Price = product.Price; Amount = count; }
public void AddProduct(Product product, int count) { Total += product.Price * count; if (Products.Find(p => p.Index == product.Index) != null) { var temp = Products.Find(p => p.Index == product.Index); temp.Amount += count; } else { Products.Add(new BillEntry(product, count)); } }
private void ButtonProductChange(Product product) { var productView = new FormProductView(product); if (productView.ShowDialog() == DialogResult.OK) { if (!Environment.HasProduct(productView.Product.Index)) { Environment.Products.Add(productView.Product); } else { Environment.Products[productView.Product.Index - 1] = productView.Product; } Reload(); } }
// 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); } } }
public FormProductView(Product product) { InitializeComponent(); Product = product; if (Config.Get<bool>("billing.vat.enable")) { _radioButtonVat19.Select(); } else { _radioButtonVatZero.Select(); _radioButtonVatZero.Enabled = false; _radioButtonVat7.Enabled = false; _radioButtonVat19.Enabled = false; _textBoxPriceNet.Enabled = false; } }
// Constructor public BillEntry(Product product) : this(product, 1) { }
// Methods public void AddProduct(Product product) { AddProduct(product, 1); }
private void InsertNewOrder(Product product) { var item = new ListViewItem(product.ListViewKey) { Name = product.ListViewKey }; item.SubItems.Add(product.Name); item.SubItems.Add("1"); item.SubItems.Add(product.Price.ToString(ProductHelper.DecimalFormat)); item.SubItems.Add(product.Price.ToString(ProductHelper.DecimalFormat)); if (_listView.Items.ContainsKey(product.ListViewKey)) { var listViewItem = _listView.Items[product.ListViewKey]; var amount = listViewItem.SubItems.At(ProductListViewOrder.Amount).Text.AsInteger(); var price = listViewItem.SubItems.At(ProductListViewOrder.Price).Text.AsMoney(); amount++; listViewItem.SubItems.At(ProductListViewOrder.Amount).Text = amount.ToString(); listViewItem.SubItems.At(ProductListViewOrder.Total).Text = (price * amount).ToString(ProductHelper.DecimalFormat); } else { _listView.Items.Add(item); } }
private void BuyProduct(Product product) { Sum += product.Price; InsertNewOrder(product); if (CurrentBill == null) { CurrentBill = new Bill(); } CurrentBill.Date = DateTime.Now; CurrentBill.AddProduct(product); }
private void ButtonAcceptClick(object sender, EventArgs e) { if (_buttonAccept.Tag == null) { CaluclateVat(); _buttonAccept.Text = "OK"; _buttonAccept.Tag = 1; } else { var index = _textBoxID.IntValue; var name = _textBoxName.Text; var price = _textBoxPriceGross.MoneyValue; var net = _textBoxPriceNet.MoneyValue; var desc = _textBoxDesc.Text; if (index < 0) { MessageBox.Show("Ungültige Produkt-ID"); return; } if (string.IsNullOrEmpty(name)) { MessageBox.Show("Ungültiger Name"); return; } if (price < 0.00m) { MessageBox.Show("Ungültiger Preis"); return; } if (Product == null) { Product = new Product(index, name, price); } else { Product.Name = name; Product.Price = price; Product.PriceN = net; Product.Description = desc; } DialogResult = DialogResult.OK; } }