/// <summary>
        /// 加载用户信息数据
        /// </summary>
        private void GetUserInfo()
        {
            //从数据库中加载数据
            DataTable dt = UserGroupInformationManagementBLL.GetUserInformationForInputWindow();

            if (dt != null)
            {
                //datagridview显示用户信息
                _dgrvdUserInfo.DataSource = DecryptDataTable(dt);

                for (int i = 0; i < _dgrvdUserInfo.ColumnCount; i++)
                {
                    //"USER_LOGIN_NAME"
                    if (_dgrvdUserInfo.Columns[i].HeaderText == LibBusiness.UserLoginInformationManagementDbConstNames.USER_LOGIN_NAME)
                    {
                        _dgrvdUserInfo.Columns[i].HeaderText = LibCommon.Const.USER_GROUP_NAME_LOGIN_NAME;
                    }
                    //"USER_GROUP_NAME"
                    if (_dgrvdUserInfo.Columns[i].HeaderText == LibBusiness.UserLoginInformationManagementDbConstNames.USER_GROUP_NAME)
                    {
                        _dgrvdUserInfo.Columns[i].HeaderText = LibCommon.Const.USER_GROUP_NAME_LOGIN_NAME_USER_GROUP;
                    }
                    //"USER_PERMISSION"
                    if (_dgrvdUserInfo.Columns[i].HeaderText == LibBusiness.UserLoginInformationManagementDbConstNames.USER_PERMISSION)
                    {
                        _dgrvdUserInfo.Columns[i].HeaderText = LibCommon.Const.USER_GROUP_NAME_PERMISSION;
                    }

                    //设置datagridview列的尺寸
                    _dgrvdUserInfo.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                }
            }
            //清除选择
            _dgrvdUserInfo.ClearSelection();
        }
        /// <summary>
        /// 加载用户组信息数据
        /// </summary>
        private void GetUserGrouptInfo()
        {
            #region  除垃圾数据
            while (_fpUserGroupInfo.ActiveSheet.Rows.Count > _fpRowsTitleCount)
            {
                _fpUserGroupInfo.ActiveSheet.Rows.Remove(_fpRowsTitleCount, 1);
            }
            #endregion

            //从数据库中获取用户组信息值
            DataTable dt = UserGroupInformationManagementBLL.GetUserGroupInformation();

            if (dt != null)
            {
                //记录条数
                int n = dt.Rows.Count;
                //记录列数
                int k = dt.Columns.Count;

                for (int i = 0; i < n; i++)
                {
                    this._fpUserGroupInfo.ActiveSheet.Rows.Add(i + _fpRowsTitleCount, 1);
                    for (int j = 0; j < k; j++)
                    {
                        //设置单元格类型
                        this._fpUserGroupInfo.Sheets[0].Cells[i + 2, j + 1].CellType = new FarPoint.Win.Spread.CellType.TextCellType();
                        //锁定单元格
                        this._fpUserGroupInfo.Sheets[0].Cells[i + 2, j + 1].Locked = true;
                        //设置单元格的值
                        this._fpUserGroupInfo.Sheets[0].Cells[i + 2, j + 1].Text = dt.Rows[i][j].ToString();
                        //设置单元格对其方式
                        this._fpUserGroupInfo.Sheets[0].Cells[i + 2, j + 1].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Left;
                        this._fpUserGroupInfo.Sheets[0].Cells[i + 2, j + 1].VerticalAlignment   = FarPoint.Win.Spread.CellVerticalAlignment.Center;
                    }

                    //设置选择单元格的类型与对其方式
                    this._fpUserGroupInfo.Sheets[0].Cells[i + 2, 0].CellType            = new FarPoint.Win.Spread.CellType.CheckBoxCellType();
                    this._fpUserGroupInfo.Sheets[0].Cells[i + 2, 0].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
                    this._fpUserGroupInfo.Sheets[0].Cells[i + 2, 0].VerticalAlignment   = FarPoint.Win.Spread.CellVerticalAlignment.Center;
                }
            }

            //设置焦点
            this._fpUserGroupInfo.ActiveSheet.SetActiveCell(1, 0);
        }
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOK_Click(object sender, EventArgs e)
        {
            //解决确定后窗体关闭问题
            DialogResult = DialogResult.None;
            //用户组名称
            string name = _txtGroupName.Text.ToString().Trim();

            //检查用户组名称不能为空,不能重复
            if (LibCommon.Validator.checkSpecialCharacters(name) || LibCommon.Validator.IsEmpty(name) || UserGroupInformationManagementBLL.FindTheSameGroupName(name))
            {
                Alert.alert(LibCommon.Const.USER_GROUP_NAME_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //设置焦点
                _txtGroupName.Focus();
                return;
            }
            //选择用户的数量
            int userCount = _lstSelUserName.Items.Count;

            //定义用户组信息实体
            LibEntity.UserGroup ent = new LibEntity.UserGroup();
            //组名
            ent.GroupName = _txtGroupName.Text.ToString().Trim();
            //人数
            ent.UserCount = userCount.ToString();
            //备注
            ent.Remark = _rtxtRemarks.Text.ToString().Trim();
            //插入数据库
            UserGroupInformationManagementBLL.InsertRecordIntoTableUserGroupInformation(ent);

            //修改用户登录信息表中记录的组名
            for (int i = 0; i < userCount; i++)
            {
                UserGroupInformationManagementBLL.ChangeUserGroup(ent.GroupName, _lstSelUserName.Items[i].ToString());
            }

            DataTable dt = UserGroupInformationManagementBLL.GetUserGroupInformation();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                UserGroupInformationManagementBLL.UpdateUserCountFromUserGroup(dt.Rows[i][UserGroupInformationMangementDbConstNames.USER_GROUP_NAME].ToString());
            }
            this.Close();
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsBtnDel_Click(object sender, EventArgs e)
        {
            if (Alert.confirm(Const.DEL_CONFIRM_MSG, Const.NOTES, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                //获取记录条数
                int n = GetTableRecordCount();
                for (int i = n - 1; i >= 0; i--)
                {
                    if (this._fpUserGroupInfo.ActiveSheet.Cells[2 + i, 0].CellType is CheckBoxCellType)
                    {
                        if (this._fpUserGroupInfo.ActiveSheet.Cells[2 + i, 0].Value != null)
                        {
                            if ((bool)this._fpUserGroupInfo.ActiveSheet.Cells[2 + i, 0].Value)
                            {
                                this._fpUserGroupInfo.ActiveSheet.Rows.Remove(2 + i, 1);
                            }
                        }
                    }
                }

                //更新数据库中用户组、用户信息
                foreach (string str in _strUserGroupSel)
                {
                    //删除用户组
                    UserGroupInformationManagementBLL.DeleteUserGroupInformationByGroupName(str);
                    //删除登录用户的用户组信息
                    UserGroupInformationManagementBLL.UpdateUserInformationWhenDeleteGroup(str);
                }

                //farPoint刷新
                _fpUserGroupInfo.Refresh();

                //设置焦点
                this._fpUserGroupInfo.ActiveSheet.SetActiveCell(UserGroupInformationManagementBLL.GetRecordCountFromTable() + 1, 0);

                //设置删除按钮不可用
                tsBtnDel.Enabled = false;
            }
        }
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOK_Click(object sender, EventArgs e)
        {
            //登录名
            string loginname = _txtLoginName.Text;
            //密码
            string password = _txtPassWord.Text;
            //所属用户组
            string groupname = _cboGroup.Text;
            //权限
            string permission = _cboPermission.Text;
            //备注
            string remarks = _rtxtRemark.Text;

            //用户登录名不能包含特殊字符且不能为空
            //查空、特殊字符
            if (LibCommon.Validator.checkSpecialCharacters(_txtLoginName.Text.ToString()) || LibCommon.Validator.IsEmpty(_txtLoginName.Text.ToString()))
            {
                Alert.alert(LibCommon.Const.LOGIN_NAME_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                _txtLoginName.Focus();
                return;
            }

            //添加时查重
            if (_strIsAddOrModify == "add")
            {
                UserLogin entAdd = UserLogin.FindOneByLoginName(_txtLoginName.Text.ToString().Trim());
                if (entAdd != null)
                {
                    if (entAdd.LoginName == _txtLoginName.Text.ToString())
                    {
                        Alert.alert(LibCommon.Const.LOGIN_NAME_EXIST, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        _txtLoginName.Focus();
                        return;
                    }
                }
            }
            //修改
            else if (_strIsAddOrModify == "modify")
            {
                UserLogin entModify = UserLogin.Find(_needModifyEnt.Id);
                if (entModify != null)
                {
                    Alert.alert(LibCommon.Const.LOGIN_NAME_EXIST, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    _txtLoginName.Focus();
                    return;
                }
            }

            //密码不能包含特殊字符且不能为空
            if (LibCommon.Validator.checkSpecialCharacters(password) || LibCommon.Validator.IsEmptyOrBlank(password))
            {
                Alert.alert(LibCommon.Const.PASS_WORD_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                _txtPassWord.Focus();
                return;
            }

            //确认密码不能为空且必须与密码值相同
            if (_txtConfirmPassword.Text != _txtPassWord.Text)
            {
                Alert.alert(LibCommon.Const.CONFIRM_PASSWORD_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                _txtConfirmPassword.Focus();
                return;
            }

            //权限选择不能为空
            if (_cboPermission.SelectedItem == null)
            {
                Alert.alert(LibCommon.Const.PERMISSION_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                _cboPermission.Focus();
                return;
            }

            //定义用户实体
            UserLogin ent = new UserLogin();

            //登录名
            ent.LoginName = loginname;
            //密码
            ent.PassWord = password;
            //权限
            ent.Permission = permission;
            //所属用户组
            ent.GroupName = groupname;
            //备注
            ent.Remarks = remarks;
            //尚未登录系统,在插入新值时,默认为True
            ent.IsLogined = 0;
            //记住密码,在插入新值时,默认为False
            ent.IsSavePassWord = 0;

            //添加
            if (_strIsAddOrModify == "add")
            {
                //数据库插值
                ent.Save();
                UserGroupInformationManagementBLL.UpdateUserCountFromUserGroup(ent.GroupName);
            }
            //修改
            if (_strIsAddOrModify == "modify")
            {
                //数据库更新,ent代表修改的实体,参数2代表LoginName
                UserLogin.FindOneByLoginName(UserLoginInformationManagement._userSel[0]);
                ent.LoginName      = loginname;
                ent.PassWord       = password;
                ent.Permission     = permission;
                ent.GroupName      = groupname;
                ent.Remarks        = remarks;
                ent.IsLogined      = 0;
                ent.IsSavePassWord = 0;
                ent.Save();
            }

            //初次登录系统时,需要添加新用户。记录初次登录的用户名与密码,并直接输入到LoginForm中
            if (LibCommon.Const.FIRST_TIME_LOGIN)
            {
                LibCommon.Const.FIRST_LOGIN_NAME       = ent.LoginName;
                LibCommon.Const.FIRST_LOGIN_PASSWORD   = ent.PassWord;
                LibCommon.Const.FIRST_LOGIN_PERMISSION = ent.Permission;
                this.Close();
                return;
            }
            this.Close();
        }
        /// <summary>
        /// 属性值更改
        /// </summary>
        /// <param name="s"></param>
        /// <param name="e"></param>
        private void _propInfo_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            //获取当前行的行索引
            int n = this._fpUserGroupInfo.ActiveSheet.ActiveCell.Row.Index;

            //选择表题时,返回
            if (n < 2)
            {
                return;
            }

            //定义接收变化的值
            string changeValue = "";

            if (e.ChangedItem.Value != null)
            {
                //若易报错,则首先检查fp中columns的tag是否与ss相同
                //获取更改值的Label
                string ss = e.ChangedItem.Label.ToString();
                //获取列索引
                int columnIndex = this._fpUserGroupInfo.ActiveSheet.Columns[ss].Index;
                //获取修改的值
                changeValue = e.ChangedItem.Value.ToString();

                if (ss == _strUserGroupNameLable)
                {
                    //检测特殊字符、是否为空、是否重复
                    if (LibCommon.Validator.checkSpecialCharacters(changeValue) ||
                        LibCommon.Validator.IsEmpty(changeValue) ||
                        UserGroupInformationManagementBLL.FindTheSameGroupName(changeValue))
                    {
                        Alert.alert(LibCommon.Const.USER_GROUP_NAME_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        fpUserInfo_SelectionChanged(null, null);
                        return;
                    }

                    //检查字符串的长度
                    if (changeValue.Length > _iUserGroupNameLength)
                    {
                        Alert.alert(LibCommon.Const.TXT_IS_WRONG1 + _iUserGroupNameLength + LibCommon.Const.TXT_IS_WRONG2, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        fpUserInfo_SelectionChanged(null, null);
                        return;
                    }
                }

                #region 获取旧值
                //定义组名称
                string groupName = "";
                //人数
                string userCount = "";
                //备注
                string remark = "";

                //从farpoint取值时,检查是否为空
                if (this._fpUserGroupInfo.ActiveSheet.Cells[n, 1].Value != null)
                {
                    groupName = this._fpUserGroupInfo.ActiveSheet.Cells[n, 1].Value.ToString();
                }
                if (this._fpUserGroupInfo.ActiveSheet.Cells[n, 2].Value != null)
                {
                    userCount = this._fpUserGroupInfo.ActiveSheet.Cells[n, 2].Value.ToString();
                }
                if (this._fpUserGroupInfo.ActiveSheet.Cells[n, 3].Value != null)
                {
                    remark = this._fpUserGroupInfo.ActiveSheet.Cells[n, 3].Value.ToString();
                }

                //用户组名称旧值
                string oldName = groupName;

                if (ss == _strUserGroupNameLable)
                {
                    oldName = e.OldValue.ToString();
                }
                #endregion

                //修改farpoint的显示值
                this._fpUserGroupInfo.ActiveSheet.Cells[n, columnIndex].Text = changeValue;

                //定义用户组信息实体,接收新值
                LibEntity.UserGroup userGroupInfo = new LibEntity.UserGroup();
                userGroupInfo.GroupName = groupName;
                userGroupInfo.UserCount = userCount;
                userGroupInfo.Remark    = remark;

                //更新数据库
                UserGroupInformationManagementBLL.UpdateUserGroupInfomationDatabase(userGroupInfo, oldName);
            }
        }
 /// <summary>
 /// 从表中获取数据
 /// </summary>
 /// <param name="tableName"></param>
 /// <returns></returns>
 private int GetTableRecordCount()
 {
     return(UserGroupInformationManagementBLL.GetRecordCountFromTable());
 }
 /// <summary>
 /// farpoint单击事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void fpUserInfo_ButtonClicked(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
 {
     if (this._fpUserGroupInfo.ActiveSheet.Cells[e.Row, 1] != null)
     {
         // 判断点击的空间类型是否是.FpCheckBox)
         if (e.EditingControl is FarPoint.Win.FpCheckBox)
         {
             FarPoint.Win.FpCheckBox fpChk = (FarPoint.Win.FpCheckBox)e.EditingControl;
             // 判断是否被选中
             if (fpChk.Checked)
             {
                 if (!_strUserGroupSel.Contains(this._fpUserGroupInfo.ActiveSheet.Cells[e.Row, 1].Value.ToString()))
                 {
                     //记录选中的用户组名称
                     _strUserGroupSel.Add(this._fpUserGroupInfo.ActiveSheet.Cells[e.Row, 1].Value.ToString());
                     //判断是否已全选
                     this._chkSelAll.CheckedChanged -= this.chkSelAll_CheckedChanged;
                     this._chkSelAll.Checked         = _strUserGroupSel.Count == UserGroupInformationManagementBLL.GetRecordCountFromTable() ? true : false;
                     this._chkSelAll.CheckedChanged += this.chkSelAll_CheckedChanged;
                 }
             }
             else
             {
                 // 移除索引号
                 _strUserGroupSel.Remove(this._fpUserGroupInfo.ActiveSheet.Cells[e.Row, 1].Value.ToString());
                 // 全选/全不选checkbox设为未选中
                 this._chkSelAll.CheckedChanged -= this.chkSelAll_CheckedChanged;
                 this._chkSelAll.Checked         = false;
                 this._chkSelAll.CheckedChanged += this.chkSelAll_CheckedChanged;
             }
             // 删除按钮
             this.tsBtnDel.Enabled = (_strUserGroupSel.Count >= 1) ? true : false;
         }
     }
 }