userstatus.ascx.cs
来自「网上书店系统由两部分组成:购书网站和订单处理中心。其中购书网站是一个Web应用程」· CS 代码 · 共 128 行
CS
128 行
namespace Bookshop
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Collections;
/// <summary>
/// UserStatus 的摘要说明。
/// </summary>
public class UserStatus : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Button Button4;
protected System.Web.UI.WebControls.Panel Panel2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if( Session["uid"] == null )
{
Panel1.Visible = true;
Panel2.Visible = false;
}
else
{
Panel1.Visible = false;
Panel2.Visible = true;
Label2.Text = "<li>Welcome [" + Session["uname"] + "] to Bookshop!";
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Button4.Click += new System.EventHandler(this.Button4_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
string name = TextBox1.Text;
string psw = TextBox2.Text;
Label1.Text = "";
string connectText = System.Configuration.ConfigurationSettings.AppSettings["connString"];
string commandText = "Select * from Users where uname=\'" + name.Trim().Replace("\'", "\"") + "\'";
Label1.Text = commandText;
OleDbDataReader myReader = OleDbConn.ExecuteReader( commandText );
if(!myReader.Read())
{
Label1.Text = "<li>The user isn't existed!";
}
else
{
if( psw.Trim().Replace( "\'", "\"" ).Equals( myReader["upsw"] ) )
{
Session.Add( "uid", myReader["uid"] );
Session.Add( "uname", myReader["uname"] );
ArrayList bookCart = new ArrayList();
Panel1.Visible = false;
Panel2.Visible = true;
Session.Add( "bookCart", bookCart );
//Label2.Text = "<li>Welcome [" + Session["uname"] + "] to shopping! Check your Shopping Cart";
string[] temp = Request.Url.ToString().Split('/');
Response.Write( "<meta http-equiv=\'refresh\' content=\'0;url=" + temp[temp.Length-1] + "\'>" );
}
else
{
Label1.Text = "<li>Password error!";
}
}
myReader.Close();
OleDbConn.CloseConn();
}
private void Button2_Click(object sender, System.EventArgs e)
{
Response.Write( "<script language=javascript>window.open(\'Register.aspx\',0,\'scrollbar=yes,width=350,height=200\');</script>" );
string[] temp = Request.Url.ToString().Split('/');
Response.Write( "<meta http-equiv=\'refresh\' content=\'0;url=" + temp[temp.Length-1] + "\'>" );
}
private void Button3_Click(object sender, System.EventArgs e)
{
Session.Clear();
string[] temp = Request.Url.ToString().Split('/');
Response.Write( "<meta http-equiv=\'refresh\' content=\'0;url=" + temp[temp.Length-1] + "\'>" );
}
private void Button4_Click(object sender, System.EventArgs e)
{
Response.Write( "<script language=javascript>window.open(\'changePsw.aspx?uname="+Session["uname"]+" \',0,\'scrollbar=yes,width=550,height=350\');</script>" );
string[] temp = Request.Url.ToString().Split('/');
Response.Write( "<meta http-equiv=\'refresh\' content=\'0;url=" + temp[temp.Length-1] + "\'>" );
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?