Example #1
0
 /// <summary>
 /// 添加成员
 /// </summary>
 /// <param name="authorizeType">权限分类</param>
 /// <param name="objectId">对象Id</param>
 /// <param name="userIds">成员Id</param>
 public void SaveMember(AuthorizeTypeEnum authorizeType, string objectId, string[] userIds)
 {
     try
     {
         using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction())
         {
             Base_UserRelation.Delete("where ObjectId=@0 and IsDefault=0", objectId);
             int SortCode = 1;
             foreach (string item in userIds)
             {
                 UserRelationEntity userRelationEntity = new UserRelationEntity();
                 userRelationEntity.Create();
                 userRelationEntity.Category = (int)authorizeType;
                 userRelationEntity.ObjectId = objectId;
                 userRelationEntity.UserId   = item;
                 userRelationEntity.SortCode = SortCode++;
                 Base_UserRelation userrelation = EntityConvertTools.CopyToModel <UserRelationEntity, Base_UserRelation>(userRelationEntity, null);
                 userrelation.Insert();
             }
             tran.Complete();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #2
0
 /// <summary>
 /// 删除用户
 /// </summary>
 /// <param name="keyValue">主键</param>
 public void RemoveForm(string keyValue)
 {
     using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction())
     {
         Base_User.Delete("where UserId=@0", keyValue);
         Base_UserRelation.Delete("where UserId=@0", keyValue);
         Base_UserRole.Delete("where UserId=@0", keyValue);
         Base_UserAuthorize.Delete("where UserId=@0", keyValue);
         tran.Complete();
     }
 }
Example #3
0
        /// <summary>
        /// 获取对象列表
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public IEnumerable <UserRelationEntity> GetObjectList(string userId)
        {
            var sql = PetaPoco.Sql.Builder.Append(@"select * from Base_UserRelation where 1=1 ");

            if (!string.IsNullOrEmpty(userId))
            {
                sql.Append(" and UserId=@0", userId);
            }
            sql.Append(" order by CreateDate desc");
            var list = Base_UserRelation.Query(sql);

            return(EntityConvertTools.CopyToList <Base_UserRelation, UserRelationEntity>(list.ToList()));
        }
Example #4
0
        /// <summary>
        /// 保存用户表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="userEntity">用户实体</param>
        /// <returns></returns>
        public string SaveForm(string keyValue, UserEntity userEntity)
        {
            try
            {
                using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction())
                {
                    #region 基本信息
                    if (!string.IsNullOrEmpty(keyValue))
                    {
                        userEntity.Modify(keyValue);
                        userEntity.Password = null;
                        Base_User model = Base_User.SingleOrDefault("where UserId=@0", keyValue);
                        model        = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, model);
                        model.UserId = keyValue;
                        model.Update();
                    }
                    else
                    {
                        userEntity.Create();
                        keyValue               = userEntity.UserId;
                        userEntity.Secretkey   = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower();
                        userEntity.Password    = Md5Helper.MD5(DESEncrypt.Encrypt(userEntity.Password, userEntity.Secretkey).ToLower(), 32).ToLower();
                        userEntity.EnabledMark = 1;
                        userEntity.DeleteMark  = 0;
                        Base_User model = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, null);
                        model.Insert();
                    }
                    #endregion

                    #region 默认添加 角色、岗位、职位
                    Base_UserRelation.Delete("where UserId=@0 and IsDefault=1", userEntity.UserId);
                    List <UserRelationEntity> userRelationEntitys = new List <UserRelationEntity>();
                    //角色 这里多个角色逻辑处理
                    //if (!string.IsNullOrEmpty(userEntity.RoleId))
                    //{
                    //    userRelationEntitys.Add(new UserRelationEntity
                    //    {
                    //        Category = (int)QSDMS.Model.Enums.UserCategoryEnum.角色,
                    //        UserRelationId = Guid.NewGuid().ToString(),
                    //        UserId = userEntity.UserId,
                    //        ObjectId = userEntity.RoleId,
                    //        CreateDate = DateTime.Now,
                    //        CreateUserId = OperatorProvider.Provider.Current().UserId,
                    //        CreateUserName = OperatorProvider.Provider.Current().UserName,
                    //        IsDefault = 1,
                    //    });
                    //}
                    //一个用户多个角色
                    if (!string.IsNullOrEmpty(userEntity.RoleId))
                    {
                        Base_UserRole.Delete("where UserId=@0", userEntity.UserId);
                        string[] roles = userEntity.RoleId.Split(',');
                        for (int i = 0; i < roles.Length; i++)
                        {
                            //用户角色表
                            string roleid   = roles[i];
                            var    userrole = new UserRoleEntity();
                            userrole.UserRoleId = Util.Util.NewUpperGuid();
                            userrole.UserId     = userEntity.UserId;
                            userrole.RoleId     = roleid.Split('|')[0];
                            userrole.RoleName   = roleid.Split('|')[1];
                            Base_UserRole model = EntityConvertTools.CopyToModel <UserRoleEntity, Base_UserRole>(userrole, null);
                            model.Insert();

                            //用户关系表
                            userRelationEntitys.Add(new UserRelationEntity
                            {
                                Category       = (int)QSDMS.Model.Enums.UserCategoryEnum.角色,
                                UserRelationId = Guid.NewGuid().ToString(),
                                UserId         = userEntity.UserId,
                                ObjectId       = userrole.RoleId,
                                CreateDate     = DateTime.Now,
                                CreateUserId   = OperatorProvider.Provider.Current().UserId,
                                CreateUserName = OperatorProvider.Provider.Current().UserName,
                                IsDefault      = 1,
                            });
                        }
                    }
                    //岗位
                    if (!string.IsNullOrEmpty(userEntity.DutyId))
                    {
                        userRelationEntitys.Add(new UserRelationEntity
                        {
                            Category       = (int)QSDMS.Model.Enums.UserCategoryEnum.岗位,
                            UserRelationId = Guid.NewGuid().ToString(),
                            UserId         = userEntity.UserId,
                            ObjectId       = userEntity.DutyId,
                            CreateDate     = DateTime.Now,
                            CreateUserId   = OperatorProvider.Provider.Current().UserId,
                            CreateUserName = OperatorProvider.Provider.Current().UserName,
                            IsDefault      = 1,
                        });
                    }
                    //职位
                    if (!string.IsNullOrEmpty(userEntity.PostId))
                    {
                        userRelationEntitys.Add(new UserRelationEntity
                        {
                            Category       = (int)QSDMS.Model.Enums.UserCategoryEnum.职位,
                            UserRelationId = Guid.NewGuid().ToString(),
                            UserId         = userEntity.UserId,
                            ObjectId       = userEntity.PostId,
                            CreateDate     = DateTime.Now,
                            CreateUserId   = OperatorProvider.Provider.Current().UserId,
                            CreateUserName = OperatorProvider.Provider.Current().UserName,
                            IsDefault      = 1,
                        });
                    }
                    //插入用户关系表
                    foreach (UserRelationEntity userRelationItem in userRelationEntitys)
                    {
                        Base_UserRelation model = EntityConvertTools.CopyToModel <UserRelationEntity, Base_UserRelation>(userRelationItem, null);
                        model.Insert();
                    }
                    #endregion

                    Base_UserAuthorize.Delete("where UserId=@0", userEntity.UserId);
                    //插入用户对应数据权限
                    if (!string.IsNullOrEmpty(userEntity.AuthorizeDataId))
                    {
                        string[] uthorizeDatas = userEntity.AuthorizeDataId.Split(',');
                        for (int i = 0; i < uthorizeDatas.Length; i++)
                        {
                            string objectid      = uthorizeDatas[i];
                            var    userAuthorize = new UserAuthorizeEntity();
                            userAuthorize.UserAuthorizeId = Util.Util.NewUpperGuid();
                            userAuthorize.UserId          = userEntity.UserId;
                            userAuthorize.ObjectId        = objectid.Split('|')[0];
                            userAuthorize.ObjectName      = objectid.Split('|')[1];
                            Base_UserAuthorize model = EntityConvertTools.CopyToModel <UserAuthorizeEntity, Base_UserAuthorize>(userAuthorize, null);
                            model.Insert();
                        }
                    }

                    tran.Complete();
                }
                return(keyValue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }