Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 16994 was 16994, checked in by gkronber, 5 years ago

#2520 Update plugin dependencies and references for HL.DataImporter for new persistence

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