Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • deleted INamedMatrixJsonItem and all corresponding classes/views, because of bad design
  • added ILookupJsonItem and IValueLookupJsonItem (incl. all corresponding implementations, VMs, Views)
  • added IResultJsonItem
  • changed type of property Control from JsonItemBaseControl to UserControl in IJsonItemVM (because the details control now builds up with linked user controls -> allows better construction of dynamic controls)
  • added all properties of INamedMatrixJsonItem in IMatrixJsonItem
  • refactored a lot of views for better usage (TableLayoutPanel is used a lot now -> for better item positioning)
  • property ActualName is now located in ILookupJsonItem instead of IJsonItem
File size: 2.5 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.MinRange));
61      NumericRangeControl.TBMaxRange.DataBindings.Add("Text", VM, nameof(RangedValueBaseVM.MaxRange));
62      NumericRangeControl.EnableMinRange.DataBindings.Add("Checked", VM, nameof(RangedValueBaseVM.EnableMinRange),
63        false, DataSourceUpdateMode.OnPropertyChanged);
64      NumericRangeControl.EnableMaxRange.DataBindings.Add("Checked", VM, nameof(RangedValueBaseVM.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.