Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Data.SqlClient;
- namespace Bank_of_Glumorgan
- {
- public partial class frmAccount : Form
- {
- DialogResult quitResult;
- int accountID;
- decimal balance;
- decimal overdraft;
- decimal withdraw;
- frmMessageBox frmMessageBox = new frmMessageBox();
- string transactionType = "withdrawl";
- decimal transactionAmount;
- DateTime transactionDate;
- public frmAccount()
- {
- InitializeComponent();
- }
- private void frmAccount_Load(object sender, EventArgs e)// Working
- {
- Text = dataClass.frmLoginCardNum;
- }
- private void btnBalance_Click(object sender, EventArgs e)// Working
- {
- string accountQuery = "SELECT accountID FROM dbo.ATMCards WHERE (cardNumber = @cardNumber)";
- SqlCommand balanceCommand = new SqlCommand(accountQuery, frmAccountSqlConnection);
- SqlParameter accountParameter = new SqlParameter("@cardNumber", SqlDbType.VarChar);
- accountParameter.Value = dataClass.frmLoginCardNum;
- balanceCommand.Parameters.Add(accountParameter);
- try
- {
- frmAccountSqlConnection.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- accountID = ((int)balanceCommand.ExecuteScalar());
- frmAccountSqlConnection.Close();
- }
- string accountQuery2 = "SELECT balance FROM dbo.Accounts WHERE (accountID = @accountID)";
- SqlCommand balanceCommand2 = new SqlCommand(accountQuery2, frmAccountSqlConnection);
- SqlParameter accountParameter2 = new SqlParameter("@accountID", SqlDbType.VarChar);
- accountParameter2.Value = accountID;
- balanceCommand2.Parameters.Add(accountParameter2);
- string accountQuery3 = "SELECT overdraftLimit FROM dbo.Accounts WHERE (accountID = @accountID)";
- SqlCommand balanceCommand3 = new SqlCommand(accountQuery3, frmAccountSqlConnection);
- SqlParameter accountParameter3 = new SqlParameter("@accountID", SqlDbType.VarChar);
- accountParameter3.Value = accountID;
- balanceCommand3.Parameters.Add(accountParameter3);
- try
- {
- frmAccountSqlConnection.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- balance = ((decimal)balanceCommand2.ExecuteScalar());
- balance = decimal.Round(balance, 2);
- overdraft = ((decimal)balanceCommand3.ExecuteScalar());
- overdraft = decimal.Round(overdraft, 2);
- frmAccountSqlConnection.Close();
- }
- lblBalance.Text = balance.ToString();
- lblOverdraft.Text = overdraft.ToString();
- lblPound2.Text = "£";
- lblPound3.Text = "£";
- btnWithdraw.Enabled = true;
- btn5.Enabled = true;
- btn10.Enabled = true;
- btn20.Enabled = true;
- btn30.Enabled = true;
- btn40.Enabled = true;
- btn50.Enabled = true;
- btn100.Enabled = true;
- btn200.Enabled = true;
- }
- private void btnWithdraw_Click(object sender, EventArgs e)
- {
- if (txtWithdraw.Text != "")
- {
- try
- {
- withdraw = Convert.ToDecimal(txtWithdraw.Text);
- balance = Convert.ToDecimal(lblBalance.Text);
- overdraft = Convert.ToDecimal(lblOverdraft.Text);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- if (withdraw <= balance + overdraft)// enough funds
- {
- transactionAmount = withdraw;
- dataClass.frmMessageboxString = "card";
- frmMessageBox.ShowDialog();
- if (dataClass.frmMessageBoxBool == true)
- {
- dataClass.frmMessageboxString = "cash";
- frmMessageBox.ShowDialog();
- if (dataClass.frmMessageBoxBool == true)
- {
- //transaction succesful
- if (withdraw > balance)
- {
- withdraw = withdraw - balance;
- balance = 0;
- overdraft = overdraft - withdraw;
- try
- {
- //convert to string
- txtWithdraw.Clear();
- lblPound1.Text = "";
- lblBalance.Text = Convert.ToString(balance);
- lblOverdraft.Text = Convert.ToString(overdraft);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- mthdWithdraw();
- //mthdLogs();
- }
- else if (withdraw <= balance)
- {
- balance = balance - withdraw;
- try
- {
- //convert to string
- lblBalance.Text = Convert.ToString(balance);
- txtWithdraw.Clear();
- lblPound1.Text = "";
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- mthdWithdraw();
- //mthdLogs();
- }
- else if (dataClass.frmMessageBoxBool == false)
- {
- //did not take cash
- MessageBox.Show("You did not take your cash in time, it has been returned to the machine. You have not been debitted for this transaction.", "Cash Returned", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- }
- else if (dataClass.frmMessageBoxBool == false)
- {
- // did not take card
- MessageBox.Show("Your card has been confiscated", "Card confiscated", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- string query = "UPDATE dbo.ATMCards SET confiscated = 1 WHERE (cardNumber = @cardNumber)";
- SqlCommand confiscateCommand = new SqlCommand(query, frmAccountSqlConnection);
- SqlParameter parameterConfiscate = new SqlParameter("@cardNumber", SqlDbType.Int);
- parameterConfiscate.Value = dataClass.frmLoginCardNum;
- confiscateCommand.Parameters.Add(parameterConfiscate);
- try
- {
- frmAccountSqlConnection.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- confiscateCommand.ExecuteNonQuery();
- frmAccountSqlConnection.Close();
- }
- this.Close();
- }
- }
- }
- else if (withdraw > balance + overdraft)// not enough funds
- {
- MessageBox.Show("the amount you have requested exceeds the amount available", "Insufficient Funds", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- }
- }
- private void btnMiniStatement_Click(object sender, EventArgs e)
- {
- frmMiniStatement frmMiniStatement = new frmMiniStatement();
- frmMiniStatement.Show();
- }
- private void btnQuit_Click(object sender, EventArgs e)// Working
- {
- quitResult = MessageBox.Show("Are you sure you want to quit?", "Program Closing", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (quitResult == System.Windows.Forms.DialogResult.Yes)
- {
- this.Close();
- }
- }
- private void btnAmount_Click(object sender, EventArgs e)// Working
- {
- Button buttonAmount = (Button)sender;
- txtWithdraw.Text = buttonAmount.Text;
- lblPound1.Text = "£";
- }
- private void mthdWithdraw()
- {
- string balanceQuery = "UPDATE dbo.Accounts SET balance = @balance WHERE (accountID = @accountID)";
- SqlCommand balanceCommand = new SqlCommand(balanceQuery, frmAccountSqlConnection);
- SqlParameter balanceParameter = new SqlParameter("@balance", SqlDbType.Money);
- balanceParameter.Value = balance;
- balanceCommand.Parameters.Add(balanceParameter);
- balanceParameter = new SqlParameter("@accountID", SqlDbType.Int);
- balanceParameter.Value = accountID;
- balanceCommand.Parameters.Add(balanceParameter);
- string overdraftQuery = "UPDATE dbo.Accounts SET overdraftLimit = @overdraft WHERE (accountID = @accountID)";
- SqlCommand overdraftCommand = new SqlCommand(overdraftQuery, frmAccountSqlConnection);
- SqlParameter overdraftParameter = new SqlParameter("@overdraft", SqlDbType.Money);
- overdraftParameter.Value = overdraft;
- overdraftCommand.Parameters.Add(overdraftParameter);
- overdraftParameter = new SqlParameter("@accountID", SqlDbType.Int);
- overdraftParameter.Value = accountID;
- overdraftCommand.Parameters.Add(overdraftParameter);
- try
- {
- frmAccountSqlConnection.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- balanceCommand.ExecuteNonQuery();
- overdraftCommand.ExecuteNonQuery();
- frmAccountSqlConnection.Close();
- }
- }
- private void mthdLogs()
- {
- transactionDate = System.DateTime.Today;
- string insert = "INSERT INTO dbo.Log (id, cardNumber, transactionType, transactionAmount, transactionDate) Values(@id, @cardNumber, @transactiontype, @transactionAmount, @transactionDate)";
- SqlCommand insertLog = new SqlCommand(insert, frmAccountSqlConnection);
- SqlParameter insertParameter = new SqlParameter("@id", SqlDbType.Int);
- insertParameter.Value = null;
- insertLog.Parameters.Add(insertParameter);
- insertParameter = new SqlParameter("@cardNumber", SqlDbType.VarChar);
- insertParameter.Value = dataClass.frmLoginCardNum;
- insertLog.Parameters.Add(insertParameter);
- insertParameter = new SqlParameter("@transactionType", SqlDbType.VarChar);
- insertParameter.Value = transactionType;
- insertLog.Parameters.Add(insertParameter);
- insertParameter = new SqlParameter("@transactionAmount", SqlDbType.Money);
- insertParameter.Value = transactionAmount;
- insertLog.Parameters.Add(insertParameter);
- insertParameter = new SqlParameter("@transactionDate", SqlDbType.DateTime);
- insertParameter.Value = transactionDate;
- insertLog.Parameters.Add(insertParameter);
- try
- {
- frmAccountSqlConnection.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- insertLog.ExecuteNonQuery();
- frmAccountSqlConnection.Close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment