1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using System.Windows.Forms;
|
---|
27 | using System.Xml;
|
---|
28 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
29 | using HeuristicLab.DataImporter.Data.Model;
|
---|
30 | using HeuristicLab.DataImporter.Data;
|
---|
31 | using HeuristicLab.DataImporter.Command.View;
|
---|
32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.DataImporter.Command {
|
---|
35 | [StorableClass]
|
---|
36 | [ViewableCommandInfoAttribute("Set Part of DateTime", 1, ColumnGroupState.DateTimeColumnSelected, "Time Series",
|
---|
37 | Position = 2, SelectedColumns = 1, OptionsView = typeof(TimeBasedWithoutOffsetCommandView))]
|
---|
38 | public class SetPartOfDateTimeCommand : ColumnGroupCommandWithAffectedColumnsBase {
|
---|
39 | private DateTimeColumn oldColumn;
|
---|
40 | private ICollection<int> oldSortedColumnIndices;
|
---|
41 | private IEnumerable<SortOrder> oldSortOrder;
|
---|
42 |
|
---|
43 | private SetPartOfDateTimeCommand()
|
---|
44 | : base(null, string.Empty, null) {
|
---|
45 | }
|
---|
46 |
|
---|
47 | public SetPartOfDateTimeCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
|
---|
48 | : base(dataSet, columnGroupName, affectedColumns) {
|
---|
49 | }
|
---|
50 |
|
---|
51 | [Storable]
|
---|
52 | private DateTimeSpan dateTimePart;
|
---|
53 | public DateTimeSpan DateTimePart {
|
---|
54 | get { return this.dateTimePart; }
|
---|
55 | set { this.dateTimePart = value; }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public override string Description {
|
---|
59 | get { return "Set specific part of datetime"; }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public override void Execute() {
|
---|
63 | base.Execute();
|
---|
64 | oldColumn = (DateTimeColumn)ColumnGroup.GetColumn(AffectedColumns[0]);
|
---|
65 | DateTimeColumn newColumn = (DateTimeColumn)oldColumn.CreateCopyOfColumnWithoutValues();
|
---|
66 | DateTime? value;
|
---|
67 | DateTimeSpan newValue;
|
---|
68 | oldSortedColumnIndices = new List<int>(ColumnGroup.SortedColumnIndexes);
|
---|
69 | oldSortOrder = ColumnGroup.SortOrdersForColumns.ToList();
|
---|
70 |
|
---|
71 | for (int i = 0; i < oldColumn.TotalValuesCount; i++) {
|
---|
72 | newValue = (DateTimeSpan)dateTimePart.Clone();
|
---|
73 | value = (DateTime?)oldColumn.GetValue(i);
|
---|
74 | if (value != null) {
|
---|
75 | if (newValue.Seconds == -1)
|
---|
76 | newValue.Seconds = value.Value.Second;
|
---|
77 | if (newValue.Minutes == -1)
|
---|
78 | newValue.Minutes = value.Value.Minute;
|
---|
79 | if (newValue.Hours == -1)
|
---|
80 | newValue.Hours = value.Value.Hour;
|
---|
81 | if (newValue.Days == -1)
|
---|
82 | newValue.Days = value.Value.Day;
|
---|
83 | if (newValue.Months == -1)
|
---|
84 | newValue.Months = value.Value.Month;
|
---|
85 | if (newValue.Years == -1)
|
---|
86 | newValue.Years = value.Value.Year;
|
---|
87 |
|
---|
88 | newColumn.AddValue(new DateTime(newValue.Years, newValue.Months, newValue.Days, newValue.Hours, newValue.Minutes, newValue.Seconds));
|
---|
89 | } else
|
---|
90 | newColumn.AddValue(null);
|
---|
91 | }
|
---|
92 | ColumnGroup.ReplaceColumn(AffectedColumns[0], newColumn);
|
---|
93 | ColumnGroup.FireChanged();
|
---|
94 | this.ColumnGroup = null;
|
---|
95 | }
|
---|
96 |
|
---|
97 | public override void UndoExecute() {
|
---|
98 | base.UndoExecute();
|
---|
99 | ColumnGroup.ReplaceColumn(AffectedColumns[0], oldColumn);
|
---|
100 | ColumnGroup.SortOrdersForColumns = oldSortOrder;
|
---|
101 | ColumnGroup.SortedColumnIndexes = oldSortedColumnIndices;
|
---|
102 | oldSortedColumnIndices = null;
|
---|
103 | oldSortOrder = null;
|
---|
104 | oldColumn = null;
|
---|
105 | ColumnGroup.FireChanged();
|
---|
106 | this.ColumnGroup = null;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|