Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/View/TimeBasedWithoutOffsetCommandView.cs @ 15694

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

#1734: Updated copyright information in all DataImporter classes.

File size: 3.5 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 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}
Note: See TracBrowser for help on using the repository browser.