Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.MainForm.WindowsForms/3.3/Dialogs/DefineArithmeticProgressionDialog.cs @ 15318

Last change on this file since 15318 was 14186, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Collections.Generic;
23using System.ComponentModel;
24using System.Globalization;
25using System.Windows.Forms;
26using HeuristicLab.Common;
27
28namespace HeuristicLab.MainForm.WindowsForms {
29  public partial class DefineArithmeticProgressionDialog : Form {
30    private bool allowOnlyInteger;
31
32    public decimal Minimum { get; private set; }
33    public decimal Maximum { get; private set; }
34    public decimal Step { get; private set; }
35
36    public IEnumerable<decimal> Values {
37      get { return SequenceGenerator.GenerateSteps(Minimum, Maximum, Step, includeEnd: true); }
38    }
39
40    public DefineArithmeticProgressionDialog() {
41      InitializeComponent();
42      Icon = HeuristicLab.Common.Resources.HeuristicLab.Icon;
43      Minimum = 0; Maximum = 100; Step = 10;
44    }
45    public DefineArithmeticProgressionDialog(bool allowOnlyInteger)
46      : this() {
47      this.allowOnlyInteger = allowOnlyInteger;
48    }
49    public DefineArithmeticProgressionDialog(bool allowOnlyInteger, decimal minimum, decimal maximum, decimal step)
50      : this(allowOnlyInteger) {
51      Minimum = minimum;
52      Maximum = maximum;
53      Step = step;
54    }
55
56    private void DefineArithmeticProgressionDialog_Load(object sender, System.EventArgs e) {
57      minimumTextBox.Text = Minimum.ToString();
58      maximumTextBox.Text = Maximum.ToString();
59      stepSizeTextBox.Text = Step.ToString();
60    }
61
62    private void textBox_Validating(object sender, CancelEventArgs e) {
63      var textBox = (TextBox)sender;
64      decimal value = 0;
65      if (allowOnlyInteger) {
66        int intValue;
67        if (!int.TryParse(textBox.Text, out intValue)) {
68          errorProvider.SetError(textBox, "Please enter a valid integer value.");
69          e.Cancel = true;
70          return;
71        } else {
72          value = intValue;
73          errorProvider.SetError(textBox, null);
74        }
75      } else {
76        if (!decimal.TryParse(textBox.Text, NumberStyles.Float, CultureInfo.CurrentCulture.NumberFormat, out value)) {
77          errorProvider.SetError(textBox, "Please enter a valid double value.");
78          e.Cancel = true;
79          return;
80        } else errorProvider.SetError(textBox, null);
81      }
82      if (textBox == minimumTextBox) Minimum = value;
83      else if (textBox == maximumTextBox) Maximum = value;
84      else if (textBox == stepSizeTextBox) Step = value;
85      okButton.Enabled = IsValid();
86    }
87
88    private bool IsValid() {
89      return Minimum <= Maximum && Step >= 0;
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.