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>
        /// <returns></returns>
        public IEnumerable <DataItemModel> GetDataItemList()
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(@"SELECT  i.ItemId ,
                                    i.ItemCode AS EnCode ,
                                    d.ItemDetailId ,
                                    d.ParentId ,
                                    d.ItemCode ,
                                    d.ItemName ,
                                    d.ItemValue ,
                                    d.QuickQuery ,
                                    d.SimpleSpelling ,
                                    d.IsDefault ,
                                    d.SortCode ,
                                    d.EnabledMark,
                                    d.Description
                            FROM    Base_DataItemDetail d
                                    LEFT JOIN Base_DataItem i ON i.ItemId = d.ItemId
                            WHERE   1 = 1
                                    AND d.EnabledMark = 1
                                    AND d.DeleteMark = 0
                            ORDER BY d.SortCode ASC");
            return(QSDMS_SQLDB.GetInstance().Fetch <DataItemModel>(strSql.ToString()));
        }
Example #3
0
        /// <summary>
        /// 删除机构
        /// </summary>
        /// <param name="keyValue">主键</param>
        public void RemoveForm(string keyValue)
        {
            int count = QSDMS_SQLDB.GetInstance().Fetch <Base_Organize>("select * from Base_Organize").FindAll(t => t.ParentId == keyValue).Count();

            if (count > 0)
            {
                throw new Exception("当前所选数据有子节点数据!");
            }
            Base_Organize.Delete("where OrganizeId=@0", keyValue);
        }
Example #4
0
        public int Insert()
        {
            T_Test test = new T_Test();

            test.Name   = "aaaa";
            test.Remark = "备注";
            int count = QSDMS_SQLDB.GetInstance().Execute("insert into t_test(name,remark) values(@0,@1)", "aaaa", "备注111");

            return(count);
        }
Example #5
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="moduleEntity">功能实体</param>
 /// <param name="moduleButtonList">按钮实体列表</param>
 /// <param name="moduleColumnList">视图实体列表</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, ModuleEntity moduleEntity, List <ModuleButtonEntity> moduleButtonList, List <ModuleColumnEntity> moduleColumnList)
 {
     try
     {
         using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction())
         {
             if (!string.IsNullOrEmpty(keyValue))
             {
                 moduleEntity.Modify(keyValue);
                 Base_Module moudle = Base_Module.SingleOrDefault("where ModuleId=@0", keyValue);
                 //if (moduleEntity.UrlAddress == null)
                 //{
                 //    moduleEntity.UrlAddress = "";
                 //}
                 moudle          = EntityConvertTools.CopyToModel <ModuleEntity, Base_Module>(moduleEntity, moudle);
                 moudle.ModuleId = keyValue;
                 moudle.Update();
             }
             else
             {
                 moduleEntity.Create();
                 Base_Module moudle = new Base_Module();
                 moudle = EntityConvertTools.CopyToModel <ModuleEntity, Base_Module>(moduleEntity, null);
                 moudle.Insert();
             }
             //删除操作按钮
             Base_ModuleButton.Delete("where ModuleId=@0", keyValue);
             if (moduleButtonList != null)
             {
                 foreach (ModuleButtonEntity buttonItem in moduleButtonList)
                 {
                     Base_ModuleButton modulebutton = new Base_ModuleButton();
                     modulebutton = EntityConvertTools.CopyToModel <ModuleButtonEntity, Base_ModuleButton>(buttonItem, null);
                     modulebutton.Insert();
                 }
             }
             //删除字段
             Base_ModuleColumn.Delete("where ModuleId=@0", keyValue);
             if (moduleColumnList != null)
             {
                 foreach (ModuleColumnEntity columnItem in moduleColumnList)
                 {
                     Base_ModuleColumn modulecolumn = new Base_ModuleColumn();
                     modulecolumn = EntityConvertTools.CopyToModel <ModuleColumnEntity, Base_ModuleColumn>(columnItem, null);
                     modulecolumn.Insert();
                 }
             }
             tran.Complete();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #6
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 #7
0
        /// <summary>
        /// 获取授权功能视图
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public IEnumerable <ModuleColumnEntity> GetModuleColumnList(string userId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.AppendFormat(@"SELECT  *
                            FROM    Base_ModuleColumn
                            WHERE   ModuleColumnId IN (
                                    SELECT  ItemId
                                    FROM    Base_Authorize
                                    WHERE   ItemType = 3
                                            AND ( ObjectId IN (
                                                  SELECT    ObjectId
                                                  FROM      Base_UserRelation
                                                  WHERE     UserId = '{0}' ) )
                                            OR ObjectId = '{0}')", userId);

            return(QSDMS_SQLDB.GetInstance().Fetch <ModuleColumnEntity>("select * from (" + strSql.ToString() + ")a  Order By SortCode"));
        }
Example #8
0
        /// <summary>
        /// 角色列表all
        /// </summary>
        /// <returns></returns>
        public IEnumerable <RoleEntity> GetAllList()
        {
            var strSql = new StringBuilder();

            strSql.AppendFormat(@"SELECT  r.RoleId ,
				                    o.FullName AS OrganizeId ,
				                    r.Category ,
				                    r.EnCode ,
				                    r.FullName ,
				                    r.SortCode ,
				                    r.EnabledMark ,
				                    r.Description ,
				                    r.CreateDate
                    FROM    Base_Role r
				                    LEFT JOIN Base_Organize o ON o.OrganizeId = r.OrganizeId
                    WHERE   o.FullName is not null and r.Category = '{0}' and r.EnabledMark =1
                    ORDER BY o.FullName, r.SortCode", (int)QSDMS.Model.Enums.RoleCategoryEnum.角色);
            return(QSDMS_SQLDB.GetInstance().Query <RoleEntity>("select * from (" + strSql.ToString() + ")a"));
        }
Example #9
0
        /// <summary>
        /// 获取授权功能Url、操作Url
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public IEnumerable <AuthorizeUrlModel> GetUrlList(string userId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.AppendFormat(@"SELECT  ModuleId AS AuthorizeId ,
                                    ModuleId ,
                                    UrlAddress ,
                                    FullName
                            FROM    Base_Module
                            WHERE   ModuleId IN (
                                    SELECT  ItemId
                                    FROM    Base_Authorize
                                    WHERE   ItemType = 1
                                            AND ( ObjectId IN (
                                                  SELECT    ObjectId
                                                  FROM      Base_UserRelation
                                                  WHERE     UserId = '{0}' ) )
                                            OR ObjectId = '{0}' )
                                    AND EnabledMark = 1
                                    AND DeleteMark = 0
                                    AND IsMenu = 1
                                    AND UrlAddress IS NOT NULL
                            UNION
                            SELECT  ModuleButtonId AS AuthorizeId ,
                                    ModuleId ,
                                    ActionAddress AS UrlAddress ,
                                    FullName
                            FROM    Base_ModuleButton
                            WHERE   ModuleButtonId IN (
                                    SELECT  ItemId
                                    FROM    Base_Authorize
                                    WHERE   ItemType = 2
                                            AND ( ObjectId IN (
                                                  SELECT    ObjectId
                                                  FROM      Base_UserRelation
                                                  WHERE     UserId = '{0}' ) )
                                            OR ObjectId = '{0}' )
                                    AND ActionAddress IS NOT NULL", userId);

            return(QSDMS_SQLDB.GetInstance().Fetch <AuthorizeUrlModel>("select * from (" + strSql.ToString() + ")a"));
        }
Example #10
0
        /// <summary>
        /// 获得权限范围用户ID
        /// </summary>
        /// <param name="operators">当前登陆用户信息</param>
        /// <param name="isWrite">可写入</param>
        /// <returns></returns>
        public string GetDataAuthorUserId(Operator operators, bool isWrite = false)
        {
            string userIdList = GetDataAuthor(operators, isWrite);

            if (userIdList == "")
            {
                return("");
            }
            var               db       = QSDMS_SQLDB.GetInstance();
            string            userId   = operators.UserId;
            List <UserEntity> userList = db.Fetch <UserEntity>(userIdList).ToList();
            StringBuilder     userSb   = new StringBuilder("");

            if (userList != null)
            {
                foreach (var item in userList)
                {
                    userSb.Append(item.UserId);
                    userSb.Append(",");
                }
            }
            return(userSb.ToString());
        }
Example #11
0
 /// <summary>
 /// 删除功能
 /// </summary>
 /// <param name="keyValue">主键</param>
 public void RemoveForm(string keyValue)
 {
     try
     {
         QSDMS_SQLDB db = QSDMS_SQLDB.GetInstance();
         using (var tran = db.GetTransaction())
         {
             int count = db.Fetch <Base_Module>("select * from Base_Module").FindAll(t => t.ParentId == keyValue).Count();
             if (count > 0)
             {
                 throw new Exception("当前所选数据有子节点数据!");
             }
             Base_Module.Delete("where ModuleId=@0", keyValue);
             Base_ModuleButton.Delete("where ModuleId=@0", keyValue);
             Base_ModuleColumn.Delete("where ModuleId=@0", keyValue);
             //提交事务
             tran.Complete();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #12
0
        /// <summary>
        /// 获得可读数据权限范围SQL
        /// </summary>
        /// <param name="operators">当前登陆用户信息</param>
        /// <param name="isWrite">可写入</param>
        /// <returns></returns>
        public string GetDataAuthor(Operator operators, bool isWrite = false)
        {
            //如果是系统管理员直接给所有数据权限
            if (operators.IsSystem)
            {
                return("");
            }
            var           db            = QSDMS_SQLDB.GetInstance();
            string        userId        = operators.UserId;
            StringBuilder whereSb       = new StringBuilder(" select UserId from Base_user where 1=1 ");
            string        strAuthorData = "";

            if (isWrite)
            {
                strAuthorData = @"   SELECT    *
                                        FROM      Base_AuthorizeData
                                        WHERE     IsRead=0 AND
                                        ObjectId IN (
                                                SELECT  ObjectId
                                                FROM    Base_UserRelation
                                                WHERE   UserId =@UserId)";
            }
            else
            {
                strAuthorData = @"   SELECT    *
                                        FROM      Base_AuthorizeData
                                        WHERE     
                                        ObjectId IN (
                                                SELECT  ObjectId
                                                FROM    Base_UserRelation
                                                WHERE   UserId =@UserId)";
            }

            whereSb.Append(string.Format("AND( UserId ='{0}'", userId));
            IEnumerable <AuthorizeDataEntity> listAuthorizeData = db.Fetch <AuthorizeDataEntity>(strAuthorData, new { UserId = userId });

            foreach (AuthorizeDataEntity item in listAuthorizeData)
            {
                switch (item.AuthorizeType)
                {
                //0代表最大权限
                case 0:    //
                    return("");

                //本人及下属
                case -2:    //
                    whereSb.Append("  OR ManagerId ='{0}'");
                    break;

                case -3:
                    whereSb.Append(@"  OR DepartmentId = (  SELECT  DepartmentId
                                                                    FROM    Base_User
                                                                    WHERE   UserId ='{0}'
                                                                  )");
                    break;

                case -4:
                    whereSb.Append(@"  OR OrganizeId = (    SELECT  OrganizeId
                                                                    FROM    Base_User
                                                                    WHERE   UserId ='{0}'
                                                                  )");
                    break;

                case -5:
                    whereSb.Append(string.Format(@"  OR DepartmentId='{1}' OR OrganizeId='{1}'", userId, item.ResourceId));
                    break;
                }
            }
            whereSb.Append(")");
            return(whereSb.ToString());
        }
Example #13
0
 /// <summary>
 /// 获取关联用户关系
 /// </summary>
 /// <param name="userId">用户Id</param>
 /// <returns></returns>
 public IEnumerable <UserRelationEntity> GetUserRelationList(string userId)
 {
     return(QSDMS_SQLDB.GetInstance().Fetch <UserRelationEntity>("select * from Base_UserRelation where UserId=@0", userId));
 }
Example #14
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;
            }
        }
Example #15
0
        /// <summary>
        /// 添加授权
        /// </summary>
        /// <param name="authorizeType">权限分类</param>
        /// <param name="objectId">对象Id</param>
        /// <param name="moduleIds">功能Id</param>
        /// <param name="moduleButtonIds">按钮Id</param>
        /// <param name="moduleColumnIds">视图Id</param>
        /// <param name="authorizeDataList">数据权限</param>
        public void SaveAuthorize(AuthorizeTypeEnum authorizeType, string objectId, string[] moduleIds, string[] moduleButtonIds, string[] moduleColumnIds, IEnumerable <AuthorizeDataEntity> authorizeDataList)
        {
            try
            {
                using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction())
                {
                    //删除授权
                    Base_Authorize.Delete("where ObjectId=@0", objectId);

                    #region 功能
                    int SortCode = 1;
                    foreach (string item in moduleIds)
                    {
                        AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                        authorizeEntity.Create();
                        authorizeEntity.Category = (int)authorizeType;
                        authorizeEntity.ObjectId = objectId;
                        authorizeEntity.ItemType = (int)Enums.FormElementTypeEnum.菜单;
                        authorizeEntity.ItemId   = item;
                        authorizeEntity.SortCode = SortCode++;
                        Base_Authorize authorize = EntityConvertTools.CopyToModel <AuthorizeEntity, Base_Authorize>(authorizeEntity, null);
                        authorize.Insert();
                    }
                    #endregion

                    #region  钮
                    SortCode = 1;
                    foreach (string item in moduleButtonIds)
                    {
                        AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                        authorizeEntity.Create();
                        authorizeEntity.Category = (int)authorizeType;
                        authorizeEntity.ObjectId = objectId;
                        authorizeEntity.ItemType = (int)Enums.FormElementTypeEnum.钮;
                        authorizeEntity.ItemId   = item;
                        authorizeEntity.SortCode = SortCode++;
                        Base_Authorize authorize = EntityConvertTools.CopyToModel <AuthorizeEntity, Base_Authorize>(authorizeEntity, null);
                        authorize.Insert();
                    }
                    #endregion

                    #region 视图
                    SortCode = 1;
                    foreach (string item in moduleColumnIds)
                    {
                        AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                        authorizeEntity.Create();
                        authorizeEntity.Category = (int)authorizeType;
                        authorizeEntity.ObjectId = objectId;
                        authorizeEntity.ItemType = (int)Enums.FormElementTypeEnum.视图;
                        authorizeEntity.ItemId   = item;
                        authorizeEntity.SortCode = SortCode++;
                        Base_Authorize authorize = EntityConvertTools.CopyToModel <AuthorizeEntity, Base_Authorize>(authorizeEntity, null);
                        authorize.Insert();
                    }
                    #endregion

                    #region 数据权限
                    SortCode = 1;
                    Base_AuthorizeDatum.Delete("where objectId=@0", objectId);
                    int index = 0;
                    foreach (AuthorizeDataEntity authorizeDataEntity in authorizeDataList)
                    {
                        authorizeDataEntity.Create();
                        authorizeDataEntity.Category = (int)authorizeType;
                        authorizeDataEntity.ObjectId = objectId;
                        authorizeDataEntity.SortCode = SortCode++;
                        Base_AuthorizeDatum authorizedata = EntityConvertTools.CopyToModel <AuthorizeDataEntity, Base_AuthorizeDatum>(authorizeDataEntity, null);
                        authorizedata.Insert();
                        index++;
                    }
                    #endregion
                    tran.Complete();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }