public GridOilView() { InitializeComponent(); AutoReplenished = true; AllowEditColumn = true; InitStyle(); undoRedoManager = new DataGridViewUndoRedoManager(this); }
/// <summary> /// 撤销修改值 /// </summary> /// <param name="dgv"></param> private void UndoRedoValues(DataGridViewUndoRedoManager manager, bool isUndo) { if (manager == null) { return; } var dgv = manager.GridView; if (dgv == null || Values == null || Values.Count == 0) { return; } foreach (var column in Values.GroupBy(o => o.ColumnIndex)) { Application.DoEvents(); var col = dgv.Columns[column.Key]; var col2 = col as GridOilColumnItem; if (col2 == null) { foreach (var cell in column) { dgv[cell.ColumnIndex, cell.RowIndex].Value = isUndo ? cell.OldValue : cell.NewValue; } } else { foreach (var e in column) { var cell = dgv[e.ColumnIndex, e.RowIndex] as GridOilCellItem; GridOilCellGroup cellGroup; if (cell == null) { cellGroup = new GridOilCellGroup(col2.Group, e.RowIndex, null); cellGroup.Bind(); switch (col2.Type) { case GridOilColumnType.Lab: cell = cellGroup.LabCell; break; case GridOilColumnType.Calc: cell = cellGroup.CalcCell; break; default: continue; } } cell.Value2 = isUndo ? e.OldValue : e.NewValue; } } } }
public IGridOilView() { InitializeComponent(); AutoReplenished = true; AllowEditColumn = true; InitStyle(); undoRedoManager = new DataGridViewUndoRedoManager(this); undoRedoManager.BusyStateChanged += undoRedoManager_BusyStateChanged; undoRedoManager.CanRedoChanged += (a, b) => needSave = true; undoRedoManager.CanUndoChanged += (a, b) => needSave = true; waitingPanel = new WaitingPanel(this); }
public void Redo(DataGridViewUndoRedoManager manager) { if (manager == null) { return; } var dgv = manager.GridView; if (dgv == null) { return; } manager.IsBusy = true; try { switch (CommandType) { case DataGridViewUndoRedoCommandType.ChangeValue: UndoRedoValues(manager, false); break; case DataGridViewUndoRedoCommandType.ChangeColumn: if (OldColumns != null && OldColumns.Count > 0) { OldColumns.ForEach(o => o.Remove()); } if (NewColumns != null && NewColumns.Count > 0) { NewColumns.ToList().ForEach(o => o.Insert(o.LastIndex)); } break; case DataGridViewUndoRedoCommandType.RemoveColumn: if (OldColumns != null && OldColumns.Count > 0) { OldColumns.ForEach(o => o.Remove()); } break; case DataGridViewUndoRedoCommandType.AddColumn: if (NewColumns != null && NewColumns.Count > 0) { NewColumns.ToList().ForEach(o => o.Insert(o.LastIndex)); } break; case DataGridViewUndoRedoCommandType.RemoveRow: if (Rows != null && Rows.Count > 0) { Rows.ForEach(o => dgv.Rows.Remove(o)); } break; case DataGridViewUndoRedoCommandType.AddRow: if (Rows != null && Rows.Count > 0) { Rows.OrderBy(o => o.Index).ToList().ForEach(o => dgv.Rows.Insert(o.Index, o)); } break; } } finally { manager.IsBusy = false; } }