1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Threading.Tasks;
|
---|
9 | using System.Windows.Forms;
|
---|
10 | using System.Globalization;
|
---|
11 |
|
---|
12 | namespace 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 | }
|
---|