WinTaskManager.xaml.cs
8.34 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
using XingYe_ACS.BaseStruct;
using XingYe_ACS.Business;
using XingYe_ACS.Common;
using XingYe_ACS.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace XingYe_ACS.UI
{
/// <summary>
/// WinTaskManager.xaml 的交互逻辑
/// </summary>
public partial class WinTaskManager : Window
{
public WinTaskManager()
{
InitializeComponent();
}
/// <summary>
/// 任务界面加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DGrid_Tasks.ItemsSource = App.TaskList;
}
/// <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();
}
/// <summary>
/// 任务清除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MItem_TaskClear_Click(object sender, RoutedEventArgs e)
{
try
{
if (MessageBox.Show("请确认是否删除任务?\n删除任务后,需记录信息,到WMS处理订单!", "警告", MessageBoxButton.YesNo) == MessageBoxResult.No) return;
if (DGrid_Tasks.SelectedItem == null) return;
FTask task = DGrid_Tasks.SelectedItem as FTask;
if (task == null) return;
Agv agv = App.AgvList.FirstOrDefault(a => a.strAgvNo == task.strTaskAgv);
string sqlDelete = string.Format("DELETE FROM T_SonTask WHERE strTaskNo = '{0}';", task.strTaskNo);
foreach (SonTask sonTask in task.sonTaskList)
{
sqlDelete += string.Format("DELETE FROM T_Base_PathPoint WHERE intSonTaskNo = '{0}';", sonTask.intSonTaskNo);
}
bool sqlResult = DbHelperSQL.SqlTransOperator(sqlDelete);
if (!sqlResult)
{
MessageBox.Show("子任务数据库清除失败");
return;
}
task.strEndTime = DateTime.Now.ToString();
task.taskState = EnumMsg.ErrMsg.手动删除任务.ToString();
bool isUpdateFTaskResult = UpdateManage.UpdateFTask(task);
if (task.strTaskAgv != "") UpdateManage.InsertAgvMilage(task);
if (!isUpdateFTaskResult)
{
MessageBox.Show("主任务数据库清除失败");
return;
}
CServiceImpl.ToWebTaskRefresh(task, 99);
App.AppDispatcher.Invoke(new Action(() =>
{
App.TaskList.Remove(task);
}));
if (agv != null && agv.agvTask == task) agv.agvTask = null;
if (agv != null && agv.strChooseStation != "")
{
UpdateManage.UpdateAgvMsg(agv);
Station station = App.StationList.Find(a => a.strStationNo == agv.strChooseStation);
station.isLocked = false;
UpdateManage.UpdateStation(station);
agv.strChooseStation = "";
}
}
catch (Exception Ex)
{
MessageBox.Show("任务清除:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
private void MItem_ErrHandle_Click(object sender, RoutedEventArgs e)
{
try
{
if (DGrid_Tasks.SelectedItem == null) return;
FTask task = DGrid_Tasks.SelectedItem as FTask;
if (task == null || !task.isTaskSubmit)
{
MessageBox.Show("任务尚未提交/任务为空,无法进行此操作!");
return;
}
if (MessageBox.Show("确定执行此操作!", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
bool isChangeAgv = false;
if (MessageBox.Show("是否需要更改Agv执行此任务", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
isChangeAgv = true;
}
//清除当前主任务下的所有子任务
string sqlDelete = string.Format("DELETE FROM T_SonTask WHERE strTaskNo = '{0}';", task.strTaskNo);
foreach (SonTask sonTask in task.sonTaskList)
{
sqlDelete += string.Format("DELETE FROM T_Base_PathPoint WHERE intSonTaskNo = '{0}';", sonTask.intSonTaskNo);
}
bool sqlResult = DbHelperSQL.SqlTransOperator(sqlDelete);
if (!sqlResult)
{
MessageBox.Show("子任务数据库清除失败");
return;
}
App.AppDispatcher.Invoke(new Action(() =>
{
task.sonTaskList.Clear();
}));
//更新主任务信息
task.isTaskSubmit = false;
task.strBeginTime = "";
if (isChangeAgv)
{
Agv agv = App.AgvList.First(a => a.strAgvNo == task.strTaskAgv);
agv.agvTask = null;
}
task.strTaskAgv = isChangeAgv ? "" : task.strTaskAgv;
bool isUpdateFTaskResult = UpdateManage.UpdateFTask(task);
if (isUpdateFTaskResult)
{
MessageBox.Show("异常处理成功!");
}
}
}
catch (Exception Ex)
{
MessageBox.Show("异常处理:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
private void MItem_TaskUpdate_Click(object sender, RoutedEventArgs e)
{
try
{
//if (DGrid_Tasks.SelectedItem == null) return;
//FTask task = DGrid_Tasks.SelectedItem as FTask;
//if (task == null || task.isTaskSubmit)
//{
// MessageBox.Show("任务已提交/任务为空,无法进行此操作!");
// return;
//}
//if (task.taskType != EnumMsg.TaskType.配送出库)
//{
// MessageBox.Show("只能更新出库任务站台!");
// return;
//}
//int index = new Random().Next(0,App.StationList.FindAll(a => a.isEnable && a.stationType == EnumMsg.StationType.出库站台).Count);
//Station station = App.StationList.FindAll(a => a.isEnable && a.stationType == EnumMsg.StationType.出库站台)[index];
//task.strStationNo = station.strStationNo;
//task.endPoint = App.PointList.Find(a => a.strBarcode == station.strBarcode);
//bool isUpdateResult = UpdateManage.UpdateFTask(task);
//if (!isUpdateResult)
//{
// MessageBox.Show("更新任务站台失败");
//}
}
catch (Exception Ex)
{
MessageBox.Show("更新任务站台出现异常:" + Ex.Message.Replace(Environment.NewLine, ""));
}
}
}
}