protected void ButtonOK_Click(object sender, EventArgs e)
        {
            bool done = false;
            StringBuilder stringBuilder = new StringBuilder();

            EnvironmentalMonitor.Support.Module.Manage.User sessionUser = this.Session[Constant.SESSION_KEY_USER] as EnvironmentalMonitor.Support.Module.Manage.User;

            UserBusiness business = new UserBusiness();
            User user = business.QueryByAccount(sessionUser.Account);

            if ((user != null) && (string.Equals(user.Password, this.TextBoxOldPassword.Text, StringComparison.CurrentCulture)))
            {
                done = business.ChangePassword(sessionUser.Guid, this.TextBoxPassword.Text);
            }
            if (done)
            {
                sessionUser.Password = this.TextBoxPassword.Text;
                this.Session[Constant.SESSION_KEY_USER] = sessionUser;
                stringBuilder.Append("修改密码成功!");
            }
            else
            {
                stringBuilder.Append("修改密码失败!");
            }

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

            this.InitializeBind();
        }
        protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            UserBusiness business = new UserBusiness();
            string account = this.TextBoxUsername.Text;
            string password = this.TextBoxPassword.Text;

            User user = business.Login(account, password);

            if ((user != null) && (user.Authentication))
            {
                this.Session[Constant.SESSION_KEY_USER] = user;
                this.Response.Redirect(string.Format("{0}Manages/Defaults/About.aspx", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath));
            }
        }
        protected void ButtonOK_Click(object sender, EventArgs e)
        {
            bool done = false;
            StringBuilder stringBuilder = new StringBuilder();

            UserBusiness business = new UserBusiness();

            if (this.CheckBoxListUsers.Items != null)
            {
                List<User> users = new List<User>();
                for (int i = 0; i < this.CheckBoxListUsers.Items.Count; i++)
                {
                    if (this.CheckBoxListUsers.Items[i].Selected)
                    {
                        User user = new User();
                        user.Guid = this.CheckBoxListUsers.Items[i].Value;
                        users.Add(user);
                    }
                }

                if ((users != null) && (users.Count > 0))
                {
                    int success = 0;
                    int fail = 0;
                    for (int i = 0; i < users.Count; i++)
                    {
                        done = business.Delete(users[i]);
                        if (done)
                        {
                            success++;
                        }
                        else
                        {
                            fail++;
                        }
                    }
                    stringBuilder.Append(string.Format("删除{0}个用户成功!", success));
                    stringBuilder.Append(string.Format("删除{0}个用户失败!", fail));
                }
            }

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

            this.InitializeBind();
        }
        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();
            }
        }
        protected void DropDownListUsers_SelectedIndexChanged(object sender, EventArgs e)
        {
            string guid = this.DropDownListUsers.SelectedValue;
            if (!string.IsNullOrEmpty(guid))
            {
                this.LabelMessage.Text = string.Empty;
                UserBusiness business = new UserBusiness();

                User currentUser = business.QueryByGuid(guid);

                if (currentUser != null)
                {
                    this.TextBoxName.Text = currentUser.Name;
                    this.TextBoxAccount.Text = currentUser.Account;
                    this.TextBoxPassword.Attributes["value"] = currentUser.Password;
                    this.TextBoxRepassword.Attributes["value"] = currentUser.Password;

                    business.Refresh(currentUser);

                    this.CheckBoxListRooms.ClearSelection();
                    if (currentUser.Rooms != null)
                    {
                        for (int i = 0; i < currentUser.Rooms.Count; i++)
                        {
                            for (int j = 0; j < this.CheckBoxListRooms.Items.Count; j++)
                            {
                                if (string.Equals(currentUser.Rooms[i].Guid, this.CheckBoxListRooms.Items[j].Value, StringComparison.CurrentCulture))
                                {
                                    this.CheckBoxListRooms.Items[j].Selected = true;
                                    break;
                                }
                            }
                        }
                    }

                    this.CheckBoxListModules.ClearSelection();
                    if (currentUser.UserModules != null)
                    {
                        for (int i = 0; i < currentUser.UserModules.Count; i++)
                        {
                            for (int j = 0; j < this.CheckBoxListModules.Items.Count; j++)
                            {
                                if (string.Equals(currentUser.UserModules[i].ModuleCode, this.CheckBoxListModules.Items[j].Value, StringComparison.CurrentCulture))
                                {
                                    this.CheckBoxListModules.Items[j].Selected = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            bool login = false;

            User user = this.Session[Constant.SESSION_KEY_USER] as User;
            if (user != null)
            {
                if ((user.Authentication) || (user.Prerogative))
                {
                    login = true;
                }
            }

            if (!login)
            {
                this.Response.Redirect(string.Format("{0}Manages/Users/Logout.aspx", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath));
            }
            else
            {
                Type pageType = this.GetType();
                UserBusiness business = new UserBusiness();
                bool allow = business.VerifyPage(user, pageType);

                if (!allow)
                {
                    this.Response.Redirect(string.Format("{0}Messages/VerifyFalse.aspx", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath));
                }
            }
        }
 public void RefreshUser()
 {
     User sessionUser = this.Session[Constant.SESSION_KEY_USER] as User;
     if (sessionUser != null)
     {
         if ((sessionUser.Authentication) || (sessionUser.Prerogative))
         {
             UserBusiness business = new UserBusiness();
             business.Refresh(sessionUser);
             this.Session[Constant.SESSION_KEY_USER] = sessionUser;
         }
     }
 }