PetShop课程设计报告.doc

上传人:仙人指路1688 文档编号:2884176 上传时间:2023-03-01 格式:DOC 页数:22 大小:413.50KB
返回 下载 相关 举报
PetShop课程设计报告.doc_第1页
第1页 / 共22页
PetShop课程设计报告.doc_第2页
第2页 / 共22页
PetShop课程设计报告.doc_第3页
第3页 / 共22页
PetShop课程设计报告.doc_第4页
第4页 / 共22页
PetShop课程设计报告.doc_第5页
第5页 / 共22页
点击查看更多>>
资源描述

《PetShop课程设计报告.doc》由会员分享,可在线阅读,更多相关《PetShop课程设计报告.doc(22页珍藏版)》请在三一办公上搜索。

1、 经济管理学院管科系 课程设计报告课程设计名称 : web技术课程设计 课程设计时间: 第19周上午4节和晚上4节 专 业 班 级 学生姓名 学 号 指导老师 课程设计报告格式1.课程设计目的 Web技术课程设计是信息管理与信息系统专业的一个重要的实践性环节,是Web开发技术课的理论实践,课程设计涉及到网页设计基础、数据库应用有关知识与技能,通过本课程设计目的是让学生掌握B/S体系结构开发的基本开发思想与开发步骤及方法,掌握设计、开发、调试Web应用系统,理解HTTP协议,掌握.NET环境下有关理论与特性,学会使用C#进行系统业务逻辑的编写,掌握使用 ADO.NET进行数据库开发,掌握ASP.

2、NET 控件和创建自定义 ASP.NET 控件,了解分层架构的基本思想。2.课程设计题目描述和要求 使用.NET技术实现类似Microsoft Petshop 4.0 的宠物店网站。 要求:使用主题、母版、Web用户控件、自定义控件等特性,使用标准、数据、验证、登录等控件,实现宠物浏览,购物车,用户注册登录等功能,独立完成,正常运行,鼓励创新。3.课程设计报告内容3.1 实现的主要功能和使用的关键技术3.2 主要文件及有关功能说明3.3 核心代码及有关逻辑说明3.4 遇到的主要问题及解决思路3.5 系统特色4.课程设计总结附页参考书目:1 (美)Stephen Walther主编,ASP.NE

3、T 3.5揭秘(卷1),人民邮电出版社,北京,2009年2 (美)Stephen Walther主编,ASP.NET 3.5揭秘(卷2),人民邮电出版社,北京,2009年课程设计报告(附页)PetShop 是一个范例,微软用它来展示.Net企业系统开发的能力。然而PetShop随着版本的不断更新,至现在基 于.Net 2.0的PetShop4.0为止,整个设计逐渐变得成熟而优雅,却又很多可以借鉴之处。PetShop是一个小型的项目,系统架构与代码都比较简单,却也凸现了许多颇有价值的设计与开发理念。经过一个学期的课程设计,下面根据我自己做的petshop,对里面的内容进行分析。一、 实现的主要功

4、能和使用的关键技术1) 数据库链接:两种方法:datasource手动连接。 Web.config 中链接,利用connectionstring连接到对应的数据库中。 2)注册页面:通过使用TextBox、DropDownList、Button等控件实现页面的布置,并提供注册信息的输入功能。MySqlConnection实现对数据库的链接,运用sql语句判断用户名注册与否。非已注册用户完成注册功能。3)登录,首先判断用户是否存在和密码是否正确,若存在,则更新数据库中用户最后登录时间、建立SessionUsername、跳转页面至首页;若不存在,则弹窗警告。4)菜单展示,使用DataList实现

5、。首先通过SessionUsername判断用户是否登录。默认首次登录后菜单页显示第一页。在cs文件中初始化DataList1的各项属性,DataSource属性实现与数据库的product_info表的链接。在前台页运用DataBind绑定数据 至所需位置。最终实现菜单页面的显示。另外还可进行菜单类别的选择。 5) 购物车功能,DataList实现订单的显示,所使用技术类似菜单显示,最终按钮为确认按钮,确认菜谱确认。另外还可实现对订单的增删改操作。二、 主要文件及有关功能说明Default.aspx: 主页:利用repeatercontrol控件,控制宠物分类,是的每个宠物链接均能与prod

6、uct页面中的分类相链接。建立登录按钮,可以登录到数据库中,并且利用session 记住登录状态。Product.aspx页面:Datalist中绑定数据,分页处理,包括:上一页 下一页 首页 末页 跳转页。 Placeholder中将每个弹出页面反映到导航上;建立一个MasterPage.master:Product的页面、Item页面均利用此页面来构建。Newuser.aspx页面注册新用户。Newusersuccess页面注册新用户成功提示。SignIn页面:登陆页面,购物车页面运行之前必须登录。ShoppingCart页面购物车页面,用户将购物存进临时表。包括单价汇总。Checkout

7、页面支付页面,从购物车跳入此页面,支付成功。三、 核心代码及有关逻辑说明Default.aspx页面中:Default.aspx.cs中: protected void LinkButton1_Click(object sender, EventArgs e) Response.Redirect(SignIn.aspx);表示点击登录按钮进入到登录页面。Product.aspx: asp:Image ID=Image1 runat=server ImageUrl= /   a href=Items.aspx?productId= > >    

8、;        上一页      下一页                首 页     末页      Product.aspx.cs中:int CurrentPage, Pagesize, RecordCount, PageCount; protected void Page_Load(object se

9、nder, EventArgs e) Pagesize = 4; Page.Title = Request.QueryStringCategoryId.ToLower(); if (!Page.IsPostBack) ListBind(); CurrentPage = 0; ViewStatecurrentPage = CurrentPage; RecordCount = newRecordCount(); PageCount = RecordCount / Pagesize; if (RecordCount % Pagesize 0) PageCount = PageCount + 1; V

10、iewStatepageCount = PageCount; lbRecorderCount.Text = 总记录 + RecordCount.ToString(); lbpageandTotal.Text = (CurrentPage + 1) + / + PageCount.ToString(); lbTotalpage.Text = 共 + PageCount.ToString()+页; protected void ListBind() SqlConnection myconn = new SqlConnection(DB.CreateConnStr(); SqlDataAdapter

11、 myda = new SqlDataAdapter(select * from product where Categoryid= + Request.QueryStringCategoryId.ToString() + , myconn); DataSet myds = new DataSet(); int StartIndex = CurrentPage * Pagesize; myda.Fill(myds, StartIndex,Pagesize,product); DataList1.DataSource = myds.Tables0.DefaultView; DataList1.D

12、ataBind(); myconn.Close(); lbdown.Enabled = true; lbup.Enabled = true; if (CurrentPage = 0) lbup.Enabled = false; if (CurrentPage = PageCount - 1) lbdown.Enabled = false; private int newRecordCount() SqlConnection myconn = new SqlConnection(DB.CreateConnStr(); myconn.Open(); SqlCommand myCommand = n

13、ew SqlCommand(select count(*) from product where Categoryid= + Request.QueryStringCategoryId.ToString() + ,myconn); return Int32.Parse(myCommand.ExecuteScalar().ToString(); myconn.Close() protected void Page_Click(object sender, CommandEventArgs e) CurrentPage = (int)ViewStatecurrentPage; PageCount

14、= (int)ViewStatepageCount; string lbname = e.CommandName; switch (lbname) case up: if (CurrentPage 0) CurrentPage-; break; case down: if (CurrentPage PageCount - 1) CurrentPage+; break; case first: CurrentPage = 0; break; caselast: CurrentPage = PageCount - 1; break ViewStatecurrentPage = CurrentPag

15、e; ListBind(); lbpageandTotal.Text = (CurrentPage + 1) + / + PageCount.ToString(); protected void btgo_Click(object sender, EventArgs e) CurrentPage =Int32.Parse(TextBox2.Text.ToString()-1; PageCount = (int)ViewStatepageCount; if (CurrentPage PageCount - 1) CurrentPage = PageCount - 1; /ViewStatecur

16、rentPage = CurrentPage; ListBind(); lbpageandTotal.Text = (CurrentPage + 1) + / + PageCount.ToString(); MasterPage.master中:源代码:protected void Page_Load(object sender, EventArgs e) HtmlAnchor lnkhome = new HtmlAnchor(); lnkhome.InnerText = 主页; lnkhome.HRef = default.aspx; PlaceHolder1.Controls.Add(ln

17、khome); Literal myLt = new Literal(); myLt.Text = ; PlaceHolder1.Controls.Add(myLt); if (Request.QueryStringCategoryId != null) HtmlAnchor lnkProsuct = new HtmlAnchor(); lnkProsuct.InnerText = Request.QueryStringCategoryId.ToString(); lnkProsuct.HRef = Products.aspx?page=0&CategoryId= + Request.Quer

18、yStringCategoryId.ToString(); PlaceHolder1.Controls.Add(lnkProsuct); Label1.Text = Page.Title.ToString(); Page.Title = string.Format(.net pet shop: 0,Page.Title.ToString();if (Request.QueryStringProductId != null) SqlConnection myconn = new SqlConnection(DB.CreateConnStr(); SqlCommand myCommand = ne

19、w SqlCommand(select CategoryId from product where ProductId= + Request.QueryStringProductId.ToString() + , myconn);myconn.Open(); string CategoryId = myCommand.ExecuteScalar().ToString(); myconn.Close();HtmlAnchor lnkProsuct1 = new HtmlAnchor(); lnkProsuct1.InnerText = CategoryId; lnkProsuct1.HRef =

20、 Products.aspx?page=0&CategoryId= + CategoryId+; PlaceHolder1.Controls.Add(lnkProsuct1);Literal myll = new Literal(); myll.Text = ; PlaceHolder1.Controls.Add(myll);HtmlAnchor lnkItem = new HtmlAnchor(); SqlConnection myconn1 = new SqlConnection(DB.CreateConnStr(); SqlCommand myCommand1 = new SqlComm

21、and(select name from product where ProductId= + Request.QueryStringProductId.ToString() + , myconn);myconn.Open(); string name = myCommand1.ExecuteScalar().ToString(); myconn.Close(); lnkItem.InnerText = name; lnkItem.HRef = Items.aspx?productId=&categoryId= + name+; PlaceHolder1.Controls.Add(lnkIte

22、m); protected void LinkButton1_Click(object sender, EventArgs e) Response.Redirect(SignIn.aspx); protected void LinkButton2_Click(object sender, EventArgs e)Response.Redirect(ShoppingCart.aspx);Items页面中:Item.aspx.cs中代码: private string ItemId; private string CategoryId; private string productName; st

23、ring _ItemId, _ItemName, pId,Qty; int m; float Unitprice; int CurrentPage, Pagesize, RecordCount, PageCount; protected void Page_Load(object sender, EventArgs e) SqlConnection myconn = new SqlConnection(DB.CreateConnStr(); SqlCommand myCommand = new SqlCommand(select name from product where ProductI

24、d= + Request.QueryStringProductId.ToString() + , myconn);myconn.Open(); string name = myCommand.ExecuteScalar().ToString(); myconn.Close(); Page.Title = name; Pagesize = 4; /Page.Title = Request.QueryStringItemId.ToLower(); if (!Page.IsPostBack) ListBind(); CurrentPage = 0; ViewStatecurrentPage = Cu

25、rrentPage; PageCount = RecordCount / Pagesize; if (RecordCount % Pagesize 0) PageCount = PageCount + 1; ViewStatepageCount = PageCount; protected void ListBind() SqlConnection myconn = new SqlConnection(DB.CreateConnStr(); SqlDataAdapter myda = new SqlDataAdapter(select b.* ,c.* from Product a join

26、Item b on a.ProductId =b.ProductId join Inventory c on b.ItemId =c.ItemId where a.ProductId= + Request.QueryStringProductId.ToString() + , myconn); DataSet myds = new DataSet(); int StartIndex = CurrentPage * Pagesize; myda.Fill(myds, StartIndex, Pagesize, select b.* ,c.* from Product a join Item b

27、on a.ProductId =b.ProductId join Inventory c on b.ItemId =c.ItemId ); DataList1.DataSource = myds.Tables0.DefaultView; DataList1.DataBind(); myconn.Close(); private int newRecordCount() SqlConnection myconn = new SqlConnection(DB.CreateConnStr(); myconn.Open(); SqlCommand myCommand = new SqlCommand(

28、select count(*) from Item where ProductId= + Request.QueryStringProductId.ToString() + , myconn); return Int32.Parse(myCommand.ExecuteScalar().ToString(); myconn.Close(); protected void Page_Click(object sender, CommandEventArgs e) string lbname = e.CommandName; switch (lbname) case back: SqlConnect

29、ion myconn = new SqlConnection(DB.CreateConnStr(); SqlCommand myCommand = new SqlCommand(select Categoryid from product where ProductId= + Request.QueryStringProductId.ToString() + , myconn); myconn.Open(); string Categoryid= myCommand.ExecuteScalar().ToString(); myconn.Close(); Response.Redirect(Pr

30、oducts.aspx?page=0&CategoryId= + Categoryid + ); break; ListBind();protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) if (Sessionusername != null) if (e.CommandName.ToString() != addCart) string ConnSql = System.Configuration.ConfigurationManager.ConnectionStringsmyConn.

31、ConnectionString; SqlConnection myConn = new SqlConnection(ConnSql); string SelectSql = select * from Item where itemid= + e.CommandName.ToString() + ; SqlDataAdapter da = new SqlDataAdapter(SelectSql, myConn); DataSet ds = new DataSet(); da.Fill(ds, Item); DataTable mydt = new DataTable(); if (Sess

32、ionCart = null) mydt.Columns.Add(Qty, typeof(Int32); mydt.Columns.Add(ItemPrice, typeof(float); mydt.Columns.Add(pId, typeof(string); mydt.Columns.Add(ItemId, typeof(string); mydt.Columns.Add(ItemName, typeof(string); SessionCart = mydt; /DataList1.DataSource = ds.Tables0.DefaultView; /DataList1.Dat

33、aBind(); /Response.Write(ds.Tables0.Rows.Count); _ItemName = ds.Tables0.Rows0Name.ToString(); Unitprice = float.Parse(ds.Tables0.Rows0ListPrice.ToString(); pId = ds.Tables0.Rows0ProductId.ToString(); myConn.Close();DataTable dt = (DataTable)SessionCart; for (int i = 0; i dt.Rows.Count; i+) if (_ItemId =

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号