?? default.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.Configuration ;
using System.Data .SqlClient ;
namespace BMS
{
/// <summary>
/// _Default 的摘要說明。
/// </summary>
public class _Default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList dlt_class1;
protected System.Web.UI.WebControls.DataList dlt_class2;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Button btn_submit;
protected System.Web.UI.WebControls.TextBox tbx_uid;
protected System.Web.UI.WebControls.TextBox tbx_upassword;
protected System.Web.UI.WebControls.TextBox tbx_bid;
protected System.Web.UI.WebControls.Button btn_search;
protected System.Web.UI.WebControls.Label lbl_message;
protected System.Web.UI.WebControls.HyperLink hlk_advsearchforcust;
protected System.Web.UI.WebControls.HyperLink hlk_BookListSortByC1;
protected System.Web.UI.WebControls.HyperLink hlk_BookListSortByC2;
protected System.Web.UI.WebControls.HyperLink hlk_BookListSortByC0;
protected System.Web.UI.WebControls.HyperLink hlk_orderstate;
protected System.Web.UI.WebControls.DataList dlt_class0;
private void Page_Load(object sender, System.EventArgs e)
{
BindList();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.btn_submit.Click += new System.EventHandler(this.btn_submit_Click);
this.btn_search.Click += new System.EventHandler(this.btn_search_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public void BindList()
{ //從文件Web.config中讀取連接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//連接本地計算機的MMS數據庫
SqlConnection cn= new SqlConnection (strconn);
//創建查詢語句--按計算機分類,只選出最前面的三種,按BID號降序,即顯示新增的書
string sqlSortByC1="select top 3 * from book,bookprice where book.bid=bookprice.ppid and book.bgroup=1 order by bid desc";
//創建SqlDataAdapter對象,調用視圖
SqlDataAdapter da1=new SqlDataAdapter (sqlSortByC1,cn);
//創建并填充DataSet
DataSet ds1=new DataSet ();
da1.Fill (ds1);
dlt_class1.DataSource =ds1;
dlt_class1.DataBind ();
//創建查詢語句--按科普分類,只選出最前面的三種,按BID號降序,即顯示新增的書
string sqlSortByC2="select top 3 * from book,bookprice where book.bid=bookprice.ppid and book.bgroup=2 order by bid desc";
//創建SqlDataAdapter對象,調用視圖
SqlDataAdapter da2=new SqlDataAdapter (sqlSortByC2,cn);
//創建并填充DataSet
DataSet ds2=new DataSet ();
da2.Fill (ds2);
dlt_class2.DataSource =ds2;
dlt_class2.DataBind ();
//創建查詢語句--按其他分類,只選出最前面的三種,按BID號降序,即顯示新增的書
string sqlSortByC0="select top 3 * from book,bookprice where book.bid=bookprice.ppid and book.bgroup=0 order by bid desc";
//創建SqlDataAdapter對象,調用視圖
SqlDataAdapter da0=new SqlDataAdapter (sqlSortByC0,cn);
//創建并填充DataSet
DataSet ds0=new DataSet ();
da0.Fill (ds0);
dlt_class0.DataSource =ds0;
dlt_class0.DataBind ();
cn.Close ();
}
private void btn_submit_Click(object sender, System.EventArgs e)
{ //從文件Web.config中讀取連接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//連接本地計算機的BMS數據庫
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
//構造SQL語句,該語句在Users表中檢查用戶名和密碼是否正確
string mysql= "select * from Users where Uid='"+tbx_uid.Text +"'and UPassword='"+tbx_upassword.Text +"'";
//創建Command對象
SqlCommand cm=new SqlCommand (mysql,cn);
//執行ExecuteReader ()方法
SqlDataReader dr=cm.ExecuteReader ();
if(dr.Read ())
{
lbl_message.Text= "";
//保存當前用戶名及用戶權限
Session["uid"]=dr["uid"];
Session["upower"]=dr["upower"];
lbl_message.Text="歡迎您!"+Session["uid"];
if(Session["upower"].ToString ()=="1")
{ //進入管理人員界面
Response.Redirect ("bookmanage.aspx");
}
else
{ //普通用戶,界面不變
}
}
else
{
lbl_message.Text ="對不起,您的用戶名/密碼不正確,請重新輸入";
}
//關閉連接
cn.Close();
}
private void btn_search_Click(object sender, System.EventArgs e)
{ //進入書目詳細信息頁
int varbid=Convert.ToInt16 (tbx_bid.Text .ToString ());
Response.Redirect ("bookdetail.aspx?bid="+varbid);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -