package com.zx.model;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import com.fate.model.*;;
public class ChargeBeanCl {
private Statement sm=null;//PreparedStatement
private ResultSet rs=null;
private Connection ct=null;
private int pageSize=5;
private int rowCount=0;//该值从数据库查询
private int pageCount=0;//该值是通过pageSize和rowCount
UserBeanCl ubc=new UserBeanCl();
public boolean addCharge(String cman,String ctime,String cname,double csum,String cway,String cbz){
boolean b=false;
try {
//得到连接
ct=new ConnDB().getConn();
sm=ct.createStatement();
//执行
int a=sm.executeUpdate("insert into charge values('"+cman+"','"+ctime+"','"+cname+"','"+csum+"','"+cway+"','"+cbz+"')");
if(a==1){
//添加成功
b=true;
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
ubc.close();
}
return b;
}
//修改用户
public boolean updateCharge(int cno,String cman,String ctime,String cname,double csum,String cway,String cbz){
boolean b=false;
try {
//得到连接
ct=new ConnDB().getConn();
sm=ct.createStatement();
//执行语句
int a =sm.executeUpdate("update charge set chargeman='"+cman+"',chargetime='"+ctime+"',chargename='"+cname+"',chargesum='"+csum+"',chargeway='"+cway+"',chargebz='"+cbz+"' where chargeno ='"+cno+"'" );
if(a==1){
b=true;
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
ubc.close();
}
return b;
}
//删除用户
public boolean delChargeById(String id){
boolean b=false;
try {
//得到连接
ct=new ConnDB().getConn();
sm=ct.createStatement();
//执行
int a=sm.executeUpdate("delete from charge where chargeno='"+id+"'");
if(a==1){
//删除成功
b=true;
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
ubc.close();
}
return b;
}
//返回,分页的总页数
public int getPageCount(){
//...
try {
//得到连接
ct=new ConnDB().getConn();
sm=ct.createStatement();
// 4. 查询
rs=sm.executeQuery("select count(*) from charge ");
//请注意,一定要rs.next()
if(rs.next()){
rowCount=rs.getInt(1);
}
//计算pageCount,
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
//计算pageCount..
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
ubc.close();
}
return pageCount;
}
//得到用户需要显示的用户信息(分页)
public ArrayList getChargeByPage(int pageNow){
ArrayList al=new ArrayList();
try {
ct=new ConnDB().getConn();
// 3.创建Statement
sm=ct.createStatement();
//查询出需要显示的记录
rs=sm.executeQuery("select top "+pageSize
+" * from charge where chargeno not in (select top "
+pageSize*(pageNow-1)+" chargeno from charge ) ");
//开始将rs封装到ArrayList
while(rs.next()){
ChargeBean cb=new ChargeBean();
cb.setChargeno(rs.getInt(1));
cb.setChargeman(rs.getString(2));
cb.setChargetime(rs.getString(3));
cb.setChargename(rs.getString(4));
cb.setChargesum(rs.getDouble(5));
cb.setChargeway(rs.getString(6));
cb.setChargebz(rs.getString(7));
//将ub放入到arryalist中
al.add(cb);
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
//关闭资源
ubc.close();
}
return al;
}
public ArrayList getChargeIn(int pageNow){
ArrayList al=new ArrayList();
try {
ct=new ConnDB().getConn();
// 3.创建Statement
sm=ct.createStatement();
//查询出需要显示的记录
rs=sm.executeQuery("select top "+pageSize
+" * from charge where chargeno not in (select top "
+pageSize*(pageNow-1)+" chargeno from charge )and chargeway='in' ");
//开始将rs封装到ArrayList
while(rs.next()){
ChargeBean cb=new ChargeBean();
cb.setChargeno(rs.getInt(1));
cb.setChargeman(rs.getString(2));
cb.setChargetime(rs.getString(3));
cb.setChargename(rs.getString(4));
cb.setChargesum(rs.getDouble(5));
cb.setChargeway(rs.getString(6));
cb.setChargebz(rs.getString(7));
//将ub放入到arryalist中
al.add(cb);
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
//关闭资源
ubc.close();
}
return al;
}
public ArrayList getChargeOut(int pageNow){
ArrayList al=new ArrayList();
try {
ct=new ConnDB().getConn();
// 3.创建Statement
sm=ct.createStatement();
//查询出需要显示的记录
rs=sm.executeQuery("select top "+pageSize
+" * from charge where chargeno not in (select top "
+pageSize*(pageNow-1)+" chargeno from charge )and chargeway='out' ");
//开始将rs封装到ArrayList
while(rs.next()){
ChargeBean cb=new ChargeBean();
cb.setChargeno(rs.getInt(1));
cb.setChargeman(rs.getString(2));
cb.setChargetime(rs.getString(3));
cb.setChargename(rs.getString(4));
cb.setChargesum(rs.getDouble(5));
cb.setChargeway(rs.getString(6));
cb.setChargebz(rs.getString(7));
//将ub放入到arryalist中
al.add(cb);
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
//关闭资源
ubc.close();
}
return al;
}
public int getPageInCount(){
//...
try {
//得到连接
ct=new ConnDB().getConn();
sm=ct.createStatement();
// 4. 查询
rs=sm.executeQuery("select count(*) from charge where chargeway='in' ");
//请注意,一定要rs.next()
if(rs.next()){
rowCount=rs.getInt(1);
}
//计算pageCount,
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
//计算pageCount..
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
ubc.close();
}
return pageCount;
}
public int getPageOutCount(){
//...
try {
//得到连接
ct=new ConnDB().getConn();
sm=ct.createStatement();
// 4. 查询
rs=sm.executeQuery("select count(*) from charge where chargeway='out'");
//请注意,一定要rs.next()
if(rs.next()){
rowCount=rs.getInt(1);
}
//计算pageCount,
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
//计算pageCount..
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
ubc.close();
}
return pageCount;
}
}
评论0