tx
2025-04-10 2538101febc78f525945da72c7cdcb2589f9e6ea
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
using NPOI.HSSF.UserModel;
using System;
using System.IO;
using System.Linq;
 
 
namespace TProduct.DataFile.PumpReport
{
    /// <summary>
    /// TPump里面的V2模版(来源湖南)
    /// </summary>
    public class TestReportFileT2 : TestReportFileExcelBase
    {
        public TestReportFileT2() { }
 
        protected string _strExcelFile = null;
        public override string Create(string strFilePath, TProduct.Model.DispStautInfo infoDelegete)
        {
            //初始化文件
            var message = InitialFile(strFilePath);
            if (!string.IsNullOrEmpty(message))
            {
                infoDelegete("泵数据表V1 生成失败,Error:" + message, 1);
                return message;
            }
            this._strExcelFile = strFilePath;
 
            try
            {
                using (FileStream fileStream = new FileStream(_strExcelFile, FileMode.Open, FileAccess.ReadWrite))
                {
                    _theBookHander = new HSSFWorkbook(fileStream);
                }
 
                if (_theBookHander == null)
                {
                    infoDelegete("泵数据表V1 生成失败,Error:未能打开模版Excel文件", 1);
                    return "未能打开模版Excel文件";
                }
 
 
                WritePage封面(infoDelegete);
                WritePage1_检查报告(infoDelegete);
                WritePage2_分析报告(infoDelegete);
                WritePage3_试验报告(infoDelegete);
                WritePage4_性能测试(infoDelegete);
 
                using (var fileStream = new FileStream(_strExcelFile, FileMode.Create))
                {
                    _theBookHander.Write(fileStream);
                }
            }
            catch (Exception ex)
            {
                infoDelegete("泵数据表V1 生成失败,Error:" + ex.Message, 1);
                return ex.Message;
            }
            finally
            {
                //workSheet.Save();
                //workSheet.Close();
                //workSheet = null;
            }
 
            return null;
        }
 
        public override string GetTemplateFilePath()
        {
            return System.IO.Path.Combine(
              TProduct.DataFolderParas.FullPath,
              "PumpFeatReportTemplate",
              "P_CN_T2_V1.xls");
        }
 
        //初始化文件
        private string InitialFile(string strFilePath)
        {
            string strTemplateFile = GetTemplateFilePath();
            if (!File.Exists(strTemplateFile))
            {
                return strTemplateFile + ": 模板文件被非法删除";
            }
 
            if (File.Exists(strFilePath))
            {
                File.Delete(strFilePath);
            }
 
            File.Copy(strTemplateFile, strFilePath, true);
 
 
            return null;
        }
 
 
 
        private bool WritePage封面(TProduct.Model.DispStautInfo infoDelegete)
        {
            NPOI.SS.UserModel.ISheet sheet封面 = _theBookHander.GetSheetAt(0);
            if (sheet封面 == null)
            {
                infoDelegete(" 生成失败,Error:未发现模版封面页", 1);
                return false;
            }
            //产品名称
            SetCellValue(sheet封面, 1, "F", this._testProject.ReportFileNO);
            //产品名称
            SetCellValue(sheet封面, 10, "B", this._currentPart.Name);
            //型号
            SetCellValue(sheet封面, 11, "B", this._currentPump.Name);
 
            //生产单位 / 受检单位
            var manufacture_name = new BLL.ManufacturerBase().GetNameByID(this._currentPart.ManufacturerID);
            SetCellValue(sheet封面, 13, "B", manufacture_name);
            //送检单位 / 委托单位
            var sender_name = new BLL.Senderbase().GetNameByID(this._currentPart.SenderID);
            SetCellValue(sheet封面, 14, "B", sender_name);
 
 
            sheet封面.ForceFormulaRecalculation = true;
 
            return true;
        }
 
        private bool WritePage1_检查报告(TProduct.Model.DispStautInfo infoDelegete)
        {
            NPOI.SS.UserModel.ISheet sheet检查报告 = _theBookHander.GetSheetAt(1);
            if (sheet检查报告 == null)
            {
                infoDelegete(" 生成失败,Error:未发现模版封面页", 1);
                return false;
            }
            //文件编号
            SetCellValue(sheet检查报告, 3, "B", this._testProject.ReportFileNO);
            //产品名称
            SetCellValue(sheet检查报告, 4, "B", this._currentPart.Name);
            //型号
            SetCellValue(sheet检查报告, 4, "D", this._currentPump.Name);
            //型号
            SetCellValue(sheet检查报告, 5, "B", this._currentPart.Code);
            //收样日期
            SetCellValue(sheet检查报告, 4, "D", this._currentPart.SendTime);
 
            var manufacture = new BLL.ManufacturerBase().GetByID(this._currentPart.ManufacturerID);
            var sender = new BLL.Senderbase().GetByID(this._currentPart.SenderID);
            var senderuser = new BLL.LoginUser().GetByID(_currentPart.SenderID);
            //生产单位 / 受检单位
            SetCellValue(sheet检查报告, 8, "B", manufacture?.FullName == null ? manufacture?.ShortName : manufacture?.FullName);
            //生产单位地址
            SetCellValue(sheet检查报告, 9, "B", manufacture?.Address);
            //送检单位 / 委托单位
            SetCellValue(sheet检查报告, 10, "B", sender?.FullName == null ? sender?.ShortName : sender?.FullName);
            //送检人
            SetCellValue(sheet检查报告, 10, "D", senderuser?.RealName);
            //送检单位地址 / 委托单位地址
            SetCellValue(sheet检查报告, 11, "B", sender?.Address);
 
            //送检日期
            SetCellValue(sheet检查报告, 11, "D", this._testProject.CreateTime.ToString("yyyy-MM-dd"));
 
            //送检日期
            SetCellValue(sheet检查报告, 22, "A", this._testProject.JudgeResult.ToString());
            sheet检查报告.ForceFormulaRecalculation = true;
 
            return true;
        }
 
        private bool WritePage2_分析报告(TProduct.Model.DispStautInfo infoDelegete)
        {
            NPOI.SS.UserModel.ISheet sheet分析报告 = _theBookHander.GetSheetAt(2);
            if (sheet分析报告 == null)
            {
                infoDelegete(" 生成失败,Error:未发现模版封面页", 1);
                return false;
            }
 
            var flow = TProduct.Common.PumpTestJudgeHelper.ConnectFlow(_testJudgeResults);
            var head = TProduct.Common.PumpTestJudgeHelper.ConnectHead(_testJudgeResults);
 
            //产品名称
            SetCellValue(sheet分析报告, 1, "B", this._testProject.ReportFileNO);
 
            SetCellValue(sheet分析报告, 4, "B", "m³/h");
            SetCellValue(sheet分析报告, 5, "B", "m");
 
            SetCellValue(sheet分析报告, 4, "C", flow.RequestPercent);
            SetCellValue(sheet分析报告, 5, "C", head.RequestPercent);
 
 
            SetCellValue(sheet分析报告, 4, "D", flow.ItemJudgResultName);
            SetCellValue(sheet分析报告, 5, "D", head.ItemJudgResultName);
 
            if (flow.IsQualified || head.IsQualified)
                SetCellValue(sheet分析报告, 4, "E", "合格");
            else
                SetCellValue(sheet分析报告, 4, "E", "不合格");
 
            var eta = _testJudgeResults.Find(x => x.TargeType == Model.eTestJudgeTargetType.泵效率);
            if (eta != null)
            {
                SetCellValue(sheet分析报告, 6, "C", eta.RequestPercent);
                SetCellValue(sheet分析报告, 6, "D", eta.ItemJudgResultName);
                if (eta.IsQualified)
                    SetCellValue(sheet分析报告, 6, "E", "合格");
                else SetCellValue(sheet分析报告, 6, "E", "不合格");
            }
 
 
            sheet分析报告.ForceFormulaRecalculation = true;
 
            return true;
        }
 
        private bool WritePage3_试验报告(TProduct.Model.DispStautInfo infoDelegete)
        {
            NPOI.SS.UserModel.ISheet sheet试验报告 = _theBookHander.GetSheetAt(3);
            if (sheet试验报告 == null)
            {
                infoDelegete(" 生成失败,Error:未发现模版封面页", 1);
                return false;
            }
 
 
 
            //产品名称
            SetCellValue(sheet试验报告, 2, "C", this._testProject.ReportFileNO);
            //产品型号
            SetCellValue(sheet试验报告, 3, "C", this._currentPump.Name);
            //产品编号
            SetCellValue(sheet试验报告, 3, "J", this._currentPart.Code);
            //产品名称
            SetCellValue(sheet试验报告, 4, "C", this._currentPumpSeries.Name);
            //检验日期
            SetCellValue(sheet试验报告, 4, "J", this._testProject.CreateTime.ToString("yyyy-MM-dd"));
            //制造单位
            var mfName = new BLL.ManufacturerBase().GetNameByID(_currentPart.ManufacturerID);
            SetCellValue(sheet试验报告, 5, "J", mfName);
 
            if (this._ratedParas != null)
            {
                SetCellValue(sheet试验报告, 8, "A", _ratedParas.Q);
                SetCellValue(sheet试验报告, 8, "C", _ratedParas.H);
                if (this._currentPump.Ratedn.HasValue)
                    SetCellValue(sheet试验报告, 8, "E", this._currentPump.Ratedn.Value);
                SetCellValue(sheet试验报告, 8, "I", _ratedParas.E);
                SetCellValue(sheet试验报告, 8, "G", _ratedParas.P);
                if (_ratedParas.NPSHr.HasValue && _ratedParas.NPSHr > 0)
                    SetCellValue(sheet试验报告, 8, "L", _ratedParas.NPSHr.Value);
            }
 
            if (_testJudgeResults != null && _testJudgeResults.Count > 0)
            {
                var judge_flow = TProduct.Common.PumpTestJudgeHelper.ConnectFlow(_testJudgeResults);
                var judge_head = TProduct.Common.PumpTestJudgeHelper.ConnectHead(_testJudgeResults);
                var eta_result = _testJudgeResults.Find(x => x.TargeType == Model.eTestJudgeTargetType.泵效率);
 
 
                SetCellValue(sheet试验报告, 13, "A", Math.Round(judge_flow.JudgeValue, 2));
                SetCellValue(sheet试验报告, 13, "C", Math.Round(judge_head.JudgeValue, 2));
                if (this._currentPump.Ratedn.HasValue)
                    SetCellValue(sheet试验报告, 13, "E", this._currentPump.Ratedn.Value);
                if (eta_result != null)
                {
                    SetCellValue(sheet试验报告, 13, "I", Math.Round(eta_result.JudgeValue, 2));
                    var power = Eventech.Common.PumpParaHelper.CalculateP(Math.Round(judge_flow.JudgeValue, 2),
                        Math.Round(judge_head.JudgeValue, 2), Math.Round(eta_result.JudgeValue, 2));
                    SetCellValue(sheet试验报告, 13, "G", Math.Round(power, 2));
                }
 
                SetCellValue(sheet试验报告, 17, "D", Math.Round(Math.Abs(_ratedParas.Q - judge_flow.JudgeValue), 2));
                SetCellValue(sheet试验报告, 17, "F", "m³/h");
 
                SetCellValue(sheet试验报告, 17, "K", Math.Round(Math.Abs(_ratedParas.H - judge_head.JudgeValue), 2));
 
                bool isQualifyAll = true;
                if (judge_flow.IsQualified || judge_head.IsQualified)
                    SetCellValue(sheet试验报告, 20, "D", "合格");
                else
                {
                    SetCellValue(sheet试验报告, 20, "D", "不合格");
                    isQualifyAll = false;
                }
 
 
                if (eta_result != null)
                {
                    SetCellValue(sheet试验报告, 18, "D", Math.Round(eta_result.JudgeValue, 2));
 
                    if (eta_result.IsQualified)
                        SetCellValue(sheet试验报告, 20, "K", "合格");
                    else
                    {
                        SetCellValue(sheet试验报告, 20, "K", "不合格");
                        isQualifyAll = false;
                    }
                }
 
                if (isQualifyAll)
                    SetCellValue(sheet试验报告, 26, "A", "合格");
                else
                {
                    SetCellValue(sheet试验报告, 26, "A", "不合格");
                    isQualifyAll = false;
                }
 
                //曲线分析
                if (_curveExpressQH != null)
                {
                    var min_flow = (from x in this._allRecords select x.CorrectPtQ).Min();
                    //最小流量点流量
                    SetCellValue(sheet试验报告, 18, "K", Math.Round(min_flow, 2));
 
                    var min_flow_head = Eventech.Common.FitCurveHelper.GetFitPointY(_curveExpressQH, Math.Round(min_flow, 2));
                    //最小流量点流量
                    SetCellValue(sheet试验报告, 19, "D", Math.Round(min_flow_head, 2));
 
                    //最高扬程(m)
                    var max_head_pt = Eventech.Common.FitCurveHelper.GetMaxPoint(_curveExpressQH, 200);
                    SetCellValue(sheet试验报告, 19, "K", Math.Round(max_head_pt.Y, 2));
                }
 
            }
 
 
            sheet试验报告.ForceFormulaRecalculation = true;
 
            return true;
        }
 
        private bool WritePage4_性能测试(TProduct.Model.DispStautInfo infoDelegete)
        {
            NPOI.SS.UserModel.ISheet sheet性能测试 = _theBookHander.GetSheetAt(4);
            if (sheet性能测试 == null)
            {
                infoDelegete(" 生成失败,Error:未发现模版封面页", 1);
                return false;
            }
            var sdName = new BLL.Senderbase().GetNameByID(_currentPart.SenderID);
            //产品名称
            SetCellValue(sheet性能测试, 1, "B", this._testProject.ReportFileNO);
            //产品名称
            SetCellValue(sheet性能测试, 2, "B", sdName);
            //产品名称
            SetCellValue(sheet性能测试, 3, "B", _currentPump.Name);
 
            //送检日期
            SetCellValue(sheet性能测试, 3, "H", this._testProject.CreateTime.ToString("yyyy-MM-dd"));
 
            if (this._allMonitorPoints == null || this._allMonitorPoints.Count() == 0)
                return false;
 
            if (this._allRecords == null || this._allRecords.Count() == 0)
                return false;
 
            if (_featChartImage != null)
            {
                _featChartImage.SetDockType(PumpGraph.Picture.FeatChart.eDockType.测试报告, 769, 850);
                var image1 = _featChartImage.CreateImage();
                //System.Drawing.Image img = SPump.DataFile.BASE.NPIOExcelHelper.CreateNewLargeImage(image1, width, height);
 
                AddImage1(sheet性能测试, 3, "A", 5, "K", image1);//添加图片
            }
 
            if (this._allMonitorPoints == null || this._allMonitorPoints.Count() == 0)
                return false;
 
            if (this._allRecords == null || this._allRecords.Count() == 0)
                return false;
            var sort_allRecords = (from x in this._allRecords orderby x.CorrectPtQ select x).ToList();
            SetCellValue(sheet性能测试, 8, "A", "m³/h");
            SetCellValue(sheet性能测试, 8, "G", "m³/h");
            //流量
            var mp_flow = this._allMonitorPoints.Find(x => x.MonitorType == Model.eMonitorType.流量);
            if (mp_flow != null)
            {
                for (var index = 0; index < sort_allRecords.Count(); index++)
                {
                    var rs = sort_allRecords[index].MonitorRecordList.Find(x => x.ID == mp_flow.ID);
                    if (rs != null)
                        SetCellValue(sheet性能测试, 9 + index, "A", rs.Value);
                }
            }
 
            //入口压力 
            var mp_inlet = this._allMonitorPoints.Find(x => x.MonitorType == Model.eMonitorType.压力 && x.Property == TProduct.Model.MonitorTypeProperty.进口);
            if (mp_inlet != null)
            {
                for (var index = 0; index < sort_allRecords.Count(); index++)
                {
                    var rs = sort_allRecords[index].MonitorRecordList.Find(x => x.ID == mp_inlet.ID);
                    if (rs != null)
                        SetCellValue(sheet性能测试, 9 + index, "B", rs.Value);
                }
            }
 
            //出口压力
            var mp_outlet = this._allMonitorPoints.Find(x => x.MonitorType == Model.eMonitorType.压力 && x.Property == TProduct.Model.MonitorTypeProperty.出口);
            if (mp_outlet != null)
            {
                for (var index = 0; index < sort_allRecords.Count(); index++)
                {
                    var rs = sort_allRecords[index].MonitorRecordList.Find(x => x.ID == mp_outlet.ID);
                    if (rs != null)
                        SetCellValue(sheet性能测试, 9 + index, "C", rs.Value);
                }
            }
 
 
            //电流
            var mp_功率 = this._allMonitorPoints.Find(x => x.MonitorType == Model.eMonitorType.功率);
            if (mp_功率 != null)
            {
                for (var index = 0; index < sort_allRecords.Count(); index++)
                {
                    var rs = sort_allRecords[index].MonitorRecordList.Find(x => x.ID == mp_功率.ID);
                    if (rs != null)
                        SetCellValue(sheet性能测试, 9 + index, "E", rs.Value);
                }
            }
 
            //转速
            var mp_speed = this._allMonitorPoints.Find(x => x.MonitorType == Model.eMonitorType.转速);
            if (mp_speed != null)
            {
                for (var index = 0; index < sort_allRecords.Count(); index++)
                {
                    var rs = sort_allRecords[index].MonitorRecordList.Find(x => x.ID == mp_speed.ID);
                    if (rs != null)
                        SetCellValue(sheet性能测试, 9 + index, "F", rs.Value);
                }
            }
 
            for (var index = 0; index < sort_allRecords.Count(); index++)
            {
                SetCellValue(sheet性能测试, 9 + index, "G", sort_allRecords[index].CorrectPtQ);
                SetCellValue(sheet性能测试, 9 + index, "D", sort_allRecords[index].TestPtH);
                SetCellValue(sheet性能测试, 9 + index, "H", sort_allRecords[index].CorrectPtH); 
                SetCellValue(sheet性能测试, 9 + index, "I", sort_allRecords[index].CorrectPtP.ToString()); 
                SetCellValue(sheet性能测试, 9 + index, "J", sort_allRecords[index].CorrectPtE.ToString());
            }
 
 
            sheet性能测试.ForceFormulaRecalculation = true;
            return true;
        }
 
    }
}