📄 bookinfo.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using BLL.interfaces;
using Model;
public partial class bookInfo : System.Web.UI.Page
{
IReaderComments readerMessage = Factory.greatReaderComments();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request["Id"] == null||Request["Id"].Equals(""))
Response.Redirect("error.aspx");
ViewState["id"] = int.Parse(Request["id"].ToString());
showbookInfo();
showreader();
}
}
private void showbookInfo()
{
IBook bookMessage = Factory.greatBook();
List<Book> list = new List<Book>();
list= bookMessage.selctBookInfo((int)ViewState["id"]);
dtlbook.DataSource = list;
dtlbook.DataBind();
}
private void showreader()
{
IPage pagerMessage=Factory.greatPager();
List<ReaderComments> list = new List<ReaderComments>();
//int count=readerMessage.count();
//Model.Page pager=pagerMessage.getPager(cruutenPager,mothed,count);
list = readerMessage.selReaderC((int)ViewState["id"]);
DataList1.DataSource = list;
DataList1.DataBind();
}
protected void btnfb_Click(object sender, EventArgs e)
{
if (Session["userId"]==null)
Response.Redirect("error.aspx?mes="+"游客不能发表评论");
string contens = this.TextBox2.Text;
ReaderComments rdc = new ReaderComments();
rdc.BookId = (int)ViewState["id"];
rdc.Comment = contens;
rdc.UserId = int.Parse(Session["userId"].ToString());
if (readerMessage.addReaderC(rdc))
{
ClientScript.RegisterStartupScript(typeof(string), "a", "alert('发表成功!')", true);
showreader();
}
else
{
Response.Redirect("error.aspx?mes="+"系统错误\\n发表失败!");
}
}
private bool ex(DataTable dt,int id)
{
bool flag = false;
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i]["bookId"].ToString().Equals(id.ToString()))
{
dt.Rows[i]["Quantity"] = int.Parse(dt.Rows[i]["Quantity"].ToString()) + 1;
int Quantity = int.Parse(dt.Rows[i]["Quantity"].ToString());
int unitPrice = int.Parse(dt.Rows[i]["unitPrice"].ToString());
dt.Rows[i]["Price"] = Quantity * unitPrice;
flag = true;
}
}
Session["ShopingCar"] = dt;
return flag;
}
private void addTable(int id)
{
DataTable dt = new DataTable("shoping");
dt.Columns.Add("number", typeof(int));
dt.Columns.Add("bookId", typeof(int));
dt.Columns.Add("Title", typeof(string));
dt.Columns.Add("unitPrice", typeof(double));
dt.Columns.Add("Quantity", typeof(double));
dt.Columns.Add("Price", typeof(double));
addRow(dt,id);
}
private void addRow(DataTable dt,int id)
{
DataRow row = dt.NewRow();
row["number"] = dt.Rows.Count <= 0 ? 1 : dt.Rows.Count + 1;
row["bookId"] = id;
Label lblTitle=dtlbook.FindControl("lblTitle") as Label;
Label lblUnitPrice = dtlbook.FindControl("lblUnitPrice") as Label;
double unitPrice = Double.Parse(lblUnitPrice.Text.Trim());
row["Title"] = lblTitle.Text;
row["unitPrice"] = unitPrice;
row["Quantity"] = 1;
row["Price"] = unitPrice * 1;
dt.Rows.Add(row);
Session["ShopingCar"] = dt;
}
protected void btnbuydeng_Command(object sender, CommandEventArgs e)
{
if (Session["userId"] == null)
ClientScript.RegisterStartupScript(typeof(string), "b", "alert('您上未登录\\n请快点登录吧!');window.location='login.aspx'", true);
if (e.CommandName=="gg")
{
int id = int.Parse(e.CommandArgument.ToString());
if (Session["ShopingCar"] != null)
{
DataTable dt = Session["ShopingCar"] as DataTable;
if (!ex(dt,id))
{
addRow(dt, id);
}
}
else
{
addTable(id);
}
ClientScript.RegisterStartupScript(typeof(string), "c", "alert('已经成功添加到您的购物车')", true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -