Esempio n. 1
0
        /// <summary>
        /// 数据验证
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvSetLevelValue_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            this.dgvSetLevelValue.EndEdit();  //结束编辑状态
            string value = this.dgvSetLevelValue.CurrentCell.Value == null ? "" : this.dgvSetLevelValue.CurrentCell.Value.ToString().Trim();

            if (value == "")
            {
                return;
            }
            if (this.dgvSetLevelValue.CurrentCell.OwningColumn.Name == "More" || this.dgvSetLevelValue.CurrentCell.OwningColumn.Name == "Less")
            {
                if (!DataCheck.CheckRegEx(value, "^(-?\\d+)(\\.\\d+)?$"))
                {
                    e.Cancel         = true;
                    this._isValidate = false;
                    MessageBox.Show("数据类型不对,应该为浮点数!", "信息提示");

                    this.dgvSetLevelValue.BeginEdit(true);
                    return;
                }
            }
        }
        /// <summary>
        /// 单元格数据验证
        /// </summary>
        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            this.dataGridView1.EndEdit();  //结束编辑状态
            string value = this.dataGridView1.CurrentCell.Value == null ? "" : this.dataGridView1.CurrentCell.Value.ToString().Trim();

            if (this.dataGridView1.CurrentCell.ColumnIndex == 5 || this.dataGridView1.CurrentCell.ColumnIndex == 6)
            {
                if (value != "")
                {
                    if (!DataCheck.CheckRegEx(value, "^(-?\\d+)(\\.\\d+)?$"))
                    {
                        e.Cancel    = true;
                        _isValidate = false;
                        MessageBox.Show("数据类型不对,应该为浮点数!", "信息提示");
                        this.dataGridView1.BeginEdit(true);
                        return;
                    }
                }
            }

            this._isValidate = true;
        }
Esempio n. 3
0
        /// <summary>
        /// 单元格数据验证
        /// </summary>
        private void dgdViewAll_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            this.dgdViewAll.EndEdit();  //结束编辑状态
            string value = dgdViewAll.CurrentCell.Value == null ? "" : dgdViewAll.CurrentCell.Value.ToString().Trim();

            if (dgdViewAll.CurrentCell.OwningColumn.Name.Equals("itemOrder"))
            {
                //if (!DataCheck.CheckRegEx(value, "^[0-9]*[1-9][0-9]*$"))
                //{
                //    e.Cancel = true;
                //    _isValidate = false;
                //    MessageBox.Show("序号应该为整数!", "信息提示");
                //    dgdViewAll.CurrentCell = this.dgdViewAll.CurrentRow.Cells["itemOrder"];
                //    this.dgdViewAll.BeginEdit(true);
                //    return;
                //}
            }
            //else if (if (dgdViewAll.CurrentCell.OwningColumn.Name.Equals("itemName")))
            //{
            //    if (value == "")
            //    {
            //        e.Cancel = true;
            //        _isValidate = false;
            //        MessageBox.Show("项目名不能为空!", "信息提示");
            //        dgdViewAll.CurrentCell = this.dgdViewAll.CurrentRow.Cells["itemName"];
            //        this.dgdViewAll.BeginEdit(true);
            //        return;
            //    }
            //}
            else if (dgdViewAll.CurrentCell.OwningColumn.Name.Equals("decNumber"))//decNumber
            {
                if (value == "")
                {
                    return;
                }
                if (!DataCheck.CheckRegEx(value, "^[0-9]*[0-9][0-9]*$"))
                {
                    e.Cancel    = true;
                    _isValidate = false;
                    MessageBox.Show("数据类型不对,应该为正整数或为空!", "信息提示");
                    this.dgdViewAll.BeginEdit(true);
                    return;
                }
            }
            else if (dgdViewAll.CurrentCell.OwningColumn.Name.Equals("valDigital"))//ValDigal
            {
                if (value == "")
                {
                    return;
                }
                if (!DataCheck.CheckRegEx(value, "^[0-9]*[0-9][0-9]*$"))
                {
                    e.Cancel    = true;
                    _isValidate = false;
                    MessageBox.Show("数据类型不对,应该为大于0的数!", "信息提示");
                    this.dgdViewAll.BeginEdit(true);
                    return;
                }
                else
                {
                    int temp;
                    if (int.TryParse(value, out temp) && temp > 0)
                    {
                    }
                    else
                    {
                        e.Cancel    = true;
                        _isValidate = false;
                        MessageBox.Show("数据类型不对,应该为大于0的数!", "信息提示");
                        //dgdViewAll.CurrentCell = this.dgdViewAll.CurrentRow.Cells["itemName"];
                        this.dgdViewAll.BeginEdit(true);
                        return;
                    }
                }
            }
            else if (dgdViewAll.CurrentCell.OwningColumn.Name.Equals("errDownLimit") ||
                     dgdViewAll.CurrentCell.OwningColumn.Name.Equals("errUpLimit") ||
                     dgdViewAll.CurrentCell.OwningColumn.Name.Equals("trend"))
            {
                if (value != "")
                {
                    if (!DataCheck.CheckRegEx(value, "^(-?\\d+)(\\.\\d+)?$"))
                    {
                        e.Cancel    = true;
                        _isValidate = false;
                        MessageBox.Show("数据类型不对,应该为浮点数!", "信息提示");
                        this.dgdViewAll.BeginEdit(true);
                        return;
                    }
                }
            }
            else if (dgdViewAll.CurrentCell.OwningColumn.Name == "outExcel")
            {
            }
            _isValidate = true;
        }