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

📄 ve-2d4.tmp

📁 一个简单的网上书店
💻 TMP
字号:
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 Model;
using BLL;
using BLL.interfaces;

public partial class booklist : System.Web.UI.Page
{
    IBook bookMessage = Factory.greatBook();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["orderbyType"] = "date";
            ViewState["method"] = (Request["method"] != null) ? Request["method"].ToString() : "";
            ViewState["counts"] = bookMessage.count();
            show(null, null);
        }
    }

    private void show(string mothed, string cruutenPager)
    {
        List<Book> list = new List<Book>();
        IPage pagerMessage = Factory.greatPager();
        Model.Page pager = pagerMessage.getPager(cruutenPager, mothed, (int)ViewState["counts"]);
        lblcruutenPager.Text = pager.getCurrentPage().ToString();
        lblcPagers.Text = pager.getTotalPages().ToString();
        list = bookMessage.SeachBook(null, pager, ViewState["orderbyType"].ToString(), ViewState["method"].ToString());
        dtlBook.DataSource = list;
        dtlBook.DataBind();
    }

    protected void btnFirst_Click(object sender, ImageClickEventArgs e)
    {
        show("first", null);
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        show("previous", null);
    }
    protected void btnNext_Click(object sender, ImageClickEventArgs e)
    {
        show("next", null);
    }
    protected void btnLast_Click(object sender, ImageClickEventArgs e)
    {
        show("last", null);
    }
    protected void btnpage_Click(object sender, EventArgs e)
    {
        //string cupager = txtcrupager.Text;
        //string counts = txtcrupager.Text;
        //if (int.Parse(cupager) < int.Parse(counts))
        //{
        //    show(null, cupager);
        //}
    }


    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;
                flag = true;
            }
        }
        Session["ShopingCar"] = dt;
        return flag;
    }
    private void addTable(int id,int num)
    {
        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,num);
    }
    private void addRow(DataTable dt, int id,int num)
    {
        DataRow row = dt.NewRow();
        row["number"] = dt.Rows.Count <= 0 ? 1 : dt.Rows.Count + 1;
        row["bookId"] = id;
        LinkButton linkBtn = (LinkButton)dtlBook.Items[num].FindControl("LinkButton1");
        Label lblUnitPrice = (Label)dtlBook.Items[num].FindControl("lblUnitPrice");
        double unitPrice = double.Parse(lblUnitPrice.Text);
        row["Title"] = linkBtn.Text;
        row["unitPrice"] = unitPrice;
        row["Quantity"] = 1;
        row["Price"] = unitPrice * 1;
        dt.Rows.Add(row);
        Session["ShopingCar"] = dt;
    }
    protected void LinkButton1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "kk")
            Response.Redirect("bookInfo.aspx?id=" + e.CommandArgument);
    }
    protected void ImageButton1_Command1(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "yy")
            Response.Redirect("bookInfo.aspx?id=" + e.CommandArgument);
    }
    protected void btnbuy_Command(object sender, CommandEventArgs e)
    {
        if (Session["userId"] == null)
            ClientScript.RegisterStartupScript(typeof(string), "a", "alert('您上未登录\\n请快点登录吧!');window.location='login.aspx'", true);
        if (e.CommandName == "Buy")
        {
            DataListItem item = ((ImageButton)sender).Parent as DataListItem;
           int num= item.ItemIndex;
            int id = int.Parse(e.CommandArgument.ToString());
            if (Session["ShopingCar"] != null)
            {
                DataTable dt = Session["ShopingCar"] as DataTable;
                if (!ex(dt, id))
                {
                    addRow(dt, id,num);
                    ClientScript.RegisterStartupScript(typeof(string), "b", "alert('已经成功添加到您的购物车')", true);
                }
            }
            else
            {
                addTable(id,num);
                ClientScript.RegisterStartupScript(typeof(string), "c", "alert('已经成功添加到您的购物车')", true);
            }
        }
    }
    protected void btnMonry_Click(object sender, EventArgs e)
    {
        ViewState["orderbyType"] = "price";
        string cupager = lblcruutenPager.ToString();
        show(null, cupager);
        btnMonry.Enabled = false;
    }
    protected void btndate_Click(object sender, EventArgs e)
    {
        ViewState["orderbyType"] = "date";
        string cupager = lblcruutenPager.ToString();
        show(null, cupager);
        btndate.Enabled = false;
    }
}

⌨️ 快捷键说明

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