📄 login.ascx.cs
字号:
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 System.Data.SqlClient;
public partial class Control_login : System.Web.UI.UserControl
{
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
cn.Open();
SqlCommand cmd = new SqlCommand("select*from userinfo where username='" + this.txtusername.Text.ToString().Trim() + "' and pwd='" + this.txtpwd.Text.ToString().Trim() + "'and role='" + this.ddlrole.SelectedItem.Value.ToString() + "'", cn);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["id"] = dr["id"];
Session["username"] = dr["username"].ToString();
Session["role"] = dr["role"].ToString();
Session["pwd"] = dr["pwd"].ToString();
Session["entertime"] = dr["entertime"].ToString();
Session["loginouttime"] = dr["loginouttime"].ToString();
Session["loginnum"] = dr["loginnum"].ToString();
dr.Close();
SqlCommand cmd1 = new SqlCommand("update userinfo set logintime=getdate(),loginnum=loginnum+1,attr='在线' where id=" + Convert.ToInt32(Session["id"]), cn);
cmd1.ExecuteNonQuery();
cn.Close();
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.txtusername.Text, false);
Response.Redirect("Default.aspx");
}
else
{
this.Labmessage.Text = "用户名或密码错误";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
this.txtpwd.Text = "";
this.txtusername.Text = "";
this.txtusername.Focus();
this.Labmessage.Text = "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -