www.pudn.com > zhaobiao.rar > MakerManager.java


/** 
 *  
 */ 
package com.centralsoft.zhaobiao.qtdatachaxun; 
 
import java.sql.*; 
import java.util.*; 
 
import com.centralsoft.zhaobiao.qtdataguanli.*; 
import com.centralsoft.zhaobiao.util.*; 
/** 
 * @author Administrator 
 * 
 */ 
public class MakerManager { 
	public MakerManager() {		 
	} 
	/** 
	 * 获的所有的厂商的集合的数量 
	 * @return 
	 */ 
	public long getMakerListCount() { 
		long count = 0; 
		dataBase db = new dataBase(); 
		ResultSet rs = null; 
		String sql = "select * from maker"; 
		rs = db.getResultSet(sql); 
		try { 
			while (rs.next()) { 
				count ++; 
			} 
		} catch (Exception e) { 
			System.out.println(e.getMessage()); 
		} finally { 
			try { 
				if (rs != null) { 
					rs.close(); 
				} 
				db.closeConn(); 
			} catch (Exception e) { 
				System.out.println(e.getMessage()); 
			} 
		} 
		return count; 
	} 
	/** 
	 * 获的所有的厂商的集合 
	 * @param page 
	 * @param pagemax 
	 * @return 
	 */ 
	public Vector getMakerList(long page,long pagemax) { 
		page = page - 1; 
		Vector list = new Vector(); 
		dataBase db = new dataBase(); 
		ResultSet rs = null; 
		String sql = "select * from maker"; 
		rs = db.getResultSet(sql); 
		try { 
			int count = 1; 
			while (rs.next()) { 
				if (count > (page * pagemax) && count <= (page * pagemax + pagemax)) { 
					Maker mk = new Maker(); 
					mk.setMaker_id(rs.getLong("maker_id")); 
					mk.setMaker_name(rs.getString("maker_name")); 
					mk.setMaker_address(rs.getString("maker_address")); 
					mk.setMaker_cr_time(rs.getString("maker_cr_time")); 
					mk.setMaker_cr_address(rs.getString("maker_cr_address")); 
					mk.setMaker_cr_cost(rs.getString("maker_cr_cost")); 
					mk.setMaker_fr_name(rs.getString("maker_fr_name")); 
					mk.setMaker_fr_position(rs.getString("maker_fr_position")); 
					mk.setMaker_attribute(rs.getString("maker_attribute")); 
					mk.setMaker_relation(rs.getString("maker_relation")); 
					mk.setMaker_db_content(rs.getString("maker_db_content")); 
					list.add(mk); 
				} 
				count ++; 
			} 
		} catch (Exception e) { 
			System.out.println(e.getMessage()); 
		} 
		return list; 
	} 
	/** 
	 * 根据厂商的id获的该厂商所有参加过的项目的数量,去掉其中的重复值 
	 * @param maker_id 
	 * @return 
	 */ 
	public long getPPMListCount(long maker_id) { 
		long count = 0; 
		Set set1=new TreeSet(); 
		dataBase db = new dataBase(); 
		ResultSet rs = null; 
		Basic basic = new Basic(); 
		String sql = "select * from ppm where maker_id ="+maker_id; 
		rs = db.getResultSet(sql); 
		try { 
			while (rs.next()) { 
				Project pj = new Project(); 
				pj = basic.getProject(rs.getLong("project_id")); 
				if (set1.add(pj)) { 
					count ++; 
				} 
			} 
		} catch (Exception e) { 
			System.out.println(e.getMessage()); 
		} finally { 
			try { 
				 
			} catch (Exception e) { 
				System.out.println(e.getMessage()); 
			} 
		} 
		return count; 
	} 
	/** 
	 * 根据厂商的id获的该厂商所有参加过的项目列表/使用set返回,去掉其中的重复值 
	 * @param page 
	 * @param pagemax 
	 * @param maker_id 
	 * @return 
	 */ 
	public Set getPPMProjectList(long page,long pagemax,long maker_id) { 
		page = page - 1; 
		Set set1 = new TreeSet(); 
		Set set2 = new TreeSet(); 
		dataBase db = new dataBase(); 
		ResultSet rs = null; 
		Basic basic = new Basic(); 
		String sql = "select * from ppm where maker_id ="+maker_id; 
		rs = db.getResultSet(sql); 
		try { 
			int count = 1; 
			while (rs.next()) { 
				Project pj = new Project(); 
				pj = basic.getProject(rs.getLong("project_id")); 
				if (set1.add(pj)) { 
					if (count > (page * pagemax) && count <= (page * pagemax + pagemax)) { 
						set2.add(pj); 
					} 
					count ++; 
				} 
			} 
		} catch (Exception e) { 
			System.out.println(e.getMessage()); 
		} finally { 
			try { 
				 
			} catch (Exception e) { 
				System.out.println(e.getMessage()); 
			} 
		} 
		return set2; 
	} 
	public Vector getPPMProductList(long project_id,long maker_id) { 
		Vector list = new Vector(); 
		return list; 
	} 
	/** 
	 * 根据项目id和产品id和厂商id得到相关的PPM对象实例 
	 * @param project_id 
	 * @param product_id 
	 * @param maker_id 
	 * @return 
	 */ 
	public PPM getPPMList(long project_id,long product_id,long maker_id) { 
		PPM ppm = new PPM(); 
		dataBase db = new dataBase(); 
		Connection conn = null; 
		conn = db.getConnection(); 
		PreparedStatement ps = null; 
		ResultSet rs = null; 
		Basic basic  = new Basic(); 
		String sql = "select * from ppm where project_id=? and product_id=? and maker_id=?"; 
		try { 
			ps=conn.prepareStatement(sql); 
		    ps.setLong(1,project_id); 
		    ps.setLong(2,product_id); 
		    ps.setLong(3,maker_id); 
		    rs = ps.executeQuery(); 
		    if (rs.next()) { 
		    	long id; 
		    	id = rs.getLong("id"); 
		    	ppm = basic.getPPM(id); 
		    } 
		} catch (Exception e) { 
			System.out.println(e.getMessage()); 
		} finally { 
			try { 
				if (rs != null) { 
					rs.close(); 
				} 
				if (ps != null) { 
					rs.close(); 
				} 
				if (conn != null) { 
					conn.close(); 
				} 
				db.closeConn(); 
			} catch (Exception e) { 
				System.out.println(e.getMessage()); 
			} 
		} 
		return ppm; 
	} 
}