fix(print): 避免 FastReport 模板重复写入

仅在报表连接串与系统连接串不一致时才更新并保存模板,
同时增加模板文件存在性校验,减少打印时因模板文件异常导致的报错。
2.修复无损检测委托单生成逻辑
This commit is contained in:
李鹏飞 2026-04-21 19:37:20 +08:00
parent ecd2d00ef7
commit 453d1d5a3b
2 changed files with 1306 additions and 1298 deletions

View File

@ -418,37 +418,35 @@ namespace BLL
Model.HJGL_Batch_PointBatch batch = BLL.PointBatchService.GetPointBatchById(pointBatchId); Model.HJGL_Batch_PointBatch batch = BLL.PointBatchService.GetPointBatchById(pointBatchId);
if (batch != null) if (batch != null)
{ {
Model.HJGL_Batch_BatchTrust newBatchTrust = new Model.HJGL_Batch_BatchTrust();
var project = BLL.ProjectService.GetProjectByProjectId(batch.ProjectId);
var unit = BLL.UnitService.GetUnitByUnitId(batch.UnitId);
var area = BLL.UnitWorkService.getUnitWorkByUnitWorkId(batch.UnitWorkId);
var ndt = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(batch.DetectionTypeId);
var rate = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(batch.DetectionRateId);
string perfix = string.Empty;
newBatchTrust.TrustBatchCode = batch.PointBatchCode.Replace("-DK-", "-WT-");
string trustBatchId = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_BatchTrust)); string trustBatchId = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_BatchTrust));
newBatchTrust.TrustBatchId = trustBatchId;
newBatchTrust.TrustDate = DateTime.Now;
newBatchTrust.ProjectId = batch.ProjectId;
newBatchTrust.PointBatchId = batch.PointBatchId;
newBatchTrust.UnitId = batch.UnitId;
newBatchTrust.UnitWorkId = batch.UnitWorkId;
newBatchTrust.DetectionTypeId = batch.DetectionTypeId;
newBatchTrust.DetectionRateId = batch.DetectionRateId;
newBatchTrust.NDEUnit = nDEUnit;
newBatchTrust.PointBatchId = pointBatchId;
BLL.Batch_BatchTrustService.AddBatchTrust(newBatchTrust); // 新增委托单
// 生成委托条件对比 // 生成委托条件对比
var generateTrustItem = from x in db.View_GenerateTrustItem var generateTrustItem = (from x in db.View_GenerateTrustItem
where x.PointBatchId == pointBatchId where x.PointBatchId == pointBatchId
select x; select x).ToList();
if (generateTrustItem.Count == 0)
{
return "当前检验批没有可生成的委托明细!";
}
List<string> toPointBatchList = generateTrustItem.Select(x => x.PointBatchId).Distinct().ToList(); List<string> toPointBatchList = generateTrustItem.Select(x => x.PointBatchId).Distinct().ToList();
Model.HJGL_Batch_BatchTrust newBatchTrust = new Model.HJGL_Batch_BatchTrust
{
TrustBatchId = trustBatchId,
TrustBatchCode = batch.PointBatchCode.Replace("-DK-", "-WT-"),
TrustDate = DateTime.Now,
ProjectId = batch.ProjectId,
PointBatchId = pointBatchId,
UnitId = batch.UnitId,
UnitWorkId = batch.UnitWorkId,
DetectionTypeId = batch.DetectionTypeId,
DetectionRateId = batch.DetectionRateId,
NDEUnit = nDEUnit,
IsAudit = true
};
db.HJGL_Batch_BatchTrust.InsertOnSubmit(newBatchTrust);
// 生成委托明细,并回写点口明细信息 // 生成委托明细,并回写点口明细信息
foreach (var item in generateTrustItem) foreach (var item in generateTrustItem)
{ {
@ -460,15 +458,15 @@ namespace BLL
TrustBatchId = trustBatchId, TrustBatchId = trustBatchId,
PointBatchItemId = item.PointBatchItemId, PointBatchItemId = item.PointBatchItemId,
WeldJointId = item.WeldJointId, WeldJointId = item.WeldJointId,
CreateDate = DateTime.Now CreateDate = DateTime.Now,
TrustNum = 1
}; };
Batch_BatchTrustItemService.AddBatchTrustItem(trustItem); db.HJGL_Batch_BatchTrustItem.InsertOnSubmit(trustItem);
} }
Model.HJGL_Batch_PointBatchItem pointBatchItem = db.HJGL_Batch_PointBatchItem.First(x => x.PointBatchItemId == item.PointBatchItemId); Model.HJGL_Batch_PointBatchItem pointBatchItem = db.HJGL_Batch_PointBatchItem.First(x => x.PointBatchItemId == item.PointBatchItemId);
pointBatchItem.IsBuildTrust = true; pointBatchItem.IsBuildTrust = true;
db.SubmitChanges();
} }
@ -476,14 +474,9 @@ namespace BLL
if (toPointBatchList.Count() > 0) if (toPointBatchList.Count() > 0)
{ {
string toPointBatch = String.Join(",", toPointBatchList); string toPointBatch = String.Join(",", toPointBatchList);
newBatchTrust.TopointBatch = toPointBatch;
var updateTrut = BLL.Batch_BatchTrustService.GetBatchTrustById(trustBatchId);
if (updateTrut != null)
{
updateTrut.TopointBatch = toPointBatch;
BLL.Batch_BatchTrustService.UpdateBatchTrust(updateTrut);
}
} }
db.SubmitChanges();
result = "委托成功!"; result = "委托成功!";
} }
} }
@ -542,29 +535,33 @@ namespace BLL
string perfix = string.Empty; string perfix = string.Empty;
perfix = unit.UnitCode + "-" + ndt.DetectionTypeCode + "-" + rate.DetectionRateValue.ToString() + "%-"; perfix = unit.UnitCode + "-" + ndt.DetectionTypeCode + "-" + rate.DetectionRateValue.ToString() + "%-";
newBatchTrust.TrustBatchCode = BLL.SQLHelper.RunProcNewId("SpGetNewCode5ByProjectId", "dbo.HJGL_Batch_BatchTrust", "TrustBatchCode", project.ProjectId, perfix);
string trustBatchId = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_BatchTrust)); string trustBatchId = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_BatchTrust));
newBatchTrust.TrustBatchId = trustBatchId;
// 生成委托条件对比
var generateTrustItem = (from x in db.View_GenerateTrustItem
where x.ProjectId == trust.ProjectId
&& x.UnitWorkId == trust.UnitWorkId && x.UnitId == trust.UnitId
&& x.DetectionTypeId == trust.DetectionTypeId
&& x.DetectionRateId == trust.DetectionRateId
select x).ToList();
if (generateTrustItem.Count == 0)
{
continue;
}
List<string> toPointBatchList = generateTrustItem.Select(x => x.PointBatchId).Distinct().ToList();
newBatchTrust.TrustBatchCode = BLL.SQLHelper.RunProcNewId("SpGetNewCode5ByProjectId", "dbo.HJGL_Batch_BatchTrust", "TrustBatchCode", project.ProjectId, perfix);
newBatchTrust.TrustBatchId = trustBatchId;
newBatchTrust.TrustDate = DateTime.Now; newBatchTrust.TrustDate = DateTime.Now;
newBatchTrust.ProjectId = trust.ProjectId; newBatchTrust.ProjectId = trust.ProjectId;
newBatchTrust.UnitId = trust.UnitId; newBatchTrust.UnitId = trust.UnitId;
newBatchTrust.UnitWorkId = trust.UnitWorkId; newBatchTrust.UnitWorkId = trust.UnitWorkId;
newBatchTrust.DetectionTypeId = trust.DetectionTypeId; newBatchTrust.DetectionTypeId = trust.DetectionTypeId;
newBatchTrust.NDEUnit = unitWork.NDEUnit; newBatchTrust.NDEUnit = unitWork.NDEUnit;
newBatchTrust.DetectionRateId = trust.DetectionRateId;
BLL.Batch_BatchTrustService.AddBatchTrust(newBatchTrust); // 新增委托单 newBatchTrust.IsAudit = true;
db.HJGL_Batch_BatchTrust.InsertOnSubmit(newBatchTrust);
// 生成委托条件对比
var generateTrustItem = from x in db.View_GenerateTrustItem
where x.ProjectId == trust.ProjectId
&& x.UnitWorkId == trust.UnitWorkId && x.UnitId == trust.UnitId
&& x.DetectionTypeId == trust.DetectionTypeId
&& x.DetectionRateId == trust.DetectionRateId
select x;
List<string> toPointBatchList = generateTrustItem.Select(x => x.PointBatchId).Distinct().ToList();
// 生成委托明细,并回写点口明细信息 // 生成委托明细,并回写点口明细信息
foreach (var item in generateTrustItem) foreach (var item in generateTrustItem)
@ -577,15 +574,18 @@ namespace BLL
TrustBatchId = trustBatchId, TrustBatchId = trustBatchId,
PointBatchItemId = item.PointBatchItemId, PointBatchItemId = item.PointBatchItemId,
WeldJointId = item.WeldJointId, WeldJointId = item.WeldJointId,
CreateDate = DateTime.Now CreateDate = DateTime.Now,
TrustNum = 1
}; };
Batch_BatchTrustItemService.AddBatchTrustItem(trustItem); db.HJGL_Batch_BatchTrustItem.InsertOnSubmit(trustItem);
} }
Model.HJGL_Batch_PointBatchItem pointBatchItem = db.HJGL_Batch_PointBatchItem.FirstOrDefault(e => e.PointBatchItemId == item.PointBatchItemId); Model.HJGL_Batch_PointBatchItem pointBatchItem = db.HJGL_Batch_PointBatchItem.FirstOrDefault(e => e.PointBatchItemId == item.PointBatchItemId);
if (pointBatchItem != null)
{
pointBatchItem.IsBuildTrust = true; pointBatchItem.IsBuildTrust = true;
db.SubmitChanges(); }
} }
@ -593,14 +593,9 @@ namespace BLL
if (toPointBatchList.Count() > 0) if (toPointBatchList.Count() > 0)
{ {
string toPointBatch = String.Join(",", toPointBatchList); string toPointBatch = String.Join(",", toPointBatchList);
newBatchTrust.TopointBatch = toPointBatch;
var updateTrut = BLL.Batch_BatchTrustService.GetBatchTrustById(trustBatchId);
if (updateTrut != null)
{
updateTrut.TopointBatch = toPointBatch;
BLL.Batch_BatchTrustService.UpdateBatchTrust(updateTrut);
}
} }
db.SubmitChanges();
} }
} }
@ -683,8 +678,8 @@ namespace BLL
{ {
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{ {
var getDataLists = (from x in db.View_GenerateTrustItem var getDataLists = (from x in db.View_Batch_BatchTrustItem
where x.PointBatchId == trustBatchId where x.TrustBatchId == trustBatchId
orderby x.WeldJointCode orderby x.WeldJointCode
select new Model.NDETrustItem select new Model.NDETrustItem
{ {
@ -1061,7 +1056,12 @@ namespace BLL
newRepairTrust.UnitId = repairRecord.UnitId; newRepairTrust.UnitId = repairRecord.UnitId;
newRepairTrust.UnitWorkId = repairRecord.UnitWorkId; newRepairTrust.UnitWorkId = repairRecord.UnitWorkId;
newRepairTrust.DetectionTypeId = repairRecord.DetectionTypeId; newRepairTrust.DetectionTypeId = repairRecord.DetectionTypeId;
var oldTrust = (from x in Funs.DB.HJGL_Batch_BatchTrust join y in Funs.DB.HJGL_Batch_BatchTrustItem on x.TrustBatchId equals y.TrustBatchId join z in Funs.DB.HJGL_Batch_NDEItem on y.TrustBatchItemId equals z.TrustBatchItemId where z.NDEItemID == repairRecord.NDEItemID select x).FirstOrDefault(); newRepairTrust.DetectionRateId = oldTrust.DetectionRateId; var oldTrust = (from x in Funs.DB.HJGL_Batch_BatchTrust
join y in Funs.DB.HJGL_Batch_BatchTrustItem on x.TrustBatchId equals y.TrustBatchId
join z in Funs.DB.HJGL_Batch_NDEItem on y.TrustBatchItemId equals z.TrustBatchItemId
where z.NDEItemID == repairRecord.NDEItemID
select x).FirstOrDefault();
newRepairTrust.DetectionRateId = oldTrust.DetectionRateId;
newRepairTrust.TrustType = "R"; newRepairTrust.TrustType = "R";
BLL.Batch_BatchTrustService.AddBatchTrust(newRepairTrust); // 新增返修委托单 BLL.Batch_BatchTrustService.AddBatchTrust(newRepairTrust); // 新增返修委托单

View File

@ -38,6 +38,10 @@ namespace FineUIPro.Web.Controls
{ {
ReportPath = Request.Params["ReportPath"]; ReportPath = Request.Params["ReportPath"];
WebReport1.StartReport += WebReport1_StartReport; WebReport1.StartReport += WebReport1_StartReport;
if (string.IsNullOrEmpty(ReportPath) || !System.IO.File.Exists(ReportPath))
{
throw new System.IO.FileNotFoundException("打印模板不存在!", ReportPath);
}
if (dataTables != null && dataTables.Count > 0) if (dataTables != null && dataTables.Count > 0)
{ {
for (int i = 0; i < dataTables.Count; i++) for (int i = 0; i < dataTables.Count; i++)
@ -49,9 +53,13 @@ namespace FineUIPro.Web.Controls
WebReport1.Report.Load(ReportPath); WebReport1.Report.Load(ReportPath);
if (WebReport1.Report.Dictionary.Connections.Count > 0) if (WebReport1.Report.Dictionary.Connections.Count > 0)
{ {
WebReport1.Report.Dictionary.Connections[0].ConnectionString = Funs.ConnString; var reportConnection = WebReport1.Report.Dictionary.Connections[0];
if (reportConnection.ConnectionString != Funs.ConnString)
{
reportConnection.ConnectionString = Funs.ConnString;
WebReport1.Report.Save(ReportPath); WebReport1.Report.Save(ReportPath);
} }
}
WebReport1.ReportFile = ReportPath; WebReport1.ReportFile = ReportPath;
WebReport1.Prepare(); WebReport1.Prepare();
// WebReport1.ExportPdf(); // WebReport1.ExportPdf();