www.pudn.com > BeiJie.rar > GetListOperation.java


package operation; 
 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.util.ArrayList; 
import java.util.Collection; 
import java.util.Vector; 
 
import entity.GetList; 
import entity.PageBean; 
 
import dataBase.*; 
public class GetListOperation 
{ 
	private DataBase db=null; 
	private ResultSet rs = null; 
	int totalrows = 0; 
	Vector v = null; 
	public GetListOperation() 
	{ 
		db = new DataBase(); 
		v = new Vector(); 
	} 
	public Collection getGetList(String shouldGetID) 
	{ 
		Collection ret = new ArrayList(); 
		String sql = "select * from GetList where ShouldGetID = '"+shouldGetID+"'"; 
		rs=db.getResult(sql);//执行SQL语句 
		try 
		{ 
			while(rs.next()) 
			{ 
				GetList gl = new GetList(); 
				gl.setGetID(rs.getString("GetID")); 
				gl.setShouldGetID(rs.getString("ShouldGetID")); 
				gl.setGetSum(rs.getFloat("GetSum")); 
				gl.setChargeman(rs.getString("Chargeman")); 
				gl.setGetDate(rs.getDate("GetDate")); 
				gl.setGetNotice(rs.getString("GetNotice")); 
				ret.add(gl); 
			} 
		} catch (SQLException e) 
		{ 
			// TODO 自动生成 catch 块 
			e.printStackTrace(); 
		}	 
		return ret; 
	} 
	 
	public Collection getGetList(String starttime,String endtime) 
	{ 
		Collection ret = new ArrayList(); 
		String sql = "select * from GetList where GetDate between '"+starttime+"' and '"+endtime+"'"; 
		rs=db.getResult(sql);//执行SQL语句 
		try 
		{ 
			while(rs.next()) 
			{ 
				GetList gl = new GetList(); 
				gl.setGetID(rs.getString("GetID")); 
				gl.setShouldGetID(rs.getString("ShouldGetID")); 
				gl.setGetSum(rs.getFloat("GetSum")); 
				gl.setChargeman(rs.getString("Chargeman")); 
				gl.setGetDate(rs.getDate("GetDate")); 
				gl.setGetNotice(rs.getString("GetNotice")); 
				//System.out.println(gl.getGetDate()); 
				ret.add(gl); 
			} 
		} catch (SQLException e) 
		{ 
			// TODO 自动生成 catch 块 
			e.printStackTrace(); 
		} 
		return ret; 
	} 
	 
	public int getAvailableCount() throws Exception 
	{ 
		int rows = 0; 
		String sql = "select count(*) from GetList"; 
		ResultSet rs = db.getResult(sql); 
		while(rs.next()) 
		{ 
			rows = rs.getInt(1); 
		} 
		return rows; 
	} 
	 
	public Vector getResult() throws Exception 
	{ 
		return v; 
	} 
	 
	public GetListPage listData(String page,String starttime,String endtime) throws Exception 
	{ 
		 
		int pageNum = Integer.parseInt(page); 
		String rowssql = "select count(*) from GetList where GetDate between '"+starttime+"' and '"+endtime+"'"; 
		 
		ResultSet rst = db.getResult(rowssql); 
		while(rst.next()) 
		{ 
			totalrows = rst.getInt(1); 
		} 
		GetListPage glp = new GetListPage(this); 
		String sql = "select * from GetList where GetDate between '"+starttime+"' and '"+endtime+"'"+" limit "+0+","+pageNum*glp.rowsPerPage; 
		ResultSet rs = db.getResult(sql); 
		int i = 0; 
		while(rs.next()) 
		{ 
			if(i>(pageNum-1)*glp.rowsPerPage-1) 
			{ 
				Object[] obj = new Object[6]; 
				obj[0] = rs.getString(1); 
				obj[1] = rs.getString(2); 
				obj[2] = rs.getString(3); 
				obj[3] = rs.getString(4); 
				obj[4] = rs.getString(5); 
				obj[5] = rs.getString(6); 
				v.add(obj); 
			} 
			i++; 
		} 
		rst.close(); 
		rs.close(); 
		db.close(); 
		glp.curPage=pageNum; 
		glp.data=v; 
		return glp; 
	} 
	 
	public GetListPage listData(String page,String shouldGetID) throws Exception 
	{ 
		 
		int pageNum = Integer.parseInt(page); 
		String rowssql = "select count(*) from GetList where ShouldGetID = '"+shouldGetID+"'"; 
		 
		ResultSet rst = db.getResult(rowssql); 
		 
		while(rst.next()) 
		{ 
			totalrows = rst.getInt(1); 
		} 
		GetListPage glp = new GetListPage(this); 
		String sql = "select * from GetList where ShouldGetID ='"+shouldGetID+"'"+" limit "+0+","+pageNum*glp.rowsPerPage; 
		ResultSet rs = db.getResult(sql); 
		int i = 0; 
		while(rs.next()) 
		{ 
			if(i>(pageNum-1)*glp.rowsPerPage-1) 
			{ 
				Object[] obj = new Object[6]; 
				obj[0] = rs.getString(1); 
				obj[1] = rs.getString(2); 
				obj[2] = rs.getString(3); 
				obj[3] = rs.getString(4); 
				obj[4] = rs.getString(5); 
				obj[5] = rs.getString(6); 
				v.add(obj); 
			} 
			i++; 
		} 
		rs.close(); 
		db.close(); 
		glp.curPage=pageNum; 
		glp.data=v; 
		return glp; 
		 
	} 
}