Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValueControl.cs @ 17530

Last change on this file since 17530 was 17473, checked in by dpiringe, 5 years ago

#3026:

  • refactored inheritance structure of json items, now the default JsonItem is an abstract class without properties Value and Range -> splitted up into new interfaces
  • updated view models for new json item structure
  • updated SingleLineArrayJsonWriter
File size: 2.6 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 
14  public class JsonItemIntValueControl : JsonItemValueControl {
15   
16    #region Overriden Properties
17    protected override string ValuePropertyId => nameof(IntValueVM.Value);
18    #endregion
19   
20    public JsonItemIntValueControl(IntValueVM vm) : base(vm) {
21      Init();
22    }
23  }
24
25  public class JsonItemDoubleValueControl : JsonItemValueControl {
26   
27    #region Overriden Properties
28    protected override string ValuePropertyId => nameof(DoubleValueVM.Value);
29    #endregion
30   
31    public JsonItemDoubleValueControl(DoubleValueVM vm) : base(vm) {
32      Init();
33    }
34  }
35 
36  public abstract partial class JsonItemValueControl : UserControl {
37    #region Protected Properties
38    protected IJsonItemVM VM { get; set; }
39    protected TextBox TBValue { get; set; }
40    protected NumericRangeControl NumericRangeControl { get; set; }
41    #endregion
42
43    #region Abstract Properties
44    protected abstract string ValuePropertyId { get; }
45    #endregion
46
47    public JsonItemValueControl() {
48      InitializeComponent();
49    }
50
51    public JsonItemValueControl(IJsonItemVM vm) {
52      InitializeComponent();
53      VM = vm;
54      TBValue = textBoxValue;
55      NumericRangeControl = numericRangeControl1;
56    }
57   
58    protected void Init() {
59      TBValue.DataBindings.Add("Text", VM, ValuePropertyId);
60      NumericRangeControl.TBMinRange.DataBindings.Add("Text", VM, nameof(RangedValueBaseVM<int, IntJsonItem>.MinRange));
61      NumericRangeControl.TBMaxRange.DataBindings.Add("Text", VM, nameof(RangedValueBaseVM<int, IntJsonItem>.MaxRange));
62      NumericRangeControl.EnableMinRange.DataBindings.Add("Checked", VM, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMinRange),
63        false, DataSourceUpdateMode.OnPropertyChanged);
64      NumericRangeControl.EnableMaxRange.DataBindings.Add("Checked", VM, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMaxRange),
65        false, DataSourceUpdateMode.OnPropertyChanged);
66    }
67
68    private void textBoxValue_Validating(object sender, CancelEventArgs e) {
69      if (string.IsNullOrWhiteSpace(textBoxValue.Text)) {
70        errorProvider.SetError(textBoxValue, "Value must not be empty.");
71        e.Cancel = true;
72      } else {
73        errorProvider.SetError(textBoxValue, null);
74      }
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.