Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeValues/DeleteRowsWithGivenValueCommand.cs @ 6133

Last change on this file since 6133 was 6133, checked in by gkronber, 13 years ago

#1471: imported generic parts of DataImporter from private code base

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Xml;
6using HeuristicLab.DataImporter.Data;
7using HeuristicLab.DataImporter.Data.CommandBase;
8using HeuristicLab.DataImporter.Data.Model;
9using HeuristicLab.DataImporter.Command.View;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11using System.Drawing;
12
13namespace HeuristicLab.DataImporter.Command {
14  [StorableClass]
15  [ViewableCommandInfoAttribute("Search and Remove Rows", 1, ColumnGroupState.ColumnSelected, "Change Values",
16    Position = 1, OptionsView = typeof(SearchWithMatchOperationCommandView))]
17  public class DeleteRowsWithGivenValueCommand : SearchWithMatchOperationCommandBase {
18    private Dictionary<int, IComparable[]> deletedRows;
19
20    private DeleteRowsWithGivenValueCommand()
21      : base(null, string.Empty, null) {
22      deletedRows = new Dictionary<int, IComparable[]>();
23    }
24
25    public DeleteRowsWithGivenValueCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
26      : base(dataSet, columnGroupName, affectedColumns) {
27      deletedRows = new Dictionary<int, IComparable[]>();
28    }
29
30    public override string Description {
31      get { return "Delete rows which match given value"; }
32    }
33
34    public override void Execute() {
35      base.Execute();
36      Point[] affectedCells = this.GetAffectedCells();
37      int[] rows = affectedCells.Select(c => c.Y).Distinct().OrderBy(x => x).Reverse().ToArray();
38
39      foreach (int rowIndex in rows) {
40        deletedRows[rowIndex] = ColumnGroup.GetRow(rowIndex);
41        ColumnGroup.DeleteRow(rowIndex);
42      }
43      ColumnGroup.FireChanged();
44      ColumnGroup = null;
45    }
46
47    public override void UndoExecute() {
48      base.UndoExecute();
49      foreach (KeyValuePair<int, IComparable[]> row in deletedRows.OrderBy(x => x.Key))
50        ColumnGroup.InsertRow(row.Key, row.Value);
51      deletedRows.Clear();
52      ColumnGroup.FireChanged();
53      ColumnGroup = null;
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.