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.

357 lines
9.9 KiB

package com.bean;
/**
* <EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>
* @author Administrator
*
*/
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 GuestBookBean {
private List list;
private ResultSet rs;
private String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
private int EVERYPAGENUM = 2;
private int count = -1;
private int qq = 0;
private String sql="select count(*) from guestbook where ifhide='1'";
private String sql2="select * from guestbook where ifhide='1' order by addtime desc ";
public void setEVERYPAGENUM(int EVERYPAGENUM){
this.EVERYPAGENUM=EVERYPAGENUM;
}
public int getMessageCount() { //<2F>õ<EFBFBD><C3B5><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
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() { //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿҳҪ<D2B3><D2AA>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
if (count % EVERYPAGENUM == 0) {
return count / EVERYPAGENUM;
} else {
return count / EVERYPAGENUM + 1;
}
}
public List getMessage(int page) { //<2F>õ<EFBFBD>ÿҳҪ<D2B3><D2AA>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>Ϣ
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.getInt("id"));//0
list2.add(rs.getString("nickname"));//1
list2.add(rs.getString("pic"));//2
list2.add(rs.getString("email"));//3
list2.add(rs.getString("qq"));//4
list2.add(rs.getString("weburl"));//5
list2.add(rs.getString("blogurl"));//6
list2.add(rs.getString("expressions"));//7
list2.add(rs.getString("content"));//8
list2.add(rs.getString("addtime"));//9
list2.add(rs.getString("ip"));//10
list2.add(rs.getString("replay"));//11
list.add(list2);
} else {
break; //<2F><><EFBFBD>ٿ<EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
}
}
return list;
} catch (SQLException ex) {
ex.printStackTrace();
return null;
} finally {
dbo.close();
}
}
//<2F><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD>ҳ
//private String sql4="select * from guestbook order by addtime desc ";
public int getMessageCountM(String stime,String etime) { //<2F>õ<EFBFBD><C3B5><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
String sql3=null;
if(stime.equals("0")){//<2F><><EFBFBD>ε<EFBFBD>
sql3="select count(*) from guestbook where ifhide='0'";
}
else if(stime.equals("1")){//<2F><>ʾ<EFBFBD><CABE>
sql3="select count(*) from guestbook where ifhide='1'";
}
else if(stime.equals("2")){//<2F><><EFBFBD>е<EFBFBD>
sql3="select count(*) from guestbook ";
}
else{
sql3="select count(*) from guestbook where addtime between '"+stime+"' and '"+etime+" 23:59:59'";
}
DBO dbo=new DBO();
dbo.open();
try {
rs = dbo.executeQuery(sql3);
rs.next();
count = rs.getInt(1);
return count;
} catch (SQLException ex) {
ex.printStackTrace();
return -1;
} finally {
dbo.close();
}
}
public List getMessageM(int page,String stime,String etime) { //<2F>õ<EFBFBD>ÿҳҪ<D2B3><D2AA>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>Ϣ
String sql4=null;
if(stime.equals("0")){//<2F><><EFBFBD>ε<EFBFBD>
sql4="select * from guestbook where ifhide='0'";
}
else if(stime.equals("1")){//<2F><>ʾ<EFBFBD><CABE>
sql4="select * from guestbook where ifhide='1'";
}
else if(stime.equals("2")){//<2F><><EFBFBD>е<EFBFBD>
sql4="select * from guestbook order by addtime desc ";
}
else{
sql4="select * from guestbook where addtime between '"+stime+"' and '"+etime+" 23:59:59'";
}
DBO dbo=new DBO();
dbo.open();
List list = new ArrayList();
try {
rs = dbo.executeQuery(sql4);
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.getInt("id"));//0
list2.add(rs.getString("nickname"));//1
list2.add(rs.getString("pic"));//2
list2.add(rs.getString("email"));//3
list2.add(rs.getString("qq"));//4
list2.add(rs.getString("weburl"));//5
list2.add(rs.getString("blogurl"));//6
list2.add(rs.getString("expressions"));//7
list2.add(rs.getString("content"));//8
list2.add(rs.getString("addtime"));//9
list2.add(rs.getString("ip"));//10
list2.add(rs.getString("replay"));//11
list2.add(rs.getString("ifhide"));//12
list.add(list2);
} else {
break; //<2F><><EFBFBD>ٿ<EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
}
}
return list;
} catch (SQLException ex) {
ex.printStackTrace();
return null;
} finally {
dbo.close();
}
}
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public int hideGuestBook(int id){
String sql = "select ifhide from guestbook where id='"+id+"' ";
String sql2 = "update guestbook set ifhide='0' where id ='"+id+"'";
String sql3 = "update guestbook set ifhide='1' where id ='"+id+"'";
DBO dbo = new DBO();
dbo.open();
try{
rs = dbo.executeQuery(sql);
rs.next();
if(rs.getInt(1) == 1){
int i = dbo.executeUpdate(sql2);
if(i == 1)
return Constant.SUCCESS;
else
return Constant.SYSTEM_ERROR;
}
else{
int i = dbo.executeUpdate(sql3);
if(i == 1)
return Constant.SUCCESS;
else
return Constant.SYSTEM_ERROR;
}
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public int addGuestBook(String nickname,String pic,String email,String qq,String weburl,String blogurl,String expressions,String content,String ip,int ifhide){
String sql = "insert into guestbook ( nickname, pic, email, qq, weburl, blogurl, expressions, content,addtime,ip,replay,ifhide)" +
" values('"+nickname+"','"+pic+"','"+email+"','"+qq+"','"+weburl+"','"+blogurl+"','"+expressions+"','"+content+"','"+date+"','"+ip+"','0','"+ifhide+"') ";
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();
}
}
//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public String getGuestBook(int id){
String sql = "select content from guestbook where id='"+id+"' ";
DBO dbo=new DBO();
dbo.open();
try{
rs = dbo.executeQuery(sql);
rs.next();
return rs.getString(1);
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
dbo.close();
}
}
// <09><>ѯ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
public String getReplay(int id){
String sql = "select replay from replay where mid='"+id+"' ";
DBO dbo=new DBO();
dbo.open();
try{
rs = dbo.executeQuery(sql);
rs.next();
return rs.getString(1);
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
dbo.close();
}
}
// <09><>ѯ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
public List getReplayInfo(int id){
String sql = "select * from replay where mid='"+id+"' ";
DBO dbo=new DBO();
list = new ArrayList();
dbo.open();
try{
rs = dbo.executeQuery(sql);
while(rs.next()){
list.add(rs.getString(3));
list.add(rs.getString(4));
list.add(rs.getString(5));
}
return list;
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
dbo.close();
}
}
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public int delGuestBook(int id[]){
DBO dbo=new DBO();
dbo.open();
try{
for(int i = 0;i<id.length;i++){
dbo.executeUpdate("delete from guestbook where id = '"+id[i]+"'");
dbo.executeUpdate("delete from replay where mid = '"+id[i]+"'");
}
return Constant.SUCCESS;
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
//<2F>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
public int reGuestBook(int mid ,String replay,String replayer){
String sql = "insert into replay (mid,replay,replayer,replaytime)" +
" values ('"+mid+"','"+replay+"','"+replayer+"','"+date+"') ";
String sql2 = "update guestbook set replay='1' where id='"+mid+"' ";
DBO dbo = new DBO();
dbo.open();
try{
int i = dbo.executeUpdate(sql);
int j = dbo.executeUpdate(sql2);
if(i == j && i== 1)
return Constant.SUCCESS;
else
return Constant.SYSTEM_ERROR;
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
// <09>޸Ļظ<C4BB>
public int upReplay(int mid ,String replay){
String sql = "update replay set replay='"+replay+"',replaytime='"+date+"' where mid='"+mid+"' ";
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();
}
}
// <09><>ѯ<EFBFBD><D1AF>Ա<EFBFBD>Ա<EFBFBD>
public String getSex(String username){
String sql = "select sex from member where username='"+username+"' ";
DBO dbo = new DBO();
dbo.open();
try{
rs = dbo.executeQuery(sql);
if(rs.next())
return rs.getString(1);
else
return null;
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
dbo.close();
}
}
}