第四次團隊做業

1、代碼倉庫地址html

 https://github.com/SE17/Order-food-on-the-Internetgit

2、Quick Start(簡易快速使用指南)github

1.註冊功能web

 

 

2.登陸功能sql

 

 

3.瀏覽商品數據庫

 
 

 

3.1查看商品詳情測試

 

 

3.2搜索商品ui

 
 

 

4.我的訂單url

 

 

5.個人收藏spa

 

 

3、代碼實現:闡述是如何實現產品的,文字內容用於輔助閱讀源代碼(好比代碼目錄結構),能夠粘一些核心代碼,不要大段大段代碼地貼。

 

.net代碼目錄

數據庫代碼目錄

   

 

舉例說明:商品瀏覽模塊

.net代碼視圖層

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="goodlist.aspx.cs" Inherits="OnlineOrder.goodlist" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>無標題頁</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <center>

        <asp:HyperLink ID="HyperLink7" runat="server" NavigateUrl="Index.aspx">首頁</asp:HyperLink>      

        <asp:HyperLink ID="HyperLink1" runat="server">註冊</asp:HyperLink>

        <asp:HyperLink ID="HyperLink2" runat="server">登陸</asp:HyperLink>

    </center>    

    </div>

    <div>

    <center >

        <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>   

        <asp:Button ID="Button1" runat="server" Text="搜索" onclick="Button1_Click" />

    </center>      

    </div>

    <div>

     <center>    

         <asp:Label ID="Label3" runat="server" Text="排序"></asp:Label>

         <asp:DropDownList ID="DropDownList1" runat="server" onselectedindexchanged="DropDownList1_SelectedIndexChanged">

             <asp:ListItem Value="pro_price" Selected="True">價格</asp:ListItem>

             <asp:ListItem Value="pro_amount">商品庫存數</asp:ListItem>

         </asp:DropDownList>

       

         <asp:DropDownList ID="DropDownList2" runat="server"

             onselectedindexchanged="DropDownList2_SelectedIndexChanged">

             <asp:ListItem Value="ASC" Selected="True">升序</asp:ListItem>

             <asp:ListItem Value="DESC">降序</asp:ListItem>

         </asp:DropDownList>

       

     </center>  

    </div>

    <div>

    <center>      

       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"

            BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"

            CellPadding="4" AllowPaging="True" EmptyDataText="暫無記錄" >

            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />

            <Columns>

               

                <asp:TemplateField HeaderText="商品名稱" SortExpression="商品名稱">

                    <ItemTemplate>

                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("商品名稱") %>'></asp:Label>

                    </ItemTemplate>

                </asp:TemplateField>

                <asp:ImageField AlternateText="123" DataImageUrlField = "商品圖片" >

                                       

                 </asp:ImageField>

                <asp:TemplateField HeaderText="商品價格" SortExpression="商品價格">

                    <ItemTemplate>

                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("商品價格") %>' ></asp:Label>

                    </ItemTemplate>

                </asp:TemplateField>

               

                <asp:HyperLinkField DataNavigateUrlFields="pro_id" Text="查看詳情"

                  HeaderText="查看詳情" DataNavigateUrlFormatString="GoodDetail.aspx?pro_id={0}" />

           </Columns>

            <RowStyle BackColor="White" ForeColor="#003399" />

            <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />

            <PagerStyle BackColor="#C0C0FF" ForeColor="#003399" HorizontalAlign="Left" />

            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />

        </asp:GridView>      

    </center>

       

    </div>

    </form>

    <p>

          

    </p>

</body>

</html>

.net代碼控制層(調用數據庫接口)

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

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.Xml.Linq;

using System.Data.SqlClient;

 

namespace OnlineOrder

{

    public partial class goodlist : System.Web.UI.Page

    {

        SqlConnection con;

        String ConnectionString = "Data Source=localhost;Persist Security Info=True;User ID=sa;Password=root; Initial Catalog=OnlineOrderVegetable;";

        SqlCommand com;

        SqlDataAdapter da;

        DataTable table;

        protected void Page_Load(object sender, EventArgs e)

        {

            if (Session["webuser_id"] != null)

            {

                HyperLink1.Text = Session["account"].ToString();

                HyperLink1.NavigateUrl = "UserInfo.aspx";

                HyperLink2.Text = "購物車";

                HyperLink2.NavigateUrl = "Cart.aspx";

            }

            //搜索框搜索

            if (Request.QueryString["key"] != null)

            {

                String key = Request.QueryString["key"];

          

                produceSearch(key);                          

            

            }

             //類別搜索

            else

            {

                produceSelect();

 

            }      

        }

        //關鍵字模糊查詢

        protected void produceSearch(string key)

        {

            String sql = "proc_ProduceNameSelect";

            con = new SqlConnection(ConnectionString);

            //打開鏈接

            con.Open();

            //生成SqlCommand對象

            com = new SqlCommand(sql, con);

            //選擇執行命令,存儲過程

            com.CommandType = CommandType.StoredProcedure;

            //添加參數

            com.Parameters.AddWithValue("@key", key);

            //執行存儲過程

            com.ExecuteNonQuery();

            //生成Adapter對象

            da = new SqlDataAdapter();

            //生成table

            table = new DataTable();

            //Adapter對象獲取數據

            da.SelectCommand = com;

            //Adapter對象填充數據

            da.Fill(table);

            //釋放對象

            con.Close();

            //數據綁定

            GridView1.DataSource = table;

            GridView1.DataBind();

        }

        //商品類別檢索

        protected void produceSelect()

        {

            String sql = "proc_ProduceSelect";

            String protype_id = Request.QueryString["protype_id"];

            con = new SqlConnection(ConnectionString);

            //打開鏈接

            con.Open();

            //生成SqlCommand對象

            com = new SqlCommand(sql,con);

          

            //選擇執行命令,存儲過程

            com.CommandType = CommandType.StoredProcedure;

            //添加參數

            com.Parameters.AddWithValue("@protype_id", protype_id);

            //調用數據庫接口存儲過程proc_ProduceSelect

            com.ExecuteNonQuery();

            //生成Adapter對象

            da = new SqlDataAdapter();

            //生成table

            table = new DataTable();

            //Adapter對象獲取數據

            da.SelectCommand = com;

            //Adapter對象填充數據

            da.Fill(table);

            //釋放對象

            con.Close();

            //數據綁定

            GridView1.DataSource = table;

            GridView1.DataBind();

        }

 

       //響應用戶搜索請求

        protected void Button1_Click(object sender, EventArgs e)

        {

            string key;

            string url;

            key = TextBox1.Text;

            //彈出對話框?

            if (key == null || key == "")

            {

 

            }

            else

            {

                url = "goodlist.aspx?key=" + key;

                Response.Redirect(url);

            }

        }

      

    }

}

Sql 存儲過程接口proc_ProduceSelect

--存儲過程:proc_ProduceSelect

--功能:分類瀏覽商品

--輸入參數:商品類別編號、排序字段、排序類別

ALTER PROC proc_ProduceSelect

@protype_id char(10)=NULL,

@order_name varchar(10)=NULL,

@order_type varchar(10)='ASC'

AS

BEGIN

         DECLARE @sql varchar(255)

         IF(@order_name IS NULL)

         BEGIN

                   SELECT pro_id ,pro_name 商品名稱,protype_name 商品類別,pro_icon 商品圖片,pro_price 商品價格,pro_disprice 促銷價,pro_amount 商品數量,collect_num 收藏次數

                   FROM produce INNER JOIN protype

                   ON produce.protype_id = protype.protype_id

                   WHERE (@protype_id = produce.protype_id OR @protype_id IS NULL)

         END

         ELSE

         BEGIN

                   SET @sql = 'SELECT pro_id 商品編號,pro_name 商品名稱,protype_name 商品類別,pro_icon 商品圖片,pro_price 商品價格,pro_amount 商品數量

                   FROM produce INNER JOIN protype '+

                   'ON produce.protype_id = protype.protype_id '+

                   'WHERE ( produce.protype_id '+'LIKE '+@protype_id +' )'

                   +' ORDER BY '+@order_name+' '+@order_type

                   EXEC(@sql)

         END

END

GO

 

4、 軟件測試:闡述如何測試所開發的軟件。

因爲本產品尚未正式發佈,沒法讓測試人員進行黑盒測試。

此處選擇讓開發人員一邊開發一邊進行白盒測試:測試存儲過程可否正常執行功能。

舉例模塊:用戶下訂單模塊

 

--①生成用戶2的一條訂單,返回訂單編號給用戶

DECLARE @order_id int

EXEC proc_OrdersInsert 2,4,@order_id OUTPUT

PRINT '訂單編號:'+CAST(@order_id AS VArchar(4))

GO

(1 行受影響)

訂單編號:24

 

--②根據訂單編號和訂單中的商品系統自動生成訂單明細

--若其中某種商品庫存不足,則刪除該訂單。

 

--a.若其中某種商品庫存不足,則刪除該訂單。

EXEC proc_OrdersInfoInsert 20,1,3

GO

--查看該訂單20,已被刪除。

EXEC proc_OrdersInfoOrderIdSelect 20

GO

沒有該訂單!

--b. 給24號訂單添加1件1號商品,4件2號商品

EXEC proc_OrdersInfoInsert 24,1,1

GO

EXEC proc_OrdersInfoInsert 24,2,4

GO

 

--③生成給用戶的訂單,訂單狀態默認爲‘待付款’

EXEC proc_OrdersInfoOrderIdSelect 24

GO

 

 

--④用戶給24號訂單付款,扣除用戶餘額

--付款前

EXEC proc_WebuserSelect '15985700852'

GO

 

--付款結果,成功以後系統根據用戶最近下單狀況,自動推薦兩種類別的隨機產品給用戶。

DECLARE @result varchar(20)

EXEC proc_OrderStateUpdatePay 24,2,@result OUTPUT

PRINT @result

GO

(1 行受影響)

付款成功

 

--付款後,用戶帳號餘額狀況

EXEC proc_WebuserSelect '15985700852'

GO

 

 

--⑤用戶確認收貨訂單24號

EXEC proc_OrderStateUpdateReceive 24

GO

成功收到24號訂單,該訂單等待您的評價~

(1 行受影響)

 

--⑥2號用戶對剛纔收到的24號訂單的商品作出評價

--對2號商品的評價

exec proc_OrderStateUpdateComment 2,24,"食材新鮮美味!還會回購的。"

GO

--對1號商品的評價

exec proc_OrderStateUpdateComment 1,24,"味道通常吧。"

GO

 

 

--⑦若用戶喜歡哪一件商品,能夠對商品進行收藏

--2號用戶對2號商品進行了收藏

exec proc_CollectInsert 2,2

成功收藏2號商品!

相關文章
相關標籤/搜索