protected override void OnOpenNew() { int iInvoiceNumber; var firstOrDefault = ContextManager.Context.Sales.OrderByDescending(p => p.InvoiceNumber).FirstOrDefault(); if (firstOrDefault != null) { iInvoiceNumber = int.Parse(firstOrDefault.InvoiceNumber); iInvoiceNumber++; } else { iInvoiceNumber = 1; } Purchase = new CoffeePurchase { Date = DateTime.Now, PaymentDate = DateTime.Now, Paid = true, Account = ContextManager.ActiveAccounts.FirstOrDefault(), Supplier = ContextManager.ActiveSuppliers.FirstOrDefault(), InvoiceNumber = iInvoiceNumber.ToString() }; Details = new ObservableCollection <CoffeePurchaseDetails>(); }
private void cmdPay_Execute(object arg) { wrapCoffeePurchase wrapperPurchase = arg as wrapCoffeePurchase; if (wrapperPurchase != null) { CoffeePurchase purchase = wrapperPurchase.Purchase; if (purchase.PaymentDate == null) { return; } purchase.Paid = true; // Change account balance ContextManager.Context.dAccountsBalances.First( p => p.Account.Id == purchase.Account.Id).Balance -= wrapperPurchase.Sum; // Add new transaction ContextManager.Context.dTransactions.Add(new dTransaction { Account = purchase.Account, Date = (DateTime)purchase.PaymentDate, Description = "Закупка кофе", Participant = purchase.Supplier.Name, Sum = -wrapperPurchase.Sum }); } wrapSale wrapperSale = arg as wrapSale; if (wrapperSale != null) { Sale sale = wrapperSale.Sale; if (sale.PaymentDate == null) { return; } sale.Paid = true; // Change account balance ContextManager.Context.dAccountsBalances.First( p => p.Account.Id == sale.Account.Id).Balance += wrapperSale.Sum; // Add new transaction ContextManager.Context.dTransactions.Add(new dTransaction { Account = sale.Account, Date = (DateTime)sale.PaymentDate, Description = "Продажа кофе", Participant = sale.Recipient.Name, Sum = wrapperSale.Sum }); } ContextManager.Context.SaveChanges(); }
protected override void OnOpenEdit(object argEntity) { Purchase = argEntity as CoffeePurchase; _oldPurchase = Purchase.Clone(); Details = new ObservableCollection <CoffeePurchaseDetails>(Purchase.CoffeePurchaseDetails); }