Advertisement
Guest User

Untitled

a guest
May 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.88 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.Data.OleDb;
  10. using System.IO;
  11.  
  12. namespace Descartes
  13. {
  14.     public partial class frmTop : Form
  15.     {
  16.         public frmTop()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         int Sum = 0;
  22.         OleDbConnection con;
  23.         DataSet ds;
  24.         OleDbDataAdapter da;
  25.  
  26.         int TempBalance;
  27.         int MaxRows = 0;
  28.         string User = "";
  29.  
  30.  
  31.         private void mainMenuToolStripMenuItem3_Click(object sender, EventArgs e)
  32.         {
  33.             // Goes to the Main Menu Page
  34.  
  35.             frmMainMenu frm = new frmMainMenu();
  36.             frm.Show();
  37.             this.Hide();
  38.         }
  39.  
  40.         private void catalogueToolStripMenuItem3_Click(object sender, EventArgs e)
  41.         {
  42.             // Goes to the Catalogue Page
  43.  
  44.             frmCatalogue frm = new frmCatalogue();
  45.             frm.Show();
  46.             this.Hide();
  47.         }
  48.  
  49.         private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  50.         {
  51.             Application.Exit();
  52.         }
  53.  
  54.         private void tmrFadeIn_Tick(object sender, EventArgs e)
  55.         {
  56.             //Fades the page in
  57.  
  58.             this.Opacity += 0.02;
  59.         }
  60.  
  61.         private void tmrWait_Tick(object sender, EventArgs e)
  62.         {
  63.             //Stops the fade in function
  64.  
  65.             tmrFadeIn.Enabled = false;
  66.         }
  67.  
  68.         private void button1_Click(object sender, EventArgs e)
  69.         {
  70.             // Goes to the Main Menu Page
  71.  
  72.             frmMainMenu frm = new frmMainMenu();
  73.             frm.Show();
  74.             this.Hide();
  75.         }
  76.  
  77.         private void accountInformationToolStripMenuItem3_Click(object sender, EventArgs e)
  78.         {
  79.             // Goes to the Account Information Page
  80.  
  81.             frmAccount frm = new frmAccount();
  82.             frm.Show();
  83.             this.Hide();
  84.         }
  85.  
  86.         private void logoutToolStripMenuItem3_Click(object sender, EventArgs e)
  87.         {
  88.             // Goes to the Login Page
  89.  
  90.             frmLogin frm = new frmLogin();
  91.             frm.Show();
  92.             this.Hide();
  93.         }
  94.  
  95.         private void frmTop_Load(object sender, EventArgs e)
  96.         {
  97.             string file_name = "user.ini";
  98.  
  99.             System.IO.StreamReader objReader;
  100.             objReader = new System.IO.StreamReader(file_name);    //Reads the text file and saves it as a variable
  101.             User = objReader.ReadLine().ToString();
  102.  
  103.             objReader.Close();
  104.  
  105.  
  106.  
  107.             con = new OleDbConnection();
  108.  
  109.             con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " + Application.StartupPath + "\\..\\..\\banking.mdb"; //connection to database
  110.             con.Open();
  111.  
  112.             ds = new DataSet();
  113.  
  114.             string sql = "SELECT * From account";
  115.             da = new OleDbDataAdapter(sql, con);
  116.             da.Fill(ds, "UserList");
  117.             MaxRows = ds.Tables["UserList"].Rows.Count;
  118.  
  119.             string Balance;
  120.             int User_int;
  121.             int user;
  122.             User_int = Convert.ToInt32(User);
  123.             user = User_int - 2;      //user is just the row which the logged in user is situated on
  124.             DataRow dRow = ds.Tables["UserList"].Rows[user];
  125.             Balance = dRow.ItemArray.GetValue(3).ToString();
  126.  
  127.             label3.Text = Balance + ".00";
  128.  
  129.             con.Close();
  130.             con.Dispose();
  131.         }
  132.  
  133.         private void btnTopUp_Click(object sender, EventArgs e)
  134.         {
  135.             if (radioButton1.Checked == true)
  136.             {
  137.                 Sum = 5;
  138.                 radioButton1.Checked = false;
  139.                 radioButton2.Checked = false;
  140.                 radioButton3.Checked = false;
  141.                 radioButton4.Checked = false;
  142.                 radioButton5.Checked = false;
  143.                 radioButton6.Checked = false;
  144.                 radioButton7.Checked = false;
  145.                 radioButton8.Checked = false;
  146.                 radioButton9.Checked = false;
  147.                 radioButton11.Checked = false;
  148.                 radioButton12.Checked = false;
  149.             }
  150.  
  151.             if (radioButton2.Checked == true)
  152.             {
  153.                 Sum = 10;
  154.                 radioButton1.Checked = false;
  155.                 radioButton2.Checked = false;
  156.                 radioButton3.Checked = false;
  157.                 radioButton4.Checked = false;
  158.                 radioButton5.Checked = false;
  159.                 radioButton6.Checked = false;
  160.                 radioButton7.Checked = false;
  161.                 radioButton8.Checked = false;
  162.                 radioButton9.Checked = false;
  163.                 radioButton11.Checked = false;
  164.                 radioButton12.Checked = false;
  165.             }
  166.  
  167.             if (radioButton3.Checked == true)
  168.             {
  169.                 Sum = 20;
  170.                 radioButton1.Checked = false;
  171.                 radioButton2.Checked = false;
  172.                 radioButton3.Checked = false;
  173.                 radioButton4.Checked = false;
  174.                 radioButton5.Checked = false;
  175.                 radioButton6.Checked = false;
  176.                 radioButton7.Checked = false;
  177.                 radioButton8.Checked = false;
  178.                 radioButton9.Checked = false;
  179.                 radioButton11.Checked = false;
  180.                 radioButton12.Checked = false;
  181.             }
  182.  
  183.             if (radioButton4.Checked == true)
  184.             {
  185.                 Sum = 250;
  186.                 radioButton1.Checked = false;
  187.                 radioButton2.Checked = false;
  188.                 radioButton3.Checked = false;
  189.                 radioButton4.Checked = false;
  190.                 radioButton5.Checked = false;
  191.                 radioButton6.Checked = false;
  192.                 radioButton7.Checked = false;
  193.                 radioButton8.Checked = false;
  194.                 radioButton9.Checked = false;
  195.                 radioButton11.Checked = false;
  196.                 radioButton12.Checked = false;
  197.             }
  198.  
  199.             if (radioButton5.Checked == true)
  200.             {
  201.                 Sum = 100;
  202.                 radioButton1.Checked = false;
  203.                 radioButton2.Checked = false;
  204.                 radioButton3.Checked = false;
  205.                 radioButton4.Checked = false;
  206.                 radioButton5.Checked = false;
  207.                 radioButton6.Checked = false;
  208.                 radioButton7.Checked = false;
  209.                 radioButton8.Checked = false;
  210.                 radioButton9.Checked = false;
  211.                 radioButton11.Checked = false;
  212.                 radioButton12.Checked = false;
  213.             }
  214.  
  215.             if (radioButton6.Checked == true)
  216.             {
  217.                 Sum = 50;
  218.                 radioButton1.Checked = false;
  219.                 radioButton2.Checked = false;
  220.                 radioButton3.Checked = false;
  221.                 radioButton4.Checked = false;
  222.                 radioButton5.Checked = false;
  223.                 radioButton6.Checked = false;
  224.                 radioButton7.Checked = false;
  225.                 radioButton8.Checked = false;
  226.                 radioButton9.Checked = false;
  227.                 radioButton11.Checked = false;
  228.                 radioButton12.Checked = false;
  229.             }
  230.  
  231.             if (radioButton7.Checked == true)
  232.             {
  233.                 Sum = 2500;
  234.                 radioButton1.Checked = false;
  235.                 radioButton2.Checked = false;
  236.                 radioButton3.Checked = false;
  237.                 radioButton4.Checked = false;
  238.                 radioButton5.Checked = false;
  239.                 radioButton6.Checked = false;
  240.                 radioButton7.Checked = false;
  241.                 radioButton8.Checked = false;
  242.                 radioButton9.Checked = false;
  243.                 radioButton11.Checked = false;
  244.                 radioButton12.Checked = false;
  245.             }
  246.  
  247.             if (radioButton8.Checked == true)
  248.             {
  249.                 Sum = 1000;
  250.                 radioButton1.Checked = false;
  251.                 radioButton2.Checked = false;
  252.                 radioButton3.Checked = false;
  253.                 radioButton4.Checked = false;
  254.                 radioButton5.Checked = false;
  255.                 radioButton6.Checked = false;
  256.                 radioButton7.Checked = false;
  257.                 radioButton8.Checked = false;
  258.                 radioButton9.Checked = false;
  259.                 radioButton11.Checked = false;
  260.                 radioButton12.Checked = false;
  261.             }
  262.  
  263.             if (radioButton9.Checked == true)
  264.             {
  265.                 Sum = 500;
  266.                 radioButton1.Checked = false;
  267.                 radioButton2.Checked = false;
  268.                 radioButton3.Checked = false;
  269.                 radioButton4.Checked = false;
  270.                 radioButton5.Checked = false;
  271.                 radioButton6.Checked = false;
  272.                 radioButton7.Checked = false;
  273.                 radioButton8.Checked = false;
  274.                 radioButton9.Checked = false;
  275.                 radioButton11.Checked = false;
  276.                 radioButton12.Checked = false;
  277.             }
  278.  
  279.             if (radioButton12.Checked == true)
  280.             {
  281.                 Sum = 5000;
  282.                 radioButton1.Checked = false;
  283.                 radioButton2.Checked = false;
  284.                 radioButton3.Checked = false;
  285.                 radioButton4.Checked = false;
  286.                 radioButton5.Checked = false;
  287.                 radioButton6.Checked = false;
  288.                 radioButton7.Checked = false;
  289.                 radioButton8.Checked = false;
  290.                 radioButton9.Checked = false;
  291.                 radioButton11.Checked = false;
  292.                 radioButton12.Checked = false;
  293.             }
  294.  
  295.             if (radioButton11.Checked == true)
  296.             {
  297.                 Sum = 10000;
  298.                 radioButton1.Checked = false;
  299.                 radioButton2.Checked = false;
  300.                 radioButton3.Checked = false;
  301.                 radioButton4.Checked = false;
  302.                 radioButton5.Checked = false;
  303.                 radioButton6.Checked = false;
  304.                 radioButton7.Checked = false;
  305.                 radioButton8.Checked = false;
  306.                 radioButton9.Checked = false;
  307.                 radioButton11.Checked = false;
  308.                 radioButton12.Checked = false;
  309.             }
  310.  
  311.             con = new OleDbConnection();
  312.  
  313.             con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " + Application.StartupPath + "\\..\\..\\banking.mdb"; //connection to database
  314.             con.Open();
  315.  
  316.             ds = new DataSet();
  317.  
  318.             string sql = "SELECT * From account";
  319.             da = new OleDbDataAdapter(sql, con);
  320.             da.Fill(ds, "UserList");
  321.             MaxRows = ds.Tables["UserList"].Rows.Count;
  322.  
  323.             string Balance;
  324.             int User_int;
  325.             int user;
  326.             User_int = Convert.ToInt32(User);
  327.             user = User_int - 2;      //user is just the row which the logged in user is situated on
  328.             DataRow dRow = ds.Tables["UserList"].Rows[user];
  329.             Balance = dRow.ItemArray.GetValue(3).ToString();     //Balance has been found
  330.             TempBalance = Convert.ToInt32(Balance);
  331.  
  332.             TempBalance = TempBalance + Sum;
  333.  
  334.             decimal finalBalance = TempBalance;
  335.  
  336.             System.Data.OleDb.OleDbCommandBuilder cb;
  337.             cb = new System.Data.OleDb.OleDbCommandBuilder(da);
  338.             System.Data.DataRow dRow2 = ds.Tables["UserList"].Rows[user];
  339.  
  340.             dRow[3] = finalBalance;
  341.  
  342.             da.Update(ds, "UserList");
  343.  
  344.             label3.Text = TempBalance + ".00";
  345.  
  346.             MessageBox.Show("Your balance has been successfully updated! Your new balance is shown on the right.", "Top-up Successful", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  347.  
  348.             con.Close();
  349.             con.Dispose();
  350.         }
  351.     }
  352. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement