📄 st_cart.cs
字号:
using System;
using System.Collections;
using System.Data;
namespace STGROUP.ST_BookBiz
{
/// <summary>
/// ST_Cart 的摘要说明。
/// </summary>
public class ST_Cart
{
public ST_Cart()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private int _index; // 该购物项在购物车中的编号
private ArrayList alItemList = new ArrayList();
public int Index
{
get{return _index;}
set{_index = value;}
}
public float Total
{
get
{
float total = 0.00F;
if (alItemList.Count == 0)
return total;
foreach (ST_OrderProduct op in alItemList)
total += op.Total;
return total;
}
}
public int Count
{
get{return alItemList.Count;}
}
public ICollection GetProducts()
{
return alItemList;
}
/// <summary>
/// 取得商品信息
/// </summary>
/// <param name="productID"></param>
/// <returns></returns>
public ST_OrderProduct GetProduct(long productID)
{
foreach (ST_OrderProduct op in alItemList)
{
if (op.ST_ProductID == productID)
{
return op;
}
}
return null;
}
/// <summary>
/// 添加商品至购物车
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public bool Add(ST_OrderProduct value)
{
bool result = true;
foreach (ST_OrderProduct op in alItemList)
{
if (op.ST_ProductID == value.ST_ProductID)
{
op.ST_Quantity += value.ST_Quantity;
return result;
}
}
alItemList.Add(value);
return result;
}
public void Remove(long productID)
{
foreach (ST_OrderProduct op in alItemList)
{
if (op.ST_ProductID == productID)
{
alItemList.Remove(op);
break;
}
}
}
// 更新商品数量,qty必须大于0,为0的情况(即删除商品的情况)在Remove函数处理
public void UpdateQty(long productID,int qty)
{
foreach (ST_OrderProduct op in alItemList)
{
if (op.ST_ProductID == productID)
{
op.ST_Quantity = qty;
return;
}
}
}
/// <summary>
/// 获得购物车中所有的商品
/// 将部分产品信息重新组合为一个数据表
/// </summary>
/// <returns></returns>
public DataTable GetProductItems()
{
DataTable table = new DataTable();
table.Columns.Add("itemIndex");
table.Columns.Add("ST_ProductId");
table.Columns.Add("ST_ProductName");
table.Columns.Add("ST_Price");
table.Columns.Add("ST_SoldPrice");
table.Columns.Add("ST_Quantity");
table.Columns.Add("ST_Total");
foreach(object obj1 in this.GetProducts())
{
ST_OrderProduct product = (ST_OrderProduct)obj1;
DataRow row = table.NewRow();
row["itemIndex"] = this.Index;
row["ST_ProductId"] = product.ST_ProductID;
row["ST_ProductName"] = product.ST_ProductName;
row["ST_Price"] = product.ST_Price;
row["ST_SoldPrice"] = product.ST_SoldPrice;
row["ST_Quantity"] = product.ST_Quantity;
row["ST_Total"] = product.Total;
table.Rows.Add(row);
}
return table;
}
/// <summary>
/// 构建订单详情的xml
/// </summary>
/// <returns></returns>
public string BuildXml()
{
string strLine = "";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach(ST_OrderProduct op in alItemList)
{
strLine = "<OrderItem ProductID='" + op.ST_ProductID.ToString() +
"' Quantity='" + op.ST_Quantity.ToString() +
"' PaySum='" + op.ST_Quantity*op.ST_SoldPrice +
"' Price='" + op.ST_Price.ToString() +
"' SoldPrice='" + op.ST_SoldPrice.ToString() +
" />";
sb.Append(strLine);
}
return sb.ToString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -