网上商城详细设计说明书(共16页).doc
精选优质文档-倾情为你奉上网上商城设计详细说明书姓名: lclboss班级:微机1024 学号:1.引言1.1编写目的通过学习ASP.NET,以及结合教师给的源代码,进一步修改,从而实现网上商城系统1.2 前期工作在编写该需求前,首先是对各大网上销售网站进行了调查,其中包括:网页排版、顾客消费流程、以及管理员的操作,这三大块进行了调查。并总结出了有自己特色的设计思路。1.3编写背景随着Internet国际互联网的发展,越来越多的企业开始建造自己的网站。基于Internet的信息服务,商务服务已经成为现代企业一项不可缺少的内容。很多企业都已不满足于建立一个简单的仅仅能够发布信息的静态网站。现代企业需要的是一个功能强大的,能提供完善的电子商务服务的动态商务网站。本网上商城系统就是根据电子商务和互联网的发展,针对网上顾客所开发的网络购物系统,本商城系统主要有:1)用户浏览、注册、登录与购买商品;2)商品的入库资料登记;3)商城访问者的在线留言、查看留言,管理员的在线管理留言等;4)商城最新的新闻显示,历史新闻的分页显示,新闻详细情况的显示,后台管理员添加、删除、修改新闻等。本数据采用access作为数据库,亦可以使用SQL作为数据库,项目的重点是商品的添加、删除、显示与修改,需要克服的难点是商品图片的上传和删除。 2.技术概述2.1 目标我们使用C#以及数据库技术构建网站,争取将本网站做成一个界面友好、用户购物方便、管理员管理方便的购物系统。2.2 硬件支持Cpu: 弄个四核最好 比如老一代core Q84002.3 软件支持 操作系统:Windows xp/vista/seven均可,C#开发环境。3.功能需求3.1 功能块划分1)用户浏览、注册、登录与购买商品;2)商品的入库资料登记;3)商城访问者的在线留言、查看留言,管理员的在线管理留言等;4)商城最新的新闻显示,历史新闻的分页显示,新闻详细情况的显示,后台管理员添加、删除、修改新闻等。网上购物系统在线购物添加留言显示留言管理留言购物车管理商品管理分类展示生成订单商城留言4.具体设计4.1首页设计新建web窗体default.aspx,其代码为:<% Page Title="" Language="C#" MasterPageFile="/shop.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <style type="text/css"> .style23 width: 116px; height: 94px; .style24 width: 600px; height: 132px; .style25 width: 104px; .style26 width: 598px; .style27 width: 106px; </style></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <table style="font-size: 9pt" class="style24"> <tr> <td valign="top" align="left"> <table> <tr> <td class="style25" style="font-size: 11pt; color: #FFFFFF; background-color: #FF0000; border-width: 0px"> 热点促销 </td> <td style="font-size: 9pt; border-width: 0px; background-image: url('images/line.GIF'); width: 178px;"> <b><a href="newsmore.aspx">更多>>></a></b> </td> </tr> </table> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <a href="newsshow.aspx?id=<%#Eval("id") %>" target="_blank"> <%#Eval("title")%></a> <%#Eval("AddTime","0:d") %><br /> </ItemTemplate> </asp:Repeater> </td> <td valign="top"> <img alt="电话" src="images/TEL.gif" /> </td> </tr> </table> <table class="style26"> <tr> <td class="style27" style="font-size: 11pt; color: #FFFFFF; background-color: #FF0000; border-width: 0px"> 最新产品 </td> <td style="background-image: url('images/line.GIF')"> </td> </tr> </table> <asp:DataList ID="DataList1" runat="server" DataKeyField="bh" DataSourceID="AccessDataSource1" RepeatColumns="3" RepeatDirection="Horizontal" > <ItemTemplate> <a href="show.aspx?id=<%# Eval("bh") %>"> <altimg src="images/<%#Eval("pic")%>" class="style23" style="border-style: none" /><br /> <span><asp:Label ID="titleLabel" runat="server" Text='<%# Eval("productName") %>' /> <br /> <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>' /> </span></a> </ItemTemplate> </asp:DataList> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="/App_Data/shop.mdb" SelectCommand="SELECT top 9 bh, pic, price, productName FROM product order by bh desc "></asp:AccessDataSource></asp:Content>接着,切换到程序文件.cs编辑栏里,写入代码:using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) string strSQL = "select top 7 * from news order by id desc" Repeater1.DataSource =DbManager.ExecuteQuery(strSQL); Repeater1.DataBind(); 4.2商品详细信息页面设计新建show.aspx,配置好各项值以后,载入代码:<% Page Title="" Language="C#" MasterPageFile="/shop.master" AutoEventWireup="true" CodeFile="show.aspx.cs" Inherits="show" %><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> <style type="text/css"> .style3 width: 100%; .style4 text-align: center; width: 253px; </style> </asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <table class="style3"> <tr> <td class="style4"> <asp:Image ID="Image1" runat="server" /> <br /> <asp:Label ID="txtTitle" runat="server" Text="Label"></asp:Label> </td> <td align="left"> <br /> <asp:Label ID="txtContents" runat="server" Text="Label"></asp:Label> <br /> 售价:<asp:Label ID="txtPrice" runat="server" Text="Label"></asp:Label> </td> </tr> </table> <br /> 购买数量:<asp:TextBox ID="num" runat="server" Width="37px">1</asp:TextBox> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/images/gouWuChe3.jpg" Height="74px" ImageAlign="Middle" onclick="ImageButton1_Click" Width="72px"/></asp:Content>接着建立.cs程序文件,编辑写入以下代码:using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;public partial class show : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) string sql = "select * from product where bh=" + Request.QueryString"id" DataTable dt= DbManager.ExecuteQuery(sql); Image1.ImageUrl ="images/"+dt.Rows0"pic".ToString(); txtTitle.Text = dt.Rows0"productName".ToString(); txtContents.Text = dt.Rows0"contents".ToString(); txtPrice.Text = dt.Rows0"price".ToString(); protected void ImageButton1_Click(object sender, ImageClickEventArgs e) Response.Redirect("buy.aspx?id=" + Request.QueryString"id" + "&num=" + Convert.ToInt32(num.Text); 4.3 实现商品搜索功能新建search.aspx,配置相关参数,载入以下代码:<% Page Language="C#" MasterPageFile="/shop.master" AutoEventWireup="true" CodeFile="search.aspx.cs" Inherits="search" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <strong> 查询结果 <hr width="75%" /> </strong> <br /> <asp:Repeater ID="Repeater1" runat="server" > <HeaderTemplate> <table> </HeaderTemplate> <ItemTemplate> <tr><td> <%#Eval("bh") %></td> <td><a href="show.aspx?id=<%#Eval("bh") %>" target="_blank"><%#Eval("productName")%></a></td></tr> </ItemTemplate> <FooterTemplate></table></FooterTemplate> </asp:Repeater></asp:Content>然后编辑.cs文件using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class search : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) string strSQL = "select * from product where productName like '%" + Server.UrlDecode(Request.QueryString"txtSearchName") + "%'" DataTable dt = DbManager.ExecuteQuery(strSQL); Repeater1.DataSource = dt; Repeater1.DataBind(); 4.4商城后台管理登录设计新建一个login.aspx,添加所需要的元件,在.cs程序文件中编写ImageButton的事件代码:using System;public partial class login : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) Session"pass" = 0; protected void Button1_Click(object sender, EventArgs e) if (TextBox3.Text != Request.Cookies"CheckCode".Value.ToString() Response.Write("<script>alert('验证码错误!')</script>"); else string strSQL = "select * from users where userName='" + TextBox1.Text + "' and pwd='" + TextBox2.Text + "'" if (DbManager.ExecuteQuery(strSQL).Rows.Count > 0) Session"pass" = 1; Response.Redirect("manageProduct.aspx"); else Response.Write("<script>alert('用户名或密码错误!')</script>"); 4.5商城后台商城管理页面设计新建.aspx文件,添加好所需控件元件以后,载入源代码:<% Control Language="C#" AutoEventWireup="true" CodeFile="fenyePro.ascx.cs" Inherits="fenyepro" %><div> <asp:DataList ID="DataList1" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"> <ItemTemplate> <a href="showpro.aspx?id=<%# Eval("bh") %>"> <img src="images/<%#Eval("pic")%>" class="style23" style="border-style: none" height="80" width="111" /></a><br /> <asp:Label ID="titleLabel" runat="server" Text='<%# Eval("productName") %>' /> 单价:<asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>' /> 元 <br /> <a href="updatepro.aspx?id=<%#Eval("bh")%>" target="_blank">修改</a> <a href="delpro.aspx?id=<%#Eval("bh")%>" target="_blank">删除</a> </span> </ItemTemplate> </asp:DataList> <asp:Panel ID="Panel1" runat="server"> <asp:Label ID="lblTotal" runat="server" Text=""></asp:Label> <asp:HyperLink ID="hlFirst" runat="server">首页</asp:HyperLink> <asp:HyperLink ID="hlPre" runat="server">上一页</asp:HyperLink> <asp:HyperLink ID="hlNext" runat="server">下一页</asp:HyperLink> <asp:HyperLink ID="hlLast" runat="server">末页</asp:HyperLink> 第<asp:TextBox ID="txtGoPage" runat="server" Width="40px"></asp:TextBox> 页<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="转到" /> </asp:Panel></div>然后编辑.cs程序文件,其代码为:using System;public partial class fenyepro : System.Web.UI.UserControl protected void Page_Load(object sender, EventArgs e) int iPageSize = 9; /每页几条 string strTableName = "product" /要显示的数据表 string strKey = "bh" /说明数据表的关键字段 string strOrder = "desc" /按关键字段升序asc,降序desc排列 string strFields = "*" /要显示的字段,用"*"表示或用英文逗号分隔开如"产品名称,单价,单位数量" int iCurPage; int iMaxPage = 1; string sql = "" string sqlstr = "select count(*) from " + strTableName; if (Request.QueryString"page" != "") iCurPage = Convert.ToInt32(Request.QueryString"page"); else iCurPage = 1; int intTotalRec = Convert.ToInt32(DbManager.ExecuteScalar(sqlstr);/求总记录数 if (intTotalRec % iPageSize = 0) iMaxPage = intTotalRec / iPageSize;/求总页数 else iMaxPage = intTotalRec / iPageSize + 1; if (iMaxPage = 0) iMaxPage = 1; if (iCurPage < 1) iCurPage = 1; else if (iCurPage > iMaxPage) iCurPage = iMaxPage; if (intTotalRec != 0) if (iCurPage = 1) sql = "select top " + iPageSize + " " + strFields + " from " + strTableName + " order by " + strKey + " " + strOrder; else sql = "select top " + iPageSize + " " + strFields + " from " + strTableName + " where " + strKey + " not in(select top " + (iCurPage - 1) * iPageSize + " " + strKey + " from " + strTableName + " order by " + strKey + " " + strOrder + " ) order by " + strKey + " " + strOrder; DataList1.DataSource = DbManager.ExecuteQuery(sql);/显示控件名称要根据实际使用控件名修改 DataList1.DataBind(); lblTotal.Text = "共有" + intTotalRec.ToString() + "条记录 当前是第" + iCurPage.ToString() + "/" + iMaxPage.ToString() + "页 " if (iCurPage != 1) hlFirst.NavigateUrl = Request.FilePath + "?page=1" hlPre.NavigateUrl = Request.FilePath + "?page=" + (iCurPage - 1); if (iCurPage != iMaxPage) hlNext.NavigateUrl = Request.FilePath + "?page=" + (iCurPage + 1); hlLast.NavigateUrl = Request.FilePath + "?page=" + iMaxPage; if (intTotalRec <= iPageSize) Panel1.Visible = false; else Panel1.Visible = true; protected void Button1_Click(object sender, EventArgs e) int iCurPage = 1; if (txtGoPage.Text != "") iCurPage = Convert.ToInt32(txtGoPage.Text); Response.Redirect(Request.FilePath + "?page=" + iCurPage); 然后建立商品显示窗体页,新建manageProduct.aspx,拖fenyePro.aspx到其中,添加一个“增加新商品”link,链接指向insertPro.aspx。接着,为manageProduct.aspx.cs添加程序代码:using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class manageProduct : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) if (Convert.ToInt32(Session"pass") != 1) Response.Write("<script>alert('用户名或密码不对,请重新登录')</script>"); Response.Write("<script>location.assign('login.aspx')</script>"); Response.End(); protected void Button1_Click(object sender, EventArgs e) Session.Clear(); Response.Redirect("default.aspx");4.6 建立删除商品信息页面在manageProduct.aspx中建立一个删除链接。指向delpro.aspx,并为程序文件添加代码:using System;using System.Data;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;/删除图片文件时要用到这个命名空间public partial class delpro : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) if (Convert.ToInt32(Session"pass") != 1) Respons