www.pudn.com > shop.rar > GoodDTO.java
package com.soft136.shop.model;
import java.sql.SQLException;
import java.util.ArrayList;
import oracle.jdbc.rowset.OracleCachedRowSet;
import com.soft136.shop.DAO.GoodDao;
import com.soft136.shop.model.GoodsBean;
public class GoodDTO {
public ArrayList getGoodsMessage() throws SQLException,
ClassNotFoundException {
OracleCachedRowSet crs = new GoodDao().getGoodsMessage();
if (crs != null) {
ArrayList list = new ArrayList();
while (crs.next()) {
list.add(new GoodsBean(crs.getInt(1), crs.getString(2), crs
.getInt(3), crs.getInt(4), crs.getInt(5), crs
.getString(6), crs.getString(7), crs.getInt(8), crs
.getInt(9), crs.getString(10)));
}
return list;
} else {
return null;
}
}
public ArrayList getResult(int goods_id, int flag, ArrayList list)
throws SQLException, ClassNotFoundException {
if (flag == 1) {
for (int i = 0; i < list.size(); i++) {
GoodsBean gb = (GoodsBean) list.get(i);
if (gb.getGoods_id() == goods_id) {
gb.setNumber(gb.getNumber() + 1);
return list;
}
}
OracleCachedRowSet crs = new GoodDao().getResult(goods_id);
if (crs.next()) {
GoodsBean gb = new GoodsBean(crs.getInt(1), crs.getString(2),
crs.getInt(3), crs.getInt(4), crs.getInt(5), crs
.getString(6), crs.getString(7), crs.getInt(8),
crs.getInt(9), crs.getString(10), 1);
list.add(gb);
}
}
if (flag == 2) {
if (!list.isEmpty()) {
for (int i = 0; i <= list.size(); i++) {
GoodsBean gb = (GoodsBean) list.get(i);
if (gb.getGoods_id() == goods_id) {
list.remove(gb);
return list;
}
}
}
}
if (flag == 3) {
if (!list.isEmpty()) {
list.clear();
}
return list;
}
return list;
}
public ArrayList getResult(int goods_id, ArrayList list, int count)
throws SQLException, ClassNotFoundException {
for (int i = 0; i < list.size(); i++) {
GoodsBean gb = (GoodsBean) list.get(i);
if (gb.getGoods_id() == goods_id) {
gb.setNumber(count);
return list;
}
}
OracleCachedRowSet crs = new GoodDao().getResult(goods_id);
if (crs.next()) {
GoodsBean gb = new GoodsBean(crs.getInt(1), crs.getString(2), crs
.getInt(3), crs.getInt(4), crs.getInt(5), crs.getString(6),
crs.getString(7), crs.getInt(8), crs.getInt(9), crs
.getString(10),crs.getInt(11));
list.add(gb);
}
return list;
}
}