精品文档
《.Net体系及编程》大作业
——网上商城
姓名张通
学号 2220143682
一、实验目的
实现一个网上商城。管理员将货物信息整理归类发布到网上用户登录该网站后首先要注册为会员才能购买图书。该系统的使用者主要分为2类注册用户和管理员。注册用户除了可以浏览网上商城中的货物信息外还可以进行网上购物管理员可以对网上商城中的商品信息进行管理、对客户订单进行处理等。主要包括以下功能模块
前台
1用户注册登录
2货物查询
3货物订购
4订单查询
5用户信息修改
后台
1欢。迎下载
精品文档
1货物管理
2订单管理
3用户管理
二、实验数据库
三、实验代码
Default.aspx
<%@PageLanguage="C#"AutoEventWi reup="true"CodeFi l e="Defau lt.aspx.c s"Inherit s="_Defau lt"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0
Transit ional//EN""http://www.w3.org/TR/xhtml 1/DTD/xhtml 1-transi tional.dt d">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="s erver">
<title></title>
</head>
<body>
<bodystyle="background-image:url(1. jpg)"background-pos iti on:center;background-repeat:no-repeat;background-at tachment:f ixed; >
<formid="f orm1"runat="server">
&nbs p;&nbs p;&nbs p;&nbs p;&nbs p;&nbs p;&nbs p;&nbs p;&nbs p;&nb sp;&nb sp;&nb sp;&nb sp;&nb sp;&nbs p;&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;
<asp:ImageBut ton ID="login"runat="s erver"Hei ght="22px"ImageUr l="toum. j pg"
Width="38px"PostBackUr l="~/l ogin.aspx"/>
<asp:ImageBut ton ID="logon"runat="s erver"Hei ght="20p x"ImageUr l="toum. j pg"Width="51px"PostBackUr l="~/l ogon.aspx"/>
&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb sp;
<div>
</div>
<p>
&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb s p;&nb sp;
<asp:ImageBut ton ID="home"runat="server"Height="61 px"ImageUrl="t oum. jpg"
Width="323px"/>
</p>
2欢。迎下载
精品文档
<p>
&nb s p;</p>
</fo rm>
</body>
</html>
Login.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFil e="login.aspx. cs"Inheri ts="login"Debug="true"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0
Transit ional//EN""http://www.w3.org/TR/xhtml 1/DTD/xhtml 1-transi tional.dt d">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="s erver">
<title></title>
</head>
<body>
<formid="f orm1"runat="server">
<div>
<tablestyle="width: 400px; height: 120px; font-size:
9pt;"border="1"cellpadding="0"cellspacing="0"align="center">
<tr>
<tdstyle="width: 78px">
会员姓名 </td>
<tdstyle="width: 145px">
<asp:TextBoxID="txtMName"runat="server"></asp:TextBox></td>
<tdstyle="width: 134px">
<asp:Requi redFie ldVal i datorID="RequiredFiel dVal idator1"runat="s erver"ErrorMessage="*"ControlToVal idate="txtMName"></asp:RequiredFieldVal idator></td>
</tr>
<tr>
<tdstyle="width: 78px">
会员密码 </td>
<tdstyle="width: 145px">
<asp:TextBoxID="txtMPwd"runat="server"TextMode="Password"Width="149px"></asp:TextBox></td>
<tdstyle="width: 134px">
<asp:Requi redFie ldVal i datorID="RequiredFiel dVal idator2"runat="s erver"ErrorMessage="*"ControlToVal idate="txtMPwd"></asp:RequiredFieldVali dator></td>
</tr>
<tr>
<tdstyle="width: 78px">
&nbs p;验&nbs p;证&nb sp;码 </td>
3欢。迎下载
精品文档
<tdstyle="width: 145px">
<asp:TextBoxID="txtMCode"runat="server"></asp:TextBox></td>
<tdstyle="width: 134px">
<asp:Label ID="labCode"runat="server"Height="19px"BackColor="#FFC0FF"></asp:Label></td></tr>
<tr>
<tdcolspan="3"style="text-al ign: center">
<asp:ButtonID="btnLogin"runat="server"Text="登录"OnCli ck="btnLogin_Cl ick"/>
&nb s p;&nb s p;
<asp:ButtonID="btnCanc le"runat="server"Text="取消"OnCl ick="btnCanc le_Cli ck"/></td></tr>
</table>
</div>
</fo rm>
</body>
</html>
Login.aspx.csusing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ;using System.Web.UI.WebControls;using System.Data;using System.Data.SqlClient;publicpartialclasslogin : System.Web.UI.Page
{protectedvoid Page_Load(object sender, EventArgs e)
{
SqlConnection Conn;
Conn = newSqlConnection("Data Source=pc-1230;Initial Catalog=user;IntegratedSecurity=True") ;
//Windows身份验证if ( !IsPostBack)
{
Random randob j = newRandom() ;l abCode.Text =randobj.Next(1000, 10000) .ToStri ng() ;//返回一个指定范围内的随机数(int)
}
4欢。迎下载
精品文档
}protectedvoid btnLogin_Click(object sender, EventArgs e)
{
SqlConnection sqlconn;sqlconn = newSqlConnection("Data Source=pc-1230;Initial Catalog=user;IntegratedSecurity=True") ;sqlconn.Open() ;string sql = "select * from member1 where id = @id and pwd = @pwd";
SqlCommand Comm = newSqlCommand(sql, sqlconn) ;
Comm.Parame ter s.Add("id", txtMName.Text) ;
Comm.Parame ter s.Add("pwd", txtMPwd.Text) ;
SqlDataReader sdr = Comm.ExecuteReader() ;i f (txtMCode.Text.Trim() == labCode.Text.Tr im())
{i f (sdr.Re ad())
{
Session["id"] = txtMName.Text;if (Session["id"].ToString() != "admin")
Response.Redirect("SuccReg.aspx") ;else
Response.Redirect("admin.aspx") ;
}else
{
Response.Write("<script>alert('您输入的用户名或密码错误请重新输入' ) ;location=' javascript:history.go(-1)' ;</script>") ;
}
}else
Response.Write("<script>alert('验证码输入有误请重新输入
' ) ;location=' javascript:history.go(-1)' ;</script>") ;sqlconn.Close() ;
}protectedvoid btnCancle_Click(object sender, EventArgs e)
{
Response.Write("<script>window. close() ;location=' javascript:history.go(-1)' ;</script>");
}
}
Logon.aspx
<%@PageLanguage="C#"AutoEventWi reup="true"CodeFi l e="logon.aspx. cs"Inheri ts="logon"%>
5欢。迎下载
精品文档
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0
Transit ional//EN""http://www.w3.org/TR/xhtml 1/DTD/xhtml 1-transi tional.dt d"><htmlxmlns="http://www.w3.org/1999/xhtml">
<headid="Head1"runat="server">
<title></title>
</head>
<body>
<formid="f orm1"runat="server">
<div>
用户名&nb sp;&nb sp;
<asp:TextBoxi d="TextBox1"runat="Server"/>
<asp:RequiredFie ldVali datori d="RequiredFiel dValidator3"runat="Server"
ControlToVali date="TextBox1"SetFocusOnError="true"
ErrorMe ssage="用户名不能为空"Di spl ay="Stati c">
</asp:RequiredFieldVal idator>
<asp:ButtonID="Button2"runat="server"onc lick="Button2_Cli ck"
Text="用户名是否重复"/>
<br/>
密码
<asp:TextBoxi d="TextBox2"runat="Server"ClientIDMode="Inherit"TextMode="Password"/><asp:RequiredFie ldVali datori d="RequiredFiel dValidator1"runat="Server"
ControlToVali date="TextBox2"SetFocusOnError="true"
ErrorMe ssage="密码不能为空"Disp lay="Stat ic">
</asp:RequiredFieldVal idator><br/>
确认密码&nb s p;
<asp:TextBoxi d="TextBox3"runat="Server"TextMode="Pas sword"/>
<asp:RequiredFie ldVali datori d="RequiredFiel dValidator2"runat="Server"
ControlToVali date="TextBox3"SetFocusOnError="true"
ErrorMessage="确认密码不能为空"Display="Static">
</asp:RequiredFieldVal idator>
<asp:CompareVal i datorID="CompareVal idator1"runat="server"
ControlToCompare="TextBox2"ControlToVal i dat e="TextBox3"
ErrorMe ssage="密码不一致">
</asp:CompareVal idator><br/>
生日
<asp:TextBoxID="TextBox4"runat="server"></asp:TextBox>
<asp:RangeVal idatorID="RangeVal idator 1"runat="server"
Control ToVal i dat e="TextBox4"ErrorMessage="生日输入错误"
Maxi mumVal ue="2010-1-1"
M inimumVal ue="1900-1-1"
Type="Date">
</asp:RangeVal idator><br/>
电话号码&nb s p;
6欢。迎下载
精品文档
<asp:TextBoxID="TextBox5"runat="server"></asp:TextBox>
<asp:RequiredFie ldVali datori d="RequiredFiel dValidator5"runat="Server"
ControlToVali date="TextBox5"SetFocusOnError="true"
ErrorMessage="电话号码不能为空"Display="Static">
</asp:RequiredFieldVal idator>
<asp:Regul arExpress ionVal idator ID="Regul arExpress ionVal idator1"runat="server"ControlToVal i dat e="TextBox5"
ErrorMe ssage="请输入合法的电话号码"
Enab leClientScript="true"SetFocusOnError="true"
Vali dat ionExpres sion="(\(\d{3}\) |\d{3}-)?\d{8}"></asp:RegularExpressi onVali dator><br/>邮箱
<asp:TextBoxID="TextBox6"runat="server"></asp:TextBox>
<asp:RequiredFie ldVali datori d="RequiredFiel dValidator4"runat="Server"
ControlToVali date="TextBox6"SetFocusOnError="true"
ErrorMe ssage="邮箱不能为空"Disp lay="Stat ic">
</asp:RequiredFieldVal idator>
<asp:Regul arExpress ionVal idator ID="Regul arExpress ionVal idator2"runat="server"ControlToVal i dat e="TextBox6"
ErrorMe ssage="请输入合法的E-mai l地址 "
Enab leClientScript="true"
Validat ionExpression="\w+([-+. ' ]\w+)*@\w+([-. ]\w+)*\.\w+( [-. ]\w+)*">
</asp:Regu larExpres sionVa l idator><br/>
<asp:ButtonID="Button1"runat="server"Text="提交"oncl ick="Button1_Click"/>
<asp:Va l idat i onSummary id="Va l idat i onSummary"
DisplayMode="Bul letList"
HeaderText="必须做以下输入或选择:"runat="server"/>
</div>
</fo rm>
</body>
</html>
Logon.aspx.csusing System;using System.Data;using System.Data.SqlClient;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI ;
7欢。迎下载
精品文档using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;publ icpart ialclasslogon : System.Web.UI.Page
{protectedvoid Page_Load(object sender, EventArgs e)
{
}protectedvoid Button2_Click(object sender, EventArgs e)
{
SqlConnection sqlconn;sqlconn = newSqlConnection("Data Source=pc-1230;Initial Catalog=user;IntegratedSecurity=True") ;string sqlstr = "select * from member1 where id=' " + this.TextBox1.Text + "'";sqlconn.Open() ;
SqlCommand sqlcom= newSqlCommand(sqlstr, sqlconn) ;
SqlDataReader read = sqlcom.ExecuteReader() ;read.Read() ;i f (read.HasRows)
{if (thi s.TextBox1.Text.Trim() == read["id"] .ToString() .Trim())
{
Response.Write("<script language=' javascript'>alert('该会员已经注册过' ) ;localtion='Register.aspx' </script>") ;return;
}
}else
{
Response.Write("<script language=' javascript' >alert('您可以进行正常注册' ) ;localtion='Register.aspx' </script>") ;
}read.Close() ;sqlconn.Close() ;
}
8欢。迎下载
精品文档protectedvoid Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlconn;sqlconn = newSqlConnection("Data Source=pc-1230;Initial Catalog=user;IntegratedSecurity=True") ;sqlconn.Open() ;string sqlstr = "insert into member1 "
+ "(id,pwd,bi rth,phone,emai l)"
+ "values(' " + TextBox1.Text + "' , ' " + TextBox2.Text + "' , '" + TextBox4.Text+ "' , '" + TextBox5.Text + "' , '" + TextBox6.Text + "' )";
SqlCommand Comm = newSqlCommand(sqlstr, sqlconn) ;
Comm.Exe cut eNonQuery() ;sqlconn.Close() ;
Session["id"] = TextBox1.Text.Trim() ;
Response.Redirect("SuccReg.aspx") ;
}
}
Car.aspx
<%@PageLanguage="C#"AutoEventWi reup="true"CodeFi l e="car.aspx.cs"Inher its="car"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0
Transit ional//EN""http://www.w3.org/TR/xhtml 1/DTD/xhtml 1-transi tional.dt d">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="s erver">
<title></title>
</head>
<body>
<formid="f orm1"runat="server">
<div>
<asp:Gr idV iewID="Gr idV iew 1"runat="server"Al lowPag ing="True"
AutoGenerateColumns="False"DataKeyNames="id,goods id"
DataSourceID="SqlDataSource2">
<Co l umn s>
<asp:CommandF iel dShowEditBut ton="True"/>
<asp:BoundFie ldDataFie ld="id"HeaderText="id"ReadOnly="True"
SortExpression="id"Visible="False"/>
<asp:BoundFie ldDataFie ld="goods id"HeaderText="goodsi d"ReadOnly="True"
SortExpression="goodsid"Visible="False"/>
<asp:BoundFie ldDataFie ld="goodsname"HeaderText="商品名称"
9欢。迎下载
zji怎么样?zji是一家老牌国人主机商家,公司开办在香港,这个平台主要销售独立服务器业务,和hostkvm是同一样,两个平台销售的产品类别不一平,商家的技术非常不错,机器非常稳定。昨天收到商家的优惠推送,目前针对香港邦联四型推出了65折优惠BGP线路服务器,性价比非常不错,有需要香港独立服务器的朋友可以入手,非常适合做站。zji优惠码:月付/年付优惠码:zji 物理服务器/VDS/虚拟主机空间订...
Chia矿机,Spinservers怎么样?Spinservers好不好,Spinservers大硬盘服务器。Spinservers刚刚在美国圣何塞机房补货120台独立服务器,CPU都是双E5系列,64-512GB DDR4内存,超大SSD或NVMe存储,数量有限,机器都是预部署好的,下单即可上架,无需人工干预,有需要的朋友抓紧下单哦。Spinservers是Majestic Hosting So...
提速啦的来历提速啦是 网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑 由赣州王成璟网络科技有限公司旗下赣州提速啦网络科技有限公司运营 投资1000万人民币 在美国Cera 香港CTG 香港Cera 国内 杭州 宿迁 浙江 赣州 南昌 大连 辽宁 扬州 等地区建立数据中心 正规持有IDC ISP CDN 云牌照 公司。公司购买产品支持3天内退款 超过3天步退款政策。提速啦的市场定位提速啦主...