熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET項目開發指南:訂單的生成(2)[2]

2013-11-13 12:23:47  來源: .NET編程 

  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開發培訓視頻教程

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/15820.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.