using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBAccess;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
if (returnName(UserName.Value.Trim()))
{
if (Password.Value.Trim() == returnPassword(Password.Value.Trim()))
{
returnSession(UserName.Value.Trim());
Response.Redirect("default.aspx");
}
else
{
UseJavaScript.ExcuteAlert("密码错误!");
}
}
else
{
UseJavaScript.ExcuteAlert("该工号不存在!");
}
}
}
private bool returnName(string LoginName)
{
DbHelper db = new DbHelper();
string sql;
int count = 0;
try
{
sql = " select count(*) from T_User where Name=@Name";
DbCommand cmd = db.GetSqlStringCommond(sql);
db.AddInParameter(cmd, "@Name", DbType.String, LoginName);
count = Convert.ToInt32(db.ExecuteScalar(cmd));
}
catch (Exception e)
{
throw new ApplicationException(e.Message);
}
if (count == 0)
return false;
else
return true;
}
private string returnPassword(string LoginName)
{
DbHelper db = new DbHelper();
string password = "";
DataSet ds;
string sql;
try
{
sql = " select password from t_user where Name=@Name";
DbCommand cmd = db.GetSqlStringCommond(sql);
db.AddInParameter(cmd, "@Name", DbType.String, LoginName);
ds = db.ExecuteDataSet(cmd);
if (ds.Tables[0].Rows.Count > 0)
{
password = ds.Tables[0].Rows[0]["password"].ToString();
}
}
catch (Exception e)
{
throw new ApplicationException(e.Message);
}
return password; }
private void returnSession(string LoginName)
{
DbHelper db = new DbHelper();
DataSet ds;
string sql;
try
{
sql = " select id,name from t_user where Name=@Name";
DbCommand cmd = db.GetSqlStringCommond(sql);
db.AddInParameter(cmd, "@Name", DbType.String, LoginName);
ds = db.ExecuteDataSet(cmd);
if (ds.Tables[0].Rows.Count > 0)
{
Session["userid"] = ds.Tables[0].Rows[0]["id"].ToString();
Session["name"] = ds.Tables[0].Rows[0]["name"].ToString();
}
}
catch (Exception e)
{
throw new ApplicationException(e.Message);
} }
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBAccess;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
if (returnName(UserName.Value.Trim()))
{
if (Password.Value.Trim() == returnPassword(Password.Value.Trim()))
{
returnSession(UserName.Value.Trim());
Response.Redirect("default.aspx");
}
else
{
UseJavaScript.ExcuteAlert("密码错误!");
}
}
else
{
UseJavaScript.ExcuteAlert("该工号不存在!");
}
}
}
private bool returnName(string LoginName)
{
DbHelper db = new DbHelper();
string sql;
int count = 0;
try
{
sql = " select count(*) from T_User where Name=@Name";
DbCommand cmd = db.GetSqlStringCommond(sql);
db.AddInParameter(cmd, "@Name", DbType.String, LoginName);
count = Convert.ToInt32(db.ExecuteScalar(cmd));
}
catch (Exception e)
{
throw new ApplicationException(e.Message);
}
if (count == 0)
return false;
else
return true;
}
private string returnPassword(string LoginName)
{
DbHelper db = new DbHelper();
string password = "";
DataSet ds;
string sql;
try
{
sql = " select password from t_user where Name=@Name";
DbCommand cmd = db.GetSqlStringCommond(sql);
db.AddInParameter(cmd, "@Name", DbType.String, LoginName);
ds = db.ExecuteDataSet(cmd);
if (ds.Tables[0].Rows.Count > 0)
{
password = ds.Tables[0].Rows[0]["password"].ToString();
}
}
catch (Exception e)
{
throw new ApplicationException(e.Message);
}
return password; }
private void returnSession(string LoginName)
{
DbHelper db = new DbHelper();
DataSet ds;
string sql;
try
{
sql = " select id,name from t_user where Name=@Name";
DbCommand cmd = db.GetSqlStringCommond(sql);
db.AddInParameter(cmd, "@Name", DbType.String, LoginName);
ds = db.ExecuteDataSet(cmd);
if (ds.Tables[0].Rows.Count > 0)
{
Session["userid"] = ds.Tables[0].Rows[0]["id"].ToString();
Session["name"] = ds.Tables[0].Rows[0]["name"].ToString();
}
}
catch (Exception e)
{
throw new ApplicationException(e.Message);
} }
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货