宾馆客房管理系统Word文件下载.docx
《宾馆客房管理系统Word文件下载.docx》由会员分享,可在线阅读,更多相关《宾馆客房管理系统Word文件下载.docx(23页珍藏版)》请在冰豆网上搜索。
宾馆客房管理系统第0层数据流图
4数据库设计
局部E-R图
全局E-R图,附加属性参见局部图
客户信息表(customer)
字段名称
含义
类型
长度
是否为空
黙认值
主键
外键
约束
id
身份证号
varchar
20
N
P
name
姓名
sex
性别
2
Checkin(‘男’,’女’)
age
年龄
int
phone
联系号码
Y
客房信息表(room)
num
房间号
10
Type
客房类型
price
价格(xx元/天)
numeric
8
status
房间状态
check(status='
空'
orstatus='
满'
)
订单信息表(reservation)
Book_id
订单号
Int
identity(1,1)
F
referencescustomer(id)
referencesroom(num)
Check_in
入住日期
Smalldatetime
Check_out
退房日期
Deadline
截至日期
Quit_type
退房类型
varchar(10)
check(quit_type='
调房'
orquit_type='
到期'
退订'
Sum
结算额
5关键技术实现
--===========================================================================================
useHotel_Booking
if(object_id('
tgr_check_in'
'
tr'
)isnotnull)
-----触发器,客户订房触发,设置房间状态
droptriggertgr_check_in
go
createtriggertgr_check_in
onreservation
forinsert--插入触发
as
declare@numvarchar(10)
select@num=numfrominserted
updateroom
setstatus='
wherenum=@num
go
tgr_quit_type'
-------触发器,客户退房,调房触发,设置房间状态
droptriggertgr_quit_type
createtriggertgr_quit_type
forupdate--更新触发
declare@quit_typevarchar(10),@numvarchar(10)
select@quit_type=quit_type,@num=numfrominserted
wherenum=@numand@quit_typeisnotnull--到期置空
tgr_quit_print'
-------触发器,退房时,结算显示
droptriggertgr_quit_print
createtriggertgr_quit_print
ifupdate(quit_type)
begin
select(cast((selectsumfrominserted)asvarchar(20)))[目前结算金额]
end
createviewbook_status-------------视图,订房情况
as
selectc.book_idas订票号,
a.nameas客户名,
a.sexas性别,
a.ageas年龄,
b.numas房间号,
b.typeas房间类型,
b.priceas[价格(xx元/天)],
a.phoneas客户电话,
a.idas客户身份证号,
c.deadline[截止期]
fromcustomera,roomb,reservationc
wherea.id=c.idandb.num=c.numandc.check_outisnull
createviewroom_available-----------视图,可用房间查询
select*
fromroom
wherestatus='
proc_available'
P'
--------存储过程,查看可用房间
dropprocproc_available
createprocproc_available
as
select*fromroom_available
proc_book_status'
--------存储过程,查看正在使用的房间
dropprocproc_book_status
createprocproc_book_status
select*frombook_status
proc_book'
-----存储过程,新客户订房
dropprocproc_book
createprocproc_book(@numvarchar(10),@book_datesmalldatetime,@lastint,@idvarchar(20),@namevarchar(20),@sexvarchar
(2),@ageint,@phonevarchar(20))
declare@errorint
set@error=@@error
begintran
ifnotexists(select*fromcustomerwhereid=@id)
begin
insertcustomervalues(@id,@name,@sex,@age,@phone)
set@error=@error+@@error
if'
<
>
(selectstatusfromroomwherenum=@num)
rollbacktran
return0
set@error=@error+@@error
insertreservationvalues(@id,@num,@book_date,null,CAST(dateadd(day,@last,cast(@book_dateassmalldatetime))assmalldatetime),null,0)
updateroomsetstatus='
wherenum=@num
if(@error<
0)
rollbacktran
return0
else
committran
return1
调用测试
proc_change'
-----存储过程,客户调房
dropprocproc_change
createprocproc_change(@num1varchar(10),@num2varchar(10))
declare@book_idint
if(selectstatusfromroomwherenum=@num2)<
'
print('
该房间正在使用中'
select@book_id=book_idfromreservationwherenum=@num1andcheck_outisnull
set@error=@error+@@error
updatereservation
setcheck_out=convert(smalldatetime,GETDATE())
fromreservation
where@book_id=book_id
set@error=@error+@@error
setsum=(DATEDIFF(day,check_in,check_out)+1)*(selectpricefromroomwherenum=@num1)
setquit_type='
where@book_id=book_id
set@error=@error+@@error
insertreservation
selectid,@num2,convert(smalldatetime,GETDATE()),null,deadline,null,sum
fromreservation
where@book_id=book_id
proc_quit'
-----存储过程,客户退房
dropprocproc_quit
createprocproc_quit(@numvarchar(10))
declare@@sumint
declare@check_insmalldatetime
declare@check_outsmalldatetime
set@@sum=0
set@error=0
updatereservation
setcheck_out=CONVERT(smalldatetime,getdate())
wherequit_typeisnullandnum=@num
set@error=@error+@@ERROR
select@@sum=sumfromreservationwherequit_typeisnullandnum=@num
select@check_in=check_in,@check_out=check_outfromreservationwherequit_typeisnullandnum=@num
set@@sum=@@sum+
(DATEDIFF(day,@check_in,@check_out)+1)*(selectpricefromroomwherenum=@num)
setsum=@@sum
setquit_type='
if(@error<
0)
committran
proc_renewal'
-----存储过程,客户续房
dropprocproc_renewal
createprocproc_renewal(@room_numvarchar(10),@day_numint)
setdeadline=CONVERT(smalldatetime,dateadd(day,@day_num,deadline))
wherenum=@room_numandquit_typeisnull
proc_customer_from_room'
-----存储过程,查看某个房间的客户信息
dropprocproc_customer_from_room
createprocproc_customer_from_room(@room_numvarchar(10))
select*fromcustomera
whereexists
(select*fromreservationbwherea.id=b.idandb.num=@room_numandb.quit_typeisnull)
Go
proc_room_from_customer'
-----存储过程,查看某个客户所用房间的信息
dropprocproc_room_from_customer
createprocproc_room_from_customer(@idvarchar(20))
select*fromrooma
(select*fromreservationbwhereb.id=@idandb.num=a.numandb.quit_typeisnull)
6数据库安全性控制
--===============================================================================
--首先在SQLServer服务器级别,创建登陆帐户(createlogin)
createlogindba
withpassword='
password'
default_database=master
--创建数据库用户(createuser)
createuserdba
forlogindba
withdefault_schema=dbo
--通过加入数据库角色,赋予数据库用户“dba”权限:
execsp_addrolemember'
db_owner'
dba'
--禁用、启用登陆帐户:
alterlogindbadisable
alterlogindbaenable
--登陆帐户改名:
alterlogindbawithname=dba_tom
--数据库用户改名
alteruserdbawithname=dba_tom
--删除指定登录名
droplogindba
--===============================================================================数据库的备份与恢复
backupdatabasehotel_booki