private async void btnRemove_Click(object sender, EventArgs e) { try { if (_transactionProductID > 0) { if (!_isFinishedSale) { var dialogResult = MetroMessageBox.Show(this, "Do you want to remove this product?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { var transactionProduct = await _transactionProductService.GetAsync(_transactionProductID); if (!transactionProduct.IsPaid) { await _transactionProductService.RemoveTransactionProductAsync(_transactionProductID); _transactionProductID = 0; } else { MetroMessageBox.Show(this, "Product is already paid. You cannot remove the product!", "Remove Product", MessageBoxButtons.OK, MessageBoxIcon.Error); } } await SetTransactionData(); await LoadProductsOnTransaction(); } else { MetroMessageBox.Show(this, "You cannot delete products with finished Point of Sale Transaction!", "Remove Product", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MetroMessageBox.Show(this, "No record selected to remove", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MetroMessageBox.Show(this, ex.ToString()); } }
private async Task SetTransactionProductData() { try { var transactionProduct = await _transactionProductService.GetAsync(_transactionProductID); lblProductName.Text = "Product Name: " + transactionProduct.ProductName; lblQuantity.Text = "Quantity: " + transactionProduct.Quantity; lblOfQuantityOnCancel.Text = "of " + transactionProduct.Quantity; lblOfQuantityOnReplace.Text = "of " + transactionProduct.Quantity; txtQuantityToCancel.Text = transactionProduct.Quantity.ToString(); txtQuantityToReplace.Text = transactionProduct.Quantity.ToString(); } catch (RecordNotFoundException ex) { MetroMessageBox.Show(this, "No product selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } catch (Exception ex) { MetroMessageBox.Show(this, ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }