Banking application example using dot net framework
This article present about how to work a Banking application example using dot net framework with code snippet
just a code for the credit debit and transfer of amount functions using simple code
create an account
this code helps one to create an account for an user after he has entered his personal details
auto update of account no is given and u can view it after entering name and password
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class create : Form
{
int a,accno,count;
string b;
SqlConnection conn;
SqlCommand cmd;
SqlDataAdapter da;
DataTable dt;
int c, c1;
DataSet ds;
DataRow[] dr, dr1;
DataRow r;
SqlCommandBuilder cb;
static int i = 0;
public create()
{
InitializeComponent();
String s = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + @"z:\dot\WindowsApplication1\WindowsApplication1\bank.mdf" + @";Integrated Security=True;Connect Timeout=30;User Instance=True";
conn = new SqlConnection(s);
}
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
a = System.Convert.ToInt16(textBox8.Text);
if (a > 1000)
{
//count++;
// accno = accno + 1;
//b = System.Convert.ToString(accno);
string sql = "insert into account values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "')";
cmd = new SqlCommand(sql, conn);
int c = cmd.ExecuteNonQuery();
if (c == 1)
{
//MessageBox.Show("your account is created and your accountno is '" + count + "'");
MessageBox.Show("your account is created to view your account no enter name and password and press view");
//count++;
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
textBox9.Clear();
textBox1.Focus();
}
else
MessageBox.Show("your account cannot be created due to low pay");
conn.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
textBox9.Clear();
textBox1.Focus();
}
private void create_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
conn.Open();
dataGridView1.Visible = true;
string sql = "select accno from account where name='" + textBox1.Text + "'";
// and p.no=d.no";
cmd = new SqlCommand(sql, conn);
da = new SqlDataAdapter(cmd);
cb = new SqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "person,details");
dt = ds.Tables[0];
dr = dt.Select();
//textBox8.Text = dr[i][2].ToString();
//textBox9.Text = dr[i][3].ToString();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "person,details";
//label5.Text = System.Convert.ToString(a);
conn.Close();
}
private void label7_Click(object sender, EventArgs e)
{
}
}
}
***********************
credit to account
after creating an account you can add to amount of the user by entering user name and password
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class credit : Form
{
int c;
SqlConnection conn;
SqlCommand cmd;
public credit()
{
InitializeComponent();
String s = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + @"z:\dot\WindowsApplication1\WindowsApplication1\bank.mdf" + @";Integrated Security=True;Connect Timeout=30;User Instance=True";
conn = new SqlConnection(s);
}
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
c = System.Convert.ToInt16(textBox4.Text);
string sql = "Update account Set amount =amount+'"+ c + "'where name='" + textBox1.Text + "'";
cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
// if (c == 1)
// if(c1==1)
MessageBox.Show("credited");
conn.Close();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
****************************
debit from account
after creating an account you can debit from amount of the user by entering user name and password
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class debit : Form
{
int c;
SqlConnection conn;
SqlCommand cmd;
public debit()
{
InitializeComponent();
String s = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + @"z:\dot\WindowsApplication1\WindowsApplication1\bank.mdf" + @";Integrated Security=True;Connect Timeout=30;User Instance=True";
conn = new SqlConnection(s);
}
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
c = System.Convert.ToInt16(textBox4.Text);
string sql = "Update account Set amount =amount-'" + c + "'where name='" + textBox1.Text + "'";
cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
// if (c == 1)
// if(c1==1)
MessageBox.Show("Debited");
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
*********************************
transfer amount between two users
after creating an account you can transfer amount of one user to another by entering user name and password of both
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class trans : Form
{
int c;
SqlConnection conn;
SqlCommand cmd;
public trans()
{
InitializeComponent();
String s = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + @"z:\dot\WindowsApplication1\WindowsApplication1\bank.mdf" + @";Integrated Security=True;Connect Timeout=30;User Instance=True";
conn = new SqlConnection(s);
}
private void label7_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
c = System.Convert.ToInt16(textBox7.Text);
string sql = "Update account Set amount =amount+'" + c + "'where name='" + textBox1.Text + "'";
cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
string dfg = "Update account Set amount =amount-'" + c + "'where name='" + textBox4.Text + "'";
cmd = new SqlCommand(dfg, conn);
cmd.ExecuteNonQuery();
// if (c == 1)
// if(c1==1)
MessageBox.Show("transfered");
conn.Close();
}
}
}
************************************************
check balance
after creating an account you can check your balance by entering user name and password
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class balance : Form
{
SqlConnection conn;
SqlCommand cmd;
SqlDataAdapter da;
DataTable dt;
int a;
int c,c1;
DataSet ds;
DataRow[] dr, dr1;
DataRow r;
SqlCommandBuilder cb;
static int i = 0;
public balance()
{
InitializeComponent();
String s = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + @"z:\dot\WindowsApplication1\WindowsApplication1\bank.mdf" + @";Integrated Security=True;Connect Timeout=30;User Instance=True";
conn = new SqlConnection(s);
}
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
dataGridView1.Visible = true;
string sql = "select name,amount as balance,accno from account where name='" + textBox1.Text + "'";
// and p.no=d.no";
cmd = new SqlCommand(sql, conn);
da = new SqlDataAdapter(cmd);
cb = new SqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "person,details");
dt = ds.Tables[0];
dr = dt.Select();
//textBox8.Text = dr[i][2].ToString();
//textBox9.Text = dr[i][3].ToString();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "person,details";
//label5.Text = System.Convert.ToString(a);
conn.Close();
}
}
}
1