在数据库链接后,后续页面未遇到较大困难,备份留用。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace bank_management_system
{
public partial class draw : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
drawValue.Focus();
}
protected void submitbtn_Click(object sender, EventArgs e)
{
string Temp;
Temp = Request.Cookies["name"].Value.ToString();
double drawvalue = Convert.ToDouble(drawValue.Text);
string Scon = @"Server=(local);uid=sa;Pwd=123456;DataBase=bankManagement";
SqlConnection con = new SqlConnection(Scon);
con.Open();
string sqlstring = "update client set balance=balance-'" + drawvalue + "' where account='" + Temp + "'";
string sqlcheck = "select balance from client where account='"+Temp+"'"; // 查询余额
SqlCommand checkCmd = new SqlCommand(sqlcheck, con);
SqlDataReader ds = checkCmd.ExecuteReader();
ds.Read();
string TempStr=ds["balance"].ToString();
double i = Convert.ToDouble(TempStr);
// Response.Write("<script>alert('" + TempStr + "')</script>");
//Response.Write("<script>alert('当前余额为"+i+"')</script>");
ds.Close();
if (drawvalue > i)//余额不足
{
Response.Write("<script>alert('余额不足,请重新输入取款金额!')</script>");
Response.Write("<script>location.href='draw.aspx';</script>");
}
else
{
SqlCommand cmd = new SqlCommand(sqlstring, con);
cmd.ExecuteNonQuery();
{
string sqldetails = "insert into details (account,Opamount,Toaccount,Mytime,operationName)values('" + Temp + "','" + drawvalue + "','',GETDATE(),'取出')";
SqlCommand conn = new SqlCommand(sqldetails, con);
conn.ExecuteNonQuery();
}
Response.Write("<script>alert('取款成功!')</script>");
Response.Write("<script>location.href='content.aspx';</script>");
}
con.Close();
}
protected void returnbtn_Click(object sender, EventArgs e)
{
Response.Write("<script>location.href='content.aspx';</script>");
}
}
}
上述为取款
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace bank_management_system
{
public partial class deposit : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
despositValue.Focus();
}
protected void returnbtn_Click(object sender, EventArgs e)
{
Response.Write("<script>location.href='content.aspx';</script>");
}
protected void submitbtn_Click(object sender, EventArgs e)
{
string Temp;
Temp = Request.Cookies["name"].Value.ToString();
int depvalue = Convert.ToInt32(despositValue.Text);
string Scon = @"Server=(local);uid=sa;Pwd=123456;DataBase=bankManagement";
SqlConnection con = new SqlConnection(Scon);
con.Open();
string sqlstring = "update client set balance=balance+'" + depvalue + "' where account='" + Temp + "'";
SqlCommand cmd = new SqlCommand(sqlstring, con);
cmd.ExecuteNonQuery();
{
string sqldetails = "insert into details (account,Opamount,Toaccount,Mytime,operationName)values('"+Temp+"','"+depvalue+"','',GETDATE(),'存入')";
SqlCommand conn = new SqlCommand(sqldetails, con);
conn.ExecuteNonQuery();
}
Response.Write("<script>alert('存款成功!')</script>");
Response.Write("<script>location.href='content.aspx';</script>");
con.Close();
}
}
}
以上为取款。
虽然简单,但不失为入门参考,权当抛砖引玉。