예제 #1
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsBtnDel_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(@"确认要删除部门信息吗?", "提示:", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                int n = GetTableRecordCount();//获取表中记录条数
                for (int i = n - 1; i >= 0; i--)
                {
                    if (this._fpDepartmentInfo.ActiveSheet.Cells[2 + i, 0].CellType is CheckBoxCellType)
                    {
                        if (this._fpDepartmentInfo.ActiveSheet.Cells[2 + i, 0].Value != null)
                        {
                            if ((bool)this._fpDepartmentInfo.ActiveSheet.Cells[2 + i, 0].Value)
                            {
                                this._fpDepartmentInfo.ActiveSheet.Rows.Remove(2 + i, 1);
                            }
                        }
                    }
                }
                foreach (string str in _departmentSel)
                {
                    //删除数据库中部门信息
                    DepartmentInformationManagementBLL.DeleteDeptInformationByDeptName(str);
                    //更新用户详细信息表中部门信息
                    DepartmentInformationManagementBLL.UpdateUserInformationWhenDeleteDept(str);
                }
                //刷新
                _fpDepartmentInfo.Refresh();

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

                //设置按钮不可用
                this.tsBtnDel.Enabled = false;
            }
        }
예제 #2
0
        /// <summary>
        /// 获取所有部门信息
        /// </summary>
        private void GetDepartmentInfo()
        {
            #region  除垃圾数据
            while (_fpDepartmentInfo.ActiveSheet.Rows.Count > _ifpRowTitleCount)
            {
                _fpDepartmentInfo.ActiveSheet.Rows.Remove(_ifpRowTitleCount, 1);
            }
            #endregion

            //数据库中读取数据
            DataTable dt = DepartmentInformationManagementBLL.GetDeptInformation();
            if (dt != null)
            {
                //获取行列数
                int n = dt.Rows.Count;
                int k = dt.Columns.Count;
                for (int i = 0; i < n; i++)
                {
                    this._fpDepartmentInfo.ActiveSheet.Rows.Add(_ifpRowTitleCount + i, 1);
                    for (int j = 0; j < k; j++)
                    {
                        //设置单元格类型
                        this._fpDepartmentInfo.Sheets[0].Cells[i + 2, j + 1].CellType = new FarPoint.Win.Spread.CellType.TextCellType();
                        //锁定单元格
                        this._fpDepartmentInfo.Sheets[0].Cells[i + 2, j + 1].Locked = true;
                        //设置单元格显示文本
                        this._fpDepartmentInfo.Sheets[0].Cells[i + 2, j + 1].Text = dt.Rows[i][j].ToString();
                        //调整单元格对其方式
                        this._fpDepartmentInfo.Sheets[0].Cells[i + 2, j + 1].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Left;
                        this._fpDepartmentInfo.Sheets[0].Cells[i + 2, j + 1].VerticalAlignment   = FarPoint.Win.Spread.CellVerticalAlignment.Center;
                    }

                    //设置第一列的值为checkbox,并设置格式
                    this._fpDepartmentInfo.Sheets[0].Cells[i + 2, 0].CellType            = new FarPoint.Win.Spread.CellType.CheckBoxCellType();
                    this._fpDepartmentInfo.Sheets[0].Cells[i + 2, 0].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
                    this._fpDepartmentInfo.Sheets[0].Cells[i + 2, 0].VerticalAlignment   = FarPoint.Win.Spread.CellVerticalAlignment.Center;
                }
            }
            //设置单元格焦点
            this._fpDepartmentInfo.ActiveSheet.SetActiveCell(1, 0);
        }
예제 #3
0
 /// <summary>
 /// farPoint单击 触发
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void fpDepartmentInfo_ButtonClicked(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
 {
     if (this._fpDepartmentInfo.ActiveSheet.Cells[e.Row, 1].Value != null)
     {
         // 判断点击的空间类型是否是.FpCheckBox)
         if (e.EditingControl is FarPoint.Win.FpCheckBox)
         {
             FarPoint.Win.FpCheckBox fpChk = (FarPoint.Win.FpCheckBox)e.EditingControl;
             // 判断是否被选中
             if (fpChk.Checked)
             {
                 // 保存索引号
                 if (!_departmentSel.Contains(this._fpDepartmentInfo.ActiveSheet.Cells[e.Row, 1].Value.ToString()))
                 {
                     _departmentSel.Add(this._fpDepartmentInfo.ActiveSheet.Cells[e.Row, 1].Value.ToString());
                     this._chkSelAll.CheckedChanged -= this.chkSelAll_CheckedChanged;
                     this._chkSelAll.Checked         = _departmentSel.Count == DepartmentInformationManagementBLL.GetRecordCountFromTable() ? true : false;
                     this._chkSelAll.CheckedChanged += this.chkSelAll_CheckedChanged;
                 }
             }
             else
             {
                 // 移除索引号
                 _departmentSel.Remove(this._fpDepartmentInfo.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           = (_departmentSel.Count >= 1) ? true : false;
         this.除ToolStripMenuItem.Enabled = (_departmentSel.Count >= 1) ? true : false;
     }
 }
예제 #4
0
 /// <summary>
 /// 从数据库中获取记录条数
 /// </summary>
 /// <returns></returns>
 private int GetTableRecordCount()
 {
     return(DepartmentInformationManagementBLL.GetRecordCountFromTable());
 }
예제 #5
0
        /// <summary>
        /// 属性窗口的值发生变化
        /// </summary>
        /// <param name="s"></param>
        /// <param name="e"></param>
        private void propertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            //获取fp中的当前行
            int currentRow = this._fpDepartmentInfo.ActiveSheet.ActiveCell.Row.Index;
            //定义变量,接收修改的值
            string changeValue = "";

            //存在修改值时
            if (e.ChangedItem.Value != null)
            {
                //修改值的标题
                string ss = e.ChangedItem.Label.ToString();
                //获取fp中修改值的列索引
                int columnIndex = this._fpDepartmentInfo.ActiveSheet.Columns[ss].Index;
                //获取修改的值
                changeValue = e.ChangedItem.Value.ToString();

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

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

                //验证邮箱
                if (ss == _strDeptEmailLable)
                {
                    //邮箱格式
                    if (!LibCommon.Validator.checkIsEmailAddress(changeValue))
                    {
                        Alert.alert(LibCommon.Const.DEPT_EMAIL_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        fpDepartmentInfo_SelectionChanged(null, null);
                        return;
                    }
                    //检查字符串的长度
                    if (changeValue.Length > _iDeptEmailLength)
                    {
                        Alert.alert(LibCommon.Const.TXT_IS_WRONG1 + _iDeptEmailLength + LibCommon.Const.TXT_IS_WRONG2, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        fpDepartmentInfo_SelectionChanged(null, null);
                        return;
                    }
                }

                //验证电话
                if (ss == _strDeptTelLable)
                {
                    //验证电话格式
                    if (!LibCommon.Validator.checkIsIsTelePhone(changeValue))
                    {
                        Alert.alert(LibCommon.Const.DEPT_TEL_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        fpDepartmentInfo_SelectionChanged(null, null);
                        return;
                    }

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

                //验证人数必须是数字
                if (ss == _strDeptStuffCount)
                {
                    if (!LibCommon.Validator.IsNumeric(changeValue))
                    {
                        Alert.alert(LibCommon.Const.DEPT_STAFF_COUNT_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        fpDepartmentInfo_SelectionChanged(null, null);
                        return;
                    }
                }

                //Farpoint显示修改值
                this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, columnIndex].Text = changeValue;

                //部门名称
                string name = "";
                //部门电话
                string tel = "";
                //部门邮箱
                string email = "";
                //部门人数
                string staff = "";
                //备注
                string remark = "";

                //从FarPoint上取值,检查值是否为空
                if (this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, 1].Value != null)
                {
                    name = this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, 1].Value.ToString();
                }
                if (this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, 2].Value != null)
                {
                    tel = this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, 2].Value.ToString();
                }
                if (this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, 3].Value != null)
                {
                    email = this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, 3].Value.ToString();
                }
                if (this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, 4].Value != null)
                {
                    staff = this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, 4].Value.ToString();
                }
                if (this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, 5].Value != null)
                {
                    remark = this._fpDepartmentInfo.ActiveSheet.Cells[currentRow, 5].Value.ToString();
                }

                //旧的 部门名称
                string oldName = name;
                if (ss == _strDeptNameLable)
                {
                    oldName = e.OldValue.ToString();
                }

                //定义 部门信息实体 接收新修改的数据
                LibEntity.Department userDeptInfo = new LibEntity.Department();
                //部门名称
                userDeptInfo.Name = name;
                //人数
                userDeptInfo.Staff = staff;
                //邮箱
                userDeptInfo.Email = email;
                //电话
                userDeptInfo.Tel = tel;
                //备注
                userDeptInfo.Remark = remark;

                //更新数据库
                DepartmentInformationManagementBLL.UpdateDepartmentInfomationDatabase(userDeptInfo, oldName);
            }
        }
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOK_Click(object sender, EventArgs e)
        {
            string name  = _txtName.Text.ToString().Trim();
            string tel   = _txtTel.Text.ToString().Trim();
            string email = _txtEmail.Text.ToString().Trim();
            string staff = _txtStaffCount.Text.ToString().Trim();

            //查询数据库中是否已存在该部门名称
            if (LibCommon.Validator.checkSpecialCharacters(name) ||
                LibCommon.Validator.IsEmpty(name) ||
                DepartmentInformationManagementBLL.FindDeptInformationByDeptName(name))
            {
                //部门名称不能为空,且不能重复
                Alert.alert(LibCommon.Const.DEPT_NAME_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //设置焦点
                _txtName.Focus();
                return;
            }

            //验证电话格式
            if (!LibCommon.Validator.checkIsIsTelePhone(tel) && tel != "")
            {
                Alert.alert(LibCommon.Const.DEPT_TEL_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                _txtTel.Focus();
                return;
            }

            //邮箱格式
            if (!LibCommon.Validator.checkIsEmailAddress(email) && email != "")
            {
                Alert.alert(LibCommon.Const.DEPT_EMAIL_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                _txtEmail.Focus();
                return;
            }

            //定义默认的部门人数
            int staffNumber = 0;

            //部门人数可以为空,但不能为非数字
            if (!int.TryParse(_txtStaffCount.Text.ToString().Trim(), out staffNumber) && staff != "")
            {
                //提示用户部门人数不为数字,并设置焦点
                Alert.alert(LibCommon.Const.DEPT_STAFF_COUNT_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                _txtStaffCount.Focus();
                return;
            }

            //定义部门信息实体
            LibEntity.Department ent = new LibEntity.Department();
            //部门名称
            ent.Name = _txtName.Text.ToString().Trim();
            //部门邮箱
            ent.Email = _txtEmail.Text.ToString().Trim();
            //部门电话
            ent.Tel = _txtTel.Text.ToString().Trim();
            //部门人数
            ent.Staff = staffNumber.ToString();
            //备注
            ent.Remark = _rtxtRemarks.Text.ToString().Trim();

            //添加数据到数据库
            DepartmentInformationManagementBLL.InsertDeptInfoIntoTable(ent);

            this.Close();
        }