protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ if (Request.QueryString["ProductId"] != null)
{
string Id = Request.QueryString["ProductId"].ToString();
try
{
decimal.Parse(Id);
}
catch
{
Response.Write("请不要从外部提交非法字串!!!");
return;
}
//读取cookie
if (Request.Cookies["UserBus"] != null && Request.Cookies["UserBus"].Values.Count > 0)
{
HttpCookie cookie = Request.Cookies["UserBus"];
if (cookie.Values.ToString().IndexOf(Id) == -1)
{
cookie.Values.Add(Id, "'"+Id + "'$1");
}
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie); }
else
{
HttpCookie cookie = new HttpCookie("UserBus");//定义cookie对象以及名为Info的项
cookie.Values.Add(Id, "'"+Id + "'$1");
Response.AppendCookie(cookie);//确定写入cookie中
}
}
BindDropDownList();
LoadDefault();
BindDataGrid(); } } //绑定gridView
protected void BindDataGrid()
{ string Ids = "";
HttpCookie getcookie = Request.Cookies["UserBus"];
string[] arr = new string[getcookie.Values.Count];
for (int i = 0; i < getcookie.Values.Count; i++)
{
string value = getcookie.Values[i].ToString();
Ids += value.Split('$')[0].ToString() + ",";
arr[i] = value.Split('$')[1].ToString();
}
decimal productMoney = 0;//商品总价
decimal CostPrice = 0; // 商品成本价
int Weight = 0;//商品总重量
int Number = 0;//商品总数量 DataTable dt = new DataTable();
if (Ids.Length > 1)
{
int page = 0;
int i, j;
dt = NetCMS.Content.Search.getShopViewHistory(Ids.Substring(0, Ids.Length - 1), page, 15, out i, out j); if (dt != null && dt.Rows.Count > 0)
{
dt.Columns.Add("num", typeof(string));
dt.Columns.Add("money", typeof(decimal));
for (int k = 0; k < dt.Rows.Count; k++)
{
dt.Rows[k]["num"] = arr[k];
decimal money = Convert.ToDecimal(dt.Rows[k]["SalePrice"].ToString());
dt.Rows[k]["money"] = money * Convert.ToInt32(arr[k]);
productMoney += money * Convert.ToInt32(arr[k]);
CostPrice += Convert.ToDecimal(dt.Rows[k]["CostPrice"].ToString()) * Convert.ToInt32(arr[k]);
Weight += Convert.ToInt32(dt.Rows[k]["Weight"].ToString()) * Convert.ToInt32(arr[k]);
}
}
} GridView1.DataSource = dt;
GridView1.DataBind(); this.productMoney.Text = string.Format("{0:F2}",productMoney.ToString());
this.Weight.Value = Weight + "";
this.CostPrice.Value = CostPrice + "";
}
{
if (!IsPostBack)
{ if (Request.QueryString["ProductId"] != null)
{
string Id = Request.QueryString["ProductId"].ToString();
try
{
decimal.Parse(Id);
}
catch
{
Response.Write("请不要从外部提交非法字串!!!");
return;
}
//读取cookie
if (Request.Cookies["UserBus"] != null && Request.Cookies["UserBus"].Values.Count > 0)
{
HttpCookie cookie = Request.Cookies["UserBus"];
if (cookie.Values.ToString().IndexOf(Id) == -1)
{
cookie.Values.Add(Id, "'"+Id + "'$1");
}
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie); }
else
{
HttpCookie cookie = new HttpCookie("UserBus");//定义cookie对象以及名为Info的项
cookie.Values.Add(Id, "'"+Id + "'$1");
Response.AppendCookie(cookie);//确定写入cookie中
}
}
BindDropDownList();
LoadDefault();
BindDataGrid(); } } //绑定gridView
protected void BindDataGrid()
{ string Ids = "";
HttpCookie getcookie = Request.Cookies["UserBus"];
string[] arr = new string[getcookie.Values.Count];
for (int i = 0; i < getcookie.Values.Count; i++)
{
string value = getcookie.Values[i].ToString();
Ids += value.Split('$')[0].ToString() + ",";
arr[i] = value.Split('$')[1].ToString();
}
decimal productMoney = 0;//商品总价
decimal CostPrice = 0; // 商品成本价
int Weight = 0;//商品总重量
int Number = 0;//商品总数量 DataTable dt = new DataTable();
if (Ids.Length > 1)
{
int page = 0;
int i, j;
dt = NetCMS.Content.Search.getShopViewHistory(Ids.Substring(0, Ids.Length - 1), page, 15, out i, out j); if (dt != null && dt.Rows.Count > 0)
{
dt.Columns.Add("num", typeof(string));
dt.Columns.Add("money", typeof(decimal));
for (int k = 0; k < dt.Rows.Count; k++)
{
dt.Rows[k]["num"] = arr[k];
decimal money = Convert.ToDecimal(dt.Rows[k]["SalePrice"].ToString());
dt.Rows[k]["money"] = money * Convert.ToInt32(arr[k]);
productMoney += money * Convert.ToInt32(arr[k]);
CostPrice += Convert.ToDecimal(dt.Rows[k]["CostPrice"].ToString()) * Convert.ToInt32(arr[k]);
Weight += Convert.ToInt32(dt.Rows[k]["Weight"].ToString()) * Convert.ToInt32(arr[k]);
}
}
} GridView1.DataSource = dt;
GridView1.DataBind(); this.productMoney.Text = string.Format("{0:F2}",productMoney.ToString());
this.Weight.Value = Weight + "";
this.CostPrice.Value = CostPrice + "";
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货