private bool ValidateData() { foreach (WorkPackageClosingDataGridViewRow row in dataGridViewItems.Rows.OfType <WorkPackageClosingDataGridViewRow>()) { if ((bool)row.Cells[ColumnClosed.Index].Value == false) { continue; } string message; if (row.ClosingItem is Component) { TransferRecord tr = row.Record as TransferRecord; if (tr == null) { message = "Performance for:" + $"\n{row.ClosingItem} " + "\nin not transfer record"; message += "\nAbort operation"; MessageBox.Show(message, (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (tr.DestinationObjectId == 0 || tr.TransferDate < DateTimeExtend.GetCASMinDateTime()) { message = @"Displacement parameters are specified components" + "\nClick the link 'Edit Transfer' for set it"; message += "\nAbort operation"; MessageBox.Show(message, (string)new GlobalTermsProvider()["SystemName"], MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { if (!Lifelength.ValidateHours((string)row.Cells[ColumnHours.Index].Value)) { MessageBox.Show("Invalid value for hours parameter", new GlobalTermsProvider()["SystemName"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); row.Cells[ColumnHours.Index].Style.BackColor = Color.Red; return(false); } if (!Lifelength.ValidateCyclesOrDays((string)row.Cells[ColumnCycles.Index].Value)) { MessageBox.Show("Invalid value for cycles parameter", new GlobalTermsProvider()["SystemName"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); row.Cells[ColumnCycles.Index].Style.BackColor = Color.Red; return(false); } } } return(true); }
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 }