Ejemplo n.º 1
0
        /// <summary>
        /// 验证用户名和密码是否正确
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>登录成功后的用户信息</returns>
        public SysPerson ValidateUser(string userName, string password)
        {
            if (String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(password))
                return null;

            //获取用户信息,请确定web.config中的连接字符串正确
            using (SysEntities db = new SysEntities())
            {
                var person = (from p in db.SysPerson
                              where p.Name == userName
                              && p.Password == password
                              && p.State == "开启"
                              select p).FirstOrDefault();
                if (person != null)
                {//登录成功
                    person.LastLogonTime = person.LogonTime;
                    person.LastLogonIP = person.LogonIP;
                    person.LogonNum++;
                    person.LogonTime = DateTime.Now;
                    person.LogonIP = Common.IP.GetIP();
                    db.SaveChanges();
                    return person;
                }

            } return null;
        }
 /// <summary>
 /// 验证用户名是否改变
 /// </summary>
 /// <param name="name">用户名</param>
 /// <returns></returns>
 public bool CheckName(SysPerson sysPerson)
 {
     using (SysEntities dbCheckName = new SysEntities())
     {
         SysPerson person = dbCheckName.SysPerson.FirstOrDefault(f => f.Id == sysPerson.Id);
         if (person != null)
         {
             if (sysPerson.Name == person.Name)
             {
                 return false;//没有修改用户名
             }
             else
             {
                 return CheckName(sysPerson.Name);
             }
         }
     }
     return true;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="personName">用户名</param>
        /// <param name="oldPassword">旧密码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns>修改密码是否成功</returns>
        public bool ChangePassword(string personName, string oldPassword, string newPassword)
        {
            if (!string.IsNullOrWhiteSpace(personName) && !string.IsNullOrWhiteSpace(oldPassword) && !string.IsNullOrWhiteSpace(newPassword))
            {
                try
                {
                    using (SysEntities db = new SysEntities())
                    {
                        var person = db.SysPerson.FirstOrDefault(p => (p.Name == personName) && (p.Password == oldPassword));
                        person.Password = newPassword;
                        person.SurePassword = newPassword;
                        db.SaveChanges();
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    ExceptionsHander.WriteExceptions(ex);
                }

            }
            return false;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public SysMenuBLL()
 {
     db = new SysEntities();
 }
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public SysPersonBLL()
 {
     db = new SysEntities();
 }
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public FileUploaderBLL()
 {
     db = new SysEntities();
 }
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public SysDepartmentBLL()
 {
     db = new SysEntities();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public SysRoleBLL(SysEntities entities)
 {
     db = entities;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public SysRoleBLL()
 {
     db = new SysEntities();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public SysFieldBLL()
 {
     db = new SysEntities();
 }
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public SysOperationBLL(SysEntities entities)
 {
     db = entities;
 }
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public SysOperationBLL()
 {
     db = new SysEntities();
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public SysLogBLL(SysEntities entities)
 {
     db = entities;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public SysLogBLL()
 {
     db = new SysEntities();
 }
Ejemplo n.º 15
0
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public SysPersonBLL(SysEntities entities)
 {
     db = entities;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public SysMenuBLL(SysEntities entities)
 {
     db = entities;
 }
Ejemplo n.º 17
0
        /// <summary>
        /// 创建一个菜单
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个菜单</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity)
        {
            int count = 1;

            foreach (string item in entity.SysOperationId.GetIdSort())
            {
                SysOperation sys = new SysOperation { Id = item };
                db.SysOperation.Attach(sys);
                entity.SysOperation.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                //创建后重置菜单编码
                List<int> flags = new List<int>();//层级
                GetMenus2(null, flags);
                db.SaveChanges();
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }
Ejemplo n.º 18
0
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public SysFieldBLL(SysEntities entities)
 {
     db = entities;
 }
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public SysMenuSysRoleSysOperationBLL()
 {
     db = new SysEntities();
 }
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public SysMenuSysRoleSysOperationBLL(SysEntities entities)
 {
     db = entities;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// 编辑一个角色
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个角色</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysRole entity)
        {  /*                       
                           * 不操作 原有 现有
                           * 增加   原没 现有
                           * 删除   原有 现没
                           */
            if (entity == null)
            {
                return false;
            }
            int count = 1;
            SysRole editEntity = repository.Edit(db, entity);

            List<string> addSysPersonId = new List<string>();
            List<string> deleteSysPersonId = new List<string>();
            DataOfDiffrent.GetDiffrent(entity.SysPersonId.GetIdSort(), entity.SysPersonIdOld.GetIdSort(), ref addSysPersonId, ref deleteSysPersonId);
            if (addSysPersonId != null && addSysPersonId.Count() > 0)
            {
                foreach (var item in addSysPersonId)
                {
                    SysPerson sys = new SysPerson { Id = item };
                    db.SysPerson.Attach(sys);
                    editEntity.SysPerson.Add(sys);
                    count++;
                }
            }
            if (deleteSysPersonId != null && deleteSysPersonId.Count() > 0)
            {
                List<SysPerson> listEntity = new List<SysPerson>();
                foreach (var item in deleteSysPersonId)
                {
                    SysPerson sys = new SysPerson { Id = item };
                    listEntity.Add(sys);
                    db.SysPerson.Attach(sys);
                }
                foreach (SysPerson item in listEntity)
                {
                    editEntity.SysPerson.Remove(item);//查询数据库
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("编辑角色出错了");
            }
            return false;
        }
 /// <summary>
 /// 构造函数,默认加载数据访问上下文
 /// </summary>
 public SysExceptionBLL()
 {
     db = new SysEntities();
 }
Ejemplo n.º 23
0
        /// <summary>
        /// 创建一个角色
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个角色</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysRole entity)
        {
            int count = 1;

            foreach (string item in entity.SysPersonId.GetIdSort())
            {
                SysPerson sys = new SysPerson { Id = item };
                db.SysPerson.Attach(sys);
                entity.SysPerson.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public SysExceptionBLL(SysEntities entities)
 {
     db = entities;
 }
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public SysDepartmentBLL(SysEntities entities)
 {
     db = entities;
 }
Ejemplo n.º 26
0
        /// <summary>
        /// 根据PersonId获取已经启用的菜单
        /// </summary>
        /// <param name="personId">人员的Id</param>
        /// <returns>菜单拼接的字符串</returns>
        public string GetMenuByAccount(ref Common.Account person)
        {
            using (SysEntities db = new SysEntities())
            {
                string personId = person.Id;
                var roleIds =
                           (
                           from r in db.SysRole
                           from p in r.SysPerson
                           where p.Id == personId
                           select r.Id
                           ).ToList();
                person.RoleIds = roleIds;

                List<SysMenu> menuNeed =
                            (
                            from m2 in db.SysMenu
                            from f in m2.SysMenuSysRoleSysOperation
                            where roleIds.Any(a => a == f.SysRoleId) && f.SysOperationId == null
                            select m2
                            ).Distinct().OrderBy(o => o.Remark).ToList();//此方法由临海人(qq:1012999282)提供
                //person.MenuIds = menuNeed.Where(w => w.IsLeaf == null).Select(s => s.Url).ToList();

                StringBuilder strmenu2 = new StringBuilder();//拼接菜单的字符串
                int lever = 0;//上一个菜单的层级
                int current = 0;//当前菜单的层级
                //在1.2版本中修改
                if (menuNeed.Count > 1)
                {
                    for (int i = 0; i < menuNeed.Count; i++)
                    {
                        current = menuNeed[i].Remark.Length / 4;//按照4位数字的编码格式

                        if (current == 1)//加载根目录的菜单
                        {
                            //解决ie6下没有滚动条的问题
                            strmenu2.Replace('^', ' ')
                                .Append(string.Format(" <div data-options=@iconCls:'{0}'@ title=@{1}@> <div class=@easyui-panel@ fit=@true@ border=@false@><ul class=@easyui-tree@ >^</ul></div></div>", menuNeed[i].Iconic, menuNeed[i].Name));
                        }
                        else if (current < lever)//进入上一个菜单层级
                        {
                            string replace = string.Empty;
                            for (int c = 0; c < lever - current; c++)//减少了几个层级
                            {
                                replace += ("</ul></li>");
                            }
                            if ((i == menuNeed.Count - 1) || (menuNeed[i].Remark.Length >= menuNeed[i + 1].Remark.Length))
                                strmenu2.Replace("^" + replace, replace + GetNode(menuNeed[i], true));
                            else
                                strmenu2.Replace("^" + replace, replace + GetNode(menuNeed[i], false));
                        }
                        else//进入本级菜单或者下一个菜单
                        {

                            if ((i == menuNeed.Count - 1) || (menuNeed[i].Remark.Length >= menuNeed[i + 1].Remark.Length))//最后一个,或者下一个长度不小于这个的长度
                                strmenu2.Replace("^", GetNode(menuNeed[i], true));
                            else
                                strmenu2.Replace("^", GetNode(menuNeed[i], false));

                        }
                        lever = current;
                    }
                }
                return strmenu2.ToString().Replace('@', '"').Replace('^', ' ');
            }
        }
 /// <summary>
 /// 已有数据访问上下文的方法中调用
 /// </summary>
 /// <param name="entities">数据访问上下文</param>
 public FileUploaderBLL(SysEntities entities)
 {
     db = entities;
 }
Ejemplo n.º 28
0
        /// <summary>
        /// 创建一个人员
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个人员</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysPerson entity)
        {
            int count = 1;
            if (CheckName(entity.Name))
            {
                validationErrors.Add("用户名已被占用,请换一个新的用户名");
                return false;
            }
            foreach (string item in entity.SysRoleId.GetIdSort())
            {
                SysRole sys = new SysRole { Id = item };
                db.SysRole.Attach(sys);
                entity.SysRole.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }