/// <summary> /// Reflects changes in Excel worksheet if this row has just been modified. /// </summary> private void ReflectChangesForModifiedRow() { if (RowState == DataRowState.Added && ExcelRange != null) { // A recently added row's value is being modified, we just need to re-paint the whole "added" row. ExcelRange.SetInteriorColor(ExcelUtilities.UncommittedCellsOleColor); } if (RowState != DataRowState.Modified) { return; } if (ExcelRange != null) { ExcelModifiedRangesList.Clear(); } ChangedColumnNames.Clear(); // Check column by column for data changes, set related Excel cells color accordingly. for (int colIndex = 0; colIndex < Table.Columns.Count; colIndex++) { ExcelInterop.Range columnCell = ExcelRange != null ? ExcelRange.Cells[1, colIndex + 1] : null; bool originalAndModifiedIdentical = this[colIndex].Equals(this[colIndex, DataRowVersion.Original]); if (!originalAndModifiedIdentical) { if (columnCell != null) { ExcelModifiedRangesList.Add(columnCell); } ChangedColumnNames.Add(Table.Columns[colIndex].ColumnName); } if (columnCell == null) { continue; } var cellColor = originalAndModifiedIdentical ? _excelRangePreviousColors[colIndex] : ExcelUtilities.UncommittedCellsOleColor; columnCell.SetInteriorColor(cellColor); } // If the row resulted with no modifications (maybe some values set back to their original values by the user) then undo changes. if (ChangedColumnNames.Count == 0) { RejectChanges(); } }
/// <summary> /// Reflects changes in Excel worksheet if this row has just been commited. /// </summary> private void ReflectChangesForCommittedRow() { if (!IsBeingDeleted && ExcelRange != null) { ExcelModifiedRangesList.SetInteriorColor(ExcelUtilities.CommitedCellsOleColor); SaveCurrentColor(ExcelUtilities.CommitedCellsOleColor); if (!HasErrors) { ExcelModifiedRangesList.Clear(); } } if (!HasErrors) { ChangedColumnNames.Clear(); } }
/// <summary> /// Reflects changes in Excel worksheet if this row has just been rolled back. /// </summary> private void ReflectChangesForRolledbackRow() { if (!IsBeingDeleted) { for (int colIndex = 0; colIndex < Table.Columns.Count; colIndex++) { ExcelInterop.Range columnCell = ExcelRange != null ? ExcelRange.Cells[1, colIndex + 1] : null; if (columnCell == null) { continue; } columnCell.SetInteriorColor(_excelRangePreviousColors[colIndex]); } ExcelModifiedRangesList.Clear(); } ChangedColumnNames.Clear(); IsBeingDeleted = false; }