www.pudn.com > MyShop.rar > Admin.cs


using System; 
using System.Collections.Generic; 
 
using System.Data; 
 
 
using MyShop.DALFactory; 
using MyShop.IDAL; 
using MyShop.Model; 
 
namespace MyShop.BLL 
{ 
    public class Admin 
    { 
        private IAdmin dal = DataAccess.CreateAdmin(); 
 
        #region  IAdmin 
 
        ///  
        /// 密码未md5加密 
        ///  
        ///  
        ///  
        protected int Add(AdminInfo model) 
        { 
            if (model == null) 
            { 
                return 0; 
            } 
            return dal.Add(model); 
        } 
 
        protected int Delete(string filter) 
        { 
            if (string.IsNullOrEmpty(filter)) 
                return 0; 
            return dal.Delete(filter); 
        } 
 
        public bool Exist(string filter) 
        { 
            filter = filter.Trim(); 
            if (string.IsNullOrEmpty(filter)) 
                return false; 
            return dal.Exist(filter); 
        } 
        public DataSet GetDataSet() 
        { 
            return dal.GetDataSet(); 
        } 
 
        public DataSet GetDataSet(string filter) 
        { 
            filter = filter.Trim(); 
            if (string.IsNullOrEmpty(filter)) 
                return null; 
            return dal.GetDataSet(filter); 
        } 
 
        public AdminInfo GetModel(DataRow dr) 
        { 
            if (dr == null) 
                return null; 
            return dal.GetModel(dr); 
        } 
 
        private DataSet Query(string sql) 
        { 
            sql = sql.Trim(); 
            if (string.IsNullOrEmpty(sql)) 
                return null; 
            return dal.Query(sql); 
        } 
 
        public int Update(AdminInfo model, string filter) 
        { 
            if (model == null) 
                return 0; 
            filter = filter.Trim(); 
            if (string.IsNullOrEmpty(filter)) 
                return 0; 
            return dal.Update(model, filter); 
        } 
 
        #endregion 
 
        #region common 
 
        ///  
        /// 加入管理员,password应为已MD5加密 
        ///  
        ///  
        ///  
        ///  
        public int Add(AdminInfo model, out string msg) 
        { 
            msg = ""; 
            if (model == null) 
            { 
                msg = msg + "
  • 数据不能为空
  • "; return 0; } bool isErr = false; if (isErr) return 0; int count = 0; count = Add(model); if (count == 0) msg = "
  • 系统发生错误,请重新添加!
  • "; if (count == 1) msg = "
  • 添加成功!
  • "; return count; } /// /// 不能删除Admin管理员和ID ==1的管理员 /// /// /// public int Delete(int adminId) { if (string.IsNullOrEmpty(adminId.ToString()) || adminId == 1) return 0; AdminInfo model = new AdminInfo(); model = GetModel(adminId); if (model == null) return 0; if (model.AdminName == "admin") return 0; string filer; filer = " Id =" + adminId; return Delete(filer); } /// /// 删除自己以外的管理员(不能删除Admin管理员和ID ==1的管理员) /// /// 当前管理员ID /// public int DeleteAll(int adminId) { if (adminId == 0) return 0; return Delete( " Id <> 1 and adminName <> 'admin' and Id <> " + adminId ); } public int Update(AdminInfo model) { if (model == null) { return 0; } string filter; filter = " Id=" + model.ID; return Update(model, filter); } public AdminInfo GetModel(int adminId) { DataSet dataset = new DataSet(); dataset = GetDataSet(" Id=" + adminId); if (dataset != null && dataset.Tables[0].Rows.Count > 0) return GetModel(dataset.Tables[0].Rows[0]); return null; } public AdminInfo GetModel(string adminName) { adminName = Utils.ReplaceBadSQL(adminName.Trim()); if (string.IsNullOrEmpty(adminName.ToString())) return null; DataSet dataset = new DataSet(); dataset = GetDataSet(" adminName='" + adminName + "'"); if (dataset != null && dataset.Tables[0].Rows.Count > 0) return GetModel(dataset.Tables[0].Rows[0]); return null; } /// /// 管理员名是否已被注册 /// /// /// public bool ExistAdminName(string adminName) { if (string.IsNullOrEmpty(adminName)) return true; return Exist(" adminname ='" + Utils.ReplaceBadSQL(adminName.Trim()) + "'"); } /// /// 管理员是否存在 /// /// /// 未加密的明码 /// public bool Exist(string adminName, string password) { if (Exist("adminname = '" + Utils.ReplaceBadSQL( adminName.Trim() )+ "' and password = '" + Utils.MD5( Utils.ReplaceBadSQL(password)) + "'")) { return true; } else return false; } /// /// 管理员是否存在 /// /// /// 管理员密码 /// 管理员密码是否已MD5加密 /// public bool Exist(string adminName, string password, bool MD5) { password = Utils.ReplaceBadSQL(password); if (MD5) { if (Exist("adminname = '" + adminName + "' and password = '" + password + "'")) { return true; } else return false; } else { if (Exist("adminname = '" + adminName + "' and password = '" + Utils.MD5(password) + "'")) { return true; } else return false; } } #endregion } }