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 |
|
---|
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 | }
|
---|