1 file10 days ago
1

--

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
-- go create procedure spDatPhong @makh char(10), @maphong char(10), @ngaydat datetime as begin --lay ma dat phong hien tai declare @madatphong int; set @madatphong=(select count(*) from datphong) + 1; --neu khach hang khong ton tai trong bang khach hang thi thong bao roi ket thuc if (not exists (select * from khachhang where @makh=khachhang.makh)) begin print 'da ton tai ma khach hang nay' return end --neu phong hang khong ton tai trong bang phong thi thong bao roi ket thuc if (not exists (select * from phong where @maphong=phong.maphong)) begin print 'da ton tai ma phong nay' return end --xet dieu kien phong co ranh hay khong if (exists (select * from phong where @maphong=phong.maphong and phong.tinhtrang=N"Bận")) begin print 'phong nay da duoc thue' return end --them vao danh sach dat phong else begin insert into datphong values(@madatphong,@makh,@maphong,@ngaydat,NULL,NULL) --dat lai tinh trang cho phong duoc thue update phong set phong.tinhtrang=N"Rãnh" where @maphong=phong.maphong end end go -- go create procedure spTraPhong @madp char(10), @makh char(10) as begin --luu ma phong declare @maphong int set @maphong=(select maphong from datphong where madp=@madp) --kiem tra ma khach hang if (not exists (select * from datphong where @makh=datphong.makh)) begin print 'khach hang nay khong dat phong' return end --kiem tra ma dat phong if (not exists (select * from datphong where @madp=datphong.madp)) begin print 'ma dat phong khong ton tai' return end --tinh tien update datphong set datphong.thanhtien=(day(ngaytra)-day(ngaydp))*(select dongia from phong where maphong=@maphong) --dat lai tinh trang cho phong update phong set phong.tinhtrang=N"Rãnh" where phong.maphong=@maphong end go