Пример #1
0
        /// <summary>
        /// Used to process all valid transaction records
        /// </summary>
        /// <param name="transactionRecords">The records to be processed</param>
        private void processTransactions(IEnumerable <XElement> transactionRecords)
        {
            foreach (XElement transaction in transactionRecords)
            {
                double?     balance         = 0;
                long        accountNo       = long.Parse(transaction.Element("account_no").Value);
                string      transactionType = string.Empty;
                BankAccount account         = db.BankAccounts.Where(x => x.AccountNumber ==
                                                                    accountNo).SingleOrDefault();

                if (int.Parse(transaction.Element("type").Value) == 2)
                {
                    balance = transactionManager.Withdrawal(account.BankAccountId, double.Parse(transaction.Element("amount").Value),
                                                            transaction.Element("notes").Value);
                    transactionType = "Transaction Completed Successfully: Withdrawal $" +
                                      transaction.Element("amount").Value + " from account " + account.AccountNumber + "\n";
                }
                else if (int.Parse(transaction.Element("type").Value) == 6)
                {
                    balance         = transactionManager.CalculateInterest(account.BankAccountId, transaction.Element("notes").Value);
                    transactionType = "Transaction Completed Successfully: Interest charged to account "
                                      + account.AccountNumber + "\n";
                }

                if (balance != null)
                {
                    logData += transactionType;
                }
            }
        }
Пример #2
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.");
            }
        }