private void computeTotalPrice() { try { //compute discount decimal _totalPrice = 0; decimal _qty = 0; decimal _discountAmount = 0; if (decimal.Parse(txtQty.Text) != 0) { _qty = decimal.Parse(txtQty.Text); } else { _qty = 0; } _totalPrice = _qty * decimal.Parse(txtUnitPrice.Text); try { foreach (DataRow _dr in loSalesDiscount.getAllData("", cboDiscount.SelectedValue.ToString(), "").Rows) { if (_dr["Type"].ToString() == "Percentage") { _discountAmount = _totalPrice * (decimal.Parse(_dr["Value"].ToString())) / 100; txtDiscountAmount.Text = string.Format("{0:n}", _discountAmount); } else { _discountAmount = decimal.Parse(txtDiscountAmount.Text); } } } catch { _discountAmount = 0; } txtTotalPrice.Text = string.Format("{0:n}", _totalPrice - _discountAmount); } catch { txtTotalPrice.Text = "0.00"; } }
private void AddDiscountUI_Load(object sender, EventArgs e) { cboDiscount.DataSource = loDiscount.getAllData("ViewAll", "", ""); cboDiscount.DisplayMember = "Description"; cboDiscount.ValueMember = "Id"; cboDiscount.SelectedIndex = -1; txtAmount.Text = "0.00"; txtPercentage.Text = "0.00"; chkVATExempt.Checked = false; txtDetails.Clear(); lDiscountId = ""; lDiscountDescription = ""; lAmount = 0; lPercentage = 0; lVATExempt = false; lDetails = ""; lFromClose = false; txtAmount.Enabled = false; txtPercentage.Enabled = false; }