?? 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
*<p>Title: 產(chǎn)品信息管理類</p>
*<p>Description: 有關(guān)產(chǎn)品的瀏覽操作</p>
*/
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;
}
/**
* 根據(jù)該產(chǎn)品id獲得PPM表中的項目集合數(shù)量(去掉PPM表中重復(fù)的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("根據(jù)該產(chǎn)品id獲得PPM表中的項目集合數(shù)量:"+count);
return count;
}
/**
* 根據(jù)類別id,獲得類別下的所有產(chǎn)品集合的數(shù)目
* @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;
}
/**
* 根據(jù)類別id,獲得某一頁類別下的所有產(chǎn)品集合
* @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;
}
/**
* 根據(jù)該產(chǎn)品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;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -