package com.bean;
/**
* 新闻管理
*
*/
import java.io.File;
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 NewsBean {
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 news where up='0' ";
private String sql2="select * from news where up='0' order by id desc ";
private String sql3="select count(*) from news where up='1' ";
private String sql4="select * from news where up='1' 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.getInt(1));
list2.add(rs.getString(2));
list2.add(rs.getString(3));
list2.add(rs.getString(5));
list2.add(rs.getString(6));
list2.add(rs.getInt(7));
list2.add(rs.getInt(8));
list2.add(rs.getInt(9));
list.add(list2);
} else {
break; //减少空循环的时间
}
}
return list;
} catch (SQLException ex) {
ex.printStackTrace();
return list;
} finally {
dbo.close();
}
}
/////////////////////////////////////////
//置顶新闻分页
public int getMessageCountUp() { //得到信息总数
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 getMessageUp(int page) { //得到每页要显示的信息
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(1));
list2.add(rs.getString(2));
list2.add(rs.getString(3));
list2.add(rs.getString(5));
list2.add(rs.getString(6));
list2.add(rs.getInt(7));
list2.add(rs.getInt(8));
list2.add(rs.getInt(9));
list.add(list2);
} else {
break; //减少空循环的时间
}
}
return list;
} catch (SQLException ex) {
ex.printStackTrace();
return list;
} finally {
dbo.close();
}
}
//add news
public int addNews(String title,String pic,String content,String adder,String ifhide){
String sql = "insert into news (title,pic,content,addtime,adder,ifhide,visit,up) " +
"values ('"+title+"','"+pic+"','"+content+"','"+date+"','"+adder+"','"+ifhide+"','0','0')";
String sql2 = "update news set ifhide='0' where pic!='无'";
DBO dbo = new DBO();
dbo.open();
try{
if(!pic.equals("无")){
dbo.executeUpdate(sql2);
}
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 news no pic
public int updateNews(int id,String title,String content,String adder,String ifhide){
String sql = "update news set title = '"+title+"',content='"+content+"',addtime='"+date+"'," +
"adder='"+adder+"',ifhide='"+ifhide+"' 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();
}
}
// update news with pic
public int updateNewsWithPic(int id,String title,String pic,String content,String adder,String ifhide){
String sql = "update news set title = '"+title+"',pic='"+pic+"',content='"+content+"',addtime='"+date+"'," +
"adder='"+adder+"',ifhide='"+ifhide+"' 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();
}
}
//delete news
public int delNews(int id[],String dir){
DBO dbo = new DBO();
dbo.open();
try{
for(int i = 0;i<id.length;i++){
rs = dbo.executeQuery("select pic from news where id='"+id[i]+"'");
rs.next();
String str=rs.getString(1);
del(dir+str);
dbo.executeUpdate("delete from news where id = '"+id[i]+"'");
}
return Constant.SUCCESS;
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
public void del(String filepath) {
try{
File f = new File(filepath);//定义文件路径
if(f.exists()){//判断是文件还是目录
f.delete();//递归调用
}
}catch(Exception e){
}
}
//屏蔽、显示新闻
public int hideNews(int id){
String sql = "update news set ifhide='1' where id='"+id+"'";
String sql2 = "update news set ifhide='0' where id='"+id+"'";
String sql3 = "select ifhide,pic from news where id='"+id+"'";
DBO dbo = new DBO();
dbo.open();
try{
rs = dbo.executeQuery(sql3);
rs.next();
int i = rs.getInt(1);
String pic=rs.getString(2);
if(!pic.trim().equals("无")){
dbo.executeUpdate("update news set ifhide='0' where pic!='无'");
}
if(i == 1){
int flag = dbo.executeUpdate(sql2);
if(flag == 1)
return Constant.SUCCESS;
else
return Constant.SYSTEM_ERROR;
}
else{
int flag = dbo.executeUpdate(sql);
if(flag == 1)
return Constant.SUCCESS;
else
return Constant.SYSTEM_ERROR;
}
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
//置顶 取消置顶 新闻
public int upNews(int id){
String sql = "upd
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
JAVA JSP MYSQL失物招领系统 源代码 (626个子文件)
class_upload.asp 6KB
class_upload.asp 6KB
commands.asp 5KB
upload.asp 3KB
connector.asp 3KB
io.asp 2KB
basexml.asp 2KB
config.asp 2KB
config.asp 2KB
util.asp 1KB
io.asp 836B
connector.aspx 1KB
upload.aspx 1KB
connector.cfm 11KB
spellchecker.cfm 6KB
upload.cfm 6KB
config.cfm 3KB
config.cfm 3KB
connector.cgi 4KB
SmartUpload.class 16KB
MemberBean.class 13KB
AfficheBean.class 12KB
NewsBean.class 12KB
TraveBean.class 12KB
MemberManageBean.class 12KB
GuestBookBean.class 9KB
NewsServlet.class 8KB
SystemBean.class 8KB
AdminBean.class 7KB
AdminServlet.class 7KB
MemberServlet.class 6KB
SmartFile.class 6KB
GuestBookServlet.class 5KB
ProServlet.class 5KB
MemberManageServlet.class 4KB
AfficheServlet.class 4KB
CommonServlet.class 4KB
LoginServlet.class 4KB
DBO.class 3KB
Common.class 2KB
SmartRequest.class 2KB
SmartFiles.class 2KB
Log.class 1KB
MD5.class 1KB
Filter.class 936B
CheckCode.class 887B
Constant.class 674B
SmartUploadException.class 364B
.classpath 709B
css.css 10KB
fck_editor.css 8KB
fck_editor.css 8KB
fck_editor.css 8KB
Admin_Style.css 6KB
Admin_Style.css 6KB
style.css 4KB
style.css 4KB
fck_internal.css 2KB
fck_dialog.css 2KB
fck_dialog.css 2KB
fck_dialog.css 2KB
fck_editorarea.css 2KB
browser.css 2KB
fck_dialog_common.css 2KB
fck_showtableborders_gecko.css 1KB
spellerStyle.css 888B
default.css 463B
Thumbs.db 67KB
Thumbs.db 17KB
Thumbs.db 16KB
Thumbs.db 10KB
Thumbs.db 8KB
MainBg.gif 25KB
MainBg.gif 25KB
fck_strip.gif 9KB
girl.gif 7KB
boy.gif 6KB
fck_strip.gif 4KB
fck_strip.gif 4KB
5.gif 4KB
4.gif 3KB
8.gif 3KB
11.gif 2KB
Key.gif 2KB
logo_fckeditor.gif 2KB
6.gif 2KB
10.gif 2KB
7.gif 2KB
zhuce.gif 2KB
Title.gif 2KB
1.gif 2KB
qq_22.gif 2KB
qq_22.gif 2KB
Title.gif 2KB
html.gif 1KB
htm.gif 1KB
rdp.gif 1KB
12.gif 1KB
back.gif 1KB
sub.gif 1KB
共 626 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
cadnxxx
- 粉丝: 8
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 风光储、风光储并网直流微电网simulink仿真模型 系统由光伏发电系统、风力发电系统、混合储能系统(可单独储能
- 微环谐振腔的光学频率梳matlab仿真 微腔光频梳仿真 包括求解LLE方程(Lugiato-Lefever equation)实
- 51单片机温室大棚温湿度光照控制系统资料包括原理图,PCB文件,源程序,一些软件等,仿真文件 设计简介: (1)51单片机+D
- 033.2.3-选择21-25.sz
- FLAC3D蠕变模型 伯格斯模型
- UE5中的UV编辑:深入探索创建与编辑工具
- MySQL基础语法-空间数据类型.pdf
- 深入探索Oracle与MySQL在备份与恢复方面的显著差异
- SVM及其实践系列博文对应的数据和代码
- UE5中的网格体编辑与几何体编辑:深入指南与代码示例
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功