宾馆客房管理系统的设计与实现

mac2022-06-30  16

 

课程设计(论文)任务书

 

     软件      学院  软件工程 专业 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=45610 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.互联网资源

 

公众号回复--“宾馆”--获取文档

转载于:https://www.cnblogs.com/chenqiwei/p/RunWsh_room.html

相关资源:酒店客房管理系统
最新回复(0)