📄 changeroom.java
字号:
package GuestManagement;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.BorderFactory;
import ShowTable.TableExample;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import hotelinformationmanagesystem.JudgeValidity;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.sql.ResultSet;
import hotelinformationmanagesystem.DataConnect;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
/**
* <p>Title: 酒店信息管理系统</p>
*
* <p>Description: The Management Information System of Hotel</p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: JSP</p>
*
* @author 江世澎
* @version 1.0
*/
public class ChangeRoom extends JFrame {
XYLayout xYLayout1 = new XYLayout();
JTable jTable1;
JTable jTable11;
TableExample table = new TableExample();
TableExample table1 = new TableExample();
JScrollPane jSPShowFreeRoom = new JScrollPane();
JTextField jTFOldRoomID = new JTextField();
JTextField jTFNewRoomID = new JTextField();
JLabel jLChange = new JLabel();
JLabel jLOldRoomID = new JLabel();
JLabel jLabel1 = new JLabel();
JButton jBFinish = new JButton();
JButton jButton1 = new JButton();
JScrollPane jSPGuestInfo = new JScrollPane();
JLabel jLGuestInfo = new JLabel();
JLabel jLabel2 = new JLabel();
GuestRegister guestreg = new GuestRegister();
hotelinformationmanagesystem.JudgeValidity judgeval = new JudgeValidity();
public static String strNewRoomID = "";
public static String strOldRoomID = "";
public static String strYesOrNot = "";
DataConnect connect1;
DataConnect connect2;
DataConnect connect3;
ResultSet rs1l = null;
public ChangeRoom() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
jTable1 = table.createTable();
jTable11 = table1.createTable();
getContentPane().setLayout(xYLayout1);
this.setResizable(false);
this.setBounds(6,260,400, 300);
this.setTitle("置换客房界面");
xYLayout1.setWidth(399);
xYLayout1.setHeight(261);
jTFOldRoomID.setEnabled(false);
jTFOldRoomID.setFont(new java.awt.Font("宋体", Font.BOLD, 20));
jTFOldRoomID.setBorder(BorderFactory.createEtchedBorder());
jTFNewRoomID.setEnabled(false);
jTFNewRoomID.setFont(new java.awt.Font("宋体", Font.BOLD, 20));
jTFNewRoomID.setBorder(BorderFactory.createEtchedBorder());
jLChange.setFont(new java.awt.Font("宋体", Font.BOLD, 20));
jLChange.setText("换为");
jLOldRoomID.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
jLOldRoomID.setText("旧客房ID");
jLabel1.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
jLabel1.setText("新客房ID");
jBFinish.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
jBFinish.setText("完成");
jBFinish.addActionListener(new ChangeRoom_jBFinish_actionAdapter(this));
jButton1.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
jButton1.setText("退出");
jButton1.addActionListener(new ChangeRoom_jButton1_actionAdapter(this));
jLGuestInfo.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
jLGuestInfo.setText("客户旧客房信息");
jLabel2.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
jLabel2.setText("酒店剩余空闲客房信息");
jTable11.addMouseListener(new ChangeRoom_jTable11_mouseAdapter(this));
jTable1.addMouseListener(new ChangeRoom_jTable1_mouseAdapter(this));
this.getContentPane().add(jSPGuestInfo,
new XYConstraints(4, 21, 186, 132));
jSPGuestInfo.getViewport().add(jTable11);
this.getContentPane().add(jLGuestInfo, new XYConstraints(4, 2, -1, -1));
this.getContentPane().add(jLOldRoomID,
new XYConstraints(13, 165, -1, -1));
this.getContentPane().add(jTFOldRoomID,
new XYConstraints(13, 187, 117, 33));
this.getContentPane().add(jTFNewRoomID,
new XYConstraints(264, 187, 117, 33));
this.getContentPane().add(jLabel1, new XYConstraints(264, 164, -1, -1));
this.getContentPane().add(jButton1, new XYConstraints(316, 228, -1, -1));
this.getContentPane().add(jBFinish, new XYConstraints(223, 228, -1, -1));
jSPShowFreeRoom.getViewport().add(jTable1);
this.getContentPane().add(jSPShowFreeRoom,
new XYConstraints(203, 21, 186, 132));
this.getContentPane().add(jLabel2, new XYConstraints(203, 2, -1, -1));
this.getContentPane().add(jLChange, new XYConstraints(171, 191, -1, -1));
table.fetch("select distinct HIMS_RoomInfo.RoomID as 客房ID,Class as 客房类型,RoomArea as 客房面积,BedNo as 床位数,StandardPri as 标准价,RebatePri as 折扣价,place as 客房位置,RoomIntro as 客房简介,Remark as 备注 from HIMS_RoomInfo,HIMS_RoomState WHERE HIMS_RoomInfo.RoomID = HIMS_RoomState.RoomID AND HIMS_RoomState.OnUser in ('2' , '4' , '6')");
table1.fetch("Select distinct RoomID as 客房ID,Class as 客房类型,RoomArea as 客房面积,BedNo as 床位数 ,StandardPri as 标准价,RebatePri as 折扣价,Place as 客房位置 ,RoomIntro as 客房信息,Remark as 备注 from HIMS_Register_CheckInRoom,HIMS_RoomInfo where HIMS_RoomInfo .RoomID in (select RoomName01 from HIMS_Register_CheckInRoom where RegRoomID = '" +
guestreg.RegisterID + "') or HIMS_RoomInfo.RoomID in (select RoomName02 from HIMS_Register_CheckInRoom where RegRoomID = '" +
guestreg.RegisterID + "') or HIMS_RoomInfo.RoomID in (select RoomName03 from HIMS_Register_CheckInRoom where RegRoomID = '" +
guestreg.RegisterID + "') or HIMS_RoomInfo.RoomID in (select RoomName04 from HIMS_Register_CheckInRoom where RegRoomID = '" +
guestreg.RegisterID + "') or HIMS_RoomInfo.RoomID in (select RoomName05 from HIMS_Register_CheckInRoom where RegRoomID = '" +
guestreg.RegisterID + "') or HIMS_RoomInfo.RoomID in (select RoomName06 from HIMS_Register_CheckInRoom where RegRoomID = '" +
guestreg.RegisterID + "') or HIMS_RoomInfo.RoomID in (select RoomName07 from HIMS_Register_CheckInRoom where RegRoomID = '" +
guestreg.RegisterID + "') or HIMS_RoomInfo.RoomID in (select RoomName08 from HIMS_Register_CheckInRoom where RegRoomID = '" +
guestreg.RegisterID + "');");
if (jTable1.getRowCount() == 0){
jBFinish.setEnabled(false);
}
}
public void jBFinish_actionPerformed(ActionEvent e) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String strSystemDate = format.format(date); //得到系统时间
strYesOrNot = "Y";
try {
connect1 = new DataConnect();
connect1.con1 = DriverManager.getConnection(connect1.url); //建立连接
connect1.stmt1 = connect1.con1.createStatement(); //创建语句
connect1.sql1 =
"SELECT CheckInType FROM HIMS_Register where RegisterID = '" +
guestreg.RegisterID + "'";
rs1l = connect1.stmt1.executeQuery(connect1.sql1);
while (rs1l.next()) {
String strCheckInType = rs1l.getString("CheckInType"); //入住类型
if (strCheckInType.equals("F")) {
connect2 = new DataConnect();
connect3 = new DataConnect();
connect2.con2 = DriverManager.getConnection(connect2.url); //建立连接
connect3.con3 = DriverManager.getConnection(connect3.url); //建立连接
connect2.stmt2 = connect2.con2.createStatement(); //创建语句
connect3.stmt3 = connect3.con3.createStatement(); //创建语句
connect2.sql2 =
" UPDATE HIMS_RoomState SET OnUser = '3', Reason = '此房间以被预定了!', StartDate= '" +
strSystemDate + "', EndDate = '"
+ strSystemDate + "' where RoomID = '" +
strNewRoomID +
"'";
connect3.sql3 =
" UPDATE HIMS_RoomState SET OnUser = '2', Reason = '此房间以可以使用!', StartDate= '" +
strSystemDate + "', EndDate = '"
+ strSystemDate + "' where RoomID = '" +
strOldRoomID +
"'";
connect2.stmt2.executeUpdate(connect2.sql2);
connect3.stmt3.executeUpdate(connect3.sql3);
JOptionPane.showMessageDialog(this, "操作成功!", "酒店信息管理系统警告",
JOptionPane.
INFORMATION_MESSAGE);
return;
} else if (strCheckInType.equals("N")) {
connect2 = new DataConnect();
connect3 = new DataConnect();
connect2.con2 = DriverManager.getConnection(connect2.url); //建立连接
connect3.con3 = DriverManager.getConnection(connect3.url); //建立连接
connect2.stmt2 = connect2.con2.createStatement(); //创建语句
connect3.stmt3 = connect3.con3.createStatement(); //创建语句
connect2.sql2 =
" UPDATE HIMS_RoomState SET OnUser = '3', Reason = '此房间以被入住!', StartDate= '" +
strSystemDate + "', EndDate = '"
+ strSystemDate + "' where RoomID = '" +
strNewRoomID +
"'";
connect3.sql3 =
" UPDATE HIMS_RoomState SET OnUser = '2', Reason = '此房间以可以使用!', StartDate= '" +
strSystemDate + "', EndDate = '"
+ strSystemDate + "' where RoomID = '" +
strOldRoomID +
"'";
connect2.stmt2.executeUpdate(connect2.sql2);
connect3.stmt3.executeUpdate(connect3.sql3);
JOptionPane.showMessageDialog(this, "操作成功!", "酒店信息管理系统警告",
JOptionPane.
INFORMATION_MESSAGE);
jBFinish.setEnabled(false);
return;
}
} //while
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
if (connect1.con1 != null) {
connect1.con1.close(); //关闭数据库
connect1.stmt1.close();
} //if
} catch (SQLException ex) {
System.out.println(ex);
} //catch
} //finally
}
public void jButton1_actionPerformed(ActionEvent e) {
this.setVisible(false);
}
public void jTable11_mouseClicked(MouseEvent e) {
strOldRoomID = jTable11.getValueAt(jTable11.getSelectedRow(), 0).
toString();
jTFOldRoomID.setText(strOldRoomID);
strYesOrNot = "N";
}
public void jTable1_mouseClicked(MouseEvent e) {
strNewRoomID = jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString();
jTFNewRoomID.setText(strNewRoomID);
strYesOrNot = "N";
}
}
class ChangeRoom_jTable1_mouseAdapter extends MouseAdapter {
private ChangeRoom adaptee;
ChangeRoom_jTable1_mouseAdapter(ChangeRoom adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jTable1_mouseClicked(e);
}
}
class ChangeRoom_jTable11_mouseAdapter extends MouseAdapter {
private ChangeRoom adaptee;
ChangeRoom_jTable11_mouseAdapter(ChangeRoom adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jTable11_mouseClicked(e);
}
}
class ChangeRoom_jButton1_actionAdapter implements ActionListener {
private ChangeRoom adaptee;
ChangeRoom_jButton1_actionAdapter(ChangeRoom adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class ChangeRoom_jBFinish_actionAdapter implements ActionListener {
private ChangeRoom adaptee;
ChangeRoom_jBFinish_actionAdapter(ChangeRoom adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jBFinish_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -