Example #1
0
        private void ValidateCells(CancelEventArgs e)
        {
            for (int i = _cropsView.Rows.Count - 1; i >= 0; i--)
            {
                DataGridViewRow curRow = _cropsView.Rows[i];
                if (!curRow.IsNewRow)
                {
                    curRow.ErrorText = string.Empty;
                    curRow.Cells["WidthColumn"].ErrorText  = string.Empty;
                    curRow.Cells["HeightColumn"].ErrorText = string.Empty;

                    string curName = curRow.Cells["NameColumn"].Value != null ? curRow.Cells["NameColumn"].Value.ToString() : string.Empty;
                    if (!string.IsNullOrEmpty(curName))
                    {
                        foreach (DataGridViewRow row in _cropsView.Rows)
                        {
                            if (row != curRow && string.IsNullOrEmpty(row.ErrorText) && curName.Equals(row.Cells["NameColumn"].Value))
                            {
                                curRow.ErrorText = RM.GetString("CropFormatDuplicateError");
                            }
                        }
                    }
                    else
                    {
                        curRow.ErrorText = RM.GetString("CropFormatEmptyError");
                    }

                    float width = 0.0f;
                    if (curRow.Cells["WidthColumn"].Value == null || !float.TryParse(curRow.Cells["WidthColumn"].Value.ToString(), out width) || width < 0)
                    {
                        curRow.Cells["WidthColumn"].ErrorText = RM.GetString("CropWidthError");
                    }

                    float height = 0.0f;
                    if (curRow.Cells["HeightColumn"].Value == null || !float.TryParse(curRow.Cells["HeightColumn"].Value.ToString(), out height) || height < 0)
                    {
                        curRow.Cells["HeightColumn"].ErrorText = RM.GetString("CropHeightError");
                    }

                    if ((width == 0 && height > 0) || (width > 0 && height == 0))
                    {
                        curRow.ErrorText = RM.GetString("FreeCropError");
                    }
                }
            }

            if (BasePanel.HasErrors(_cropsView, false) && e != null)
            {
                e.Cancel = true;
            }
        }