You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

433 lines
10 KiB

package com.bean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import com.util.Constant;
import com.util.DBO;
public class HzpBean {
private String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
private List list;
private ResultSet rs = null;
private int EVERYPAGENUM = 2;
private int count = -1;
private int qq = 0;
private String sql="select count(*) from sale ";
private String sql2="select * from sale order by id desc ";
public void setEVERYPAGENUM(int EVERYPAGENUM){
this.EVERYPAGENUM=EVERYPAGENUM;
}
public int getMessageCount() { //得到信息总数
DBO dbo=new DBO();
dbo.open();
try {
rs = dbo.executeQuery(sql);
rs.next();
count = rs.getInt(1);
return count;
} catch (SQLException ex) {
ex.printStackTrace();
return -1;
} finally {
dbo.close();
}
}
public int getPageCount() { //得到共多少页(根据每页要显示几条信息)
if (count % EVERYPAGENUM == 0) {
return count / EVERYPAGENUM;
} else {
return count / EVERYPAGENUM + 1;
}
}
public List getMessage(int page) { //得到每页要显示的信息
DBO dbo=new DBO();
dbo.open();
List list = new ArrayList();
try {
rs = dbo.executeQuery(sql2);
for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {
rs.next();
}
for (int t = 0; t < EVERYPAGENUM; t++) {
if (rs.next()) {
qq++;
List list2=new ArrayList();
list2.add(rs.getString(1));
list2.add(rs.getString(2));
list2.add(rs.getString(3));
list2.add(rs.getString(4));
list2.add(rs.getString(5));
list2.add(rs.getString(6));
list2.add(rs.getString(7));
list2.add(rs.getString(8));
list2.add(rs.getString(9));
list.add(list2);
} else {
break; //减少空循环的时间
}
}
return list;
} catch (SQLException ex) {
ex.printStackTrace();
return list;
} finally {
dbo.close();
}
}
////////////////////////////////////////////////////
public int addType(String title){
String sql = "insert into type (title,addtime) values ('"+title+"','"+date+"')";
DBO dbo = new DBO();
dbo.open();
try{
rs=dbo.executeQuery("select * from type where title ='"+title+"'");
if(rs.next())return Constant.SAME_NAME;
else{
int i = dbo.executeUpdate(sql);
if(i == 1){
return Constant.SUCCESS;
}
else{
return Constant.SYSTEM_ERROR;
}
}
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
public List getType(){
String sql = "select * from type order by id desc";
DBO dbo = new DBO();
list = new ArrayList();
dbo.open();
try{
rs = dbo.executeQuery(sql);
while(rs.next()){
List list2=new ArrayList();
list2.add(rs.getString(1));
list2.add(rs.getString(2));
list2.add(rs.getString(3));
list.add(list2);
}
return list;
}catch(Exception e){
e.printStackTrace();
return list;
}finally{
dbo.close();
}
}
public int delType(String id){
String sql="delete from type where id='"+id+"'";
DBO dbo = new DBO();
dbo.open();
try{
int i = dbo.executeUpdate(sql);
if(i == 1){
return Constant.SUCCESS;
}
else{
return Constant.SYSTEM_ERROR;
}
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
//add -------------------------------------------------------
/*
* String title = "";
String type="请选择";
String co="";
String time="";
String price="";
String vipprice="";
*/
public int addTrave(String title,String type,String url,String co,String time,String price,String vipprice,String content,String flag,String num,String sl){
String sql = "insert into sale (title,type,url,co,time,price,vipprice,content,addtime,flag,num,sl) " +
"values ('"+title+"','"+type+"','"+url+"','"+co+"','"+time+"','"+price+"','"+vipprice+"','"+content+"','"+date+"','"+flag+"','"+num+"','"+sl+"')";
DBO dbo = new DBO();
dbo.open();
try{
int i = dbo.executeUpdate(sql);
if(i == 1){
return Constant.SUCCESS;
}
else{
return Constant.SYSTEM_ERROR;
}
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
//update
public int updateTrave(String id,String title,String type,String url,String co,String time,String price,String vipprice,String content,String flag,String num,String sl){
String sql = "update sale set title = '"+title+"',type='"+type+"',url='"+url+"'," +
"co='"+co+"',time='"+time+"',price='"+price+"',vipprice='"+vipprice+"',content='"+content+"',flag='"+flag+"',num='"+num+"',sl='"+sl+"' where id = '"+id+"' ";
DBO dbo = new DBO();
dbo.open();
try{
int i = dbo.executeUpdate(sql);
if(i == 1){
return Constant.SUCCESS;
}
else{
return Constant.SYSTEM_ERROR;
}
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
public int delTrave(String id){
String sql="delete from sale where id='"+id+"'";
DBO dbo = new DBO();
dbo.open();
try{
int i = dbo.executeUpdate(sql);
if(i == 1){
return Constant.SUCCESS;
}
else{
return Constant.SYSTEM_ERROR;
}
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
public List getOneTrave(int id){
String sql = "select * from sale where id = '"+id+"'";
DBO dbo = new DBO();
list = new ArrayList();
dbo.open();
try{
rs = dbo.executeQuery(sql);
while(rs.next()){
list.add(rs.getString(1));
list.add(rs.getString(2));
list.add(rs.getString(3));
list.add(rs.getString(4));
list.add(rs.getString(5));
list.add(rs.getString(6));
list.add(rs.getString(7));
list.add(rs.getString(8));
list.add(rs.getString(9));
}
return list;
}catch(Exception e){
e.printStackTrace();
return list;
}finally{
dbo.close();
}
}
public List getAllPTrave(){
String sql = "select * from sale order by id desc";
DBO dbo = new DBO();
list = new ArrayList();
dbo.open();
try{
rs = dbo.executeQuery(sql);
while(rs.next()){
List list2=new ArrayList();
list2.add(rs.getString(1));
list2.add(rs.getString(2));
list2.add(rs.getString(3));
list2.add(rs.getString(4));
list2.add(rs.getString(5));
list2.add(rs.getString(6));
list2.add(rs.getString(7));
list2.add(rs.getString(8));
list2.add(rs.getString(9));
list.add(list2);
}
return list;
}catch(Exception e){
e.printStackTrace();
return list;
}finally{
dbo.close();
}
}
public List getAllPTrave(String sql){
DBO dbo = new DBO();
list = new ArrayList();
dbo.open();
try{
rs = dbo.executeQuery(sql);
while(rs.next()){
List list2=new ArrayList();
list2.add(rs.getString(1));
list2.add(rs.getString(2));
list2.add(rs.getString(3));
list2.add(rs.getString(4));
list2.add(rs.getString(5));
list2.add(rs.getString(6));
list2.add(rs.getString(7));
list2.add(rs.getString(8));
list2.add(rs.getString(9));
list.add(list2);
}
return list;
}catch(Exception e){
e.printStackTrace();
return list;
}finally{
dbo.close();
}
}
public List get10PTrave(){
String sql = "select * from sale order by id desc limit 0,5 ";
DBO dbo = new DBO();
list = new ArrayList();
dbo.open();
try{
rs = dbo.executeQuery(sql);
while(rs.next()){
List list2=new ArrayList();
list2.add(rs.getString(1));
list2.add(rs.getString(2));
list2.add(rs.getString(3));
list2.add(rs.getString(4));
list2.add(rs.getString(5));
list2.add(rs.getString(6));
list2.add(rs.getString(7));
list2.add(rs.getString(8));
list2.add(rs.getString(9));
list.add(list2);
}
return list;
}catch(Exception e){
e.printStackTrace();
return list;
}finally{
dbo.close();
}
}
public List getMyPrep(String sql){
DBO dbo = new DBO();
list = new ArrayList();
dbo.open();
try{
rs = dbo.executeQuery(sql);
while(rs.next()){
List list2=new ArrayList();
list2.add(rs.getString(1));
list2.add(rs.getString(2));
list2.add(rs.getString(3));
list2.add(rs.getString(4));
list2.add(rs.getString(5));
list2.add(rs.getString(6));
list2.add(rs.getString(7));
list2.add(rs.getString(8));
list2.add(rs.getString(9));
list.add(list2);
}
return list;
}catch(Exception e){
e.printStackTrace();
return list;
}finally{
dbo.close();
}
}
public List getMy11Prep(String sql){
DBO dbo = new DBO();
list = new ArrayList();
dbo.open();
try{
rs = dbo.executeQuery(sql);
rs.next();
list.add(rs.getString(1));
list.add(rs.getString(2));
list.add(rs.getString(3));
list.add(rs.getString(4));
list.add(rs.getString(5));
list.add(rs.getString(6));
list.add(rs.getString(7));
list.add(rs.getString(8));
list.add(rs.getString(9));
return list;
}catch(Exception e){
e.printStackTrace();
return list;
}finally{
dbo.close();
}
}
public List gegComMethod(String sql,int row){
DBO dbo = new DBO();
list = new ArrayList();
dbo.open();
try{
rs = dbo.executeQuery(sql);
while(rs.next()){
List list2=new ArrayList();
for(int i=1;i<=row;i++){
list2.add(rs.getString(i));
}
list.add(list2);
}
return list;
}catch(Exception e){
e.printStackTrace();
return list;
}finally{
dbo.close();
}
}
public int gegXsl(String title){
String sql="select sum(rs) from prep where zt='已提交' and title='"+title+"'";
DBO dbo = new DBO();
dbo.open();
try{
rs = dbo.executeQuery(sql);
rs.next();
return rs.getInt(1);
}catch(Exception e){
e.printStackTrace();
return 0;
}finally{
dbo.close();
}
}
}