StepTraceInfoVM.cs
6.91 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
using HHECS.Application.Enums;
using HHECS.BllModel;
using HHECS.Dal;
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 StepTraceInfoVM : VMBase
{
public PageInfo PageInfo { get; set; } = new PageInfo();
public string Id { get; set; }
public string FirstStatus { get; set; }
public string LastStatus { get; set; }
public string LineCode { get; set; }
public string NowStation { get; set; }
public string NextStation { get; set; }
public DateTime? StartTime { get; set; } = DateTime.Now.Date.AddDays(-7);
public DateTime? EndTime { get; set; } = DateTime.Now.Date.AddDays(2).AddSeconds(-1);
public Dictionary<string, object> Stations { get; set; }
public Dictionary<string, object> LineCodes { get; set; }
public Dictionary<string, object> Statuss { get; set; }
List<BaseProcessRouteDetail> ProcessRouteDetails { get; set; } = new List<BaseProcessRouteDetail>();
List<BaseWorkStation> WorkStations { get; set; } = new List<BaseWorkStation>();
List<BaseStepTrace> StepTraces { get; set; } = new List<BaseStepTrace>();
List<Line> Lines { get; set; } = new List<Line>();
public StepTraceInfoVM()
{
var result1 = App.TaskService.GetStations(t => true);
if (result1.Success)
{
WorkStations = result1.Data;
Stations = result1.Data.ToDictionary(t => t.WorkStationName, x => (object)x.Id);
}
var result = App.TaskService.GetLines(t => true);
if (result.Success)
{
Lines = result.Data;
LineCodes = result.Data.ToDictionary(t => t.lineName, x => (object)x.lineCode);
}
var statu = EnumHelper.EnumListDicString<StepTraceStatus>("全部", "");
Statuss = statu;
ProcessRouteDetails = DALHelper.GetFreeSql().GetRepository<BaseProcessRouteDetail>().Where(x => true).ToList();
}
public Expression<Func<BaseStepTrace, bool>> GetStepTraceExpression()
{
Expression<Func<BaseStepTrace, bool>> filter = a => true;
if (!string.IsNullOrWhiteSpace(Id))
{
filter = filter.And(a => a.Id.ToString() == Id);
}
if (!string.IsNullOrWhiteSpace(FirstStatus))
{
filter = filter.And(a => a.Status.ToString() == FirstStatus);
}
if (!string.IsNullOrWhiteSpace(LastStatus))
{
filter = filter.And(a => a.Status.ToString() == LastStatus);
}
if (!string.IsNullOrWhiteSpace(LineCode))
{
filter = filter.And(a => a.LineId.ToString() == LineCode);
}
if (StartTime != null)
{
filter = filter.And(a => a.LineInTime >= StartTime);
}
if (EndTime != null)
{
filter = filter.And(a => a.LineInTime <= EndTime);
}
return filter;
}
public void Query()
{
Expression<Func<BaseStepTrace, bool>> filter = GetStepTraceExpression();
var result = App.TaskService.GetAllStepTraces(filter, PageInfo.PageIndex, PageInfo.PageSize, out long totalCount);
if (result.Success)
{
PageInfo.TotalCount = totalCount;
var stepTraces = result.Data;
stepTraces.ForEach(t =>
{
//t.WoTypeDesc = WoTypes[t.WoType];
t.ProcessRouteDetail = ProcessRouteDetails.FirstOrDefault(a => a.Id == t.ProcessRouteDetailId);
t.NextProcessRouteDetail = ProcessRouteDetails.FirstOrDefault(a => a.Id == t.NextProcessRouteDetailId);
t.StationIdVM = WorkStations?.FirstOrDefault(a => a.Id == t.StationId);
t.NextStationIdVM = WorkStations?.FirstOrDefault(a => a.Id == t.NextStationId);
t.LineVM = Lines.FirstOrDefault(a => a.Id == t.LineId);
});
StepTraces = stepTraces.OrderByDescending(pet => pet.Id).ToList();
}
else
{
MessageBox.Show($"查询失败:{result.Msg}", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
public void Complete(List<BaseStepTrace> stepTraces)
{
if (stepTraces == null || stepTraces.Count() != 1)
{
MessageBox.Show("请选中一条任务后继续", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
{
var stepTrace = stepTraces[0];
if (MessageBox.Show($"是否要强制完成在制品:{stepTrace.Id};这可能导致未知异常发生!", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
var result = App.TaskService.StepTraceExceptionOver(stepTrace.Id, App.User.UserCode);
if (result.Success)
{
MessageBox.Show($"完成在制品{stepTrace.Id}成功");
Query();
}
else
{
MessageBox.Show($"完成在制品{stepTrace.Id}失败:{result.Msg}");
}
}
}
}
/// <summary>
/// 任务维护
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Maintain(List<BaseStepTrace> stepTraces)
{
if (stepTraces == null || stepTraces.Count() != 1)
{
MessageBox.Show("请选中一条任务后继续", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
{
WinStepTraceMaintain winStepTraceMaintain = new WinStepTraceMaintain(stepTraces[0].Id);
winStepTraceMaintain.ShowDialog();
Query();
}
}
//public void QueryCarTask(List<BaseStepTrace> stepTraces)
//{
// if (stepTraces == null || stepTraces.Count() != 1)
// {
// MessageBox.Show("请选中一条任务后继续", "注意", MessageBoxButton.OK, MessageBoxImage.Warning);
// }
// else
// {
// var winCarTaskInfo = new WinCarTaskInfo(stepTraces[0].Id)
// {
// //Owner = this.Owner
// };
// winCarTaskInfo.Show();
// }
//}
}
}