⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newsfunc.java~137~

📁 c++通信编程学习1
💻 JAVA~137~
字号:
package com.j2ee.func.news;

import java.util.Vector;
import java.sql.SQLException;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import com.j2ee.func.systemvia.SystemviaInfo;
import com.j2ee.func.systemvia.SystemviaFunc;
import com.j2ee.func.qyzp.ZpBean;
import com.j2ee.database.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class NewsFunc {
    public static String searchkey = "";
    public static String typep = "";
    public String sortid;
    public String sorttype;
    public int ptype; //哪一种类型;
    public int pageno; //分页的页数;
    public String type;
    public int id;
    public int flag=0; //是否过期的推荐新闻或文章;
    public TjnewsInfo ti;
    public NewsInfo nif;
    public NewsFunc() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public NewsFunc(int ptype, int pageno, String sortid, String sorttype) { //选出所有新闻
        this.ptype = ptype;
        this.pageno = pageno;
        this.sortid = sortid;
        this.sorttype = sorttype;
    }

    public NewsFunc(TjnewsInfo ti) {
        this.ti = ti;
    }

    public NewsFunc(String type) {
        this.type = type;
    }

    public NewsFunc(String type, int flag) {
        this.type = type;
        this.flag = flag;

    }

    public NewsFunc(String type, int page, int ptype) {
        this.type = type;
        this.pageno = page;
        this.ptype = ptype;
    }

    public NewsFunc(int id) {
        this.id = id;
    }

    public NewsFunc(NewsInfo nif) {
        this.nif = nif;
    }

    public String selecttopNewssql() {
        String sql = "select * from news where type='" + this.type +
                     "'order by newsdate desc limit 5";
        return sql;
    }

    public Vector SelecttopNews() throws SQLException { //取出type类型的数据
        NewsBean nb = new NewsBean();
        Vector vct = nb.selectNews(selecttopNewssql());
        return vct;
    }

    public int SelectCount() throws SQLException {
        String sql = "select count(*) from news where type like '%" + this.type +
                     "%'";
        NewsBean nb = new NewsBean();
        int count = nb.selectCount(sql);
        return count;
    }


    public String selectNewssql() throws SQLException {
        SystemviaFunc svf = new SystemviaFunc();
        Vector vct = svf.getPagesize();
        SystemviaInfo svi = (SystemviaInfo) vct.firstElement();
        int pagestart = 0, pagesize = 100;
        if (this.ptype == 1) {
            pagestart = (this.pageno - 1) * svi.getPagesizeone(); //一级页面
            pagesize = svi.getPagesizeone();
        } else if (this.ptype == 2) {
            pagestart = (this.pageno - 1) * svi.getPagesizetwo(); //2级页面
            pagesize = svi.getPagesizetwo();
        } else if (this.ptype == 3) {
            pagestart = (this.pageno - 1) * svi.getPagesizethree(); //3级页面
            pagesize = svi.getPagesizethree();
        } else if (this.ptype == 4) {
            pagestart = (this.pageno - 1) * svi.getPagesizeback(); //后台页面大小;
            pagesize = svi.getPagesizeback();
        }
        String sql = "select * from news where type like '%" + this.type +
                     "%' order by newsdate desc limit " + pagestart + "," +
                     pagesize;
        return sql;
    }

    public Vector SelectNews() throws SQLException { //取出type类型的数据
        NewsBean nb = new NewsBean();
        Vector vct = nb.selectNews(selectNewssql());
        return vct;
    }

    public String selectdetailNewssql() {
        String sql = "select * from news where  id='" + this.id + "'";
        return sql;
    }

    public Vector SelectdetailNews() throws SQLException { //显示详细信息
        NewsBean nb = new NewsBean();
        Vector vct = nb.selectNews(selectdetailNewssql());
        return vct;
    }

    public boolean increaseCount() {
        String sql = "update news set seecount=seecount+1 where id='" + this.id +
                     "'";
        NewsBean nb = new NewsBean();
        boolean bl = nb.updateSeecount(sql);
        return bl;
    }

    public String selecttalltitle() {
        String sql = "select * from news order by newsdate desc limit 5";
        return sql;
    }

    public Vector selectTalltitle() throws SQLException {
        NewsBean nb = new NewsBean();
        Vector vct = nb.selectNews(selecttalltitle());
        return vct;
    }

    public String selectTjnews() {
        String sql = "select * from news,tjnews  where news.type='" + this.type +
                     "' and news.id=tjnews.newsid order by news.newsdate desc limit 3";
        return sql;
    }

    public Vector SelectTjnews() throws SQLException {
        NewsBean nb = new NewsBean();
        Vector vct = null;
        vct = nb.selectTjnews(selectTjnews());
        return vct;
    }

//************ 热点新闻
     public String selectTopnews() {
         String sql = "select * from news order by seecount desc limit 10";
         return sql;
     }

    public Vector SelectTopNews() throws SQLException { //显示详细信息
        NewsBean nb = new NewsBean();
        Vector vct = nb.selectNews(selectTopnews());
        return vct;
    }

//************ 添加xinwen类
     public String addNewsSql() {
         Calendar now = Calendar.getInstance();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         String date = sdf.format(now.getTime());
         String sql = "insert into news values(null,'" + nif.getTitle() + "','" +
                      nif.getContent() +
                      "','" + nif.getAuthor() + "','" + nif.getType() + "','" +
                      nif.getComefrom() + "','" +
                      date + "',0)";
         return sql;
     }

    public boolean addNews() {
        NewsBean nb = new NewsBean();
        boolean bl = nb.insertNews(addNewsSql());
        return bl;
    }

    //***************选出所有的新闻进行管理

     public int getAllNewscount() throws SQLException {
         String sql = "select count(*) from news";
         ZpBean zb = new ZpBean();
         int count = zb.getpositionCount(sql);
         return count;
     }

    public int getPagesize() throws SQLException {
        SystemviaFunc svf = new SystemviaFunc();
        Vector vct = svf.getPagesize();
        SystemviaInfo svi = (SystemviaInfo) vct.firstElement();
        int pagestart = 0, pagesize = 0;
        if (this.ptype == 1) {
            pagestart = (this.pageno - 1) * svi.getPagesizeone(); //一级页面
            pagesize = svi.getPagesizeone();
        } else if (this.ptype == 2) {
            pagestart = (this.pageno - 1) * svi.getPagesizetwo(); //2级页面
            pagesize = svi.getPagesizetwo();
        } else if (this.ptype == 3) {
            pagestart = (this.pageno - 1) * svi.getPagesizethree(); //3级页面
            pagesize = svi.getPagesizethree();
        } else if (this.ptype == 4) {
            pagestart = (this.pageno - 1) * svi.getPagesizeback(); //后台页面大小;
            pagesize = svi.getPagesizeback();
        }
        return pagesize;
    }

    public Vector getAllNews() throws SQLException {
        SystemviaFunc svf = new SystemviaFunc();
        Vector vct = svf.getPagesize();
        SystemviaInfo svi = (SystemviaInfo) vct.firstElement();
        int pagestart = 0, pagesize = 100;
        if (this.ptype == 1) {
            pagestart = (this.pageno - 1) * svi.getPagesizeone(); //一级页面
            pagesize = svi.getPagesizeone();
        } else if (this.ptype == 2) {
            pagestart = (this.pageno - 1) * svi.getPagesizetwo(); //2级页面
            pagesize = svi.getPagesizetwo();
        } else if (this.ptype == 3) {
            pagestart = (this.pageno - 1) * svi.getPagesizethree(); //3级页面
            pagesize = svi.getPagesizethree();
        } else if (this.ptype == 4) {
            pagestart = (this.pageno - 1) * svi.getPagesizeback(); //后台页面大小;
            pagesize = svi.getPagesizeback();
        }
        NewsBean nb = new NewsBean();
        String sql = " select * from news  where (title like '%" +
                     this.searchkey + "%'" +
                     " or author like '%" + this.searchkey +
                     "%' or type like '%" + this.searchkey + "%'" +
                     "  or newsdate like '%" + this.searchkey +
                     "%' or content like '%" + this.searchkey + "%' )" +
                     " and type like '%" + this.typep + "%' order by " +
                     this.sortid + " " +
                     this.sorttype + " limit " + pagestart + "," + pagesize;
        Vector vctall = nb.selectNews(sql);
        return vctall;
    }

    public boolean upDateNews() {
        String sql = " update news set title='" + nif.getTitle() +
                     "', content='" + nif.getContent() +
                     "', author='" + nif.getAuthor() + "',type='" + nif.getType() +
                     "', comefrom='" + nif.getComefrom() + "' where id=" +
                     nif.getId();
        NewsBean nb = new NewsBean();
        boolean bl = nb.updateSeecount(sql);
        return bl;
    }

    public boolean deleteNews() {
        String sql = "delete from news where id=" + this.id;
        NewsBean nb = new NewsBean();
        boolean bl = nb.deleteNews(sql);
        String sql1 = "delete from tjnews where newsid=" + this.id;
        NewsBean nb1 = new NewsBean();
        boolean b= nb1.deleteNews(sql1);
        return bl;
    }
//**************************************************
     public boolean deleteNewstj() {
         String sql = "delete from tjnews where newsid=" + this.id;
         NewsBean nb = new NewsBean();
         boolean bl = nb.deleteNews(sql);
         return bl;
     }

    //********************管理是否过期的推荐文章或新闻;
     public String selectmanaTjnews() {
         Calendar now = Calendar.getInstance();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         String date = sdf.format(now.getTime());
         String sql=null;
         if (flag==2) { //非过期文章
             sql = "select * from news,tjnews  where news.type='" +
                   this.type +
                   "' and news.id=tjnews.newsid and " +
                   " tjnews.begindate <='" + date +
                   "' and tjnews.enddate >='" + date +
                   "' order by news.newsdate desc limit 3";
         }
         else if(flag==1){ //过期文章;
             sql = "select * from news,tjnews  where news.type='" +
                   this.type +
                   "' and news.id=tjnews.newsid and " +
                   " tjnews.enddate <='" + date +
                   "' order by news.newsdate desc limit 3";
         }
         return sql;
     }

    public Vector SelectmanaTjnews() throws SQLException {
        NewsBean nb = new NewsBean();
        Vector vct = null;
        vct = nb.selectTjnews(selectmanaTjnews());
        return vct;
    }

    //******判断是否存在该新闻;
     public boolean ifExistTjnews() {
         String sql = "select * from news where id='" + this.flag +
                      "' and type='" + this.type + "'";
         J2eedatabase j2db = new J2eedatabase();
         boolean bl = j2db.isExitInDB(sql);
         return bl;
     }

    public boolean insertTjnews() {
        String sql = "insert into tjnews values(null,'" + ti.getNewsid() +
                     "','" + ti.getBeginddate() +
                     "','" + ti.getEnddate() + "')";
        NewsBean nb = new NewsBean();
        boolean bl = nb.insertNews(sql);
        return bl;
    }

    private void jbInit() throws Exception {
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -