基于javaSwing、MySQL的酒店客房管理系统(附源码)
该系统实现对酒店管理的基本操作:酒店客房信息添加、修改、删除、查询;客房入住、退订功能:顾客信息的录入、保存、显示;
由于近期询要的人过多,自行加群769119544领取源码
目录
集成开发环境:IntelliJ IDEA (2020); 使用插件:Jform Designer; 数据库:MySQL 8.0;适用
课程设计,大作业,项目练习,学习演示等
一、功能需求
1、住户信息维护
浏览所有住户的信息。包括入住时间、退房时间、身份证号、入住客房编号等等,提供了增删改查等功能;
2、客房信息维护
浏览所有客房信息。包括房间编号、房间描述、房间空闲状态等。还需要添加新客房、删除房间、修改房间信息等功能。
3、客房查询功能
通过客房编号、客房名称直接搜索到相关客房的信息;
4、账号管理功能
管理员可以对账号进行注册、修改密码等操作;
二、数据字典
1.数据流条目
(1)数据流名:登录信息
数据流来源:管理员
数据流去向:管理系统
数据流组成:用户名+用户密码
(2)数据流名:预订信息
数据流来源:旅客
数据流去向:管理系统
数据流组成:房间编号+入住人姓名+入住人身份证号+订房日期+入住天数
(3)数据流名:客房状态
数据流来源:客房状态表
数据流去向:管理系统
数据流组成:房间当前状态
(4)数据流名:退房请求
数据流来源:旅客
数据流去向:管理系统
数据流组成:入住人姓名+入住人身份证号+状态描述
2.文件条目
(1)数据文件名:管理员表
简述:记录用户信息
文件内容:管理员表=用户名+用户密码
(2)数据文件名:入住信息
简述:存放顾客入住信息
文件内容:顾客编号+顾客姓名+顾客身份证号+入住房间号+预定日期+退房时间+入住天数
(3)数据文件名:客房信息
简述:记录客房信息
文件内容:房间编号+房间类型+房间描述+房间状态编号+房间位置
(4)数据文件名:客房类型
简述:存放客房类型信息
文件内容:客房类型编号+客房类型名称+客房标准面积+客房标准床位+标准收费+类型描述
(5)数据文件名:客房状态
简述:存放客房状态
文件内容:房间编号+房间状态
三、用例图
四、数据流图
五、E-R图
六、系统框架
七、数据库设计
1.房间信息表(room)
2.入住信息表(roomIn)
3.管理员信息表
八、界面设计
九、代码展示
1、数据表对象层(domain层)
1.1、房间对象初始化
public class Room {
private String roomid;//房间编号
private String housename;//名称
private String homeloc;//位置
private int housecoast;//标准收费
private String housesnull;//客房空闲情况
private String housesclean;//客房清洁状况
private String housesdesc;//类型描述
public Room() {
}
public Room(String roomid, String housename, String homeloc, int housecoast, String housesnull, String housesclean, String housesdesc) {
this.roomid = roomid;
this.housename = housename;
this.homeloc = homeloc;
this.housecoast = housecoast;
this.housesnull = housesnull;
this.housesclean = housesclean;
this.housesdesc = housesdesc;
}
public String getRoomid() {
return roomid;
}
public void setRoomid(String roomid) {
this.roomid = roomid;
}
public String getHousename() {
return housename;
}
public void setHousename(String housename) {
this.housename = housename;
}
public String getHomeloc() {
return homeloc;
}
public void setHomeloc(String homeloc) {
this.homeloc = homeloc;
}
public int getHousecoast() {
return housecoast;
}
public void setHousecoast(int housecoast) {
this.housecoast = housecoast;
}
public String getHousesnull() {
return housesnull;
}
public void setHousesnull(String housesnull) {
this.housesnull = housesnull;
}
public String getHousesclean() {
return housesclean;
}
public void setHousesclean(String housesclean) {
this.housesclean = housesclean;
}
public String gethousesdesc() {
return housesdesc;
}
public void sethousesdesc(String housesdesc) {
this.housesdesc = housesdesc;
}
@Override
public String toString() {
return "Room{" +
"roomid='" + roomid + '\'' +
", housename='" + housename + '\'' +
", homeloc='" + homeloc + '\'' +
", housecoast=" + housecoast +
", housesnull='" + housesnull + '\'' +
", housesclean='" + housesclean + '\'' +
", housesdesc='" + housesdesc + '\'' +
'}';
}
}
1.2、旅客对象初始化
public class RoomIn {
private String username;
private String idcard;
private String roomId;
private String datain;
private String dataout;
private int dataNum;
public String getRoomId() {
return roomId;
}
public void setRoomId(String roomId) {
this.roomId = roomId;
}
public RoomIn() {
}
public RoomIn(String username, String idcard,String roomId, String datain, String dataout, int dataNum) {
this.username = username;
this.idcard = idcard;
this.datain = datain;
this.dataout = dataout;
this.dataNum = dataNum;
this.roomId=roomId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getIdcard() {
return idcard;
}
public void setIdcard(String idcard) {
this.idcard = idcard;
}
public String getDatain() {
return datain;
}
public void setDatain(String datain) {
this.datain = datain;
}
public String getDataout() {
return dataout;
}
public void setDataout(String dataout) {
this.dataout = dataout;
}
public int getdataNum() {
return dataNum;
}
public void setdataNum(int dataNum) {
this.dataNum = dataNum;
}
@Override
public String toString() {
return "RoomIn{" +
"username='" + username + '\'' +
", idcard='" + idcard + '\'' +
", roomId='" + roomId + '\'' +
", datain=" + datain +
", dataout=" + dataout +
", dataNum=" + dataNum +
'}';
}
}
1.3、 管理员对象初始化
public class User {
private String id;
private String password;
public User() {
}
public User(String id, String password) {
this.id = id;
this.password = password;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "User{" +
"id='" + id + '\'' +
", password='" + password + '\'' +
'}';
}
}
2、数据访问对象层(dao层)
2.1、房间相关信息
import com.keshe.domain.Room;
import com.keshe.util.DBUtil;
import java.util.List;
public class RoomDao {
//插入房间信息
public int insert(Room rm){
String sql ="insert room values(?,?,?,?,?,?,?)";
int count= DBUtil.update(sql,rm.getRoomid(),rm.getHousename(),rm.getHomeloc(),rm.getHousecoast(),rm.getHousesnull(),rm.getHousesclean(),rm.gethousesdesc());
return count;
}
//显示房间信息
public List<Room> select(){
String sql="select * from room";
List<Room> ri =DBUtil.query(sql,Room.class);
return ri;
}
//根据id查询房间用于删除数据
public List<Room> selectId(String roomid ){
String sql="select * from room where roomid=?";
List<Room> ri =DBUtil.query(sql,Room.class,roomid);
return ri;
}
//根据房间名查询房间
public List<Room> selectName(String housesname ){
String sql="select * from room where housename=?";
List<Room> ri =DBUtil.query(sql,Room.class,housesname);
return ri;
}
//根据id删除数据
public int delete(String id){
String sql="delete from room where roomid=?";
int count=DBUtil.update(sql,id);
return count;
}
//根据id修改数据
public int update(String id,String housename,String homeloc,int housecoast,String housesnull,String housesclean,String housesdesc){
String sql="update room set housename=?,homeloc=?,housecoast=?,housesnull=?,housesclean=?,housesdesc=? where roomid=?";
int count= DBUtil.update(sql,housename,homeloc,housecoast,housesnull,housesclean,housesdesc,id);
return count;
}
//根据id修改房间空闲状态
public int updateId(String id,String housesnull){
String sql="update room set housesnull=?where roomid=?";
int count= DBUtil.update(sql,housesnull,id);
return count;
}
}
2.2、旅客信息
import com.keshe.domain.RoomIn;
import com.keshe.util.DBUtil;
import java.util.List;
public class RoomInDao {
//插入入住信息
public int insert(RoomIn ri){
String sql="insert roomIn(username,idcard,roomId,datain,dataout,dataNum) values (?,?,?,?,?,?)";
int count= DBUtil.update(sql,ri.getUsername(),ri.getIdcard(),ri.getRoomId(),ri.getDatain(),ri.getDataout(),ri.getdataNum());
return count;
}
//修改入住天数
public int uptateDateNum(int dataNum,String idcard){
String sql="uptate roomIn set dataNum=? where username=?";
int count=DBUtil.update(sql,dataNum,idcard);
return count;
}
//修改退房日期(退房)
public int updateDateout(String dateout,String idcard)
{
String sql="update roomIn set dataout=? where idcard=?";
int count=DBUtil.update(sql,dateout,idcard);
return count;
}
//删除入住信息
public int delete(String idcard){
String sql="delete from roomIn where idcard=?";
int count=DBUtil.update(sql,idcard);
return count;
}
//查看入住名单
public List<RoomIn> select(){
String sql="select * from roomIn";
List<RoomIn> ri =DBUtil.query(sql,RoomIn.class);
return ri;
}
//根据姓名查询入住名单信息
public List<RoomIn> selectUserName(String username){
String sql="select * from roomIn where username=?";
List<RoomIn> ri =DBUtil.query(sql,RoomIn.class,username);
return ri;
}
}
2.3、管理员信息
import com.keshe.domain.User;
import com.keshe.util.DBUtil;
import java.util.List;
public class UserDao {
//添加账号至数据库
public int insertUSer(User user){
String sql="insert user values(?,?)";
int count= DBUtil.update(sql,user.getId(),user.getPassword());//返回影响数据数目
return count;
}
//查询
public List<User> selectId(String id){
String sql = "select * from user where id=?";
List<User> list=DBUtil.query(sql,User.class,id);
return list;
}
//修改密码
public int updateUser(String id,String passworld){
String sql="update user set password=? where id=?";
int count= DBUtil.update(sql,passworld,id);
return count;
}
}
3、util包
3.1、JDBC交互数据库(DBUtil)
import com.keshe.domain.Room;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class DBUtil {
//数据库用户名
private static final String USERNAME = "root";
//数据库密码
private static final String PASSWORD = "root456";
//驱动信息
private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
//数据库地址
private static final String URL = "jdbc:mysql://43.138.53.7/room"
+ "?serverTimezone=UTC&useSSL=false"
+"&useUnicode=true&characterEncoding=UTF-8";
//private static Connection connection;
//private static PreparedStatement pstmt;
//private static ResultSet resultSet;
static{
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection(){
Connection connection = null;
try {
//Class.forName(DRIVER);
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connection;
}
public static void close(Connection connection,PreparedStatement pstmt,ResultSet resultSet){
try {
if(resultSet!=null){
resultSet.close();
}
if(pstmt!=null){
pstmt.close();
}
if(connection!=null){
connection.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*
将查询到的结果集转换成自定义类的对象,并存在在List中
<T>声明此方法持有一个类型T,此方法为一个泛型方法
Class<T> cla指明泛型T的具体类型
params是一个Object类型的数组
*/
public static <T> List<T> query(String sql, Class<T> cla, Object... params){
Connection conn = DBUtil.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
List<T> list = null;
try{
//预编译
ps = conn.prepareStatement(sql);
if(params != null){
for(int i = 0; i < params.length; ++i){
//替换指定位置的占位符
ps.setObject(i+1, params[i]);
}
}
//执行查询
rs = ps.executeQuery();
//获取描述结果集基础信息(列数、数据类型、字段)的meta元数据
ResultSetMetaData rsd = rs.getMetaData();
//返回值
list = new ArrayList<T>();
while (rs.next()){
//实例化一个泛型类
//T t = cla.newInstance();
T t = cla.getDeclaredConstructor().newInstance(); // 创建对象
for (int i = 0; i < rsd.getColumnCount(); ++i){
//获取列名,sql语句中有别名返回别名,否则返回值与getColumnName()方法相同
String columnName = rsd.getColumnLabel(i+1);
//根据列名取值
Object columnValue = rs.getObject(columnName);
//根据索引取值
//Object value = rs.getObject(i+1);
//根据列名获取属性
Field field;
field = cla.getDeclaredField(convertFormat(columnName));
//开启私有变量访问权限
field.setAccessible(true);
//给对象t的变量赋值
field.set(t, columnValue);
}
list.add(t);
}
return list;
} catch (Exception e) {
e.printStackTrace();
return null;
}finally {
// 关闭资源
DBUtil.close(conn, ps, rs);
}
}
//表中字段有可能有下划线,下划线命名转小驼峰命名
public static String convertFormat(String source){
String[] strings = source.split("_");
StringBuffer sf = new StringBuffer(strings[0]);
for(int i = 1; i < strings.length; ++i){
sf.append(strings[i].substring(0,1).toUpperCase() + strings[i].substring(1));
}
return sf.toString();
}
/**
* 对任意表的一个非查询
*
* @param sql
* @param objects
* @return
*/
public static int update(String sql, Object... objects) {
Connection conn = DBUtil.getConnection();
PreparedStatement ps = null;
int i = 0;
try {
// 预编译
ps = conn.prepareStatement(sql);
// 给sql赋值
for (int j = 0; j < objects.length; j++) {
ps.setObject(j + 1, objects[j]);
}
// 执行
i = ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 关闭资源
DBUtil.close(conn, ps, null);
}
return i;
}
public static void main(String[] args) {
String sql="select * from room";
List<Room> roomList=DBUtil.query(sql, Room.class);
for(Room r:roomList){
System.out.println(r);
}
// String sql1="delete from Room where roomid=?";
// int i=DBUtil.update(sql1,4);
// System.out.println(i);
}
}
3.2、实时时间(DateUtil)
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtils {
private DateUtils(){}//防止外界对象默认无参构造
//将日期转化为指定格式的字符串(静态方法,用类名即可访问)
public static String dateToString(Date date,String format){
SimpleDateFormat s = new SimpleDateFormat(format);//指定格式对象创建
String sb=s.format(date);//将传入的日转化为指定格式并转换为字符串
return sb;
}
//将字符串解析为指定的日期格式
public static Date stringToDate(String s,String format) throws ParseException {
SimpleDateFormat dd=new SimpleDateFormat(format);
Date d=dd.parse(s);//parse将指定的字符串解析为时间格式
return d;
}
}
4、业务层(server层)
4.1、房间(RoomContorller)
import com.keshe.dao.RoomDao;
import com.keshe.domain.Room;
import java.util.List;
public class RoomContorller {
//显示房间信息至table
public String[][] showALL() {
RoomDao rd = new RoomDao();
List<Room> allRoom = rd.select();
String table[][] = new String[allRoom.size()][8];
for (int i = 0; i < allRoom.size(); i++) {
table[i][0] = allRoom.get(i).getRoomid();
table[i][1] = allRoom.get(i).getHousename();
table[i][2] = allRoom.get(i).getHomeloc();
table[i][3] = Integer.toString(allRoom.get(i).getHousecoast());
table[i][4] = allRoom.get(i).getHousesnull();
table[i][5] = allRoom.get(i).getHousesclean();
table[i][6] = allRoom.get(i).gethousesdesc();
table[i][7] = null;
}
return table;
}
//添加客房信息
public int addRoom(String roomid, String housename, String homeloc, int housecoast, String housesnull, String housesclean, String housesdesc) {
String coast = Integer.toString(housecoast);
int count = 0;
if (roomid.equals("") || housename.equals("") || homeloc.equals("") || coast.equals("") || housesnull.equals("") || housesclean.equals("") || housesdesc.equals("")) {
count = -1;
}
Room rm = new Room(roomid, housename, homeloc, housecoast, housesnull, housesclean, housesdesc);
RoomDao rc = new RoomDao();
count = rc.insert(rm);//调用数据库
return count;
}
//查询客房信息(根据房间类型)
public String[][] selectName(String name) {
RoomDao rd = new RoomDao();
List<Room> allRoom = rd.selectName(name);
String table[][] = new String[allRoom.size()][8];
for (int i = 0; i < allRoom.size(); i++) {
table[i][0] = allRoom.get(i).getRoomid();
table[i][1] = allRoom.get(i).getHousename();
table[i][2] = allRoom.get(i).getHomeloc();
table[i][3] = Integer.toString(allRoom.get(i).getHousecoast());
table[i][4] = allRoom.get(i).getHousesnull();
table[i][5] = allRoom.get(i).getHousesclean();
table[i][6] = allRoom.get(i).gethousesdesc();
table[i][7] = null;
}
System.out.println("房间类型查询成功!");
return table;
}
//查询客房信息(根据编号类型)
public String[][] selectId(String id) {
RoomDao rd = new RoomDao();
List<Room> allRoom = rd.selectId(id);
String table[][] = new String[allRoom.size()][8];
for (int i = 0; i < allRoom.size(); i++) {
table[i][0] = allRoom.get(i).getRoomid();
table[i][1] = allRoom.get(i).getHousename();
table[i][2] = allRoom.get(i).getHomeloc();
table[i][3] = Integer.toString(allRoom.get(i).getHousecoast());
table[i][4] = allRoom.get(i).getHousesnull();
table[i][5] = allRoom.get(i).getHousesclean();
table[i][6] = allRoom.get(i).gethousesdesc();
table[i][7] = null;
}
System.out.println("编号查询成功!");
return table;
}
//修改客房信息
public int updateRoom(String id, String housename, String homeloc, int housecoast, String housesnull, String housesclean, String housesdesc) {
RoomDao rd = new RoomDao();
String coast = Integer.toString(housecoast);
int count = 0;
if (id.equals("") || housename.equals("") || homeloc.equals("") || coast.equals("") || housesnull.equals("") || housesclean.equals("") || housesdesc.equals("")) {
count = -1;
return count;
}
count = rd.update(id, housename, homeloc, housecoast, housesnull, housesclean, housesdesc);
return count;
}
//删除客房
public int deleteRoom(String id){
RoomDao rd=new RoomDao();
int count=0;
if(id.equals("")){
count=-1;
return count;
}
count=rd.delete(id);
return count;
}
}
4.2、旅客(RoomInContorller)
import java.util.Date;
import java.util.List;
import com.keshe.dao.RoomDao;
import com.keshe.dao.RoomInDao;
import com.keshe.domain.Room;
import com.keshe.domain.RoomIn;
import com.keshe.util.DateUtils;
public class RoomInContorller {
//获取时间
public RoomInContorller() {
}
public String getTime() {
Date d = new Date();
String time = DateUtils.dateToString(d, "yyyy-MM-dd HH:mm:ss");
return time;
}
//显示入住信息至table
public String[][] showALL() {
RoomInDao ri = new RoomInDao();
List<RoomIn> allRoomIn = ri.select();
String table[][] = new String[allRoomIn.size()][6];
for (int i = 0; i < allRoomIn.size(); i++) {
table[i][1] = allRoomIn.get(i).getUsername();
table[i][2] = allRoomIn.get(i).getIdcard();
table[i][0] = allRoomIn.get(i).getRoomId();
table[i][3] = allRoomIn.get(i).getDatain();
table[i][4] = allRoomIn.get(i).getDataout();
table[i][5] = Integer.toString(allRoomIn.get(i).getdataNum());
}
return table;
}
//新旅客入住信息输入
public int insertRoomIn(String roomid, String username, String idcard, int dataNum) {
int count = 0;
if (roomid.equals("") || username.equals("") || idcard.equals("") || dataNum == 0) {
count = -1;
}
//在客房表中查询是否有该客房
RoomDao rd = new RoomDao();
List<Room> room = rd.select();
for (int i = 0; i < room.size(); i++) {
if (room.get(i).getRoomid().equals(roomid)) {
if (room.get(i).getHousesnull().equals("是")) {
String datain = getTime();
String dataout = "暂未退房";
RoomIn r = new RoomIn(username, idcard, roomid, datain, dataout, dataNum);
RoomInDao ri = new RoomInDao();
count = ri.insert(r);//调用数据库
int test = rd.updateId(roomid, "否");
if (test != 0) {
System.out.println("修改客房状态成功!");
}
return count;
}else{
System.out.println("该客房已被占用!");
return -2;
}
}
}
System.out.println("客房中无该客房信息,不可入住");
return count;
}
//旅客退房
public int updateRoomInNull(String idcard) {
RoomInDao ri = new RoomInDao();
List<RoomIn> allRoomIn = ri.select();
int count = 0;
if (idcard.equals("")) {
System.out.println("输入数据后再搜索!");
return -1;
}
for (int i = 0; i < allRoomIn.size(); i++) {
if ((allRoomIn.get(i).getIdcard()).equals(idcard)) {
String dateout = getTime();
count = ri.updateDateout(dateout, idcard);
RoomDao rd = new RoomDao();
int test = rd.updateId(allRoomIn.get(0).getRoomId(), "是");
if (test != 0) {
System.out.println("修改客房状态成功!");
} else {
System.out.println("修改客房状态失败");
}
return count;//退房办理成功
}
}
return count;
}
}
4.3、管理员(UserContorller)
import com.keshe.dao.UserDao;
import com.keshe.domain.User;
import java.util.List;
public class UserContorller {
//注册功能
public int login(String id, String password) {
if (id.equals("") || password.equals("")) {
return 0;
}
//查验账号是否存在
UserDao us = new UserDao();
List<User> list = us.selectId(id);//查询数据库中是否有该账号
System.out.println("用户名:" + id + "\n密码:" + password);
if (list.size() == 0) {
//账号不存在
User user = new User(id, password);
int i = us.insertUSer(user);
if (i == 1) {
System.out.println("注册成功");
return 1;
} else {
System.out.println("注册失败");
return -1;
}
} else {
System.out.println("账号已存在");
return -2;
}
}
//登录
public int login_in(String id, String password) {
UserDao us = new UserDao();
List<User> list = us.selectId(id);//查询数据库中是否有该账号
System.out.println("用户名:" + id + "\n密码:" + password);
if (id.equals("") || password.equals("")) {
return 0;
}
if (list.size() == 0) {
System.out.println("当前无该账号,请先注册");
} else {
User user = list.get(0);
if (user.getPassword().equals(password)) {
System.out.println("登录成功");
return 1;
} else {
System.out.println("登录失败");
return -1;
}
}
return -1;
}
//修改密码
public int updatePassword(String id,String olePassword,String newPassword){
UserDao us=new UserDao();
int count=0;
List<User> user= us.selectId(id);
if(id.equals("")||olePassword.equals("")||newPassword.equals("")){
return -2;
}
if(user.size()==0){
return -3;
}
if(user.get(0).getPassword().equals(olePassword)){
count=us.updateUser(id,newPassword);
return count;
}else{
System.out.println("原密码错误");
return -1;
}
}
}
5、数据显示层(JSP层)
此处代码过多,需要者联系博主私发~~~~~
6、测试层(test)
import com.keshe.jsp.Login;
public class test {
public static void main(String[] args) {
new Login().setVisible(true);
}
}
更多推荐
所有评论(0)