⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showbookdetail.aspx.cs

📁 这是一个编好的网上书店系统
💻 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 RobertSoft.BookStore.DBClass;

namespace BookStore
{
	/// <summary>
	/// ShowBookDetail 的摘要说明。
	/// </summary>
	public class ShowBookDetail : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox tbKeyword;
		protected System.Web.UI.WebControls.DropDownList ddChoice;
		protected System.Web.UI.WebControls.Button btQuickSearch;
		protected System.Web.UI.WebControls.TextBox tbCommentName;
		protected System.Web.UI.WebControls.TextBox tbCommentEmail;
		protected System.Web.UI.WebControls.TextBox tbCommentTitle;
		protected System.Web.UI.WebControls.TextBox tbCommentContent;
		protected System.Web.UI.WebControls.Button btReset;
		protected System.Web.UI.WebControls.Button btPost;
		protected System.Web.UI.WebControls.Label lbBookName;
		protected System.Web.UI.WebControls.Label lbAuthor;
		protected System.Web.UI.WebControls.Label lbPublisher;
		protected System.Web.UI.WebControls.Label lbBookType;
		protected System.Web.UI.WebControls.Label lbBookISBN;
		protected System.Web.UI.WebControls.Label lbPublishDate;
		protected System.Web.UI.WebControls.Label lbBookPage;
		protected System.Web.UI.WebControls.Label lbTranslater;
		protected System.Web.UI.WebControls.Label lbHitNumber;
		protected System.Web.UI.WebControls.Label lbPrice;
		protected System.Web.UI.WebControls.Label lbOurPrice;
		protected System.Web.UI.WebControls.Label lbFourStarPrice;
		protected System.Web.UI.WebControls.Label lbFiveStarPrice;
		protected System.Web.UI.WebControls.DataGrid dgQuickBookType;
		protected System.Web.UI.WebControls.Image imgCover;
		protected System.Web.UI.WebControls.Label lbDescription;
		protected System.Web.UI.HtmlControls.HtmlForm QuickSearchFrom;
		protected System.Web.UI.WebControls.Label lbImg;
		protected System.Web.UI.WebControls.Label lbCount;
		protected System.Web.UI.WebControls.LinkButton lbAddToCart;
		protected System.Web.UI.WebControls.LinkButton lbFavorite;
		static int BookID;
		protected Lei.WebControls.PagerDataList PagerDLComment;
		protected System.Web.UI.WebControls.Label lbInfo;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
		protected System.Web.UI.WebControls.Label lbTwoStarPrice;
		protected System.Web.UI.WebControls.Label lbThreeStarPrice;
		protected System.Web.UI.WebControls.Label lbDiamondPrice;
		RobertSoft.BookStore.Book currentBook = new RobertSoft.BookStore.Book();

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
				BookID = int.Parse(Request.QueryString["ID"]);
				currentBook.AddHitNumber(BookID);
				InitDataBind(BookID);				
			}
		}

		protected void InitDataBind(int id)
		{
			DataRow currentDR;
			DataView currentDVTypeSearch;
			currentDR = currentBook.GetBookDetail(id);		
			this.lbBookName.Text = currentDR["BookName"].ToString();
			this.lbAuthor.Text = currentDR["Author"].ToString();
			this.lbTranslater.Text = currentDR["Translator"].ToString();
			this.lbPublisher.Text = currentDR["PublishingHouse"].ToString();
			this.lbBookType.Text = currentDR["TypeName"].ToString();
			this.lbBookISBN.Text = currentDR["ISBN"].ToString();
			this.lbPublishDate.Text = currentDR["PublishDate"].ToString();
			this.lbBookPage.Text = currentDR["Pages"].ToString();
			this.lbHitNumber.Text = currentDR["HitNumber"].ToString();
			this.lbPrice.Text = currentDR["Price"].ToString();
			this.lbDescription.Text = currentDR["Description"].ToString();
			this.lbImg.Text = currentDR["img"].ToString();
			if(int.Parse(currentDR["SpecialPrice"].ToString()) == 1)
			{
				// 这里可能需要改进:即特价书的价格可能高于5星或者钻石级用户的价格
				// 所以对这些用户,需要显示比特价还低的价格[12/12/2004]
				int nDiscount;
				float fPrice;
				nDiscount = int.Parse(currentDR["Discount"].ToString());
				fPrice = float.Parse(currentDR["Price"].ToString());
				fPrice = (float)nDiscount*fPrice/100;
				int n = (int) (fPrice * 10);
				fPrice = (float)n / 10;
				string strPrice= "本站统一特价:" + fPrice.ToString();
				this.lbOurPrice.Text = strPrice;
				this.lbTwoStarPrice.Text = strPrice;
				this.lbThreeStarPrice.Text = strPrice;
				this.lbFourStarPrice.Text = strPrice;
				this.lbFiveStarPrice.Text = strPrice;
				this.lbDiamondPrice.Text = strPrice;
			}
			else
			{
				// Because the discount price will be float, so I do sth that makes 
				// only have one digit after the dot  [12/12/2004]
				float fPrice, fCount;
				string str;
				int n;
				str = currentDR["Price"].ToString();
				fPrice = float.Parse(str);		
		
				fCount = fPrice * (float)0.9;
				// Get only int by enlarge 10 times then convert to float
				n = (int) (fCount * 10);
				fCount = (float)n / 10;
				this.lbOurPrice.Text = fCount.ToString("");

				fCount = fPrice * (float)0.88;
				n = (int) (fCount * 10);
				fCount = (float)n / 10;
				this.lbTwoStarPrice.Text = fCount.ToString("");

				fCount = fPrice * (float)0.85;
				n = (int) (fCount * 10);
				fCount = (float)n / 10;
				this.lbThreeStarPrice.Text = fCount.ToString("");				

				fCount = fPrice * (float)0.8;
				n = (int) (fCount * 10);
				fCount = (float)n / 10;
				this.lbFourStarPrice.Text = fCount.ToString("");

				fCount = fPrice * (float)0.78;
				n = (int) (fCount * 10);
				fCount = (float)n / 10;
				this.lbFiveStarPrice.Text = fCount.ToString("");

				fCount = fPrice * (float)0.75;
				n = (int) (fCount * 10);
				fCount = (float)n / 10;
				this.lbDiamondPrice.Text = fCount.ToString("");
			}

			currentDVTypeSearch = RobertSoft.BookStore.Book.GetQuickType();
			this.dgQuickBookType.DataSource = currentDVTypeSearch;
			this.dgQuickBookType.DataBind();

			// Bind Comment
			string strSql;
			strSql = "select * from BookComment where BookID=" + id;
			DataSet currentDS;
			currentDS = RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLForDS(strSql);
			this.PagerDLComment.DataSource = currentDS.Tables[0].DefaultView;
			this.PagerDLComment.DataBind();
			this.lbCount.Text = "目前共有 " + currentDS.Tables[0].Rows.Count.ToString() + " 条评论";
		}


		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.btQuickSearch.Click += new System.EventHandler(this.btQuickSearch_Click);
			this.lbAddToCart.Click += new System.EventHandler(this.lbAddToCart_Click);
			this.lbFavorite.Click += new System.EventHandler(this.lbFavorite_Click);
			this.PagerDLComment.PageIndexChanged += new System.EventHandler(this.PagerDLComment_PageIndexChanged);
			this.btPost.Click += new System.EventHandler(this.btPost_Click);
			this.btReset.Click += new System.EventHandler(this.btReset_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btQuickSearch_Click(object sender, System.EventArgs e)
		{
			string strURL;
			strURL = "QuickSearch.aspx?strSearchType=" + ddChoice.SelectedValue + "&SearchKeyword=" + tbKeyword.Text;
			Response.Redirect(strURL);
		}

		private void lbAddToCart_Click(object sender, System.EventArgs e)
		{
			string strURL;
			strURL = "Payment/AddToCart.aspx?BookID=" + int.Parse(Request.QueryString["ID"]);
			Response.Redirect(strURL);
		}

		private void lbFavorite_Click(object sender, System.EventArgs e)
		{
			string strURL;
			strURL = "MyBookStore/AddToFavorite.aspx?BookID=" + int.Parse(Request.QueryString["ID"]);
			Response.Redirect(strURL);
		}

		private void btReset_Click(object sender, System.EventArgs e)
		{
			this.tbCommentContent.Text = "";
			this.tbCommentEmail.Text = "";
			this.tbCommentName.Text = "";
			this.tbCommentTitle.Text = "";
			this.lbInfo.Text = "";
			this.lbInfo.Visible = false;
		}

		private void btPost_Click(object sender, System.EventArgs e)
		{
			if(this.tbCommentContent.Text.Trim() == "")
			{
				this.lbInfo.Text = "评论内容不能为空!";
				return;
			}
			if(this.tbCommentName.Text.Trim() == "")
			{
				this.lbInfo.Text = "姓名不能为空!";
				return;
			}
			string strCommentContent = this.tbCommentContent.Text.Trim();
			string strCommentEmail = this.tbCommentEmail.Text.Trim();
			string strCommentName = this.tbCommentName.Text.Trim();
			string strCommentTitle = this.tbCommentTitle.Text.Trim();
			string strDate = DateTime.Now.ToString();
			string strSql;

			strSql = "INSERT INTO [BookComment]( BookID, Caption, Comment, UserName, Email, PublishDate)VALUES("
				+ BookID + ","
				+ "'" + strCommentTitle + "',"
				+ "'" + strCommentContent + "',"
				+ "'" + strCommentName + "',"
				+ "'" + strCommentEmail + "',"
				+ "'" + strDate + "')";
			try
			{
				RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLCmd(strSql);			
			}
			catch
			{
				return;
			}		
			this.tbCommentContent.Text = "";
			this.tbCommentEmail.Text = "";
			this.tbCommentName.Text = "";
			this.tbCommentTitle.Text = "";
			InitDataBind(BookID);
		}

		private void PagerDLComment_PageIndexChanged(object sender, System.EventArgs e)
		{
			int pageindex = ((DataGridPageChangedEventArgs)e).NewPageIndex;
			this.PagerDLComment.CurrentPageIndex = pageindex;
			this.InitDataBind(BookID);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -