Esempio n. 1
0
        private void dgvLinkData_CellValidating(object sender,
                                                DataGridViewCellValidatingEventArgs e)
        {
            // Validate the values input into the fields

            // From Node must be a positive integer
            if (dgvLinkData.Columns[e.ColumnIndex].Name == "FromNode")
            {
                if (!ValidateData.IsUInt16(e.FormattedValue.ToString()))
                //value is not a positive integer
                {
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.ForeColor = Color.Red;
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Yellow;
                    CellDataError = true;
                }
                else
                {
                    CellDataError = false;
                }
            }
            // To Node must be a positive integer
            if (dgvLinkData.Columns[e.ColumnIndex].Name == "ToNode")
            {
                if (!ValidateData.IsUInt16(e.FormattedValue.ToString()))
                //value is not a positive integer
                {
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.ForeColor = Color.Red;
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Yellow;
                    CellDataError = true;
                }
                else
                {
                    CellDataError = false;
                }
            }
            // Length must be a numeric value
            if (dgvLinkData.Columns[e.ColumnIndex].Name == "Length")
            {
                if (!ValidateData.IsNumeric(e.FormattedValue.ToString()))
                //value is not numeric
                {
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.ForeColor = Color.Red;
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Yellow;
                    CellDataError = true;
                }
                else
                {
                    CellDataError = false;
                }
            }
            // Capacity must be a positive integer
            if (dgvLinkData.Columns[e.ColumnIndex].Name == "Capacity")
            {
                if (!ValidateData.IsUInt16(e.FormattedValue.ToString()))
                //value is not a positive integer
                {
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.ForeColor = Color.Red;
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Yellow;
                    CellDataError = true;
                }
                else
                {
                    CellDataError = false;
                }
            }
            // Free flow speed must be a positive integer
            if (dgvLinkData.Columns[e.ColumnIndex].Name == "FFS")
            {
                if (!ValidateData.IsUInt16(e.FormattedValue.ToString()))
                //value is not a positive integer
                {
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.ForeColor = Color.Red;
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Yellow;
                    CellDataError = true;
                }
                else
                {
                    CellDataError = false;
                }
            }

            // Do not allow description entry to be empty
            if (dgvLinkData.Columns[e.ColumnIndex].Name == "Descrip")
            {
                if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
                {
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.ForeColor = Color.Red;
                    dgvLinkData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Yellow;
                    CellDataError = true;
                }
                else
                {
                    CellDataError = false;
                }
            }
        }