Digital Twin - GUI
TimeslotDialog.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using GUI.Datatypes;
11 
12 namespace GUI
13 {
17 
21  public partial class TimeslotDialog : Form
22  {
24  private List<CheckBox> checkbox;
26  private MachineCB m;
28  private LocationCB l;
29 
36 
38  public TimeslotDialog(CheckBox loc_mac, DateTime start, DateTime end)
39  {
41  int num = (int)Math.Ceiling(end.Subtract(start).TotalHours);
42  checkbox = new List<CheckBox>();
43 
44  if (loc_mac is MachineCB) { m = (MachineCB) loc_mac; }
45  if (loc_mac is LocationCB) { l = (LocationCB) loc_mac; }
46  label1.Text = loc_mac.Text;
47 
48  for (int i = 0; i < 24; i++)
49  {
50  // label the rows
51  tableLayoutPanel1.Controls.Add(new Label { Text = i +":00 - " + (i+1) + ":00" }, 0, i+1);
52  }
53 
54  int column = 1;
55  int row = start.Hour+1;
56  for (int i = 0; i<num; i++)
57  {
58  CheckBox c = new CheckBox() { Text = "" };
59  if (loc_mac is MachineCB)
60  {
61  if (m.stateOfTimeslot(checkbox.Count)) { c.CheckState = CheckState.Checked; }
62  else { c.CheckState = CheckState.Unchecked; }
63  c.CheckStateChanged += new EventHandler(machineCheckboxClicked);
64  checkbox.Add(c);
65  }
66 
67  if (loc_mac is LocationCB)
68  {
69  if (l.stateOfTimeslot(checkbox.Count)) { c.CheckState = CheckState.Checked; }
70  else { c.CheckState = CheckState.Unchecked; }
71  c.CheckStateChanged += new EventHandler(locationCheckboxClicked);
72  checkbox.Add(c);
73  }
74 
75  tableLayoutPanel1.Controls.Add(checkbox[i], column, row);
76  if (row == 24)
77  {
78  row = 1;
79  column++;
80  }
81  else
82  {
83  row++;
84  }
85  }
86 
87  // label the columns
88  DayOfWeek day = start.DayOfWeek;
89  for (int i = 0; i < column; i++)
90  {
91  // make it German
92  var culture = new System.Globalization.CultureInfo("de-DE");
93  tableLayoutPanel1.Controls.Add(new Label { Text = culture.DateTimeFormat.GetDayName(day) }, i + 1, 0);
94  //start iteration again after end is reached.
95  if (day.Equals(DayOfWeek.Saturday))
96  {
97  day = DayOfWeek.Sunday;
98  }
99  else
100  {
101  day++;
102  }
103  }
104 
105  }
106 
112 
115  private void button1_Click(object sender, EventArgs e)
116  {
117  this.Close();
118  }
119 
125 
128  private void machineCheckboxClicked(object sender, EventArgs e)
129  {
130  CheckBox c = (CheckBox)sender;
131  m.changeStateOfTimeslot(checkbox.IndexOf(c));
132  }
133 
139 
142  private void locationCheckboxClicked(object sender, EventArgs e)
143  {
144  CheckBox c = (CheckBox)sender;
145  l.changeStateOfTimeslot(checkbox.IndexOf(c));
146  }
147  }
148 }
bool stateOfTimeslot(int t)
Get the availability of this machine at timeslot t.
Definition: MachineCB.cs:145
TimeslotDialog(CheckBox loc_mac, DateTime start, DateTime end)
The Constructor.
MachineCB m
Machine for which the timeslots appears.
LocationCB l
Location for which the timeslots appears.
void locationCheckboxClicked(object sender, EventArgs e)
Eventhandler that is called when the state of a location CheckBox has changed.
Dialog that lets users choose which timeslots are available.
A wrapper class for locations.
Definition: LocationCB.cs:19
void button1_Click(object sender, EventArgs e)
Eventhandler that is called when the "Close" button is clicked.
void machineCheckboxClicked(object sender, EventArgs e)
Eventhandler that is called when the state of a machine CheckBox has changed.
void changeStateOfTimeslot(int t)
Change the availability of this machine at timeslot t.
Definition: MachineCB.cs:158
void changeStateOfTimeslot(int t)
Change the availability of this location at timeslot t.
Definition: LocationCB.cs:144
A wrapper class for machines.
Definition: MachineCB.cs:18
bool stateOfTimeslot(int t)
Get the availability of this location at timeslot t.
Definition: LocationCB.cs:123
List< CheckBox > checkbox
List of checkboxes that represent the timeslots.
void InitializeComponent()
Required method for Designer support - do not modify the contents of this method with the code editor...