分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-06-20 00ad010a45f2f58807eb0f4f70e2dcf66ef35085
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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Repositories;
using WIDESEA_WCS.WCSClient;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
using static WIDESEA_Comm.Wheel_trace;
 
namespace WIDESEA_WCS
{
    public class Wheel_info_trace
    {
        /// <summary>
        /// 查询车轮上线
        /// </summary>
        /// <param name="client"></param>
        public static void Wheel_online(PLCClient client)
        {
            VOLContext context = new VOLContext();
            Idt_info_traceRepository traceRepository = new dt_info_traceRepository(context);
            IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context);
            PropertyInfo[] propertyInfos = typeof(Wheel_online).GetProperties();
            var groups = client.itemGroups.Where(x => x.opratortype == "trace_online").OrderBy(x => x.Methods).ThenBy(x => x.name).GroupBy(x => x.Methods).ToList();
            foreach (var key in groups)
            {
                try
                {
                    Wheel_online StackerDBItem = new Wheel_online();
                    foreach (var propertyInfo in propertyInfos)
                    {
                        if (propertyInfo.Name == "Name")
                        {
                            StackerDBItem.Name = key.Key;
                        }
                        else
                        {
                            DBItemGroup group = key.FirstOrDefault(x => x.name == propertyInfo.Name);
                            if (group != null)
                            {
                                var readData = DBExtension.Read(group, client);
                                switch (propertyInfo.Name)
                                {
                                    case "oi_on":
                                        StackerDBItem.oi_on = Convert.ToByte(readData);
                                        break;
                                    case "o_wp_id":
                                        StackerDBItem.o_wp_id = Convert.ToString(readData);
                                        break;
                                    case "o_online_time":
                                        StackerDBItem.o_online_time = readData.ToString();
                                        break;
                                }
                            }
                        }
                    }
                    #region 替换老PCS时使用
                    if (/*StackerDBItem.oi_on == 1*/true)
                    {
                        if (string.IsNullOrEmpty(StackerDBItem.o_wp_id)) throw new Exception($"{StackerDBItem.Name}:SN号为空");
                        if (string.IsNullOrEmpty(StackerDBItem.o_online_time)) throw new Exception($"{StackerDBItem.Name}:上线时间为空");
                        var info = traceRepository.Find(x => x.trace_SN == StackerDBItem.o_wp_id).FirstOrDefault();
                        if (info != null) throw new Exception();
                        info = new dt_info_trace();
                        info.trace_SN = StackerDBItem.o_wp_id;
                        var time = DateTime.ParseExact(StackerDBItem.o_online_time, "yyyyMMddHHmmss", CultureInfo.CurrentCulture);
                        //var time1 = DateTime.ParseExact(StackerDBItem.o_online_time, "yyyyMMddHHmmss", new CultureInfo("zh-CN", true));
                        info.trace_status = "待加工";
                        info.trace_online_time = time;
                        info.trace_line_number = StackerDBItem.Name;
                        var Work = workinfoRepository.Find(x => x.SN == info.trace_SN && x.processCode == "17").FirstOrDefault();
                        if (Work != null)
                        {
                            info.trace_workOrder = Work.workOrder;
                            info.trace_productName = Work.productName;
                            info.trace_drawingNo = Work.drawingNo;
                            info.trace_heatBatchID = Work.heatBatchID;
                            info.trace_heatID = Work.heatID;
                            info.trace_billetID = Work.billetID.ToString();
                        }
                        traceRepository.Add(info, true);
                        //client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//信号复位
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    //client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//信号复位
                }
            }
        }
        /// <summary>
        /// 查询车轮加工
        /// </summary>
        /// <param name="client"></param>
        public static void Wheel_machine(PLCClient client)
        {
            VOLContext context = new VOLContext();
            Idt_info_traceRepository traceRepository = new dt_info_traceRepository(context);
            PropertyInfo[] propertyInfos = typeof(Wheel_Machine).GetProperties();
            var groups = client.itemGroups.Where(x => x.opratortype == "trace_Machine").OrderBy(x => x.Methods).ThenBy(x => x.name).GroupBy(x => x.Methods).ToList();
            foreach (var key in groups)
            {
                try
                {
                    Wheel_Machine StackerDBItem = new Wheel_Machine();
                    foreach (var propertyInfo in propertyInfos)
                    {
                        if (propertyInfo.Name == "Name")
                        {
                            StackerDBItem.Name = key.Key;
                        }
                        else
                        {
                            DBItemGroup group = key.FirstOrDefault(x => x.name == propertyInfo.Name);
                            if (group != null)
                            {
                                var readData = DBExtension.Read(group, client);
                                switch (propertyInfo.Name)
                                {
                                    case "oi_on":
                                        StackerDBItem.oi_on = Convert.ToByte(readData);
                                        break;
                                    case "o_wp_id":
                                        StackerDBItem.o_wp_id = Convert.ToString(readData);
                                        break;
                                    case "o_mach_start_time":
                                        StackerDBItem.o_mach_start_time = readData.ToString();
                                        break;
                                    case "o_mach_finish_time":
                                        StackerDBItem.o_mach_finish_time = readData.ToString();
                                        break;
                                    case "o_operator":
                                        StackerDBItem.o_operator = readData.ToString();
                                        break;
                                    case "o_shift":
                                        StackerDBItem.o_shift = readData.ToString();
                                        break;
                                    case "o_wp_status":
                                        StackerDBItem.o_wp_status = Convert.ToInt16(readData);
                                        break;
                                    case "o_wp_process":
                                        StackerDBItem.o_wp_process = Convert.ToInt16(readData);
                                        break;
                                }
                            }
                        }
                    }
                    #region 替换老PCS时使用
                    if (/*StackerDBItem.oi_on == 1*/true)
                    {
                        if (string.IsNullOrEmpty(StackerDBItem.o_wp_id)) throw new Exception($"{StackerDBItem.Name}:SN号为空");
                        var info = traceRepository.Find(x => x.trace_SN == StackerDBItem.o_wp_id).FirstOrDefault();
                        if (info != null)
                        {
                            if (!string.IsNullOrEmpty(StackerDBItem.o_mach_start_time))
                                info.trace_mach_start_time = DateTime.ParseExact(StackerDBItem.o_mach_start_time, "yyyyMMddHHmmss", CultureInfo.CurrentCulture);
                            if (!string.IsNullOrEmpty(StackerDBItem.o_mach_finish_time))
                                info.trace_mach_finish_time = DateTime.ParseExact(StackerDBItem.o_mach_finish_time, "yyyyMMddHHmmss", CultureInfo.CurrentCulture);
                            if (!string.IsNullOrEmpty(StackerDBItem.o_operator)) info.trace_operator = StackerDBItem.o_operator;
                            if (!string.IsNullOrEmpty(StackerDBItem.o_shift)) info.trace_shift = info.trace_shift;
                            info.trace_mach_statu = StackerDBItem.o_wp_status;
                            info.trace_process = StackerDBItem.o_wp_process;
                            info.trace_mach_number = StackerDBItem.Name;
                            traceRepository.Update(info, x => new { x.trace_mach_start_time, x.trace_mach_finish_time, x.trace_operator, x.trace_shift, x.trace_mach_statu, x.trace_process, x.trace_mach_number }, true);
                        }
                        //client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//信号复位
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    //client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//信号复位
                }
            }
        }
        /// <summary>
        /// 查询车轮下线
        /// </summary>
        /// <param name="client"></param>
        public static void Wheel_offline(PLCClient client)
        {
            VOLContext context = new VOLContext();
            Idt_info_traceRepository traceRepository = new dt_info_traceRepository(context);
            PropertyInfo[] propertyInfos = typeof(Wheel_offline).GetProperties();
            var groups = client.itemGroups.Where(x => x.opratortype == "trace_offline").OrderBy(x => x.Methods).ThenBy(x => x.name).GroupBy(x => x.Methods).ToList();
            foreach (var key in groups)
            {
                try
                {
                    Wheel_offline StackerDBItem = new Wheel_offline();
                    foreach (var propertyInfo in propertyInfos)
                    {
                        if (propertyInfo.Name == "Name")
                        {
                            StackerDBItem.Name = key.Key;
                        }
                        else
                        {
                            DBItemGroup group = key.FirstOrDefault(x => x.name == propertyInfo.Name);
                            if (group != null)
                            {
                                var readData = DBExtension.Read(group, client);
                                switch (propertyInfo.Name)
                                {
                                    case "oi_on":
                                        StackerDBItem.oi_on = Convert.ToByte(readData);
                                        break;
                                    case "o_wp_id":
                                        StackerDBItem.o_wp_id = Convert.ToString(readData);
                                        break;
                                    case "o_offline_time":
                                        StackerDBItem.o_offline_time = readData.ToString();
                                        break;
                                    case "o_direction":
                                        StackerDBItem.o_direction = Convert.ToByte(readData);
                                        break;
                                }
                            }
                        }
                    }
                    #region 替换老PCS时使用
                    if (/*StackerDBItem.oi_on == 1*/true)
                    {
                        if (string.IsNullOrEmpty(StackerDBItem.o_wp_id)) throw new Exception($"{StackerDBItem.Name}:SN号为空");
                        var info = traceRepository.Find(x => x.trace_SN == StackerDBItem.o_wp_id).FirstOrDefault();
                        if (info != null)
                        {
                            if (!string.IsNullOrEmpty(StackerDBItem.o_offline_time))
                                info.trace_offline_time = DateTime.ParseExact(StackerDBItem.o_offline_time, "yyyyMMddHHmmss", CultureInfo.CurrentCulture);
                            info.trace_direction = StackerDBItem.o_direction.ToString();
                            //info.trace_line_number = info.trace_line_number + StackerDBItem.Name;
                            traceRepository.Update(info, x => new { x.trace_offline_time, x.trace_direction }, true);
                        }
                        //client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//信号复位
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    //client.Write(key.FirstOrDefault(x => x.name == "oi_on").dbAddress, (byte)0);//信号复位
                }
            }
        }
 
 
    }
}