Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/NumericRangeControl.cs @ 17405

Last change on this file since 17405 was 17405, checked in by dpiringe, 4 years ago

#3026:

  • added a new way to setup the targeted result types
  • added new ui controls: NumericRangeControl, JsonItemArrayControl, JsonItemDefaultControl
  • redesigned export dialog -> now the user can navigate with a tree view
  • enhanced JsonItemVM
File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10using System.Globalization;
11
12namespace HeuristicLab.JsonInterface.OptimizerIntegration.Shared {
13  public partial class NumericRangeControl : UserControl {
14
15    private JsonItemVM vm;
16    public JsonItemVM VM {
17      get => vm;
18      set {
19        vm = value;
20        Init();
21      }
22    }
23    public bool IsDouble { get; set; }
24
25
26
27    public NumericRangeControl() {
28      InitializeComponent();
29      Init();
30    }
31
32    private void Init() {
33      textBoxFrom.Text = "";
34      textBoxTo.Text = "";
35      textBoxFrom.ReadOnly = true;
36      textBoxTo.ReadOnly = true;
37      checkBoxFrom.Checked = false;
38      checkBoxFrom.Checked = false;
39    }
40   
41    private void checkBoxFrom_CheckStateChanged(object sender, EventArgs e) {
42      textBoxFrom.ReadOnly = !checkBoxFrom.Checked;
43      textBoxFrom.Text = "";
44      if(!checkBoxFrom.Checked)
45        SetRange();
46    }
47
48    private void checkBoxTo_CheckStateChanged(object sender, EventArgs e) {
49      textBoxTo.ReadOnly = !checkBoxTo.Checked;
50      textBoxTo.Text = "";
51      if (!checkBoxTo.Checked)
52        SetRange();
53    }
54
55    private void textBoxFrom_Leave(object sender, EventArgs e) {
56      if (checkBoxFrom.Checked)
57        SetRange();
58    }
59
60    private void textBoxTo_Leave(object sender, EventArgs e) {
61      if (checkBoxTo.Checked)
62        SetRange();
63    }
64
65    private void SetRange() {
66      object[] range = new object[2];
67      if (checkBoxFrom.Checked && !string.IsNullOrWhiteSpace(textBoxFrom.Text))
68        range[0] = Parse(textBoxFrom.Text);
69      else
70        range[0] = IsDouble ? double.MinValue : int.MinValue;
71
72      if (checkBoxTo.Checked && !string.IsNullOrWhiteSpace(textBoxTo.Text))
73        range[1] = Parse(textBoxTo.Text);
74      else
75        range[1] = IsDouble ? double.MinValue : int.MinValue;
76      VM.Item.Range = range;
77    }
78
79    private object Parse(string s) {
80      if (IsDouble) {
81        return double.Parse(s.Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture);
82      }
83      return int.Parse(s);
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.