📄 returnroomframe.java
字号:
JOptionPane.showMessageDialog(this, "请选择相应的房间类别和房间号!!", "提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
AccountBean account = new AccountBean();
String sql = "select name,AccountNo,rebatePri,deposit,reckoning,operator from Account where roomno = '" +
this.cboRoomNo.getSelectedItem().toString() + "' and isreturnrm= '0'";
try {
rs = dbo.returnQuery(sql);
if (rs.next()) {
account.setName(rs.getString(1));
account.setAccountNo(rs.getInt(2));
account.setRebatePri(rs.getInt(3));
account.setDeposit(rs.getInt(4));
account.setReckoning(rs.getInt(5));
account.setOperator(rs.getString(6));
}
} catch (SQLException ex) {
ex.printStackTrace();
}
this.txtName.setText(account.getName());
this.txtAccount.setText("" + account.getAccountNo());
this.txtDepatePri.setText("" + account.getRebatePri());
this.txtDeposit.setText("" + account.getDeposit());
this.txtReckoning.setText("" + account.getReckoning());
this.txtAdmin.setText(account.getOperator());
GuestRegistBean regist = new GuestRegistBean();
String sql2 =
"select checkInDate,checkOutdate,total from register where roomNo = '" +
this.cboRoomNo.getSelectedItem().toString() + "'";
rs = dbo.returnQuery(sql2);
try {
while (rs.next()) {
regist.setCheckInDate(rs.getString(1));
regist.setCheckOutDate(rs.getString(2));
regist.setTotal(rs.getInt(3));
}
} catch (SQLException ex1) {
}
// System.out.println(regist.getCheckInDate());
String checkInDate = new String(regist.getCheckInDate().substring(0, 11));
String checkOutDate = new String(regist.getCheckOutDate().substring(0,
11));
int days = 0; //计算住店天数
days = register.getDays(checkInDate, checkOutDate);
this.txtCheckIn.setText(checkInDate);
this.txtCheckOut.setText(checkOutDate);
this.txtTotal.setText("" + regist.getTotal());
this.txtlivDays.setText("" + days);
this.btnOK.setEnabled(true);
}
//房间类型下拉框的选项的变化事件
public void cboRoomType_itemStateChanged(ItemEvent e) {
if (this.cboRoomType.getSelectedItem().toString().equals("豪华间")) {
this.cboRoomNo.removeAllItems();
String sql1 =
"select roomNo from register where Class = '豪华间' and isReturnRm = '0'";
rs = dbo.returnQuery(sql1);
try {
while (rs.next()) {
this.cboRoomNo.addItem(rs.getString(1));
}
if (this.cboRoomNo.getSelectedItem() == null) {
JOptionPane.showMessageDialog(this, "该类客房没有客人!", "提示",
JOptionPane.
INFORMATION_MESSAGE);
this.btnQuery.setEnabled(false);
return;
} else {
this.btnQuery.setEnabled(true);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
} else if (this.cboRoomType.getSelectedItem().toString().equals("标准间")) {
this.cboRoomNo.removeAllItems();
String sql1 =
"select roomNo from register where Class = '标准间' and isReturnRm = '0'";
rs = dbo.returnQuery(sql1);
try {
while (rs.next()) {
this.cboRoomNo.addItem(rs.getString(1));
}
if (this.cboRoomNo.getSelectedItem() == null) {
JOptionPane.showMessageDialog(this, "该类客房没有客人!");
this.btnQuery.setEnabled(false);
return;
} else {
this.btnQuery.setEnabled(true);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
} else if (this.cboRoomType.getSelectedItem().toString().equals("普通间")) {
this.cboRoomNo.removeAllItems();
String sql1 =
"select roomNo from register where Class = '普通间' and isReturnRm = '0'";
rs = dbo.returnQuery(sql1);
try {
while (rs.next()) {
this.cboRoomNo.addItem(rs.getString(1));
}
if (this.cboRoomNo.getSelectedItem() == null) {
JOptionPane.showMessageDialog(this, "该类客房没有客人!");
this.btnQuery.setEnabled(false);
return;
} else {
this.btnQuery.setEnabled(true);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
} else if (this.cboRoomType.getSelectedItem().toString().equals("房间类别")) {
this.cboRoomNo.removeAllItems();
this.cboRoomNo.addItem("房间号");
}
}
//退房确认按钮单击事件
public void btnOK_actionPerformed(ActionEvent e) {
String checkOutDate = this.txtCheckOut.getText();
int days = Integer.parseInt(this.txtlivDays.getText());
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int date = cal.get(Calendar.DATE);
String now = "";
if ((1 + cal.get(Calendar.MONTH)) < 10 && cal.get(Calendar.DATE) > 10) {
now = cal.get(Calendar.YEAR) + "-0" +
(1 + cal.get(Calendar.MONTH)) + "-" +
cal.get(Calendar.DATE);
} else if (cal.get(Calendar.DATE) < 10 &&
(1 + cal.get(Calendar.MONTH)) > 10) {
now = cal.get(Calendar.YEAR) + "-" +
(1 + cal.get(Calendar.MONTH)) + "-0" +
cal.get(Calendar.DATE);
} else if (cal.get(Calendar.DATE) < 10 &&
(1 + cal.get(Calendar.MONTH)) < 10) {
now = cal.get(Calendar.YEAR) + "-0" +
(1 + cal.get(Calendar.MONTH)) + "-0" +
cal.get(Calendar.DATE);
} else {
now = cal.get(Calendar.YEAR) + "-" +
(1 + cal.get(Calendar.MONTH)) + "-" +
cal.get(Calendar.DATE);
}
int nowdays = register.getDays(checkOutDate, now);
int countdays = 0;
int totalpay =0;
if (nowdays - days > 0) {
countdays = nowdays - days;
totalpay = Integer.parseInt(txtDepatePri.getText())*countdays-Integer.parseInt(this.txtDeposit.getText());
JOptionPane.showMessageDialog(this,
"您没有按时退房,延迟了" + countdays + "天退房!!\n扣除您的押金,请付"+totalpay+"元!!\n\n现在结算吗??","提示",JOptionPane.WARNING_MESSAGE);
}
Object[] op = {"是", "否"};
int option = JOptionPane.showOptionDialog(this, "确认退房吗!", "确认",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null,
op, "是");
if (option == 0) {
int resetReckoning = Integer.parseInt(this.txtReckoning.getText())+totalpay;
String update1 =
"update roomStatus set onuse = '0' where roomno = '" +
this.cboRoomNo.getSelectedItem().toString() + "'";
String update2 =
" update Account set isReturnRm = '1',reckoning="+resetReckoning+" where roomNO = '" +
this.cboRoomNo.getSelectedItem().toString() + "' and accountNO = '"+this.txtAccount.getText()+"'";
String update3 =
"update register set isreturnRm = '1' where roomNO = '" +
this.cboRoomNo.getSelectedItem().toString() + "' and accountNO = '"+this.txtAccount.getText()+"'";
if (dbo.updateNoReturn(update1) && dbo.updateNoReturn(update2) &&
dbo.updateNoReturn(update3)) {
JOptionPane.showMessageDialog(this, "退房成功!!");
} else {
JOptionPane.showMessageDialog(this, "退房失败!!检查相关信息!!");
}
} else {
return;
}
this.txtAccount.setText("");
this.txtAdmin.setText("");
this.txtCheckIn.setText("");
this.txtCheckOut.setText("");
this.txtDepatePri.setText("");
this.txtDeposit.setText("");
this.txtlivDays.setText("");
this.txtName.setText("");
this.txtReckoning.setText("");
this.txtTotal.setText("");
this.btnQuery.setEnabled(false);
this.cboRoomNo.removeItem(this.cboRoomNo.getSelectedItem());
this.btnOK.setEnabled(false);
}
//单击取消按钮事件
public void btnCancel_actionPerformed(ActionEvent e) {
Object[] op = {"是", "否"};
int option = JOptionPane.showOptionDialog(this, "确认退出退房吗!", "确认",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null,
op, "是");
if (option == 0) {
this.dispose();
} else {
return;
}
}
public void showTime() {
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
Calendar cal = Calendar.getInstance();
String showTime = "";
showTime = "当前时间:" + cal.get(Calendar.YEAR) + "-" +
(cal.get(Calendar.MONTH) + 1) + "-" +
cal.get(Calendar.DATE);
showTime += " " + cal.get(Calendar.HOUR) + ":" +
cal.get(Calendar.MINUTE) + ":" +
cal.get(Calendar.SECOND);
lblTime.setText(showTime);
// Date d = new Date();
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH小时mm分钟ss秒");
// lblTime.setText(sdf.format(d));
}
};
timer = new Timer(1000, al);
timer.start();
}
}
class ReturnRoomFrame_btnCancel_actionAdapter implements ActionListener {
private ReturnRoomFrame adaptee;
ReturnRoomFrame_btnCancel_actionAdapter(ReturnRoomFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnCancel_actionPerformed(e);
}
}
class ReturnRoomFrame_btnOK_actionAdapter implements ActionListener {
private ReturnRoomFrame adaptee;
ReturnRoomFrame_btnOK_actionAdapter(ReturnRoomFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnOK_actionPerformed(e);
}
}
class ReturnRoomFrame_cboRoomType_itemAdapter implements ItemListener {
private ReturnRoomFrame adaptee;
ReturnRoomFrame_cboRoomType_itemAdapter(ReturnRoomFrame adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent e) {
adaptee.cboRoomType_itemStateChanged(e);
}
}
class ReturnRoomFrame_btnQuery_actionAdapter implements ActionListener {
private ReturnRoomFrame adaptee;
ReturnRoomFrame_btnQuery_actionAdapter(ReturnRoomFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnQuery_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -