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*/ } }
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); }