1、ASPNET应用开发综合实验报告网上订购系统实验报告姓名:蔡双江 学号:1108203422班级:软件114 指导老师:张金姬 一、 实验目的1、 学习在ASP.NET+SQL Server平台设计动态网站的方法2、 掌握设计网站涉及到的各种技术:模板设计、样式设计、站点地图导航设计、主页面设计与编程、功能页面设计与编程3、 掌握ASP.NET应用程序访问数据库的技术4、 掌握ASP.NET提供的各种控件应用技巧及主要事件处理程序的编程二、 实验内容和要求1、 设计网站模板、样式、菜单导航2、 购物网站所管理的信息数据库3、 设计网站主页4、 按站点地图设计各功能页面并编写相应的事件处理程序三
2、、 实验步骤1、 新建项目并构建购物网站母版页备注:打开Visual Studio 2005,新建ASP.Net网站并设置保存路径,新建母版页以下为设计好母版页的框架备注:创建网站模板时,需要注意排版的高度宽度尺寸,我设置的网站宽度为850px,高度为649px;其中最上的Logo栏高度为181px,菜单栏高度为30px;导航栏高度占380px,宽度为170px;编辑区域高度和导航栏高度保持一致为380px,宽度为680px;最底端处高度为58px。2、 数据库设计:(一共7个信息表)员工信息表客户信息表订单信息表订单详情表产品信息表产品类别表供应商信息表3、 建立站点地图Web.sitema
3、p文件 4、 设计层叠样式右击-添加样式规则选择元素、类名或者元素ID右击生成样式,对字体、背景、文本等等进行编辑,代码自动生成。BODYbackground-color: #ddedd0;.tr border-right: black thin solid; border-top: black thin solid; border-left: black thin solid; border-bottom: black thin solid;A:hover font-weight: bold; color: purple; font-family: 华文中宋; text-decoration
4、: underline overline; font-size: 18px;.bbackground-color: #ddedd0;#td1background-image:url(img/logo.jpg);#td2background-image:url(img/left.jpg);#b1background-color:transparent;#b3background-color: transparent;#div2 width:476px; height:316px; background-image:url(img/mb.jpg); display:none; font-famil
5、y:黑体; font-size:large;5、 数据库连接SqlConnection conn = new SqlConnection(); conn.ConnectionString = Data Source=.;Initial Catalog=shopping;Integrated Security=True; SqlCommand cmd = new SqlCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = sql; cmd.Connection = conn;6、 设计员工或客户注
6、册备注:采用上传控件FileUpload,并将上传路径显示在Label内。上传员工照片代码: string zp = Label1.Text; string xqah = ; for (int i = 0; i 3; i+) if (this.CheckBoxList1.Itemsi.Selected) xqah = xqah + + CheckBoxList1.Itemsi.Text; string csrq = TextBox8.Text; string sql =insert into dbo.Member(MemberID,memName,Title,Address,City,Phon
7、e,pwd,xingbie,csny,xqah,memphoto)values(+ygh+,+xm+,+zw+,+xxdz+,+cs+,+lxfs+,+mm+,+xb+,+csrq+,+xqah+,+zp+); SqlConnection conn=new SqlConnection(); conn.ConnectionString = Data Source=.;Initial Catalog=shopping;Integrated Security=True; SqlCommand cmd=new SqlCommand(); cmd.CommandType=System.Data.Comm
8、andType.Text; cmd.CommandText=sql; cmd.Connection =conn; try conn.Open(); int num = cmd.ExecuteNonQuery() ; if (num = 1) Response.Write(操作:插入成功!); catch(Exception ex) Response.Write(ex.Message.ToString(); finally /关闭对象 if(conn!=null) conn.Close(); protected void Button2_Click(object sender, EventArg
9、s e) string flname = FileUpload1.FileName; Label1.Text =+ upload + flname.Substring(flname.LastIndexOf()+1); string fm = flname.Substring(flname.LastIndexOf()+1); FileUpload1.PostedFile.SaveAs(HttpRuntime.AppDomainAppPath+upload+fm); 7、 分类查询设计以及详细信息显示备注:使用下拉框控件DropDrownList并勾选AutoPostBack选项,实现无刷新显示所
10、查询的类别商品信息。8、 登陆页面设计以及密码修改9、 购物车设计备注:在C盘下路径:WINDOWSMicrosoft.NETFramworkv2.0.50727下找到_regsql.exe文件,并直接双击它即可对Profile的配置实现多用户(支持匿名用户)购物系统。Web.config文件代码“Asp.Net 配置”选项。 设置和注释的完整列表在 ments 中,该文件通常位于 WindowsMicrosoft.NetFrameworkv2.xConfig 中-configuration xmlns= !- 通过 节可以配置 ASP.NET 使用的 安全身份验证模式, 以标识传入的用户。
11、- !- - !- 如果在执行请求的过程中出现未处理的错误, 则通过 节可以配置相应的处理步骤。具体说来, 开发人员通过该节可以配置 要显示的 html 错误页 以代替错误堆栈跟踪。 - 备注:采用DetailView表显示所选商品的详细信息,并且LinkButton控件点击事件引入CartItem.cs和ShoppingCart.cs来对所购商品进行加入购物车处理CartItem.csusing System;using System.Collections.Generic;using System.Web; Serializablepublic class Cartitem private
12、 int prouductid; private string prouductname; private decimal bookprice; private int quality = 1; public int ProductId get return prouductid; public string prouductName get return prouductname; public decimal price get return bookprice; public int Quantity get return quality; set quality = value; pu
13、blic decimal subtotalprice get return bookprice * quality; public Cartitem(int Prouductid, string Prouductname, decimal pricE) prouductid = Prouductid; prouductname = Prouductname; bookprice = pricE; ShoppingCart.csusing System;using System.Collections.Generic;using System.Web;using System.Collectio
14、ns; Serializablepublic class ShoppingCart private Hashtable mycart = new Hashtable(); public ICollection CartItems get return mycart.Values; public decimal TotalPrice get decimal sum = 0; foreach (Cartitem item in mycart.Values) sum += item.price * item.Quantity; return sum; / 定义向购物车中添加 public void
15、AddBook(int productid, string productname, decimal price) Cartitem item = (Cartitem)mycartproductid; if (item = null) mycart.Add(productid, new Cartitem(productid, productname, price); else item.Quantity+; mycartproductid = item; public void RemoveBook(int productid) Cartitem item = (Cartitem)mycart
16、productid; if (item != null) mycart.Remove(productid); public void SetQuantity(int productid, int quanlity) Cartitem item = (Cartitem)mycartproductid; if (item != null & quanlity 0) item.Quantity = quanlity; mycartproductid = item; 备注:根据是否为匿名用户对购物车的商品是否被购入作出判断,如果用户尚未登录就给予尚未登录的警告框,登录之后则跳转到购买成功页面。购物车实
17、现代码using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class buyproduct3 : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) BindShoppingCart(); protected void GridView1_SelectedIndexChanged(object se
18、nder, EventArgs e) int id = (int)GridView1.SelectedDataKey.Value; Profile.ShoppingCart.RemoveBook(id); GridView1.SelectedIndex = -1; BindShoppingCart(); protected void BindShoppingCart() if (Profile.ShoppingCart != null) GridView1.DataSource = Profile.ShoppingCart.CartItems; GridView1.DataBind(); if
19、 (GridView1.FooterRow != null) Label1.Text = 总价: + Profile.ShoppingCart.TotalPrice.ToString(c); Sessiontotalprice = Profile.ShoppingCart.TotalPrice.ToString(c); protected void Txtproductquality_TextChanged1(object sender, EventArgs e) bool isSuccess = false; TextBox txtquality = new TextBox(); txtquality = (TextBox)GridView1.Rows0.Cells5.FindControl(txtproductquality); GridViewRow row = txtquality.Parent.Parent as GridViewRow; if (!string.IsNullOrEmpty(txtquality.Text)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1