Example #1
0
        private void DataGridViewItemsCellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return;
            }

            #region             //Проверка колонки "Выполнено"
            if (e.ColumnIndex == ColumnClosed.Index)
            {
                checkBoxSelectAll.CheckedChanged -= CheckBoxSelectAllCheckedChanged;

                IEnumerable <WorkPackageClosingDataGridViewRow> rows =
                    dataGridViewItems.Rows.OfType <WorkPackageClosingDataGridViewRow>();
                bool checkedValue   = rows.FirstOrDefault(r => (bool)r.Cells[ColumnClosed.Index].Value) != null;
                bool unCheckedValue = rows.FirstOrDefault(r => !(bool)r.Cells[ColumnClosed.Index].Value) != null;
                if (checkedValue && unCheckedValue)
                {
                    checkBoxSelectAll.CheckState = CheckState.Indeterminate;
                }
                else if (checkedValue)
                {
                    checkBoxSelectAll.CheckState = CheckState.Checked;
                }
                else
                {
                    checkBoxSelectAll.CheckState = CheckState.Unchecked;
                }

                checkBoxSelectAll.CheckedChanged += CheckBoxSelectAllCheckedChanged;
            }
            #endregion

            #region             //Проверка колонки "Часы"
            if (e.ColumnIndex == ColumnHours.Index)
            {
                WorkPackageClosingDataGridViewRow row =
                    dataGridViewItems.Rows[e.RowIndex] as WorkPackageClosingDataGridViewRow;
                if (row == null || row.ClosingItem is Component)
                {
                    return;
                }
                DataGridViewCell cell  = dataGridViewItems[e.ColumnIndex, e.RowIndex];
                string           value = cell.Value as string;
                if (value == null)
                {
                    return;
                }
                if (Lifelength.ValidateHours(value))
                {
                    int?totalMinutes = Lifelength.ParseTotalMinutes(value);
                    if (totalMinutes == null)
                    {
                        return;
                    }

                    if (row.MinPerfSource != null &&
                        row.MinPerfSource.TotalMinutes != null &&
                        row.MinPerfSource.TotalMinutes > totalMinutes)
                    {
                        cell.Style.BackColor = Color.Red;
                    }
                    else
                    {
                        cell.Style.BackColor = Color.White;
                    }
                }
                else
                {
                    cell.Style.BackColor = Color.Red;
                }
            }
            #endregion

            #region             //Проверка колонки "Циклы"
            if (e.ColumnIndex == ColumnCycles.Index)
            {
                WorkPackageClosingDataGridViewRow row =
                    dataGridViewItems.Rows[e.RowIndex] as WorkPackageClosingDataGridViewRow;
                if (row == null || row.ClosingItem is Component)
                {
                    return;
                }

                DataGridViewCell cell  = dataGridViewItems[e.ColumnIndex, e.RowIndex];
                string           value = cell.Value as string;
                if (value == null)
                {
                    return;
                }
                if (Lifelength.ValidateCyclesOrDays(value))
                {
                    int?cycles = Lifelength.ParseCyclesOrDays(value);
                    if (cycles == null)
                    {
                        return;
                    }
                    if (row.MinPerfSource != null &&
                        row.MinPerfSource.Cycles != null &&
                        row.MinPerfSource.Cycles > cycles)
                    {
                        cell.Style.BackColor = Color.Red;
                    }
                    else
                    {
                        cell.Style.BackColor = Color.White;
                    }
                }
                else
                {
                    cell.Style.BackColor = Color.Red;
                }
            }
            #endregion

            #region             //Проверка колонки "Дни"
            if (e.ColumnIndex == ColumnDays.Index)
            {
                WorkPackageClosingDataGridViewRow row =
                    dataGridViewItems.Rows[e.RowIndex] as WorkPackageClosingDataGridViewRow;
                if (row == null || row.ClosingItem is Component)
                {
                    return;
                }

                DataGridViewCell cell  = dataGridViewItems[e.ColumnIndex, e.RowIndex];
                string           value = cell.Value as string;
                if (value == null)
                {
                    return;
                }
                if (Lifelength.ValidateCyclesOrDays(value))
                {
                    int?cycles = Lifelength.ParseCyclesOrDays(value);
                    if (cycles == null)
                    {
                        return;
                    }
                    if (row.MinPerfSource != null &&
                        row.MinPerfSource.Days != null &&
                        row.MinPerfSource.Days > cycles)
                    {
                        cell.Style.BackColor = Color.Red;
                    }
                    else
                    {
                        cell.Style.BackColor = Color.White;
                    }
                }
                else
                {
                    cell.Style.BackColor = Color.Red;
                }
            }
            #endregion

            #region             //Проверка колонки "Дата"

            if (e.ColumnIndex == ColumnDate.Index)
            {
                WorkPackageClosingDataGridViewRow row =
                    dataGridViewItems.Rows[e.RowIndex] as WorkPackageClosingDataGridViewRow;
                if (row != null && !(row.ClosingItem is Component))
                {
                    DateTime dateTime = Convert.ToDateTime(row.Cells[ColumnDate.Index].Value);

                    if (row.PrevPerfDate != null && dateTime < row.PrevPerfDate)
                    {
                        row.Cells[ColumnDate.Index].Value = row.PrevPerfDate.Value;
                    }
                    else if (dateTime < new DateTime(1950, 1, 1))
                    {
                        row.Cells[ColumnDate.Index].Value = DateTimeExtend.GetCASMinDateTime();
                    }
                    if (row.NextPerfDate != null && dateTime > row.NextPerfDate)
                    {
                        row.Cells[ColumnDate.Index].Value = row.NextPerfDate.Value;
                    }
                    else if (dateTime > DateTime.Now)
                    {
                        row.Cells[ColumnDate.Index].Value = DateTime.Now;
                    }

                    if (row.ClosingItem.LifeLengthParent is Operator)
                    {
                        row.Cells[ColumnHours.Index].Value  = "n/a";
                        row.Cells[ColumnCycles.Index].Value = "n/a";
                        row.Cells[ColumnDays.Index].Value   = "n/a";
                    }
                    else
                    {
                        Lifelength performanceSource =
                            GlobalObjects.CasEnvironment.Calculator.GetFlightLifelengthOnStartOfDay(row.ClosingItem.LifeLengthParent, dateTime);
                        row.Cells[ColumnHours.Index].Value = performanceSource.Hours != null?performanceSource.ToHoursMinutesFormat("") : "n/a";

                        row.Cells[ColumnCycles.Index].Value = performanceSource.Cycles != null?performanceSource.Cycles.ToString() : "n/a";

                        row.Cells[ColumnDays.Index].Value = performanceSource.Days != null?performanceSource.Days.ToString() : "n/a";
                    }
                }
            }
            #endregion
        }