?? displayproduct.aspx.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 + -