📄 login.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace gllbysj
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel3;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.HyperLink HyperLink3;
protected System.Web.UI.WebControls.Panel Panel2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection con=db.createcon();
con.Open();
SqlDataAdapter sda=new SqlDataAdapter();
DataSet ds=new DataSet();
sda.SelectCommand=new SqlCommand("select top 10 id,name from mess order by hits desc",con);
sda.Fill(ds);
this.DataGrid1.DataSource=ds;
this.DataGrid1.DataBind();
con.Close();
SqlConnection cn=db.createcon();
cn.Open();
SqlCommand cm=new SqlCommand("select leftmess from publ where id=1",cn);
SqlDataReader sdr=cm.ExecuteReader();
sdr.Read();
this.Label2.Text="★★"+sdr["leftmess"].ToString();
cn.Close();
}
public bool login1()
{
SqlConnection cnn=db.createcon();
cnn.Open();
string st="select id,issuper from user1 where name='"+this.TextBox1.Text+"' and password='"+this.TextBox2.Text+"'";
SqlCommand cmd=new SqlCommand(st,cnn);
SqlDataReader reader=cmd.ExecuteReader();
if(reader.Read())
{
// Session["username"]=name;
//Session["issuper"]=reader["issuper"].ToString();
Session["issuper"]=reader["issuper"].ToString();
return true;
cnn.Close();
}
else
{
return false;
cnn.Close();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
//SqlConnection cn=db.createcon();
string name=this.TextBox1.Text;
string psd=this.TextBox2.Text;
if(this.login1())
{
Session["name"]=name;
// Session["issuper"]=reader["issuper"].ToString();
this.Panel3.Visible=false;
this.Panel2.Visible=true;
//Response.Write("<script language=javascript>alert('登陆成功')</script>");
// Response.Write(Session["issuper"]);
//int a=Convert.ToInt32(Session["issuper"]);
this.Label1.Text="欢迎:"+Session["name"];
this.LinkButton1.Visible=true;
string st=Convert.ToString(Session["issuper"]);
if(st=="True")
{
Session["gl"]="1";
}
if(Session["gl"]=="1")
{
Response.Redirect("managerleft.aspx");
}
}
else
{
//Response.Write("<script language=javascript>alert('用户名或密码错误')</script>");
this.Label1.Text="登陆失败!";
}
//this.Panel3.Visible=false;
//this.Panel2.Visible=true;
}
private void LinkButton1_Click(object sender, System.EventArgs e)
{
Session["name"]=null;
this.Label1.Text="用户尚末登陆";
this.LinkButton1.Visible=false;
this.Panel2.Visible=false;
this.Panel3.Visible=true;
Response.Write("<script language='javascript'>top.location='index.htm'</script>");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -