Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/View/TimeBasedCommandView.cs

Last change on this file was 16994, checked in by gkronber, 5 years ago

#2520 Update plugin dependencies and references for HL.DataImporter for new persistence

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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
22using System;
23using System.ComponentModel;
24using System.Windows.Forms;
25using HeuristicLab.DataImporter.Data;
26
27namespace HeuristicLab.DataImporter.Command.View {
28  public partial class TimeBasedCommandView : HeuristicLab.DataImporter.Data.CommandBase.CommandViewBase {
29    private TimeBasedCommandView() {
30      InitializeComponent();
31      cmbUnit.SelectedIndex = 0;
32      frequency = new DateTimeSpan();
33      frequency.Seconds = 1;
34      startTime = DateTime.Now;
35      txtStartTime.Text = startTime.ToString();
36      UpdateCommand();
37    }
38
39    public TimeBasedCommandView(EquidistantTimeSeriesCommandBase command)
40      : this() {
41      this.Command = command;
42    }
43
44    public new EquidistantTimeSeriesCommandBase Command {
45      get { return (EquidistantTimeSeriesCommandBase)base.Command; }
46      set { base.Command = value; this.UpdateCommand(); }
47    }
48
49    private DateTimeSpan frequency;
50    public DateTimeSpan SampleFrequency {
51      get { return this.frequency; }
52    }
53
54    private DateTime startTime;
55    public DateTime StartTime {
56      get { return this.startTime; }
57    }
58
59    private void txtFrequency_Validating(object sender, CancelEventArgs e) {
60      int value;
61      if (!Int32.TryParse(txtFrequency.Text, out value))
62        e.Cancel = true;
63      else if (value <= 0)
64        e.Cancel = true;
65
66      if (e.Cancel)
67        MessageBox.Show("A numeric positive value must be entered!");
68      else
69        CalculateNewFrequency();
70    }
71
72    private void UpdateCommand() {
73      if(this.Command != null) {
74        this.Command.StartTime = this.startTime;
75        this.Command.SampleFrequency = this.SampleFrequency;
76      }
77    }
78
79    private void txtStartTime_Validating(object sender, CancelEventArgs e) {
80      if (!DateTime.TryParse(txtStartTime.Text, out startTime)) {
81        e.Cancel = true;
82        MessageBox.Show("A date value must be entered (e.g. " + DateTime.Now.ToString() + ").");
83      } else
84        this.UpdateCommand();
85    }
86
87    private void cmbUnit_SelectedIndexChanged(object sender, EventArgs e) {
88      CalculateNewFrequency();
89    }
90
91    private void CalculateNewFrequency() {
92      int value = Int32.Parse(txtFrequency.Text);
93      frequency = new DateTimeSpan();
94      switch (cmbUnit.SelectedIndex) {
95        case 0:
96          frequency.Seconds = value;
97          break;
98        case 1:
99          frequency.Minutes = value;
100          break;
101        case 2:
102          frequency.Hours = value;
103          break;
104        case 3:
105          frequency.Days = value;
106          break;
107        case 4:
108          frequency.Months = value;
109          break;
110        case 5:
111          frequency.Years = value;
112          break;
113      }
114      this.UpdateCommand();
115    }
116   
117  }
118}
Note: See TracBrowser for help on using the repository browser.