WinOrganization.xaml.cs
13.6 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
using RCS.Dal;
using RCS.Communication;
using RCS.Model.Comm;
using RCS.Model.Entity;
using RCS.Model.PLC;
using RCS.WinClient.Common;
using RCS.WinClient.PLC;
using RCS.WinClient.Service;
using System.Windows;
using System.Windows.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace RCS.WinClient.Views.Pages
{
/// <summary>
/// WinOrganization.xaml 的交互逻辑
/// </summary>
public partial class WinOrganization : Window
{
private static BaseDal<Base_Agv> _agvDb = new BaseDal<Base_Agv>();
private static BaseDal<Base_Station> _stationDb = new BaseDal<Base_Station>();
public WinOrganization()
{
InitializeComponent();
}
/// <summary>
/// 关闭按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
//重写Closing方法
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
this.Hide();
e.Cancel = true;
}
/// <summary>
/// 拖动事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DGrid_AGV.ItemsSource = App.AgvList.OrderBy(a => a.AgvNo).ToList();
DGrid_Charge.ItemsSource = App.StationList.Where(a => a.StationType == EnumMsg.StationType.充电桩).OrderBy(a => a.Name).ToList();
DGrid_Station.ItemsSource = App.StationList.Where(a => a.StationType > EnumMsg.StationType.充电桩).OrderBy(a => a.Name).ToList();
DGrid_MatixManager.ItemsSource = App.PointList;
DGrid_HuahengStaion.ItemsSource = App.HuahengStaionList;
}
/// <summary>
/// 解锁站台事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MItem_Locked_Click(object sender, RoutedEventArgs e)
{
try
{
//if (DGrid_Station.SelectedItem == null) return;
//Station station = DGrid_Station.SelectedItem as Station;
//if (station == null) return;
//station.isLocked = false;
//bool updateResult = UpdateManage.UpdateStation(station);
//if (updateResult)
//{
// ComnMethod.Message("解锁成功");
//}
//else
//{
// ComnMethod.Message("解锁失败");
//}
}
catch (Exception ex)
{
ComnMethod.Message("操作失败:" + ex.ToString());
}
}
private void MItem_AgvOnline_Click(object sender, RoutedEventArgs e)
{
Base_Agv agv = DGrid_AGV.SelectedItem as Base_Agv;
try
{
if (agv == null) return;
if (agv.AgvTask != null)
{
ComnMethod.Message(string.Format("{0}存在任务,不能上下线!", agv.AgvNo));
return;
}
var updateResult = _agvDb.Update(it => it.AgvNo == agv.AgvNo, it => new Base_Agv()
{
IsEnable = true
});
if (updateResult.IsSuccess)
{
agv.IsEnable = true;
ComnMethod.Message(string.Format("{0}上线成功!", agv.AgvNo));
}
}
catch (Exception ex)
{
ComnMethod.Message(ex.ToString());
}
}
private void MItem_AgvOut_Click(object sender, RoutedEventArgs e)
{
Base_Agv agv = DGrid_AGV.SelectedItem as Base_Agv;
try
{
if (agv == null) return;
if (agv.AgvTask != null)
{
ComnMethod.Message(string.Format("{0}存在任务,不能上下线!", agv.AgvNo));
return;
}
var updateResult = _agvDb.Update(it => it.AgvNo == agv.AgvNo, it => new Base_Agv()
{
Barcode = "0",
LockStation = null,
IsEnable = false,
});
if (updateResult.IsSuccess)
{
agv.AgvState = 0;
agv.Barcode = "0";
agv.IsEnable = false;
agv.IsOnline = false;
agv.LockStation = null;
List<Base_Point> agvLockedList = App.PointList.FindAll(a => a.LockedAgv == agv);
foreach (Base_Point point in agvLockedList)
{
point.LockedAgv = null;
}
//更新界面小车位置
App.Sharp.AgvChange(agv);
ComnMethod.Message(string.Format("{0}下线成功!", agv.AgvNo));
}
}
catch (Exception ex)
{
ComnMethod.Message(ex.ToString());
}
}
/// <summary>
/// 禁用充电桩
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MItem_Cforbit_Click(object sender, RoutedEventArgs e)
{
try
{
Base_Station chargeStation = DGrid_Charge.SelectedItem as Base_Station;
if (chargeStation == null) return;
chargeStation.IsEnable = false;
var isResult = UpdateManage.UpdateStation(chargeStation);
if (isResult.IsSuccess)
{
ComnMethod.Message(string.Format("{0}充电桩禁用成功!", chargeStation.Name));
}
}
catch (Exception ex)
{
ComnMethod.Message(ex.ToString());
}
}
/// <summary>
/// 启用充电桩
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MItem_CEnable_Click(object sender, RoutedEventArgs e)
{
try
{
Base_Station chargeStation = DGrid_Charge.SelectedItem as Base_Station;
if (chargeStation == null) return;
chargeStation.IsEnable = true;
var isResult = UpdateManage.UpdateStation(chargeStation);
if (isResult.IsSuccess)
{
ComnMethod.Message(string.Format("{0}充电桩启用成功!", chargeStation.Name));
}
}
catch (Exception ex)
{
ComnMethod.Message(ex.ToString());
}
}
/// <summary>
/// 解锁充电桩
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MItem_CUnLock_Click(object sender, RoutedEventArgs e)
{
try
{
if (DGrid_Charge.SelectedItem is not Base_Station chargeStation) return;
Base_Agv? agv = App.AgvList.FirstOrDefault(a => a.Barcode == chargeStation.Barcode);
if (agv != null)
{
ComnMethod.Message(string.Format("{0}占用当前充电桩无法解锁!", agv.AgvNo));
return;
}
chargeStation.IsLocked = false;
agv = App.AgvList.Find(x => x.LockStation?.Name == chargeStation.Name);
if (agv != null)
{
agv.LockStation = null;
}
var isResult = UpdateManage.UpdateStation(chargeStation);
if (isResult.IsSuccess)
{
ComnMethod.Message(string.Format("{0}充电桩解锁成功!", chargeStation.Name));
}
}
catch (Exception ex)
{
ComnMethod.Message(ex.ToString());
}
}
/// <summary>
/// 更改为有托盘
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MItem_OnEnable_Click(object sender, RoutedEventArgs e)
{
try
{
Base_Station station = DGrid_Station.SelectedItem as Base_Station;
if (station == null) return;
var updateresult = _stationDb.Update(it => it.Name == station.Name, it => new Base_Station()
{
StationState = EnumMsg.StationState.有托盘
});
if (updateresult.IsSuccess)
{
station.StationState = EnumMsg.StationState.有托盘;
}
else
{
ComnMethod.Message(string.Format("更改{0}工位失败!", station.Name));
}
}
catch (Exception ex)
{
ComnMethod.Message(ex.ToString());
}
}
/// <summary>
/// 更改为无托盘
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MItem_OffEnable_Click(object sender, RoutedEventArgs e)
{
try
{
Base_Station station = DGrid_Station.SelectedItem as Base_Station;
if (station == null) return;
var updateresult = _stationDb.Update(it => it.Name == station.Name, it => new Base_Station()
{
StationState = EnumMsg.StationState.无托盘
});
if (updateresult.IsSuccess)
{
station.StationState = EnumMsg.StationState.无托盘;
}
else
{
ComnMethod.Message(string.Format("更改{0}工位失败!", station.Name));
}
}
catch (Exception ex)
{
ComnMethod.Message(ex.ToString());
}
}
/// <summary>
/// 更改货架信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MItem_ChangeShelf_Click(object sender, RoutedEventArgs e)
{
}
private void MItem_ShelfUnLock_Click(object sender, RoutedEventArgs e)
{
}
private void MItem_SelectShelf_Click(object sender, RoutedEventArgs e)
{
}
private void MItem_Hoister_Click(object sender, RoutedEventArgs e)
{
Config_Equipment equipment = DGrid_Hoister.SelectedItem as Config_Equipment;
if (equipment == null) return;
ComnMethod.Message("清除成功");
}
private async void MItem_ClearHuahengStaion_Click(object sender, RoutedEventArgs e)
{
HuahengStaion huahengStaion = DGrid_HuahengStaion.SelectedItem as HuahengStaion;
if (huahengStaion == null)
{
ComnMethod.Message("没有选中数据!");
return;
}
if (string.IsNullOrEmpty(huahengStaion.EquipmentName))
{
ComnMethod.Message("选中的数据没有对应的设备名称!");
return;
}
var msg = $"请确认是否清除华恒站台【{huahengStaion.EquipmentName}】的交互信号?可能导致任务出错!";
if (MessageBox.Show(msg, "警告", MessageBoxButton.YesNo) == MessageBoxResult.No) return;
await Task.Run(() =>
{
//因为PLC操作是异步的,第一次提交的结果是“等待处理”,所以等待2秒再次提交获取结果
EquipmentExecutor.Instance.RequestOperator(huahengStaion.EquipmentName, EnumMsg.RequestType.清空数据);
Thread.Sleep(EquipmentExecutor.Instance.ExecuteTime);
var bllResult = EquipmentExecutor.Instance.RequestOperator(huahengStaion.EquipmentName, EnumMsg.RequestType.清空数据);
if (!bllResult.IsSuccess)
{
ComnMethod.Message($"清除华恒站台【{huahengStaion.EquipmentName}】的交互信号失败!失败原因:{bllResult.Message}");
return;
}
ComnMethod.Message($"清除华恒站台【{huahengStaion.EquipmentName}】的交互信号成功");
});
}
private void MItem_EnableChange_Click(object sender, RoutedEventArgs e)
{
var point = DGrid_MatixManager.SelectedItem as Base_Point;
if (point == null) return;
point.IsEnable = !point.IsEnable;
ComnMethod.Message("操作成功");
}
private void MItem_StopChange_Click(object sender, RoutedEventArgs e)
{
var point = DGrid_MatixManager.SelectedItem as Base_Point;
if (point == null) return;
point.IsStop = !point.IsStop;
ComnMethod.Message("操作成功");
}
private void DGrid_HuahengStaion_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
}
}
}