項目源碼地址:https://github.com/TreeDream/Hotelgit
轉載註明出處!!!github
目 錄sql
1 問題的提出................................................................................................................... 3數據庫
2 可行性分析................................................................................................................. 4編程
2.1 技術可行性...................................................................................................... 4安全
2.2 經濟可行性...................................................................................................... 4網絡
2.3 操做可行性...................................................................................................... 4數據庫設計
3 需求分析.................................................................................................................... 5ide
3.1 數據需求分析................................................................................................... 5工具
3.2 功能需求分析................................................................................................... 5
3.3 關係模式.......................................................................................................... 5
3.4 數據流圖.......................................................................................................... 6
3.5 數據字典.......................................................................................................... 6
4 數據庫設計................................................................................................................. 7
4.1 概念設計............................................................................................................ 7
4.2 邏輯設計............................................................................................................ 8
4.2.1 物理結構模型............................................................................................ 8
4.2.2 表結構...................................................................................................... 8
4.3 物理設計............................................................................................................ 9
4.4 數據庫創建...................................................................................................... 9
4.5其餘設計........................................................................................................... 13
4.5.1存儲過程設計......................................................................................... 13
4.5.2 觸發器設計............................................................................................ 15
5 應用程序設計............................................................................................................. 15
隨着計算機技術的飛速發展,信息時代的到來,信息改變了這個社會,各種行業在平常經營管理各個方面也在走向規範化和網絡化。
近年來,隨着旅遊業的快速發展,旅遊的人也愈來愈多,在旅遊業中,對酒店的管理是一個重要部分。一個好的酒店房間預訂管理系統對於酒店來講是十分重要的。
如何利用數據庫更好的管理酒店房間資源,如何給客戶提供服務是要解決的問題。本系統利用數據庫對房間資源作了充分的利用,可以對客戶提供簡單的服務。
採用SQL Server 2016數據庫和C#開發,使用了先進的數據庫技術與數據管理技術,在用戶使用和管理的方面提供了便捷。本系統主要採用VS 2015 和 SQL Server2016進行相關的開發,而VS 2015是面向對象的可視化軟件開發工具,其對編程平臺對數據庫的訪問作了很好的封裝;SQL Server 2016數據庫,它可以處理大量數據,同時保持數據的完整性並提供許多高級管理功能。它的靈活性、安全性和易用性爲數據庫編程提供了良好的條件。
現代化的酒店組織龐大、服務項目多、信息量大,要想提升勞動生產、下降成本、提升服務質量和管理水平,促進經濟效益,必須藉助計算機來進行現代化信息管理。
能夠預估該系統的開發、運行、維護費用,預估該系統能給酒店帶來的經濟效益。而後將所需費用與所獲經濟利益比較,能夠看出對企業有利。
購買安裝設備費用:計算機
本系統採用C#語言開發,使用VS 2015做爲開發平臺,後臺數據庫使用SQL Server 2016創建。所作的系統爲酒店管理人員開發的界面,界面友好,只須要懂得簡單的計算機操做知識,就能自用應用本軟件。
數據庫能夠對信息進行存儲,系統的數據都是右數據庫來提供,查詢和使用數據都必需要進入數據庫,這就須要對數據庫創建相應的表來提供數據。本系統須要如下數據:
(1)用戶登陸基本信息,包括登陸 ID,密碼等。
(2)房間信息,包括房間的ID,種類。
(3)房間統計,每一類的房間具體信息,包括統一價格等。
(4)用戶訂房信息,包括訂房時間及繳費等。
需求分析從客戶的需求中提取出軟件系統可以幫助用戶解決的業務問題,經過對用戶業務問題的分析,規劃出系統的功能模塊。
通過分析後,肯定酒店房間管理系統的功能模塊包括:
(1)對用戶信息的管理。
(2)對用戶訂房信息的查詢。
(3)對房間信息的管理。
(4)對房間資源的充分利用。
(1) 客戶(客戶編號,客戶姓名,客戶密碼,客戶種類)
(2) 房間(房間編號,房間種類)
(3) 客戶訂購(訂購客戶編號,訂購房間編號,訂購開始時間,訂購結束時間,訂購繳費)
(4) 房間種類(房間種類,某類房間總個數,某類房間標準價)
數據元素 |
數據類型 |
數據來源 |
客戶編號 |
Varchar(18) |
客戶表 |
客戶姓名 |
Varchar(20) |
客戶表 |
客戶密碼 |
Varchar(20) |
客戶表 |
客戶種類 |
bit |
客戶表 |
房間編號 |
int |
房間表 |
房間種類 |
Varchar(18) |
房間表 |
訂購客戶編號 |
Varchar(18) |
訂購表 |
訂購房間編號 |
Int |
訂購表 |
訂購開始時間 |
Datatime |
訂購表 |
訂購結束時間 |
Datatime |
訂購表 |
訂購繳費 |
money |
訂購表 |
房間種類 |
Varchar(18) |
房間種類表 |
某類房間個數 |
int |
房間種類表 |
某類房間標準價 |
money |
房間種類表 |
Customer 客戶信息表
表中列名 |
數據類型 |
能否爲空 |
說明 |
ID |
Varchar(18) |
not null(主鍵) |
客戶編號 |
Name |
Varchar(20) |
not null |
客戶編號 |
password |
Varchar(20) |
not null |
客戶密碼 |
isVIP |
Bit |
not null |
客戶是不是VIP |
Room房間信息表
表中列名 |
數據類型 |
能否爲空 |
說明 |
roomNum |
int |
not null(主鍵) |
房間編號 |
Category |
varchar(20) |
not null |
房間種類 |
RoomCategory房間種類表
表中列名 |
數據類型 |
能否爲空 |
說明 |
Category |
Varchar(20) |
Not null(主鍵) |
房間種類名 |
cnt |
int |
Not null |
某一類房間個數 |
price |
money |
Not null |
某一類房間標準價 |
Order訂購表
表中列名 |
數據類型 |
能否爲空 |
說明 |
ID |
Varchar(18) |
Not null |
訂房客戶編號 |
roomNum |
int |
Not null |
訂房客戶房間編號 |
beginDate |
Datetime |
Not null |
訂房開始時間 |
endDate |
Datetime |
Not null |
訂房結束時間 |
price |
money |
Not null |
實際繳費 |
(1)創建索引:
對Customer表在ID屬性列上創建彙集索引
對Room表在roomNum屬性列上創建彙集索引
對RoomCategory表是在Category屬性列上創建彙集索引
(2)存儲結構
系統的日誌文件和數據文件在D:\Hotel\Data,文件夾下。
1 if exists (select 1 2 3 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F') 4 5 where r.fkeyid = object_id('"Order"') and o.name = 'FK_ORDER_ORDER_CUSTOMER') 6 7 alter table "Order" 8 9 drop constraint FK_ORDER_ORDER_CUSTOMER 10 11 go 12 13 14 15 if exists (select 1 16 17 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F') 18 19 where r.fkeyid = object_id('"Order"') and o.name = 'FK_ORDER_ORDER2_ROOM') 20 21 alter table "Order" 22 23 drop constraint FK_ORDER_ORDER2_ROOM 24 25 go 26 27 28 29 if exists (select 1 30 31 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F') 32 33 where r.fkeyid = object_id('Room') and o.name = 'FK_ROOM_CONTAIN_ROOMCATE') 34 35 alter table Room 36 37 drop constraint FK_ROOM_CONTAIN_ROOMCATE 38 39 go 40 41 42 43 if exists (select 1 44 45 from sysobjects 46 47 where id = object_id('Customer') 48 49 and type = 'U') 50 51 drop table Customer 52 53 go 54 55 56 57 if exists (select 1 58 59 from sysindexes 60 61 where id = object_id('"Order"') 62 63 and name = 'Order2_FK' 64 65 and indid > 0 66 67 and indid < 255) 68 69 drop index "Order".Order2_FK 70 71 go 72 73 74 75 if exists (select 1 76 77 from sysindexes 78 79 where id = object_id('"Order"') 80 81 and name = 'Order_FK' 82 83 and indid > 0 84 85 and indid < 255) 86 87 drop index "Order".Order_FK 88 89 go 90 91 92 93 if exists (select 1 94 95 from sysobjects 96 97 where id = object_id('"Order"') 98 99 and type = 'U') 100 101 drop table "Order" 102 103 go 104 105 106 107 if exists (select 1 108 109 from sysindexes 110 111 where id = object_id('Room') 112 113 and name = 'Contain_FK' 114 115 and indid > 0 116 117 and indid < 255) 118 119 drop index Room.Contain_FK 120 121 go 122 123 124 125 if exists (select 1 126 127 from sysobjects 128 129 where id = object_id('Room') 130 131 and type = 'U') 132 133 drop table Room 134 135 go 136 137 138 139 if exists (select 1 140 141 from sysobjects 142 143 where id = object_id('RoomCategory') 144 145 and type = 'U') 146 147 drop table RoomCategory 148 149 go 150 151 152 153 /*==============================================================*/ 154 155 /* Table: Customer */ 156 157 /*==============================================================*/ 158 159 create table Customer ( 160 161 ID varchar(18) not null, 162 163 name varchar(20) null, 164 165 password varchar(20) null, 166 167 isVIP tinyint null, 168 169 constraint PK_CUSTOMER primary key nonclustered (ID) 170 171 ) 172 173 go 174 175 176 177 /*==============================================================*/ 178 179 /* Table: "Order" */ 180 181 /*==============================================================*/ 182 183 create table "Order" ( 184 185 ID varchar(18) not null, 186 187 roomNum int not null, 188 189 beginDate datetime null, 190 191 endDate datetime null, 192 193 price money null, 194 195 constraint PK_ORDER primary key (ID, roomNum) 196 197 ) 198 199 go 200 201 202 203 /*==============================================================*/ 204 205 /* Index: Order_FK */ 206 207 /*==============================================================*/ 208 209 create index Order_FK on "Order" ( 210 211 ID ASC 212 213 ) 214 215 go 216 217 218 219 /*==============================================================*/ 220 221 /* Index: Order2_FK */ 222 223 /*==============================================================*/ 224 225 create index Order2_FK on "Order" ( 226 227 roomNum ASC 228 229 ) 230 231 go 232 233 234 235 /*==============================================================*/ 236 237 /* Table: Room */ 238 239 /*==============================================================*/ 240 241 create table Room ( 242 243 roomNum int not null, 244 245 Category varchar(18) null, 246 247 constraint PK_ROOM primary key nonclustered (roomNum) 248 249 ) 250 251 go 252 253 254 255 /*==============================================================*/ 256 257 /* Index: Contain_FK */ 258 259 /*==============================================================*/ 260 261 create index Contain_FK on Room ( 262 263 Category ASC 264 265 ) 266 267 go 268 269 270 271 /*==============================================================*/ 272 273 /* Table: RoomCategory */ 274 275 /*==============================================================*/ 276 277 create table RoomCategory ( 278 279 Category varchar(18) not null, 280 281 cnt int null, 282 283 price money null, 284 285 constraint PK_ROOMCATEGORY primary key nonclustered (Category) 286 287 ) 288 289 go 290 291 292 293 alter table "Order" 294 295 add constraint FK_ORDER_ORDER_CUSTOMER foreign key (ID) 296 297 references Customer (ID) 298 299 go 300 301 302 303 alter table "Order" 304 305 add constraint FK_ORDER_ORDER2_ROOM foreign key (roomNum) 306 307 references Room (roomNum) 308 309 go 310 311 312 313 alter table Room 314 315 add constraint FK_ROOM_CONTAIN_ROOMCATE foreign key (Category) 316 317 references RoomCategory (Category) 318 319 go
查詢是否有該用戶
1 if exists (select name from sysobjects where name = 'select_exp' and type = 'P') 2 3 drop procedure select_exp 4 5 GO 6 7 create procedure select_exp @id varchar(18),@passwords varchar(20) 8 9 as 10 11 select * 12 13 from Customer 14 15 where Customer.ID = id and Customer.password = @passwords 16 17 Go
查詢該用戶的訂房清單
1 if exists (select name from sysobjects where name = 'order_exp' and type = 'P') 2 3 drop procedure order_exp 4 5 GO 6 7 create procedure order_exp @the_id varchar(18) 8 9 as 10 11 select Customer.name,[Order].beginDate,[Order].endDate,Room.Category,[Order].price 12 13 from Customer left join [Order] on Customer.ID = [Order].ID 14 15 left join Room on [Order].roomNum = Room.roomNum 16 17 where Customer.ID = [Order].ID and [Order].ID = @the_id 18 19 GO
查詢房間的全部用房時間
1 if exists (select name from sysobjects where name = 'orderbynum_exp' and type = 'P') 2 3 drop procedure orderbynum_exp 4 5 GO 6 7 create procedure orderbynum_exp @type int 8 9 as 10 11 select [Order].beginDate,[Order].endDate 12 13 from [Order] 14 15 where [Order].roomNum = @type 16 17 Go
查詢某類房間具體有哪些房間
1 if exists (select name from sysobjects where name = 'room_exp' and type = 'P') 2 3 drop procedure room_exp 4 5 GO 6 7 create procedure room_exp @type varchar(18) 8 9 as 10 11 select roomNum,price 12 13 from Room left join RoomCategory on Room.Category = RoomCategory.Category 14 15 where Room.Category = @type 16 17 Go
插入一條訂房信息
1 if exists (select name from sysobjects where name = 'insert_exp' and type = 'P') 2 3 drop procedure insert_exp 4 5 GO 6 7 create procedure insert_exp @id varchar(18),@room int,@begin DateTime,@end DateTime,@money money 8 9 as 10 11 insert into [Order](ID,roomNum,beginDate,endDate,price) 12 13 values (@id,@room,@begin,@end,@money) 14 15 GO 16 17
--統計房間觸發器
1 alter trigger cnt 2 3 on Room for insert 4 5 as 6 7 declare @type varchar(20),@tmp int 8 9 select @type = Category 10 11 from inserted 12 13 select @tmp = COUNT(*) 14 15 from Room 16 17 where Room.Category = @type 18 19 update RoomCategory 20 21 set cnt = @tmp 22 23 where RoomCategory.Category = @type 24 25 go 26 27
應用程序採用C#製做,數據庫鏈接使用ADO.NET
考慮到客戶定房間只會給定一個房間種類,和入住時段,如何充分利用房間資源,給客戶提供訂房服務。這裏的解決方案是,遍歷全部該種類的房間,找出每一個房間的入住時間,若是客戶需求的時間不與任何一個時間段衝突,則將這間房間給客戶,不然繼續找下一個房間。
具體核心程序:
登陸數據庫:
//登陸數據庫
1 private void button1_Click(object sender, EventArgs e) 2 3 { 4 5 if(textBox1.Text=="") 6 7 { 8 9 MessageBox.Show("請輸入要鏈接的數據庫名"); 10 11 } 12 13 else 14 15 { 16 17 try 18 19 { 20 21 //datastr = "Server=.;Database="+textBox1.Text.Trim()+";Trusted_Connection=SSPI"; 22 23 datastr = "Data Source=.;" +"Persist Security Info=True;" + "Initial Catalog=Hotel;" + "Integrated Security=false;" + "User ID=sa;" + "Password=yinjian..m;"; 24 25 conn = new SqlConnection(datastr); 26 27 conn.Open(); 28 29 if (conn.State==ConnectionState.Open) 30 31 { 32 33 label2.Text = "數據庫【" + textBox1.Text.Trim() + "】鏈接成功"; 34 35 } 36 37 } 38 39 catch 40 41 { 42 43 } 44 45 } 46 47 }
用戶身份驗證及用戶訂房清單查詢:
//登陸身份
1 private void button3_Click(object sender, EventArgs e) 2 3 { 4 5 conn = new SqlConnection(datastr); 6 7 conn.Open(); 8 9 id = textBox2.Text.Trim(); 10 11 string password = textBox5.Text.Trim(); 12 13 14 15 SqlCommand cmd = new SqlCommand(); 16 17 cmd.Connection = conn; 18 19 20 21 //以存儲過程形式執行 sql 語句 22 23 cmd.CommandType = CommandType.StoredProcedure; 24 25 cmd.CommandText = "select_exp"; 26 27 //設置輸入參數 28 29 cmd.Parameters.AddWithValue("id", id); 30 31 cmd.Parameters.AddWithValue("passwords", password); 32 33 34 35 cmd.ExecuteNonQuery(); 36 37 38 39 //listView1.Clear(); 40 41 SqlDataReader sdr = cmd.ExecuteReader(); 42 43 sdr.Read(); 44 45 if(sdr.HasRows) 46 47 { 48 49 flag = true; 50 51 if (sdr[3].ToString() == "True") 52 53 { 54 55 isVIP = true; 56 57 } 58 59 else isVIP = false; 60 61 label2.Text = sdr[1].ToString() + "用戶登陸成功!"; 62 63 sdr.Close(); 64 65 cmd = new SqlCommand(); 66 67 cmd.Connection = conn; 68 69 cmd.CommandType = CommandType.StoredProcedure; 70 71 cmd.CommandText = "order_exp"; 72 73 cmd.Parameters.AddWithValue("the_id", id); 74 75 76 77 //數據適配器 78 79 SqlDataAdapter sda = new SqlDataAdapter(); 80 81 sda.SelectCommand = cmd; 82 83 84 85 //數據集 86 87 DataSet ds = new DataSet(); 88 89 sda.Fill(ds, "cs"); 90 91 dataGridView1.DataSource = ds.Tables[0]; 92 93 } 94 95 else 96 97 { 98 99 MessageBox.Show("用戶名或密碼錯誤!"); 100 101 } 102 103 }
訂房操做
//訂購房間
1 private void button4_Click(object sender, EventArgs e) 2 3 { 4 5 conn = new SqlConnection(datastr); 6 7 conn.Open(); 8 9 10 11 if (flag==true) 12 13 { 14 15 begin = dateTimePicker1.Value; 16 17 end = dateTimePicker2.Value; 18 19 20 21 MessageBox.Show(end.ToString()); 22 23 24 25 if(end<begin) 26 27 { 28 29 MessageBox.Show("時間非法!"); 30 31 32 33 } 34 35 else 36 37 { 38 39 string type = textBox3.Text.Trim(); 40 41 42 43 SqlCommand cmd = new SqlCommand(); 44 45 cmd.Connection = conn; 46 47 cmd.CommandType = CommandType.StoredProcedure; 48 49 cmd.CommandText = "room_exp"; 50 51 cmd.Parameters.AddWithValue("type", type); 52 53 54 55 56 57 //listView1.Clear(); 58 59 SqlDataReader sdr = cmd.ExecuteReader(); 60 61 62 63 //找出標準單人間有哪些房間,房間號 64 65 66 67 int [] room = new int[1000]; 68 69 int cnt = 0; 70 71 72 73 while (sdr.Read()) 74 75 { 76 77 78 79 room[cnt++] = int.Parse(sdr[0].ToString()); 80 81 xmoneys = decimal.Parse(sdr[1].ToString()); 82 83 84 85 } 86 87 sdr.Close(); 88 89 90 91 bool isflag = true; 92 93 for(int i = 0; i < cnt; i++) 94 95 { 96 97 SqlCommand cmd2 = new SqlCommand(); 98 99 cmd2.Connection = conn; 100 101 cmd2.CommandType = CommandType.StoredProcedure; 102 103 cmd2.CommandText = "orderbynum_exp"; 104 105 cmd2.Parameters.AddWithValue("type", room[i]); 106 107 sdr = cmd2.ExecuteReader(); 108 109 while(sdr.Read()) 110 111 { 112 113 114 115 if(DateTime.Parse(sdr[0].ToString()) <=begin && begin <=DateTime.Parse(sdr[1].ToString())) 116 117 { 118 119 isflag = false; 120 121 break; 122 123 } 124 125 if(DateTime.Parse(sdr[0].ToString())<=end && end <= DateTime.Parse(sdr[1].ToString())) 126 127 { 128 129 isflag = false; 130 131 break; 132 133 } 134 135 } 136 137 sdr.Close(); 138 139 140 141 if (isflag) 142 143 { 144 145 146 147 // room[i] 有空 148 149 SqlCommand cmd3 = new SqlCommand(); 150 151 cmd3.Connection = conn; 152 153 cmd3.CommandType = CommandType.StoredProcedure; 154 155 cmd3.CommandText = "insert_exp"; 156 157 cmd3.Parameters.AddWithValue("id", id); 158 159 cmd3.Parameters.AddWithValue("room", room[i]); 160 161 cmd3.Parameters.AddWithValue("begin",begin); 162 163 cmd3.Parameters.AddWithValue("end", end); 164 165 cmd3.Parameters.AddWithValue("money", xmoneys); 166 167 168 169 //MessageBox.Show(cmd3.ExecuteNonQuery().ToString()); 170 171 cmd3.ExecuteNonQuery(); 172 173 if(isVIP==true) 174 175 { 176 177 xmoneys = xmoneys * (decimal)0.8; 178 179 MessageBox.Show("您的房間號是:"+room[i].ToString()+"您是VIP用戶,給您打了8折優惠"+xmoneys.ToString()+"元"); 180 181 182 183 } 184 185 else 186 187 { 188 189 MessageBox.Show("您的房間號是:" + room[i].ToString() +"繳費"+ xmoneys.ToString() + "元"); 190 191 } 192 193 break; 194 195 } 196 197 } 198 199 200 201 if(isflag==false) 202 203 { 204 205 MessageBox.Show("房間已經被訂購完了!"); 206 207 } 208 209 } 210 211 } 212 213 else 214 215 { 216 217 MessageBox.Show("請先登陸用戶!"); 218 219 } 220 221 }
結 論
在關係數據庫中:
明確設計的最終目標。
對於這些數據,要按照功能和邏輯來進行拆分,而且存放在不一樣的表中,而且明確之間的關係;
對於設計好的表,要進行重構,根據設計範式對錶進行拆分和優化;
對於每一個表要增長對應的完整性檢查,關鍵是實體完整性和參照完整性;
參 考 文 獻
[1] 王珊 薩師煊.數據庫系統概論.第4版.高等教育出版社,2011.5
[2] 張海藩.軟件工程導論(第六版)[M].北京:清華大學出版社,2013.8