Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Encodings.ScheduleEncoding.Views/3.3/TaskView.cs @ 17928

Last change on this file since 17928 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 5.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.ComponentModel;
24using System.Windows.Forms;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Encodings.ScheduleEncoding.Views {
29  [View("TaskView")]
30  [Content(typeof(Task))]
31  public partial class TaskView : ItemView {
32    protected bool SuppressEvents = false;
33
34    public new Task Content {
35      get { return (Task)base.Content; }
36      set { base.Content = value; }
37    }
38
39    public TaskView() {
40      InitializeComponent();
41    }
42
43    protected override void DeregisterContentEvents() {
44      Content.PropertyChanged -= Content_PropertyChanged;
45      base.DeregisterContentEvents();
46    }
47
48    protected override void RegisterContentEvents() {
49      base.RegisterContentEvents();
50      Content.PropertyChanged += Content_PropertyChanged;
51    }
52
53    protected override void OnContentChanged() {
54      base.OnContentChanged();
55      if (Content == null) {
56        taskNrTextBox.Text = String.Empty;
57        resourceNrTextBox.Text = String.Empty;
58        jobNrTextBox.Text = String.Empty;
59        durationTextBox.Text = String.Empty;
60      } else {
61        SuppressEvents = true;
62        try {
63          taskNrTextBox.Text = Content.TaskNr.ToString();
64          resourceNrTextBox.Text = Content.ResourceNr.ToString();
65          jobNrTextBox.Text = Content.JobNr.ToString();
66          durationTextBox.Text = Content.Duration.ToString();
67        } finally { SuppressEvents = false; }
68      }
69    }
70
71    protected override void SetEnabledStateOfControls() {
72      base.SetEnabledStateOfControls();
73      taskNrTextBox.Enabled = !ReadOnly && !Locked && Content != null && !Content.IsScheduled;
74      resourceNrTextBox.Enabled = !ReadOnly && !Locked && Content != null && !Content.IsScheduled;
75      jobNrTextBox.Enabled = !ReadOnly && !Locked && Content != null && !Content.IsScheduled;
76      durationTextBox.Enabled = !ReadOnly && !Locked && Content != null && !Content.IsScheduled;
77    }
78
79    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
80      SuppressEvents = true;
81      try {
82        switch (e.PropertyName) {
83          case "TaskNr":
84            taskNrTextBox.Text = Content.TaskNr.ToString();
85            break;
86          case "ResourceNr":
87            resourceNrTextBox.Text = Content.ResourceNr.ToString();
88            break;
89          case "JobNr":
90            jobNrTextBox.Text = Content.JobNr.ToString();
91            break;
92          case "Duration":
93            durationTextBox.Text = Content.Duration.ToString();
94            break;
95          case "IsScheduled":
96            SetEnabledStateOfControls();
97            break;
98          default:
99            break;
100        }
101      } finally {
102        SuppressEvents = false;
103      }
104    }
105
106    private void taskNrTextBox_Validating(object sender, CancelEventArgs e) {
107      if (!SuppressEvents && Content != null && taskNrTextBox.Enabled) {
108        int value;
109        if (int.TryParse(taskNrTextBox.Text, out value)) {
110          Content.TaskNr = value;
111          errorProvider.SetError(taskNrTextBox, String.Empty);
112        } else {
113          e.Cancel = true;
114          errorProvider.SetError(taskNrTextBox, "Please provide a valid integer.");
115        }
116      }
117    }
118
119    private void resourceNrTextBox_Validating(object sender, CancelEventArgs e) {
120      if (!SuppressEvents && Content != null && taskNrTextBox.Enabled) {
121        int value;
122        if (int.TryParse(resourceNrTextBox.Text, out value)) {
123          Content.ResourceNr = value;
124          errorProvider.SetError(resourceNrTextBox, String.Empty);
125        } else {
126          e.Cancel = true;
127          errorProvider.SetError(resourceNrTextBox, "Please provide a valid integer.");
128        }
129      }
130    }
131
132    private void jobNrTextBox_Validating(object sender, CancelEventArgs e) {
133      if (!SuppressEvents && Content != null && taskNrTextBox.Enabled) {
134        int value;
135        if (int.TryParse(jobNrTextBox.Text, out value)) {
136          Content.JobNr = value;
137          errorProvider.SetError(jobNrTextBox, String.Empty);
138        } else {
139          e.Cancel = true;
140          errorProvider.SetError(jobNrTextBox, "Please provide a valid integer.");
141        }
142      }
143    }
144
145    private void durationTextBox_Validating(object sender, CancelEventArgs e) {
146      if (!SuppressEvents && Content != null && resourceNrTextBox.Enabled) {
147        double value;
148        if (double.TryParse(durationTextBox.Text, out value)) {
149          Content.Duration = value;
150          errorProvider.SetError(durationTextBox, String.Empty);
151        } else {
152          e.Cancel = true;
153          errorProvider.SetError(durationTextBox, "Please provide a valid double.");
154        }
155      }
156    }
157  }
158}
Note: See TracBrowser for help on using the repository browser.