📄 cmsinfodaoim.java
字号:
package com.yhcms.cmsinfo.dao;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import com.yhcms.cmsinfo.bean.AboutUsInfo;
import com.yhcms.cmsinfo.bean.CmsInfo;
import com.yhcms.cmsinfo.bean.Link;
import com.yhcms.cmsinfo.bean.Notice;
import com.yhcms.cmsinfo.bean.Survey;
import com.yhcms.cmsinfo.dto.LinkDto;
import com.yhcms.cmsinfo.itface.CmsInfoDao;
import com.yhcms.db.DBConnException;
import com.yhcms.db.DBConnect;
/**
* <p>Title:系统属性数据操作</p>
* <li>系统各属性的相关操作</li>
* <br><b>CopyRight: yyhweb[由由华网]</b>
* @author stephen
* @version YH-2.0
*/
public class CmsInfoDaoIm implements CmsInfoDao {
private static Logger yhlog = Logger.getLogger(CmsInfoDaoIm.class.getName());
private DBConnect dbconn = null;
private static CmsInfoDaoIm cmsinfodao = new CmsInfoDaoIm();
/**
* @return 取得一个系统文章操作对象
*/
public static CmsInfoDaoIm getInstance(){
return cmsinfodao;
}
public CmsInfo getCmsInfo() throws DBConnException {
CmsInfo curInfo = null;
String sql = "select i.name,i.url,i.title,i.logo,i.banner,i.banlink,i.copyright," +
"i.record,i.contact from info as i";
try{
dbconn = new DBConnect(sql);
dbconn.executeQuery();
if(dbconn.next()){
curInfo = new CmsInfo();
curInfo.setName(dbconn.getString(1));
curInfo.setUrl(dbconn.getString(2));
curInfo.setTitle(dbconn.getString(3));
curInfo.setLogo(dbconn.getString(4));
curInfo.setBanner(dbconn.getString(5));
curInfo.setBanlink(dbconn.getString(6));
curInfo.setCopyright(dbconn.getString(7));
curInfo.setRecord(dbconn.getString(8));
curInfo.setContact(dbconn.getString(9));
}
}catch(Exception e){
yhlog.warn("When get system info,throw an Exception!");
}finally{
dbconn.close();
}
return curInfo;
}
public boolean updateCmsInfo(CmsInfo cmsInfo) throws DBConnException {
int i = 0;
String sql = "update info set name=?,url=?,title=?,logo=?,banner=?,banlink=?,copyright=?,record=?,contact=?";
// String sql = "update info set name='"+cmsInfo.getName()+"',url='"+cmsInfo.getUrl()+"',title='"+
// cmsInfo.getTitle()+"',logo='"+cmsInfo.getLogo()+"',banner='"+cmsInfo.getBanner()+"',banlink='"+
// cmsInfo.getBanlink()+"',copyright='"+cmsInfo.getCopyright()+"',record='"+cmsInfo.getRecord()+
// "',contact='"+cmsInfo.getContact()+"'";
try{
dbconn = new DBConnect(sql);
dbconn.setString(1, cmsInfo.getName());
dbconn.setString(2, cmsInfo.getUrl());
dbconn.setString(3, cmsInfo.getTitle());
dbconn.setString(4, cmsInfo.getLogo());
dbconn.setString(5, cmsInfo.getBanner());
dbconn.setString(6, cmsInfo.getBanlink());
dbconn.setString(7, cmsInfo.getCopyright());
dbconn.setString(8, cmsInfo.getRecord());
dbconn.setString(9, cmsInfo.getContact());
i = dbconn.executeUpdate();
}catch(Exception e){
yhlog.warn("When update system info,throw an Exception!");
}finally{
dbconn.close();
}
if(i>0){
yhlog.info("Update system info successfully.");
return true;
}else{
yhlog.info("Update system info unsuccessfully.");
return false;
}
}
public boolean addAboutUs(AboutUsInfo aboutus,String info) throws DBConnException {
int i = 0;
String content = "";
content = aboutus.getAboutus();
String sql = "";
// 先判断数据库里是否有数据
if(getAboutUs(info)!=null){
if(updateAboutUs(aboutus,info)){
return true;
}else{
return false;
}
}else{
if(info.equals("aboutus")){
sql = "insert into aboutus(id,aboutus) values(?,?)";
}
if(info.equals("copyright")){
sql = "insert into aboutus(id,copyright) values(?,?)";
}
if(info.equals("contactus")){
sql = "insert into aboutus(id,contactus) values(?,?)";
}
}
try{
dbconn = new DBConnect(sql);
dbconn.setInt(1, 1);
dbconn.setString(2, content);
i = dbconn.executeUpdate();
}catch(Exception e){
yhlog.warn("When update system "+info+" info,throw an Exception!");
}finally{
dbconn.close();
}
if(i>0){
yhlog.info("Update system "+info+" info successfully.");
return true;
}else{
yhlog.info("update system "+info+" info unsuccessfully.");
return false;
}
}
public boolean updateAboutUs(AboutUsInfo aboutus,String info) throws DBConnException {
int i = 0;
String content = aboutus.getAboutus();
String sql = "";
if(info.equals("aboutus")){
sql = "update aboutus set aboutus=? where id=1";
}
if(info.equals("copyright")){
sql = "update aboutus set copyright=? where id=1";
}
if(info.equals("contactus")){
sql = "update aboutus set contactus=? where id=1";
}
try{
dbconn = new DBConnect(sql);
dbconn.setString(1, content);
i = dbconn.executeUpdate();
}catch(Exception e){
yhlog.warn("When update system "+info+" info,throw an Exception!");
}finally{
dbconn.close();
}
if(i>0){
yhlog.info("Update system "+info+" info successfully.");
return true;
}else{
yhlog.info("Update system "+info+" info unsuccessfully.");
return false;
}
}
public AboutUsInfo getAboutUs(String action) throws DBConnException {
AboutUsInfo aboutus = null;
String info = action;
String sql = "";
if(info.equals("aboutus")){
sql = "select a.id,a.aboutus from aboutus as a";
}
if(info.equals("copyright")){
sql = "select a.id,a.copyright from aboutus as a";
}
if(info.equals("contactus")){
sql = "select a.id,a.contactus from aboutus as a";
}
try{
dbconn = new DBConnect(sql);
dbconn.executeQuery();
if(dbconn.next()){
aboutus = new AboutUsInfo();
aboutus.setId(dbconn.getInt(1));
aboutus.setAboutus(dbconn.getString(2));
}
}catch(Exception e){
yhlog.warn("When get system "+info+" info,throw an Exception!");
}finally{
dbconn.close();
}
return aboutus;
}
public Notice getNotice(int id) throws DBConnException {
Notice notice = null;
String sql = "select n.name,n.content,n.display,n.posttime,n.byuser from notice as n where n.id="+id;
try{
dbconn = new DBConnect(sql);
dbconn.executeQuery();
if(dbconn.next()){
notice = new Notice();
notice.setId(id);
notice.setName(dbconn.getString(1));
notice.setContent(dbconn.getString(2));
notice.setDisplay(dbconn.getString(3));
notice.setPosttime(dbconn.getString(4));
notice.setByuser(dbconn.getString(5));
}
}catch(Exception e){
yhlog.warn("When get system notice,throw an Exception!The notice id is:"+id+".");
}finally{
dbconn.close();
}
return notice;
}
public List getAllNotice() throws DBConnException {
List nlist = new ArrayList();
Notice notice = null;
String str = "";
String sql = "select n.id,n.name,n.content,n.display,n.posttime,n.byuser " +
"from notice as n order by n.id desc";
try{
dbconn = new DBConnect(sql);
dbconn.executeQuery();
while(dbconn.next()){
notice = new Notice();
notice.setId(dbconn.getInt(1));
notice.setName(dbconn.getString(2));
str = dbconn.getString(3);
if(str.length()>18){
notice.setContent(str.substring(0,18)+"......");
}else{
notice.setContent(str);
}
notice.setAllcontent(str);
notice.setDisplay(dbconn.getString(4));
notice.setPosttime(dbconn.getString(5));
notice.setByuser(dbconn.getString(6));
nlist.add(notice);
}
}catch(Exception e){
yhlog.warn("When get system all notice,throw an Exception!");
}finally{
dbconn.close();
}
return nlist;
}
public boolean addNotice(Notice notice) throws DBConnException {
int i = 0;
String name = notice.getName();
String display = notice.getDisplay();
String content = notice.getContent();
String posttime = notice.getPosttime();
String byuser = notice.getByuser();
String sql = "insert into notice(name,content,display,posttime,byuser) values('"+name+"','"+content+
"','"+display+"','"+posttime+"','"+byuser+"')";
try{
dbconn = new DBConnect(sql);
i = dbconn.executeUpdate();
}catch(Exception e){
yhlog.warn("When insert a notice,throw an Exception!");
}finally{
dbconn.close();
}
if(i>0){
yhlog.info("Insert a notice successfully.");
return true;
}else{
yhlog.info("Insert a notice unsuccessfully.");
return false;
}
}
public boolean deleteNotice(int id) throws DBConnException {
int i = 0;
String sql = "delete from notice where id="+id;
try{
dbconn = new DBConnect(sql);
i = dbconn.executeUpdate();
}catch(Exception e){
yhlog.warn("When delete a notice,throw an Exception!The notice id is:"+id+".");
}finally{
dbconn.close();
}
if(i>0){
yhlog.info("Delete a notice successfully,the notice id is:"+id+".");
return true;
}else{
yhlog.info("Delete a notice unsuccessfully,the notice id is:"+id+".");
return false;
}
}
public boolean updateNotice(Notice notice) throws DBConnException {
int i = 0;
int id = notice.getId();
String name = notice.getName();
String content = notice.getContent();
String display = notice.getDisplay();
String posttime = notice.getPosttime();
String byuser = notice.getByuser();
String sql = "update notice set name='"+name+"',content='"+content+"',display='"+display+
"',posttime='"+posttime+"',byuser='"+byuser+"' where id="+id;
try{
dbconn = new DBConnect(sql);
i = dbconn.executeUpdate();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -