📄 shoppingcartaccess.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.Common;
/// <summary>
///ShoppingCartAccess 的摘要说明
/// </summary>
public static class ShoppingCartAccess
{
//取得客户的cookie的ID号
private static string shoppingCartId
{
get
{
HttpContext context = HttpContext.Current;
string cartId = "";
if (context.Request.Cookies["shoesShop_CartID"] != null)
{
cartId = context.Request.Cookies["shoesShop_CartID"].Value;
return cartId;
}
else
{
cartId = Guid.NewGuid().ToString();
HttpCookie cookie = new HttpCookie("shoesShop_CartID", cartId.ToString());
int howManyDays = DatabaseConfiguration.CartPersistDays;
DateTime currentDate = DateTime.Now;
TimeSpan timeSpan = new TimeSpan(howManyDays, 0, 0, 0);
DateTime expirationDate = currentDate.Add(timeSpan);
cookie.Expires = expirationDate;
context.Response.Cookies.Add(cookie);
return cartId.ToString();
}
}
}
//添加购物车信息
public static bool ShoppingCartAddItem(string BookId)
{
DbCommand cmd = CmdPart.CreateCommand();
cmd.CommandText = "ShoppingCartAddItem";
DbParameter param = cmd.CreateParameter();
param.ParameterName = "@CartID";
param.Value = shoppingCartId;
param.DbType = DbType.String;
param.Size = 36;
cmd.Parameters.Add(param);
param = cmd.CreateParameter();
param.ParameterName = "@BookID";
param.Value = BookId;
param.DbType = DbType.Int32;
cmd.Parameters.Add(param);
return CmdPart.ExcuteNonSelectCommand(cmd);
}
//显示购物车信息
public static DataTable GetShoppingCartItems()
{
DbCommand cmd = CmdPart.CreateCommand();
cmd.CommandText = "ShoppingCartGetItems";
DbParameter param = cmd.CreateParameter();
param.ParameterName = "@CartID";
param.Value = shoppingCartId;
param.DbType = DbType.String;
param.Size = 36;
cmd.Parameters.Add(param);
return CmdPart.ExcuteSelectCommand(cmd);
}
//取得购物车商品总价
public static decimal GetTotalAmount()
{
DbCommand cmd = CmdPart.CreateCommand();
cmd.CommandText = "ShoppingCartGetTotalAmount";
DbParameter param = cmd.CreateParameter();
param.ParameterName = "@CartID";
param.Value = shoppingCartId;
param.DbType = DbType.String;
param.Size = 36;
cmd.Parameters.Add(param);
return Decimal.Parse(CmdPart.ExecuteScalar(cmd));
}
//删除购物车某项信息
public static bool RemoveItem(string BookId)
{
DbCommand cmd = CmdPart.CreateCommand();
cmd.CommandText = "ShoppingCartRemoveItem";
DbParameter param = cmd.CreateParameter();
param.ParameterName = "@BookID";
param.Value = BookId;
param.DbType = DbType.Int32;
cmd.Parameters.Add(param);
param = cmd.CreateParameter();
param.ParameterName = "@CartID";
param.Value = shoppingCartId;
param.DbType = DbType.String;
param.Size = 36;
cmd.Parameters.Add(param);
return CmdPart.ExcuteNonSelectCommand(cmd);
}
//更新购物车信息
public static bool UpdateItem(string bookId, int quantity)
{
DbCommand cmd = CmdPart.CreateCommand();
cmd.CommandText = "ShoppingCartUpdateItem";
DbParameter param = cmd.CreateParameter();
param.ParameterName = "@CartID";
param.Value = shoppingCartId;
param.DbType = DbType.String;
param.Size = 36;
cmd.Parameters.Add(param);
param = cmd.CreateParameter();
param.ParameterName = "@BookID";
param.Value = bookId;
param.DbType = DbType.Int32;
cmd.Parameters.Add(param);
param = cmd.CreateParameter();
param.ParameterName = "@Quantity";
param.Value = quantity;
param.DbType = DbType.Int32;
cmd.Parameters.Add(param);
return CmdPart.ExcuteNonSelectCommand(cmd);
}
//取得订单号
public static object CreateCustomerOrder(string customerName)
{
DbCommand cmd = CmdPart.CreateCommand();
cmd.CommandText = "CreateCustomerOrder";
DbParameter param = cmd.CreateParameter();
param.ParameterName = "@CartID";
param.Value = shoppingCartId;
param.DbType = DbType.String;
param.Size = 36;
cmd.Parameters.Add(param);
param = cmd.CreateParameter();
param.ParameterName = "@CustomerName";
param.Value = customerName;
param.DbType = DbType.String;
cmd.Parameters.Add(param);
return CmdPart.ExecuteScalar(cmd);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -