一、介绍
在这篇博客中,我们将介绍一个基于MySQL数据库、Java编程语言和Swing图形用户界面的简单酒店管理系统。该系统包括了查询房客信息、查询房客状态、修改房客信息、添加房间信息、添加住户、退房管理、预定管理、退订管理、入账管理、出账管理、修改资料等多个功能。
二、数据库介绍
1.t_book(预订信息表):
表示酒店客房的预订信息,每条记录对应一个预订订单。
字段解释:
id: 预订编号,主键。
name: 预订人姓名。
phone: 预订人电话。
checkTime: 预订入住时间。
creditTime: 订单创建时间。
state: 预订状态(已退订等)。
t_cashier(收支信息表):
记录酒店的收入和支出情况,用于财务管理。
字段解释:
id: 记录编号,主键。
type: 类型(收入/支出)。
money: 金额。
remarks: 备注。
time: 创建时间。
2.t_guestroom(客房信息表):
存储酒店客房的基本信息,包括房间号、状态和类型。
字段解释:
id: 客房编号,主键。
num: 房间号。
state: 房间状态(0表示空闲,1表示已入住)。
type: 客房类型。
3.t_household(住户信息表):
记录入住和退房的住户信息,包括姓名、身份证号、入住时间、房间号等。
字段解释:
id: 住户编号,主键。
name: 住户姓名。
idNum: 身份证号码。
checkTime: 入住时间。
roomNum: 入住房号。
money: 收费金额。
state: 入住状态。
outTime: 退房时间。
4.t_user(用户信息表):
存储系统用户的登录名和密码。
字段解释:
id: 用户编号,主键。
userName: 登录名。
password: 登录密码。
三、程序截图
1.查询房客信息
2.查询房客状态
3.修改客房信息
4.添加房间信息
5.添加住户
6.退房管理
7.预定管理
8.退订管理
9.入账管理
10.出账管理
11.修改资料
四、代码
1.addGuestRoom
/** addGuestRoom.java** Created on __DATE__, __TIME__*/package hotel.view;import java.awt.event.ActionEvent;
import java.sql.Connection;import hotel.dao.KeFangDao;
import hotel.model.KeFang;
import hotel.util.DbUtil;import javax.swing.JOptionPane;/**** @author __USER__*/
public class addGuestRoom extends javax.swing.JInternalFrame {DbUtil dbUtil = new DbUtil();KeFangDao guestRoomDao = new KeFangDao();/** Creates new form addGuestRoom */public addGuestRoom() {initComponents();}//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {jLabel1 = new javax.swing.JLabel();
num = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
type = new javax.swing.JTextField();
save = new javax.swing.JButton();
reset = new javax.swing.JButton();setClosable(true);
setTitle("添加房间信息");jLabel1.setText("房间号");num.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
numActionPerformed(evt);
}
});jLabel2.setText("类型");save.setText("保存");
save.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveActionPerformed(evt);
}
});reset.setText("重置");
reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetActionPerformed(evt);
}
});org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(45, 45, 45)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel1)
.add(jLabel2))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(type)
.add(num, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)))
.add(layout.createSequentialGroup()
.add(84, 84, 84)
.add(save)
.add(18, 18, 18)
.add(reset)))
.addContainerGap(88, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(38, 38, 38)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(num, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(type, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 17, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(reset)
.add(save))
.addContainerGap())
);pack();
} /*** 重置按钮时间* @param evt*/private void resetActionPerformed(ActionEvent evt) {reset();}private void saveActionPerformed(java.awt.event.ActionEvent evt) {String num = this.num.getText();String type = this.type.getText();if(num == null || "".equals(num)){JOptionPane.showMessageDialog(null, "请输入房间号");return;}if(type == null && "".equals(type)){JOptionPane.showMessageDialog(null, "请输入类型");return;}Connection con = null;try {con = dbUtil.getCon();KeFang g = guestRoomDao.findByRoomNum(con, Integer.parseInt(num));//判断房间号是否存在if(g != null){JOptionPane.showMessageDialog(null, "该房间已存在");return;}//封装对象KeFang guestRoom = new KeFang();guestRoom.setNum(Integer.parseInt(num));guestRoom.setState(0);guestRoom.setType(type);//保存数据int result = guestRoomDao.addGusteRoom(con, guestRoom);if(result != 0){JOptionPane.showMessageDialog(null, "添加成功");}else{JOptionPane.showMessageDialog(null, "添加失败");}} catch (Exception e) {JOptionPane.showMessageDialog(null, "添加失败");e.printStackTrace();}finally{try {dbUtil.closeCon(con);//关闭数据库连接} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}/*** 清空输入框的值*/private void reset(){this.num.setText("");this.type.setText("");}void numActionPerformed(java.awt.event.ActionEvent evt) {// TODO add your handling code here:}//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField num;
private javax.swing.JButton reset;
private javax.swing.JButton save;
private javax.swing.JTextField type;
// End of variables declaration//GEN-END:variables}
2.addHousehold
/** addHousehold.java** Created on __DATE__, __TIME__*/package hotel.view;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;import hotel.dao.ShouYinDao;
import hotel.dao.KeFangDao;
import hotel.dao.RuZhuDao;
import hotel.model.ShouYin;
import hotel.model.KeFang;
import hotel.model.ZhuHu;
import hotel.util.DbUtil;import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;/**** 添加住户窗口*/
public class addHousehold extends JInternalFrame {//实例化对象DbUtil dbUtil = new DbUtil();RuZhuDao householdDao = new RuZhuDao();KeFangDao guestRoomDao = new KeFangDao();ShouYinDao cashierDao = new ShouYinDao();//创建窗口public addHousehold() {initComponents();this.setLocation(200, 50);}//控件private void initComponents() {jLabel1 = new JLabel();jLabel2 = new JLabel();jLabel3 = new JLabel();jLabel4 = new JLabel();name = new JTextField();idNum = new JTextField();money = new JTextField();roomNum = new JTextField();jButton1 = new JButton();jButton2 = new JButton();setClosable(true);setIconifiable(true);setMaximizable(true);setTitle("添加住户");jLabel1.setText("姓名");jLabel2.setText("身份证");jLabel3.setText("房间号");jLabel4.setText("收费");jButton1.setText("添加");jButton1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent evt) {jButton1ActionPerformed(evt);}});jButton2.setText("重置");/*** layout布局*/GroupLayout layout = new GroupLayout(getContentPane());getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.LEADING).add(layout.createSequentialGroup().addContainerGap(56, Short.MAX_VALUE).add(layout.createParallelGroup(GroupLayout.LEADING).add(GroupLayout.TRAILING,layout.createSequentialGroup().add(jButton1).add(51,51,51).add(jButton2).add(119,119,119)).add(GroupLayout.TRAILING,layout.createSequentialGroup().add(layout.createParallelGroup(GroupLayout.TRAILING).add(jLabel3).add(jLabel4).add(jLabel2).add(jLabel1)).add(50,50,50).add(layout.createParallelGroup(GroupLayout.LEADING).add(layout.createParallelGroup(GroupLayout.TRAILING,false).add(GroupLayout.LEADING,idNum).add(GroupLayout.LEADING,name,GroupLayout.DEFAULT_SIZE,195,Short.MAX_VALUE)).add(layout.createParallelGroup(GroupLayout.TRAILING,false).add(GroupLayout.LEADING,money).add(GroupLayout.LEADING,roomNum,GroupLayout.DEFAULT_SIZE,193,Short.MAX_VALUE))).add(89,89,89)))));layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.LEADING).add(layout.createSequentialGroup().add(39, 39, 39).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jLabel1).add(name,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)).addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jLabel2).add(idNum,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)).addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jLabel3).add(roomNum,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)).add(4, 4, 4).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jLabel4).add(money,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)).add(18, 18, 18).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jButton1).add(jButton2)).addContainerGap()));pack();}// </editor-fold>//GEN-END:initComponentsprivate void jButton1ActionPerformed(ActionEvent evt) {//获取输入框的值String name = this.name.getText();//姓名String idNum = this.idNum.getText();//身份证号String roomNum = this.roomNum.getText();//房间号String money = this.money.getText();//费用//验证值是否为空if("".equals(name) || name == null){JOptionPane.showMessageDialog(null, "请输入姓名");return;}if("".equals(idNum) || idNum == null){JOptionPane.showMessageDialog(null, "请输入身份证号码");return;}if("".equals(roomNum) || roomNum == null){JOptionPane.showMessageDialog(null, "请输入房间号");return;}if("".equals(money) || money == null){JOptionPane.showMessageDialog(null, "请输入入住费用");}//封装对象ZhuHu household = new ZhuHu();household.setName(name);household.setIdNum(idNum);household.setRoomNum(Integer.parseInt(roomNum));household.setMoney(Integer.parseInt(money));household.setState("入住中");Connection con = null;try {con = dbUtil.getCon();KeFang gr = new KeFang();//判断房间是否存在或者是否已有人入住gr = guestRoomDao.findByRoomNum(con, Integer.parseInt(roomNum));if(gr == null){JOptionPane.showMessageDialog(null, "未查询到客房信息");return;}if(gr.getState() == 1){JOptionPane.showMessageDialog(null, "房间占用,请重新选择房间");return;}int result = householdDao.addHousehold(con, household);if(result != 0){JOptionPane.showMessageDialog(null, "添加成功");reset();//更新房间状态未已入住KeFang guestRoom = new KeFang();guestRoom.setNum(Integer.parseInt(roomNum));guestRoom.setState(1);guestRoomDao.updateState(con, guestRoom);//添加收银信息ShouYin cashier = new ShouYin();cashier.setType("收入");cashier.setMoney(money);cashier.setRemarks("用户"+name+"入住收入金额"+money);cashierDao.addCashier(con, cashier);}else{JOptionPane.showMessageDialog(null, "添加失败");}} catch (Exception e) {JOptionPane.showMessageDialog(null, "添加失败");e.printStackTrace();}finally{try {dbUtil.closeCon(con);//关闭数据库连接} catch (Exception e) {e.printStackTrace();}}}//清空输入框的值public void reset(){this.name.setText("");this.idNum.setText("");this.roomNum.setText("");this.money.setText("");}//窗口控件private JTextField idNum;private JButton jButton1;private JButton jButton2;private JLabel jLabel1;private JLabel jLabel2;private JLabel jLabel3;private JLabel jLabel4;private JTextField money;private JTextField name;private JTextField roomNum;}
3.BookManger
/** BookManger.java** Created on __DATE__, __TIME__*/package hotel.view;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;import hotel.dao.YuDingDao;
import hotel.model.YuDing;
import hotel.util.DbUtil;import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;
/***添加预订信息* @author Administrator**/
public class BookManger extends javax.swing.JInternalFrame {//实例化对象DbUtil dbUtil = new DbUtil();YuDingDao bookDao = new YuDingDao();/** 创建窗口 */public BookManger() {initComponents();this.setLocation(200, 50);//设置窗口位置}//初始化控件private void initComponents() {jLabel1 = new JLabel();name = new JTextField();jLabel2 = new JLabel();phone = new JTextField();jLabel3 = new JLabel();checkTime = new JTextField();save = new JButton();jButton2 = new JButton();setClosable(true);setIconifiable(true);setTitle("预订管理");jLabel1.setText("姓名");jLabel2.setText("联系电话");jLabel3.setText("入住时间");save.setText("保存");save.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent evt) {saveActionPerformed(evt);}});jButton2.setText("重置");/*** layout布局*/GroupLayout layout = new GroupLayout(getContentPane());getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.LEADING).add(layout.createSequentialGroup().add(layout.createParallelGroup(GroupLayout.LEADING).add(layout.createSequentialGroup().add(32,32,32).add(layout.createParallelGroup(GroupLayout.LEADING).add(jLabel3).add(jLabel2).add(jLabel1)).addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.LEADING,false).add(GroupLayout.TRAILING,phone,GroupLayout.DEFAULT_SIZE,153,Short.MAX_VALUE).add(save).add(checkTime).add(GroupLayout.TRAILING,name))).add(layout.createSequentialGroup().add(186,186,186).add(jButton2))).addContainerGap(89, Short.MAX_VALUE)));layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.LEADING).add(layout.createSequentialGroup().add(30, 30, 30).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jLabel1).add(name,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)).addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jLabel2).add(phone,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)).addPreferredGap(LayoutStyle.RELATED).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jLabel3).add(checkTime,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)).addPreferredGap(LayoutStyle.RELATED,28, Short.MAX_VALUE).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jButton2).add(save)).addContainerGap()));pack();}/*** 保存按钮事件* @param evt*/private void saveActionPerformed(java.awt.event.ActionEvent evt) {String name = this.name.getText();//姓名String phone = this.phone.getText();//联系电话String checkTime = this.checkTime.getText();//预订入住时间//验证数据是否为空if (name == null || "".equals(name)) {JOptionPane.showMessageDialog(null, "请输入入住人姓名");}if (phone == null || "".equals(phone)) {JOptionPane.showMessageDialog(null, "请输入联系电话");}if (checkTime == null || "".equals(checkTime)) {JOptionPane.showMessageDialog(null, "请输入入住时间");}//封装数据对象YuDing book = new YuDing();book.setName(name);book.setPhone(phone);book.setCheckTime(checkTime);book.setState("已预订");Connection con = null;//保存数据try {con = dbUtil.getCon();int result = bookDao.addBook(con, book);if (result != 0) {JOptionPane.showMessageDialog(null, "保存成功");reset();} else {JOptionPane.showMessageDialog(null, "保存失败");}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();JOptionPane.showMessageDialog(null, "保存失败");}finally{try {dbUtil.closeCon(con);//关闭数据库连接} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}//清空输入框的值private void reset() {this.name.setText("");this.phone.setText("");this.checkTime.setText("");}/** 控件 */private JTextField checkTime;private JButton jButton2;private JLabel jLabel1;private JLabel jLabel2;private JLabel jLabel3;private JTextField name;private JTextField phone;private JButton save;}
4.editAdmin
* editAdmin.java** Created on __DATE__, __TIME__*/package hotel.view;import hotel.dao.BianJiDao;
import hotel.util.DbUtil;import java.sql.Connection;import javax.swing.JOptionPane;/**** @author __USER__*/
public class editAdmin extends javax.swing.JInternalFrame {DbUtil dbUtil = new DbUtil();BianJiDao editModulDao = new BianJiDao();/** Creates new form editAdmin */public editAdmin() {initComponents();}/** This method is called from within the constructor to* initialize the form.* WARNING: Do NOT modify this code. The content of this method is* always regenerated by the Form Editor.*///GEN-BEGIN:initComponents// <editor-fold defaultstate="collapsed" desc="Generated Code">private void initComponents() {jLabel1 = new javax.swing.JLabel();jTextField1 = new javax.swing.JTextField();jLabel2 = new javax.swing.JLabel();password = new javax.swing.JPasswordField();jLabel3 = new javax.swing.JLabel();repassword = new javax.swing.JPasswordField();jButton1 = new javax.swing.JButton();jLabel4 = new javax.swing.JLabel();oldpassword = new javax.swing.JPasswordField();setClosable(true);setResizable(true);jLabel1.setText("\u7528\u6237\u540d");jTextField1.setText("admin");jTextField1.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt) {jTextField1ActionPerformed(evt);}});jLabel2.setText("\u65b0\u5bc6\u7801");password.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt) {passwordActionPerformed(evt);}});jLabel3.setText("\u786e\u8ba4\u5bc6\u7801");jButton1.setText("\u4fee\u6539");jButton1.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt) {jButton1ActionPerformed(evt);}});jLabel4.setText("\u65e7\u5bc6\u7801");org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(layout.createSequentialGroup().add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(layout.createSequentialGroup().add(26, 26, 26).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING).add(jLabel3).add(jLabel2).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jLabel4).add(jLabel1))).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING,false).add(oldpassword, 0, 0,Short.MAX_VALUE).add(jTextField1,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,181, Short.MAX_VALUE).add(repassword, 0, 0,Short.MAX_VALUE).add(password, 0, 0,Short.MAX_VALUE))).add(layout.createSequentialGroup().add(134, 134, 134).add(jButton1))).addContainerGap(82, Short.MAX_VALUE)));layout.setVerticalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(layout.createSequentialGroup().add(26, 26, 26).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jTextField1,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).add(jLabel1)).add(18, 18, 18).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel4).add(oldpassword,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).add(12, 12, 12).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(password,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).add(jLabel2)).addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(repassword,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).add(jLabel3)).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 23,Short.MAX_VALUE).add(jButton1).add(28, 28, 28)));pack();}// </editor-fold>//GEN-END:initComponentsprivate void passwordActionPerformed(java.awt.event.ActionEvent evt) {// TODO add your handling code here:}private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {Connection con = null;String password = new String(this.password.getPassword());String repassword = new String(this.repassword.getPassword());String oldpassword = new String(this.oldpassword.getPassword());try {con = dbUtil.getCon();String oldpwd = editModulDao.oldPassword(con);if(!oldpassword.equals(oldpwd)){JOptionPane.showMessageDialog(null, "旧密码不符");return;}} catch (Exception e1) {e1.printStackTrace();}if (password == null || "".equals(password)) {JOptionPane.showMessageDialog(null, "请输入密码");return;}if (!password.equals(repassword)) {JOptionPane.showMessageDialog(null, "两次输入密码不一致");return;}//修改数据库操作try {con = dbUtil.getCon();int result = editModulDao.updateAdmin(con, password);if (result != 0) {JOptionPane.showMessageDialog(null, "修改成功");this.password.setText("");} else {JOptionPane.showMessageDialog(null, "修改失败");}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {try {dbUtil.closeCon(con);//关闭数据库连接} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {// TODO add your handling code here:}//GEN-BEGIN:variables// Variables declaration - do not modifyprivate javax.swing.JButton jButton1;private javax.swing.JLabel jLabel1;private javax.swing.JLabel jLabel2;private javax.swing.JLabel jLabel3;private javax.swing.JLabel jLabel4;private javax.swing.JTextField jTextField1;private javax.swing.JPasswordField oldpassword;private javax.swing.JPasswordField password;private javax.swing.JPasswordField repassword;// End of variables declaration//GEN-END:variables}```## 5.editData
```java
/** editData.java** Created on __DATE__, __TIME__*/package hotel.view;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;import hotel.dao.BianJiDao;
import hotel.util.DbUtil;/*** 修改管理员资料* @author Administrator**/
public class editData extends javax.swing.JInternalFrame {DbUtil dbUtil = new DbUtil();BianJiDao editModulDao = new BianJiDao();/** Creates new form editData */public editData() {initComponents();this.setLocation(300, 100);//设置窗口位置}/** 控件 */private void initComponents() {jLabel1 = new JLabel();jTextField1 = new JTextField();jLabel2 = new JLabel();password = new JPasswordField();password2 = new JPasswordField();jButton1 = new JButton();reset = new JButton();setClosable(true);setTitle("修改资料");jLabel1.setText("账号");jTextField1.setEditable(false);jTextField1.setText("admin");jLabel2.setText("密码");jButton1.setText("修改");jButton1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent evt) {jButton1ActionPerformed(evt);}});reset.setText("重置");reset.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent evt) {resetActionPerformed(evt);}});/*** layout布局*/GroupLayout layout = new GroupLayout(getContentPane());getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.LEADING).add(layout.createSequentialGroup().add(29, 29, 29).add(layout.createParallelGroup(GroupLayout.LEADING,false).add(layout.createSequentialGroup().add(jLabel1).add(18,18,18).add(jTextField1,GroupLayout.PREFERRED_SIZE,172,GroupLayout.PREFERRED_SIZE)).add(layout.createSequentialGroup().add(jLabel2).add(18,18,18).add(layout.createParallelGroup(GroupLayout.LEADING).add(password,0,0,Short.MAX_VALUE).add(layout.createSequentialGroup().add(jButton1).addPreferredGap(LayoutStyle.RELATED,35,Short.MAX_VALUE).add(reset).add(23,23,23))))).addContainerGap(52, Short.MAX_VALUE)));layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.LEADING).add(layout.createSequentialGroup().add(31, 31, 31).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jLabel1).add(jTextField1,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)).add(18, 18, 18).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jLabel2).add(password,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)).add(18, 18, 18).add(layout.createParallelGroup(GroupLayout.BASELINE).add(jButton1).add(reset)).addContainerGap(35, Short.MAX_VALUE)));pack();}/*** 修改管理员资料*///修改按钮事件private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {String password = new String(this.password.getPassword());String repassword = new String(this.password2.getPassword());if (password == null || "".equals(password)) {JOptionPane.showMessageDialog(null, "请输入密码");return;}if(!password.equals(repassword)){JOptionPane.showMessageDialog(null, "两次输入密码不一致");return;}Connection con = null;//修改数据库操作try {con = dbUtil.getCon();int result = editModulDao.updateAdmin(con, password);if (result != 0) {JOptionPane.showMessageDialog(null, "修改成功");this.password.setText("");} else {JOptionPane.showMessageDialog(null, "修改失败");}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {try {dbUtil.closeCon(con);//关闭数据库连接} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}//重置输入框的值private void resetActionPerformed(ActionEvent evt) {this.password.setText("");}//页面控件private JButton jButton1;private JLabel jLabel1;private JLabel jLabel2;private JTextField jTextField1;private JPasswordField password;private JPasswordField password2;private JButton reset;}
5.inAccountManger
/** inAccountManger.java** Created on __DATE__, __TIME__*/package hotel.view;import hotel.dao.YuDingDao;
import hotel.dao.ShouYinDao;
import hotel.model.ShouYin;
import hotel.util.DbUtil;import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;import com.sun.org.apache.bcel.internal.generic.NEW;/**** @author __USER__*/
public class inAccountManger extends javax.swing.JInternalFrame {DbUtil dbUtil = new DbUtil();ShouYinDao cashierDao = new ShouYinDao();/** Creates new form inAccountManger */public inAccountManger() {initComponents();this.fillTable();this.setLocation(200, 50);//设置窗口位置}/*** 填充表格数据* @param name*/public void fillTable() {DefaultTableModel dtm = (DefaultTableModel) inAccountTable.getModel();dtm.setRowCount(0);Connection con = null;try {con = dbUtil.getCon();ResultSet re = cashierDao.cashier(con);while (re.next()) {Vector v = new Vector();//添加每一行的数据v.add(re.getString("id"));v.add(re.getString("type"));v.add(re.getString("money"));v.add(re.getString("remarks"));v.add(re.getString("time"));dtm.addRow(v);}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {try {dbUtil.closeCon(con);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}/** This method is called from within the constructor to* initialize the form.* WARNING: Do NOT modify this code. The content of this method is* always regenerated by the Form Editor.*///GEN-BEGIN:initComponents// <editor-fold defaultstate="collapsed" desc="Generated Code">private void initComponents() {jScrollPane1 = new javax.swing.JScrollPane();inAccountTable = new javax.swing.JTable();jPanel1 = new javax.swing.JPanel();jLabel1 = new javax.swing.JLabel();money = new javax.swing.JTextField();jLabel2 = new javax.swing.JLabel();remarks = new javax.swing.JTextField();add = new javax.swing.JButton();jLabel3 = new javax.swing.JLabel();type = new javax.swing.JTextField();setClosable(true);setIconifiable(true);setTitle("\u5165\u8d26\u7ba1\u7406");inAccountTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { { null, null, null, null, null },{ null, null, null, null, null },{ null, null, null, null, null },{ null, null, null, null, null } }, new String[] {"编号", "状态", "金额", "备注", "时间" }) {boolean[] canEdit = new boolean[] { false, false, false, false,false };public boolean isCellEditable(int rowIndex, int columnIndex) {return canEdit[columnIndex];}});jScrollPane1.setViewportView(inAccountTable);jLabel1.setText("\u91d1\u989d");jLabel2.setText("\u5907\u6ce8");add.setText("\u6dfb\u52a0");add.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt) {addActionPerformed(evt);}});jLabel3.setText("\u7c7b\u578b");type.setEditable(false);type.setText("\u6536\u5165");type.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt) {jTextField1ActionPerformed(evt);}});org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);jPanel1.setLayout(jPanel1Layout);jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jPanel1Layout.createSequentialGroup().addContainerGap().add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING).add(add).add(jPanel1Layout.createSequentialGroup().add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING,false).add(org.jdesktop.layout.GroupLayout.LEADING,jPanel1Layout.createSequentialGroup().add(jLabel3).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(type)).add(jPanel1Layout.createSequentialGroup().add(jLabel1).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(money,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,176,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))).add(18,18,18).add(jLabel2).add(18,18,18).add(remarks,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,181,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))).addContainerGap(439, Short.MAX_VALUE)));jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jPanel1Layout.createSequentialGroup().addContainerGap().add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel1).add(money,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).add(jLabel2).add(remarks,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).add(18, 18, 18).add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel3).add(type,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE).add(add)));org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(org.jdesktop.layout.GroupLayout.TRAILING,layout.createSequentialGroup().addContainerGap().add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING).add(org.jdesktop.layout.GroupLayout.LEADING,jPanel1,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE).add(org.jdesktop.layout.GroupLayout.LEADING,jScrollPane1,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,897, Short.MAX_VALUE)).addContainerGap()));layout.setVerticalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(layout.createSequentialGroup().addContainerGap().add(jScrollPane1,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED).add(jPanel1,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE).addContainerGap(30, Short.MAX_VALUE)));pack();}// </editor-fold>//GEN-END:initComponentsprivate void addActionPerformed(java.awt.event.ActionEvent evt) {String money = this.money.getText();String remarks = this.remarks.getText();String type = this.type.getText();if("".equals(money) || money == null){JOptionPane.showMessageDialog(null, "请输入金额");return;}if("".equals(remarks) || remarks == null){JOptionPane.showMessageDialog(null, "请输入备注");return;}ShouYin cashier = new ShouYin();cashier.setMoney(money);cashier.setRemarks(remarks);cashier.setType(type);Connection con = null; try {con = dbUtil.getCon();int result = cashierDao.addCashier(con, cashier);if(result != 0){JOptionPane.showMessageDialog(null, "添加成功!");this.fillTable();this.money.setText("");this.remarks.setText("");}} catch (Exception e) {JOptionPane.showMessageDialog(null, "添加失败!");e.printStackTrace();}}private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {// TODO add your handling code here:}//GEN-BEGIN:variables// Variables declaration - do not modifyprivate javax.swing.JButton add;private javax.swing.JTable inAccountTable;private javax.swing.JLabel jLabel1;private javax.swing.JLabel jLabel2;private javax.swing.JLabel jLabel3;private javax.swing.JPanel jPanel1;private javax.swing.JScrollPane jScrollPane1;private javax.swing.JTextField type;private javax.swing.JTextField money;private javax.swing.JTextField remarks;// End of variables declaration//GEN-END:variables}
6.login
/** login.java** Created on __DATE__, __TIME__*/package hotel.view;import hotel.dao.UserDao;
import hotel.model.User;
import hotel.util.DbUtil;import java.awt.Font;
import java.sql.Connection;import javax.swing.JOptionPane;
import javax.swing.UIManager;/**** @author __USER__*/
public class login extends javax.swing.JFrame {DbUtil dbUtil = new DbUtil();UserDao userDao = new UserDao();/** Creates new form login */public login() {//改变系统默认字体Font font = new Font("Dialog", Font.PLAIN, 12);java.util.Enumeration keys = UIManager.getDefaults().keys();while (keys.hasMoreElements()) {Object key = keys.nextElement();Object value = UIManager.get(key);if (value instanceof javax.swing.plaf.FontUIResource) {UIManager.put(key, font);}}initComponents();// 设置Frame居中显示this.setLocationRelativeTo(null);}/** This method is called from within the constructor to* initialize the form.* WARNING: Do NOT modify this code. The content of this method is* always regenerated by the Form Editor.*///GEN-BEGIN:initComponents// <editor-fold defaultstate="collapsed" desc="Generated Code">private void initComponents() {jLabel1 = new javax.swing.JLabel();jLabel2 = new javax.swing.JLabel();userName = new javax.swing.JTextField();password = new javax.swing.JPasswordField();login = new javax.swing.JButton();reset = new javax.swing.JButton();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);setTitle("\u7ba1\u7406\u5458\u767b\u9646");jLabel1.setText("\u767b\u5f55\u540d");jLabel2.setText("\u5bc6\u7801");login.setText("\u767b\u9646");login.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt) {loginActionPerformed(evt);}});reset.setText("\u91cd\u7f6e");org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(layout.createSequentialGroup().add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(layout.createSequentialGroup().add(39,39,39).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(jLabel1).add(jLabel2)).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING,false).add(password,0,0,Short.MAX_VALUE).add(userName,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,154,Short.MAX_VALUE))).add(layout.createSequentialGroup().add(81,81,81).add(login).add(18,18,18).add(reset))).addContainerGap(55, Short.MAX_VALUE)));layout.setVerticalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(layout.createSequentialGroup().add(32, 32, 32).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel1).add(userName,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).add(18, 18, 18).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(jLabel2).add(password,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)).addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED,18, Short.MAX_VALUE).add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE).add(reset).add(login)).addContainerGap()));pack();}// </editor-fold>//GEN-END:initComponentsprivate void loginActionPerformed(java.awt.event.ActionEvent evt) {String userName = this.userName.getText();String password = new String(this.password.getPassword());if("".equals(userName) || userName == null){JOptionPane.showMessageDialog(null, "用户名不能为空");return;}if("".equals(password) || password == null){JOptionPane.showMessageDialog(null, "密码不能为空");return;}User user = new User();user.setUserName(userName);user.setPassword(password);Connection conn = null;try {conn = dbUtil.getCon();User us = userDao.login(conn, user);if(us == null){JOptionPane.showMessageDialog(null, "用户名或密码错误");}else{this.dispose();new main().setVisible(true);}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{try {dbUtil.closeCon(conn);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}/*** @param args the command line arguments*/public static void main(String args[]) {java.awt.EventQueue.invokeLater(new Runnable() {public void run() {new login().setVisible(true);}});}//GEN-BEGIN:variables// Variables declaration - do not modifyprivate javax.swing.JLabel jLabel1;private javax.swing.JLabel jLabel2;private javax.swing.JButton login;private javax.swing.JPasswordField password;private javax.swing.JButton reset;private javax.swing.JTextField userName;// End of variables declaration//GEN-END:variables}
五、联系与交流
扣:969060742 完整程序资源、sql、代码