#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using HeuristicLab.DataImporter.Data; namespace HeuristicLab.DataImporter.Command.View { public partial class TimeBasedCommandView : HeuristicLab.DataImporter.Data.CommandBase.CommandViewBase { private TimeBasedCommandView() { InitializeComponent(); cmbUnit.SelectedIndex = 0; frequency = new DateTimeSpan(); frequency.Seconds = 1; startTime = DateTime.Now; txtStartTime.Text = startTime.ToString(); UpdateCommand(); } public TimeBasedCommandView(EquidistantTimeSeriesCommandBase command) : this() { this.Command = command; } public new EquidistantTimeSeriesCommandBase Command { get { return (EquidistantTimeSeriesCommandBase)base.Command; } set { base.Command = value; this.UpdateCommand(); } } private DateTimeSpan frequency; public DateTimeSpan SampleFrequency { get { return this.frequency; } } private DateTime startTime; public DateTime StartTime { get { return this.startTime; } } private void txtFrequency_Validating(object sender, CancelEventArgs e) { int value; if (!Int32.TryParse(txtFrequency.Text, out value)) e.Cancel = true; else if (value <= 0) e.Cancel = true; if (e.Cancel) MessageBox.Show("A numeric positive value must be entered!"); else CalculateNewFrequency(); } private void UpdateCommand() { if(this.Command != null) { this.Command.StartTime = this.startTime; this.Command.SampleFrequency = this.SampleFrequency; } } private void txtStartTime_Validating(object sender, CancelEventArgs e) { if (!DateTime.TryParse(txtStartTime.Text, out startTime)) { e.Cancel = true; MessageBox.Show("A date value must be entered (e.g. " + DateTime.Now.ToString() + ")."); } else this.UpdateCommand(); } private void cmbUnit_SelectedIndexChanged(object sender, EventArgs e) { CalculateNewFrequency(); } private void CalculateNewFrequency() { int value = Int32.Parse(txtFrequency.Text); frequency = new DateTimeSpan(); switch (cmbUnit.SelectedIndex) { case 0: frequency.Seconds = value; break; case 1: frequency.Minutes = value; break; case 2: frequency.Hours = value; break; case 3: frequency.Days = value; break; case 4: frequency.Months = value; break; case 5: frequency.Years = value; break; } this.UpdateCommand(); } } }