E-R图
数据库搭建
功能模块
1.首先要通过 JAVA 代码连接数据库,通过 jdbc 插件
2.设计主菜单、子菜单,里面内容是管理酒店的各种操作,我会设置相应的功能模块完成操作。
3.要使这个系统能够持续运行且可以选择相应的功能模块,需要设计一个主控制函数,这个函数通过一个 while 循环持续运行,操作者输入 1、2、3。。。来选择相应的功能实现。
难点:如果操作者需要从子菜单返回到主菜单,需要编写一个能使操作者输入数字就能返回的功能,我们可以设置一个 flag 变量,每次循环时刷新为 1
while( true)
{
flag = 1;
子菜单在 flag=1 的时候才能运行,在 switch 语句里面,如果操作者输入 4,令 flag=0,
while(flag == 1)
{
menu3();//客房管理菜单
System. out .println("\t\t请输入选项:");
x = scan.nextInt();
switch(x)
{
case 1:b.increase_room(); break;//增加客房
case 2:b.decrease_room(); break;//减少客房
case 3:flag = 0; break;//返回
case 4:b.change_roomprice(); break;//修改房价
case 5:b.change_roomtype(); break;//修改房型
}
}
那么这个子菜单循环就结束了,就可以直接返回到主菜单的大循环里。
4.顾客登记模块,在这个模块里,我们要输入顾客的姓名、身份证号、电话、性别、订单号、房间号,然后把这些数据通过 sql 的 insert value 语句插入到数据库中,然后还需要生成订单,会继续输入入住天数、房间类型、订房数量,然后插入数据库中。
难点:入住时间设置为当前操作的时间
String sql3 = "select CONVERT(varchar, getdate(), 120 ) 当前时间";
rs=st.executeQuery(sql3);
while(rs.next())
{
time = rs.getString("当前时间");
}
通过 sql 语句获得当前时间,然后使 time 变量等于当前时间插入订单表的入住时间中。
5.团体登记的功能,团体登记需要输入团体名、团体号、团体电话、团体人数、
订单号然后插入到团体登记表中,然后通过输入的团体人数决定登记顾客的人数,然后循环顾客登记的模块,将团体中的成员录入顾客登记表中,最后调用生成订单模块生成订单。
难点:
String sql2 = "update 房间信息 set 是否入住 = '是' where 房间号 = '"+roomnum1+"'";
顾客登记后意味着房间已入住,所以房间信息表中是否入住这一属性也要相应的更改,通过这条 sql 语句即可实现
6.设计客房管理,客房管理有多项内容,我们创建了一个子菜单,里面有查询可用房间模块,增减客房、更改房价、更改房型。
7.可用房间模块通过 sql 语句查询是否入住属性为“否”的所有房间信息
rs=st.executeQuery("select * from 房间信息 where 是否入住 = '否' ");
while (rs.next())
{
System. out .println("房间号: "+rs.getString("房间号") + " 房间类型: " +
rs.getString("房间类型")
- " 房间价格: " + rs.getString("房间价格"));
}
通过 while 循环 rs.next()来遍历表中所有内容打印出来。
8.增加客房模块,首先要输入增加数量,然后把增加的操作放到 for 循环里,循环增加数量次,输入增加的房型,房价,新的房间号然后插入房间信息表中。
9.减少客房模块,只需要输入需删除的房间号,然后用 sql delete 语句删除即可。
10.更改房价模块,输入要更改的房型,然后输入修改后的房价,然后用 sql update 语句更新房间即可。
11.更改房间类型模块,输入要更改的房间号,然后输入修改后的房型,然后用 sql update 语句更新即可。
12.设置登录模块
int login(String id,String psw)
实现管理员登录的操作,只有管理员才能进入客房管理和设置模块,登录模块要用到操作员信息表找到操作员 ID 和密码,与输入的 ID 和密码进行比较,看是否相等,相等则可进入相应界面。
13.设计设置,设置也有子菜单,包括修改密码,添删用户,实现比较简单,通过 sql 语句的增删改即可。
14.退房功能,分为顾客退房和团体退房
顾客退房:顾客只需输入身份证号即可完成退房,然后通过查询语句找到身份证号所对应的房间号,取得房间号,再把对应房间号的是否入住改为“否”,然后通过等值连接订单和顾客登记表,通过身份证号找到订单总金额,打印输出。
团体退房:与顾客退房相似,区别在于需输入团体号和退房数量,根据退房数量循环改是否入住属性,然后查询语句得到总金额打印输出。
15.查询界面设计
有查询所有顾客、所有团体、所有订单、根据姓氏查询顾客、根据身份证号查询顾客、根据团体号查询顾客、根据顾客电话查询顾客的房间类型,这些所有功能模块都只需相应的 sql 语句,查询到结果,打印输出。
代码部分
import java.sql.*;
import java.util.Scanner;
import java.util.Vector;
public class databaseConnect {
private String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=宾馆客房管理系统";
private String userName="sa";
private String userPwd="qzt1220796416";
private Connection ct=null;
private ResultSet rs=null;
private Statement st;
static int number = 0;
public void mainmenu()//主菜单
{
System.out.println("\n\n");
System.out.println("\t\t* * * * * * 酒店管理系统 * * * * * *\n");
System.out.println("\t\t* 1.:顾客登记 *\n");
System.out.println("\t\t* 2.:团体登记 *\n");
System.out.println("\t\t* 3.:客房管理 *\n");
System.out.println("\t\t* 4.:设置 *\n");
System.out.println("\t\t* 5.:查询 *\n");
System.out.println("\t\t* 6.:退房 *\n");
System.out.println("\t\t* * * * * * * * * * * * * * * * * * * *\n\n");
}
public void menu5()//查询
{
System.out.println("\n\n");
System.out.println("\t\t* * * * * * 酒店管理系统 * * * * * *\n");
System.out.println("\t\t* 1.:所有顾客 *\n");
System.out.println("\t\t* 2.:所有团体 *\n");
System.out.println("\t\t* 3.:所有订单 *\n");
System.out.println("\t\t* 4.:返回 *\n");
System.out.println("\t\t* 5.:根据姓氏查询顾客 *\n");
System.out.println("\t\t* 6.:根据身份证号查询顾客 *\n");
System.out.println("\t\t* 7.:根据团体号查询团体信息 *\n");
System.out.println("\t\t* 8.:根据顾客电话查询顾客的房间类型 *\n");
System.out.println("\t\t* 9.:可用房间 *\n");
System.out.println("\t\t* * * * * * * * * * * * * * * * * * * *\n\n");
}
public void menu6()//退房
{
System.out.println("\n\n");
System.out.println("\t\t* * * * * * 酒店管理系统 * * * * * *\n");
System.out.println("\t\t* 1.:顾客退房 *\n");
System.out.println("\t\t* 2.:团体退房 *\n");
System.out.println("\t\t* 3.:返回 *\n");
System.out.println("\t\t* * * * * * * * * * * * * * * * * * * *\n\n");
}
public void menu3()//客房管理
{
System.out.println("\n\n");
System.out.println("\t\t* * * * * * 酒店管理系统 * * * * * *\n");
System.out.println("\t\t* 1.:增加客房 *\n");
System.out.println("\t\t* 2.:减少客房 *\n");
System.out.println("\t\t* 3.:返回 *\n");
System.out.println("\t\t* 4.:更改房价 *\n");
System.out.println("\t\t* 5.:更改房间类型 *\n");
System.out.println("\t\t* * * * * * * * * * * * * * * * * * * *\n\n");
}
public void menu4()//设置
{
System.out.println("\n\n");
System.out.println("\t\t* * * * * * 酒店管理系统 * * * * * *\n");
System.out.println("\t\t* 1.:修改密码 *\n");
System.out.println("\t\t* 2.:添加用户 *\n");
System.out.println("\t\t* 3.:删除用户 *\n");
System.out.println("\t\t* 4.:返回 *\n");
System.out.println("\t\t* * * * * * * * * * * * * * * * * * * *\n\n");
}
public void search_roomtype() throws Exception//根据顾客电话查询房间类型
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入顾客的手机号");
String num = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "select 房间类型 from 顾客登记,订单 where 顾客登记.订单号=订单.订单号 and 顾客电话 = '"+num+"'";
rs = st.executeQuery(sql);
while (rs.next())
{
System.out.println("房间类型:"+rs.getString("房间类型") );
}
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void search_group() throws Exception//根据团体号查询团体信息
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入您想查询团体的团体号:");
String num = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "select * from 团体登记 where 团体号 = '"+num+"'";
rs = st.executeQuery(sql);
while (rs.next())
{
System.out.println("团体名:"+rs.getString("团体名") + "\n团体号:" + rs.getString("团体号")
+ "\n团体电话:" + rs.getString("团体电话")+ "\n团体人数:" + rs.getString("团体人数")+ "\n订单号:" + rs.getString("订单号"));
}
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void search_customer2() throws Exception//根据姓氏查询顾客
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入您想查询顾客的姓");
String name1 = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "select * from 顾客登记 where 顾客姓名 like '"+name1+"%'";
rs = st.executeQuery(sql);
while (rs.next())
{
System.out.println("顾客姓名:"+rs.getString("顾客姓名") + "\n顾客身份证号:" + rs.getString("顾客身份证号")
+ "\n顾客电话:" + rs.getString("顾客电话")+ "\n顾客性别:" + rs.getString("顾客性别")+ "\n订单号:" + rs.getString("订单号"));
}
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void search_customer1() throws Exception//根据身份证号查询顾客
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入您想查询顾客的身份证号");
String ID = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "select * from 顾客登记 where 顾客身份证号 = '"+ID+"'";
rs = st.executeQuery(sql);
while (rs.next())
{
System.out.println("顾客姓名:"+rs.getString("顾客姓名") + "\n顾客身份证号:" + rs.getString("顾客身份证号")
+ "\n顾客电话:" + rs.getString("顾客电话")+ "\n顾客性别:" + rs.getString("顾客性别")+ "\n订单号:" + rs.getString("订单号"));
}
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void change_roomprice() throws Exception//更改房价
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入您想更改的房型");
String roomtype = scan.next();
System.out.println("请输入修改后的房价");
int price = scan.nextInt();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "update 房间信息 set 房间价格 = "+price+" where 房间类型 = '"+roomtype+"'";
st.executeUpdate(sql);
System.out.println("修改成功");
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void change_roomtype() throws Exception//更改房间类型
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入您想更改的房间号");
String roomnum = scan.next();
System.out.println("请输入您想更改的房型");
String roomtype = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "update 房间信息 set 房间类型 = '"+roomtype+"' where 房间号 = '"+roomnum+"'";
st.executeUpdate(sql);
System.out.println("修改成功");
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void show_group() throws Exception//所有团体
{
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
rs=st.executeQuery("select * from 团体登记");
while (rs.next())
{
System.out.println("团体名: "+rs.getString("团体名") + " 团体号: " + rs.getString("团体号")
+ " 团体电话: " + rs.getString("团体电话")+ " 团体人数: " + rs.getInt("团体人数")+ " 订单号: " + rs.getString("订单号"));
}
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void show_customer() throws Exception//所有顾客
{
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
rs=st.executeQuery("select * from 顾客登记");
while (rs.next())
{
System.out.println("顾客姓名: "+rs.getString("顾客姓名") + " 顾客身份证号: " + rs.getString("顾客身份证号")
+ " 顾客电话: " + rs.getString("顾客电话")+ " 顾客性别: " + rs.getString("顾客性别")+ " 订单号: " + rs.getString("订单号"));
}
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void show_order() throws Exception//所有订单
{
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
rs=st.executeQuery("select * from 订单");
while (rs.next())
{
System.out.println("订单号: "+rs.getString("订单号") + " 入住天数: " + rs.getInt("入住天数")
+ " 房间类型: " + rs.getString("房间类型")+ " 订房数量: " + rs.getInt("订房数量")+ " 总金额: " + rs.getInt("总金额")
+ " 入住时间: " + rs.getString("入住时间")+ " 房间号: " + rs.getString("房间号"));
}
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void group_exit() throws Exception//团体退房
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入团体号");
String ID = scan.next();
System.out.println("请输入需要退的房间数量");
int num = scan.nextInt();
for(int i=0;i<num;i++)
{
System.out.println("请输入房间号");
String number = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "update 房间信息 set 是否入住 = '否' where 房间号 = '"+number+"'";
st.executeUpdate(sql);
}
String sql2 = "select 总金额 from 订单,团体登记 where 订单.订单号 = 团体登记.订单号 and 团体号 = '"+ID+"'";
rs=st.executeQuery(sql2);
while (rs.next())
{
System.out.println("顾客需支付金额为: "+rs.getString("总金额"));
}
System.out.println("离店操作成功");
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void customer_exit() throws Exception//顾客退房
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入顾客身份证号");
String ID = scan.next();
String number=null;
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
rs=st.executeQuery("select 房间号 from 顾客登记 where 顾客身份证号 = '"+ID+"'");
while (rs.next())
{
number = rs.getString("房间号");
}
String sql = "update 房间信息 set 是否入住 = '否' where 房间号 = '"+number+"'";
String sql2 = "select 总金额 from 订单,顾客登记 where 订单.订单号 = 顾客登记.订单号 and 顾客身份证号 = '"+ID+"'";
st.executeUpdate(sql);
rs=st.executeQuery(sql2);
while (rs.next())
{
System.out.println("顾客需支付金额为: "+rs.getString("总金额"));
}
System.out.println("离店操作成功");
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void change_psw() throws Exception//修改密码
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入操作员ID");
String ID = scan.next();
System.out.println("请输入新的密码");
String number = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "update 操作员信息 set 密码 = '"+number+"' where 操作员ID = '"+ID+"'";
st.executeUpdate(sql);
System.out.println("修改密码成功");
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void add_user() throws Exception//添加用户
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入新的操作员ID");
String ID = scan.next();
System.out.println("请输入密码");
String number = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "insert into 操作员信息 values"+"('"+ID+"','"+number+"')";
st.executeUpdate(sql);
System.out.println("添加用户成功");
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void delete_user() throws Exception//删除用户
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入需要删除的操作员ID");
String ID = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "delete from 操作员信息 where 操作员ID = '"+ID+"'";
st.executeUpdate(sql);
System.out.println("删除成功");
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void increase_room() throws Exception//增加客房
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入增加客房数量");
int roomnum = scan.nextInt();
for(int i = 0; i<roomnum; i++)
{
System.out.println("请输入增加客房的房型");
String roomtype = scan.next();
System.out.println("请输入房间价格");
int price = scan.nextInt();
System.out.println("请输入新的房间号");
String number = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "insert into 房间信息 values"+"('"+number+"','"+roomtype+"','否',"+price+")";
st.executeUpdate(sql);
System.out.println("添加成功");
}
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void decrease_room() throws Exception//减少客房
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入需要删除的房间号");
String number = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "delete from 房间信息 where 房间号 = '"+number+"'";
st.executeUpdate(sql);
System.out.println("删除成功");
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void creat_order(String order) throws Exception//生成订单
{
Vector<Object> data=new Vector<Object>();
int total_price=0;
Scanner scan=new Scanner(System.in);
System.out.println("请输入入住天数");
int days = scan.nextInt();
System.out.println("请输入房间类型");
String roomtype = scan.next();
System.out.println("请输入订房数量");
int roomnum = scan.nextInt();
String time=null;
System.out.println("请输入房间号");
String roomnumber = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
rs=st.executeQuery("select 房间价格 from 房间信息 where 房间类型 = '"+roomtype+"'");
while(rs.next())
{
total_price = days*roomnum *rs.getInt("房间价格");
}
String sql3 = "select CONVERT(varchar, getdate(), 120 ) 当前时间";
rs=st.executeQuery(sql3);
while(rs.next())
{
time = rs.getString("当前时间");
}
String sql = "insert into 订单 values"+"('"+order+"',"+days+",'"+
roomtype+"',"+roomnum+","+total_price+",'"+time+"','"+roomnumber+"')";
st.executeUpdate(sql);
System.out.println("订单生成成功");
}
public void group_sign() throws Exception//团体登记
{
databaseConnect g = new databaseConnect();
Scanner scan=new Scanner(System.in);
System.out.println("请输入团体名");
String name = scan.next();
System.out.println("请输入团体号");
String pID = scan.next();
System.out.println("请输入团体电话");
String phonenum = scan.next();
System.out.println("请输入团体人数");
int people = scan.nextInt();
System.out.println("请输入订单号");
String order = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "insert into 团体登记 values"+"('"+name+"','"+pID+"','"+phonenum+"',"+people+",'"+order+"')";
st.executeUpdate(sql);
for(int i = 0; i<people; i++)
{
System.out.println("第"+(i+1)+"位客人");
System.out.println("请输入您的姓名");
String name1 = scan.next();
System.out.println("请输入您的身份证号");
String pID1 = scan.next();
System.out.println("请输入您的电话");
String phonenum1 = scan.next();
System.out.println("请输入您的性别");
String gender = scan.next();
System.out.println("请输入订单号");
String order1 = scan.next();
System.out.println("请输入房间号");
String roomnum1 = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql1 = "insert into 顾客登记 values"+"('"+name1+"','"+pID1+"','"+phonenum1+"','"+gender+"','"+order1+"','"+roomnum1+"')";
st.executeUpdate(sql1);
String sql2 = "update 房间信息 set 是否入住 = '是' where 房间号 = '"+roomnum1+"'";
st.executeUpdate(sql2);
System.out.println("登记成功");
}
g.creat_order(order);//生成订单
System.out.println("团体登记成功");
ct.commit();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void sign() throws Exception//顾客登记
{
databaseConnect f = new databaseConnect();
Scanner scan=new Scanner(System.in);
System.out.println("请输入您的姓名");
String name = scan.next();
System.out.println("请输入您的身份证号");
String pID = scan.next();
System.out.println("请输入您的电话");
String phonenum = scan.next();
System.out.println("请输入您的性别");
String gender = scan.next();
System.out.println("请输入订单号");
String order = scan.next();
System.out.println("请输入房间号");
String roomnum = scan.next();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
String sql = "insert into 顾客登记 values"+"('"+name+"','"+pID+"','"+phonenum+"','"+gender+"','"+order+"','"+roomnum+"')";
st.executeUpdate(sql);
String sql1 = "update 房间信息 set 是否入住 = '是' where 房间号 = '"+roomnum+"'";
st.executeUpdate(sql1);
Vector<Object> data=new Vector<Object>();
int total_price=0;
System.out.println("请输入入住天数");
int days = scan.nextInt();
System.out.println("请输入房间类型");
String roomtype = scan.next();
System.out.println("请输入订房数量");
int roomnum1 = scan.nextInt();
String time = null;
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
rs=st.executeQuery("select 房间价格 from 房间信息 where 房间类型 = '"+roomtype+"'");
while(rs.next())
{
total_price = days*roomnum1 *rs.getInt("房间价格");
}
String sql3 = "select CONVERT(varchar, getdate(), 120 ) 当前时间";
rs=st.executeQuery(sql3);
while(rs.next())
{
time = rs.getString("当前时间");
}
String sql2 = "insert into 订单 values"+"('"+order+"',"+days+",'"+
roomtype+"',"+roomnum1+","+total_price+",'"+time+"',"+roomnum+")";
st.executeUpdate(sql2);
System.out.println("订单生成成功");
System.out.println("登记成功");
ct.commit();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public int login(String id,String psw) throws Exception//登录系统
{
Vector<Object> data1=new Vector<Object>();
Vector<Object> data2=new Vector<Object>();
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
rs=st.executeQuery("select * from 操作员信息");
while(rs.next())
{
data1.add(rs.getString(1));
data2.add(rs.getString(2));
}
for(int i = 0; i < data1.size(); i++)
{
if(id.equals(data1.elementAt(i)) && psw.equals(data2.elementAt(i)))
{
System.out.println("登录成功");
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
return 1;
}
}
System.out.println("登录失败");
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
return 0;
}
public void available_rooms() throws Exception//可用房间
{
Class.forName(driverName);
ct=DriverManager.getConnection(dbURL,userName,userPwd);
st=ct.createStatement();
rs=st.executeQuery("select * from 房间信息 where 是否入住 = '否' ");
while (rs.next())
{
System.out.println("房间号: "+rs.getString("房间号") + " 房间类型: " + rs.getString("房间类型")
+ " 房间价格: " + rs.getString("房间价格"));
}
if(rs!=null)
rs.close();
if(st!=null)
st.close();
if(ct!=null)
ct.close();
}
public void maincontrol() throws Exception//主控制函数
{
databaseConnect b = new databaseConnect();
int x1,x;
int flag;
Scanner scan=new Scanner(System.in);
while(true)
{
flag = 1;
mainmenu();//首页菜单
System.out.println("\t\t请输入选项:");
x1 = scan.nextInt();
if(x1==1)//顾客登记
{
b.sign();
}
else if(x1==2)//团体登记
{
b.group_sign();
}
else if(x1==3)//客房管理
{
System.out.println("请输入您的ID:");
String id = scan.next();
System.out.println("请输入您的密码:");
String psw = scan.next();
if(b.login(id, psw) == 1)
{
while(flag == 1)
{
menu3();//客房管理菜单
System.out.println("\t\t请输入选项:");
x = scan.nextInt();
switch(x)
{
case 1:b.increase_room();break;//增加客房
case 2:b.decrease_room();break;//减少客房
case 3:flag = 0;break;//返回
case 4:b.change_roomprice();break;//修改房价
case 5:b.change_roomtype();break;//修改房型
}
}
}
}
else if(x1==4)//设置
{
System.out.println("请输入您的ID:");
String id = scan.next();
System.out.println("请输入您的密码:");
String psw = scan.next();
if(b.login(id, psw) == 1)
{
while(flag == 1)
{
menu4();//设置菜单
System.out.println("\t\t请输入选项:");
x = scan.nextInt();
switch(x)
{
case 1:b.change_psw();break;//修改密码
case 2:b.add_user();break;//添加用户
case 3:b.delete_user();break;//删除用户
case 4:flag = 0;break;//返回
}
}
}
}
else if(x1==5)//查询
{
while(flag == 1)
{
menu5();//查询菜单
System.out.println("\t\t请输入选项:");
x = scan.nextInt();
switch(x)
{
case 1:b.show_customer();break;//所有顾客
case 2:b.show_group();break;//所有团体
case 3:b.show_order();break;//所有订单
case 4:flag = 0;break;//返回
case 5:b.search_customer2();break;//根据姓氏查询顾客
case 6:b.search_customer1();break;//根据身份证号查询顾客
case 7:b.search_group();break;//根据团体号查询团体
case 8:b.search_roomtype();break;//根据顾客电话查询房间类型
case 9:b.available_rooms();break;//预定客房或登记入住
}
}
}
else if(x1==6)//退房
{
while(flag == 1)
{
menu6();//退房菜单
System.out.println("\t\t请输入选项:");
x = scan.nextInt();
switch(x)
{
case 1:b.customer_exit();break;//顾客退房
case 2:b.group_exit();break;//团体退房
case 3:flag = 0;break;//返回
}
}
}
}
}
public static void main(String[] args) throws Exception
{
databaseConnect a = new databaseConnect();
a.maincontrol();//进入主控制函数;
}
}
版权归原作者 你是我的神111 所有, 如有侵权,请联系我们删除。