📄 mainbean.java
字号:
+ e);
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
System.out
.println("MainBean.getArticle(String id1,String menu2,int cur,int records)关闭声明时statement出错"
+ e);
}
}
}
}
//if(rs!=null)try{ stmt = rs.getStatement();
// rs.close();}catch(Exception
// e){System.out.println("MainBean.getArticle(String id1,String
// menu2,int cur,int records)关闭记录集rs时出错"+e);}
//if(stmt!=null) try{stmt.close();}catch(Exception
// e){System.out.println("MainBean.getArticle(String id1,String
// menu2,int cur,int records)关闭声明时statement出错"+e);}
//检索文章编号
sql = "";
for (int i = 0; i < v_menu.size(); i++) {
if (!sql.equals(""))
sql += " union ";
sql += "select id from news.article where whichtable='1' and ifshow='1' and ORGANID='00000000000000000000' and menuid="
+ (String) v_menu.get(i);
}
for (int i = 0; i < v_child.size(); i++) {
if (!sql.equals(""))
sql += " union ";
sql += "select id from news.article where whichtable='0' and ifshow='1' and ORGANID='00000000000000000000' and menuid="
+ (String) v_child.get(i);
}
//计算总页数
rs = selectRecord("select count(id) from news.article where id in ("
+ sql + ") order by edittime desc");
rs.next();
int rows = rs.getInt(1);
int sum = rows / records;
if (rows % records != 0 || rows == 0)
sum++;
v_article.add("" + sum);
v_article.add("" + rows);
int pos = (cur - 1) * records + 1;
//if(rs!=null)try{ stmt = rs.getStatement();
// rs.close();}catch(Exception
// e){System.out.println("MainBean.getArticle(String id1,String
// menu2,int cur,int records)关闭记录集rs时出错"+e);}
//if(stmt!=null) try{stmt.close();}catch(Exception
// e){System.out.println("MainBean.getArticle(String id1,String
// menu2,int cur,int records)关闭声明时statement出错"+e);}
sql = "select id,title,addtime,hits from news.article where id in ("
+ sql + ") order by edittime desc";
rs = selectRecord(sql);
int i = 0;
ResultSetMetaData rsmd = rs.getMetaData();
int cols = 0;
cols = rsmd.getColumnCount();
while (rs.next()) {
i++;
if (i < pos)
continue;
Hashtable hash = new Hashtable();
for (int j = 1; j <= cols; j++) {
String field = ds.toString(rsmd.getColumnName(j));
String value = ds.toString(rs.getString(j));
hash.put(field, value);
}
v_article.add(hash);//把焦点文章信息存入
if ((v_article.size() - 2) == num)
break;
if (i == rows)
break;
}
//if(rs!=null)try{ stmt = rs.getStatement();
// rs.close();}catch(Exception
// e){System.out.println("MainBean.getArticle(String id1,String
// menu2,int cur,int records)关闭记录集rs时出错"+e);}
//if(stmt!=null) try{stmt.close();}catch(Exception
// e){System.out.println("MainBean.getArticle(String id1,String
// menu2,int cur,int records)关闭声明时statement出错"+e);}
} catch (Exception e) {
System.out
.println("MainBean.getArticle(String id1,String menu2,int cur,int records)运行时出错:"
+ e);
} finally {
//if(rs!=null)try{ stmt = rs.getStatement();
// rs.close();}catch(Exception
// e){System.out.println("MainBean.getArticle(String id1,String
// menu2,int cur,int records)关闭记录集rs时出错"+e);}
//if(stmt!=null) try{stmt.close();}catch(Exception
// e){System.out.println("MainBean.getArticle(String id1,String
// menu2,int cur,int records)关闭声明时statement出错"+e);}
}
if (rs != null)
try {
stmt = rs.getStatement();
rs.close();
} catch (Exception e) {
System.out.println("MainBean.getArticle(String id)关闭记录集rs时出错"
+ e);
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
System.out
.println("MainBean.getArticle(String id)关闭声明时statement出错"
+ e);
}
return v_article;
}
//生三级以下成树并返回根节点--------------------------------------------------------------------
public Vector buildTree() {
Vector vt = new Vector();
String sql = " Select * from news.MENU Where ID1 = " + id1
+ " and ID2 = " + id2 + " and ID3 = 0";
ResultSet rs1 = selectRecord(sql);
Statement stmt = null;
try {
ResultSetMetaData rsmd1 = rs1.getMetaData();
int cols1 = rsmd1.getColumnCount();
if (rs1.next()) {
Hashtable hash1 = new Hashtable();
for (int i1 = 1; i1 <= cols1; i1++) {
String field1 = ds.toString(rsmd1.getColumnName(i1));
String value1 = ds.toString(rs1.getString(i1));
hash1.put(field1, value1);
}
DefaultMutableTreeNode root1 = new DefaultMutableTreeNode(hash1);//生成二级节点,二级版面
sql = "select * from news.menu where id1=" + id1 + " and id2="
+ id2 + " and id3!=0 order by id3";
ResultSet rs2 = selectRecord(sql);
MenuChildBean mcb = null;
try {
ResultSetMetaData rsmd2 = rs2.getMetaData();
int cols2 = rsmd2.getColumnCount();
mcb = new MenuChildBean();
while (rs2.next()) {
Hashtable hash2 = new Hashtable();
for (int i2 = 1; i2 <= cols2; i2++) {
String field2 = ds
.toString(rsmd2.getColumnName(i2));
String value2 = ds.toString(rs2.getString(i2));
hash2.put(field2, value2);
}
DefaultMutableTreeNode root2 = new DefaultMutableTreeNode(
hash2);//生成三级节点,三级版面
String str = (String) hash2.get("ID");
mcb.setParentID(Integer.parseInt(str));
Vector child = mcb.buildTree();
if (child.size() != 0) {
for (int a = 0; a < child.size(); a++) {
DefaultMutableTreeNode root3 = (DefaultMutableTreeNode) child
.get(a);
root2.add(root3);
}
}
root1.add(root2);
}
vt.add(root1);
} catch (Exception e) {
System.out.println("MainBean.buildTree()运行时出错:" + e);
} finally {
if (mcb != null)
mcb.closeConn();
if (rs2 != null)
try {
stmt = rs2.getStatement();
rs2.close();
} catch (Exception e) {
System.out.println("MainBean.buildTree()关闭记录集rs时出错"
+ e);
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
System.out
.println("MainBean.buildTree()关闭声明时statement出错"
+ e);
}
}
}
} catch (Exception e) {
System.out.println("MainBean.buildTree()运行时出错:" + e);
} finally {
if (rs1 != null)
try {
stmt = rs1.getStatement();
rs1.close();
} catch (Exception e) {
System.out.println("MainBean.buildTree()关闭记录集rs时出错" + e);
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
System.out.println("MainBean.buildTree()关闭声明时statement出错"
+ e);
}
}
return vt;
}
//取得所有首页图片新闻-------------------------------------------------------------------------------
public Vector getPicNew() {
String sql = "";
sql = " select * from news.ARTICLE where IFSHOW = '1' and IFIMG='1' and IFHEAD='1' and ORGANID='00000000000000000000' order by edittime desc";
ResultSet rs = selectRecord(sql);
return getResultSetData(rs);
}
//取得某一版面的首页图片新闻----------------------------------------------------------
public Vector getPicNew(String id) {
String sql="";
sql="select ARTICLEID,FILENAME,HITS from news.PICNEWS where MENUID="+id;
ResultSet rs = selectRecord(sql);
Vector retV=new Vector();
int i=0;
try {
if (rs.next()) {
Hashtable hash=new Hashtable();
hash.put("ARTICLEID",ds.toString(rs.getString("FTPIP")));
hash.put("FILENAME",ds.toString(rs.getString("FILENAME")));
hash.put("HITS",ds.toString(rs.getString("HITS")));
retV.add(hash);
}
} catch (Exception e) {
System.out.println("运行时出错:" + e);
}
return retV;
}
//得天FTP的地址
public String getftpsite() {
String sql = "";
String ftpsite = "";
sql = "select FTPIP from news.NB_FTPSET";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try {
if (rs.next()) {
ftpsite = ds.toString(rs.getString("FTPIP"));
}
} catch (Exception e) {
System.out.println("运行时出错:" + e);
} finally {
if (rs != null)
try {
stmt = rs.getStatement();
rs.close();
} catch (Exception e) {
System.out.println("关闭记录集rs时出错" + e);
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
System.out.println("关闭声明时statement出错" + e);
}
}
return ftpsite;
}
//设置默认Css格式时,修改数据表
public void setMrCss(String cssstyle) {
String sql = "update NB_YSB set ISNOW=0 where STYLE!='" + cssstyle
+ "'";
deleteRecord(sql);
sql = "update NB_YSB set ISNOW=1 where STYLE='" + cssstyle + "'";
deleteRecord(sql);
}
//取得显示图片新闻的数目-----------------------------------------------------------------
public int getPicNum() {
String sql = "select NUM from news.NB_TPSZB";
ResultSet rs = selectRecord(sql);
return getIntByResultSet(rs, "NUM");
}
//取得显示图片新闻的高度-----------------------------------------------------------------
public int getPicHeight() {
String sql = "select HEIGHT from news.NB_TPSZB";
ResultSet rs = selectRecord(sql);
return getIntByResultSet(rs, "HEIGHT");
}
//取得显示图片新闻的宽度----------------------------------------------------------------
public int getPicWidth() {
String sql = "select WIDTH from news.NB_TPSZB";
ResultSet rs = selectRecord(sql);
return getIntByResultSet(rs, "WIDTH");
}
//取得所有公开的专题
public Vector getTopic() {
String sql = "select * from news.NB_TOPIC where STATUS = 0 order by edittime desc";
ResultSet rs = selectRecord(sql);
return getResultSetData(rs);
}
//取得某一版面下的公开的专题
public Vector getTopic(String muname) {
String sql = "";
int menuid1 = toID("news.MENU", "MENU1", "ID1", muname);
sql = "select * from news.NB_TOPIC where STATUS = 0 and MENUID1='"
+ menuid1 + "' order by JBXH";
ResultSet rs = selectRecord(sql);
return getResultSetData(rs);
}
//取得一级版面下的设置显示的新闻条数-----------------------------------------------------------------
public int getNewsNum(String i) {
String sql = "select NUM from news.NB_ZYSZB where ID = " + i + "";
ResultSet rs = selectRecord(sql);
return getIntByResultSet(rs, "NUM");
}
//取得一级版面的新闻后面是否显示时间----------------------------------------------------------------
public boolean isShowTime(String i) {
String sql = "select ISSHOWTIME from news.NB_ZYSZB where ID = " + i
+ "";
ResultSet rs = selectRecord(sql);
if (getIntByResultSet(rs, "ISSHOWTIME") == 1)
return true;
else
return false;
}
//取得主页设置中的所有信息-----------------------------------------------------------------------
public Vector getMain() {
String sql = " select * from news.NB_ZYSZB order by Id ";
ResultSet rs = selectRecord(sql);
return getResultSetData(rs);
}
//根据某文章ID取得某一篇文章信息--------------------------------------------------------------
public Hashtable getOneNews(String id) {
Hashtable hash = new Hashtable();
Vector v = new Vector();
String sql = "";
if (id.equals("")) {
return null;
}
sql = "select * from news.article where ID = " + id + "";
ResultSet rs = selectRecord(sql);
v = getResultSetData(rs);
hash = (Hashtable) v.get(0);
return hash;
}
//取得某文章的相关评论信息--------------------------------------------------------------------------
public Vector getRelateCom(String id) {
String sql = "select * from news.COMMENTB where ARTICLEID = " + id + "";
ResultSet rs = selectRecord(sql);
return getResultSetData(rs);
}
///public String getOneContent(String id) {
///////////////////////// String sql="select "
/// return content;
//}
//取得某文章的相关评论信息--------------------------------------------------------------------------
public Vector getRelateArticle(String id) {
String sql = "";
String keyword = toName("ARTICLE", "ID", "KEYWORD", id + "");
sql = "select ID,TITLE,ADDTIME,HITS from news.ARTICLE where ifshow='1' and ORGANID='00000000000000000000' and ID!="
+ id
+ " and (TITLE like '%"
+ keyword
+ "%' or KEYWORD like '%" + keyword + "%')";
ResultSet rs = selectRecord(sql);
return getResultSetData(rs);
}
//取得某一个版面下的文章------------------------------------------------------------
public Vector getArc(String menuid, String whichtable) {
String sql = "select * from news.ARTICLE where MENUID = "
+ menuid
+ " and IFSHOW = '1' and WHICHTABLE = '"
+ whichtable
+ "' and ORGANID='00000000000000000000' order by edittime desc";
ResultSet rs = selectRecord(sql);
return getResultSetData(rs);
}
//分页取得某一个版面下的文章------------------------------------------------------------
public Vector getArc(String menuid, String whichtable, int page, int records) {
String sql = "";
sql = "select ID,TITLE,ADDTIME,HITS from news.ARTICLE where MENUID = "
+ menuid
+ " and IFSHOW ='1' and WHICHTABLE = '"
+ whichtable
+ "' and ORGANID='00000000000000000000' order by edittime desc";
return db.getOnePage(sql, page, records, false);
}
//取得二级以下菜单的名称--------------------------------------------------------------
public String getMenuName(String menuid, String which) {
String sql = "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -