Exemplo n.º 1
0
        /// <summary>
        /// Handles the LinkClicked event of the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lnkProcess_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //Create an instance of the local BankService
            transactionManager = new BankService.TransactionManagerClient();

            double?transaction;

            try
            {
                //Value is non-numeric or less than 0
                if (!Utility.Numeric.isNumeric(txtAmount.Text, System.Globalization.NumberStyles.AllowDecimalPoint))
                {
                    MessageBox.Show("Error - Amount entered must be a non-negative numeric value.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                //If the selected value of the combobox is Withdrawal, Bill Payment, or Transfer
                else if (descriptionComboBox.SelectedIndex >= 1 && descriptionComboBox.SelectedIndex <= 3)
                {
                    if (double.Parse(txtAmount.Text) > constructorData.BankAccount.Balance)
                    {
                        MessageBox.Show("Error - Insufficient funds.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    //Selected value is Withdrawal
                    else if (descriptionComboBox.SelectedIndex == 1)
                    {
                        transaction = transactionManager.Withdrawal(constructorData.BankAccount.BankAccountId, double.Parse(txtAmount.Text),
                                                                    "Withdrawal from " + constructorData.BankAccount.AccountNumber);
                        evaluateTransaction(transaction);
                    }
                    //Selected value is Bill Payament
                    else if (descriptionComboBox.SelectedIndex == 2)
                    {
                        transaction = transactionManager.BillPayment(constructorData.BankAccount.BankAccountId, double.Parse(txtAmount.Text),
                                                                     "Bill Payment from " + constructorData.BankAccount.AccountNumber + " to " +
                                                                     cboAccountPayee.SelectedValue.ToString());
                        evaluateTransaction(transaction);
                    }
                    //Selected value is Transfer
                    else if (descriptionComboBox.SelectedIndex == 3)
                    {
                        int accountId = int.Parse(cboAccountPayee.SelectedValue.ToString());

                        string toAccountNumber = db.BankAccounts.Where(x => x.BankAccountId == accountId).Select(x => x.AccountNumber).SingleOrDefault().ToString();

                        transaction = transactionManager.Transfer(constructorData.BankAccount.BankAccountId, int.Parse(cboAccountPayee.SelectedValue.ToString()),
                                                                  double.Parse(txtAmount.Text), "Transfer from " + constructorData.BankAccount.AccountNumber +
                                                                  " to " + toAccountNumber);
                        evaluateTransaction(transaction);
                    }
                }
                else
                {
                    transaction = transactionManager.Deposit(constructorData.BankAccount.BankAccountId, double.Parse(txtAmount.Text),
                                                             "Deposit to " + constructorData.BankAccount.AccountNumber);
                    evaluateTransaction(transaction);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error - Could not process your transaction.");
            }
        }