ASPNET应用开发综合实验报告.docx
- 文档编号:10286253
- 上传时间:2023-02-09
- 格式:DOCX
- 页数:27
- 大小:2.25MB
ASPNET应用开发综合实验报告.docx
《ASPNET应用开发综合实验报告.docx》由会员分享,可在线阅读,更多相关《ASPNET应用开发综合实验报告.docx(27页珍藏版)》请在冰豆网上搜索。
ASPNET应用开发综合实验报告
网上订购系统实验报告
姓名:
蔡双江
学号:
1108203422
班级:
软件114
指导老师:
张金姬
一、实验目的
1、学习在ASP.NET+SQLServer平台设计动态网站的方法
2、掌握设计网站涉及到的各种技术:
模板设计、样式设计、站点地图导航设计、主页面设计与编程、功能页面设计与编程
3、掌握ASP.NET应用程序访问数据库的技术
4、掌握ASP.NET提供的各种控件应用技巧及主要事件处理程序的编程
二、实验内容和要求
1、设计网站模板、样式、菜单导航
2、购物网站所管理的信息数据库
3、设计网站主页
4、按站点地图设计各功能页面并编写相应的事件处理程序
三、实验步骤
1、新建项目并构建购物网站母版页
备注:
打开VisualStudio2005,新建ASP.Net网站并设置保存路径,新建母版页
以下为设计好母版页的框架
备注:
创建网站模板时,需要注意排版的高度宽度尺寸,我设置的网站宽度为850px,高度为649px;其中最上的Logo栏高度为181px,菜单栏高度为30px;导航栏高度占380px,宽度为170px;编辑区域高度和导航栏高度保持一致为380px,宽度为680px;最底端处高度为58px。
2、数据库设计:
(一共7个信息表)
员工信息表
客户信息表
订单信息表
订单详情表
产品信息表
产品类别表
供应商信息表
3、建立站点地图
Web.sitemap文件
xmlversion="1.0"encoding="utf-8"?
>
4、设计层叠样式
右击--添加样式规则—选择元素、类名或者元素ID
右击—生成样式,对字体、背景、文本等等进行编辑,代码自动生成。
BODY
{background-color:
#ddedd0;}
.tr
{border-right:
blackthinsolid;
border-top:
blackthinsolid;
border-left:
blackthinsolid;
border-bottom:
blackthinsolid;}
A:
hover
{font-weight:
bold;
color:
purple;
font-family:
华文中宋;
text-decoration:
underlineoverline;
font-size:
18px;}
.b
{background-color:
#ddedd0;}
#td1
{background-image:
url(img/logo.jpg);}
#td2
{background-image:
url(img/left.jpg);}
#b1
{background-color:
transparent;}
#b3
{background-color:
transparent;}
#div2
{width:
476px;
height:
316px;
background-image:
url(img/mb.jpg);
display:
none;
font-family:
黑体;
font-size:
large;}
5、数据库连接
SqlConnectionconn=newSqlConnection();
conn.ConnectionString="DataSource=.;InitialCatalog=shopping;IntegratedSecurity=True";
SqlCommandcmd=newSqlCommand();
cmd.CommandType=System.Data.CommandType.Text;
cmd.CommandText=sql;
cmd.Connection=conn;
6、设计员工或客户注册
备注:
采用上传控件FileUpload,并将上传路径显示在Label内。
上传员工照片代码:
stringzp=Label1.Text;
stringxqah="";
for(inti=0;i<3;i++)
{if(this.CheckBoxList1.Items[i].Selected)
xqah=xqah+""+CheckBoxList1.Items[i].Text;}
stringcsrq=TextBox8.Text;
stringsql="insertintodbo.Member(MemberID,memName,Title,Address,City,Phone,pwd,xingbie,csny,xqah,memphoto)values("+ygh+",'"+xm+"','"+zw+"','"+xxdz+"','"+cs+"',"+lxfs+","+mm+",'"+xb+"','"+csrq+"','"+xqah+"','"+zp+"')";
SqlConnectionconn=newSqlConnection();
conn.ConnectionString="DataSource=.;InitialCatalog=shopping;IntegratedSecurity=True";
SqlCommandcmd=newSqlCommand();
cmd.CommandType=System.Data.CommandType.Text;
cmd.CommandText=sql;
cmd.Connection=conn;
try
{conn.Open();
intnum=cmd.ExecuteNonQuery();
if(num==1)
{Response.Write("操作:
插入成功!
");}
catch(Exceptionex)
{Response.Write(ex.Message.ToString());}
finally
{//关闭对象
if(conn!
=null)
{conn.Close();}}}
protectedvoidButton2_Click(objectsender,EventArgse)
{
stringflname=FileUpload1.FileName;
Label1.Text="~"+@"\upload\"+flname.Substring(flname.LastIndexOf(@"\")+1);
stringfm=flname.Substring(flname.LastIndexOf(@"\")+1);
FileUpload1.PostedFile.SaveAs(HttpRuntime.AppDomainAppPath+@"\upload\"+fm);
}
7、分类查询设计以及详细信息显示
备注:
使用下拉框控件DropDrownList并勾选AutoPostBack选项,实现无刷新显示所查询的类别商品信息。
8、登陆页面设计以及密码修改
9、购物车设计
备注:
在C盘下路径:
WINDOWS\Microsoft.NET\Framwork\v2.0.50727下找到_regsql.exe文件,并直接双击它即可对Profile的配置实现多用户(支持匿名用户)购物系统。
Web.config文件代码
xmlversion="1.0"?
>
--
注意:
除了手动编辑此文件以外,您还可以使用
Web管理工具来配置应用程序的设置。
可以使用VisualStudio中的
“网站”->“Asp.Net配置”选项。
设置和注释的完整列表在
ments中,该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config中
-->
providerName="System.Data.SqlClient"/> --设置compilationdebug="true"将调试符号插入已编译的页面中。 但由于这会影响性能,因此只在开发过程中将此值设置为true。 --> -- 通过 安全身份验证模式, 以标识传入的用户。 --> -- --> -- 如果在执行请求的过程中出现未处理的错误, 则通过 具体说来, 开发人员通过该节可以配置 要显示的html错误页 以代替错误堆栈跟踪。 --> type="System.Web.Profile.SqlProfileProvider" connectionStringName="LocalSqlServer"/> type="ShoppingCart" serializeAs="Binary" allowAnonymous="true"/> 备注: 采用DetailView表显示所选商品的详细信息,并且LinkButton控件点击事件引入CartItem.cs和ShoppingCart.cs来对所购商品进行加入购物车处理 CartItem.cs usingSystem; usingSystem.Collections.Generic; usingSystem.Web; [Serializable] publicclassCartitem { privateintprouductid; privatestringprouductname; privatedecimalbookprice; privateintquality=1; publicintProductId { get{returnprouductid;} } publicstringprouductName { get{returnprouductname;} } publicdecimalprice { get{returnbookprice;} } publicintQuantity { get{returnquality;} set{quality=value;} } publicdecimalsubtotalprice { get{returnbookprice*quality;} } publicCartitem(intProuductid,stringProuductname,decimalpricE) { prouductid=Prouductid; prouductname=Prouductname; bookprice=pricE; } } ShoppingCart.cs usingSystem; usingSystem.Collections.Generic; usingSystem.Web; usingSystem.Collections; [Serializable] publicclassShoppingCart { privateHashtablemycart=newHashtable(); publicICollectionCartItems { get{returnmycart.Values;} } publicdecimalTotalPrice { get { decimalsum=0; foreach(Cartitemiteminmycart.Values) { sum+=item.price*item.Quantity; } returnsum; }} //定义向购物车中添加 publicvoidAddBook(intproductid,stringproductname,decimalprice) { Cartitemitem=(Cartitem)mycart[productid]; if(item==null) { mycart.Add(productid,newCartitem(productid,productname,price)); } else { item.Quantity++; mycart[productid]=item; } } publicvoidRemoveBook(intproductid) {Cartitemitem=(Cartitem)mycart[productid]; if(item! =null) { mycart.Remove(productid); }} publicvoidSetQuantity(intproductid,intquanlity) { Cartitemitem=(Cartitem)mycart[productid]; if(item! =null&&quanlity>0) { item.Quantity=quanlity; mycart[productid]=item; }}} 备注: 根据是否为匿名用户对购物车的商品是否被购入作出判断,如果用户尚未登录就给予尚未登录的警告框,登录之后则跳转到购买成功页面。 购物车实现代码 usingSystem; usingSystem.Collections.Generic; usingSystem.Web; usingSystem.Web.UI; usingSystem.Web.UI.WebControls; publicpartialclassbuyproduct3: System.Web.UI.Page { protectedvoidPage_Load(objectsender,EventArgse) { BindShoppingCart(); } protectedvoidGridView1_SelectedIndexChanged(objectsender,EventArgse) { intid=(int)GridView1.SelectedDataKey.Value; Profile.ShoppingCart.RemoveBook(id); GridView1.SelectedIndex=-1; BindShoppingCart(); } protectedvoidBindShoppingCart() { if(Profile.ShoppingCart! =null) { GridView1.DataSource=Profile.ShoppingCart.CartItems; GridView1.DataBind(); if(GridView1.FooterRow! =null) {Label1.Text="总价: "+Profile.ShoppingCart.TotalPrice.ToString("c"); Session["totalprice"]=Profile.ShoppingCart.TotalPrice.ToString("c"); }}} protectedvoidTxtproductquality_TextChanged1(objectsender,EventArgse) { boolisSuccess=false; TextBoxtxtquality=newTextBox(); txtquality=(TextBox)GridView1.Rows[0].Cells[5].FindControl("txtproductquality"); GridViewRowrow=txtquality.Parent.ParentasGridViewRow; if(! string.IsNullOrEmpty(txtquality.Text))
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ASPNET 应用 开发 综合 实验 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)