/// <summary>
        /// 创建子用户组
        /// </summary>
        /// <param name="parentGroup"></param>
        /// <param name="childGroup"></param>
        /// <returns></returns>
        public bool CreateChildGroup(IUserGroup parentGroup, IUserGroup childGroup)
        {
            UserGroup child  = childGroup as UserGroup;
            UserGroup parent = parentGroup as UserGroup;

            if (child != null && parent != null)
            {
                child.ParentId   = parent.GroupId;
                child.GroupLevel = (short)(parent.GroupLevel + (short)1);
                child.CreateBy   = SecuritySession.CurrentUser.UserId;
                child.CreateTime = DateTime.Now;
                child.ModifyBy   = child.CreateBy;
                child.ModifyTime = child.CreateTime;
                child.GroupType  = parent.GroupType;

                return(child.Create(this._session));
            }

            return(false);
        }
Exemplo n.º 2
0
    //Save Data
    private void SaveData()
    {
        UserGroup userGroup = new  UserGroup();
        bool flag = true;
        try
        {
            userGroup.ParentId = UserGroup.Root.GroupId;
            userGroup.Name = txtName.Text.Trim();
            userGroup.Description = txtDescription.Text.Trim();
            userGroup.GroupType = (UserGroupType)Enum.Parse(typeof(UserGroupType),rblGroupType.SelectedValue);
            userGroup.GroupLevel = (short)(UserGroup.Root.GroupLevel + 1);
            userGroup.ModifyBy = SecuritySession.CurrentUser.UserId;
            userGroup.ModifyTime = DateTime.Now;
            using (_session = new Session())
            {
                if (IsAddNew())
                {
                    userGroup.CreateTime = userGroup.ModifyTime;
                    userGroup.CreateBy = SecuritySession.CurrentUser.UserId;
                    flag = userGroup.Create(_session);
                }
                else
                {
                   userGroup.GroupId = int.Parse(this.txtGroupId.Value);
                   flag = userGroup.Update(_session,  "ParentId",  "Name",  "Description",  "GroupType",  "GroupLevel","ModifyBy","ModifyTime");
                }
            }
            this.txtGroupId.Value = userGroup.GroupId.ToString();

            if (flag)
                WebUtil.ShowMsg(this, "操作成功", "提示");
            else
                WebUtil.ShowMsg(this, "操作失败", "提示");
        }
        catch(UnauthorizedException ex)
        {
            WebUtil.ShowMsg(this,ex.Message,"警告");
        }
        catch(ApplicationException ex)
        {
            WebUtil.ShowMsg(this,ex.Message,"提示");
        }
        catch(Exception ex)
        {
            logger.Info("保存UserGroup", ex);
            WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员");
        }
    }