/// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="role">角色</param>
        /// <returns>主键</returns>
        public string AddRole(BaseUserInfo userInfo, string role)
        {
            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            string returnValue = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo);
                    string          statusCode  = string.Empty;
                    BaseRoleEntity  roleEntity  = new BaseRoleEntity();
                    roleEntity.RealName = role;
                    roleEntity.Enabled  = 1;
                    returnValue         = roleManager.Add(roleEntity, out statusCode);
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            return(returnValue);
        }
        private void btnRole_Click(object sender, EventArgs e)
        {
            string txtButton = ((Button)sender).Text;
            Button btnRole   = (Button)sender;
            string roldId    = GetRoleId(btnRole);

            if (string.IsNullOrEmpty(roldId))
            {
                BaseRoleEntity roleEntity = new BaseRoleEntity();
                roleEntity.OrganizeId        = this.EntityId;
                roleEntity.Code              = ((Button)sender).Name.Substring(3).Replace("Delete", "");
                roleEntity.RealName          = this.txtFullName.Text + "_" + txtButton;
                roleEntity.Description       = ((Button)sender).Text;
                roleEntity.CategoryCode      = "Duty";
                roleEntity.Enabled           = 1;
                roleEntity.DeletionStateCode = 0;
                BaseRoleManager roleManager = new BaseRoleManager(this.UserInfo);
                roldId      = roleManager.Add(roleEntity);
                btnRole.Tag = roldId;
            }
            FrmRoleUserAdmin frmRoleUserAdmin = new FrmRoleUserAdmin(roldId);

            frmRoleUserAdmin.ShowDialog(this);

            this.GetRoleUser(btnRole);
        }
Beispiel #3
0
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>主键</returns>
        public string Add(BaseUserInfo userInfo, BaseRoleEntity roleEntity, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            string returnValue = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    dbHelper.BeginTransaction();
                    string tableName = BaseRoleEntity.TableName;
                    if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                    {
                        tableName = BaseSystemInfo.SystemCode + "Role";
                    }
                    BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo, tableName);
                    returnValue   = roleManager.Add(roleEntity, out statusCode);
                    statusMessage = roleManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, serviceName, AppMessage.RoleService_Add, MethodBase.GetCurrentMethod());
                    dbHelper.CommitTransaction();
                }
                catch (Exception ex)
                {
                    dbHelper.RollbackTransaction();
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(returnValue);
        }