Пример #1
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();
        }