📄 sheji.java
字号:
}catch(SQLException sqle){sqle.printStackTrace();};
JOptionPane.showMessageDialog(this,"退订成功");
}
else if((condition.equals("1")||(condition.equals("0"))))
{
JOptionPane.showMessageDialog(this,"该房间没有被预定,不需要退订!");
}
close();
}
if(e.getSource()==b1)
{
this.setVisible(false);
this.dispose();
}
}catch(Exception ex){ex.printStackTrace();}
}
}
//入住登记
class GL_b3 extends JDialog implements ActionListener
{
JButton b1,b2,b3;
JTextField t1,t2,t3,t4,t5,t6,t8,t10,t11;
GL_b3()
{
JLabel l1=new JLabel("住户姓名");
JLabel l2=new JLabel("性别");
JLabel l3=new JLabel("年龄");
JLabel l4=new JLabel("身份证号码");
JLabel l5=new JLabel("电话");
JLabel l6=new JLabel("入住时间");
JLabel l8=new JLabel("房间号码");
JLabel l10=new JLabel("住房押金");
JLabel l11=new JLabel("会员帐号");
JPanel p=new JPanel();
JPanel p1=new JPanel();
t1=new JTextField(15);
t2=new JTextField(15);
t3=new JTextField(15);
t4=new JTextField(20);
t5=new JTextField(15);
t6=new JTextField(15);
t8=new JTextField(15);
t10=new JTextField(15);
t11=new JTextField(15);
b1=new JButton("普通住户登记");
b2=new JButton("会员入住登记");
b3=new JButton("退出");
p.setLayout(new GridLayout(9,2));
p.add(l1);p.add(t1);
p.add(l2);p.add(t2);
p.add(l3);p.add(t3);
p.add(l4);p.add(t4);
p.add(l5);p.add(t5);
p.add(l6);p.add(t6);
p.add(l8);p.add(t8);
p.add(l10);p.add(t10);
p.add(l11);p.add(t11);
p1.add(b1);
p1.add(b2);
p1.add(b3);
this.add(p,BorderLayout.CENTER);
this.add(p1,BorderLayout.SOUTH);
this.setTitle("入住登记");
this.setSize(400,500);
this.setLocation(500,400);
this.setVisible(true);
this.show(true);
this.setModal(true);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
try{
String condition=null;
connection();
if(e.getSource()==b1) //普通住户登记 信息存入数据库
{//////////////////////////////////////////// ///////////////////////////////////////////////
String sql="select condition from house where num='"+t8.getText()+"';";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
condition=rs.getString("condition");
}
condition=condition.trim();
System.out.print(condition);
if(condition.equals("0"))
{
try
{
String sql1;
sql1="insert into host values('"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"','"+t4.getText()+"','"+t5.getText()+"',"+Integer.parseInt(t6.getText())+",'"+"','"+t8.getText()+"','"+t10.getText()+"','"+t11.getText()+"','"+"');";
System.out.println(sql1);
stmt.executeUpdate(sql1);
sql1="Update house set people =people+1 where num='"+t8.getText()+"';";
stmt.executeUpdate(sql1);
sql1="Update house set condition='1' where num='"+t8.getText()+"';";
stmt.executeUpdate(sql1);
}catch(SQLException sqle){sqle.printStackTrace();};
JOptionPane.showMessageDialog(this,"登记成功");
}
else if((condition.equals("1"))||(condition.equals("2")))
{
JOptionPane.showMessageDialog(this,"对不起,此房间已有客户,请选择其它房间!");
}
}
else if (e.getSource()==b2) //会员入住登记 信息存入数据库
{ /////////////////////////////////////////////////////////////////////////////
String sql="select condition from house where num='"+t8.getText()+"';";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
condition=rs.getString("condition");
}
condition=condition.trim();
System.out.print(condition);
if(condition.equals("0"))
{
if((t11.getText()).equals(""))
{
JOptionPane.showMessageDialog(this,"请输入会员帐号!");
}
else
{
try
{
String sql2;
sql2="insert into host values('"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"','"+t4.getText()+"','"+t5.getText()+"',"+Integer.parseInt(t6.getText())+",'"+"','"+t8.getText()+"','"+t10.getText()+"','"+t11.getText()+"','"+"');";
System.out.println(sql2);
stmt.executeUpdate(sql2);
sql2="Update house set people =people+1 where num='"+t8.getText()+"';";
stmt.executeUpdate(sql2);
sql2="Update house set condition='1' where num='"+t8.getText()+"';";
stmt.executeUpdate(sql2);
}catch(SQLException sqle){sqle.printStackTrace();};
JOptionPane.showMessageDialog(this,"登记成功");
}
}
else if((condition.equals("1"))||(condition.equals("2")))
{
JOptionPane.showMessageDialog(this,"对不起,此房间已有客户,请选择其它房间!");
}
///////////////////////////////////////////////
}
else if (e.getSource()==b3)
{
this.setVisible(false);
this.dispose();
}
}catch(Exception ex){ex.printStackTrace();}
close();
}
}
//退房结帐
class GL_b4 extends JDialog implements ActionListener
{
JButton b,b1=null;
JTextField t1,t2,t3,t4,t5;
GL_b4()
{
JLabel l1=new JLabel("待退房号");
JLabel l3=new JLabel("客户姓名");
JLabel l2=new JLabel("退房日期");
JLabel l4=new JLabel("会员帐号");
JLabel l5=new JLabel("结帐金额");
t1=new JTextField(15);
t2=new JTextField(15);
t3=new JTextField(15);
t4=new JTextField(15);
t5=new JTextField(15);
b=new JButton("退房结帐");
b1=new JButton("退出");
this.setLayout(new GridLayout(6,2));
this.add(l1);this.add(t1);
this.add(l3);this.add(t3);
this.add(l2);this.add(t2);
this.add(l4);this.add(t4);
this.add(l5);this.add(t5);
this.add(b);this.add(b1);
this.setTitle("退房结账管理");
this.setSize(300,200);
this.setLocation(500,400);
this.setVisible(true);
this.show(true);
this.setModal(true);
b.addActionListener(this);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
try{
if(e.getSource()==b)//退房结帐
{
if(!(t4.getText()).equals(""))//会员帐号不空
{
//退房结帐 信息存入数据库
connection();
int money;
String sql;
String gtime;
int ctime;
ResultSet rs;
sql="Update host set gtime='"+t2.getText()+"' where num='"+t1.getText()+"' and name='"+t3.getText()+"'";
stmt.executeUpdate(sql);
sql="Update house set condition='0' where num='"+t1.getText()+"';";
stmt.executeUpdate(sql);
sql="select ctime,gtime from host where num='"+t1.getText()+"' and name='"+t3.getText()+"'";
rs=stmt.executeQuery(sql);
while(rs.next())
{
ctime=rs.getInt("ctime");
gtime=rs.getString("gtime");
gtime=gtime.trim();
int time2=Integer.parseInt(gtime);
money=80*(time2-ctime);
t5.setText(""+money);
}
sql="Update host set jiezhang='"+t5.getText()+"' where num='"+t1.getText()+"' and name='"+t3.getText()+"';";
stmt.executeUpdate(sql);
new CleanDialog();
close();
}
else if((t4.getText()).equals("")) //会员号码空
{
connection();
int money;
String sql;
String gtime;
int ctime;
ResultSet rs;
sql="Update host set gtime='"+t2.getText()+"' where num='"+t1.getText()+"' and name='"+t3.getText()+"' ;";
stmt.executeUpdate(sql);
sql="Update house set condition='0' where num='"+t1.getText()+"';";
stmt.executeUpdate(sql);
sql="select ctime,gtime from host where num='"+t1.getText()+"' and name='"+t3.getText()+"'";
rs=stmt.executeQuery(sql);
while(rs.next())
{
ctime=rs.getInt("ctime");
gtime=rs.getString("gtime");
gtime=gtime.trim();
// double time1=Double.parseDouble(ctime);
int time2=Integer.parseInt(gtime);
money=100*(time2-ctime);
t5.setText(""+money);
}
sql="Update host set jiezhang='"+t5.getText()+"' where num='"+t1.getText()+"' and name='"+t3.getText()+"';";
stmt.executeUpdate(sql);
new CleanDialog();
close();
}
}
if(e.getSource()==b1)
{
this.setVisible(false);
this.dispose();
}
}catch(Exception ex){ex.printStackTrace();}
}
//提示打扫房间的对话框
class CleanDialog extends JDialog implements ActionListener
{
JButton b;
CleanDialog()
{
JOptionPane.showMessageDialog(this,"退房成功");
this.setLayout(new FlowLayout());
JLabel l1=new JLabel(t1.getText()+"房间已退房,请及时清扫");
b=new JButton("确定");
this.add(l1);
this.add(b);
this.setSize(400,70);
this.setLocation(300,300);
this.show(true);
this.setModal(true);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b)
{
this.setVisible(false);
this.dispose();
}
}
}
}
//客户信息查询
class GL_b5 extends JDialog implements ActionListener
{
JButton b1,b2,b3,b4,b5;
GL_b5()
{
b1=new JButton("按姓名查询");
b2=new JButton("按房号查询");
b3=new JButton("按入住日期查询");
b4=new JButton("按离店日期查询");
b5=new JButton("退出");
this.setLayout(new GridLayout(5,1));
this.add(b1);
this.add(b2);
this.add(b3);
this.add(b4);
this.add(b5);
this.setTitle("住户信息查询");
this.setSize(300,200);
this.setLocation(500,400);
this.setVisible(true);
this.show(true);
this.setModal(true);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
try{
if(e.getSource()==b1)
{
new GL_b5_b1();
//根据姓名查询 信息存入数据库
}
else if (e.getSource()==b2)
{
new GL_b5_b2();
//根据房号查询 信息存入数据库
}
else if (e.getSource()==b3)
{
new GL_b5_b3();
//根据入住日期查询 信息存入数据库
}
else if (e.getSource()==b4)
{
new GL_b5_b4();
//根据退房离店日期查询 信息存入数据库
}
else if (e.getSource()==b5)
{
this.setVisible(false);
this.dispose();
}
}catch(Exception ex){ex.printStackTrace();}
}
}
//房态查询
class GL_b6 extends JDialog implements ActionListener
{
JButton b1,b2,b3,b4,b5,b6;
JTextArea ta;
GL_b6()
{
JPanel p=new JPanel();
p.setLayout(new FlowLayout());
b1=new JButton("已预定房间查询");
b2=new JButton("已入住房间查询");
b4=new JButton("空房查询");
b6=new JButton("退出");
ta=new JTextArea(50,50);
p.add(b1,FlowLayout.LEFT);
p.add(b2,FlowLayout.LEFT);
p.add(b4,FlowLayout.LEFT);
p.add(b6,FlowLayout.LEFT);
b1.addActionListener(this);
b2.addActionListener(this);
b4.addActionListener(this);
b6.addActionListener(this);
this.add(p,BorderLayout.NORTH);
this.add(ta,BorderLayout.CENTER);
this.setTitle("房态查询");
this.setSize(700,300);
this.setLocation(500,400);
this.setVisible(true);
this.show(true);
this.setModal(true);
}
public void actionPerformed(ActionEvent e)
{
try{
String num;
if(e.getSource()==b1)
{
//已预定房查询 结果显示在文本区
try{
connection();
ResultSet rs;
String sql;
ta.setText("");
ta.append("已预定的房间有:"+"\n");
sql="Select num from house where condition='2';";
rs=stmt.executeQuery(sql);
while(rs.next())
{
num=rs.getString("num");
ta.append(num+"\t");
}
rs.close();
close();
}catch(SQLException sql){sql.printStackTrace();};
}
else if (e.getSource()==b2)
{
//入住房查询 结果显示在文本区
try{
connection();
ResultSet rs;
String sql;
ta.setText("");
ta.append("已入住的房间有:"+"\n");
sql="Select num from house where condition='1';";
rs=stmt.executeQuery(sql);
while(rs.next())
{
num=rs.getString("num");
ta.append( num+"\t");
}
rs.close();
close();
}catch(SQLException sql){sql.printStackTrace();};
}
else if (e.getSource()==b4)
{
//空房查询 结果显示在文本区
try{
connection();
ResultSet rs;
String sql;
ta.setText("");
ta.append("空房间有:"+"\n");
sql="Select num from house where condition='0';";
rs=stmt.executeQuery(sql);
while(rs.next())
{
num=rs.getString("num");
ta.append( num+"\t");
}
rs.close();
close();
}catch(SQLException sql){sql.printStackTrace();};
}
else if (e.getSource()==b6)
{
this.setVisible(false);
this.dispose();
}
}catch(Exception ex){ex.printStackTrace();}
}
}
//不同方式查询住户信息 的按钮监听
//按姓名查
class GL_b5_b1 extends JDialog implements ActionListener
{
JButton b,b1;
JTextField t;
JTextArea ta;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -