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

📄 displayproduct.aspx.cs

📁 是一个很好的电子商务系统,是用C#语言开发的,能够完成网上购物的功能
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 System.Data.SqlClient;

public partial class DisplayProduct : System.Web.UI.Page
{
    private static int productid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["PID"] != "")
        {
            productid = Int32.Parse(Request.QueryString["PID"].ToString());
        }
        if (!Page.IsPostBack)
        {
            this.GetProductDataByPIDBind();
            this.GetReviewsDataBind();
        }
    }
    private void GetProductDataByPIDBind()
    {
        ProductDB pdb = new ProductDB();
        SqlDataReader Sdr=pdb.GetProductData(productid);
        this.DListProduct.DataSource=Sdr;
        this.DListProduct.DataBind();
        Sdr.Close();
    }
   
    private void GetReviewsDataBind()
    {
        ReviewDB rdb = new ReviewDB();
        SqlDataReader Sdr = rdb.GetReViewsData(productid);
        this.DListReView.DataSource = Sdr;
        this.DListReView.DataBind();
        Sdr.Close();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        if (this.DropDownList1.SelectedIndex > 0)
        {
            ReviewDB rdb = new ReviewDB();
            Review re = new Review();
           
            //if (this.TextBox1.Text != "" && this.TextBox2.Text != "" && this.TextBox3.Text != "")
            //{
            //    if (GetStrData()!="")
            //    {
                re.ProductID = productid;

                re.Name = this.TextBox1.Text;
                re.Email = this.TextBox2.Text;
                re.Rating = Int32.Parse(this.DropDownList1.SelectedValue);
                re.Comments = this.TextBox3.Text;
                rdb.AddReViewsData(re);
                Response.Write("<script>alert('商品评论成功!')</script>");
                this.TextBox1.Text = "";
                this.TextBox2.Text = "";
                this.TextBox3.Text = "";
                this.DropDownList1.SelectedIndex=0;
                this.GetReviewsDataBind();
        //    }
        //    else
        //    {
        //        Response.Write("<script>alert('Deny')</script>");
        //    }
           
        //}
    
       }
        else
       {
           Response.Write("<script>alert('请选择评论级别!')</script>");
       }
   }
    //private string GetStrData()
    //{
    //    string str = this.TextBox1.Text.Trim();
    //    for(int i=0;i<str.Length;i++)
    //    {
    //        if (!((str.ToCharArray(i, 1)[0] >= 'a') && (str.ToCharArray(i, 1)[0] <= 'z')) || ((str.ToCharArray(i, 1)[0] >= 'A') && (str.ToCharArray(i, 1)[0] <= 'Z')))
    //        {
    //            str ="";
    //            break;
    //        }
   //}
    //return str ;
        
    //}
    protected void DListProduct_ItemCommand(object source, DataListCommandEventArgs e)
    {
         if (!User.Identity.IsAuthenticated)
        {
            Response.Redirect("~/login_Register.aspx");
        }
        else
        {
            Shopcart shopcart = new Shopcart();
            shopcart.CustomerID = User.Identity.Name;
            shopcart.Quantity = 1;
            shopcart.ProductID = Int32.Parse(e.CommandArgument.ToString());
            ShopcarDB Sdb = new ShopcarDB();
            if (Sdb.GetShopcartItem(shopcart) > 0)
            {
                Sdb.UpdateShopCartFirst(shopcart, true);
            }
            else 
            {
                Sdb.AddShopCart(shopcart);
            }
        }
    
    }
}

⌨️ 快捷键说明

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