コード例 #1
0
        protected void ButtonOK_Click(object sender, EventArgs e)
        {
            string guid = this.DropDownListUsers.SelectedValue;
            if (!string.IsNullOrEmpty(guid))
            {
                bool done = false;
                StringBuilder stringBuilder = new StringBuilder();

                UserBusiness business = new UserBusiness();
                User module = business.QueryByGuid(guid);

                this.InitializeUpdateModule(module);

                module.Name = this.TextBoxName.Text;
                module.Account = this.TextBoxAccount.Text;
                module.Password = this.TextBoxPassword.Text;
                module.Prerogative = false;

                User user = business.QueryByAccount(module.Account);

                if ((user == null) || (string.Equals(user.Guid, module.Guid, StringComparison.CurrentCulture)))
                {
                    done = business.Update(module);

                    if (done)
                    {
                        stringBuilder.Append("修改用户成功!");
                    }
                    else
                    {
                        stringBuilder.Append("修改用户失败!");
                    }
                }
                else
                {
                    stringBuilder.Append("用户已经存在(账户相同)!");
                }

                if (done)
                {
                    user = business.QueryByAccount(module.Account);
                    if ((user != null) && (user.Guid != null))
                    {
                        if (this.CheckBoxListRooms.Items != null)
                        {
                            List<UserRoom> userRooms = new List<UserRoom>();
                            for (int i = 0; i < this.CheckBoxListRooms.Items.Count; i++)
                            {
                                if (this.CheckBoxListRooms.Items[i].Selected)
                                {
                                    UserRoom userRoom = new UserRoom();
                                    this.InitializeInsertModule(userRoom);

                                    userRoom.UserId = user.Guid;
                                    userRoom.RoomId = this.CheckBoxListRooms.Items[i].Value;

                                    userRooms.Add(userRoom);
                                }
                            }
                            UserRoomBusiness userRoomBusiness = new UserRoomBusiness();
                            done = userRoomBusiness.Refresh(user.Guid, userRooms);

                            if (done)
                            {
                                stringBuilder.Append("更新机房成功!");
                            }
                            else
                            {
                                stringBuilder.Append("更新机房失败!");
                            }
                        }
                    }
                    if ((user != null) && (user.Guid != null))
                    {
                        if (this.CheckBoxListModules.Items != null)
                        {
                            List<UserModule> userModules = new List<UserModule>();
                            for (int i = 0; i < this.CheckBoxListModules.Items.Count; i++)
                            {
                                if (this.CheckBoxListModules.Items[i].Selected)
                                {
                                    UserModule userModule = new UserModule();
                                    this.InitializeInsertModule(userModule);

                                    userModule.UserId = user.Guid;
                                    userModule.ModuleCode = this.CheckBoxListModules.Items[i].Value;

                                    userModules.Add(userModule);
                                }
                            }
                            UserModuleBusiness userModuleBusiness = new UserModuleBusiness();
                            done = userModuleBusiness.Refresh(user.Guid, userModules);

                            if (done)
                            {
                                stringBuilder.Append("更新权限成功!");
                            }
                            else
                            {
                                stringBuilder.Append("更新权限失败!");
                            }
                        }
                    }
                }

                this.LabelMessage.Text = stringBuilder.ToString();

                this.InitializeBind();
            }
        }
コード例 #2
0
        public List<UserModule> RefreshUserModules(User value)
        {
            List<UserModule> results = null;

            if (value.Prerogative)
            {
                results = new List<UserModule>();
                for (int i = 0; i < UserModule.Modules.Length; i++)
                {
                    UserModule userModule = new UserModule();
                    userModule.ModuleCode = UserModule.Modules[i];
                    results.Add(userModule);
                }
            }
            else
            {
                UserModuleBusiness business = new UserModuleBusiness();
                int total = 0;
                results = business.QueryByUser(1, int.MaxValue, ref total, value.Guid);
            }

            return results;
        }