PetShop课程设计报告_第1页
PetShop课程设计报告_第2页
PetShop课程设计报告_第3页
PetShop课程设计报告_第4页
PetShop课程设计报告_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 (_item

34、id = dt.rowsiitemid.tostring() m = 1; dt.rowsiqty = int.parse(dt.rowsiqty.tostring() + 1; break; if (m = 1) sessioncart = dt; response.redirect(shoppingcart.aspx); if (m != 1) mydt = (datatable)sessioncart; datarow mydr = mydt.newrow(); mydritemid = _itemid; mydritemname = _itemname; mydrqty = 1; my

35、dritemprice = unitprice; mydrpid = pid; mydt.rows.add(mydr); sessioncart = mydt; response.redirect(shoppingcart.aspx); sessionitemid = _itemid; response.redirect(shoppingcart.aspx); /response.write(e.commandargument.tostring(); else response.redirect(signin.aspx); newuser.aspx:注册新用户:newuser.aspx.cs:

36、代码:protected void page_load(object sender, eventargs e) page.title = 注册; protected void button1_click(object sender, eventargs e) string username = textbox2.text; string pwd = textbox3.text; string pwdconfirm = textbox4.text; string telephone = textbox5.text;sqldatasource1.insertparametersusername.d

37、efaultvalue = username; sqldatasource1.insertparameterspwd.defaultvalue = pwd; sqldatasource1.insertparameterspwdconfirm.defaultvalue = pwdconfirm;sqldatasource1.insertparameterstelephone.defaultvalue = telephone;sqldatasource1.insert();response.redirect(newusersuccess.aspx);注册成功后:跳转到newusersuccess.aspx页面恭喜您,注册成功,请继续购买吧首页        请登录.登陆页面:signin.aspx页面:sign.aspx.cs页面中: protected void page_load(object sender, eventargs e) page.title = 登录; protected void butto

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论