Ejemplo n.º 1
0
        // confirm payment button
        private void button2_Click_1(object sender, EventArgs e)
        {
            // CREDIT CARD
            if (radioButton1.Checked == true)
            {
                // null and empty char checks

                if (txtName.Text == null || txtName.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                if (txtCCNumber.Text == null || txtCCNumber.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                if (txtCVV.Text == null || txtCVV.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                if (txtOTP.Text == null || txtOTP.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                // invalid entry checks
                Match matchCardHolderName = Regex.Match(txtName.Text, @"(?i)^[a-z]+");

                if (matchCardHolderName.Success == false)
                {
                    MessageBox.Show("Card holder name may only contain non-numeric characters (A-Z), (a-z).");
                    return;
                }

                if (!System.Text.RegularExpressions.Regex.IsMatch(txtCCNumber.Text, "^[0-9]+$"))
                {
                    MessageBox.Show("Card card number should only contain numeric values (0-9).");
                    return;
                }

                if (!System.Text.RegularExpressions.Regex.IsMatch(txtCVV.Text, "^[0-9]+$"))
                {
                    MessageBox.Show("CVV number should only contain numeric values (0-9).");
                    return;
                }

                if (!System.Text.RegularExpressions.Regex.IsMatch(txtOTP.Text, "^[0-9]+$"))
                {
                    MessageBox.Show("OTP Pin should only contain numeric values (0-9).");
                    return;
                }
            }

            // CASH PAYMENT
            if (radioButton2.Checked == true)
            {
                // null checks
                if (textBox7.Text == null || textBox7.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                if (textBox8.Text == null || textBox8.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                if (textBox5.Text == null || textBox5.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                if (textBox6.Text == null || textBox6.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                // invalid entry
                if (!System.Text.RegularExpressions.Regex.IsMatch(textBox7.Text, @"(?i)^[a-z]+"))
                {
                    MessageBox.Show("Name of payer should only contain non-numeric characters (A-Z), (a-z).");
                    return;
                }

                if (!System.Text.RegularExpressions.Regex.IsMatch(textBox8.Text, "^[0-9]+$"))
                {
                    MessageBox.Show("Payer ID should only contain numeric values (0-9).");
                    return;
                }

                if (!System.Text.RegularExpressions.Regex.IsMatch(textBox5.Text, @"(?i)^[a-z]+"))
                {
                    MessageBox.Show("Received By should only contain non-numeric characters (A-Z), (a-z).");
                    return;
                }

                if (!System.Text.RegularExpressions.Regex.IsMatch(textBox6.Text, @"(?i)^[a-z]+"))
                {
                    MessageBox.Show("Charged To should only contain non-numeric characters (A-Z), (a-z).");
                    return;
                }
            }

            // EFT
            if (radioButton3.Checked == true)
            {
                // null checks
                if (textBox4.Text == null || textBox4.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                if (textBox3.Text == null || textBox3.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                if (textBox2.Text == null || textBox2.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                if (textBox1.Text == null || textBox1.Text == "")
                {
                    MessageBox.Show("Fill in missing fields");
                    return;
                }

                // invalid entry
                if (!System.Text.RegularExpressions.Regex.IsMatch(textBox4.Text, @"(?i)^[a-z]+"))
                {
                    MessageBox.Show("Beneficiary name should only contain non-numeric characters (A-Z), (a-z).");
                    return;
                }

                if (!System.Text.RegularExpressions.Regex.IsMatch(textBox3.Text, @"(?i)^[a-z]+"))
                {
                    MessageBox.Show("Bank name should only contain non-numeric characters (A-Z), (a-z).");
                    return;
                }

                if (!System.Text.RegularExpressions.Regex.IsMatch(textBox2.Text, "^[0-9]+$"))
                {
                    MessageBox.Show("Account number should only contain numeric values (0-9).");
                    return;
                }

                if (!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, @"(?i)^[a-z]+"))
                {
                    MessageBox.Show("Branch name should only contain non-numeric characters (A-Z), (a-z).");
                    return;
                }
            }

            // FINANCIAL ENTRIES
            if (!System.Text.RegularExpressions.Regex.IsMatch(txtAmount.Text, "^[0-9]+$"))
            {
                MessageBox.Show("Amount field should only contain numeric values (0-9).");
                return;
            }

            // ADD A CHARGE
            if (rbnCharge.Checked == true)
            {
                Charge aCharge = new Charge();
                aCharge.Type   = cbxTypes.SelectedItem.ToString();
                aCharge.Amount = Convert.ToDecimal(txtAmount.Text);

                bool found = false;

                // link to account using id passport field of guests
                foreach (Account account in accountController.AllAccounts)
                {
                    if (account.IDPassport == txtIDPassport.Text.Trim())
                    {
                        found             = true;
                        aCharge.AccountID = Convert.ToInt32(account.AccountID);
                        break;
                    }
                }

                if (found == false)
                {
                    MessageBox.Show("An error has occurred. Please try again.");
                }
                else  // add charge
                {
                    aCharge.Type = cbxTypes.SelectedItem.ToString();
                    chargeController.DataMaintenance(aCharge, DatabaseLayer.DB.DBOperation.Add);
                    chargeController.FinalizeChanges(aCharge);

                    // defray balance in account
                    getAccount(txtIDPassport.Text);
                    aAccount.Balance += Convert.ToDecimal(txtAmount.Text);
                    accountController.DataMaintenance(aAccount, DatabaseLayer.DB.DBOperation.Edit);
                    accountController.FinalizeChanges(aAccount);

                    MessageBox.Show("Charge successfully added to account.");
                }

                return;
            }

            // ADD A PAYMENT
            if (rbnPayment.Checked == true)
            {
                Payment aPayment = new Payment();
                aPayment.Type   = cbxTypes.SelectedItem.ToString();
                aPayment.Amount = Convert.ToDecimal(txtAmount.Text);
                if (aAccount == null)
                {
                    getAccount(txtIDPassport.Text);
                }
                increaseBalance();
                bool found = false;
                // link to account using id passport field of guests
                foreach (Account account in accountController.AllAccounts)
                {
                    if (account.IDPassport == txtIDPassport.Text.Trim())
                    {
                        found = true;
                        aPayment.AccountID = Convert.ToInt32(account.AccountID);
                        break;
                    }
                }

                if (found == false)
                {
                    MessageBox.Show("An error has occurred. Please try again.");
                }
                else
                { // add payment
                    aPayment.Type = cbxTypes.SelectedItem.ToString();
                    paymentController.DataMaintenance(aPayment, DatabaseLayer.DB.DBOperation.Add);
                    paymentController.FinalizeChanges(aPayment);

                    // update account balance
                    getAccount(txtIDPassport.Text);

                    aAccount.Balance -= Convert.ToDecimal(txtAmount.Text);
                    accountController.DataMaintenance(aAccount, DatabaseLayer.DB.DBOperation.Edit);
                    accountController.FinalizeChanges(aAccount);
                    MessageBox.Show("Payment successfully added to account.");
                }
            }
        }