FrmMain.cs
14.3 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AGVControl_Steel
{
public partial class FrmMain : Form
{
private bool checkedChange;
private BLL.Control control;
public FrmMain()
{
InitializeComponent();
control = new BLL.Control();
}
private void Control_AgvChanged(int agvIndex)
{
Invoke(new Action(() =>
{
DgvName.Rows[agvIndex].SetValues(Common.agvInfos[agvIndex].ToGridRow());
tableLayoutPanel5.Controls["TxtAgvMission" + agvIndex].Text = Common.agvInfos[agvIndex].ToMissionState();
}));
}
private void Control_AgvOnline(int agvIndex)
{
Invoke(new Action(() =>
{
DgvName.Rows[agvIndex].DefaultCellStyle.ForeColor = Common.agvInfos[agvIndex].IsOnline ? Color.Black : Color.Red;
DgvName.Rows[agvIndex].SetValues(Common.agvInfos[agvIndex].ToGridRow());
tableLayoutPanel5.Controls["TxtAgvMission" + agvIndex].Text = Common.agvInfos[agvIndex].ToMissionState();
}));
}
private void FrmMain_Load(object sender, EventArgs e)
{
string[] workshop = new string[Common.agvInfos.Count];
for (int i = 0; i < Common.agvInfos.Count; i++)
workshop[i] = Common.agvInfos[i].Workshop;
Text += " (" + string.Join(" ", workshop) + ")";
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetEntryAssembly();
LblVersion.Text = assembly.GetName().Version.ToString();
checkedChange = true;
ChkWorkTimeoutDel.Text = "回收钢板时删除" + Common.WorkTimeout + "min前的任务";
ChkWorkTimeoutDel.Checked = Common.WorkTimeoutDel;
ChkWorkAutoDel.Checked = Common.WorkAutoDel;
checkedChange = false;
Common.log.LogBox = TxtLog;
Common.lstOldSteel = LstOldSteel;
Common.lstNewSteel = LstNewSteel;
Common.lstStorage = LstStorage;
Common.lblStorageIO = LblStorageIO;
BLL.SteelManage.OldSteelWorkLoad();
BLL.SteelManage.NewSteelWorkLoad();
BLL.SteelManage.StorageWorkLoad();
BLL.RunMode.Init(this);
BLL.WebService.Open(Common.appConfig.AppSettings.Settings["WebService"].Value);
LblWeb.BackColor = BLL.WebService.IsOpen ? Color.Lime : Color.Red;
LblWeb.Text = BLL.WebService.IsOpen ? "WebService Open" : "WebService Close";
LstMission.Items.AddRange(Common.agvMissions.Keys.ToArray());
List<string> missionHint = new List<string>();
for (int i = 0; i < Common.agvLines.Count; i++)
missionHint.AddRange(Common.agvLines[i].Lines);
missionHint.Add(Common.STORAGE_ENTER_4C);
missionHint.Add(Common.STORAGE_ENTER_4D);
missionHint.Add(Common.STORAGE_LEAVE);
LblMissionHint.Text = "提示:" + string.Join(",", missionHint);
for (int i = 0; i < Common.agvInfos.Count; i++)
{
DgvName.Rows.Add(Common.agvInfos[i].ToGridRow());
DgvName.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
DgvName.Rows[i].HeaderCell.Value = (i + 1).ToString();
DgvName.Rows[i].Height = 30;
}
control.AgvChanged += Control_AgvChanged;
control.AgvOnline += Control_AgvOnline;
control.Start();
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (BLL.RunMode.Closing(e))
{
control.Stop();
BLL.WebService.Close();
}
}
private void DgvName_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1) return;
AgvInfo info = Common.agvInfos[e.RowIndex];
if (e.ColumnIndex == DgvName.Columns.Count - 2) //最后二列,自动/手动
{
info.IsAuto = !info.IsAuto;
Common.log.Info("手动修改 " + info.Name + " 自动状态" + info.IsAuto);
DgvName.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = info.IsAuto.ToString();
Common.appConfig.AppSettings.Settings[info.Name].Value = info.IsAuto.ToString();
Common.appConfig.Save();
System.Configuration.ConfigurationManager.RefreshSection("appSettings");
if (info.IsAuto && Common.WorkAutoDel)
{
BLL.SteelManage.OldSteelWorkDelAll(info.Workshop);
BLL.SteelManage.NewSteelWorkDelAll(info.Workshop);
BLL.SteelManage.StorageWorkDelAll(info.Workshop);
}
}
else if (e.ColumnIndex == DgvName.Columns.Count - 1) //最后一列,清除任务
{
string text = "确定要清除 " + info.Name + " 的任务吗?";
DialogResult dr = MessageBox.Show(text, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
Common.log.Info("手动清除 " + info.Name + " 任务");
info.CurrentJob = null;
Common.mir.Del_Mission(info.IP, info.Authorization);
info.IsAuto = false;
info.Place = "";
DgvName.Rows[e.RowIndex].Cells[e.ColumnIndex - 1].Value = info.IsAuto.ToString();
Common.appConfig.AppSettings.Settings[info.Name].Value = info.IsAuto.ToString();
Common.appConfig.Save();
System.Configuration.ConfigurationManager.RefreshSection("appSettings");
}
}
}
#region 手动添加小车任务
private void BtnMissionAdd_Click(object sender, EventArgs e)
{
if (DgvName.SelectedCells.Count == 0) return;
int idx = DgvName.SelectedCells[0].RowIndex;
if (idx < 0) return;
AgvInfo info = Common.agvInfos[idx];
if (info.IsAuto)
{
MessageBox.Show(info.Name + " 自动状态,不允许手动发送任务");
return;
}
if (LstMission.SelectedIndex == -1) return;
if (Common.FLEET_SEND)
Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, LstMission.Text, out string id);
else
Common.mir.Add_Mission(info.IP, info.Authorization, LstMission.Text, out string id);
}
private void BtnMissionClear_Click(object sender, EventArgs e)
{
if (DgvName.SelectedCells.Count == 0) return;
int idx = DgvName.SelectedCells[0].RowIndex;
if (idx < 0) return;
AgvInfo info = Common.agvInfos[DgvName.SelectedRows[0].Index];
Common.mir.Del_Mission(info.IP, info.Authorization);
}
private void BtnMissionRun_Click(object sender, EventArgs e)
{
if (DgvName.SelectedCells.Count == 0) return;
int idx = DgvName.SelectedCells[0].RowIndex;
if (idx < 0) return;
AgvInfo info = Common.agvInfos[idx];
Common.mir.State_Ready(info.IP, info.Authorization);
}
private void BtnMissionPause_Click(object sender, EventArgs e)
{
if (DgvName.SelectedCells.Count == 0) return;
int idx = DgvName.SelectedCells[0].RowIndex;
if (idx < 0) return;
AgvInfo info = Common.agvInfos[idx];
Common.mir.State_Pause(info.IP, info.Authorization);
}
#endregion
#region 手动修改钢网任务
private void BtnOldSteelWorkAdd_Click(object sender, EventArgs e)
{
string text = "手动添加回收钢板任务";
string msg = Microsoft.VisualBasic.Interaction.InputBox(text, "添加", "");
if (string.IsNullOrWhiteSpace(msg)) return;
Common.log.Info(text + " " + msg);
BLL.SteelManage.OldSteelWorkAdd(msg);
}
private void BtnOldSteelWorkDel_Click(object sender, EventArgs e)
{
if (LstOldSteel.SelectedIndex == -1) return;
string[] arr = LstOldSteel.Text.Split(',');
string text = "手动删除回收钢板任务 " + arr[0];
DialogResult dr = MessageBox.Show(text, "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
Common.log.Info(text);
BLL.SteelManage.OldSteelWorkDel(arr[0]);
}
}
private void BtnOldSteelWorkDelAll_Click(object sender, EventArgs e)
{
string text = "手动删除全部回收钢板任务";
DialogResult dr = MessageBox.Show(text, "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
Common.log.Info(text);
BLL.SteelManage.OldSteelWorkDelAll();
}
}
private void BtnNewSteelWorkAdd_Click(object sender, EventArgs e)
{
string text = "手动添加送新钢板任务,from&place逗号分割";
string msg = Microsoft.VisualBasic.Interaction.InputBox(text, "添加", "");
if (string.IsNullOrWhiteSpace(msg)) return;
string[] arr = msg.Split(',');
Common.log.Info(text + " " + msg);
BLL.SteelManage.NewSteelWorkAdd(arr[0], arr[1]);
}
private void BtnNewSteelWorkDel_Click(object sender, EventArgs e)
{
if (LstNewSteel.SelectedIndex == -1) return;
string[] arr = LstNewSteel.Text.Split(',');
string text = "手动删除【" + arr[0] + "," + arr[1] + "】送新钢板任务";
DialogResult dr = MessageBox.Show(text, "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
Common.log.Info(text);
BLL.SteelManage.NewSteelWorkDel(arr[0], arr[1]);
}
}
private void BtnNewSteelWorkDelAll_Click(object sender, EventArgs e)
{
string text = "手动删除全部送新钢板任务";
DialogResult dr = MessageBox.Show(text, "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
Common.log.Info(text);
BLL.SteelManage.NewSteelWorkDelAll();
}
}
private void BtnStorageWorkAdd_Click(object sender, EventArgs e)
{
string text = "手动添加仓库钢板任务";
string msg = Microsoft.VisualBasic.Interaction.InputBox(text, "添加", "");
if (string.IsNullOrWhiteSpace(msg)) return;
Common.log.Info(text + " " + msg);
BLL.SteelManage.StorageWorkAdd(msg);
}
private void BtnStorageWorkDel_Click(object sender, EventArgs e)
{
if (LstStorage.SelectedIndex == -1) return;
string[] arr = LstStorage.Text.Split(',');
string text = "手动删除【" + arr[0] + "】仓库钢板任务";
DialogResult dr = MessageBox.Show(text, "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
Common.log.Info(text);
BLL.SteelManage.StorageWorkDel(arr[0]);
}
}
private void BtnStorageWorkDelAll_Click(object sender, EventArgs e)
{
string text = "手动删除全部仓库钢板任务";
DialogResult dr = MessageBox.Show(text, "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
Common.log.Info(text);
BLL.SteelManage.StorageWorkDelAll();
}
}
private void ChkMissionDebug_CheckedChanged(object sender, EventArgs e)
{
BtnOldSteelWorkAdd.Enabled = ChkMissionDebug.Checked;
BtnOldSteelWorkDel.Enabled = ChkMissionDebug.Checked;
BtnOldSteelWorkDelAll.Enabled = ChkMissionDebug.Checked;
BtnNewSteelWorkAdd.Enabled = ChkMissionDebug.Checked;
BtnNewSteelWorkDel.Enabled = ChkMissionDebug.Checked;
BtnNewSteelWorkDelAll.Enabled = ChkMissionDebug.Checked;
BtnStorageWorkAdd.Enabled = ChkMissionDebug.Checked;
BtnStorageWorkDel.Enabled = ChkMissionDebug.Checked;
BtnStorageWorkDelAll.Enabled = ChkMissionDebug.Checked;
ChkStorageIO.Enabled = ChkMissionDebug.Checked;
}
private void ChkStorageIO_CheckedChanged(object sender, EventArgs e)
{
Common.StorageDockAlway = ChkStorageIO.Checked;
}
#endregion
private void BtnClearLog_Click(object sender, EventArgs e)
{
TxtLog.Text = "";
}
private void ChkWorkAutoDel_CheckedChanged(object sender, EventArgs e)
{
if (checkedChange) return;
Common.WorkAutoDel = ChkWorkAutoDel.Checked;
Common.appConfig.AppSettings.Settings["WorkAutoDel"].Value = Common.WorkAutoDel.ToString();
Common.appConfig.Save();
System.Configuration.ConfigurationManager.RefreshSection("appSettings");
Common.log.Info("修改WorkAutoDel=" + Common.WorkAutoDel.ToString());
}
private void ChkWorkTimeoutDel_CheckedChanged(object sender, EventArgs e)
{
if (checkedChange) return;
Common.WorkTimeoutDel = ChkWorkTimeoutDel.Checked;
Common.appConfig.AppSettings.Settings["WorkTimeoutDel"].Value = Common.WorkTimeoutDel.ToString();
Common.appConfig.Save();
System.Configuration.ConfigurationManager.RefreshSection("appSettings");
Common.log.Info("修改WorkTimeoutDel=" + Common.WorkTimeoutDel.ToString());
}
private void tabControl1_Click(object sender, EventArgs e)
{
ConfigHelper.AdvanceConfigForm.ShowEditDialog(this);
}
}
}