跪求C#网页登陆源代码,我的是VS2010+sql2008
这是界面,下面是源代码,用的是三层架构
protected void Page_Load(object sender, EventArgs e)
{
EventLog log = new EventLog();
log.Source = "login:test";
log.WriteEntry("aaa", EventLogEntryType.Error);
//Response.Write("Page_Load<br/>");
}
protected void Btn_Login_Click(object sender, EventArgs e)
{
// Response.Write("Btn_Login_Click<br/>");
//取得用户输入的信息:类型,用户名,密码
int nUserType = int.Parse(DDL_Type.SelectedValue);
string strUserName = TXT_UserName.Text.Trim();
string strPassword = TXT_Password.Text.Trim();
//调用业务逻辑的用户信息实现登陆功能
PaperSys_BLL.UserInfomation user = new PaperSys_BLL.UserInfomation();
bool bResult = user.UserDoLogin(nUserType, strUserName, strPassword);
//登陆成功
if (bResult)
{
Session["UserType"] = nUserType;
Session["UserName"] = strUserName;
Response.Redirect("~/Default.aspx");
}
else
{
System.Web.UI.ScriptManager.RegisterStartupScript(Btn_Login, this.GetType(), "message", "alert('用户名或者密码不正确,登陆失败');", true);
// PaperSys_Common.MessageBox.Show(this.UpdatePanel1, "用户名或者密码不正确,登陆失败");
}
}
下面是BLL层UserDoLogin方法代码
public bool UserDoLogin(int nUserType, String strUserName, String strPassword)
{
int nResult = -1;
switch (nUserType)
{
case 3://教师登陆
break;
case 4://学生登陆
break;
default://管理员
nResult = user.DoAdminLogin(nUserType, strUserName, strPassword);
break;
}
if (nResult == 1)
{
return true;
}
else
{
return false;
}
}
}
下面是DAL层DoAdminLogin方法代码
public int DoAdminLogin(int nUserType, String strUserName, String strPassword)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) from admin where adminname = @username and adminpsd = @password ");
SqlParameter[] sqlparas = { new SqlParameter("@username", SqlDbType.VarChar, 30),
new SqlParameter("@password", SqlDbType.VarChar, 33)};
sqlparas[0].Value = strUserName;
sqlparas[1].Value = strPassword;
object obj_result = DbHelperSQL.GetSingle(strSql.ToString(), sqlparas);
if (obj_result == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj_result);
}
}
望采纳,谢谢
广告 您可能关注的内容 |