#region License Information /* HeuristicLab * Copyright (C) 2002-2011 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 TimeBasedWithoutOffsetCommandView : HeuristicLab.DataImporter.Data.CommandBase.CommandViewBase { private TimeBasedWithoutOffsetCommandView() { InitializeComponent(); dateTimePart = new DateTimeSpan(); CalculateNewDateTimePart(); } public TimeBasedWithoutOffsetCommandView(SetPartOfDateTimeCommand command) :this() { this.Command = command; } public new SetPartOfDateTimeCommand Command { get { return (SetPartOfDateTimeCommand)base.Command; } set { base.Command = value; this.UpdateCommand(); } } private DateTimeSpan dateTimePart; public DateTimeSpan DateTimePart { get { return Command.DateTimePart; } } private void txtDateTimePart_Validating(object sender, CancelEventArgs e) { TextBox textBox = (TextBox) sender; int value; if (string.IsNullOrEmpty(textBox.Text)) e.Cancel = false; else if (!Int32.TryParse(textBox.Text, out value)) e.Cancel = true; else if (value < 0) e.Cancel = true; if (e.Cancel) MessageBox.Show("A numeric positive value or 0 must be entered!"); else CalculateNewDateTimePart(); } private void CalculateNewDateTimePart() { if (!string.IsNullOrEmpty(txtSeconds.Text)) dateTimePart.Seconds = Int32.Parse(txtSeconds.Text); else dateTimePart.Seconds = -1; if (!string.IsNullOrEmpty(txtMinutes.Text)) dateTimePart.Minutes = Int32.Parse(txtMinutes.Text); else dateTimePart.Minutes = -1; if (!string.IsNullOrEmpty(txtHours.Text)) dateTimePart.Hours = Int32.Parse(txtHours.Text); else dateTimePart.Hours = -1; if (!string.IsNullOrEmpty(txtDays.Text)) dateTimePart.Days = Int32.Parse(txtDays.Text); else dateTimePart.Days = -1; if (!string.IsNullOrEmpty(txtMonths.Text)) dateTimePart.Months = Int32.Parse(txtMonths.Text); else dateTimePart.Months = -1; if (!string.IsNullOrEmpty(txtYears.Text)) dateTimePart.Years = Int32.Parse(txtYears.Text); else dateTimePart.Years = -1; this.UpdateCommand(); } private void UpdateCommand() { if (this.Command != null) { Command.DateTimePart = this.dateTimePart; } } } }