AllAccount.aspx
AllAccount.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class AllAccount : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ListGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName=="delAcc"){
var ID = Convert.ToInt32(e.CommandArgument);
string query1 = "DELETE FROM AccData WHERE Id='"+ID+"'";
string query2="DELETE FROM Accounts WHERE Acc_Number='"+ID+"'";
Connect con = new Connect();
con.deleteAcc(query1, query2);
Response.Redirect("~/AllAccount.aspx",true);
}
}
}
Connect.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
///
/// Summary description for Connect
///
public class Connect
{
SqlConnection sqlcon=null;
SqlDataAdapter Adptr = null;
public Connect()
{
}
public void connection()
{
string constr = "Data Source=SARANGA-PC;Initial Catalog=Accounts;User ID=sa;Password=saranga";
sqlcon = new SqlConnection(constr);
sqlcon.Open();
}
public void Insert(string sp,SqlParameter[] para)
{
connection();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = sp;
cmd.Connection = sqlcon;
for (int i=0; i
cmd.Parameters.Add(para[i]);
}
cmd.ExecuteNonQuery();
sqlcon.Close();
}
public void update(string sp, SqlParameter[] para)
{
connection();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = sp;
cmd.Connection = sqlcon;
for (int i = 0; i < para.Length; i++)
{
cmd.Parameters.Add(para[i]);
}
cmd.ExecuteNonQuery();
sqlcon.Close();
}
public DataTable display(string query )
{
connection();
Adptr = new SqlDataAdapter(query, sqlcon);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
Adptr.Fill(dt);
sqlcon.Close();
return dt;
}
public void deleteAcc(string q1,string q2)
{
connection();
SqlCommand cmd1 = new SqlCommand();
cmd1.CommandText = q1;
cmd1.Connection = sqlcon;
cmd1.ExecuteNonQuery();
SqlCommand cmd2 = new SqlCommand();
cmd2.CommandText = q1;
cmd2.Connection = sqlcon;
cmd2.ExecuteNonQuery();
sqlcon.Close();
}
}
NewAccount.aspx
NewAccount.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class NewAccount : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnApply_Click(object sender, EventArgs e)
{
int num=int.Parse(txtNum.Text);
string name=txtName.Text;
decimal depo= Convert.ToDecimal(txtDep.Text);
decimal withd = Convert.ToDecimal(txtwithdrowal.Text);
decimal Balance = Convert.ToDecimal(txtbalance.Text);
string type = DropType.SelectedValue ;
NewAcnt NewAc = new NewAcnt();
NewAc.CreateNew(num,name,depo,withd,Balance,type);
lblApplyStatus.Text = "Account Successfully Created";
}
}
NewAcnt.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
///
/// Summary description for NewAccount
///
public class NewAcnt
{
public NewAcnt()
{
}
public void CreateNew(int num, string name, decimal depo,decimal withd,decimal balance, string type)
{
SqlParameter[] para = {new SqlParameter("@num",SqlDbType.Int),
new SqlParameter("@name",SqlDbType.VarChar,50),
new SqlParameter("@depo",SqlDbType.Decimal),
new SqlParameter("@withd",SqlDbType.Decimal),
new SqlParameter("@balance",SqlDbType.Decimal),
new SqlParameter("@type",SqlDbType.VarChar,50)};
para[0].Value = num;
para[1].Value = name;
para[2].Value = depo;
para[3].Value = withd;
para[4].Value = balance;
para[5].Value = type;
string sp= "SP_NewAcc";
Connect cont = new Connect();
cont.Insert(sp,para);
}
}
TransAccount.aspx
TransAccount.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class TransAccount : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//$ConnectionStrings:AccountsConnectionString;
if(!IsPostBack){
dropNumber.ConnectionString = "Data Source=SARANGA-PC;Initial Catalog=Accounts;User ID=sa;Password=saranga";
dropNumber.SelectCommand = "SELECT [Acc_Number] FROM [Accounts]";
}
bind();
}
protected void btnbalance_Click(object sender, EventArgs e)
{
decimal withd = Convert.ToDecimal(txtupwithd.Text);
decimal depo = Convert.ToDecimal(txtupdepo.Text);
decimal baln = Convert.ToDecimal(txtupbalance.Text);
decimal finalbalance=baln+(depo-withd);
txtupbalance.Text = finalbalance.ToString();
}
protected void btnupdate_Click(object sender, EventArgs e)
{
int num = int.Parse(DropDownNumber.SelectedValue);
string name = txtupname.Text;
string type = txtuptype.Text;
decimal withd = Convert.ToDecimal(txtupwithd.Text);
decimal depo = Convert.ToDecimal(txtupdepo.Text);
decimal baln = Convert.ToDecimal(txtupbalance.Text);
Upadate up = new Upadate();
up.updateAcc(num, name, depo, withd, baln, type);
lblupstatus.Text = "Account Successfully Updated";
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
Upadate up = new Upadate();
int ID =int.Parse(DropDownNumber.SelectedValue);
DataTable dt= up.drop(ID);
txtupname.Text = dt.Rows[0].ItemArray.GetValue(0).ToString();
txtuptype.Text = dt.Rows[0].ItemArray.GetValue(4).ToString();
txtupdepo.Text = dt.Rows[0].ItemArray.GetValue(1).ToString();
txtupwithd.Text=dt.Rows[0].ItemArray.GetValue(2).ToString();;
txtupbalance.Text = dt.Rows[0].ItemArray.GetValue(3).ToString(); ;
}
public void bind()
{
}
}
Upadate.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
///
/// Summary description for Upadate
///
public class Upadate
{
public Upadate()
{
//
// TODO: Add constructor logic here
//
}
public DataTable drop(int ID)
{
string query = "SELECT dbo.Accounts.Acc_Name, dbo.Accounts.Acc_Deposit, dbo.AccData.Withdrowal, dbo.AccData.Balance,dbo.Accounts.Acc_Type FROM dbo.AccData INNER JOIN dbo.Accounts ON dbo.AccData.Id = dbo.Accounts.Acc_Number WHERE AccData.Id='"+ID+"'";
Connect cont = new Connect();
DataTable dt = new DataTable();
dt = cont.display(query);
return dt;
}
public void updateAcc(int num, string name, decimal depo, decimal withd, decimal balance, string type)
{
SqlParameter[] para = {new SqlParameter("@num",SqlDbType.Int),
new SqlParameter("@name",SqlDbType.VarChar,50),
new SqlParameter("@depo",SqlDbType.Decimal),
new SqlParameter("@withd",SqlDbType.Decimal),
new SqlParameter("@balance",SqlDbType.Decimal),
new SqlParameter("@type",SqlDbType.VarChar,50)};
para[0].Value = num;
para[1].Value = name;
para[2].Value = depo;
para[3].Value = withd;
para[4].Value = balance;
para[5].Value = type;
string sp = "SP_Update";
Connect cont = new Connect();
cont.update(sp, para);
}
}