//PRIVATE LOGIC private void AfterProductPickAction(Product product) { if (OperationsViewService.GetAllProductIds().Contains(product.Id)) { Presenter.Loggable.Log(ProductAlreadyChosen); return; } OperationsViewService.AddSelectedProduct(OperationsViewService.GetCurrentRow(), product); }
public override void UpdateTotalPriceAction(int rowId) { try { var quantity = (double)OperationsViewService.GetDataAtRow(rowId, ProductQuantity); var prodPrice = (double)OperationsViewService.GetDataAtRow(rowId, ProductSellPrice); OperationsViewService.SetDataAtRow(rowId, TransactionTotalValue, $"{quantity * prodPrice:F2}"); } catch (Exception) { /*ignored*/ } }
public void CreateTransactionAction() { try { var products = GatherProductsForTransaction(); if (products.Count < 1) { Presenter.Loggable.Log(ChooseAtLeastOneProduct); return; } TransactionDbService.AddTransaction(products); OperationsViewService.ClearRows(); Presenter.Loggable.Log(SuccessfulOperation); } catch (ArgumentException e) { Presenter.Loggable.Log(e.Message); } }
public void RefreshGridAction() { TotalSumBox.Text = $@"{OperationsViewService.RefreshGrid():F2}"; }
public void Initialize() { OperationsViewService.Initialize(); }
public void CancelOperation() { OperationsViewService.ClearRows(); RefreshGridAction(); }
protected List <TransactionProduct> GetProductsFromDataGrid(TransactionType transactionType) { var products = new List <TransactionProduct>(); for (var i = 0; i < OperationsViewService.GetRowsCount(); i++) { //var row = this.OperationsViewService.DataGrid.Rows[i]; var transactionNumber = OperationsViewService.GetDataAtRow(i, TransactionNumber); var productId = -1; var selectedProductQuantity = 0D; Product product; try { var prodIdCell = OperationsViewService.GetDataAtRow(i, ProductId); if (prodIdCell == null) { continue; } productId = (int)prodIdCell; product = ProductDbService.FindById(productId); if (product == null) { throw new Exception(); } selectedProductQuantity = double.Parse(OperationsViewService.GetDataAtRow(i, ProductQuantity) + ""); } catch (Exception) { throw new ArgumentException($"{ThereWasAnErrorOnRow} {transactionNumber}"); } if (selectedProductQuantity <= 0D) { throw new ArgumentException($"{ChooseValidQuantity} {transactionNumber}"); } if (transactionType == TransactionType.SALE) { if (product.Quantity < selectedProductQuantity) { throw new ArgumentException($"{InsufficientAmount} {transactionNumber}"); } } var subTotal = 0.0; switch (transactionType) { case TransactionType.SALE: subTotal = product.SellPrice * selectedProductQuantity; break; case TransactionType.DELIVERY: subTotal = product.ImportPrice * selectedProductQuantity; break; } var productTransaction = new TransactionProduct { ProductId = product.Id, ProductQuantity = selectedProductQuantity, SubTotalPrice = subTotal }; products.Add(productTransaction); } return(products); }