1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Forms;
|
---|
6 | using System.Xml;
|
---|
7 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
8 | using HeuristicLab.DataImporter.Data.Model;
|
---|
9 | using HeuristicLab.DataImporter.Data;
|
---|
10 | using HeuristicLab.DataImporter.Command.View;
|
---|
11 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.DataImporter.Command {
|
---|
14 | [StorableClass]
|
---|
15 | [ViewableCommandInfoAttribute("Set Part of DateTime", 1, ColumnGroupState.DateTimeColumnSelected, "Time Series",
|
---|
16 | Position = 2, SelectedColumns = 1, OptionsView = typeof(TimeBasedWithoutOffsetCommandView))]
|
---|
17 | public class SetPartOfDateTimeCommand : ColumnGroupCommandWithAffectedColumnsBase {
|
---|
18 | private DateTimeColumn oldColumn;
|
---|
19 | private ICollection<int> oldSortedColumnIndices;
|
---|
20 | private IEnumerable<SortOrder> oldSortOrder;
|
---|
21 |
|
---|
22 | private SetPartOfDateTimeCommand()
|
---|
23 | : base(null, string.Empty, null) {
|
---|
24 | }
|
---|
25 |
|
---|
26 | public SetPartOfDateTimeCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
|
---|
27 | : base(dataSet, columnGroupName, affectedColumns) {
|
---|
28 | }
|
---|
29 |
|
---|
30 | [Storable]
|
---|
31 | private DateTimeSpan dateTimePart;
|
---|
32 | public DateTimeSpan DateTimePart {
|
---|
33 | get { return this.dateTimePart; }
|
---|
34 | set { this.dateTimePart = value; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | public override string Description {
|
---|
38 | get { return "Set specific part of datetime"; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public override void Execute() {
|
---|
42 | base.Execute();
|
---|
43 | oldColumn = (DateTimeColumn)ColumnGroup.GetColumn(AffectedColumns[0]);
|
---|
44 | DateTimeColumn newColumn = (DateTimeColumn)oldColumn.CreateCopyOfColumnWithoutValues();
|
---|
45 | DateTime? value;
|
---|
46 | DateTimeSpan newValue;
|
---|
47 | oldSortedColumnIndices = new List<int>(ColumnGroup.SortedColumnIndexes);
|
---|
48 | oldSortOrder = ColumnGroup.SortOrdersForColumns.ToList();
|
---|
49 |
|
---|
50 | for (int i = 0; i < oldColumn.TotalValuesCount; i++) {
|
---|
51 | newValue = (DateTimeSpan)dateTimePart.Clone();
|
---|
52 | value = (DateTime?)oldColumn.GetValue(i);
|
---|
53 | if (value != null) {
|
---|
54 | if (newValue.Seconds == -1)
|
---|
55 | newValue.Seconds = value.Value.Second;
|
---|
56 | if (newValue.Minutes == -1)
|
---|
57 | newValue.Minutes = value.Value.Minute;
|
---|
58 | if (newValue.Hours == -1)
|
---|
59 | newValue.Hours = value.Value.Hour;
|
---|
60 | if (newValue.Days == -1)
|
---|
61 | newValue.Days = value.Value.Day;
|
---|
62 | if (newValue.Months == -1)
|
---|
63 | newValue.Months = value.Value.Month;
|
---|
64 | if (newValue.Years == -1)
|
---|
65 | newValue.Years = value.Value.Year;
|
---|
66 |
|
---|
67 | newColumn.AddValue(new DateTime(newValue.Years, newValue.Months, newValue.Days, newValue.Hours, newValue.Minutes, newValue.Seconds));
|
---|
68 | } else
|
---|
69 | newColumn.AddValue(null);
|
---|
70 | }
|
---|
71 | ColumnGroup.ReplaceColumn(AffectedColumns[0], newColumn);
|
---|
72 | ColumnGroup.FireChanged();
|
---|
73 | this.ColumnGroup = null;
|
---|
74 | }
|
---|
75 |
|
---|
76 | public override void UndoExecute() {
|
---|
77 | base.UndoExecute();
|
---|
78 | ColumnGroup.ReplaceColumn(AffectedColumns[0], oldColumn);
|
---|
79 | ColumnGroup.SortOrdersForColumns = oldSortOrder;
|
---|
80 | ColumnGroup.SortedColumnIndexes = oldSortedColumnIndices;
|
---|
81 | oldSortedColumnIndices = null;
|
---|
82 | oldSortOrder = null;
|
---|
83 | oldColumn = null;
|
---|
84 | ColumnGroup.FireChanged();
|
---|
85 | this.ColumnGroup = null;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|