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


/** 
 *  
 */ 
package com.centralsoft.zhaobiao.qtdatachaxun; 
 
import java.sql.*; 
import java.util.*; 
 
import com.centralsoft.zhaobiao.qtdataguanli.Type; 
import com.centralsoft.zhaobiao.qtdataguanli.Project; 
import com.centralsoft.zhaobiao.qtdataguanli.Product; 
import com.centralsoft.zhaobiao.util.dataBase; 
import com.centralsoft.zhaobiao.qtdatachaxun.Basic; 
/** 
 * @author Administrator 
 *

Title: 产品信息管理类

*

Description: 有关产品的浏览操作

*/ public class ProductManager { public ProductManager() { } /** * 获得所有的类别集合 * @return */ public Vector getTypeList() { Vector list = new Vector(); ResultSet rs = null; dataBase db = new dataBase(); String sql = "select * from type"; rs = db.getResultSet(sql); try { while (rs.next()) { Type type = new Type(); type.setType_id(rs.getLong("type_id")); type.setType_name(rs.getString("type_name")); type.setType_content(rs.getString("type_content")); list.add(type); } } 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 list; } /** * 根据该产品id获得PPM表中的项目集合数量(去掉PPM表中重复的project_id) * @param product_id * @return */ public long getProjectListCount(long product_id) { long count = 0; Set set1 = new TreeSet(); Basic basic = new Basic(); dataBase db = new dataBase(); String sql = "select * from ppm where product_id ="+product_id; ResultSet rs = null; rs = db.getResultSet(sql); try { while (rs.next()) { long project_id; Project pj = new Project(); project_id = rs.getLong("project_id"); pj = basic.getProject(project_id); if (set1.add(pj)) {//将指定的元素添加到se里t count++; } } } catch (Exception e) { System.out.println(e.getMessage()); } finally { try { if (rs != null) { rs.close(); } } catch (Exception e) { System.out.println(e.getMessage()); } } System.out.println("根据该产品id获得PPM表中的项目集合数量:"+count); return count; } /** * 根据类别id,获得类别下的所有产品集合的数目 * @param type_id * @return */ public long getProductListCount(long type_id) { long count = 0; dataBase db = new dataBase(); ResultSet rs = null; String sql = "select * from product where type_id = "+type_id; 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; } /** * 根据类别id,获得某一页类别下的所有产品集合 * @param page * @param pagemax * @param type_id * @return */ public Vector getProductList(long page,long pagemax,long type_id) { Vector list = new Vector(); dataBase db = new dataBase(); ResultSet rs = null; page = page - 1; String sql = "select * from product where type_id ="+type_id; rs = db.getResultSet(sql); try { int count = 1; while (rs.next()) { if (count > (page * pagemax) && count <= (page*pagemax + pagemax)) { Product pd = new Product(); pd.setProduct_id(rs.getLong("product_id")); pd.setProduct_name(rs.getString("product_name")); pd.setMaker_id(rs.getLong("maker_id")); pd.setType_id(rs.getLong("type_id")); pd.setProduct_content(rs.getString("product_content")); list.add(pd); } 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 list; } /** * 根据该产品id获得某一页PPM表中的项目集合 * @param page * @param pagemax * @param product_id * @return */ public Set getProjectList(long page,long pagemax,long product_id) { Set set1 = new TreeSet(); Set set2 = new TreeSet(); dataBase db = new dataBase(); Basic basic = new Basic(); ResultSet rs = null; String sql = "select * from ppm where product_id ="+product_id; page = page - 1; rs = db.getResultSet(sql); try { int count = 1; while (rs.next()) { long project_id; project_id = rs.getLong("project_id"); Project pj = new Project(); pj = basic.getProject(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 { if (rs != null) { rs.close(); } db.closeConn(); } catch (Exception e) { System.out.println(e.getMessage()); } } System.out.println("set2==="+set2.size()); return set2; } }