⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sheji.java

📁 简单的客房管理系统 不完善 欢迎参考指点 统计部分没有完成
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.sql.*;
//登陆界面
class sheji extends JFrame implements ActionListener
{
	Connection con;
    Statement stmt; 
    String url; 
    JFrame f; 
    JButton gb1,gb2,cb1,cb2;
    JTextField gt1,ct1;
    JPasswordField gt2,ct2;
	sheji()
	{
		f=new JFrame ("酒店客房管理系统登录");
		f.setSize(350,250);
		f.setLocation(500,300);
		JLabel la=new JLabel("酒店客房管理系统");
		la.setFont(new Font("TimesRoman",Font.BOLD,25));
		JButton b1=new JButton("管理员登录");
		JButton b2=new JButton("操作员登录");
		JButton b3=new JButton("退出");
		f.setLayout(new GridLayout(4,1));
	    Panel p1=new Panel();   
	    Panel p2=new Panel();
	    Panel p3=new Panel(); 
	    Panel p4=new Panel();
	    p1.add(la);
	    p2.add(b1);
	    p3.add(b2);
	    p4.add(b3);
		f.add(p1);
		f.add(p2);
		f.add(p3);
		f.add(p4);
		b1.addActionListener(this);
		b2.addActionListener(this);
		b3.addActionListener(this);
		f.setVisible(true);
		f.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});
	}
	public void connection()
	{
		try
			{
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				
		    }catch(java.lang.ClassNotFoundException ef) 
			 {
		        System.err.print("ClassNotFoundException: ");
		     }
			try
			{
				String url ="jdbc:odbc:stu";
				con=DriverManager.getConnection(url,"system","system");
			    stmt=con.createStatement();
				
			}catch(SQLException ex)
			 {
	            System.err.println("SQLException: " + ex.getMessage()+" 连接异常");  
	         }
	}
	public void close()
	{
		try
		{
			stmt.close();
			con.close();
		}catch(SQLException ex)
		{
			System.err.println("SQLException:"+ex.getMessage());
		}
	}
	public static void main(String []args)
	{
		new sheji();
	}
	
	public void actionPerformed(ActionEvent e)
	{
		try
		{			
	        if(e.getActionCommand()=="管理员登录")
	        {
	        	JDialog di=new JDialog();
	        	di.setTitle("管理员登录");
		        di.setSize(300,150);
	        	di.setLocation(150,200);
	        	JLabel la1=new JLabel("用户名");
	        	JLabel la2=new JLabel("密码");
	        	gt1=new JTextField(50);
	            gt2=new JPasswordField();
	        	gb1=new JButton("登录");
	        	gb2=new JButton("退出");
	        	Panel p=new Panel();
	        	Panel p1=new Panel();
	        	di.setLayout(new GridLayout(2,1));
	        	p.setLayout(new GridLayout(2,2));
	        	di.add(p);
	        	di.add(p1);
	        	p.add(la1);
	        	p.add(gt1);
	        	p.add(la2);
	        	p.add(gt2);
	        	p1.add(gb1);
	        	p1.add(gb2);
	        	gb1.addActionListener(this);
	        	gb2.addActionListener(this);
	        	di.show(true);
	        	di.setModal(true);   	  
	        }	        
		    if(e.getSource()==gb1)  //如果点击了登录按钮
			{
				try{
                    connection();
					String sql;
					String str1=new String();
					String str2=new String();
					ResultSet rs; 
					sql="select * from userde where name='"+gt1.getText()+"'";
					rs=stmt.executeQuery(sql);
					while(rs.next())
					{
						str1=rs.getString(1);
						str2=rs.getString(2);
					}
					str1=str1.trim();
					str2=str2.trim();		
					rs.close();
					if(str1.length()!=0)
					{
						if(str2.equals(gt2.getText()))// 密码正确,可以进行查询了
						{ 
						   new GL_denglu();
						}
						else 
						{
							JOptionPane.showMessageDialog(this,"您输入的密码错误,请重新输入!");
							gt1.setText("");
					    	gt2.setText("");
						}
					}
					else
					{
						JOptionPane.showMessageDialog(this,"您输入的用户名或密码错误,请重新输入!");
						gt1.setText("");
						gt2.setText("");
					}
					close();
			       }catch(Exception e1){e1.printStackTrace();
			       	
			       }
		    }
	        if(e.getSource()==gb2) 
	        {
	        	this.setVisible(false);
	        	this.dispose();
	        }
	        if(e.getActionCommand()=="操作员登录") 
	        {
	        	JDialog di=new JDialog();
	        	di.setTitle("操作员登录");
		        di.setSize(300,150);
	        	di.setLocation(150,200);
	        	JLabel la1=new JLabel("用户名");
	        	JLabel la2=new JLabel("密码");
	        	ct1=new JTextField(50);
	        	ct2=new JPasswordField();
	        	cb1=new JButton("登录");
	        	cb2=new JButton("退出");
	        	JPanel p=new JPanel();
	        	JPanel p1=new JPanel();
	        	p.setLayout(new GridLayout(2,2));
	        	di.setLayout(new GridLayout(2,1));
	        	di.add(p);
	        	di.add(p1);
	        	p.add(la1);
	        	p.add(ct1);
	        	p.add(la2);
	        	p.add(ct2);
	        	p1.add(cb1);
	        	p1.add(cb2);
	        	cb1.addActionListener(this);
	        	cb2.addActionListener(this);
	        	di.show(true);
	        	di.setModal(true);       	
	        }
	        if(e.getSource()==cb1)  //如果点击了登录按钮
			{
				try{
                    connection();
					String sql;
					String str1=new String();
					String str2=new String();
					ResultSet rs; 
					sql="select * from usercao where name='"+ct1.getText()+"'";
					rs=stmt.executeQuery(sql);
					while(rs.next())
					{
						str1=rs.getString(1);
						str2=rs.getString(2);
					}
					str1=str1.trim();
					str2=str2.trim();		
					rs.close();
					if(str1.length()!=0)
					{
						if(str2.equals(ct2.getText()))// 密码正确,可以进行查询了
						{ 
						   new CZ_denglu();
						}
						else 
						{
							JOptionPane.showMessageDialog(this,"您输入的密码错误,请重新输入!");
							gt1.setText("");
					    	gt2.setText("");
						}
					}
					else
					{
						JOptionPane.showMessageDialog(this,"您输入的用户名或密码错误,请重新输入!");
						gt1.setText("");
						gt2.setText("");
					}
					close();
			       }catch(Exception e1){e1.printStackTrace();
			       	
			       }
		    }
	        if(e.getSource()==cb2) 
	        {
	        	this.setVisible(false);
	        	this.dispose();
	        }
	        if(e.getActionCommand()=="退出") 
	        {
	        	System.exit(0);
	        }
	       
		}catch(Exception ex){ex.printStackTrace();}		
	}
 
//管理员登录的管理界面
class GL_denglu extends JDialog implements ActionListener
{
	JButton b1,b2,b3,b4,b5,b6,b7;
	GL_denglu()
	{
		JLabel la=new JLabel("欢迎进入酒店客房管理系统");
		la.setFont(new Font("TimesRoman",Font.BOLD,35));
		JPanel p1=new JPanel();
		JPanel p2=new JPanel();
		b1=new JButton("预定客房");
		b2=new JButton("退订客房");
		b3=new JButton("入住客房");
		b4=new JButton("退房结账");
		b5=new JButton("客户信息查询");
		b6=new JButton("房态查询");
		b7=new JButton("退出");
		p2.setLayout(new GridLayout(14,1));
		p1.add(la);
		p2.add(b1);p2.add(new JLabel());
		p2.add(b2);p2.add(new JLabel());
		p2.add(b3);p2.add(new JLabel());
		p2.add(b4);p2.add(new JLabel());
		p2.add(b5);p2.add(new JLabel());
		p2.add(b6);p2.add(new JLabel());
		p2.add(b7);p2.add(new JLabel());
		this.add(p1,BorderLayout.NORTH);
		this.add(p2,BorderLayout.WEST);
		this.setTitle("管理员管理");
		this.setSize(550,400);
		this.setLocation(300,300);
		this.setVisible(true);
		this.show(true);
		this.setModal(true);
		b1.addActionListener(this);
		b2.addActionListener(this);
		b3.addActionListener(this);
		b4.addActionListener(this);
		b5.addActionListener(this);
		b6.addActionListener(this);
		b7.addActionListener(this);
	}
	public void actionPerformed(ActionEvent e)
	{
		try{
			if(e.getSource()==b1)
			{
				new GL_b1();
			}
			else if(e.getSource()==b2)
			{
				new GL_b2();
			}
			else if(e.getSource()==b3)
			{
				new GL_b3();
			}
			else if(e.getSource()==b4)
			{
				new GL_b4();
			}
			else if(e.getSource()==b5)
			{
				new GL_b5();
			}
			else if(e.getSource()==b6)
			{
				new GL_b6();
			}
			else if(e.getSource()==b7)
			{
				this.setVisible(false);
				this.dispose();
			}
		}catch(Exception ex){ex.printStackTrace();}
	}
	
}
//管理员按钮监听具体实现
//预定客房
class GL_b1 extends JDialog implements ActionListener
{
	JButton b,b1;
	JTextField t1,t2,t3,t4,t5,t6,t8;
	GL_b1()
	{
		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("房间号码");
	    t1=new JTextField(15);
	    t2=new JTextField(15);
	    t3=new JTextField(15);
	    t4=new JTextField(20);
	    t5=new JTextField(15);
	    t6=new JTextField(20);
	    t8=new JTextField(15);
    	b=new JButton("登记");
    	b1=new JButton("退出");
    	this.setLayout(new GridLayout(8,2));
    	this.add(l1);this.add(t1);
    	this.add(l2);this.add(t2);
    	this.add(l3);this.add(t3);
    	this.add(l4);this.add(t4);
    	this.add(l5);this.add(t5);
    	this.add(l6);this.add(t6);
	    this.add(l8);this.add(t8);
    	this.add(b); this.add(b1);
    	this.setTitle("房间预定管理");
    	this.setSize(300,300);
    	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)  //登记按钮
			{	//预定信息存入数据库
				connection();
			    String condition=null;
				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 sqll;
	        	    sqll="insert into host values('"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"','"+t4.getText()+"','"+t5.getText()+"',"+Integer.parseInt(t6.getText())+",'"+"','"+t8.getText()+"','"+"','"+"','"+"');";  
	                System.out.println(sqll);
			        stmt.executeUpdate(sqll); 
			        sqll="Update house  set condition='2' where num='"+t8.getText()+"';";			        
			        stmt.executeUpdate(sqll);
			        			    
	        	   }catch(SQLException sqle){sqle.printStackTrace();};	
				   JOptionPane.showMessageDialog(this,"预订成功");
				}
				else if((condition.equals("1")||(condition.equals("2"))))
				{
					JOptionPane.showMessageDialog(this,"对不起,次房间已被占用,请选择其他房间!");
				}
				close();
			}
			else if(e.getSource()==b1)
			{
				this.setVisible(false);
				this.dispose();
			} 
		}catch(Exception ex){ex.printStackTrace();}
	}
}
//退订客房 
class GL_b2 extends JDialog implements ActionListener
{
	JButton b,b1;
	JTextField t1,t2,t3;
	GL_b2()
	{
		JLabel l1=new JLabel("姓名");
		JLabel l2=new JLabel("客房号码");
		JLabel l3=new JLabel("退订日期");
		t1=new JTextField(15);
		t2=new JTextField(15);
	    t3=new JTextField(15);
		b=new JButton("退订");
		b1=new JButton("退出");
		this.setLayout(new GridLayout(4,2));
    	this.add(l1);this.add(t1);
    	this.add(l2);this.add(t2);
    	this.add(l3);this.add(t3);
    	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)
			{String sql; 
				//退定信息存入数据库
				connection();
			    String condition=null;
				sql="select condition from house where num='"+t2.getText()+"';";
	    		ResultSet rs=stmt.executeQuery(sql);
	        	while(rs.next())
  			    {
  			  	      condition=rs.getString("condition");    
		        }
		        condition=condition.trim();
		        System.out.print(condition); 
		        if(condition.equals("2"))
		        {
		        	try
	              {
	              	
	            	      	    
		        	sql="Update house set condition='0'  where num='"+t2.getText()+"';";
		        	stmt.executeUpdate(sql);
		        	sql="Update host set gtime='"+t3.getText()+"退定'  where num='"+t2.getText()+"';";
		        	stmt.executeUpdate(sql);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -