《aspnet编写的网上购物商城.doc》由会员分享,可在线阅读,更多相关《aspnet编写的网上购物商城.doc(14页珍藏版)》请在课桌文档上搜索。
1、一、实验目的实现一个网上商城。管理员将货物信息整理归类发布到网上,用户登录该后,首先要注册为会员才能购置图书。该系统的使用者主要分为2类:注册用户和管理员。注册用户除了可以浏览网上商城中的货物信息外,还可以进展网上购物;管理员可以对网上商城中的商品信息进展管理、对客户订单进展处理等。主要包括以下功能模块:前台:1用户注册登录;2货物查询;3货物订购;4订单查询;5用户信息修改;后台:1货物管理;2订单管理;3用户管理;二、实验数据库三、实验代码Default.asp* &nbs
2、p; Login.asp* 会员: 会员密码: 验 证 码: using System;using System.Collections.Gene
3、ric;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.Pageprotectedvoid Page_Load(object sender, EventArgs e) SqlConnection Conn; Conn = newSqlConnection(Data Source=pc-1230;In
4、itial Catalog=user;Integrated Security=True);/Windows身份验证if (!IsPostBack) Random randobj = newRandom(); labCode.Te*t = randobj.Ne*t(1000, 10000).ToString();/返回一个指定围的随机数(int) protectedvoid btnLogin_Click(object sender, EventArgs e) SqlConnection sqlconn; sqlconn = newSqlConnection(Data Source=pc-1230
5、;Initial Catalog=user;Integrated Security=True); sqlconn.Open();string sql = select * from member1 where id = id and pwd = pwd;Sqlmand m = newSqlmand(sql, sqlconn); m.Parameters.Add(id, t*tMName.Te*t); m.Parameters.Add(pwd, t*tMPwd.Te*t);SqlDataReader sdr = m.E*ecuteReader(); if (t*tMCode.Te*t.Trim(
6、) = labCode.Te*t.Trim() if (sdr.Read() Sessionid = t*tMName.Te*t;if (Sessionid.ToString() != admin) Response.Redirect(SuccReg.asp*);else Response.Redirect(admin.asp*); else Response.Write(alert(您输入的用户名或密码错误,请重新输入!);location=javascript:history.go(-1);); else Response.Write(alert(验证码输入有误,请重新输入!);locat
7、ion=javascript:history.go(-1);); sqlconn.Close(); protectedvoid btnCancle_Click(object sender, EventArgs e) Response.Write(window.close();location=javascript:history.go(-1);); Logon.asp*用户名 密码 确认密码 生日 using System;using System
8、.Data;using System.Data.SqlClient;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;publicpartialclasslogon : System.Web.UI.Pagep
9、rotectedvoid Page_Load(object sender, EventArgs e) protectedvoid Button2_Click(object sender, EventArgs e) SqlConnection sqlconn; sqlconn = newSqlConnection(Data Source=pc-1230;Initial Catalog=user;Integrated Security=True);string sqlstr = select * from member1 where id= + this.Te*tBo*1.Te*t + ; sql
10、conn.Open();Sqlmand sql = newSqlmand(sqlstr, sqlconn);SqlDataReader read = sql.E*ecuteReader(); read.Read();if (read.HasRows) if (this.Te*tBo*1.Te*t.Trim() = readid.ToString().Trim() Response.Write(alert(该会员已经注册过);localtion=Register.asp*);return; else Response.Write(alert(您可以进展正常注册);localtion=Regist
11、er.asp*); read.Close(); sqlconn.Close(); protectedvoid Button1_Click(object sender, EventArgs e) SqlConnection sqlconn; sqlconn = newSqlConnection(Data Source=pc-1230;Initial Catalog=user;Integrated Security=True); sqlconn.Open();string sqlstr = insert into member1 + (id,pwd,birth,phone,email) + val
12、ues( + Te*tBo*1.Te*t + , + Te*tBo*2.Te*t + , + Te*tBo*4.Te*t + , + Te*tBo*5.Te*t + , + Te*tBo*6.Te*t + );Sqlmand m = newSqlmand(sqlstr, sqlconn); m.E*ecuteNonQuery(); sqlconn.Close(); Sessionid = Te*tBo*1.Te*t.Trim(); Response.Redirect(SuccReg.asp*); Car.asp*asp:SqlDataSourceID=SqlDataSource2runat=s
13、erverConnectionString=Deletemand=DELETE FROM car1 WHERE id = id AND goodsid = goodsidInsertmand=INSERT INTO car1 (id, goodsid, goodsname, num) VALUES (id, goodsid, goodsname, num)Selectmand=SELECT * FROM car1 WHERE (id = id)Updatemand=UPDATE car1 SET goodsname = goodsname, num = num WHERE id = id AN
14、D goodsid = goodsidAdmin.asp*asp:SqlDataSourceID=SqlDataSource1runat=serverConnectionString=Deletemand=DELETE FROM goodsinfo WHERE goodsid = goodsidInsertmand=INSERT INTO goodsinfo (goodsname, goodsid, goodsnum, goodsphoto) VALUES (goodsname, goodsid, goodsnum, goodsphoto)Selectmand=SELECT * FROM go
15、odsinfoUpdatemand=UPDATE goodsinfo SET goodsname = goodsname, goodsnum = goodsnum, goodsphoto = goodsphoto WHERE goodsid = goodsidasp:SqlDataSourceID=SqlDataSource2runat=serverConnectionString=Deletemand=DELETE FROM car1 WHERE id = id AND goodsid = goodsidInsertmand=INSERT INTO car1 (id, goodsid, goodsname, num) VALUES (id, goodsid, goodsname, num)