Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Dialogs/DefineArithmeticProgressionDialog.cs @ 12311

Last change on this file since 12311 was 12293, checked in by pfleck, 10 years ago

#2301 Use decimal instead of double for the DefineArithmeticProgressionDialog and in the CreateExperimentDialog.
Note, when using decimal only during the generate process but not during some calculations (e.g. determining meaningful step sizes), numeric inaccuracies occur.
Therefore some calculations now uses decimal instead of double values.

File size: 3.3 KB
RevLine 
[8975]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[8975]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
[12293]32    public decimal Minimum { get; private set; }
33    public decimal Maximum { get; private set; }
34    public decimal Step { get; private set; }
[8975]35
[12293]36    public IEnumerable<decimal> Values {
37      get { return SequenceGenerator.GenerateSteps(Minimum, Maximum, Step, includeEnd: true); }
[8975]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    }
[12293]49    public DefineArithmeticProgressionDialog(bool allowOnlyInteger, decimal minimum, decimal maximum, decimal step)
[8975]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;
[12293]64      decimal value = 0;
[8975]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 {
[12293]76        if (!decimal.TryParse(textBox.Text, NumberStyles.Float, CultureInfo.CurrentCulture.NumberFormat, out value)) {
[8975]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.