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;
|
}
|
|
}
|
}
|