課程設計(論文)任務書
軟件 學院 軟件工程 專業 2016 -07 班
一、課程設計(論文)題目 綜合課程設計2
二、課程設計(論文)工作自 2018 年 1月 1 日起至 2018 年 1月 12 日止。
三、課程設計(論文) 地點:軟件工程實訓中心一部
四、課程設計(論文)內容要求:
1.本課程設計的目的
(1)使學生熟練掌握數據庫基本原理;
(2)使學生熟練掌握數據庫的分析和設計能力;
(3)培養學生熟練使用常見的數據庫管理系統;
(4)培養學生使用Java語言進行面向對象設計的能力;
(5)培養學生熟練使用Java語言進行數據庫應用程序設計的能力;
(6)提高學生的科技論文寫作能力。
2.基本要求:
課程設計題目:
設計主要內容:
3.課程設計論文編寫要求
(1)要按照書稿的規格打印謄寫課設報告;
(2)報告分為封面、任務書(本文檔)、正文、課程設計體會和參考文獻四部分;
學生簽名:
2018年1月 1日
課程設計(論文)評審意見
(1)題目分析 (20分):優( )、良( )、中( )、一般( )、差( );
(2)流程分析 (30分):優( )、良( )、中( )、一般( )、差( );
(3)數據定義 (30分):優( )、良( )、中( )、一般( )、差( );
(4)代碼編寫 (10分):優( )、良( )、中( )、一般( )、差( );
(5)創新能力 (10分):優( )、良( )、中( )、一般( )、差( );
(6)格式規范性、設計態度及考勤是否降等級:是( )、否( )
評閱人: 職稱:講師
2018年 1 月 12 日
標題:賓館客房管理系統的設計與實現
一、 數據設計
1. 實體
賓館客房管理系統設計中用到的實體如下:
1) 實體1:用戶信息
屬性1:用戶編號
屬性2:用戶姓名
屬性3:密碼
屬性4:性別(0-男,1-女)
屬性5:Email地址
屬性6:通訊地址
屬性7:聯系電話
屬性8:所在部門
屬性9:用戶類型(1-酒店管理員,2-前台服務員)
2) 實體2:客戶信息
l 屬性1: 身份證號
l 屬性2: 客戶姓名
l 屬性3: 聯系電話
3) 實體3:客房類型
l 屬性1:客房類型編號
l 屬性2:類型名稱
l 屬性3:客房面積
l 屬性4:配置床位
l 屬性5:客房價格
l 屬性6:配置空調(0-是,1-否)
l 屬性7:配置電視(0-是,1-否)
4) 實體4:客房信息
l 屬性1: 客房號
l 屬性2:客房類型編號
l 屬性3:客房位置
l 屬性4:描述
5) 實體5:客房狀態
l 屬性1:客房編號
l 屬性2:狀態(1-空房,2-入住)
6) 實體6:客房業務
l 屬性1:客房編號
l 屬性2:入住時間
l 屬性3:客戶身份證號
l 屬性4:備注
7) 實體7:業務記錄
l 屬性1:入住時間
l 屬性2:退房時間
l 屬性3:客房編號
l 屬性4:金額
l 屬性5:客戶身份證號
l 屬性6:客戶姓名
l 屬性7:客戶電話
l 屬性8:備注
2. 聯系
賓館客房管理系統設計中實體之間的聯系如下(E-R圖):
二、 數據庫設計
1. 關系模式
賓館客房管理設計中的關系模式如下:
客戶(客戶編號,姓名,電話,E-mail)。關系的主鍵:客戶編號;外鍵:無
用戶(用戶編號,用戶姓名,密碼,性別(0-男,1-女),Email地址,通訊地址,聯系電話,所在部門,用戶類型(1-酒店管理員,2-前台服務員)。
關系主鍵:用戶編號;外鍵:無
客戶信息(身份證號,客戶姓名,聯系電話)
關系主鍵:身份證號;外鍵:客戶姓名
客房類型(客房類型編號,類型名稱,客房面積,配置床位,客房價格,配置空調 (0-是,1-否),配置電視(0-是,1-否))
關系主鍵:客房類型編號;外鍵:類型名稱
客房信息(客房號,客房類型編號,客房位置,描述)
關系主鍵:客房號;外鍵:客房類型編號
客房狀態(客房編號,狀態(1-空房,2-入住))
關系主鍵:客房編號;外鍵:無。
客房業務(客房編號,入住時間客戶身份證號,備注)
關系主鍵:客房編號;外鍵:入住身份證號
業務記錄(入住時間,退房時間,客房編號,金額,客戶身份證號,客,姓名,客戶電話,備注)
關系主鍵:入住時間;外鍵:客房編號,客戶身份證,姓名,電話。
2. 數據表
本設計中創建的數據庫名為:
數據表分別為(將數據庫中設計的數據表表截圖至此)。
表1:用戶信息
表2:客戶信息
表3:客房信息類型表
表4:客房信息表
表5:客房狀態表
表6:客房業績表
表7:業務記錄表
數據庫關系圖為:
三、 數據庫實現
設計中實現數據庫操作的SQL 語句如下:
新建數據表:
1)用戶信息數據建表
1 CREATE TABLE [dbo].weiwei( UserId Int 用戶編號 2 Name Varchar(50) 用戶姓名 3 Password Varchar(50) 密碼 4 Gender Int 性別(0-男,1-女) 5 Email Varchar(50) Email地址 6 Address Varchar(50) 通訊地址 7 Telephone Varchar(50) 聯系電話 8 Department Varchar(50) 所在部門 9 10 Type 11 Int 用戶類型(1-酒店管理員,2-前台服務員
2)客戶信息數據建表
1 CREATE TABLE [dbo]. CustomersInfo ( CIdentityId nVarchar(50) 身份證號 2 CName nVarchar(50) 客戶姓名 3 CPhone nVarchar(50) 聯系電話)
3)客戶類型數據建表
1 CREATE TABLE [dbo]. RoomCategory ( RCategoryId Int 客房類型編號 2 Name nVarchar(50) 類型名稱History 3 Area Float 客房面積 4 BedNum Int 配置床位 5 Price Money 客房價格 6 AirCondition Int 配置空調(0-是,1-否) 7 TV Int 配置電視(0-是,1-否) 8 9 )
4)業務記錄數據建表
1 CREATE TABLE [dbo]. History ( BeginTime DateTime 入住時間 2 EndTime DateTime 退房時間 3 RoomId Int 客房編號 4 TotalPrice Money 金額 5 CIdentityId nVarchar(50) 客戶身份證號 6 CName nVarchar(50) 客戶姓名 7 CPhone nVarchar(50) 客戶電話 8 Remarks nVarchar(50) 備注
5)客房信息表
1 CREATE TABLE [dbo].RomsInfo (Room Int 客房號 2 Rcategoryld Int 客房編號 3 RPostition nvarchar(50) 客房位置 4 5 Description nvarchar(50) 描述
6)客房狀態
1 CREATE TABLE [dbo].RoomStatus (Roomld Int 客房編號 2 3 Status Int 狀態)
7)客房業務表
1 CREATE TABLE [dbo].RoomOPeration (Roomld Int 客房編號 2 3 BeginTime DateTime 入住時間 4 5 CIdentityId nVarchar(50) 客戶身份證號
二、查詢
1)業務記錄增加,刪除修改操作
插入:
1 INSERT 2 3 INTO history(Roomld,Cname) 4 5 Values(‘223456’,’345’)
刪除:
1 DELETE 2 3 FROM history 4 5 WHERE Roomld=’57’ 6 7 修改:UPDATE history 8 9 SET Cname=’456’ 10 11 WHERE Roomld=’5678’
2)用戶編號查詢:
1 SELECT userid 2 3 From usersinfo 4 5 Where Gender=’女’
3)客房類型查詢
1 select * 2 3 from view_1 where 客房類型 in"; 4 5 where RCategoryld=‘123’)
4)客房信息查詢
select *
from view_1 where 客房信息 in";
where Roomld=‘063’)
5)客房狀態查詢
1 select * 2 3 from view_1 where 客房狀態 in"; 4 5 where Roomld=‘723’)
6)客房業務表查詢
1 select * 2 3 from view_1 where 客房業務 in"; 4 5 where Roomld=‘793’)
7)客戶信息查詢
1 select * 2 3 from Customersinfo
四、 程序設計
1. 類
設計中定義的Java類如下:
1) weiwei類,表示設計中所有的客戶信息類,連接數據庫。
2) load類,表示設計中的客房管理,是weiwei的子類。
3) AddRooms類,表示設計中的客房管理,是weiwei的子類。
4) UseOfRooms類,表示設計中的客戶,是weiwei的子類。
5) CustomerInformation類,表示設計中的員工信息,是weiwei的子類。
6) CheckStaff類,表示設計中的客戶,是weiwei的子類。
2. 類設計
1)weiwei類
1 public class weiwei 2 3 { 4 5 private TAdminDAO adminDAO; 6 7 private TRenyuanDAO renyuanDAO; 8 9 public TAdminDAO getAdminDAO() 10 11 { 12 13 return adminDAO; 14 15 } 16 17 public void setAdminDAO(TAdminDAO adminDAO) 18 19 { 20 21 this.adminDAO = adminDAO; 22 23 } 24 25 26 27 public TRenyuanDAO getRenyuanDAO() 28 29 { 30 31 return renyuanDAO; 32 33 } 34 35 public void setRenyuanDAO(TRenyuanDAO renyuanDAO) 36 37 { 38 39 this.renyuanDAO = renyuanDAO; 40 41 } 42 43 public String login(String userName,String userPw,int userType) 44 45 { 46 47 System.out.println("userType"+userType); 48 49 try 50 51 { 52 53 Thread.sleep(700); 54 55 } catch (InterruptedException e) 56 57 { 58 59 // TODO Auto-generated catch block 60 61 e.printStackTrace(); 62 63 } 64 65 66 67 String result="no"; 68 69 70 71 if(userType==0)//系統管理員登陸 72 73 { 74 75 String sql="from TAdmin where userName=? and userPw=?"; 76 77 Object[] con={userName,userPw}; 78 79 List adminList=adminDAO.getHibernateTemplate().find(sql,con); 80 81 if(adminList.size()==0) 82 83 { 84 85 result="no"; 86 87 } 88 89 else 90 91 { 92 93 WebContext ctx = WebContextFactory.get(); 94 95 HttpSession session=ctx.getSession(); 96 97 TAdmin admin=(TAdmin)adminList.get(0); 98 99 session.setAttribute("userType", 0); 100 101 session.setAttribute("admin", admin); 102 103 result="yes"; 104 105 } 106 107 } 108 109 if(userType==1) 110 111 { 112 113 String sql="from TRenyuan where gonghao=? and loginpw=? and del='no'"; 114 115 Object[] con={userName.trim(),userPw.trim()}; 116 117 List renyuanList=renyuanDAO.getHibernateTemplate().find(sql,con); 118 119 if(renyuanList.size()==0) 120 121 { 122 123 result="no"; 124 125 } 126 127 else 128 129 { 130 131 WebContext ctx = WebContextFactory.get(); 132 133 HttpSession session=ctx.getSession(); 134 135 TRenyuan renyuan=(TRenyuan)renyuanList.get(0); 136 137 session.setAttribute("userType", 1); 138 139 session.setAttribute("renyuan", renyuan); 140 141 result="yes"; 142 143 } 144 145 } 146 147 if(userType==2) 148 149 { 150 151 152 153 } 154 155 return result; 156 157 } 158 159 160 161 public String adminPwEdit(String userPwNew) 162 163 { 164 165 System.out.println("DDDD"); 166 167 try 168 169 { 170 171 Thread.sleep(700); 172 173 } 174 175 catch (InterruptedException e) 176 177 { 178 179 // TODO Auto-generated catch block 180 181 e.printStackTrace(); 182 183 } 184 185 WebContext ctx = WebContextFactory.get(); 186 187 HttpSession session=ctx.getSession(); 188 189 190 191 TAdmin admin=(TAdmin)session.getAttribute("admin"); 192 193 admin.setUserPw(userPwNew); 194 195 196 197 adminDAO.getHibernateTemplate().update(admin); 198 199 session.setAttribute("admin", admin); 200 201 202 203 return "yes"; 204 205 } 206 207 208 209 } 210 211 212 213 2) load 類 214 215 public class load extends JFrame implements ActionListener { 216 217 private boolean boo1=false,boo2=false; 218 219 int Type=0; 220 221 public JTextField []t ={new JTextField("用戶名:",8),new JTextField(27), 222 223 new JTextField("密碼:",8),new JPasswordField(27), 224 225 new JTextField("賓館客房管理系統登陸界面--(設計人員:陳其巍)",36), 226 227 new JTextField("后台技術:應用數據庫加密技術--安全保護你的信息!請放心使用!",36), 228 229 new JTextField("功能:管理賓館客房!",36)}; 230 231 public JButton []b={new JButton("登陸"),new JButton("退出")}; 232 233 ImageIcon ic=new ImageIcon(HoteLand.class.getResource("/百吉星級酒店.jpg")); 234 235 JFrame app; 236 237 Statement statement; 238 239 //構造方法 240 241 public weiwei(){ 242 243 app= new JFrame("--賓館客房管理系統登陸界面--"); 244 245 app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 246 247 app.setSize(438,583); 248 249 app.setResizable(false); 250 251 Container c=app.getContentPane(); 252 253 c.setLayout(new FlowLayout()); 254 255 JLabel aLabel=new JLabel(ic,JLabel.LEFT); 256 257 t[0].setFont(new Font("TimesRoman",Font.BOLD,13)); 258 259 t[0].setForeground(Color.red); 260 261 t[0].setEditable(false); 262 263 t[2].setFont(new Font("TimesRoman",Font.BOLD,13)); 264 265 t[2].setForeground(Color.red); 266 267 t[2].setEditable(false); 268 269 for(int i=0;i<4;i++) 270 271 c.add(t[i]); 272 273 c.add(b[0]); 274 275 c.add(b[1]); 276 277 for(int j=4;j<7;j++) 278 279 { 280 281 c.add(t[j]); 282 283 t[j].setFont(new Font("TimesRoman",Font.BOLD,13)); 284 285 t[j].setForeground(Color.blue); 286 287 t[j].setEditable(false); 288 289 } 290 291 c.add(aLabel); 292 293 t[0].addActionListener(this); 294 295 t[2].addActionListener(this); 296 297 b[0].addActionListener(this); 298 299 b[1].addActionListener(this); 300 301 app.setVisible(true); 302 303 } 304 305 //消息響應方法 306 307 public void actionPerformed(ActionEvent e){ 308 309 JButton source=(JButton)e.getSource(); 310 311 //如果單擊"登陸"按鍵,執行StudentManager程序,該部分應用到數據庫加密技術 312 313 if(source==b[0]){ 314 315 316 317 try{ 318 319 //基於SQL Server 2000 的 JDBC-ODBC 橋數據庫連接(先要創建一個數據源lib) 320 321 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 322 323 //使用網絡登錄ID的Windows NT 驗證(W) 324 325 Connection conn=DriverManager.getConnection("jdbc:odbc:賓館客戶數據庫"); statement=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); 326 327 String s1=t[1].getText(); 328 329 String s2=t[3].getText(); 330 331 ResultSet resultset=statement.executeQuery("select * from UsersInfo where Name='"+s1+"'and Password='"+s2+"'"); 332 333 resultset.next(); 334 335 Type=resultset.getInt("Type"); 336 337 if(resultset!=null){ 338 339 boo1=boo2=true; 340 341 resultset.close(); 342 343 } 344 345 } 346 347 catch(Exception e1){ 348 349 JOptionPane.showMessageDialog(this,"用戶名和密碼不正確!","警告",JOptionPane.WARNING_MESSAGE); 350 351 } 352 353 //如果輸入的用戶名和密碼都正確,則登陸 354 355 if(boo1&&boo2&&Type==1){ 356 357 Type=0; 358 359 boo1=boo2=true; 360 361 new HoteMen(statement,"普通員工--"+t[1].getText()); 362 363 app.setVisible(false); 364 365 } 366 367 if(boo1&&boo2&&Type==2){ 368 369 Type=0; 370 371 boo1=boo2=true; 372 373 new HotelManagerMen(statement,"管理員--"+t[1].getText()); 374 375 //new StudentManager(); 376 377 app.setVisible(false); 378 379 } 380 381 } 382 383 //如果單擊"退出"按鍵,則退出登陸界面 384 385 if(source==b[1]){ 386 387 System.exit(0); 388 389 } 390 391 } 392 393 public static void main(String args[]){ 394 395 new weiwei(); 396 397 } 398 399 } 400 401 }
3)AddRooms類
1 public class AddRooms extends weiwei implements ActionListener 2 3 { 4 5 Hashtable 基本信息表=null; 6 7 JTextField 房間號,房間位置; 8 9 JTextArea 描述; 10 11 JButton 錄入,重置; 12 13 Choice 房間類型; 14 15 Statement statement=null; 16 17 JLabel 添加客房信息=null; 18 19 public AddRooms(Statement statement) 20 21 { 22 23 this.statement=statement; 24 25 房間號=new JTextField(10); 26 27 房間位置=new JTextField(10); 28 29 描述 =new JTextArea(7,10); 30 31 錄入=new JButton("錄入"); 32 33 重置=new JButton("重置"); 34 35 錄入.addActionListener(this); 36 37 重置.addActionListener(this); 38 39 Box box0=Box.createHorizontalBox(); 40 41 添加客房信息=new JLabel("--添加客房信息--",JLabel.CENTER); 42 43 添加客房信息.setFont(new Font("TimesRoman",Font.BOLD,25)); 44 45 添加客房信息.setForeground(Color.red); 46 47 box0.add(添加客房信息); 48 49 Box box1=Box.createHorizontalBox(); 50 51 box1.add(new JLabel("房間號:",JLabel.CENTER)); 52 53 box1.add(房間號); 54 55 房間類型=new Choice(); 56 57 房間類型.add("普通單人間"); 58 59 房間類型.add("普通雙人間"); 60 61 房間類型.add("vip單人間"); 62 63 房間類型.add("vip雙人間"); 64 65 房間類型.add("豪華貴賓間"); 66 67 房間類型.add("總統套間"); 68 69 Box box2=Box.createHorizontalBox(); 70 71 box2.add(new JLabel("房間類型:",JLabel.CENTER)); 72 73 box2.add(房間類型); 74 75 Box box3=Box.createHorizontalBox(); 76 77 box3.add(new JLabel("房間位置:",JLabel.CENTER)); 78 79 box3.add(房間位置); 80 81 Box box4=Box.createHorizontalBox(); 82 83 box4.add(new JLabel("單價 :",JLabel.CENTER)); 84 85 box4.add(new JScrollPane(描述),BorderLayout.CENTER); 86 87 Box boxH=Box.createVerticalBox(); 88 89 boxH.add(box0); 90 91 boxH.add(box1); 92 93 boxH.add(box2); 94 95 boxH.add(box3); 96 97 boxH.add(box4); 98 99 boxH.add(Box.createVerticalGlue()); 100 101 JPanel pCenter=new JPanel(); 102 103 pCenter.add(boxH); 104 105 setLayout(new BorderLayout()); 106 107 add(pCenter,BorderLayout.CENTER); 108 109 JPanel pSouth=new JPanel(); 110 111 pSouth.add(錄入); 112 113 pSouth.add(重置); 114 115 add(pSouth,BorderLayout.SOUTH); 116 117 validate(); 118 119 } 120 121 public void actionPerformed(ActionEvent e) 122 123 { 124 125 ResultSet resultset=null; 126 127 boolean boo=false; 128 129 if(e.getSource()==錄入) 130 131 { 132 133 int number=0; 134 135 try{ 136 137 number=Integer.parseInt(房間號.getText().toString()); 138 139 boo=true; 140 141 } 142 143 catch(Exception e1){ 144 145 boo=false; 146 147 } 148 149 if(boo&&(number>0)) 150 151 { 152 153 try{ 154 155 resultset=statement.executeQuery("use 賓館客戶數據庫;select * from RoomsInfo where RoomId='"+number+"'"); 156 157 try{ 158 159 resultset.next(); 160 161 resultset.getInt("RoomId"); 162 163 String warning="該客房信息已存在,請到修改頁面修改!"; 164 165 JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); 166 167 } 168 169 catch(Exception e1){ 170 171 int RoomId=Integer.parseInt(房間號.getText().toString()); 172 173 String RCategory=房間類型.getSelectedItem().toString(); 174 175 String RPostion=房間位置.getText().toString(); 176 177 String Description=描述.getText().toString(); 178 179 String str="use 賓館客戶數據庫;insert into RoomsInfo values("+RoomId+",'"+RCategory+"','"+RPostion+"','"+Description+"')"; 180 181 try{ 182 183 statement.executeUpdate(str); 184 185 statement.executeUpdate("use 賓館客戶數據庫;insert into RoomStatus values("+RoomId+","+1+")"); 186 187 JOptionPane.showMessageDialog(this,"成功錄入客房信息!","提示",JOptionPane.WARNING_MESSAGE); 188 189 } 190 191 catch(Exception e2){ 192 193 194 195 String warning="輸入格式有誤,請重新輸入!"; 196 197 JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); 198 199 e2.printStackTrace(); 200 201 } 202 203 房間號.setText(null); 204 205 房間類型.select("普通單人間"); 206 207 房間位置.setText(null); 208 209 描述.setText(null); 210 211 } 212 213 214 215 } 216 217 catch(Exception e1){ 218 219 String warning="輸入格式有誤,請重新輸入!"; 220 221 JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); 222 223 } 224 225 226 227 } 228 229 else { 230 231 String warning="必須要輸入房間號!"; 232 233 JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE); 234 235 } 236 237 } 238 239 if(e.getSource()==重置) 240 241 { 242 243 房間號.setText(null); 244 245 房間類型.select("普通單人間"); 246 247 房間位置.setText(null); 248 249 描述.setText(null); 250 251 } 252 253 } 254 255 }
4)UseOfRooms類
1 public class UseOfRooms extends weiwei implements ActionListener 2 3 { 4 5 JButton 查詢; 6 7 Choice 房間類型,狀態; 8 9 Statement statement=null; 10 11 JTextArea 房間使用情況; 12 13 JLabel 客房使用情況=null; 14 15 public UseOfRooms(Statement statement) 16 17 { 18 19 this.statement=statement; 20 21 查詢=new JButton("查詢"); 22 23 查詢.addActionListener(this); 24 25 房間類型=new Choice(); 26 27 房間類型.add("普通單人間"); 28 29 房間類型.add("普通雙人間"); 30 31 房間類型.add("vip單人間"); 32 33 房間類型.add("vip雙人間"); 34 35 房間類型.add("豪華貴賓間"); 36 37 房間類型.add("總統套間"); 38 39 狀態=new Choice(); 40 41 狀態.add("有"); 42 43 狀態.add("否"); 44 45 Box box0=Box.createHorizontalBox(); 46 47 客房使用情況=new JLabel("--客房使用情況--",JLabel.CENTER); 48 49 客房使用情況.setFont(new Font("TimesRoman",Font.BOLD,25)); 50 51 客房使用情況.setForeground(Color.red); 52 53 box0.add(客房使用情況); 54 55 Box box1=Box.createHorizontalBox(); 56 57 box1.add(new JLabel("按房間類型:",JLabel.CENTER)); 58 59 box1.add(房間類型); 60 61 Box box2=Box.createHorizontalBox(); 62 63 box2.add(new JLabel("狀態:",JLabel.CENTER)); 64 65 box2.add(狀態); 66 67 box2.add(查詢); 68 69 Box box3=Box.createHorizontalBox(); 70 71 box3.add(new JLabel("房間使用情況:",JLabel.CENTER)); 72 73 Box box4=Box.createHorizontalBox(); 74 75 box4.add(new JLabel("-客房號:")); 76 77 box4.add(new JLabel("-客房類型:")); 78 79 box4.add(new JLabel("-是否空房:")); 80 81 Box box5=Box.createHorizontalBox(); 82 83 房間使用情況=new JTextArea(8,12); 84 85 房間使用情況.setFont(new Font("TimesRoman",Font.BOLD,15)); 86 87 房間使用情況.setForeground(Color.red); 88 89 房間使用情況.setEditable(false); 90 91 box5.add(new JScrollPane(房間使用情況),BorderLayout.CENTER); 92 93 Box boxH=Box.createVerticalBox(); 94 95 boxH.add(box0); 96 97 boxH.add(box1); 98 99 boxH.add(box2); 100 101 boxH.add(box3); 102 103 boxH.add(box4); 104 105 boxH.add(box5); 106 107 boxH.add(Box.createVerticalGlue()); 108 109 JPanel pCenter=new JPanel(); 110 111 pCenter.add(boxH); 112 113 setLayout(new BorderLayout()); 114 115 add(pCenter,BorderLayout.CENTER); 116 117 validate(); 118 119 } 120 121 public void actionPerformed(ActionEvent e) 122 123 { int i=1; 124 125 ResultSet resultset=null; 126 127 String string=""; 128 129 if(e.getSource()==查詢){ 130 131 String str=房間類型.getSelectedItem().toString(); 132 133 String str1=狀態.getSelectedItem(); 134 135 if(str1.equals("有")){ 136 137 i=2; 138 139 } 140 141 else i=1; 142 143 String str2="use 賓館客戶數據庫;select RoomsInfo.RoomId,RCategory,RoomStatus.Status from RoomsInfo,RoomStatus where RoomsInfo.RoomId=RoomStatus.RoomId and Status="+i+" and RCategory='"+str+"'"; 144 145 try{ 146 147 resultset=statement.executeQuery(str2); 148 149 while(resultset.next()){ 150 151 string+=resultset.getInt(1)+", "+resultset.getString(2)+", "+str1+"\n"; 152 153 } 154 155 if(string==""){ 156 157 房間使用情況.setText("沒有要找的客房!"); 158 159 } 160 161 else 162 163 房間使用情況.setText(string); 164 165 } 166 167 catch(Exception e1){ 168 169 e1.printStackTrace(); 170 171 } 172 173 } 174 175 } 176 177 } 178 179
5)CustomerInformation類
1 public class CustomerInformation extends weiwei implements ActionListener 2 3 { 4 5 JTextField 姓名; 6 7 JTextArea 查詢結果; 8 9 JButton 查詢,查詢所有; 10 11 Statement statement=null; 12 13 JLabel 客戶信息查詢; 14 15 public CustomerInformation(Statement statement) 16 17 { 18 19 this.statement=statement; 20 21 姓名=new JTextField(10); 22 23 查詢=new JButton("查詢"); 24 25 查詢所有=new JButton("查詢所有"); 26 27 姓名.addActionListener(this); 28 29 查詢.addActionListener(this); 30 31 查詢所有.addActionListener(this); 32 33 查詢結果=new JTextArea(8,10); 34 35 查詢結果.setEditable(false); 36 37 查詢結果.setFont(new Font("TimesRoman",Font.BOLD,15)); 38 39 查詢結果.setForeground(Color.blue); 40 41 Box box0=Box.createHorizontalBox(); 42 43 客戶信息查詢=new JLabel("--客戶信息查詢--",JLabel.CENTER); 44 45 客戶信息查詢.setFont(new Font("TimesRoman",Font.BOLD,25)); 46 47 客戶信息查詢.setForeground(Color.red); 48 49 box0.add(客戶信息查詢); 50 51 Box box1=Box.createHorizontalBox(); 52 53 box1.add(new JLabel("輸入要查詢的姓名:",JLabel.CENTER)); 54 55 box1.add(姓名); 56 57 box1.add(查詢); 58 59 Box box2=Box.createHorizontalBox(); 60 61 box2.add(new JLabel("查詢結果:",JLabel.CENTER)); 62 63 box2.add(new JScrollPane(查詢結果),BorderLayout.CENTER); 64 65 Box box3=Box.createHorizontalBox(); 66 67 box3.add(查詢所有); 68 69 Box boxH=Box.createVerticalBox(); 70 71 boxH.add(box0); 72 73 boxH.add(box1); 74 75 boxH.add(box2); 76 77 boxH.add(box3); 78 79 boxH.add(Box.createVerticalGlue()); 80 81 JPanel pCenter=new JPanel(); 82 83 pCenter.add(boxH); 84 85 setLayout(new BorderLayout()); 86 87 add(pCenter,BorderLayout.CENTER); 88 89 validate(); 90 91 } 92 93 public void actionPerformed(ActionEvent e) 94 95 { 96 97 ResultSet resultset=null; 98 99 boolean boo=false; 100 101 String CName="",CIdentityId="",CPhone="",CRoom,BeginTime,Remarks; 102 103 String str="",chk; 104 105 if(e.getSource()==查詢) 106 107 { CName=姓名.getText().toString(); 108 109 if(!CName.equals("")) 110 111 { 112 113 try{ 114 115 chk="use 賓館客戶數據庫;select * from CustomersInfo,RoomOperation where CustomersInfo.CIdentityId=RoomOperation.CIdentityId and CName='"+CName+"'"; 116 117 resultset=statement.executeQuery(chk); 118 119 resultset.next(); 120 121 CIdentityId=resultset.getString("CIdentityId"); 122 123 CPhone=resultset.getString("CPhone"); 124 125 CRoom=resultset.getString("RoomId"); 126 127 BeginTime=resultset.getString("BeginTime"); 128 129 Remarks=resultset.getString("Remarks"); 130 131 str="客房號:"+CRoom+"\n身份證號碼:"+CIdentityId+"\n客戶姓名:"+CName+"\n電話:"+CPhone+"\n訂房時間:"+BeginTime+"\n備注:"+Remarks+"\n"; 132 133 查詢結果.setText(str); 134 135 } 136 137 catch(Exception e1){ 138 139 String warning="該客房信息不存在!"; 140 141 查詢結果.setText(warning); 142 143 JOptionPane.showMessageDialog(this,warning, 144 145 "警告",JOptionPane.WARNING_MESSAGE); 146 147 } 148 149 } 150 151 else{ 152 153 String warning="必須要輸入客戶姓名!"; 154 155 JOptionPane.showMessageDialog(this,warning, 156 157 "警告",JOptionPane.WARNING_MESSAGE); 158 159 } 160 161 } 162 163 if(e.getSource()==查詢所有){ 164 165 str=""; 166 167 try{ 168 169 chk="use 賓館客戶數據庫;select * from CustomersInfo,RoomOperation where CustomersInfo.CIdentityId=RoomOperation.CIdentityId"; 170 171 resultset=statement.executeQuery(chk); 172 173 while(resultset.next()){ 174 175 CIdentityId=resultset.getString("CIdentityId"); 176 177 CName=resultset.getString("CName"); 178 179 CPhone=resultset.getString("CPhone"); 180 181 CRoom=resultset.getString("RoomId"); 182 183 BeginTime=resultset.getString("BeginTime"); 184 185 Remarks=resultset.getString("Remarks"); 186 187 str="客房號:"+CRoom+"\n身份證號碼:"+CIdentityId+"\n客戶姓名:"+CName+"\n電話:"+CPhone+"\n訂房時間:"+BeginTime+"\n備注:"+Remarks+"\n"; 188 189 } 190 191 if(str.equals("")){ 192 193 姓名.setText(""); 194 195 查詢結果.setText("客戶信息不存在!"); 196 197 } 198 199 else { 200 201 姓名.setText(""); 202 203 查詢結果.setText(str); 204 205 } 206 207 } 208 209 catch(Exception e1){ 210 211 //e1.printStackTrace(); 212 213 姓名.setText(""); 214 215 查詢結果.setText("客房信息不存在!"); 216 217 String warning="客房信息不存在!"; 218 219 JOptionPane.showMessageDialog(this,warning, 220 221 "警告",JOptionPane.WARNING_MESSAGE); 222 223 } 224 225 } 226 227 } 228 229 } 230 231
6) CheckStaff類
1 public class CheckStaff extends weiwei implements ActionListener 2 3 { 4 5 JTextField 姓名; 6 7 JTextArea 查詢結果; 8 9 JButton 查詢,查詢所有; 10 11 Statement statement=null; 12 13 JLabel 客戶信息查詢; 14 15 public CheckStaff(Statement statement) 16 17 { 18 19 this.statement=statement; 20 21 姓名=new JTextField(10); 22 23 查詢=new JButton("查詢"); 24 25 查詢所有=new JButton("查詢所有"); 26 27 姓名.addActionListener(this); 28 29 查詢.addActionListener(this); 30 31 查詢所有.addActionListener(this); 32 33 查詢結果=new JTextArea(7,10); 34 35 查詢結果.setEditable(false); 36 37 查詢結果.setFont(new Font("TimesRoman",Font.BOLD,15)); 38 39 查詢結果.setForeground(Color.blue); 40 41 Box box0=Box.createHorizontalBox(); 42 43 客戶信息查詢=new JLabel("--員工信息查詢--",JLabel.CENTER); 44 45 客戶信息查詢.setFont(new Font("TimesRoman",Font.BOLD,25)); 46 47 客戶信息查詢.setForeground(Color.red); 48 49 box0.add(客戶信息查詢); 50 51 Box box1=Box.createHorizontalBox(); 52 53 box1.add(new JLabel("輸入要查詢的姓名:",JLabel.CENTER)); 54 55 box1.add(姓名); 56 57 box1.add(查詢); 58 59 Box box2=Box.createHorizontalBox(); 60 61 box2.add(new JLabel("查詢結果:",JLabel.CENTER)); 62 63 box2.add(new JScrollPane(查詢結果),BorderLayout.CENTER); 64 65 Box box3=Box.createHorizontalBox(); 66 67 box3.add(查詢所有); 68 69 Box boxH=Box.createVerticalBox(); 70 71 boxH.add(box0); 72 73 boxH.add(box1); 74 75 boxH.add(box2); 76 77 boxH.add(box3); 78 79 boxH.add(Box.createVerticalGlue()); 80 81 JPanel pCenter=new JPanel(); 82 83 pCenter.add(boxH); 84 85 setLayout(new BorderLayout()); 86 87 add(pCenter,BorderLayout.CENTER); 88 89 validate(); 90 91 } 92 93 public void actionPerformed(ActionEvent e) 94 95 { 96 97 ResultSet resultset=null; 98 99 boolean boo=false; 100 101 String Name,Password,Sex,Email,Address,Telephone,Department,Type; 102 103 int UserId=-1,Gender=0; 104 105 String str=""; 106 107 if(e.getSource()==查詢) 108 109 { 110 111 Name=姓名.getText().toString(); 112 113 if(!Name.equals("")) 114 115 { 116 117 try{ 118 119 resultset=statement.executeQuery("use 賓館客戶數據庫;select * from UsersInfo where Name='"+Name+"'"); 120 121 resultset.next(); 122 123 UserId=resultset.getInt("UserId"); 124 125 Name=resultset.getString("Name"); 126 127 Password=resultset.getString("Password"); 128 129 Gender=resultset.getInt("Gender"); 130 131 if(Gender==1){ 132 133 Sex="男"; 134 135 } 136 137 else Sex="女"; 138 139 Email=resultset.getString("Email"); 140 141 Address=resultset.getString("Address"); Telephone=resultset.getString("Telephone"); 142 143 Department=resultset.getString("Department"); 144 145 Type=resultset.getInt("Type")==1?"普通員工":"賓館管理員"; str=UserId+","+Name+","+Password+","+Sex+","+Email+","+Address+","+Telephone+","+Department+","+Type+"\n"; 146 147 查詢結果.setText(str); 148 149 } 150 151 catch(Exception e1){ 152 153 String warning="該客房信息不存在!"; 154 155 查詢結果.setText(warning); 156 157 JOptionPane.showMessageDialog(this,warning 158 159 ,"警告",JOptionPane.WARNING_MESSAGE); 160 161 } 162 163 } 164 165 else{ 166 167 String warning="必須要輸入客戶姓名!"; 168 169 JOptionPane.showMessageDialog(this,warning, 170 171 "警告",JOptionPane.WARNING_MESSAGE); 172 173 } 174 175 } 176 177 if(e.getSource()==查詢所有){ 178 179 str=""; 180 181 try{ 182 183 resultset=statement.executeQuery("use 賓館客戶數據庫;select * from UsersInfo"); 184 185 while(resultset.next()){ 186 187 UserId=resultset.getInt("UserId"); 188 189 Name=resultset.getString("Name"); 190 191 Password=resultset.getString("Password"); 192 193 Gender=resultset.getInt("Gender"); 194 195 if(Gender==1){ 196 197 Sex="男"; 198 199 } 200 201 else Sex="女"; 202 203 Email=resultset.getString("Email"); 204 205 Address=resultset.getString("Address"); 206 207 Telephone=resultset.getString("Telephone"); 208 209 Department=resultset.getString("Department"); 210 211 Type=resultset.getInt("Type")==1?"普通員工":"賓館管理員"; 212 213 str+=UserId+","+Name+","+Password+","+Sex+","+Email+","+Address+","+Telephone+","+Department+","+Type+"\n"; 214 215 } 216 217 if(str.equals("")){ 218 219 姓名.setText(""); 220 221 查詢結果.setText("客戶信息不存在!"); 222 223 } 224 225 else { 226 227 姓名.setText(""); 228 229 查詢結果.setText(str); 230 231 } 232 233 } 234 235 catch(Exception e1){ 236 237 姓名.setText(""); 238 239 查詢結果.setText("客房信息不存在!"); 240 241 String warning="客房信息不存在!"; 242 243 JOptionPane.showMessageDialog(this,warning, 244 245 "警告",JOptionPane.WARNING_MESSAGE); 246 247 }}}} 248 249 250 251 252 253 254 255
五、 Java源代碼
1 package com.util; 2 3 4 5 import java.text.ParseException; 6 7 import java.util.Date; 8 9 import java.util.GregorianCalendar; 10 11 import java.net.URL.*; 12 13 import javax.swing.*; 14 15 import javax.swing.ImageIcon; 16 17 import javax.swing.JLabel; 18 19 import java.sql.*; 20 21 import java.awt.Container; 22 23 import java.awt.GridLayout; 24 25 import java.awt.FlowLayout; 26 27 import javax.swing.JButton; 28 29 import javax.swing.JFrame; 30 31 import javax.swing.JTextField; 32 33 import javax.swing.JPasswordField; 34 35 import java.awt.event.ActionEvent; 36 37 import java.awt.event.ActionListener; 38 39 import java.awt.*; 40 41 import java.awt.*; 42 43 import java.awt.event.*; 44 45 import javax.swing.*; 46 47 import java.io.*; 48 49 import java.util.*; 50 51 import java.sql.*; 52 53 54 55 56 57 public class Util { 58 59 public static Date newDate(String s) throws ParseException { 60 61 java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( 62 63 "yyyy-MM-dd"); 64 65 Date date = new Date(); 66 67 date = sdf.parse(s); 68 69 return date; 70 71 } 72 73 74 75 public static Date newDate1(String s) throws ParseException { 76 77 java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( 78 79 "yyyy-MM-dd HH:mm"); 80 81 Date date = new Date(); 82 83 date = sdf.parse(s); 84 85 return date; 86 87 } 88 89 90 91 public static Date FormatFullDate(String s) throws ParseException { 92 93 java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( 94 95 "yyyy-MM-dd HH:mm:ss"); 96 97 Date date = new Date(); 98 99 date = sdf.parse(s); 100 101 return date; 102 103 104 105 } 106 107 108 109 public static String splitDate(Date d) { 110 111 java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( 112 113 "yyyy-MM-dd"); 114 115 return sdf.format(d); 116 117 } 118 119 120 121 public static String splitDate1(Date d) { 122 123 java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( 124 125 "yyyy年MM月dd日"); 126 127 return sdf.format(d); 128 129 } 130 131 132 133 public static String chop(String orignalString, double length, 134 135 String chopedString) { 136 137 if (orignalString == null || orignalString.length() == 0) { 138 139 return orignalString; 140 141 } 142 143 orignalString = orignalString.replaceAll(" ", " "); 144 145 if (orignalString.length() < length) { 146 147 return orignalString; 148 149 } 150 151 StringBuffer buffer = new StringBuffer((int) length); 152 153 length = length * 2; 154 155 int count = 0; 156 157 int stringLength = orignalString.length(); 158 159 int i = 0; 160 161 for (; count < length && i < stringLength; i++) { 162 163 char c = orignalString.charAt(i); 164 165 if (c < '\u00ff') { 166 167 count++; 168 169 } else { 170 171 count += 2; 172 173 } 174 175 buffer.append(c); 176 177 } 178 179 if (i < stringLength) { 180 181 buffer.append(chopedString); 182 183 } 184 185 return buffer.toString(); 186 187 } 188 189 190 191 public static long getPrimeKey() { 192 193 GregorianCalendar calendar = new GregorianCalendar(); 194 195 return calendar.getTimeInMillis(); 196 197 } 198 199 200 201 public static long stringToLong(String source) { 202 203 return Long.parseLong(source); 204 205 } 206 207 /* 208 209 * public static void main(String[] args){ for(int i=0;i<10;i++){ 210 211 * System.out.println(Util.getPrimeKey()); } } 212 213 */ 214 215 }
六、 實驗結果
圖:1-1客房管理管理頁面的設計
圖2-2客房經營管理頁面
圖3-3 客戶信息查詢頁面
圖4-4 員工信息管理頁面
七、 實驗小結
1. 數據庫設計小結
當時對於數據庫的選擇,卻走了一點彎路。因為平時對於數據庫接觸不多,所以一開始建表找工具花費時間作為數據庫。這在初期是沒啥問題的,但后來隨着項目推進,產品經理不斷地增加需求,慢慢對建表,查詢和數據類型熟練。
2. Java應用小結
我是用這個學期剛開的java語言進行編寫。這樣不僅可以學習數據庫,而且還可以對Java的知識進行鞏固。知識是相互聯系的,沒有哪一門是單獨而存在的。對java大項目應用程序,要靈活應用類的定義以及類當中的方法,在定義類時,善於用接口。面對對象中,多個實現功能,最好用類和類繼承。
3. 需完善之處
數據庫建表和java的可連接部分需要熟練,需要自己掌握。對SQL語句建表的變量需要記住,以后不需要查詢書本。當我把這個數據庫完整地設計出時,我心情是多么的激動,多么的自豪。這次實驗主要是數據庫設計,而應用程序是次要的。所以,在這次實驗中,由於時間問題,我只是做了一部分功能,但也足已蔚我心了。這個賓館客房管理系統完完全全是我自己做的,沒有一點參照成分。做完這個實驗后,盡管這個系統有不足之處,但我感覺自己的編程能力已經有了質的提升。我真的很高興!很自豪!
課程設計體會
本次實驗是對我進行一次全面的綜合訓練,這次實驗不僅僅是把這個學期的數據庫的知識總結,更是自入學以來一次知識大檢查。自己學了什么,都會心里有底。這個不單要掌握數據庫原理,還要熟練掌握一門編程語言。在這次實驗中,我是用這個學期剛開的java語言進行編寫。這樣不僅可以學習數據庫,而且還可以對Java的知識進行鞏固。知識是相互聯系的,沒有哪一門是單獨而存在的。所以,要學好一門課,就是應該橫向思考,多聯系,這樣會學得更深刻。這次實驗,首先是要縱觀全局,從大處着眼,先是需求分析,這是設計過程的基礎,是最困難,最耗時的一步。作為“地基”的分析是否做得充分與准確,決定了在其上構建數據庫大廈的速度與質量。需求分析做得不好,甚至會導致整個數據庫設計返工重做。接着就是概念結構設計,這也是整個數據庫設計的關鍵,它通過對用戶需求進行綜合,歸納與抽象,形成一個獨立具體DBMS的概念模型。再接着就是邏輯結構設計了,最后就是編程工作了。
參考文獻
1.數據庫系統概論(第5版)王珊 薩師煊編著 高等教育出版社 2014年9月
2.Java語言程序設計(第2版)丁振凡 編著 清華大學出版社2014年9月
3.求是科技編著SQLsever 2000數據庫開發技術與工程實踐 人民郵電出版社2004年6月
4.數據庫系統實驗指導 單建魁 趙啟升 編著 清華大學出版社
5.互聯網資源
公眾號回復--“賓館”--獲取文檔