1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Xml;
|
---|
6 | using HeuristicLab.DataImporter.Data;
|
---|
7 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
8 | using HeuristicLab.DataImporter.Data.Model;
|
---|
9 | using HeuristicLab.DataImporter.Command.View;
|
---|
10 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
11 | using System.Drawing;
|
---|
12 |
|
---|
13 | namespace 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 | }
|
---|