?? bookdetail.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>
/// BookDetail 的摘要說明。
/// </summary>
public class BookDetail : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbl_bid;
protected System.Web.UI.WebControls.TextBox tbx_bname;
protected System.Web.UI.WebControls.TextBox tbx_bauthor;
protected System.Web.UI.WebControls.TextBox tbx_bpress;
protected System.Web.UI.WebControls.TextBox tbx_bgroup;
protected System.Web.UI.WebControls.TextBox tbx_bisbn;
protected System.Web.UI.WebControls.TextBox tbx_bdescribe;
protected System.Web.UI.WebControls.TextBox tbx_pprice;
protected System.Web.UI.WebControls.TextBox tbx_pdiscount;
protected System.Web.UI.WebControls.TextBox tbx_nowprice;
protected System.Web.UI.WebControls.DropDownList ddl_oquantity;
protected System.Web.UI.WebControls.Label lbl_message;
protected System.Web.UI.WebControls.HyperLink hlk_default;
protected System.Web.UI.WebControls.Button btn_addorder;
private void Page_Load(object sender, System.EventArgs e)
{
//從文件Web.config中讀取連接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//連接本地計算機的BMS數據庫
SqlConnection cn= new SqlConnection (strconn);
//創建查詢相應書目信息的sql語句
string mysql="select * from book,bookprice where book.bid=bookprice.ppid and book.bid=@bid";
//創建SqlCommand
SqlCommand cm=new SqlCommand (mysql,cn);
//添加并設置參數的值
cm.Parameters .Add ("@BID", SqlDbType.Int );
cm.Parameters ["@BID"].Value =Request.QueryString [0];
//打開連接
cn.Open ();
//執行ExecuteReader
SqlDataReader dr=cm.ExecuteReader ();
if(dr.Read ())//有數據讀出,即有匹配用戶
{
//進行Label綁定
lbl_bid.Text =dr["bid"].ToString ();
tbx_bname.Text =dr["bname"].ToString ();
tbx_bisbn.Text =dr["bisbn"].ToString ();
tbx_bauthor.Text =dr["bauthor"].ToString ();
tbx_bpress.Text =dr["bpress"].ToString ();
tbx_pprice.Text =dr["pprice"].ToString ();
tbx_pdiscount.Text =dr["pdiscount"].ToString ();
if(dr["bgroup"].ToString ()=="0") tbx_bgroup.Text ="其他";
if(dr["bgroup"].ToString ()=="1") tbx_bgroup.Text ="計算機";
if(dr["bgroup"].ToString ()=="2") tbx_bgroup.Text ="科普";
tbx_bdescribe.Text =dr["bdescribe"].ToString ();
double pdiscount=Convert.ToInt32 (dr["pdiscount"].ToString ());
double pprice=Convert.ToDouble (dr["pprice"].ToString ());
tbx_nowprice.Text =Convert.ToString (pdiscount*pprice*0.1);
cn.Close ();
}
else
{
Response.Write ("該書目不存在,請返回");
Response.End ();
}
}
#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_addorder.Click += new System.EventHandler(this.btn_addorder_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btn_addorder_Click(object sender, System.EventArgs e)
{
//用異常判斷語句判斷用戶是否已登入,如果用戶未登入Session["UID"].ToString ()將會是異常操作
try//用戶用戶為合法登入用戶
{ Session["UID"].ToString ();
//從文件Web.config中讀取連接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//連接本地計算機的BMS數據庫
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
//創建cm,用于order表中數據的操作
SqlCommand cm=new SqlCommand ("orderadd",cn);
//設置存儲類型
cm.CommandType =CommandType.StoredProcedure ;
//添加參數
cm.Parameters .Add ("@OBID",SqlDbType.Int );
cm.Parameters .Add ("@OUID",SqlDbType.VarChar );
cm.Parameters .Add ("@OQuantity",SqlDbType.Int );
cm.Parameters .Add ("@ODate",SqlDbType.DateTime );
//給參數付值
string obidvalue=lbl_bid.Text .ToString ();
cm.Parameters ["@OBID"].Value =Convert.ToInt16 (obidvalue);
cm.Parameters ["@OUID"].Value =Session["UID"];
string oquantityvalue=ddl_oquantity.SelectedItem .Value .ToString ();
cm.Parameters ["@OQuantity"].Value =Convert.ToInt16 (oquantityvalue);
cm.Parameters ["@ODate"].Value =System.DateTime .Now;
cm.ExecuteNonQuery ();
cn.Close ();
Response.Redirect ("orderstate.aspx");
}
//用戶未登入
catch
{ lbl_message.Text ="您尚未登入,請返回登入后再選購圖書";
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -