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

📄 hetongchoice.java

📁 业务信息管理平台,适用于企业内部信息管理,合同管理
💻 JAVA
字号:

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;

public  class  HetongChoice extends JFrame implements ActionListener,ItemListener{
	
	private	DefaultTableModel philosophers;
  	private JTable table;
	private JScrollPane jspn;
	private	JTextField kehumingt;
	private	JButton chanxunkehu,xianshi;
	private	Choice kehumingChoice;
	private	Container con=null;  
	private	Font font;
	private	String kehumingcheng,name,truename;
	private	JCheckBox xinghao,shoukuanren,qiandingren,qiandingriqi,hetongzonge,hetongqixian,zhifuriqi,zhifujine,zhifuyue;

	public HetongChoice(String kehumingcheng,String name,String truename){
		super("客户支付记录详单");
		this.kehumingcheng=kehumingcheng;
		this.name=name;
		this.truename=truename;
		
		int iii=(int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()); 
		
		font=new java.awt.Font("宋体",Font.PLAIN,14); 
		Box box1=Box.createHorizontalBox();      //盒子 
		kehumingt=new JTextField(10);
		chanxunkehu=new JButton("查询客户");
		xianshi=new JButton("显示查询结果");
		xianshi.addActionListener(this);
		chanxunkehu.addActionListener(this);
		kehumingChoice=new Choice();
		kehumingChoice.add("                                                   ");
		
		
   		box1.add(kehumingt);
   		box1.add(chanxunkehu);
   		box1.add(kehumingChoice);
  
  		Box box2=Box.createHorizontalBox();
  		xinghao=new JCheckBox("产品型号");
  		shoukuanren=new JCheckBox("收 款 人");
  		qiandingren=new JCheckBox("签 订 人");
  		
  		hetongzonge=new JCheckBox("合同总额");
  		zhifujine=new JCheckBox("支付金额");
  		zhifuyue=new JCheckBox("支付余额");
  		
  		
  		qiandingriqi=new JCheckBox("签订日期");
  		zhifuriqi=new JCheckBox("支付日期");
  		hetongqixian=new JCheckBox("合同期限 ");
  		
  		box2.add(xinghao);
  		box2.add(shoukuanren);
  		box2.add(qiandingren);
  		box2.add(new JLabel("                                                              "));
 
  		
  		Box box3=Box.createHorizontalBox();
  		box3.add(hetongzonge);
  		box3.add(zhifujine);
  		box3.add(zhifuyue);
  		box3.add(zhifuriqi);
  		box3.add(hetongqixian);
  		box3.add(qiandingriqi);
  		
  		box3.add(xianshi);
  		//Box box4=Box.createHorizontalBox();
  		
  		
   		Box boxH=Box.createVerticalBox();              
   		boxH.add(box1);
   		boxH.setBorder(new TitledBorder("1.选择客户"));
   		boxH.add(Box.createVerticalGlue());  
   		
   		Box boxW=Box.createVerticalBox();              
   		boxW.add(box2);
   		boxW.add(box3);
   	
   		boxW.setBorder(new TitledBorder("2.选择显示内容"));
   		boxW.add(Box.createVerticalGlue());  
   		
   	
     	Box boxN=Box.createVerticalBox(); 
     	boxN.setFont(font);   
   		boxN.add(boxH);
   		boxW.setFont(font);   
   		boxN.add(boxW);
  
   		boxN.add(Box.createVerticalGlue()); 
   		
		kehumingt.setFont(font);
		kehumingt.setText(kehumingcheng);
		chanxunkehu.setFont(font);
		xianshi.setFont(font);
		kehumingChoice.setFont(font);
		kehumingChoice.addItemListener(this);
		xinghao.setFont(font);
		xinghao.setSelected(true);
		shoukuanren.setFont(font);
		//shoukuanren.setSelected(true);
		qiandingren.setFont(font);
		//qiandingren.setSelected(true);
		qiandingriqi.setFont(font);
		//qiandingriqi.setSelected(true);
		hetongzonge.setFont(font);
		hetongzonge.setSelected(true);
		hetongqixian.setFont(font);
		//hetongqixian.setSelected(true);
		zhifuriqi.setFont(font);
		zhifuriqi.setSelected(true);
		zhifujine.setFont(font);
		zhifujine.setSelected(true);
		zhifuyue.setFont(font);
		zhifuyue.setSelected(true);

   		JPanel pp=new JPanel();
    	pp.add(boxN);
    
		//lurujsp=new JScrollPane(pp);

    	con=getContentPane();
    	con.validate();
    	
   		con.setLayout(new BorderLayout());
   
   		con.add(pp,BorderLayout.NORTH);
      	
     
   		
		if(iii==800){
			font=new java.awt.Font("宋体",Font.PLAIN,12); 
			setBounds(80,70,650,400);
			
		}else{
			
			setBounds(140,80,800,600);
		}

    	setVisible( true );
    	 
    	
      	this.addWindowListener(new WindowAdapter(){
        	public void WindowClosing(WindowEvent e){
               	
            
                  System.exit(0);
                  
               }
            });   
	}
	public void actionPerformed(ActionEvent e){
		
		if(e.getSource()==xianshi){
			
			
			if(kehumingt.getText().trim().length()==0){
				
				JOptionPane.showMessageDialog(null,"请输入一个客户名称!"); 
			}else{
				StringBuffer buf=new StringBuffer();
				buf=buf.append("select distinct kehuname,");
				 //sql3="select distinct truename,name,tel,sheng,shi,xian from zhuceTable where truename='"+truename+"' and name!='master' and name!='root'";
				philosophers = new DefaultTableModel();   
				StringVector vec=new StringVector();
				vec.add("序号");
				vec.add("客户名称");
			
				if(xinghao.isSelected()){
					vec.add("产品型号");
					buf=buf.append("xinghao,");
				
				}
				if(hetongzonge.isSelected()){
					vec.add("合同总额");
					buf=buf.append("hetongzonge,");
				}
				if(zhifujine.isSelected()){
					vec.add("支付金额");
					buf=buf.append("zhifujine,");
					
				}
				if(zhifuyue.isSelected()){
					vec.add("支付余额");
					buf=buf.append("zhifuyue,");
				}
				if(shoukuanren.isSelected()){
					vec.add("收款人");
					buf=buf.append("shoukuanren,");
				}
			
				if(qiandingren.isSelected()){
					vec.add("签订人");
					buf=buf.append("qiandingren,");
				}
				if(zhifuriqi.isSelected()){
					vec.add("支付日期");
					buf=buf.append("zhifuriqi,");
					
				}
				if(qiandingriqi.isSelected()){
					
					vec.add("签订日期");
					buf=buf.append("qiandingriqi,");
				}
				if(hetongqixian.isSelected()){
					vec.add("合同期限");
					buf=buf.append("hetongqixian,");

				}
				vec.add("业务员");
				
				if(name.equals("master")||name.equals("root")){
					buf=buf.append("yewuname from hetongTable where kehuname='").append(kehumingt.getText().trim()).append("'");
				}else{
					
					buf=buf.append("yewuname from hetongTable where kehuname='").append(kehumingt.getText().trim()).append("' and yewuname='").append(truename).append("'");
				}
				
				    
				//new HetongJTable(buf.toString(),vec);
				
				
				
				philosophers = new DefaultTableModel(); //创建0行 
				 for(int i=0;i<vec.size();i++){
        	
        			philosophers.addColumn(vec.get(i));
        		}

				ResultSet resSet;	
    			Connection dbConn;
        		Statement stat;	
   				
   					
				//String sql3=buf.toString();
	
				try { 
					Class.forName(Yewu.forName);
   					dbConn=DriverManager.getConnection(Yewu.jdbc);
 
 					stat=dbConn.createStatement();
 		    		resSet=stat.executeQuery(buf.toString());
 		   			int m=1;
 		   			Vector vec1=new Vector();
 					while(resSet.next()){
 				
 						Vector vec2=new Vector();
 						vec2.add(m++);
 				
 						for(int i=1;i<vec.size();i++){
 					
 					//	Vector vec=new Vector();
 						vec2.add((resSet.getObject(i)).toString());//0
 						}
 						vec1.add(vec2);

 					}
 			
 					if(m>1){
 		
 						for(int i=0;i<vec1.size();i++){
 	     	     			philosophers.addRow(((Vector)vec1.get(i)).toArray());
 	     	     		}
 	     	 		}else{
 	     	 			JOptionPane.showMessageDialog(null,"没有此客户的合同信息"); 
 	     	 		}
 	     	     
 				
 		
 			stat.close();
 			dbConn.close();    
       }catch(Exception ex){
       		System.out.println(ex);
       }
       
      table = new JTable( philosophers ); 
      table.setFont(font);
     
      		if(jspn!=null){
      				con.remove(jspn);
      		}
      	
      		jspn=new JScrollPane(table);
      	//	con.validate();
			con.add(jspn,BorderLayout.CENTER);
   			con.validate();

			}
	
		}
		
		if(e.getSource()==chanxunkehu){
				
		
			if(kehumingt.getText().trim().length()==0){
				JOptionPane.showMessageDialog(null,"请输入您要查询的客户名"); 
			}else{
				
        		ResultSet resSet;	
     			Connection dbConn;
     			Statement stat;
     			
     			int ff=0;	
    			try{
    				Class.forName(Yewu.forName);
   	 				dbConn=DriverManager.getConnection(Yewu.jdbc);
     				stat=dbConn.createStatement();  
     				
     				if(name.equals("master")||name.equals("root")){
     					StringBuffer sql=new StringBuffer();
     					sql.append("select kehuname from yewuTab where kehuname like '%").append(kehumingt.getText().trim()).append("%'");
						resSet=stat.executeQuery(sql.toString());
 	 				
					}else{
						
						StringBuffer sql=new StringBuffer();
						sql.append("select kehuname from yewuTab where kehuname like '%").append(kehumingt.getText().trim()).append("%' and yewuname='").append(truename).append("'");
						resSet=stat.executeQuery(sql.toString());
					} 
					 StringBuffer sql2=new StringBuffer();
					 sql2.append("select kehuname from yewuTab where kehuname like '%").append(kehumingt.getText().trim()).append("%'");
 	 				 resSet=stat.executeQuery(sql2.toString());
 	 				StringVector vec=new StringVector();
 	 				while(resSet.next()){
 	 					
 						vec.add(resSet.getString("kehuname").toString());
 						ff=1;
 					}	
 					stat.close();
 					dbConn.close();
 					
 					if(ff==1){
 						
 						kehumingChoice.removeAll();//清空再添加预防组件自动扩展
   					
   						//chuchangChoice.add("                                                       .");
						//kehuChoice.removeAll();
					
 						for(int i=0;i<vec.size();i++){
 							
 							kehumingChoice.add(vec.get(i));
 						
 						}
 						//kehuChoice.add("                                                         .");
 						
 						
 					}else{
 						
 						JOptionPane.showMessageDialog(null,"您查询的客户不存在"); 
 						kehumingChoice.removeAll();
 						kehumingChoice.add("                                                   ");
 						
 					}
 					
 				
    			}catch(Exception ew){
    				System.out.println(ew);
    				JOptionPane.showMessageDialog(null,"数据库服务器是否启动"); 
    			}
    					
			}//else
		}
		
	}
	
	public void itemStateChanged(ItemEvent e){ //选择事件	
	
		if(e.getSource()==kehumingChoice&&kehumingChoice.getSelectedItem().trim().length()>0){
			
			kehumingt.setText(kehumingChoice.getSelectedItem().trim());
			
		}
	}
	
	
}

⌨️ 快捷键说明

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