您现在的位置是:首页 >

毒订单生成软件 ASP.NET项目开发指南:订单的生成(2)[2]

火烧 2022-05-03 08:13:02 1035
ASP.NET项目开发指南:订单的生成(2)[2]    t Next_Click事件负责生成订单 其主要代码如程序 所示   程序 ST_Shi I fo a x c    rotected voi

ASP.NET项目开发指南:订单的生成(2)[2]  

毒订单生成软件 ASP.NET项目开发指南:订单的生成(2)[2]

  btnNext_Click事件负责生成订单 其主要代码如程序 所示

  程序   ST_ShipInfo aspx cs

     protected void btnNext_Click(object

  sender System EventArgs e)

     {

         //取出购物车中的图书信息

         ST_BookBiz ST_Cart cart =

  (ST_BookBiz ST_Cart)Session[ Cart ];

         DataTable table = null;

         if (cart != null)

         {

             table = cart GetProductItems()

         }

         float sum = f;

         for(int i= ;i<table Rows Count;i++)

         {

             sum += float Parse(table

  Rows[i][ ST_Total ] ToString())

         }

         ST_BookBiz ST_Identity identity = new

                 ST_BookBiz ST_Identity(User Identity Name)

         int userid = identity UserID;

         ST_BookBiz ST_OrderEntity st_entity = new

                 STGROUP ST_BookBiz ST_OrderEntity()

         st_entity ST_Consignee = txtName Text;

         st_entity ST_ConsingeeAddress = txtAddress Text;

         st_entity ST_ConsingeeEmail = txtEmail Text;

         st_entity ST_ConsingeePhone = txtPhone Text;

         st_entity ST_ConsingeePostcode = txtPostCode Text;

         st_entity ST_CreateTime = DateTime Now;

         st_entity ST_Payment = Select Value;

         st_entity ST_Ship = Select Value;

         st_entity ST_UserID = userid;

         st_entity ST_Sum = sum;

  

         //生成订单

         ST_BookBiz ST_Order st_order = new

  STGROUP ST_BookBiz ST_Order()

         st_order InsertOrder(st_entity)

         //清空购物车

         Session Remove( Cart )

         Response Write( <script language=

  javascript >alert( 订单生成成功 )

         window top location= /ST_Common/

  st_main aspx ;</script> )

     }

  【代码说明】代码第 行首先读取Session中保存的购物车信息 代码第 ~ 行是获取更新的用户信息 代码第 ~ 行用来生成订单 订单生成后 代码第 行用来清空购物车

  ST_Cart类的GetProductItems()方法的代码如程序 所示

  程序   ST_Cart cs

     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 obj in this GetProducts())

         {

             ST_OrderProduct product = (ST_OrderProduct)obj ;

             //生成新行

             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;

     }

  【代码说明】代码第 ~ 行用来生成一个新的数据表 代码第 ~ 行是遍历订单中的每一行数据 因为每一行就是一种图书 代码第 行返回一个数据表给调用者

  注意 第 行中遍历数据时 因为无法提前获知数据类型 遍历时都使用了object类型

      返回目录ASP NET项目开发指南

      编辑推荐

       ASP NET MVC 框架揭秘

       ASP NET开发宝典

       ASP NET开发培训视频教程

lishixinzhi/Article/program/net/201311/15820  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码