StepTraceMaintainVM.cs
8.4 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
using HHECS.Application.Enums;
using HHECS.Dal;
using HHECS.Dal.Repository;
using HHECS.DAL.Repository;
using HHECS.Infrastructure.CommonHelper;
using HHECS.Model.Entities;
using HHECS.WinCommon.ViewModel;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Windows;
using MessageBox = HandyControl.Controls.MessageBox;
namespace HHECS.WinClient.View.TaskInfo
{
public class StepTraceMaintainVM : VMBase
{
public string Id { get; set; }
public string ProductCode { get; set; }
public string NowProcessRoute { get; set; }
public string nowStation;
public string NowStation
{
get { return nowStation; }
set { nowStation = value; OnPropertyChanged(nameof(NowStation)); }
}
public string NextProcessRoute { get; set; }
public string nextStation;
public string NextStation
{
get { return nextStation; }
set { nextStation = value; OnPropertyChanged(nameof(NextStation)); }
}
public string status;
public string Status
{
get { return status; }
set { status = value; OnPropertyChanged(nameof(Status)); }
}
public Dictionary<string, object> ProcessRoutes { get; set; }
public Dictionary<string, object> Statuss { get; set; }
public Dictionary<string, object> Stations { get; set; }
public Dictionary<string, object> LineCodes { get; set; }
List<Equipment> WorkStations { get; set; } = new List<Equipment>();
List<Line> Lines { get; set; } = new List<Line>();
CutPlanDetail TaskModel;
BusWorkOrderDetail busWorkOrderDetail;
List<BaseProcessRouteDetail> processRouteDetails { get; set; } = new List<BaseProcessRouteDetail>();
CutPlanDetailRepository cutPlanTaskRepository = new CutPlanDetailRepository();
BusWorkOrderDetailRepository BusWorkOrderDetailRepository = new BusWorkOrderDetailRepository();
BaseStepTraceRepository stepTraceRepository = new BaseStepTraceRepository();
public StepTraceMaintainVM(int id)
{
Id = id.ToString();
TaskModel = cutPlanTaskRepository.Where(u => u.Id == Convert.ToInt32(Id)).First();
busWorkOrderDetail = BusWorkOrderDetailRepository.Where(t => t.BarCode == TaskModel.BarCode && t.OprSequenceCode == "Cut").First();
var result1 = App.TaskService.GetEquipments(t => true);
if (result1.Success)
{
WorkStations = result1.Data.Where(t => t.LineCode == App.LineCode && t.EquipmentTypeId != 68).ToList();
//WorkStations.ForEach(t => { Stations.Add(t.Name, t.Id); });
Stations = WorkStations.ToDictionary(t => t.Name, x => (object)x.Code);
}
//var result = App.TaskService.GetProcessRouteDetails(t => t.ProductCode == ProductCode);
//if (result.Success)
//{
// processRouteDetails = result.Data;
// ProcessRoutes = result.Data.ToDictionary(t => t.OprSequenceName, x => (object)x.Id);
//}
//var result2 = App.TaskService.GetLines(t => true);
//if (result2.Success)
//{
// Lines = result2.Data;
// LineCodes = result2.Data.ToDictionary(t => t.lineName, x => (object)x.lineCode);
//}
var statu = EnumHelper.EnumListDic<CutPlanDetailState>();
Statuss = statu;
//myComboBox.SelectedItem = "Option 2";
}
public void EditProductId()
{
if (string.IsNullOrWhiteSpace(ProductCode))
{
MessageBox.Show($"请选择一个产品");
return;
}
//TaskModel.ProductCode = ProductCode;
var res = cutPlanTaskRepository.Update(TaskModel);
if (res > 0)
{
MessageBox.Show($"产品维护成功");
}
else
{
MessageBox.Show($"产品维护失败");
}
}
/// <summary>
/// 下个工序维护
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void EditNextStepId()
{
string str = "0";
if (MessageBox.Show($"任务{Id}是否清空下道工位?", "注意", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
//TaskModel.NextProcessRouteDetailId = Convert.ToInt32(str);
var res = cutPlanTaskRepository.Update(TaskModel);
if (res > 0)
{
MessageBox.Show($"任务{TaskModel.Id}清空下道工位成功");
}
else
{
MessageBox.Show($"任务{TaskModel.Id}清空失败");
}
}
}
/// <summary>
/// 下个工位维护
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void EditNextStationId()
{
string str = "0";
if (MessageBox.Show($"任务{TaskModel.Id}是否清空下道工位?", "注意", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
// TaskModel.NextStation = NextStation;
var res = cutPlanTaskRepository.Update(TaskModel);
if (res > 0)
{
MessageBox.Show($"任务{TaskModel.Id}清空下道工位成功");
}
else
{
MessageBox.Show($"任务{TaskModel.Id}清空失败");
}
}
}
/// <summary>
/// 工序维护
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void EditStepId()
{
}
/// <summary>
/// 工位维护
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void EditStationId(bool isNow = true)
{
//if (string.IsNullOrWhiteSpace(NowStation))
//{
// MessageBox.Show($"请选择一个工位");
// return;
//}
if (isNow)
{
// TaskModel.NowStation = NowStation;
}
else
{
// TaskModel.NextStation = NextStation;
}
var res = cutPlanTaskRepository.Update(TaskModel);
if (res > 0)
{
MessageBox.Show($"工位维护成功");
}
else
{
MessageBox.Show($"工位维护失败");
}
}
/// <summary>
/// 状态维护
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void EditStatus()
{
//if (string.IsNullOrWhiteSpace(Status))
//{
// MessageBox.Show("请先选中需要更改的状态");
// return;
//}
if (!Enum.TryParse(Status.ToString(), out CutTaskStatus newStatus))
{
MessageBox.Show($"状态:{Status}无效");
return;
}
//if (TaskModel.Status >= StepTraceStatus.生产完成.GetIndexInt())
//{
// MessageBox.Show("任务已经完成,不能修改数据");
// return;
//}
if (TaskModel.CutState == (int)CutPlanDetailState.切割完成)
{
busWorkOrderDetail.State = 100;
BusWorkOrderDetailRepository.Update(busWorkOrderDetail);
}
//原來任務狀態
int oldStatus = TaskModel.CutState;
TaskModel.CutState = (int)newStatus;
TaskModel.UpdateBy = App.User.UserCode;
TaskModel.UpdateTime = DateTime.Now;
try
{
cutPlanTaskRepository.Update(TaskModel);
MessageBox.Show($"更改任务{TaskModel.Id}状态成功");
}
catch (Exception ex)
{
TaskModel.CutState = oldStatus;
MessageBox.Show($"更改任务{TaskModel.Id}状态,出现异常:{ex.Message}");
}
}
}
}