Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemRangeControl.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.0 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 {
13  public partial class JsonItemRangeControl : JsonItemBaseControl {
14    bool isDouble = false;
15    object[] range = new object[2];
16    object[] value = new object[2];
17
18    public JsonItemRangeControl(JsonItemVM vm, bool isDouble) : base(vm) {
19      InitializeComponent();
20      this.isDouble = isDouble;
21      textBoxValueFrom.Text = ((Array)VM.Item.Value).GetValue(0).ToString();
22      textBoxValueTo.Text = ((Array)VM.Item.Value).GetValue(1).ToString();
23      textBoxValueFrom.Text = VM.Item.Range.First().ToString();
24      textBoxValueTo.Text = VM.Item.Range.Last().ToString();
25    }
26
27    private object Parse(string s) {
28      if (isDouble) {
29        if (s == "-1,79769313486232E+308") return double.MinValue;
30        if (s == "1,79769313486232E+308") return double.MaxValue;
31        return double.Parse(s.Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture);
32      }
33      return int.Parse(s);
34    }
35
36    private void SetValue() {
37      if (!string.IsNullOrWhiteSpace(textBoxValueFrom.Text))
38        value[0] = Parse(textBoxValueFrom.Text);
39      else
40        value[0] = ((Array)VM.Item.Value).GetValue(0);
41
42      if (!string.IsNullOrWhiteSpace(textBoxValueTo.Text))
43        value[1] = Parse(textBoxValueTo.Text);
44      else
45        value[1] = ((Array)VM.Item.Value).GetValue(1);
46      VM.Item.Value = value;
47    }
48   
49    private void textBoxValueFrom_Leave(object sender, EventArgs e) {
50      SetValue();
51    }
52
53    private void textBoxValueTo_Leave(object sender, EventArgs e) {
54      SetValue();
55    }
56
57    private void numericRangeControl1_Load(object sender, EventArgs e) {
58      numericRangeControl1.IsDouble = isDouble;
59      numericRangeControl1.VM = VM;
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.