ohbutt69

lollers in my drollers

Mar 21st, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Data.SqlClient;
  11.  
  12. namespace Bank_of_Glumorgan
  13. {
  14.     public partial class frmAccount : Form
  15.     {
  16.         DialogResult quitResult;
  17.         int accountID;
  18.         decimal balance;
  19.         decimal overdraft;
  20.         decimal withdraw;
  21.         frmMessageBox frmMessageBox = new frmMessageBox();
  22.  
  23.         string transactionType = "withdrawl";
  24.         decimal transactionAmount;
  25.         DateTime transactionDate;
  26.  
  27.         public frmAccount()
  28.         {
  29.             InitializeComponent();
  30.         }
  31.  
  32.         private void frmAccount_Load(object sender, EventArgs e)// Working
  33.         {
  34.             Text = dataClass.frmLoginCardNum;
  35.         }
  36.  
  37.         private void btnBalance_Click(object sender, EventArgs e)// Working
  38.         {
  39.             string accountQuery = "SELECT accountID FROM dbo.ATMCards WHERE (cardNumber = @cardNumber)";
  40.             SqlCommand balanceCommand = new SqlCommand(accountQuery, frmAccountSqlConnection);
  41.  
  42.             SqlParameter accountParameter = new SqlParameter("@cardNumber", SqlDbType.VarChar);
  43.             accountParameter.Value = dataClass.frmLoginCardNum;
  44.             balanceCommand.Parameters.Add(accountParameter);
  45.  
  46.             try
  47.             {
  48.                 frmAccountSqlConnection.Open();
  49.             }
  50.             catch (Exception ex)
  51.             {
  52.                 MessageBox.Show(ex.Message);
  53.             }
  54.             finally
  55.             {
  56.                 accountID = ((int)balanceCommand.ExecuteScalar());
  57.                 frmAccountSqlConnection.Close();
  58.             }
  59.  
  60.             string accountQuery2 = "SELECT balance FROM dbo.Accounts WHERE (accountID = @accountID)";
  61.             SqlCommand balanceCommand2 = new SqlCommand(accountQuery2, frmAccountSqlConnection);
  62.  
  63.             SqlParameter accountParameter2 = new SqlParameter("@accountID", SqlDbType.VarChar);
  64.             accountParameter2.Value = accountID;
  65.             balanceCommand2.Parameters.Add(accountParameter2);
  66.  
  67.             string accountQuery3 = "SELECT overdraftLimit FROM dbo.Accounts WHERE (accountID = @accountID)";
  68.             SqlCommand balanceCommand3 = new SqlCommand(accountQuery3, frmAccountSqlConnection);
  69.  
  70.             SqlParameter accountParameter3 = new SqlParameter("@accountID", SqlDbType.VarChar);
  71.             accountParameter3.Value = accountID;
  72.             balanceCommand3.Parameters.Add(accountParameter3);
  73.  
  74.             try
  75.             {
  76.                 frmAccountSqlConnection.Open();
  77.             }
  78.             catch (Exception ex)
  79.             {
  80.                 MessageBox.Show(ex.Message);
  81.             }
  82.             finally
  83.             {
  84.                 balance = ((decimal)balanceCommand2.ExecuteScalar());
  85.                 balance = decimal.Round(balance, 2);
  86.                 overdraft = ((decimal)balanceCommand3.ExecuteScalar());
  87.                 overdraft = decimal.Round(overdraft, 2);
  88.                 frmAccountSqlConnection.Close();
  89.             }
  90.  
  91.             lblBalance.Text = balance.ToString();
  92.             lblOverdraft.Text = overdraft.ToString();
  93.             lblPound2.Text = "£";
  94.             lblPound3.Text = "£";
  95.             btnWithdraw.Enabled = true;
  96.             btn5.Enabled = true;
  97.             btn10.Enabled = true;
  98.             btn20.Enabled = true;
  99.             btn30.Enabled = true;
  100.             btn40.Enabled = true;
  101.             btn50.Enabled = true;
  102.             btn100.Enabled = true;
  103.             btn200.Enabled = true;
  104.  
  105.         }
  106.  
  107.         private void btnWithdraw_Click(object sender, EventArgs e)
  108.         {
  109.             if (txtWithdraw.Text != "")
  110.             {
  111.                 try
  112.                 {
  113.                     withdraw = Convert.ToDecimal(txtWithdraw.Text);
  114.                     balance = Convert.ToDecimal(lblBalance.Text);
  115.                     overdraft = Convert.ToDecimal(lblOverdraft.Text);
  116.                 }
  117.                 catch (Exception ex)
  118.                 {
  119.                     MessageBox.Show(ex.Message);
  120.                 }
  121.  
  122.                 if (withdraw <= balance + overdraft)// enough funds
  123.                 {
  124.                     transactionAmount = withdraw;
  125.                     dataClass.frmMessageboxString = "card";
  126.                     frmMessageBox.ShowDialog();
  127.  
  128.                     if (dataClass.frmMessageBoxBool == true)
  129.                     {
  130.                         dataClass.frmMessageboxString = "cash";
  131.                         frmMessageBox.ShowDialog();
  132.  
  133.                         if (dataClass.frmMessageBoxBool == true)
  134.                         {
  135.                             //transaction succesful
  136.                             if (withdraw > balance)
  137.                             {
  138.                                 withdraw = withdraw - balance;
  139.                                 balance = 0;
  140.                                 overdraft = overdraft - withdraw;
  141.                                 try
  142.                                 {
  143.                                     //convert to string
  144.                                     txtWithdraw.Clear();
  145.                                     lblPound1.Text = "";
  146.                                     lblBalance.Text = Convert.ToString(balance);
  147.                                     lblOverdraft.Text = Convert.ToString(overdraft);
  148.                                 }
  149.                                 catch (Exception ex)
  150.                                 {
  151.                                     MessageBox.Show(ex.Message);
  152.                                 }
  153.                                 mthdWithdraw();
  154.                                 //mthdLogs();
  155.                             }
  156.                             else if (withdraw <= balance)
  157.                             {
  158.                                 balance = balance - withdraw;
  159.                                 try
  160.                                 {
  161.                                     //convert to string
  162.                                     lblBalance.Text = Convert.ToString(balance);
  163.                                     txtWithdraw.Clear();
  164.                                     lblPound1.Text = "";
  165.                                 }
  166.                                 catch (Exception ex)
  167.                                 {
  168.                                     MessageBox.Show(ex.Message);
  169.                                 }
  170.                                 mthdWithdraw();
  171.                                 //mthdLogs();
  172.                             }
  173.                      
  174.                             else if (dataClass.frmMessageBoxBool == false)
  175.                             {
  176.                                 //did not take cash
  177.                                 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);
  178.                             }
  179.                         }
  180.                         else if (dataClass.frmMessageBoxBool == false)
  181.                         {
  182.                             // did not take card
  183.                             MessageBox.Show("Your card has been confiscated", "Card confiscated", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  184.  
  185.                             string query = "UPDATE dbo.ATMCards SET confiscated = 1 WHERE (cardNumber = @cardNumber)";
  186.                             SqlCommand confiscateCommand = new SqlCommand(query, frmAccountSqlConnection);
  187.  
  188.                             SqlParameter parameterConfiscate = new SqlParameter("@cardNumber", SqlDbType.Int);
  189.                             parameterConfiscate.Value = dataClass.frmLoginCardNum;
  190.                             confiscateCommand.Parameters.Add(parameterConfiscate);
  191.                             try
  192.                             {
  193.                                 frmAccountSqlConnection.Open();
  194.                             }
  195.                             catch (Exception ex)
  196.                             {
  197.                                 MessageBox.Show(ex.Message);
  198.                             }
  199.                             finally
  200.                             {
  201.                                 confiscateCommand.ExecuteNonQuery();
  202.                                 frmAccountSqlConnection.Close();
  203.                             }
  204.  
  205.                             this.Close();
  206.                         }
  207.                     }
  208.                 }
  209.                     else if (withdraw > balance + overdraft)// not enough funds
  210.                     {
  211.                         MessageBox.Show("the amount you have requested exceeds the amount available", "Insufficient Funds", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  212.                     }
  213.             }
  214.         }
  215.  
  216.         private void btnMiniStatement_Click(object sender, EventArgs e)
  217.         {
  218.             frmMiniStatement frmMiniStatement = new frmMiniStatement();
  219.             frmMiniStatement.Show();
  220.         }
  221.  
  222.         private void btnQuit_Click(object sender, EventArgs e)// Working
  223.         {
  224.             quitResult = MessageBox.Show("Are you sure you want to quit?", "Program Closing", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  225.             if (quitResult == System.Windows.Forms.DialogResult.Yes)
  226.             {
  227.                 this.Close();
  228.             }
  229.         }
  230.  
  231.         private void btnAmount_Click(object sender, EventArgs e)// Working
  232.         {
  233.             Button buttonAmount = (Button)sender;
  234.             txtWithdraw.Text = buttonAmount.Text;
  235.             lblPound1.Text = "£";
  236.         }
  237.         private void mthdWithdraw()
  238.         {
  239.             string balanceQuery = "UPDATE dbo.Accounts SET balance = @balance WHERE (accountID = @accountID)";
  240.             SqlCommand balanceCommand = new SqlCommand(balanceQuery, frmAccountSqlConnection);
  241.  
  242.             SqlParameter balanceParameter = new SqlParameter("@balance", SqlDbType.Money);
  243.             balanceParameter.Value = balance;
  244.             balanceCommand.Parameters.Add(balanceParameter);
  245.  
  246.             balanceParameter = new SqlParameter("@accountID", SqlDbType.Int);
  247.             balanceParameter.Value = accountID;
  248.             balanceCommand.Parameters.Add(balanceParameter);
  249.  
  250.             string overdraftQuery = "UPDATE dbo.Accounts SET overdraftLimit = @overdraft WHERE (accountID = @accountID)";
  251.             SqlCommand overdraftCommand = new SqlCommand(overdraftQuery, frmAccountSqlConnection);
  252.  
  253.             SqlParameter overdraftParameter = new SqlParameter("@overdraft", SqlDbType.Money);
  254.             overdraftParameter.Value = overdraft;
  255.             overdraftCommand.Parameters.Add(overdraftParameter);
  256.  
  257.             overdraftParameter = new SqlParameter("@accountID", SqlDbType.Int);
  258.             overdraftParameter.Value = accountID;
  259.             overdraftCommand.Parameters.Add(overdraftParameter);
  260.  
  261.             try
  262.             {
  263.                 frmAccountSqlConnection.Open();
  264.             }
  265.             catch (Exception ex)
  266.             {
  267.                 MessageBox.Show(ex.Message);
  268.             }
  269.             finally
  270.             {
  271.                 balanceCommand.ExecuteNonQuery();
  272.                 overdraftCommand.ExecuteNonQuery();
  273.                 frmAccountSqlConnection.Close();
  274.             }
  275.         }
  276.         private void mthdLogs()
  277.         {
  278.             transactionDate = System.DateTime.Today;
  279.  
  280.             string insert = "INSERT INTO dbo.Log (id, cardNumber, transactionType, transactionAmount, transactionDate) Values(@id, @cardNumber, @transactiontype, @transactionAmount, @transactionDate)";
  281.             SqlCommand insertLog = new SqlCommand(insert, frmAccountSqlConnection);
  282.  
  283.             SqlParameter insertParameter = new SqlParameter("@id", SqlDbType.Int);
  284.             insertParameter.Value = null;
  285.             insertLog.Parameters.Add(insertParameter);
  286.  
  287.             insertParameter = new SqlParameter("@cardNumber", SqlDbType.VarChar);
  288.             insertParameter.Value = dataClass.frmLoginCardNum;
  289.             insertLog.Parameters.Add(insertParameter);
  290.  
  291.             insertParameter = new SqlParameter("@transactionType", SqlDbType.VarChar);
  292.             insertParameter.Value = transactionType;
  293.             insertLog.Parameters.Add(insertParameter);
  294.  
  295.             insertParameter = new SqlParameter("@transactionAmount", SqlDbType.Money);
  296.             insertParameter.Value = transactionAmount;
  297.             insertLog.Parameters.Add(insertParameter);
  298.  
  299.             insertParameter = new SqlParameter("@transactionDate", SqlDbType.DateTime);
  300.             insertParameter.Value = transactionDate;
  301.             insertLog.Parameters.Add(insertParameter);
  302.  
  303.             try
  304.             {
  305.                 frmAccountSqlConnection.Open();
  306.             }
  307.             catch (Exception ex)
  308.             {
  309.                 MessageBox.Show(ex.Message);
  310.             }
  311.             finally
  312.             {
  313.                 insertLog.ExecuteNonQuery();
  314.                 frmAccountSqlConnection.Close();
  315.             }
  316.         }
  317.     }
  318. }
Advertisement
Add Comment
Please, Sign In to add comment