Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/View/TimeBasedCommandView.cs @ 11152

Last change on this file since 11152 was 9615, checked in by mkommend, 11 years ago

#1734: Updated copyright information in all DataImporter classes.

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