package com;
import java.util.ArrayList;
import java.util.Collection;
import java.sql.*;
public class GoodsBean
{
private Connection con;
PageNumber pageNumber=new PageNumber();
int rowCount=1;
int showPage=16;
int pageCount=1;
public GoodsBean()
{
try
{
con = DBConnection.getConnection();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public int getRowCount()
{
return rowCount;
}
public int getAllPage()
{
try
{
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet resultset = statement.executeQuery("select * from Goods");
resultset.last();
rowCount=resultset.getRow();
pageNumber.setPageCount(rowCount,showPage);
pageCount=pageNumber.getPageCount();
}
catch(Exception e)
{
e.printStackTrace();
}
return pageCount;
}
public int getAllPageBySort(String s)
{
try
{
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet resultset = statement.executeQuery("select * from Goods where sortName='" + s + "'");
resultset.last();
rowCount=resultset.getRow();
pageNumber.setPageCount(rowCount,showPage);
pageCount=pageNumber.getPageCount();
}
catch(Exception e)
{
e.printStackTrace();
}
return pageCount;
}
public int getAllPageByPrice(String s)
{
int a=s.indexOf("-");
float one=Float.parseFloat(s.substring(0,a));
float two=Float.parseFloat(s.substring(a+1));
try
{
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet resultset = statement.executeQuery("select * from Goods where goodsPrice between "+one+" and "+two);
resultset.last();
rowCount=resultset.getRow();
pageNumber.setPageCount(rowCount,showPage);
pageCount=pageNumber.getPageCount();
}
catch(Exception e)
{
e.printStackTrace();
}
return pageCount;
}
public int getAllPageByMaterial(String s)
{
try
{
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet resultset = statement.executeQuery("select * from Goods where goodsmaterial like '%"+s+"%'");
resultset.last();
rowCount=resultset.getRow();
pageNumber.setPageCount(rowCount,showPage);
pageCount=pageNumber.getPageCount();
}
catch(Exception e)
{
e.printStackTrace();
}
return pageCount;
}
public Collection getAllGoods(int s)
{
GoodsClass goods;
ArrayList arraylist = new ArrayList();
try
{
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet resultset = statement.executeQuery("select * from Goods");
int count=0;
if(s!=0)
{
resultset.absolute(s*16);
}
while(resultset.next())
{
goods = new GoodsClass();
int i=resultset.getInt(1);
String s1=resultset.getString(2);
String s2=resultset.getString(3);
String s3=resultset.getString(4);
String s4=resultset.getString(5);
float f=resultset.getFloat(6);
String s5=resultset.getString(7);
String s6=resultset.getString(8);
String s7=resultset.getString(9);
String s8=resultset.getString(10);
String s9=resultset.getString(11);
goods.setGoodsId(i);
goods.setGoodsName(s1);
goods.setGoodsmaterial(s2);
goods.setGoodsPackage(s3);
goods.setGoodsLanguage(s4);
goods.setGoodsPrice(f);
goods.setGoodsCent(s5);
goods.setGoodsScope(s6);
goods.setGoodsPlace(s7);
goods.setGoodsHabitus(s8);
goods.setSortName(s9);
arraylist.add(goods);
count++;
if(count==16)
{
break;
}
}
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return arraylist;
}
public Collection getGoodsBySort(String s,int pageCount)
{
GoodsClass goods;
ArrayList arraylist = new ArrayList();
try
{
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet resultset = statement.executeQuery("select * from Goods where sortName='" + new String(s.getBytes("ISO-8859-1"),"GB2312") + "'");
int count=0;
if(pageCount!=0)
{
resultset.absolute(pageCount*16);
}
while(resultset.next())
{
goods = new GoodsClass();
int i=resultset.getInt(1);
String s1=resultset.getString(2);
String s2=resultset.getString(3);
String s3=resultset.getString(4);
String s4=resultset.getString(5);
float f=resultset.getFloat(6);
String s5=resultset.getString(7);
String s6=resultset.getString(8);
String s7=resultset.getString(9);
String s8=resultset.getString(10);
String s9=resultset.getString(11);
goods.setGoodsId(i);
goods.setGoodsName(s1);
goods.setGoodsmaterial(s2);
goods.setGoodsPackage(s3);
goods.setGoodsLanguage(s4);
goods.setGoodsPrice(f);
goods.setGoodsCent(s5);
goods.setGoodsScope(s6);
goods.setGoodsPlace(s7);
goods.setGoodsHabitus(s8);
goods.setSortName(s9);
arraylist.add(goods);
count++;
if(count==16)
{
break;
}
}
statement.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return arraylist;
}
public Collection getGoodsByPrice(String s,int pageCount)
{
int a=s.indexOf("-");
float one=Float.parseFloat(s.substring(0,a));
float two=Float.parseFloat(s.substring(a+1));
GoodsClass goods;
ArrayList arraylist = new ArrayList();
try
{
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet resultset = statement.executeQuery("select * from Goods where goodsPrice between "+one+" and "+two);
int count=0;
if(pageCount!=0)
{
resultset.absolute(pageCount*16);
评论0
最新资源