Example #1
0
        private void addbutton_Click(object sender, EventArgs e)
        {
            if (voucherAmountField.Text == "" || voucherAmountField.Text == "Amount")
            {
                app.notifyTo(statusLabel, "Please enter the amount!", "warning");
            }
            if (voucherTypeField.Text == "" || voucherTypeField.Text == "Voucher Type")
            {
                app.notifyTo(statusLabel, "Please select the voucher type!", "warning");
            }
            if (voucherDescriptionField.Text == "" || voucherDescriptionField.Text == "Description")
            {
                app.notifyTo(statusLabel, "Please enter the description!", "warning");
            }

            if (voucherAmountField.Text != "" && voucherTypeField.Text != "" && voucherAmountField.Text != "" &&
                voucherAmountField.Text != "Amount" && voucherTypeField.Text != "Voucher Type" && voucherDescriptionField.Text != "Description")
            {
                Voucher voucher = new Voucher()
                {
                    amount      = int.Parse(voucherAmountField.Text),
                    type        = voucherTypeField.Text,
                    description = voucherDescriptionField.Text
                };

                addbutton.Enabled = false;
                int response = addService.MakeVoucher(voucher);
                addbutton.Enabled = true;
                if (response > 0)
                {
                    User    user        = app.getSession();
                    Voucher lastVoucher = getService.getLastVoucher(user.id);
                    Report  report      = new Report(0, lastVoucher.id, "#voucher");
                    report.ShowDialog();

                    voucherAmountField.Text      = "Amount";
                    voucherTypeField.Text        = "Voucher Type";
                    voucherDescriptionField.Text = "Description";
                    loadAccountBalance();
                }
                else
                {
                    if (response == -404)
                    {
                        app.notifyTo(statusLabel, "Voucher category doesn't exist!", "warning");
                    }
                    else if (response == -402)
                    {
                        app.notifyTo(statusLabel, "Insufficient funds!", "warning");
                    }
                    else if (response == -403)
                    {
                        app.notifyTo(statusLabel, "Oops! the voucher account not found!", "warning");
                    }
                    else
                    {
                        app.notifyTo(statusLabel, "Oops! unable to complete your transaction!", "warning");
                    }
                }
            }
        }