FrmMain.cs
7.8 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
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common;
using DeviceLibrary;
using DeviceLibrary.manager;
namespace AGVControl
{
public partial class FrmMain : Form
{
private bool exit = false;
private NotifyIcon notify;
private ContextMenuStrip notifyMenu;
private System.Timers.Timer showTimer;
//private string[] agvRunStep;
public FrmMain()
{
InitializeComponent();
showTimer = new System.Timers.Timer();
showTimer.Interval = 5000;
//showTimer.Enabled = true;
showTimer.AutoReset = true;
showTimer.Elapsed += ShowTimer_Elapsed;
showTimer.Start();
LogUtil.logBox = richTextBox1;
}
private void ShowConfig()
{
//agvRunStep = new string[Common.agvInfo.Count];
for (int i = 0; i < AGVManager.agvInfo.Count; i++)
{
MiR_API.Get_IO_Status(AGVManager.agvInfo[i]);
AGVManager.agvInfo[i].IsExistShelf = AGVManager.agvInfo[i].GetInput(0,3);
flowLayoutPanel1.Controls.Add(AGVManager.agvInfo[i].StateKanban);
AddForm(AGVManager.agvInfo[i].Name, new Manual(AGVManager.agvInfo[i]));
AGVManager.agvInfo[i].StateKanban.Init(AGVManager.agvInfo[i].Name);
}
NodeManager.InitView(DgvNode);
DeviceLibrary.manager.FixMissionManager.InitView(dgvInfos);
DeviceLibrary.manager.FixMissionManager.MissionChangedEvent += FixMissionManager_MissionChangedEvent;
}
private void FixMissionManager_MissionChangedEvent()
{
this.Invoke(new Action(()=> {
DeviceLibrary.manager.FixMissionManager.UpdateDataSource(dgvInfos);
}));
}
private void Server_NodeChanged(Node node)
{
Invoke(new Action(() =>
{
for (int i = 0; i < DgvNode.Rows.Count; i++)
{
DgvNode.Rows[i].DefaultCellStyle.ForeColor = NodeManager.nodeInfo[i].Online && NodeManager.nodeInfo[i].IsUse ? Color.Black : Color.Red;
DgvNode.Rows[i].SetValues(NodeManager.nodeInfo[i].ToRow());
}
}));
}
private void Server_NodeOnline(Node node)
{
Invoke(new Action(() =>
{
for (int i = 0; i < DgvNode.Rows.Count; i++)
{
DgvNode.Rows[i].DefaultCellStyle.ForeColor = NodeManager.nodeInfo[i].Online && NodeManager.nodeInfo[i].IsUse ? Color.Black : Color.Red;
DgvNode.Rows[i].SetValues(NodeManager.nodeInfo[i].ToRow());
}
}));
}
private void ItemShow_Click(object sender, EventArgs e)
{
Show();
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
}
private void ItemExit_Click(object sender, EventArgs e)
{
notify.Dispose();
exit = true;
Close();
}
private void Notify_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
if (WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
}
private void FrmMain_Load(object sender, EventArgs e)
{
//托盘菜单
notifyMenu = new ContextMenuStrip();
ToolStripMenuItem itemShow = new ToolStripMenuItem("显示(&S)");
itemShow.Click += ItemShow_Click;
ToolStripMenuItem itemExit = new ToolStripMenuItem("退出(&X)");
itemExit.Click += ItemExit_Click;
notifyMenu.Items.Add(itemShow);
notifyMenu.Items.Add(itemExit);
//托盘控件
notify = new NotifyIcon { Icon = Icon, Visible = true, ContextMenuStrip = notifyMenu, Text = Text };
notify.MouseDoubleClick += Notify_MouseDoubleClick;
ShowConfig();
AGVManager.server.NodeChanged += Server_NodeChanged;
AGVManager.server.NodeOnline += Server_NodeOnline;
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (!exit)
{
e.Cancel = true;
Hide();
}
LogUtil.logBox = null;
//showTimer.Enabled = false;
showTimer.Stop();
AGVManager.server.NodeChanged -= Server_NodeChanged;
AGVManager.server.NodeOnline -= Server_NodeOnline;
}
private void DgvNode_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1) return;
int idx = e.RowIndex;
if (e.ColumnIndex == 6) //调用
{
DataGridView dgv = sender as DataGridView;
if (dgv != null)
{
}
NodeManager.nodeInfo[idx].IsUse = !NodeManager.nodeInfo[idx].IsUse;
DgvNode.Rows[idx].DefaultCellStyle.ForeColor = NodeManager.nodeInfo[idx].Online && NodeManager.nodeInfo[idx].IsUse ? Color.Black : Color.Red;
DgvNode.Rows[idx].SetValues(NodeManager.nodeInfo[idx].ToRow());
}
}
bool InShhow = false;
private void ShowTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//ShowEmptyTask();
if (InShhow)
return;
InShhow = true;
Invoke(new Action(() =>
{
Application.DoEvents();
if (DeviceLibrary.manager.FixMissionManager.IsOpen())
{
pictureBox1.Visible = false;
pictureBox2.Visible = true;
}
else
{
pictureBox1.Visible = true;
pictureBox2.Visible = false;
}
}));
InShhow = false;
}
private void AddForm(string text, Form form)
{
text = text.PadLeft(10, ' ');
TabPage lineTabPage = new TabPage(text);
// lineTabPage.AutoScroll = true;
// lineTabPage.Tag = lineBean;
Panel linePan = new Panel();
linePan.Dock = DockStyle.Fill;
linePan.AutoScroll = true;
lineTabPage.Controls.Add(linePan);
form.FormBorderStyle = FormBorderStyle.None;
form.TopLevel = false;
linePan.Controls.Add(form);
//form.Dock = DockStyle.Fill;
//linePan.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
//form.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
form.Show();
// tabPageList.Add(lineTabPage);
tabControlManual.Controls.Add(lineTabPage);
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 1)
{
LogUtil.logBox = this.richTextBox1;
}
}
private void dgvInfos_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4)
{
if (e.RowIndex == -1)
return;
DeviceLibrary.manager.FixMissionManager.SetMissionState(e.RowIndex);
DeviceLibrary.manager.FixMissionManager.UpdateDataSource(dgvInfos);
}
}
}
}