schangxiang@126.com
2025-01-08 4e475294999e7053036cc162de388010f6ee3132
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
using iWare_SCADA_BusinessLogical;
using iWare_SCADA_BusinessLogical.BLL;
using iWare_SCADA_BusinessLogical.BLL.Important;
using iWare_SCADA_BusinessLogical.Utils;
using iWare_SCADA_Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.IO;
using System.Linq;
 
namespace iWare_SCADA_Test
{
    [TestClass]
    public class UnitTest1
    {
 
 
        [TestMethod]
        public void TestMethoEntityValidati2222zzz()
        {
            var hour = DateTime.Now.Hour;
            if (!(hour == 1 || hour == 3 || hour == 5 || hour == 6))
            {
                var ss = "";
            }
            else
            {
                var dd = "";
            }
        }
 
        [TestMethod]
        public void TestMethoEntityValidatizzz()
        {
            try
            {
                WorkPieceLog aa = null;
                using (DbModel db = new DbModel())
                {
                    aa = db.WorkPieceLog.Where(x => x.Id == 588877956636741).FirstOrDefault();
                }
 
                // aa.WorkPieceID = "DZ045L2409100102791PAT";
                var isRight = SystemBussinessHelper.ValidateIsRightWorkPieceID(aa.WorkPieceID);
                if (isRight)
                {
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                //var bb = dbEx.EntityValidationErrors.ToList();
                //var pp = bb.First().ValidationErrors.ToList();
                //var z = JsonConvert.SerializeObject(pp);
 
                var errorMessages =
                    dbEx.EntityValidationErrors
                        .SelectMany(validationResult => validationResult.ValidationErrors)
                        .Select(m => m.ErrorMessage);
 
                var fullErrorMessage = string.Join(", ", errorMessages);
 
                //throw new DbEntityValidationException(exceptionMessage, exception.EntityValidationErrors);
            }
            catch (Exception)
            {
 
                throw;
            }
 
 
        }
 
        [TestMethod]
        public void TestMethoEntityValidationErrors()
        {
            var aa = "";
            WorkPieceInfo cur_db_info = new WorkPieceInfo()
            {
                WorkingProcedureCurrent = "OP05"
            };
 
            try
            {
                using (DbModel db = new DbModel())
                {
                    db.WorkPieceInfo.Add(cur_db_info);
                    db.SaveChanges();
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                //var bb = dbEx.EntityValidationErrors.ToList();
                //var pp = bb.First().ValidationErrors.ToList();
                //var z = JsonConvert.SerializeObject(pp);
 
                var errorMessages =
                    dbEx.EntityValidationErrors
                        .SelectMany(validationResult => validationResult.ValidationErrors)
                        .Select(m => m.ErrorMessage);
 
                var fullErrorMessage = string.Join(", ", errorMessages);
 
                //throw new DbEntityValidationException(exceptionMessage, exception.EntityValidationErrors);
            }
            catch (Exception)
            {
 
                throw;
            }
 
 
        }
 
 
        [TestMethod]
        public void TestMetho22()
        {
            var aa = "";
            WorkPieceInfo cur_db_info = new WorkPieceInfo()
            {
                WorkingProcedureCurrent = "OP05"
            };
            WorkPieceInfoManager.SetWorkingProcedureCurrentForOP10(cur_db_info, ref aa);
        }
 
        [TestMethod]
        public void TestMethod1()
        {
 
            //计算大头孔直径,大头孔直径=(大头上面X方向直径+大头上面Y方向直径+大头下面X方向直径+大头下面Y方向直径)/4
            List<decimal> valueList = new List<decimal>() {
                                                        SystemHelper.GetDecimal(""),
                                                        SystemHelper.GetDecimal("sss"),
                                                        SystemHelper.GetDecimal("12.365"),
                                                        SystemHelper.GetDecimal("201.24557"),
                                                        SystemHelper.GetDecimal("100"),
                                                    };
            var bb = SystemHelper.CalcDecimalAvg(valueList, 3);
            Assert.Fail();
        }
 
        [TestMethod]
        public void xx()
        {
            string path = ConfigHelper.GetConfigString("OP80QualityData_Test");//OP80的地址
 
            var newFiles = FileHelper.DetectNewFilesCSV(path, 300, DateTime.Now.AddDays(-10), DateTime.Now.AddDays(1));
 
            foreach (System.IO.FileInfo file in newFiles)
            {
                File.Move(file.FullName, "../CA4GC20TD_COPY/" + file.Name);//移动
            }
        }
 
 
        [TestMethod]
        public void bb()
        {
            var aa = "-2024-06-16_08_43_23__part_";
            var bb = aa.Split('-');
 
            string cc = bb[0];
        }
 
        [TestMethod]
        public void zzz()
        {
            WorkPieceLogMiddle logMiddle = new WorkPieceLogMiddle(
               )
            {
                WorkingProcedure = "OP30"
            }
            ;
            QualityDataInfo qualityData = new QualityDataInfo();
            //修改QualityDataInfo表 //重复收到质量信息,会覆盖之前的
            EntityPropHelper<WorkPieceLogMiddle, QualityDataInfo>.CopyProp(logMiddle, qualityData, WorkPieceInfoManager.GetQualityDataInfoUpdate(logMiddle, logMiddle.WorkingProcedure, logMiddle.MonitoringPoint));//指定修改字段
 
            string cc = "";
        }
 
        [TestMethod]
        public void pp()
        {
            Yitter.IdGenerator.IdGeneratorOptions options = new Yitter.IdGenerator.IdGeneratorOptions(1);
            Yitter.IdGenerator.YitIdHelper.SetIdGenerator(options);
 
            WorkPieceLogMiddle logMiddle = new WorkPieceLogMiddle(
              )
            {
                WorkingProcedure = "OP30",
                WorkPieceID = "DZ045L2406240103521TAS",
                UpdatedTime = DateTime.Now,
                QualityState = (int)QualityStateEnum.NG,
                QualityNoOk = (int)QualityNoOkEnum.OP30涨断工位力矩超差,
                QualityNoOkReason = QualityNoOkEnum.OP30涨断工位力矩超差.ToString(),
                MonitoringPoint = "",
                QualityStateStr = "NG"
            }
           ;
            string WorkingProcedure = logMiddle.WorkingProcedure;
            //根据质量数据判断是否合格/不合格 【Editby shaocx,2024-06-25】
            WorkPieceInfoManager.SetLogMiddleForQuality(ref logMiddle);
 
            //更新WorkPieceInfo表以及插入WorkPieceLog表和WorkPieceInfoLog表
            QualityInfoCompleteManager.QualityInfoComplete(logMiddle, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure));
 
 
            string cc = "";
        }
 
        [TestMethod]
        public void aaaaa()
        {
            //获取OP70未结束的工件列表
            var ooDateTime = Convert.ToDateTime("0001-01-01");
            List<WorkPieceProcess> noFinishWorkPieceProcessList = null;
            using (DbModel db = new DbModel())
            {
                var dateTime = DateTime.Now;
                noFinishWorkPieceProcessList = db.WorkPieceProcess.Where(x =>
                1 == 1
                  && x.WorkingProcedureCurrent == "OP70"
                  && x.EndTime == ooDateTime).ToList();
            }
 
 
            string cc = "";
        }
    }
}