-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodoFacil.cs
285 lines (259 loc) · 8.35 KB
/
modoFacil.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Monitor
{
public partial class modoFacil : Form
{
List<Button> botoes = new List<Button>();
List<Machine> machinesForm;
public modoFacil(List<Machine> machines)
{
InitializeComponent();
machinesForm = machines;
initializeButtons();
initializeAsyncMachines();
carregarStatusMaquina();
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
modoAvancado tela = new modoAvancado(machinesForm);
((Form)tela).Closed += (s, args) => this.Close();
tela.Show();
}
private void Maquina1_Click(object sender, EventArgs e)
{
mudaStatusMaquina(Maquina1);
}
private void Maquina2_Click(object sender, EventArgs e)
{
mudaStatusMaquina(Maquina2);
}
private void Maquina3_Click(object sender, EventArgs e)
{
mudaStatusMaquina(Maquina3);
}
private void Maquina4_Click(object sender, EventArgs e)
{
mudaStatusMaquina(Maquina4);
}
private void Maquina5_Click(object sender, EventArgs e)
{
mudaStatusMaquina(Maquina5);
}
private void Maquina6_Click(object sender, EventArgs e)
{
mudaStatusMaquina(Maquina6);
}
private void Maquina7_Click(object sender, EventArgs e)
{
mudaStatusMaquina(Maquina7);
}
private void Maquina8_Click(object sender, EventArgs e)
{
mudaStatusMaquina(Maquina8);
}
private void Maquina9_Click(object sender, EventArgs e)
{
mudaStatusMaquina(Maquina9);
}
private void Maquina10_Click(object sender, EventArgs e)
{
mudaStatusMaquina(Maquina10);
}
/* Métodos para ativar todas as maquinas */
private void AtivarTodas_Click(object sender, EventArgs e)
{
if (ativarTodas())
{
MessageBox.Show("Todas as máquinas estão ativadas", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
else
{
foreach (Machine m in machinesForm)
{
if (!m.status)
{
textBox1.Text += m.name + " está ligada" + "\r\n";
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
}
}
ativandoTodas();
mudaCorButton(Color.Green);
}
}
private Boolean ativarTodas()
{
Boolean aux = true;
foreach (Machine m in machinesForm)
{
if (m.status)
{
aux = true;
}
else
{
aux = false;
break;
}
}
return aux;
}
public void ativandoTodas()
{
foreach (Machine m in machinesForm)
{
m.status = true;
}
}
/* Métodos para desativar todas as maquinas */
private void DesativarTodas_Click(object sender, EventArgs e)
{
if (desativarTodas())
{
MessageBox.Show("Todas as máquinas estão desativadas", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
else
{
foreach (Machine m in machinesForm)
{
if (m.status)
{
textBox1.Text += m.name + " está desligada" + "\r\n";
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
}
}
desativandoTodas();
mudaCorButton(Color.Red);
}
}
private Boolean desativarTodas()
{
Boolean aux = true;
foreach (Machine m in machinesForm)
{
if (!m.status)
{
aux = true;
}
else
{
aux = false;
break;
}
}
return aux;
}
public void desativandoTodas()
{
foreach (Machine m in machinesForm)
{
m.status = false;
}
}
/* Método para popular o array de botões */
private void initializeButtons()
{
botoes.Add(Maquina1);
botoes.Add(Maquina2);
botoes.Add(Maquina3);
botoes.Add(Maquina4);
botoes.Add(Maquina5);
botoes.Add(Maquina6);
botoes.Add(Maquina7);
botoes.Add(Maquina8);
botoes.Add(Maquina9);
botoes.Add(Maquina10);
}
private void initializeAsyncMachines()
{
asyncMachines.machineExec(machinesForm[0], machinesForm);
asyncMachines.machineExec(machinesForm[1], machinesForm);
asyncMachines.machineExec(machinesForm[2], machinesForm);
asyncMachines.machineExec(machinesForm[3], machinesForm);
asyncMachines.machineExec(machinesForm[4], machinesForm);
asyncMachines.machineExec(machinesForm[5], machinesForm);
asyncMachines.machineExec(machinesForm[6], machinesForm);
asyncMachines.machineExec(machinesForm[7], machinesForm);
asyncMachines.machineExec(machinesForm[8], machinesForm);
asyncMachines.machineExec(machinesForm[9], machinesForm);
asyncMachines.mudaData += atualizaText;
}
private void mudaCorButton(Color cor)
{
foreach (Button botao in botoes)
{
botao.BackColor = cor;
}
}
private void mudaStatusMaquina(Button botao)
{
if (machinesForm[botoes.IndexOf(botao)].status)
{
Machine m = machinesForm[botoes.IndexOf(botao)];
m.status = false;
botao.BackColor = Color.Red;
if (!m.status)
{
textBox1.Text += m.name + " está desligada" + "\r\n";
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
}
}
else
{
Machine m = machinesForm[botoes.IndexOf(botao)];
m.status = true;
botao.BackColor = Color.Green;
if (m.status)
{
textBox1.Text += m.name + " está ligada" + "\r\n";
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
}
}
}
private void carregarStatusMaquina()
{
foreach (Machine maqui in machinesForm)
{
if (maqui.status)
{
botoes[machinesForm.IndexOf(maqui)].BackColor = Color.Green;
}
else
{
botoes[machinesForm.IndexOf(maqui)].BackColor = Color.Red;
}
}
}
private void atualizaText(Machine m)
{
try
{
if (m != null)
{
if (m.registerList.Find(e => e.regName == "Disponível").regCount > 0)
{
textBox1.Text += m.name + " " + m.registerList.Find(e => e.regName == "Disponível").regCount + "\r\n";
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
}
}
}
catch
{
}
}
}
}