[17405] | 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 |
|
---|
[17410] | 12 | namespace HeuristicLab.JsonInterface.OptimizerIntegration {
|
---|
[17405] | 13 | public partial class NumericRangeControl : UserControl {
|
---|
[17411] | 14 | public TextBox TBMinRange { get; set; }
|
---|
| 15 | public TextBox TBMaxRange { get; set; }
|
---|
| 16 | public CheckBox EnableMinRange { get; set; }
|
---|
| 17 | public CheckBox EnableMaxRange { get; set; }
|
---|
[17843] | 18 |
|
---|
| 19 | private NumericRangeControl() {
|
---|
[17405] | 20 | InitializeComponent();
|
---|
[17843] | 21 | Init();
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | protected NumericRangeControl(IJsonItemVM vm) {
|
---|
| 25 | InitializeComponent();
|
---|
| 26 | Init();
|
---|
| 27 | TBMinRange.DataBindings.Add("Text", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.MinRange));
|
---|
| 28 | TBMaxRange.DataBindings.Add("Text", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.MaxRange));
|
---|
| 29 | EnableMinRange.DataBindings.Add("Checked", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMinRange),
|
---|
| 30 | false, DataSourceUpdateMode.OnPropertyChanged);
|
---|
| 31 | EnableMaxRange.DataBindings.Add("Checked", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMaxRange),
|
---|
| 32 | false, DataSourceUpdateMode.OnPropertyChanged);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | private void Init() {
|
---|
[17411] | 37 | TBMinRange = textBoxFrom;
|
---|
| 38 | TBMaxRange = textBoxTo;
|
---|
| 39 | EnableMinRange = checkBoxFrom;
|
---|
| 40 | EnableMaxRange = checkBoxTo;
|
---|
| 41 | checkBoxFrom.CheckedChanged += ToggleFromInput;
|
---|
| 42 | checkBoxTo.CheckedChanged += ToggleToInput;
|
---|
[17405] | 43 | }
|
---|
| 44 |
|
---|
[17411] | 45 | private void ToggleToInput(object sender, EventArgs e) {
|
---|
[17405] | 46 | textBoxTo.ReadOnly = !checkBoxTo.Checked;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[17411] | 49 | private void ToggleFromInput(object sender, EventArgs e) {
|
---|
| 50 | textBoxFrom.ReadOnly = !checkBoxFrom.Checked;
|
---|
[17405] | 51 | }
|
---|
[17444] | 52 |
|
---|
| 53 | private void textBoxFrom_Validating(object sender, CancelEventArgs e) {
|
---|
| 54 | if (string.IsNullOrWhiteSpace(textBoxFrom.Text)) {
|
---|
| 55 | errorProvider.SetError(textBoxFrom, "'From' must not be empty.");
|
---|
| 56 | e.Cancel = true;
|
---|
| 57 | } else {
|
---|
| 58 | errorProvider.SetError(textBoxFrom, null);
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | private void textBoxTo_Validating(object sender, CancelEventArgs e) {
|
---|
| 63 | if (string.IsNullOrWhiteSpace(textBoxTo.Text)) {
|
---|
| 64 | errorProvider.SetError(textBoxTo, "'To' must not be empty.");
|
---|
| 65 | e.Cancel = true;
|
---|
| 66 | } else {
|
---|
| 67 | errorProvider.SetError(textBoxTo, null);
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
[17828] | 70 |
|
---|
[17843] | 71 | public static UserControl Create(IJsonItemVM vm) => new NumericRangeControl(vm);
|
---|
[17405] | 72 | }
|
---|
| 73 | }
|
---|