资源描述
1)研究内容
本系统根据宾馆的业务情况该系统可分客房信息管理、客房经营管理、客户信息查询、员工信息管理4个功能模块。
2)实验方案
根据课题的具体要求,可以将宾馆客房管理系统大体结构图示为如下:
宾馆客房管理系统
系统管理
(用户登陆)
客房信息管理
客房经营管理
客户信息查询
员工信息管理
查询房间信息
客房使用情况
宾馆订房
宾馆退房
删除房间信息
信息
客户信息查询
员工查询
员工添加
员工删除
修改房间信息
录入房间信息
整个系统分4个模块:
1.客房信息管理:录入房间信息、修改房间信息、查询房间信息, 删除房间信息.
2.客房经营管理:客房使用情况、宾馆订房、客房预订、宾馆退房.
3.客户信息查询:客户信息查询.
4.员工信息管理:员工查询、员工添加、员工删除。
四、数据库设计
1.E-R图的分析:
E-R图的分析工作通常采用自底向下的设计方法,首先对局部视图进行分析设计,然后再实现视图集成。宾馆客房管理系统一般包括如下几个表:用户信息(UsersInfo)、客户信息(CustomersInfo)、客房类型(RoomCategory)、客房信息(RoomsInfo)、客房状态(RoomStatus)、客房业务(RoomOperation)、业务记录(History)。他们之间关系如图1所示。
图1 宾馆客房管理系统E-R图
2. 创建表
(1) 用户信息表
表1 用户信息表(UsersInfo)
编 号
字 段 名 称
数 据 结 构
说 明
1
UserId
Int
服务员编号
2
Name
nchar(6)
服务员姓名
3
Password
Varchar(50)
密码
4
Gender
Int
性别(0-男,1-女)
5
Email
Varchar(50)
Email地址
6
Address
Varchar(50)
通讯地址
7
Telephone
nchar(11)
联系电话
8
Department
Varchar(30)
所在部门
9
Type
Int
用户类型(1-酒店管理员,2-前台服务员
(2) 客户信息表
表2 客户信息表(CustomersInfo)
编 号
字 段 名 称
数 据 结 构
说 明
1
CIdentityId
nVarchar(18)
身份证号
2
CName
nchar(6)
客户姓名
3
CPhone
nchar(11)
联系电话
4
VIPDegree
nchar(1)
会员级别
(3) 客房信息表
表3 客房类型表(RoomInfo)
编 号
字 段 名 称
数 据 结 构
说 明
1
RoomId
nVarchar(4)
客房号
2
Name
nVarchar(50)
类型名称
3
Price
Money
客房价格
4
Status
Int
状态(1-空房,2-入住)
5
Description
nVarchar(50)
描述
(4) 客户订单表
表4 客房业务表(CustomersBook)
编 号
字 段 名 称
数 据 结 构
说 明
1
RoomId
Int
客房号
2
CName
Nchar(6)
客户姓名
3
CPhone
Nchar(11)
客户电话
4
BeginTime
DateTime
入住时间
5
EndTime
DateTime
退房时间
6
CIdentityId
nVarchar(50)
客户身份证号
7
Money
Money
付款金额
8
UserId
Int
服务员编号
9
Remarks
nVarchar(50)
备注
(5)VIP折扣表
表5 VIP折扣表(VIPDiscount)
编 号
字 段 名 称
数 据 结 构
说 明
1
CPhone
Nchar(11)
用户电话
2
VIPDegree
Nchar(1)
会员等级
3
VIPDiscount
Int
会员折扣
五.页面设计及相关代码分析
宾馆客房管理系统的页面由五部分组成:
● 宾馆客房管理系统登陆界面的设计
● 客房管理管理页面的设计
● 客房经营管理页面的设计
● 客户信息查询页面的设计
● 员工信息管理页面的设计
1. 宾馆客房管理系统登陆界面的设计
系统共分两类用户:酒店管理员和前台服务员
当用户进入宾馆客房管理系统登陆界面后,首先需要进行身份验证,系统在验证通过后,将使用UserType变量记录其用户类型,并根据用户类型确定用户的使用权限。宾馆客房管理系统登陆界面如下2所示。
现在给出登陆界面的主要代码如下:
import .URL.*;
import javax.swing.*;
import java.sql.*;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
public class HoteLand extends JFrame implements ActionListener {
private boolean boo1 = false, boo2 = false;
int Type = 0;
public JTextField[] t = { new JTextField("用户名:", 6), new JTextField(20),
new JTextField("密码:", 6), new JPasswordField(20) };
public JButton[] b = { new JButton("登陆"), new JButton("退出") };
ImageIcon ic = new ImageIcon(HoteLand.class.getResource("/hotel.jpg"));
JFrame app;
Statement statement;
// 构造方法
public HoteLand() {
app = new JFrame("宾馆客房管理系统登陆界面");
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setSize(350, 345);
app.setLocation(500, 100);
app.setResizable(false);
Container c = app.getContentPane();
c.setLayout(new FlowLayout());
JLabel Label = new JLabel(ic, JLabel.LEFT);
t[0].setFont(new Font("TimesRoman", Font.BOLD, 13));
t[0].setForeground(Color.red);
t[0].setEditable(false);
t[2].setFont(new Font("TimesRoman", Font.BOLD, 13));
t[2].setForeground(Color.red);
t[2].setEditable(false);
for (int i = 0; i < 4; i++)
c.add(t[i]);
c.add(b[0]);
c.add(b[1]);
for (int j = 4; j < 4; j++) {
c.add(t[j]);
t[j].setFont(new Font("TimesRoman", Font.BOLD, 13));
t[j].setForeground(Color.blue);
t[j].setEditable(false);
}
c.add(Label);
t[0].addActionListener(this);
t[2].addActionListener(this);
b[0].addActionListener(this);
b[1].addActionListener(this);
app.setVisible(true);
}
private Image getImage(String string) {
// TODO Auto-generated method stub
return null;
}
// 消息响应方法
public void actionPerformed(ActionEvent e) {
JButton source = (JButton) e.getSource();
if (source == b[0]) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(
"jdbc:sqlserver://127.0.0.1:1433;DatabaseName=宾馆客户数据库",
"root", "root");
System.out.println("数据库驱动程序注册成功!");
System.out.println("数据库连接成功!");
statement = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String s1 = t[1].getText();
String s2 = t[3].getText();
ResultSet resultset = statement
.executeQuery("select * from UsersInfo where Name='"
+ s1 + "'and Password='" + s2 + "'");
resultset.next();
Type = resultset.getInt("Type");
if (resultset != null) {
boo1 = boo2 = true;
resultset.close();
}
}
catch (Exception e1) {
JOptionPane.showMessageDialog(this, "用户名和密码不正确!", "警告",
JOptionPane.WARNING_MESSAGE);
// e1.printStackTrace();
}
if (boo1 && boo2 && Type == 1) {
Type = 0;
boo1 = boo2 = true;
new HoteMen(statement, "普通员工--" + t[1].getText());
// new StudentManager();
app.setVisible(false);
}
if (boo1 && boo2 && Type == 2) {
Type = 0;
boo1 = boo2 = true;
new HotelManagerMen(statement, "管理员--" + t[1].getText());
// new StudentManager();
app.setVisible(false);
}
}
// 如果单击"退出"按键,则退出登陆界面
if (source == b[1]) {
System.exit(0);
}
}
public static void main(String args[]) {
new HoteLand();
}
}
2. 客房管理管理页面的设计
客房管理管理页面主要是负责所有客房信息的维护。其中功能主要包括:录入客房信息,修改客房信息,查询客房信息,删除客房信息。他们的界面如3图所示。
图 3 客房管理管理页面
现在给出客房管理界面的主要代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class AddRooms extends JPanel implements ActionListener
{
Hashtable 基本信息表=null;
JTextField 房间号,房间位置;
JTextArea 描述;
JButton 录入,重置;
Choice 房间类型;
Statement statement=null;
JLabel 添加客房信息=null;
public AddRooms(Statement statement)
{
this.statement=statement;
房间号=new JTextField(10);
房间位置=new JTextField(10);
描述 =new JTextArea(7,10);
录入=new JButton("录入");
重置=new JButton("重置");
录入.addActionListener(this);
重置.addActionListener(this);
Box box0=Box.createHorizontalBox();
添加客房信息=new JLabel("--添加客房信息--",JLabel.CENTER);
添加客房信息.setFont(new Font("TimesRoman",Font.BOLD,25));
添加客房信息.setForeground(Color.red);
box0.add(添加客房信息);
Box box1=Box.createHorizontalBox();
box1.add(new JLabel("房间号:",JLabel.CENTER));
box1.add(房间号);
房间类型=new Choice();
房间类型.add("普通单人间");
房间类型.add("普通双人间");
房间类型.add("vip单人间");
房间类型.add("vip双人间");
房间类型.add("豪华贵宾间");
房间类型.add("总统套间");
Box box2=Box.createHorizontalBox();
box2.add(new JLabel("房间类型:",JLabel.CENTER));
box2.add(房间类型);
Box box3=Box.createHorizontalBox();
box3.add(new JLabel("房间位置:",JLabel.CENTER));
box3.add(房间位置);
Box box4=Box.createHorizontalBox();
box4.add(new JLabel("单价 :",JLabel.CENTER));
box4.add(new JScrollPane(描述),BorderLayout.CENTER);
Box boxH=Box.createVerticalBox();
boxH.add(box0);
boxH.add(box1);
boxH.add(box2);
boxH.add(box3);
boxH.add(box4);
boxH.add(Box.createVerticalGlue());
JPanel pCenter=new JPanel();
pCenter.add(boxH);
setLayout(new BorderLayout());
add(pCenter,BorderLayout.CENTER);
JPanel pSouth=new JPanel();
pSouth.add(录入);
pSouth.add(重置);
add(pSouth,BorderLayout.SOUTH);
validate();
}
public void actionPerformed(ActionEvent e)
{
ResultSet resultset=null;
boolean boo=false;
if(e.getSource()==录入)
{
int number=0;
try{
number=Integer.parseInt(房间号.getText().toString());
boo=true;
}
catch(Exception e1){
boo=false;
}
if(boo&&(number>0))
{
try{
resultset=statement.executeQuery("use 宾馆客户数据库;select * from RoomsInfo where RoomId='"+number+"'");
try{
resultset.next();
resultset.getInt("RoomId");
String warning="该客房信息已存在,请到修改页面修改!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
}
catch(Exception e1){
int RoomId=Integer.parseInt(房间号.getText().toString());
String RCategory=房间类型.getSelectedItem().toString();
String RPostion=房间位置.getText().toString();
String Description=描述.getText().toString();
String str="use 宾馆客户数据库;insert into RoomsInfo values("+RoomId+",'"+RCategory+"','"+RPostion+"','"+Description+"')";
try{
statement.executeUpdate(str);
statement.executeUpdate("use 宾馆客户数据库;insert into RoomStatus values("+RoomId+","+1+")");
JOptionPane.showMessageDialog(this,"成功录入客房信息!","提示",JOptionPane.WARNING_MESSAGE);
}
catch(Exception e2){
String warning="输入格式有误,请重新输入!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
e2.printStackTrace();
}
房间号.setText(null);
房间类型.select("普通单人间");
房间位置.setText(null);
描述.setText(null);
}
}
catch(Exception e1){
String warning="输入格式有误,请重新输入!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
}
}
else {
String warning="必须要输入房间号!";
JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
}
}
if(e.getSource()==重置)
{
房间号.setText(null);
房间类型.select("普通单人间");
房间位置.setText(null);
描述.setText(null);
}
}
}
3. 客房经营管理页面的设计
该页面主要是实现如下三个功能:客房使用情况,宾馆订房,宾馆退房。其的界面如图4所示。
图 4客房经营管理页面
现在给出客房经营管理页面的主要代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class UseOfRooms extends JPanel implements ActionListener
{
JButton 查询;
Choice 房间类型,状态;
Statement statement=null;
JTextArea 房间使用情况;
JLabel 客房使用情况=null;
public UseOfRooms(Statement statement)
{
this.statement=statement;
查询=new JButton("查询");
查询.addActionListener(this);
房间类型=new Choice();
房间类型.add("普通单人间");
房间类型.add("普通双人间");
房间类型.add("vip单人间");
房间类型.add("vip双人间");
房间类型.add("豪华贵宾间");
房间类型.add("总统套间");
状态=new Choice();
状态.add("有");
状态.add("否");
Box box0=Box.createHorizontalBox();
客房使用情况=new JLabel("--客房使用情况--",JLabel.CENTER);
客房使用情况.setFont(new Font("TimesRoman",Font.BOLD,25));
客房使用情况.setForeground(Color.red);
box0.add(客房使用情况);
Box box1=Box.createHorizontalBox();
box1.add(new JLabel("按房间类型:",JLabel.CENTER));
box1.add(房间类型);
Box box2=Box.createHorizontalBox();
box2.add(new JLabel("状态:",JLabel.CENTER));
box2.add(状态);
box2.add(查询);
Box box3=Box.createHorizontalBox();
box3.add(new JLabel("房间使用情况:",JLabel.CENTER));
Box box4=Box.createHorizontalBox();
box4.add(new JLabel("-客房号:"));
box4.add(new JLabel("-客房类型:"));
box4.add(new JLabel("-是否空房:"));
Box box5=Box.createHorizontalBox();
房间使用情况=new JTextArea(8,12);
房间使用情况.setFont(new Font("TimesRoman",Font.BOLD,15));
房间使用情况.setForeground(Color.red);
房间使用情况.setEditable(false);
box5.add(new JScrollPane(房间使用情况),BorderLayout.CENTER);
Box boxH=Box.createVerticalBox();
boxH.add(box0);
boxH.add(box1);
boxH.add(box2);
boxH.add(box3);
boxH.add(box4);
boxH.add(box5);
boxH.add(Box.createVerticalGlue());
JPanel pCenter=new JPanel();
pCenter.add(boxH);
setLayout(new BorderLayout());
add(pCenter,BorderLayout.CENTER);
validate();
}
public void actionPerformed(ActionEvent e)
{ int i=1;
ResultSet resultset=null;
String string="";
if(e.getSource()==查询){
String str=房间类型.getSelectedItem().toString();
String str1=状态.getSelectedItem();
if(str1.equals("有")){
i=2;
}
else i=1;
String str2="use 宾馆客户数据库;select RoomsInfo.RoomId,RCategory,RoomStatus.Status from RoomsInfo,RoomStatus where RoomsInfo.RoomId=RoomStatus.RoomId and Status="+i+" and RCategory='"+str+"'";
try{
resultset=statement.executeQuery(str2);
while(resultset.next()){
string+=resultset.getInt(1)+", "+resultset.getString(2)+", "+str1+"\n";
}
if(string==""){
房间使用情况.setText("没有要找的客房!");
}
else
房间使用情况.setText(string);
}
catch(Exception e1){
e1.printStackTrace();
}
}
}
}
4. 客户信息查询页面的设计
该页面主要是实现客户信息查询功能。界面如图5所示。
图5 客户信息查询页面
现在给出客户信息查询页面主要代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class CustomerInformation extends JPanel implements ActionListener
{
JTextField 姓名;
JTextArea 查询结果;
JButton 查询,查询所有;
Statement statement=null;
JLabel 客户信息查询;
public CustomerInformation(Statement statement)
{
this.statement=statement;
姓名=new JTextField(10);
查询=new JButton("查询");
查询所有=new JButton("查询所有");
姓名.addActionListener(this);
查询.addActionListener(this);
查询所有.addActionListener(this);
查询结果=new JTextArea(8,10);
查询结果.setEditable(false);
查询结果.setFont(new Font("TimesRoman",Font.BOLD,15));
查询结果.setForeground(Color.blue);
Box box0=Box.createHorizontalBox();
客户信息查询=new JLabel("--客户信息查询--",JLabel.CENTER);
客户信息查询.setFont(new Font("TimesRoman",Font.BOLD,25));
客户信息查询.setForeground(Color.red);
box0.add(客户信息查询);
Box box1=Box.createHorizontalBox();
box1.add(new JLabel("输入要查询的姓名:",JLabel.CENTER));
box1.add(姓名);
box1.add(查询);
Box box2=Box.createHorizontalBox();
box2.add(new JLabel("查询结果:",JLabel.CENTER));
box2.add(new JScrollPane(查询结果),BorderLayout.CENTER);
Box box3=Box.createHorizontalBox();
box3.add(查询所有);
Box boxH=Box.createVerticalBox();
boxH.add(box0);
boxH.add(box1);
boxH.add(box2);
boxH.add(box3);
boxH.add(Box.createVerticalGlue());
JPanel pCenter=new JPanel();
pCenter.add(boxH);
setLayout(new BorderLayout());
add(pCenter,BorderLayout.CENTER);
validate();
}
public void actionPerformed(ActionEvent e)
{
ResultSet resultset=null;
boolean boo=false;
String CName="",CIdentityId="",CPhone="",CRoom,BeginTime,Remarks;
String str="",chk;
if(e.getSource()==查询)
{ CName=姓名.getText().toString();
if(!CName.equals(""))
{
try{
chk="use 宾馆客户数据库;select * from CustomersInfo,RoomOperation where CustomersInfo.CIdentityId=RoomOperation.CIdentityId and CName='"+CName+"'";
resultset=statement.executeQuery(chk);
resultset.next();
CIdentityId=resultset.getString("CIdentityId");
CPhone=resultset.getString("CPhone");
CRoom=resultset.getString("RoomId");
BeginTime=resultset.getString("BeginTime");
Remarks=resultset.getString("Remarks");
str="客房号:"+CRoom+"\n身份证号码:"+CIdentityId+"\n客户姓名:"+CName+"\n电话:"+CPhone+"\n订房时间:"+BeginTime+"\n备注:"+Remarks+"\n";
查询结果.setText(str);
}
catch(Exception e1){
String warning="该客房信息不存在!";
查询结果.setText(warning);
JOptionPane.showMessageDialog(this,warning,
"警告",JOptionPane.WARNING_MESSAGE);
}
}
else{
Stri
展开阅读全文