AdminService.java
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:3k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

JavaScript

  1. package com.chinacannel.xlchemical.service;
  2. import org.apache.commons.logging.Log;
  3. import org.apache.commons.logging.LogFactory;
  4. import com.chinacannel.common.CommonDAO;
  5. import com.chinacannel.common.DAOException;
  6. import com.chinacannel.common.TranUtil;
  7. import com.chinacannel.entity.Admin;
  8. import java.util.List;
  9. import com.chinacannel.entity.Role;
  10. import com.chinacannel.common.PageInfo;
  11. public class AdminService extends TranUtil {
  12.     private CommonDAO dao = new CommonDAO();
  13.     private static Log log = LogFactory.getLog(AdminService.class);
  14.     public Admin CheckLogin(String Name, String Pwd) {
  15.         Admin admin = null;
  16.         try {
  17.             admin = (Admin) dao.loadOneObjectBySQL
  18.                     ("from Admin where Adm_Name='" + Name + "' and Adm_Pwd='" +
  19.                      Pwd + "'");
  20.             return admin;
  21.         } catch (DAOException ex) {
  22.             log.error(ex.getMessage(), ex);
  23.             return null;
  24.         }
  25.     }
  26.     public boolean AddAdmin(Admin adm) {
  27.         try {
  28.             return dao.createObject(adm);
  29.         } catch (DAOException ex) {
  30.             log.error(ex.getMessage(), ex);
  31.             return false;
  32.         }
  33.     }
  34.     public boolean UpdateAdmin(Admin adm) {
  35.         try {
  36.             return dao.updateObject(adm);
  37.         } catch (DAOException ex) {
  38.             log.error(ex.getMessage(), ex);
  39.             return false;
  40.         }
  41.     }
  42.     public boolean DeleteAdmin(Admin adm) {
  43.         try {
  44.             return dao.removeObject(adm);
  45.         } catch (DAOException ex) {
  46.             log.error(ex.getMessage(), ex);
  47.             return false;
  48.         }
  49.     }
  50.     public Admin GetAdminById(Long ID) {
  51.         try {
  52.             return (Admin) dao.loadObject(ID, Admin.class);
  53.         } catch (DAOException ex) {
  54.             log.error(ex.getMessage(), ex);
  55.             return null;
  56.         }
  57.     }
  58.     public List getAdminList(String name, Role role, int start, int top) {
  59.         List list = null;
  60.         String hql = "from Admin as adm where adm.adm_ID!=" + 0;
  61.         try {
  62.             if (role != null) {
  63.                 hql += " and adm.role.rol_ID=" + role.getRol_ID();
  64.             }
  65.             if (!name.equals("")) {
  66.                 hql += " and adm.adm_Name like '%" + name + "%'";
  67.             }
  68.             hql += " order by adm.adm_Time desc";
  69.             list = dao.loadObjectListBySQL(hql, start, top);
  70.         } catch (DAOException ex) {
  71.             log.error(ex.getMessage(), ex);
  72.             return null;
  73.         }
  74.         return list;
  75.     }
  76.     public int getCount(String name, Role role) {
  77.         String hql =
  78.                 "select count(*) from Admin as adm where adm.adm_ID!=" + 0;
  79.         if (role != null) {
  80.             hql += " and adm.role.rol_ID='" + role.getRol_ID() + "'";
  81.         }
  82.         if (!name.equals("")) {
  83.             hql += " and adm.adm_Name like '%" + name + "%'";
  84.         }
  85.         try {
  86.             return dao.getCountBySql(hql);
  87.         } catch (DAOException ex) {
  88.             log.error(ex.getMessage(), ex);
  89.             return 0;
  90.         }
  91.     }
  92.     public PageInfo getPageInfo(String name, Role role, int pageno) {
  93.         PageInfo pageInfo = new PageInfo(this.getCount(name, role), pageno, 10);
  94.         pageInfo.setRows(this.getAdminList(name, role, pageInfo.getStartRow(),
  95.                                            pageInfo.getPageSize()));
  96.         return pageInfo;
  97.     }
  98. }