btnNext_Click事件负责生成订单其主要代码如程序所示
程序 ST_ShipInfoaspxcs
protected void btnNext_Click(object
sender SystemEventArgs e)
{
//取出购物车中的图书信息
ST_BookBizST_Cart cart =
(ST_BookBizST_Cart)Session[Cart];
DataTable table = null;
if (cart != null)
{
table = cartGetProductItems()
}
float sum = f;
for(int i=;i<tableRowsCount;i++)
{
sum += floatParse(table
Rows[i][ST_Total]ToString())
}
ST_BookBizST_Identity identity = new
ST_BookBizST_Identity(UserIdentityName)
int userid = identityUserID;
ST_BookBizST_OrderEntity st_entity = new
STGROUPST_BookBizST_OrderEntity()
st_entityST_Consignee = txtNameText;
st_entityST_ConsingeeAddress = txtAddressText;
st_entityST_ConsingeeEmail = txtEmailText;
st_entityST_ConsingeePhone = txtPhoneText;
st_entityST_ConsingeePostcode = txtPostCodeText;
st_entityST_CreateTime = DateTimeNow;
st_entityST_Payment = SelectValue;
st_entityST_Ship = SelectValue;
st_entityST_UserID = userid;
st_entityST_Sum = sum;
//生成订单
ST_BookBizST_Order st_order = new
STGROUPST_BookBizST_Order()
st_orderInsertOrder(st_entity)
//清空购物车
SessionRemove(Cart)
ResponseWrite(<script language=
javascript>alert(订单生成成功)
windowtoplocation=/ST_Common/
st_mainaspx;</script>)
}
【代码说明】代码第行首先读取Session中保存的购物车信息代码第~行是获取更新的用户信息代码第~行用来生成订单订单生成后代码第行用来清空购物车
ST_Cart类的GetProductItems()方法的代码如程序所示
程序 ST_Cartcs
public DataTable GetProductItems()
{
//生成一个新表
DataTable table = new DataTable()
//添加列
tableColumnsAdd(itemIndex)
tableColumnsAdd(ST_ProductId)
tableColumnsAdd(ST_ProductName)
tableColumnsAdd(ST_Price)
tableColumnsAdd(ST_SoldPrice)
tableColumnsAdd(ST_Quantity)
tableColumnsAdd(ST_Total)
//向表中添加数据
foreach(object obj in thisGetProducts())
{
ST_OrderProduct product = (ST_OrderProduct)obj;
//生成新行
DataRow row = tableNewRow()
row[itemIndex] = thisIndex;
row[ST_ProductId] = productST_ProductID;
row[ST_ProductName] = productST_ProductName;
row[ST_Price] = productST_Price;
row[ST_SoldPrice] = productST_SoldPrice;
row[ST_Quantity] = productST_Quantity;
row[ST_Total] = productTotal;
//插入行
tableRowsAdd(row)
}
return table;
}
【代码说明】代码第~行用来生成一个新的数据表代码第~行是遍历订单中的每一行数据因为每一行就是一种图书代码第行返回一个数据表给调用者
注意第行中遍历数据时因为无法提前获知数据类型遍历时都使用了object类型
返回目录ASPNET项目开发指南
编辑推荐
ASPNET MVC 框架揭秘
ASPNET开发宝典
ASP NET开发培训视频教程
[] []