private IRoleInfo CreateNewRole(string standardGeneralRoleId, string organizationId)
        {
            IStandardGeneralRoleInfo standardGeneralRole = this.FindOne(standardGeneralRoleId);

            IOrganizationUnitInfo organization = MembershipManagement.Instance.OrganizationUnitService.FindOne(organizationId);

            RoleInfo role = new RoleInfo();

            role.Id   = DigitalNumberContext.Generate("Key_Guid");
            role.Name = organization.GlobalName + "_" + standardGeneralRole.Name;
            role.OrganizationUnitId = organizationId;
            role.StandardRoleId     = string.Empty;
            role.Type    = 65536; // 内部虚拟角色
            role.Locking = 0;     // 非锁定
            role.Status  = 1;

            string name = role.Name;

            int count = 1;

            while (MembershipManagement.Instance.RoleService.IsExistName(role.Name))
            {
                role.Name = name + count++;

                // 避免陷入死循环, 当循环超过10次时返回空值.
                if (count > 10)
                {
                    return(null);
                }
            }

            return(MembershipManagement.Instance.RoleService.Save(role));
        }
        /// <summary>创建新的对象</summary>
        /// <param name="doc">Xml 文档对象</param>
        /// <returns>返回操作结果</returns>
        public string CreateMappingRelation(XmlDocument doc)
        {
            StringBuilder outString = new StringBuilder();

            string standardGeneralRoleId = XmlHelper.Fetch("standardGeneralRoleId", doc);

            string organizationId = XmlHelper.Fetch("organizationId", doc);

            StandardGeneralRoleMappingRelationInfo param = new StandardGeneralRoleMappingRelationInfo();

            param.StandardGeneralRoleId = standardGeneralRoleId;

            if (!string.IsNullOrEmpty(param.StandardGeneralRoleId))
            {
                IStandardGeneralRoleInfo standardGeneralRole = MembershipManagement.Instance.StandardGeneralRoleService.FindOne(param.StandardGeneralRoleId);

                param.StandardGeneralRoleName = (standardGeneralRole == null) ? string.Empty : standardGeneralRole.Name;
            }

            param.OrganizationUnitId = organizationId;

            if (!string.IsNullOrEmpty(param.OrganizationUnitId))
            {
                IOrganizationUnitInfo organization = MembershipManagement.Instance.OrganizationUnitService.FindOne(param.OrganizationUnitId);

                param.OrganizationUnitName = (organization == null) ? string.Empty : organization.Name;
            }

            outString.Append("{\"data\":" + AjaxUtil.Parse <StandardGeneralRoleMappingRelationInfo>(param) + ",");

            outString.Append(MessageObject.Stringify("0", I18n.Strings["msg_query_success"], true) + "}");

            return(outString.ToString());
        }
        // -------------------------------------------------------
        // 查询
        // -------------------------------------------------------

        #region 函数:FindOne(string id)
        /// <summary>查询某条记录</summary>
        /// <param name="id">标识</param>
        /// <returns>返回实例<see cref="IStandardGeneralRoleInfo"/>的详细信息</returns>
        public IStandardGeneralRoleInfo FindOne(string id)
        {
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("Id", StringHelper.ToSafeSQL(id));

            IStandardGeneralRoleInfo param = ibatisMapper.QueryForObject <IStandardGeneralRoleInfo>(StringHelper.ToProcedurePrefix(string.Format("{0}_FindOne", tableName)), args);

            return(param);
        }
        // -------------------------------------------------------
        // 添加 删除 修改
        // -------------------------------------------------------

        #region 函数:Save(IStandardGeneralRoleInfo param)
        /// <summary>保存记录</summary>
        /// <param name="param">实例<see cref="IStandardGeneralRoleInfo"/>详细信息</param>
        /// <returns>实例<see cref="IStandardGeneralRoleInfo"/>详细信息</returns>
        public IStandardGeneralRoleInfo Save(IStandardGeneralRoleInfo param)
        {
            if (!IsExist(param.Id))
            {
                Insert(param);
            }
            else
            {
                Update(param);
            }

            return((IStandardGeneralRoleInfo)param);
        }
        public string FindOne(XmlDocument doc)
        {
            StringBuilder outString = new StringBuilder();

            string id = XmlHelper.Fetch("id", doc);

            IStandardGeneralRoleInfo param = this.service.FindOne(id);

            outString.Append("{\"data\":" + AjaxUtil.Parse <IStandardGeneralRoleInfo>(param) + ",");

            outString.Append(MessageObject.Stringify("0", I18n.Strings["msg_query_success"], true) + "}");

            return(outString.ToString());
        }
        /// <summary>添加记录</summary>
        /// <param name="param">实例<see cref="IStandardGeneralRoleInfo"/>详细信息</param>
        public void Insert(IStandardGeneralRoleInfo param)
        {
            if (string.IsNullOrEmpty(param.Id))
            {
                param.Id = DigitalNumberContext.Generate("Key_Guid");
            }

            if (string.IsNullOrEmpty(param.Code))
            {
                param.Code = DigitalNumberContext.Generate("Table_StandardGeneralRole_Key_Code");
            }

            ibatisMapper.Insert(StringHelper.ToProcedurePrefix(string.Format("{0}_Insert", tableName)), param);
        }
 /// <summary>修改记录</summary>
 /// <param name="param">实例<see cref="IStandardGeneralRoleInfo"/>详细信息</param>
 public void Update(IStandardGeneralRoleInfo param)
 {
     ibatisMapper.Update(StringHelper.ToProcedurePrefix(string.Format("{0}_Update", tableName)), param);
 }
        // -------------------------------------------------------
        // 保存 删除
        // -------------------------------------------------------

        #region 函数:Save(IStandardGeneralRoleInfo param)
        /// <summary>保存记录</summary>
        /// <param name="param">实例<see cref="IStandardGeneralRoleInfo"/>详细信息</param>
        /// <returns>实例<see cref="IStandardGeneralRoleInfo"/>详细信息</returns>
        public IStandardGeneralRoleInfo Save(IStandardGeneralRoleInfo param)
        {
            return(provider.Save(param));
        }