功能描述
1)注册顾客:顾客以顾客ID、顾客名称、密码和地址信息注册并将数据存储于数据库
2)登录顾客:顾客以顾客名称和密码登录
3)查看商品:浏览所有商品的全部信息
4)将选中的商品放入购物车:顾客将选择商品放入购物车,如果顾客选择商品时间超过一天还未结帐,则清空原先的购物车内容,并将该种商品添加到购物车,数量为一;如果购物车尚未过期,并且该种商品不在购物车中,则将该种商品添加到购物车,数量为一;如果该种商品已在购物车中,则将该种商品的数量加一。最后,将对应商品的库存总量减一
5)查看购物车信息:顾客查看自己购物车的创建时间、商品ID、商品名称、商品单价、商品购买数量和商品总价
6)修改购物车信息:顾客可以修改购买的商品数量
7)删除购物车信息:顾客可以删除所选商品
8)生成订单:顾客确认后,系统将购物车中所有购买的商品信息生成最终订单,然后顾客的当前购物车信息将会被清空。同时,此订单号将会返还给顾客
运行说明
1)该项目使用SQL Server 2005或者2000数据库
2)直接在查询分析器中运行下面的脚本
CREATE DATABASE WebShop
GO
USE WebShop
--顾客表
CREATE TABLE [Customers]
(
[CustomerID] [int] IDENTITY (100, 1) NOT NULL ,
[CustomerName] [varchar] (10) UNIQUE NULL ,
[Password] [varchar] (10) NULL ,
[Address] [varchar] (100) NULL ,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[CustomerID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
--商品表
CREATE TABLE [Products] (
[ProductID] [int] IDENTITY (10000, 1) NOT NULL ,
[ProductName] [varchar] (50) NULL ,
[Price] [float] NULL ,
[Quantity] [int] NULL ,
CONSTRAINT [PK_TABLE1] PRIMARY KEY CLUSTERED
(
[ProductID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
--购物车表
CREATE TABLE [ShoppingCarts] (
[ShoppingCartID] [int] IDENTITY (100000, 1) NOT NULL ,
[CustomerID] [int] NULL ,
[DateCreated] [varchar] (10) NULL ,
CONSTRAINT [PK_ShoppingCarts] PRIMARY KEY CLUSTERED
(
[ShoppingCartID]
) ON [PRIMARY] ,
CONSTRAINT [FK_ShoppingCarts_Customers] FOREIGN KEY
(
[CustomerID]
) REFERENCES [Customers] (
[CustomerID]
)
) ON [PRIMARY]
GO
--购物车所购商品的表
CREATE TABLE [ShoppingCartDetails] (
[ShoppingCartID] [int] NOT NULL ,
[ProductID] [int] NOT NULL ,
[Quantity] [int] NULL ,
CONSTRAINT [PK_ShoppingCartDetails] PRIMARY KEY CLUSTERED
(
[ShoppingCartID],
[ProductID]
) ON [PRIMARY] ,
CONSTRAINT [FK_ShoppingCartDetails_Products] FOREIGN KEY
(
[ProductID]
) REFERENCES [Products] (
[ProductID]
),
CONSTRAINT [FK_ShoppingCartDetails_ShoppingCarts] FOREIGN KEY
(
[ShoppingCartID]
) REFERENCES [ShoppingCarts] (
[ShoppingCartID]
)
) ON [PRIMARY]
GO
--订单表
CREATE TABLE [Orders] (
[OrderID] [int] NOT NULL ,
[CustomerID] [int] NULL ,
[DateCreated] [varchar] (10) NULL ,
[TotalPrice] [float] NULL ,
CONSTRAINT [PK_Orders] PRIMARY KEY CLUSTERED
(
[OrderID]
) ON [PRIMARY] ,
CONSTRAINT [FK_Orders_Customers] FOREIGN KEY
(
[CustomerID]
) REFERENCES [Customers] (
[CustomerID]
)
) ON [PRIMARY]
GO
--订单中详细商品的表
CREATE TABLE [OrderDetails] (
[OrderID] [int] NOT NULL ,
[ProductID] [int] NOT NULL ,
[Quantity] [int] NULL ,
CONSTRAINT [PK_OrderDetails] PRIMARY KEY CLUSTERED
(
[OrderID],
[ProductID]
) ON [PRIMARY] ,
CONSTRAINT [FK_OrderDetails_Orders] FOREIGN KEY
(
[OrderID]
) REFERENCES [Orders] (
[OrderID]
),
CONSTRAINT [FK_OrderDetails_Products] FOREIGN KEY
(
[ProductID]
) REFERENCES [Products] (
[ProductID]
)
) ON [PRIMARY]
GO
--插入示例记录
insert Customers values('李明','liming','南京大学')
insert Customers values('张平平','111111','北京海淀')
insert Products values('迪斯尼CD',15,100)
insert Products values('手套',12.5,100)
insert Products values('夏季草编包',45,100)
insert Products values('朗科205 1G',250,200)
insert Products values('精装瓶装墨水',5,200)
insert Products values('可爱小闹钟',35,50)
insert Products values('超特价机械表',300,50)
GO
create view DetailedProductsInShoppingCart
as select
ShoppingCarts.ShoppingCartID,DateCreated,ShoppingCartDetails.ProductID,ProductName,ShoppingCartDetails.Quantity,Price,ShoppingCartDetails.Quantity*Price as 'Total' from ShoppingCarts inner join
ShoppingCartDetails on ShoppingCarts.ShoppingCartID=ShoppingCartDetails.ShoppingCartID inner join Products on ShoppingCartDetails.ProductID=Products.ProductID
GO
3)解压下面的项目文件并覆盖已有的Eclipse项目文件
项目的视图层和控制层的关系如下所示:
此主题相关图片如下:未命名.jpg
4)因为上传文件大小的限制,上述项目包中没有放入数据库访问驱动,请同学执行添加
SQL Server2005的驱动包位于:http://www.njcie.com/bbs/dispbbs.asp?boardid=20&Id=913
同时,该项目采用独立认证,所以大家需要在数据库中设置安全性为混合认证方式,并解锁sa帐户和设置相应的密码
[此贴子已经被作者于2010-11-19 09:52:26编辑过]