[6134] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2011 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 |
|
---|
| 22 | using System;
|
---|
[6133] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Data;
|
---|
| 26 | using System.Drawing;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
| 29 | using HeuristicLab.DataImporter.Data;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.DataImporter.Command.View {
|
---|
| 32 | public partial class TimeBasedWithoutOffsetCommandView : HeuristicLab.DataImporter.Data.CommandBase.CommandViewBase {
|
---|
| 33 | private TimeBasedWithoutOffsetCommandView() {
|
---|
| 34 | InitializeComponent();
|
---|
| 35 | dateTimePart = new DateTimeSpan();
|
---|
| 36 | CalculateNewDateTimePart();
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public TimeBasedWithoutOffsetCommandView(SetPartOfDateTimeCommand command) :this() {
|
---|
| 40 | this.Command = command;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | public new SetPartOfDateTimeCommand Command {
|
---|
| 44 | get { return (SetPartOfDateTimeCommand)base.Command; }
|
---|
| 45 | set { base.Command = value; this.UpdateCommand(); }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | private DateTimeSpan dateTimePart;
|
---|
| 49 | public DateTimeSpan DateTimePart {
|
---|
| 50 | get { return Command.DateTimePart; }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | private void txtDateTimePart_Validating(object sender, CancelEventArgs e) {
|
---|
| 55 | TextBox textBox = (TextBox) sender;
|
---|
| 56 | int value;
|
---|
| 57 | if (string.IsNullOrEmpty(textBox.Text))
|
---|
| 58 | e.Cancel = false;
|
---|
| 59 | else if (!Int32.TryParse(textBox.Text, out value))
|
---|
| 60 | e.Cancel = true;
|
---|
| 61 | else if (value < 0)
|
---|
| 62 | e.Cancel = true;
|
---|
| 63 |
|
---|
| 64 | if (e.Cancel)
|
---|
| 65 | MessageBox.Show("A numeric positive value or 0 must be entered!");
|
---|
| 66 | else
|
---|
| 67 | CalculateNewDateTimePart();
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | private void CalculateNewDateTimePart() {
|
---|
| 71 | if (!string.IsNullOrEmpty(txtSeconds.Text))
|
---|
| 72 | dateTimePart.Seconds = Int32.Parse(txtSeconds.Text);
|
---|
| 73 | else
|
---|
| 74 | dateTimePart.Seconds = -1;
|
---|
| 75 |
|
---|
| 76 | if (!string.IsNullOrEmpty(txtMinutes.Text))
|
---|
| 77 | dateTimePart.Minutes = Int32.Parse(txtMinutes.Text);
|
---|
| 78 | else
|
---|
| 79 | dateTimePart.Minutes = -1;
|
---|
| 80 |
|
---|
| 81 | if (!string.IsNullOrEmpty(txtHours.Text))
|
---|
| 82 | dateTimePart.Hours = Int32.Parse(txtHours.Text);
|
---|
| 83 | else
|
---|
| 84 | dateTimePart.Hours = -1;
|
---|
| 85 |
|
---|
| 86 | if (!string.IsNullOrEmpty(txtDays.Text))
|
---|
| 87 | dateTimePart.Days = Int32.Parse(txtDays.Text);
|
---|
| 88 | else
|
---|
| 89 | dateTimePart.Days = -1;
|
---|
| 90 |
|
---|
| 91 | if (!string.IsNullOrEmpty(txtMonths.Text))
|
---|
| 92 | dateTimePart.Months = Int32.Parse(txtMonths.Text);
|
---|
| 93 | else
|
---|
| 94 | dateTimePart.Months = -1;
|
---|
| 95 |
|
---|
| 96 | if (!string.IsNullOrEmpty(txtYears.Text))
|
---|
| 97 | dateTimePart.Years = Int32.Parse(txtYears.Text);
|
---|
| 98 | else
|
---|
| 99 | dateTimePart.Years = -1;
|
---|
| 100 |
|
---|
| 101 | this.UpdateCommand();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | private void UpdateCommand() {
|
---|
| 105 | if (this.Command != null) {
|
---|
| 106 | Command.DateTimePart = this.dateTimePart;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 | }
|
---|