求大神逐句解释下,感谢!!!
本界面的登录功能的实现通过一段代码完成,代码如下:protectedvoidbtnLogin_Click(objectsender,EventArgse){if(Stri...
本界面的登录功能的实现通过一段代码完成,代码如下:
protected voidbtnLogin_Click(object sender, EventArgs e)
{
if(String.Compare(Request.Cookies["CheckCode"].Value,txtPng.Text.ToString().Trim(), true) != 0)
{
CommonLib.JavaScriptHelper.Alert("验证码不正确!", Page);
txtPng.Text = "";
return;
}
else
{
string con =CommonLib.SqlHelper.SqlConnectionString;
string user =CommonLib.CutString.CutHTML(txtUserName.Text.Trim());
string pwd =txtPwd.Text.Trim();
string sql = "select count(*)from manager where manager_name='" + user
+ "' andmanager_pwd='" + pwd + "'";
int count =Convert.ToInt32(CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, sql,null));
if (count > 0)
{
HttpCookie cookies =Request.Cookies["T-TXB"];
cookies = newHttpCookie("T-TXB");
cookies.Values.Add("Manager",HttpUtility.UrlEncode(txtUserName.Text.Trim()));
Response.Cookies.Set(cookies);//存储!~
CommonLib.JavaScriptHelper.Redirect("mainframe.aspx");
}
else
{
CommonLib.JavaScriptHelper.Alert("用户名或密码错误!", Page);
}
} 展开
protected voidbtnLogin_Click(object sender, EventArgs e)
{
if(String.Compare(Request.Cookies["CheckCode"].Value,txtPng.Text.ToString().Trim(), true) != 0)
{
CommonLib.JavaScriptHelper.Alert("验证码不正确!", Page);
txtPng.Text = "";
return;
}
else
{
string con =CommonLib.SqlHelper.SqlConnectionString;
string user =CommonLib.CutString.CutHTML(txtUserName.Text.Trim());
string pwd =txtPwd.Text.Trim();
string sql = "select count(*)from manager where manager_name='" + user
+ "' andmanager_pwd='" + pwd + "'";
int count =Convert.ToInt32(CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, sql,null));
if (count > 0)
{
HttpCookie cookies =Request.Cookies["T-TXB"];
cookies = newHttpCookie("T-TXB");
cookies.Values.Add("Manager",HttpUtility.UrlEncode(txtUserName.Text.Trim()));
Response.Cookies.Set(cookies);//存储!~
CommonLib.JavaScriptHelper.Redirect("mainframe.aspx");
}
else
{
CommonLib.JavaScriptHelper.Alert("用户名或密码错误!", Page);
}
} 展开
2个回答
展开全部
protected voidbtnLogin_Click(object sender, EventArgs e)//登陆响应事件
{
if(String.Compare(Request.Cookies["CheckCode"].Value,txtPng.Text.ToString().Trim(), true) != 0)
{
CommonLib.JavaScriptHelper.Alert("验证码不正确!", Page);//判断验证码输入是否正确
txtPng.Text = "";//把验证码输入框值转为空
return;
}
else
{
string con =CommonLib.SqlHelper.SqlConnectionString;// 访问数据库
string user =CommonLib.CutString.CutHTML(txtUserName.Text.Trim());//用户名
string pwd =txtPwd.Text.Trim();//密码
string sql = "select count(*)from manager where manager_name='" + user
+ "' andmanager_pwd='" + pwd + "'";
int count =Convert.ToInt32(CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, sql,null));
if (count > 0) //判断用户名或密码是否正确
{
HttpCookie cookies =Request.Cookies["T-TXB"];
cookies = newHttpCookie("T-TXB");
cookies.Values.Add("Manager",HttpUtility.UrlEncode(txtUserName.Text.Trim()));
Response.Cookies.Set(cookies);//存储!~
CommonLib.JavaScriptHelper.Redirect("mainframe.aspx");
}
else
{
CommonLib.JavaScriptHelper.Alert("用户名或密码错误!", Page);
}
}
{
if(String.Compare(Request.Cookies["CheckCode"].Value,txtPng.Text.ToString().Trim(), true) != 0)
{
CommonLib.JavaScriptHelper.Alert("验证码不正确!", Page);//判断验证码输入是否正确
txtPng.Text = "";//把验证码输入框值转为空
return;
}
else
{
string con =CommonLib.SqlHelper.SqlConnectionString;// 访问数据库
string user =CommonLib.CutString.CutHTML(txtUserName.Text.Trim());//用户名
string pwd =txtPwd.Text.Trim();//密码
string sql = "select count(*)from manager where manager_name='" + user
+ "' andmanager_pwd='" + pwd + "'";
int count =Convert.ToInt32(CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, sql,null));
if (count > 0) //判断用户名或密码是否正确
{
HttpCookie cookies =Request.Cookies["T-TXB"];
cookies = newHttpCookie("T-TXB");
cookies.Values.Add("Manager",HttpUtility.UrlEncode(txtUserName.Text.Trim()));
Response.Cookies.Set(cookies);//存储!~
CommonLib.JavaScriptHelper.Redirect("mainframe.aspx");
}
else
{
CommonLib.JavaScriptHelper.Alert("用户名或密码错误!", Page);
}
}
展开全部
//单击事件
protected voidbtnLogin_Click(object sender, EventArgs e)
{
//从cookies获取"checkcode"值,进行对比
if(String.Compare(Request.Cookies["CheckCode"].Value,txtPng.Text.ToString().Trim(), true) != 0)
{// 弹出错误提示
CommonLib.JavaScriptHelper.Alert("验证码不正确!", Page);
txtPng.Text = "";
return;
}
else
{
string con =CommonLib.SqlHelper.SqlConnectionString;//连接数据库
string user =CommonLib.CutString.CutHTML(txtUserName.Text.Trim());//获取用户名
string pwd =txtPwd.Text.Trim();//获取密码
string sql = "select count(*)from manager where manager_name='" + user
+ "' andmanager_pwd='" + pwd + "'";//拼接SQL,查询有无当前用户名密码的用户
int count =Convert.ToInt32(CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, sql,null));
if (count > 0)//如果有查询记录,进入if
{
HttpCookie cookies =Request.Cookies["T-TXB"];
cookies = newHttpCookie("T-TXB");//新建一个cookies "T-TXB"
cookies.Values.Add("Manager",HttpUtility.UrlEncode(txtUserName.Text.Trim()));
Response.Cookies.Set(cookies);//存储新建的值
CommonLib.JavaScriptHelper.Redirect("mainframe.aspx");
}
else
{
CommonLib.JavaScriptHelper.Alert("用户名或密码错误!", Page);
}
}
protected voidbtnLogin_Click(object sender, EventArgs e)
{
//从cookies获取"checkcode"值,进行对比
if(String.Compare(Request.Cookies["CheckCode"].Value,txtPng.Text.ToString().Trim(), true) != 0)
{// 弹出错误提示
CommonLib.JavaScriptHelper.Alert("验证码不正确!", Page);
txtPng.Text = "";
return;
}
else
{
string con =CommonLib.SqlHelper.SqlConnectionString;//连接数据库
string user =CommonLib.CutString.CutHTML(txtUserName.Text.Trim());//获取用户名
string pwd =txtPwd.Text.Trim();//获取密码
string sql = "select count(*)from manager where manager_name='" + user
+ "' andmanager_pwd='" + pwd + "'";//拼接SQL,查询有无当前用户名密码的用户
int count =Convert.ToInt32(CommonLib.SqlHelper.ExecuteScalar(con, CommandType.Text, sql,null));
if (count > 0)//如果有查询记录,进入if
{
HttpCookie cookies =Request.Cookies["T-TXB"];
cookies = newHttpCookie("T-TXB");//新建一个cookies "T-TXB"
cookies.Values.Add("Manager",HttpUtility.UrlEncode(txtUserName.Text.Trim()));
Response.Cookies.Set(cookies);//存储新建的值
CommonLib.JavaScriptHelper.Redirect("mainframe.aspx");
}
else
{
CommonLib.JavaScriptHelper.Alert("用户名或密码错误!", Page);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询