2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Windows.Forms;
9 using DirectOutput.Cab;
10 using DirectOutput.Cab.Out;
11 using System.Reflection;
12 using DirectOutput.Cab.Toys;
15 namespace DirectOutput.Frontend
25 InitializeComponent();
28 this.Cabinet = Cabinet;
35 private void UpdateToys()
37 DataTable DT =
new DataTable();
38 DT.Columns.Add(
"Name", typeof(
string));
39 DT.Columns.Add(
"Type", typeof(
string));
43 DT.Rows.Add(T.
Name, T.GetType().
Name);
45 CabinetToys.ClearSelection();
46 CabinetToys.Columns.Clear();
47 CabinetToys.AutoGenerateColumns =
true;
48 CabinetToys.DataSource = DT;
49 CabinetToys.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
51 CabinetToys.Refresh();
53 UpdateToyProperties(null);
57 private void UpdateToyProperties(
IToy Toy)
59 DataTable DT =
new DataTable();
60 DT.Columns.Add(
"Property", typeof(
string));
61 DT.Columns.Add(
"Value", typeof(
string));
64 DT.Rows.Add(
"Name", Toy.
Name);
65 DT.Rows.Add(
"Type", Toy.GetType().
Name);
68 Type T = Toy.GetType();
70 foreach (PropertyInfo PI
in T.GetProperties(BindingFlags.Instance | BindingFlags.Public))
72 if (PI.Name !=
"Name")
74 DT.Rows.Add(PI.Name, PI.GetValue(Toy,
new object[] { }).ToString());
78 CabinetToyProperties.ClearSelection();
79 CabinetToyProperties.Columns.Clear();
80 CabinetToyProperties.AutoGenerateColumns =
true;
81 CabinetToyProperties.DataSource = DT;
82 CabinetToyProperties.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
84 CabinetToyProperties.Refresh();
92 DataTable DT =
new DataTable();
93 DT.Columns.Add(
"Property", typeof(
string));
94 DT.Columns.Add(
"Value", typeof(
string));
95 if (OutputController != null)
97 DT.Rows.Add(
"Name", OutputController.
Name);
98 DT.Rows.Add(
"Output Count", OutputController.
Outputs.Count);
100 Type T = OutputController.GetType();
102 foreach (PropertyInfo PI
in T.GetProperties(BindingFlags.Instance | BindingFlags.Public))
104 if (PI.Name !=
"Name" && PI.Name !=
"Outputs")
106 DT.Rows.Add(PI.Name, PI.GetValue(OutputController,
new object[] { }).ToString());
110 CabinetOutputControllerProperties.ClearSelection();
111 CabinetOutputControllerProperties.Columns.Clear();
112 CabinetOutputControllerProperties.AutoGenerateColumns =
true;
114 CabinetOutputControllerProperties.DataSource = DT;
115 CabinetOutputControllerProperties.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
116 CabinetOutputControllerProperties.Refresh();
122 DataTable DT =
new DataTable();
123 DT.Columns.Add(
"Name", typeof(
string));
124 if (OutputController != null)
126 if (OutputController.
Outputs.Count > 0)
128 Type T = OutputController.
Outputs[0].GetType();
130 foreach (PropertyInfo PI
in T.GetProperties(BindingFlags.Instance | BindingFlags.Public))
132 if (PI.Name !=
"Name")
134 DT.Columns.Add(PI.Name, PI.PropertyType);
140 object[] values =
new object[DT.Columns.Count];
143 foreach (PropertyInfo PI
in T.GetProperties(BindingFlags.Instance | BindingFlags.Public))
145 if (PI.Name !=
"Name")
147 values[Index] = PI.GetValue(O,
new object[] { });
154 CabinetOutputControllerOutputs.ClearSelection();
155 CabinetOutputControllerOutputs.Columns.Clear();
156 CabinetOutputControllerOutputs.AutoGenerateColumns =
true;
157 CabinetOutputControllerOutputs.DataSource = DT;
158 CabinetOutputControllerOutputs.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
159 CabinetOutputControllerOutputs.Refresh();
167 private void UpdateOutputControllers()
169 DataTable OutputControllersDataTable =
new DataTable();
170 OutputControllersDataTable.Columns.Add(
"Name", typeof(
string));
171 OutputControllersDataTable.Columns.Add(
"Type", typeof(
string));
172 OutputControllersDataTable.Columns.Add(
"Output Count", typeof(
int));
173 OutputControllersDataTable.Rows.Clear();
176 OutputControllersDataTable.Rows.Add(OC.
Name, OC.GetType().
Name, OC.
Outputs.Count);
178 CabinetOutputControllers.ClearSelection();
179 CabinetOutputControllers.AutoGenerateColumns =
true;
180 CabinetOutputControllers.DataSource = OutputControllersDataTable;
181 CabinetOutputControllers.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
182 CabinetOutputControllers.Refresh();
185 UpdateOutputControllerProperties(null);
189 private void UpdateWindowTitle()
191 string S =
"Cabinet Configuration";
202 S +=
" - <unsaved cabinet configuration>";
212 get {
return _Cabinet; }
216 UpdateOutputControllers();
224 private void CabinetOutputControllers_SelectionChanged(
object sender, EventArgs e)
226 if (CabinetOutputControllers.SelectedRows.Count > 0)
228 string N = (string)CabinetOutputControllers.SelectedRows[0].Cells[0].Value;
237 UpdateOutputControllerProperties(null);
242 private void CabinetToys_SelectionChanged(
object sender, EventArgs e)
244 if (CabinetToys.SelectedRows.Count > 0)
247 string N = (string)CabinetToys.SelectedRows[0].Cells[0].Value;
254 UpdateToyProperties(null);
259 private void ExportCabinetConfiguration_Click(
object sender, EventArgs e)
264 SaveCabinetConfiguration.InitialDirectory = FI.Directory.FullName;
265 SaveCabinetConfiguration.FileName = FI.FullName;
269 SaveCabinetConfiguration.InitialDirectory =
new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName;
271 if (SaveCabinetConfiguration.ShowDialog() == DialogResult.OK)
278 MessageBox.Show(
"Cabinet configuration saved to\n{0}".Build(SaveCabinetConfiguration.FileName),
"Cabinet configuration saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
282 MessageBox.Show(
"Could not save cabinet config to\n{0}\n\nThe following error occured:\n{1}".Build(SaveCabinetConfiguration.FileName, E.Message),
"File save error", MessageBoxButtons.OK, MessageBoxIcon.Error);