📄 projectmanager.java~73~
字号:
package zhaobiao.db;
import java.util.*;
import java.sql.*;
import zhaobiao.db.*;
import zhaobiao.date.*;
/**
* <p>Title: 工程项目信息管理类</p>
* <p>Description:有关工程项目的浏览操作</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class ProjectManager {
public ProjectManager() {
}
/** 获得所有的项目集合
*
*
*/
public Vector getProjectList(long page ,long pagemax)
{
page=page-1;
Vector list=new Vector();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from project";
try {
Statement ps1=con.createStatement();
rs=ps1.executeQuery(sql);
int count=1;
while(rs.next())
{
if (count>(page*pagemax)&&count<=(page*pagemax+pagemax)){
Project pj=new Project();
pj.setProject_id(rs.getLong("project_id"));
pj.setProject_name(rs.getString("project_name"));
pj.setProject_time(rs.getString("project_time"));
pj.setProject_company(rs.getString("project_company"));
pj.setProject_cost(rs.getString("project_cost"));
pj.setProject_content(rs.getString("project_content"));
list.add(pj);
}
count++;
}
if(ps1!=null)
ps1.close() ;
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return list;
}
/** 获得所有的项目集合的最大数量
*
*
*/
public long getProjectListCount()
{
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
long count=0;
String sql=" select count(*)as count from project";
try {
Statement ps1=con.createStatement();
rs=ps1.executeQuery(sql);
while(rs.next())
{
count=Long.parseLong(rs.getString("count"));
}
if(ps1!=null)
ps1.close() ;
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return count;
}
/** 根据项目id获得该项目相关的所有类别列表
*
*
*/
public Vector getProjectTypeList(long project_id)
{
Vector list=new Vector();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from project_product where project_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,project_id);
rs=ps.executeQuery();
while(rs.next())
{
//System.out.println("type_id="+rs.getLong("type_id"));
Type type=new Type();
long typeid;
typeid=rs.getLong("type_id");
Cpmec cpmec=new Cpmec();
type=cpmec.getType(typeid); //调用getType方法
// System.out.println("id="+typeid);
list.add(type);
}
}
catch (SQLException ex) {
ex.printStackTrace();
freeCon();
}
freeCon();
return list;
}
/** 根据项目id和类别id获得满足两个条件的产品集合(Set类型)
*
*
*/
public Set getPTProductList(long page ,long pagemax,long project_id,long type_id)
{
//Vector list=new Vector();
page=page-1;
Set set1=new TreeSet(); //分页判断,所得到的集合区间
Set set2=new TreeSet(); //真正的返回值
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from ppm where project_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,project_id);
rs=ps.executeQuery();
int count=1;
boolean flag=true;
Cpmec cpmec=new Cpmec();
while(rs.next())
{
Product pd=new Product();
pd=cpmec.getProduct(rs.getLong("product_id"));
if(pd.getType_id()==type_id)
{
//System.out.println("pd_id="+pd.getProduct_id());
if(set1.add(pd))
{
// System.out.println("product name="+pd.getProduct_name());
if (count>(page*pagemax)&&count<=(page*pagemax+pagemax))
{
set2.add(pd);;
}
count++; //计数器加1
}
}
}
cpmec.freeCon();
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return set2;
}
/** 根据项目id和类别id获得满足两个条件的产品集合(Set类型)
*
*
*/
public long getPTProductListCount(long project_id,long type_id)
{
long count=0;
Set set1=new TreeSet();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from ppm where project_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,project_id);
rs=ps.executeQuery();
Cpmec cpmec=new Cpmec();
while(rs.next())
{
Product pd=new Product();
pd=cpmec.getProduct(rs.getLong("product_id"));
if(pd.getType_id()==type_id)
{
if(set1.add(pd))
count++; //计数器加1
}
}
cpmec.freeCon();
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return count;
}
/** 根据项目id和产品id得到相关的PPM集合
*
*
*/
public Vector getPPMList(long project_id,long product_id)
{
Vector list=new Vector();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
Cpmec cpmec=new Cpmec();
String sql="select *from ppm where project_id=? and product_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,project_id);
ps.setLong(2,product_id);
rs=ps.executeQuery();
while(rs.next())
{
PPM ppm=new PPM();
long id;
id=rs.getLong("id");
ppm=cpmec.getPPM(id);
list.add(ppm);
}
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
cpmec.freeCon();
freeCon();
return list;
}
/** 根据项目id和产品id得到相关的PPM集合
*
*
*/
public Vector getPPMList(long page ,long pagemax,long project_id,long product_id)
{
page=page-1;
Vector list=new Vector();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from ppm where project_id=? and product_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,project_id);
ps.setLong(2,product_id);
rs=ps.executeQuery();
int count=1;
while(rs.next())
{
if (count>(page*pagemax)&&count<=(page*pagemax+pagemax)){
Long ppmid=new Long(rs.getLong("id"));
list.add(ppmid);
}
count++;
}
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return list;
}
/** 根据项目id和产品id得到相关的PPM集合
*
*
*/
public long getPPMListCount(long project_id,long product_id)
{
long count=0;
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from ppm where project_id=? and product_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,project_id);
ps.setLong(2,product_id);
rs=ps.executeQuery();
while(rs.next())
{
count++;
}
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return count;
}
/** 根据标价id获的标价对象
*
*
*/
public Price getPrice(long Price_id)
{
Price price=new Price();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from price where price_id=?";
try {
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
if(rs.next())
{
price.setPrice_id(rs.getLong("price_id"));
}
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return price;
}
/**
* 释放数据库资源<p>
*PreparedStatement和ResultSep将关闭,Connection返回给连接池
* @param 无
* @repurn 无
* @exception SQLException
*
*/
public void freeCon(){
try {
if (rs!=null)
rs.close() ;
if (ps!=null)
ps.close() ;
}
catch (SQLException ex) {
}
if (db!=null)
db.freeConnection("idb",con) ;
}
public static void main(String[] args) {
ProjectManager projectManager1 = new ProjectManager();
/* Vector list=projectManager1.getProjectTypeList(1);
for(int i=0;i<list.size();i++)
{
Type type=new Type();
type=(Type)list.elementAt(i);
System.out.println(type.getType_name());
}
*/
Set set1=new TreeSet();
// pjid=3&typeid=3&page1=2
set1= projectManager1.getPTProductList(2,1,3,3);
System.out.print("set1.size()="+set1.size());
//set1.add("ddddddddd");
//set1.add("fsdads");
}
private DBConnectionManager db;
private Connection con=null;
private ResultSet rs=null;
private PreparedStatement ps=null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -