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

📄 house.java

📁 面向对象课程设计之房屋销售管理系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		con.setLayout(new BorderLayout());
		label=new JLabel("销售编号");
		text=new JTextField("输入删除的销售编号",10);
		button1=new JButton("删除");
		button2=new JButton("取消");
		p=new JPanel();
		p.add(label);
		p.add(text);
		p.add(button1);
		button1.addActionListener(this);
		p.add(button2);
		button2.addActionListener(this);
		con.add("Center",p);
		setVisible(true);
		setBounds(250,250,400,80);
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==button1)
		{
			Connection conn;
            Statement sql; 
            ResultSet rs;
		    int sum=0;
			String sell_number=text.getText().toString().trim();
			if(sell_number.equals(""))
			{JOptionPane.showMessageDialog(null,"删除的销售编号不能为空!");}
			else
			{
				try {  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
                catch(ClassNotFoundException ee)
                     { JOptionPane.showMessageDialog(null,ee);}
                try {
					conn=DriverManager.getConnection("jdbc:odbc:house","","");
                    sql=conn.createStatement();
                     rs=sql.executeQuery("SELECT * FROM house_sell where 销售编号='"+sell_number+"'");
                     while(rs.next())
					      {sum++;}
				     if(sum==0){JOptionPane.showMessageDialog(null,"没有你想删除的销售信息!");}
				     else
					     {
					       sql.executeUpdate("DELETE * FROM house_sell WHERE 销售编号='"+sell_number+"'");
						   setVisible(false);
					        JOptionPane.showMessageDialog(null,"你已成功删除销售信息");
					      }
				         conn.close();
				}
				catch(SQLException ex) 
                      {  JOptionPane.showMessageDialog(null,ex);}
		       }
			}
		else
			{setVisible(false);}
	}
}

//////////////////////添加房屋信息/////////////////////
class Add_House extends JFrame implements ActionListener
{
	private JLabel house_id,house_address,house_direct,house_kind,house_area,house_value;
	private JTextField id,address,direct,kind,area,value;
	private JPanel p1,p2,p3,p4;
	private JButton btn1,btn2;
	Container con=getContentPane();
	Add_House(String s)
	{
		super(s);
		house_id=new JLabel("房屋编号");
		house_address=new JLabel("房屋地址");
		house_direct=new JLabel("房屋朝向");
		house_kind=new JLabel("房屋类型");
		house_area=new JLabel("房屋面积");
		house_value=new JLabel("房屋价格");
		id=new JTextField(10);
		address=new JTextField(10);
		direct=new JTextField(10);
		kind=new JTextField(10);
		area=new JTextField(10);
		value=new JTextField(10);
		p1=new JPanel();
		p2=new JPanel();
		p3=new JPanel();
		p4=new JPanel();
		btn1=new JButton("保存");
		btn2=new JButton("取消");
		con.setLayout(new FlowLayout());
		p1.add(house_id);
		p1.add(id);
		p1.add(house_address);
		p1.add(address);
		p2.add(house_direct);
		p2.add(direct);
		p2.add(house_kind);
		p2.add(kind);
		p3.add(house_area);
		p3.add(area);
		p3.add(house_value);
		p3.add(value);
		p4.add(btn1);
		btn1.addActionListener(this);
		p4.add(btn2);
		btn2.addActionListener(this);
		con.add(p1);
		con.add(p2);
		con.add(p3);
		con.add(p4);
		pack();
		setBounds(200,200,400,200);
		setVisible(true);
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e)
            {  setVisible(false);}
         });                       //窗口关闭事件,匿名类
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==btn1)
		{
			Connection conn;
            Statement sql; 
            ResultSet rs;
		    String s1=id.getText().toString().trim();
			String s2=address.getText().toString().trim();
			String s3=direct.getText().toString().trim();
			String s4=kind.getText().toString().trim();
			String s5=area.getText().toString().trim();
			String s6=value.getText().toString().trim();
			int sum=0;
			if(s1.equals(""))
			{JOptionPane.showMessageDialog(null,"房屋编号不能为空!");}
			try {  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
          }
     catch(ClassNotFoundException ee)
          {  System.out.println(""+ee);
          }
      try {  conn=DriverManager.getConnection("jdbc:odbc:house","","");
             sql=conn.createStatement();
             rs=sql.executeQuery("SELECT * FROM house where 房屋编号='"+s1+"'");
             while(rs.next())
             {        
			   sum++;
             }
			 if(sum==1)
		     {
				 JOptionPane.showMessageDialog(null,"房屋编号已经存在,请使用其他编号!");
			 }
			 else
		     {
				 sql.executeUpdate("INSERT INTO house VALUES('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"','"+s6+"')");
                 setVisible(false);
				 JOptionPane.showMessageDialog(null,"你已经成功添加房屋信息!");
			 }
			 conn.close();		
		}
		         catch(SQLException ex) 
           {  System.out.println(ex);
           }		
		}
		if(e.getSource()==btn2)
		{
			setVisible(false);
		}
	}
}
//////////////////查询信息/////////////
class Querytest extends Frame implements ItemListener,ActionListener
{
	Label label1,label2;
	Choice choice1,choice2;
	TextArea te;
	TextField text;
	Button btn1;
	int sum=0;
	Querytest(String s)
	{
		super(s);
		setLayout(new BorderLayout());		//窗口布局为BorderLayout,东、西、南、北、中
		text=new TextField(8);
		te=new TextArea();
		Panel p1=new Panel();
		Panel p2=new Panel();
		btn1=new Button("查询");
		choice1=new Choice();
		choice1.add("房屋信息表");
		choice1.add("销售信息表");
		choice1.addItemListener(this);//增加ItemListener监听器
		choice2=new Choice();
		choice2.add("房屋编号");
		choice2.add("房屋地址");
		choice2.add("房屋朝向");
		choice2.add("房屋面积");		
		label1=new Label("请选择表");
		label2=new Label("请选择关键字");
        p1.add(label1);
		p1.add(choice1);
		p1.add(label2);
		p1.add(choice2);
		p1.add(text);
		p1.add(btn1);
		btn1.addActionListener(this);//为按钮增加一个动作监听器
		p2.add(te);
		this.add(p1,BorderLayout.NORTH);
		this.add(p2,BorderLayout.CENTER);
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e)
            {  setVisible(false);
			}
         });
		setVisible(true);
		pack();	
	}
	public void itemStateChanged(ItemEvent e)
	{
		if(choice1.getSelectedIndex()==0)
		{
		choice2.removeAll();
		choice2.add("房屋编号");
		choice2.add("房屋地址");
		choice2.add("房屋朝向");
		choice2.add("房屋面积");
		}
		else
			{
			choice2.removeAll();
		    choice2.add("销售编号");
		    choice2.add("交易日期");
			}
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==btn1)
		{
			Connection conn;           
            Statement sql; 
            ResultSet rs;
			String string=text.getText().toString().trim();
	        try {  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}//使用forName()建立JDBC-ODBC桥接器,有可能发生异常,所以捕获异常
            catch(ClassNotFoundException ee)
                {  System.out.println(""+ee);}
			if(choice1.getSelectedIndex()==0)
			{
				if(choice1.getSelectedItem()=="房屋信息表")
				{
					if(choice2.getSelectedIndex()==0)
				{
					te.setText("");
					try {  conn=DriverManager.getConnection("jdbc:odbc:house","","");//创建连接与指定的数据库
                           sql=conn.createStatement();  //创建Statement对象,用来发送SQL语句,并得到SQL语句执行的接果
                           rs=sql.executeQuery("SELECT * FROM house WHERE 房屋编号='"+string+"'");//创建结果集
		              	   sum=0;
			                       while(rs.next())
	                                 {    
			                           te.append("房屋编号: "+rs.getString(1)+"    ");
	        	                       te.append("房屋地址: "+rs.getString(2)+"    ");
	        	                       te.append("房屋朝向: "+rs.getString(3)+"    ");
	        	                       te.append("房屋类型: "+rs.getString(4)+"    ");
	        	                       te.append("面积(平方米): "+rs.getString(5)+"   ");
	        	                       te.append("价格(元/平米): "+rs.getString(6)+"    ");
				                       te.append("\n");
									   sum++;
				                      }
									  if(sum==0)
						             {te.setText("");te.append("数据库中的记录为0!");}
				                      conn.close();
                          }
                        catch(SQLException ex) 
                             {  System.out.println(ex);}
				}
				if(choice2.getSelectedIndex()==1)
				{
					te.setText("");
					try {  conn=DriverManager.getConnection("jdbc:odbc:house","","");
                           sql=conn.createStatement();
                           rs=sql.executeQuery("SELECT * FROM house WHERE 房屋地址 like '"+text.getText().toString().trim()+"%'");
		                   sum=0;
			                       while(rs.next())
	                                 {    
			                           te.append("房屋编号: "+rs.getString(1)+"    ");
	        	                       te.append("房屋地址: "+rs.getString(2)+"    ");
	        	                       te.append("房屋朝向: "+rs.getString(3)+"    ");
	        	                       te.append("房屋类型: "+rs.getString(4)+"    ");
	        	                       te.append("面积(平方米): "+rs.getString(5)+"   ");
	        	                       te.append("价格(元/平米): "+rs.getString(6)+"    ");
				                       te.append("\n");
									   sum++;
				                      }
									  if(sum==0)
						             {te.setText("");te.append("数据库中的记录为0!");}
				                      conn.close();
                          }
                        catch(SQLException ex) 
                             {  System.out.println(ex);}
				}
				if(choice2.getSelectedIndex()==2)
				{
					te.setText("");
					try {  conn=DriverManager.getConnection("jdbc:odbc:house","","");
                           sql=conn.createStatement();
                           rs=sql.executeQuery("SELECT * FROM house WHERE 房屋朝向='"+text.getText().toString().trim()+"'");
		                   sum=0;
			                       while(rs.next())
	                                 {    
			                           te.append("房屋编号: "+rs.getString(1)+"    ");
	        	                       te.append("房屋地址: "+rs.getString(2)+"    ");
	        	                       te.append("房屋朝向: "+rs.getString(3)+"    ");
	        	                       te.append("房屋类型: "+rs.getString(4)+"    ");
	        	                       te.append("面积(平方米): "+rs.getString(5)+"   ");
	        	                       te.append("价格(元/平米): "+rs.getString(6)+"    ");
				                       te.append("\n");
									   sum++;
				                      }
									  if(sum==0)
						             {te.setText("");te.append("数据库中的记录为0!");}
				                      conn.close();
                          }
                        catch(SQLException ex) 
                             {  System.out.println(ex);}
				}
				if(choice2.getSelectedIndex()==4)
				{
					te.setText("");
					try {  conn=DriverManager.getConnection("jdbc:odbc:house","","");
                           sql=conn.createStatement();
                           rs=sql.executeQuery("SELECT * FROM house WHERE 房屋面积='"+text.getText().toString().trim()+"'");
		                   sum=0;
			                       while(rs.next())
	                                 {    
			                           te.append("房屋编号: "+rs.getString(1)+"    ");
	        	                       te.append("房屋地址: "+rs.getString(2)+"    ");
	        	                       te.append("房屋朝向: "+rs.getString(3)+"    ");
	        	                       te.append("房屋类型: "+rs.getString(4)+"    ");
	        	                       te.append("面积(平方米): "+rs.getString(5)+"   ");
	        	                       te.append("价格(元/平米): "+rs.getString(6)+"    ");
				                       te.append("\n");
									   sum++;
				                      }
									  if(sum==0)
						             {te.setText("");te.append("数据库中的记录为0!");}
				                      conn.close();
                          }
                        catch(SQLException ex) 
                             {  System.out.println(ex);}
				}
				}
			}
			else
			{
				if(choice2.getSelectedIndex()==0)
				{
					te.setText("");
					try {  conn=DriverManager.getConnection("jdbc:odbc:house","","");
                           sql=conn.createStatement();
                           rs=sql.executeQuery("SELECT * FROM house_sell WHERE 销售编号='"+text.getText().toString().trim()+"'");
		                   sum=0;
			                       while(rs.next())
	                                 {    
			                           te.append("销售编号: "+rs.getString(1)+"    ");
	        	                       te.append("房屋编号: "+rs.getString(2)+"    ");
	        	                       te.append("交易价格: "+rs.getString(3)+"    ");
	        	                       te.append("交易日期: "+rs.getString(4)+"    ");
	        	                       te.append("购买者 : "+rs.getString(5)+"    ");
	        	                       te.append("销售者 : "+rs.getString(6)+"    ");
				                       te.append("\n");
									   sum++;
				                      }
									  if(sum==0)
						             {te.setText("");te.append("数据库中的记录为0!");}
				                      conn.close();
                          }
                        catch(SQLException ex) 
                             {  System.out.println(ex);}
				}
				else
				{
					if(choice2.getSelectedIndex()==1)
				    {
						te.setText("");
					  try {  conn=DriverManager.getConnection("jdbc:odbc:house","","");
                           sql=conn.createStatement();
                           rs=sql.executeQuery("SELECT * FROM house_sell WHERE 交易日期='"+text.getText().toString().trim()+"'");
		                   sum=0;
			                       while(rs.next())
	                                 {    
			                           te.append("销售编号:   "+rs.getString(1)+"  ");
	        	                       te.append("房屋编号:   "+rs.getString(2)+"  ");
	        	                       te.append("交易价格:   "+rs.getString(3)+"  ");
	        	                       te.append("交易日期:   "+rs.getString(4)+"  ");
	        	                       te.append("购买者  :   "+rs.getString(5)+"  ");
	        	                       te.append("销售者  :   "+rs.getString(6)+"  ");
				                       te.append("\n");
									   sum++;
				                      }
									  if(sum==0)
						             {te.setText("");te.append("数据库中的记录为0!");}
				                      conn.close();
                          }
                        catch(SQLException ex) 
                             {  System.out.println(ex);}
				}
				}
			}
		}
	}
}

///////////////主类//////////////////
public class  House 
{
	public static void main(String[] args) 
	{
		  Load load=new Load("登录界面");
	}
}

⌨️ 快捷键说明

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