예제 #1
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>主键</returns>
        public string Add(PiRoleEntity entity, out string statusCode)
        {
            string result = string.Empty;
            // 检查名称是否重复
            var parameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(PiRoleTable.FieldRealName, entity.RealName),
                new KeyValuePair <string, object>(PiRoleTable.FieldDeleteMark, 0)
            };

            if (!string.IsNullOrEmpty(entity.OrganizeId)) //针对岗位的检查
            {
                parameters.Add(new KeyValuePair <string, object>(PiRoleTable.FieldOrganizeId, entity.OrganizeId));
            }
            if (this.Exists(parameters))
            {
                // 名称是否重复
                statusCode = StatusCode.ErrorNameExist.ToString();
            }
            else
            {
                result = this.Add(entity);
                // 运行成功
                statusCode = StatusCode.OKAdd.ToString();
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 取得实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public PiRoleEntity GetEntity(UserInfo userInfo, string id)
        {
            PiRoleEntity entity    = null;
            var          parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.RoleService_GetEntity);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                entity = new PiRoleManager(dbProvider, userInfo).GetEntity(id);
            });
            return(entity);
        }
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">sql语句生成器</param>
 /// <param name="piRoleEntity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, PiRoleEntity piRoleEntity)
 {
     sqlBuilder.SetValue(PiRoleTable.FieldSystemId, piRoleEntity.SystemId);
     sqlBuilder.SetValue(PiRoleTable.FieldOrganizeId, piRoleEntity.OrganizeId);
     sqlBuilder.SetValue(PiRoleTable.FieldCategory, piRoleEntity.Category);
     sqlBuilder.SetValue(PiRoleTable.FieldCode, piRoleEntity.Code);
     sqlBuilder.SetValue(PiRoleTable.FieldEnabled, piRoleEntity.Enabled);
     sqlBuilder.SetValue(PiRoleTable.FieldRealName, piRoleEntity.RealName);
     sqlBuilder.SetValue(PiRoleTable.FieldAllowEdit, piRoleEntity.AllowEdit);
     sqlBuilder.SetValue(PiRoleTable.FieldAllowDelete, piRoleEntity.AllowDelete);
     sqlBuilder.SetValue(PiRoleTable.FieldSortCode, piRoleEntity.SortCode);
     sqlBuilder.SetValue(PiRoleTable.FieldDescription, piRoleEntity.Description);
 }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="roleEntity">实体</param>
        public int UpdateEntity(PiRoleEntity roleEntity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DBProvider);

            sqlBuilder.BeginUpdate(PiRoleTable.TableName);
            this.SetEntity(sqlBuilder, roleEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(PiRoleTable.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(PiRoleTable.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(PiRoleTable.FieldModifiedOn);
            sqlBuilder.SetWhere(PiRoleTable.FieldId, roleEntity.Id);
            return(sqlBuilder.EndUpdate());
        }
예제 #5
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="entity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>影响的行数</returns>
        public int Update(UserInfo userInfo, PiRoleEntity entity, out string statusCode, out string statusMessage)
        {
            int    returnValue   = 0;
            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            var    parameter     = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.RoleService_Update);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                var manager   = new PiRoleManager(dbProvider, userInfo);
                returnValue   = manager.UpdateEntity(entity, out returnCode);
                returnMessage = manager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(returnValue);
        }
예제 #6
0
        public bool IsAdministrator(PiUserEntity entity)
        {
            // 用户是超级管理员
            if (entity.Id.Equals("Administrator"))
            {
                return(true);
            }
            if (entity.Code != null && entity.Code.Equals("Administrator"))
            {
                return(true);
            }
            if (entity.UserName != null && entity.UserName.Equals("Administrator"))
            {
                return(true);
            }

            if (this.UserInfo == null)
            {
                return(false);
            }

            // 用户的默认角色是超级管理员
            var roleManager = new PiRoleManager(this.DBProvider, this.UserInfo);
            // 用户默认角色是否为超级管理员
            PiRoleEntity roleEntity = null;

            if (entity.RoleId != null)
            {
                // 用户在超级管理员群里
                string[] roleIds = this.GetRoleIds(entity.Id);
                foreach (string tmpid in roleIds)
                {
                    if (tmpid.Equals(DefaultRole.Administrators.ToString()))
                    {
                        return(true);
                    }
                    roleEntity = roleManager.GetEntity(tmpid);
                    if (roleEntity.Code != null && roleEntity.Code.Equals(DefaultRole.Administrators.ToString()))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #7
0
        public UserInfo ConvertToUserInfo(UserInfo userInfo, PiUserEntity userEntity, PiUserLogOnEntity userLogOnEntity = null)
        {
            userInfo.Id             = userEntity.Id;
            userInfo.Code           = userEntity.Code;
            userInfo.UserName       = userEntity.UserName;
            userInfo.RealName       = userEntity.RealName;
            userInfo.CompanyId      = userEntity.CompanyId;
            userInfo.CompanyName    = userEntity.CompanyName;
            userInfo.DepartmentId   = userEntity.DepartmentId;
            userInfo.DepartmentName = userEntity.DepartmentName;
            userInfo.WorkgroupId    = userEntity.WorkgroupId;
            userInfo.WorkgroupName  = userEntity.WorkgroupName;

            if (userLogOnEntity != null)
            {
                userInfo.OpenId = userLogOnEntity.OpenId;
            }

            if (userEntity.SecurityLevel == null)
            {
                userEntity.SecurityLevel = 0;
            }
            else
            {
                userInfo.SecurityLevel = (int)userEntity.SecurityLevel;
            }

            if (!string.IsNullOrEmpty(userEntity.RoleId))
            {
                // 获取角色名称
                var          roleManager = new PiRoleManager(DBProvider, UserInfo);
                PiRoleEntity roleEntity  = roleManager.GetEntity(userEntity.RoleId);
                if (!string.IsNullOrEmpty(roleEntity.Id))
                {
                    userInfo.RoleName = roleEntity.RealName;
                    userInfo.RoleId   = roleEntity.Id;
                }
            }
            return(userInfo);
        }
예제 #8
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="statusCode">状态码</param>
        public int UpdateEntity(PiRoleEntity entity, out string statusCode)
        {
            int returnValue = 0;
            // 检查名称是否重复
            var parameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(PiRoleTable.FieldOrganizeId, entity.OrganizeId),
                new KeyValuePair <string, object>(PiRoleTable.FieldRealName, entity.RealName),
                new KeyValuePair <string, object>(PiRoleTable.FieldDeleteMark, 0)
            };

            if (this.Exists(parameters, entity.Id))
            {
                // 名称已重复
                statusCode = StatusCode.ErrorNameExist.ToString();
            }
            else
            {
                returnValue = this.Update(entity);
                statusCode  = returnValue == 1 ? StatusCode.OKUpdate.ToString() : StatusCode.ErrorDeleted.ToString();
            }
            return(returnValue);
        }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="piRoleEntity">实体</param>
 /// <returns>主键</returns>
 public string Add(PiRoleEntity piRoleEntity)
 {
     return(this.AddEntity(piRoleEntity));
 }
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="piRoleEntity">实体</param>
        public string AddEntity(PiRoleEntity piRoleEntity)
        {
            string sequence = string.Empty;

            if (piRoleEntity.SortCode == null || piRoleEntity.SortCode == 0)
            {
                CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity);
                sequence = sequenceManager.GetSequence(this.CurrentTableName, sequenceManager.DefaultSequence);
                piRoleEntity.SortCode = int.Parse(sequence);
            }
            this.Identity = false;
            SQLBuilder sqlBuilder = new SQLBuilder(DBProvider, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, PiRoleTable.FieldId);
            if (!this.Identity)
            {
                if (String.IsNullOrEmpty(piRoleEntity.Id))
                {
                    sequence        = BusinessLogic.NewGuid();
                    piRoleEntity.Id = sequence;
                }
                sqlBuilder.SetValue(PiRoleTable.FieldId, piRoleEntity.Id);
            }
            else
            {
                if (!this.ReturnId && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DBProvider.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(PiRoleTable.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DBProvider.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(PiRoleTable.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (piRoleEntity.Id == null)
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                CiSequenceManager sequenceManager = new CiSequenceManager(DBProvider, this.Identity);
                                sequence = sequenceManager.GetSequence(this.CurrentTableName);
                            }
                            piRoleEntity.Id = sequence;
                        }
                        sqlBuilder.SetValue(PiRoleTable.FieldId, piRoleEntity.Id);
                    }
                }
            }
            this.SetEntity(sqlBuilder, piRoleEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(PiRoleTable.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(PiRoleTable.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(PiRoleTable.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(PiRoleTable.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(PiRoleTable.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(PiRoleTable.FieldModifiedOn);
            if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.SqlServer || DBProvider.CurrentDbType == CurrentDbType.Access))
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            // 运行成功
            return(sequence);
        }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="piRoleEntity">实体</param>
 public int Update(PiRoleEntity piRoleEntity)
 {
     return(this.UpdateEntity(piRoleEntity));
 }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="piRoleEntity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// <param name="returnId">返回主键</param>
 /// <returns>主键</returns>
 public string Add(PiRoleEntity piRoleEntity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return(this.AddEntity(piRoleEntity));
 }