private void button14_Click(object sender, EventArgs e) { frmDiscount frm = new frmDiscount(); frm.OriginalAmt = Program.cartItems.Sum(p => p.Price); if (IsDiscount) { frm.DiscountType = DiscountType; frm.DiscountAmt = DiscountAmt; } frm.ShowDialog(); DiscountType = frm.DiscountType; DiscountAmt = frm.DiscountAmt; if (DiscountAmt > 0) { IsDiscount = true; if (DiscountType == EmDiscountType.Amount) { var _FinalAmt = frm.OriginalAmt - DiscountAmt; BindData(_FinalAmt); //RemAmount = RemAmount - DiscountAmt; } else if (DiscountType == EmDiscountType.Percent) { var _FinalAmt = frm.OriginalAmt - ((frm.OriginalAmt * DiscountAmt) / 100); BindData(_FinalAmt); } //BindData(RemAmount); txtAmount_TextChanged(txtAmount, null); } }
private void btnApply_Click(object sender, EventArgs e) { Double _discountAmt = 0; Double.TryParse(txtAmt.Text.Trim(), out _discountAmt); Double PercentAmt = 0; Double.TryParse(txtPercent.Text.Trim(), out PercentAmt); //Both Are Null if (String.IsNullOrEmpty(txtAmt.Text.Trim()) && String.IsNullOrEmpty(txtPercent.Text.Trim())) { MessageBox.Show("Both Amount/Percent are Empty!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtAmt.Focus(); } //Both are not Null else if (!String.IsNullOrEmpty(txtAmt.Text.Trim()) && !String.IsNullOrEmpty(txtPercent.Text.Trim())) { MessageBox.Show("Apply Either Amount or Percent!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtAmt.Text = txtPercent.Text = String.Empty; } else if (!String.IsNullOrEmpty(txtAmt.Text.Trim())) { if (_discountAmt < 0) { //Show Message for Minus values MessageBox.Show("Amount cannot be Less than or equal to 0.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtAmt.Text = ""; txtAmt.Focus(); } else if (_discountAmt > OriginalAmt) { //Show Message for Minus values MessageBox.Show("Discount Amount cannot be greater than or equal to original Price.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtAmt.Text = ""; txtAmt.Focus(); } else { DiscountType = EmDiscountType.Amount; DiscountAmt = _discountAmt; this.Close(); } } else if (!String.IsNullOrEmpty(txtPercent.Text.Trim())) { if (PercentAmt < 0) { //Show Message for Minus Percentage MessageBox.Show("Percent cannot be Less than or equal to 0.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPercent.Text = "0.00"; txtPercent.Focus(); } else if (PercentAmt >= 100) { MessageBox.Show("100% Discount cannot be applied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPercent.Text = "0.00"; txtPercent.Focus(); } else { DiscountType = EmDiscountType.Percent; DiscountAmt = PercentAmt; this.Close(); } } }