diff --git a/SGGL/BLL/CLGL/TwArrivalStatisticsService.cs b/SGGL/BLL/CLGL/TwArrivalStatisticsService.cs
index 1daa3004..6e8d41b3 100644
--- a/SGGL/BLL/CLGL/TwArrivalStatisticsService.cs
+++ b/SGGL/BLL/CLGL/TwArrivalStatisticsService.cs
@@ -1,6 +1,4 @@
-
-using Model;
-using Newtonsoft.Json;
+using Model;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -13,96 +11,95 @@ namespace BLL
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
- string WarehouseId = Base_WarehouseService.GetWarehouseList(projectid)
+ string warehouseId = Base_WarehouseService.GetWarehouseList(projectid)
.Where(x => x.WarehouseId == WarehouseCode || x.WarehouseName == WarehouseCode)
.Select(x => x.WarehouseId)
.FirstOrDefault();
- ///所需材料数量列表
- var NeedOutMateriaList = from x in db.HJGL_PipeLineMat
- join y in db.HJGL_MaterialCodeLib on x.MaterialCode equals y.MaterialCode
- join z in db.HJGL_Pipeline on x.PipelineId equals z.PipelineId
- where z.ProjectId == projectid && (string.IsNullOrEmpty(materialCode) || x.MaterialCode.Contains(materialCode)) && z.WarehouseId == WarehouseId
- group x by x.MaterialCode
- into g
- select new
- {
- g.Key,
- NeedNum = g.Sum(x => x.Number) ?? 0,
- };
- ///实际材料入库数量列表
- var RealInMateriaList = (from x in db.Tw_InputDetail
- join master in db.Tw_InputMaster on x.InputMasterId equals master.Id
- join y in db.HJGL_MaterialCodeLib on x.MaterialCode equals y.MaterialCode
- where master.ProjectId == projectid && master.WarehouseId == WarehouseId
- group x by x.MaterialCode
- into g
- where (string.IsNullOrEmpty(materialCode) || g.Key.Contains(materialCode))
- select new
- {
- g.Key,
- RealNum = g.Sum(x => x.ActNum) ?? 0,
- }).ToList();
- ///实际材料出库数量列表
- var RealOutMateriaList = (from x in db.Tw_OutputDetail
- join master in db.Tw_OutputMaster on x.OutputMasterId equals master.Id
- where master.ProjectId == projectid && master.WarehouseId == WarehouseId
- group x by x.MaterialCode
- into g
- where (string.IsNullOrEmpty(materialCode) || g.Key.Contains(materialCode))
- select new
- {
- g.Key,
- OutputNum = g.Sum(x => x.ActNum) ?? 0,
- }).ToList();
- //库存数量
- var tw_MaterialStock = (from x in db.Tw_MaterialStock
- where x.WarehouseId == WarehouseId && x.ProjectId == projectid
- select x).ToList();
+ // 所需材料数量
+ var requiredMaterialsQuery = from x in db.HJGL_PipeLineMat
+ join y in db.HJGL_MaterialCodeLib on x.MaterialCode equals y.MaterialCode
+ join z in db.HJGL_Pipeline on x.PipelineId equals z.PipelineId
+ where z.ProjectId == projectid && (string.IsNullOrEmpty(materialCode) || x.MaterialCode.Contains(materialCode)) && z.WarehouseId == warehouseId
+ group x by x.MaterialCode
+ into g
+ select new
+ {
+ g.Key,
+ NeedNum = g.Sum(x => x.Number) ?? 0,
+ };
+ // 实际入库数量
+ var inputMaterials = (from x in db.Tw_InputDetail
+ join master in db.Tw_InputMaster on x.InputMasterId equals master.Id
+ join y in db.HJGL_MaterialCodeLib on x.MaterialCode equals y.MaterialCode
+ where master.ProjectId == projectid && master.WarehouseId == warehouseId
+ group x by x.MaterialCode
+ into g
+ where (string.IsNullOrEmpty(materialCode) || g.Key.Contains(materialCode))
+ select new
+ {
+ g.Key,
+ RealNum = g.Sum(x => x.ActNum) ?? 0,
+ }).ToList();
+ // 实际出库数量
+ var outputMaterials = (from x in db.Tw_OutputDetail
+ join master in db.Tw_OutputMaster on x.OutputMasterId equals master.Id
+ where master.ProjectId == projectid && master.WarehouseId == warehouseId
+ group x by x.MaterialCode
+ into g
+ where (string.IsNullOrEmpty(materialCode) || g.Key.Contains(materialCode))
+ select new
+ {
+ g.Key,
+ OutputNum = g.Sum(x => x.ActNum) ?? 0,
+ }).ToList();
+ // 库存数量
+ var stocks = (from x in db.Tw_MaterialStock
+ where x.WarehouseId == warehouseId && x.ProjectId == projectid
+ select x).ToList();
- var needMateriaList = NeedOutMateriaList.ToList();
- var materialCodeList = needMateriaList.Select(x => x.Key)
- .Union(RealInMateriaList.Select(x => x.Key))
- .Union(RealOutMateriaList.Select(x => x.Key))
- .Distinct()
+ var requiredMaterials = requiredMaterialsQuery.ToList();
+ var materialCodes = requiredMaterials.Select(x => x.Key)
+ .Union(inputMaterials.Select(x => x.Key))
+ .Union(outputMaterials.Select(x => x.Key))
.ToList();
var materialInfoList = (from x in db.HJGL_MaterialCodeLib
- where materialCodeList.Contains(x.MaterialCode)
+ where materialCodes.Contains(x.MaterialCode)
select x).ToList();
- var StatisticsList = (from code in materialCodeList
- join x in needMateriaList on code equals x.Key into needGroup
- from x in needGroup.DefaultIfEmpty()
- join y in RealInMateriaList on code equals y.Key into realGroup
- from y in realGroup.DefaultIfEmpty()
- join o in RealOutMateriaList on code equals o.Key into outputGroup
- from o in outputGroup.DefaultIfEmpty()
- join z in materialInfoList on code equals z.MaterialCode into infoGroup
- from z in infoGroup.DefaultIfEmpty()
- join m in tw_MaterialStock on code equals m.PipeLineMatCode into stockGroup
- from m in stockGroup.DefaultIfEmpty()
- orderby code
- select new Tw_ArrivalStatisticsOutPut
- {
- MaterialCode = code,
- StockNum = m == null ? 0 : (decimal)m.StockNum,
- NeedNum = x == null ? 0 : x.NeedNum,
- RealNum = y == null ? 0 : y.RealNum,
- OutputNum = o == null ? 0 : o.OutputNum,
- Code = z == null ? null : z.Code,
- HeatNo = z == null ? null : z.HeatNo,
- BatchNo = z == null ? null : z.BatchNo,
- MaterialName = z == null ? null : z.MaterialName,
- MaterialSpec = z == null ? null : z.MaterialSpec,
- MaterialUnit = z == null ? null : z.MaterialUnit,
- MaterialDef = z == null ? null : z.MaterialDef,
- MatchRate = (x == null || x.NeedNum == 0 ? 0 : Math.Round((y == null ? 0 : y.RealNum) / x.NeedNum, 4, MidpointRounding.ToEven)),
- }).ToList();
- foreach (var item in StatisticsList)
+ var statistics = (from code in materialCodes
+ join x in requiredMaterials on code equals x.Key into needGroup
+ from x in needGroup.DefaultIfEmpty()
+ join y in inputMaterials on code equals y.Key into realGroup
+ from y in realGroup.DefaultIfEmpty()
+ join o in outputMaterials on code equals o.Key into outputGroup
+ from o in outputGroup.DefaultIfEmpty()
+ join z in materialInfoList on code equals z.MaterialCode into infoGroup
+ from z in infoGroup.DefaultIfEmpty()
+ join m in stocks on code equals m.PipeLineMatCode into stockGroup
+ from m in stockGroup.DefaultIfEmpty()
+ orderby code
+ select new Tw_ArrivalStatisticsOutPut
+ {
+ MaterialCode = code,
+ StockNum = m == null ? 0 : (decimal)m.StockNum,
+ NeedNum = x == null ? 0 : x.NeedNum,
+ RealNum = y == null ? 0 : y.RealNum,
+ OutputNum = o == null ? 0 : o.OutputNum,
+ Code = z == null ? null : z.Code,
+ HeatNo = z == null ? null : z.HeatNo,
+ BatchNo = z == null ? null : z.BatchNo,
+ MaterialName = z == null ? null : z.MaterialName,
+ MaterialSpec = z == null ? null : z.MaterialSpec,
+ MaterialUnit = z == null ? null : z.MaterialUnit,
+ MaterialDef = z == null ? null : z.MaterialDef,
+ MatchRate = (x == null || x.NeedNum == 0 ? 0 : Math.Round((y == null ? 0 : y.RealNum) / x.NeedNum, 4, MidpointRounding.ToEven)),
+ }).ToList();
+ foreach (var item in statistics)
{
item.MatchRateString = Math.Round(item.MatchRate * 100, 2).ToString() + "%";
}
- return StatisticsList;
+ return statistics;
}
}
@@ -115,12 +112,12 @@ namespace BLL
///
public static List GetMatMatchOutput(List requiredMaterials, string warehouseCode, string projectId, bool matchByMaterialCodeLibCode = false)
{
- Tw_MaterialStockOutput twMaterialStockOutput = new Tw_MaterialStockOutput
+ var stockFilter = new Tw_MaterialStockOutput
{
WarehouseId = warehouseCode,
ProjectId = projectId
};
- var stockList = TwMaterialstockService.GetTw_MaterialStockByModle(twMaterialStockOutput).ToList();//获取库存列表
+ var stockList = TwMaterialstockService.GetTw_MaterialStockByModle(stockFilter).ToList();
// 预扣除出库申请单中状态为待审核/已审核的材料数量
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
@@ -149,10 +146,7 @@ namespace BLL
}
}
- // 以下三个集合只服务于“按材料 Code 挑选材料主编码”的场景:
- // remainingRequiredNumByCode:当前明细及后续明细的剩余总需求;
- // stocksByCode:同一 Code 下所有可用的材料主编码库存;
- // usedMaterialCodesByCode:本轮匹配已经使用过的材料主编码,用于优先继续消耗其余量。
+ // 按 Code 匹配时,分别跟踪剩余总需求、可用库存和本轮已使用的主编码。
Dictionary remainingRequiredNumByCode = null;
Dictionary> stocksByCode = null;
Dictionary> usedMaterialCodesByCode = null;
@@ -181,38 +175,26 @@ namespace BLL
Tw_MaterialStockOutput stock = null;
if (matchByMaterialCodeLibCode)
{
- if (!string.IsNullOrEmpty(material.MaterialCode) && stocksByCode.ContainsKey(material.MaterialCode))
+ List codeStocks;
+ if (!string.IsNullOrEmpty(material.MaterialCode) && stocksByCode.TryGetValue(material.MaterialCode, out codeStocks))
{
decimal needNum = material.NeedNum ?? 0;
decimal remainingRequiredNum = remainingRequiredNumByCode[material.MaterialCode];
// StockNum 会在每条明细匹配后原地扣减,这里读取的是本轮实时剩余库存。
- var candidates = stocksByCode[material.MaterialCode]
+ var candidates = codeStocks
.Where(x => (x.StockNum ?? 0) > 0)
+ .OrderBy(x => x.StockNum ?? 0)
+ .ThenBy(x => x.PipeLineMatCode)
.ToList();
var usedMaterialCodes = usedMaterialCodesByCode[material.MaterialCode];
- // 第一优先级:复用已使用且能完整满足当前明细的主编码,减少主编码种类;
- // 在多个已用主编码都满足时,选择库存最小的,使其更接近用完。
+ // 前三级共用库存升序:复用已用主编码,其次覆盖剩余总需求,最后覆盖当前明细。
+ // 同级优先库存最小的主编码,减少余料;每条明细仍只选择一个主编码。
stock = candidates
- .Where(x => usedMaterialCodes.Contains(x.PipeLineMatCode) && (x.StockNum ?? 0) >= needNum)
- .OrderBy(x => x.StockNum ?? 0)
- .ThenBy(x => x.PipeLineMatCode)
- .FirstOrDefault()
- // 第二优先级:启用一个能覆盖剩余总需求的新主编码,保证后续仍只使用这一种主编码;
- // 若有多个可选,选择库存最小的,减少最终余料。
- ?? candidates
- .Where(x => !usedMaterialCodes.Contains(x.PipeLineMatCode) && (x.StockNum ?? 0) >= remainingRequiredNum)
- .OrderBy(x => x.StockNum ?? 0)
- .ThenBy(x => x.PipeLineMatCode)
- .FirstOrDefault()
- // 第三优先级:无法一次覆盖剩余总需求时,选择刚好能满足当前明细且余量最小的新主编码。
- ?? candidates
- .Where(x => !usedMaterialCodes.Contains(x.PipeLineMatCode) && (x.StockNum ?? 0) >= needNum)
- .OrderBy(x => x.StockNum ?? 0)
- .ThenBy(x => x.PipeLineMatCode)
- .FirstOrDefault()
- // 所有库存都不足以完整满足当前明细时,选择库存最大的主编码以保证匹配量最大;
- // 库存相同时优先已使用的主编码,最后按主编码排序保证结果稳定。
+ .FirstOrDefault(x => usedMaterialCodes.Contains(x.PipeLineMatCode) && (x.StockNum ?? 0) >= needNum)
+ ?? candidates.FirstOrDefault(x => !usedMaterialCodes.Contains(x.PipeLineMatCode) && (x.StockNum ?? 0) >= remainingRequiredNum)
+ ?? candidates.FirstOrDefault(x => !usedMaterialCodes.Contains(x.PipeLineMatCode) && (x.StockNum ?? 0) >= needNum)
+ // 都不足时取最大库存;数量相同则优先已用主编码,再按主编码排序。
?? candidates
.OrderByDescending(x => x.StockNum ?? 0)
.ThenByDescending(x => usedMaterialCodes.Contains(x.PipeLineMatCode))
@@ -223,7 +205,6 @@ namespace BLL
{
usedMaterialCodes.Add(stock.PipeLineMatCode);
}
- // 当前明细处理完后,只保留后续明细的总需求供下一轮选码判断。
remainingRequiredNumByCode[material.MaterialCode] -= needNum;
}
}
@@ -241,7 +222,7 @@ namespace BLL
}
else
{
- material.MatchNum = thisMaterialStockNum < 0 ? 0 : thisMaterialStockNum;
+ material.MatchNum = Math.Max(thisMaterialStockNum, 0);
material.MatchRate = (material.NeedNum == 0 ? 0 : ((material.MatchNum ?? 0) / material.NeedNum));
material.MatchRateString = Math.Round((decimal)(material.MatchRate ?? 0) * 100, 2).ToString() + "%";
@@ -255,8 +236,7 @@ namespace BLL
}
}
- var results = requiredMaterials;
- return results;
+ return requiredMaterials;
}
///
/// 获取管线匹配率
@@ -264,18 +244,11 @@ namespace BLL
///
///
public static decimal? GetPipeMatch(string pipelineId)
- {
- using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
- {
- var twPipeMatMatchOutputs = new List();
- List pipelineIds = new List();
- pipelineIds.Add(pipelineId);
- var pipelineModel = PipelineService.GetPipelineByPipelineId(pipelineId);
- string warehouseCode = PipelineService.GetPipelineByPipelineId(pipelineModel.PipelineId).WarehouseId;
- var PipeMatMatch = GetPipeMatMatch(pipelineModel.ProjectId, pipelineIds, warehouseCode);
- var pipeMatchRate = GetPipeMatch(PipeMatMatch).FirstOrDefault(x => x.PipelineId == pipelineId);
- return pipeMatchRate?.MatchRate;
- }
+ {
+ var pipeline = PipelineService.GetPipelineByPipelineId(pipelineId);
+ var materials = GetPipeMatMatch(pipeline.ProjectId, new List { pipelineId }, pipeline.WarehouseId);
+ var match = GetPipeMatch(materials).FirstOrDefault(x => x.PipelineId == pipelineId);
+ return match?.MatchRate;
}
///
/// 根据出库单主键获取材料匹配信息
@@ -286,22 +259,17 @@ namespace BLL
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
- var results = new List();
- string[] taskPipeLineList = null;
-
- var inoutPlanMasterl = db.Tw_InOutPlanMaster.FirstOrDefault(x => x.Id == outPlanMasterId);
- if (inoutPlanMasterl != null)
+ var planMaster = db.Tw_InOutPlanMaster.FirstOrDefault(x => x.Id == outPlanMasterId);
+ var taskKey = planMaster?.WeldTaskId.Split('|');
+ string[] taskPipelineIds = null;
+ if (taskKey != null && taskKey.Length == 4)
{
- if (inoutPlanMasterl.WeldTaskId.Split('|').Length == 4)
- {
- taskPipeLineList = Funs.DB.View_HJGL_WeldingTask.Where(e =>
- e.UnitWorkId == inoutPlanMasterl.WeldTaskId.Split('|')[0].ToString()
- && e.UnitId == inoutPlanMasterl.WeldTaskId.Split('|')[1].ToString()
- && e.TaskDate.Value.Date == DateTime
- .ParseExact(inoutPlanMasterl.WeldTaskId.Split('|')[2].ToString(), "yyyyMMdd", null).Date
- && e.SerialNumber == inoutPlanMasterl.WeldTaskId.Split('|')[3].ToString()
- ).Distinct().OrderBy(x => x.PipeLineSortIndex).Select(x => x.PipelineId).ToArray();
- }
+ taskPipelineIds = Funs.DB.View_HJGL_WeldingTask.Where(x =>
+ x.UnitWorkId == taskKey[0]
+ && x.UnitId == taskKey[1]
+ && x.TaskDate.Value.Date == DateTime.ParseExact(taskKey[2], "yyyyMMdd", null).Date
+ && x.SerialNumber == taskKey[3]
+ ).Distinct().OrderBy(x => x.PipeLineSortIndex).Select(x => x.PipelineId).ToArray();
}
// 获取所需材料列表
var requiredMaterials = (from x in db.Tw_InOutPlanDetail_Relation
@@ -326,18 +294,13 @@ namespace BLL
NeedNum = x.Number
}
).ToList();
- if (taskPipeLineList != null && taskPipeLineList.Any())
+ if (taskPipelineIds != null && taskPipelineIds.Any())
{
- requiredMaterials = requiredMaterials.OrderBy(x => Array.IndexOf(taskPipeLineList, x.PipelineId.ToString())).ToList();
-
+ requiredMaterials = requiredMaterials.OrderBy(x => Array.IndexOf(taskPipelineIds, x.PipelineId.ToString())).ToList();
}
- var masterModle = db.Tw_InOutPlanMaster.FirstOrDefault(x => x.Id == outPlanMasterId);
- results = GetMatMatchOutput(requiredMaterials, masterModle.WarehouseId, masterModle.ProjectId);
- return results;
+ return GetMatMatchOutput(requiredMaterials, planMaster.WarehouseId, planMaster.ProjectId);
}
-
-
}
///
/// 根据管线id获取材料匹配信息
@@ -395,11 +358,10 @@ namespace BLL
.Select(x => GetComponentKey(x.PipeLineMat.PipelineId, x.PipeLineMat.PrefabricatedComponents)));
// 页面匹配只展示并消耗尚未焊接的焊口材料;不传区域的旧调用保留原查询行为。
- var pipeLineMats = filterByPipeArea
- ? allPipeLineMats.Where(x => x.WeldJoint != null
- && x.WeldJoint.WeldingDailyId==null
- && (x.PipeLineMat.Number ?? 0) > 0).ToList()
- : allPipeLineMats.Where(x => (x.PipeLineMat.Number ?? 0) > 0).ToList();
+ var pipeLineMats = allPipeLineMats
+ .Where(x => (x.PipeLineMat.Number ?? 0) > 0)
+ .Where(x => !filterByPipeArea || (x.WeldJoint != null && x.WeldJoint.WeldingDailyId == null))
+ .ToList();
var materialCodes = pipeLineMats
.Where(x => !string.IsNullOrEmpty(x.PipeLineMat.MaterialCode))
@@ -461,11 +423,11 @@ namespace BLL
};
}).ToList();
+ var materialsByPipeline = requiredMaterials.ToLookup(x => x.PipelineId);
var orderedPipelineMaterials = new Dictionary>();
foreach (string id in pipelineIds)
{
- orderedPipelineMaterials[id] = requiredMaterials
- .Where(x => x.PipelineId == id)
+ orderedPipelineMaterials[id] = materialsByPipeline[id]
.OrderBy(x => x.PrefabricatedComponents)
.ThenBy(x => x.WeldJointCode)
.ThenBy(x => x.MaterialCode)
@@ -473,28 +435,28 @@ namespace BLL
.ToList();
}
- var newRequiredMaterials = new List();
+ var orderedMaterials = new List();
var addedMaterialIds = new HashSet();
// 先处理全部管线的手动优先焊口,保证人工选择始终高于任何自动优先规则。
foreach (string id in pipelineIds)
{
- if (priorityWeldJoints != null && priorityWeldJoints.ContainsKey(id) && priorityWeldJoints[id] != null && priorityWeldJoints[id].Any())
+ List weldJointIds;
+ if (priorityWeldJoints == null || !priorityWeldJoints.TryGetValue(id, out weldJointIds)
+ || weldJointIds == null || !weldJointIds.Any())
{
- var weldJointIds = priorityWeldJoints[id];
- var manualPriorityMaterials = orderedPipelineMaterials[id]
- .Where(x => weldJointIds.Contains(x.WeldJointId))
- .OrderBy(x => weldJointIds.IndexOf(x.WeldJointId))
- .ThenBy(x => x.PrefabricatedComponents)
- .ThenBy(x => x.WeldJointCode)
- .ThenBy(x => x.MaterialCode)
- .ToList();
- newRequiredMaterials.AddRange(manualPriorityMaterials);
- foreach (var item in manualPriorityMaterials)
- {
- addedMaterialIds.Add(item.PipeLineMatId);
- }
+ continue;
}
+
+ var manualPriorityMaterials = orderedPipelineMaterials[id]
+ .Where(x => weldJointIds.Contains(x.WeldJointId))
+ .OrderBy(x => weldJointIds.IndexOf(x.WeldJointId))
+ .ThenBy(x => x.PrefabricatedComponents)
+ .ThenBy(x => x.WeldJointCode)
+ .ThenBy(x => x.MaterialCode)
+ .ToList();
+ orderedMaterials.AddRange(manualPriorityMaterials);
+ addedMaterialIds.UnionWith(manualPriorityMaterials.Select(x => x.PipeLineMatId));
}
// 再处理全部续作组件,避免前一条管线的未开工组件抢占后一条管线续作组件的库存。
@@ -504,20 +466,17 @@ namespace BLL
.Where(x => !addedMaterialIds.Contains(x.PipeLineMatId)
&& continuationComponentKeys.Contains(GetComponentKey(x.PipelineId, x.PrefabricatedComponents)))
.ToList();
- newRequiredMaterials.AddRange(continuationMaterials);
- foreach (var item in continuationMaterials)
- {
- addedMaterialIds.Add(item.PipeLineMatId);
- }
+ orderedMaterials.AddRange(continuationMaterials);
+ addedMaterialIds.UnionWith(continuationMaterials.Select(x => x.PipeLineMatId));
}
// 最后处理所有尚未开工组件,保持管线及组件内的稳定排序。
foreach (string id in pipelineIds)
{
- newRequiredMaterials.AddRange(orderedPipelineMaterials[id].Where(x => !addedMaterialIds.Contains(x.PipeLineMatId)));
+ orderedMaterials.AddRange(orderedPipelineMaterials[id].Where(x => !addedMaterialIds.Contains(x.PipeLineMatId)));
}
- results = GetMatMatchOutput(newRequiredMaterials, warehouseCode, projectId, true);
+ results = GetMatMatchOutput(orderedMaterials, warehouseCode, projectId, true);
// 组件匹配率以当前区域剩余未焊口的材料需求为口径,并回填到每条明细供表格合并展示。
foreach (var componentGroup in results.GroupBy(x => new { x.PipelineId, x.PrefabricatedComponents }))
{
@@ -594,10 +553,8 @@ namespace BLL
int weldedCount = weldJoints.Count(x => !string.IsNullOrEmpty(x.WeldingDailyId));
int totalCount = weldJoints.Count;
// 材料编码优先采用匹配页面使用的 MaterialCode2,数量按当前区域组件材料明细汇总。
- var componentMaterialRows = group
+ var materialGroups = group
.Where(x => (x.Number ?? 0) > 0)
- .ToList();
- var materialGroups = componentMaterialRows
.Select(x => new
{
WeldJointId = x.WeldJointId,
@@ -695,7 +652,7 @@ namespace BLL
private static string GetComponentKey(string pipelineId, string componentCode)
{
- return (pipelineId ?? string.Empty) + "\u001f" + (componentCode ?? string.Empty);
+ return pipelineId + "\u001f" + componentCode;
}
///
/// 根据管线材料匹配结果,获取管线匹配率
@@ -704,20 +661,24 @@ namespace BLL
///
public static List GetPipeMatch(List twPipeMatMatch)
{
- var result = twPipeMatMatch
- .GroupBy(item => new { item.PipelineId, item.PipelineCode, item.UnitWorkName }) // 按 PipelineId 和 PipelineCode 分组
- .Select(group => new Tw_PipeMatchOutput
+ return twPipeMatMatch
+ .GroupBy(item => new { item.PipelineId, item.PipelineCode, item.UnitWorkName })
+ .Select(group =>
{
- PipelineId = group.Key.PipelineId, // 当前组的 PipelineId
- PipelineCode = group.Key.PipelineCode, // 当前组的 PipelineCode
- UnitWorkName = group.Key.UnitWorkName, // 当前组的 UnitWorkName
- SumNeedNum = group.Sum(item => item.NeedNum),
- SumMatchNum = group.Sum(item => item.MatchNum),
- MatchRate = group.Sum(item => item.MatchNum) > 0 && group.Sum(item => item.NeedNum) > 0 ? (decimal)group.Sum(item => item.MatchNum) / (decimal)group.Sum(item => item.NeedNum) : 0,
- MatchRateString = Math.Round((decimal)group.Sum(item => item.MatchNum) / (decimal)group.Sum(item => item.NeedNum) * 100, 2).ToString() + "%"
+ decimal needNum = (decimal)group.Sum(item => item.NeedNum);
+ decimal matchNum = (decimal)group.Sum(item => item.MatchNum);
+ return new Tw_PipeMatchOutput
+ {
+ PipelineId = group.Key.PipelineId,
+ PipelineCode = group.Key.PipelineCode,
+ UnitWorkName = group.Key.UnitWorkName,
+ SumNeedNum = needNum,
+ SumMatchNum = matchNum,
+ MatchRate = matchNum > 0 && needNum > 0 ? matchNum / needNum : 0,
+ MatchRateString = Math.Round(matchNum / needNum * 100, 2).ToString() + "%"
+ };
})
- .ToList(); // 转换为 List
- return result;
+ .ToList();
}
}
diff --git a/SGGL/BLL/HJGL/WeldingManage/WeldAppearanceCheckService.cs b/SGGL/BLL/HJGL/WeldingManage/WeldAppearanceCheckService.cs
index d574cf09..30e5ac5e 100644
--- a/SGGL/BLL/HJGL/WeldingManage/WeldAppearanceCheckService.cs
+++ b/SGGL/BLL/HJGL/WeldingManage/WeldAppearanceCheckService.cs
@@ -255,7 +255,10 @@ namespace BLL
var db = Funs.DB;
var joint = db.HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == item.WeldJointId);
if (joint == null || (joint.WeldingDailyId == null
- && !db.HJGL_WeldingDailyTempDetail.Any(x => x.WeldJointId == item.WeldJointId)))
+ && !db.HJGL_WeldingDailyTempDetail.Any(x => x.WeldJointId == item.WeldJointId
+ && db.AttachFile.Any(a => a.MenuId == Const.HJGL_WeldReportMenuId
+ && a.ToKeyId == x.TempDetailId + "#After"
+ && a.AttachUrl != null && a.AttachUrl != string.Empty))))
{
throw new ArgumentException("只能对已焊接焊口进行外观检测。");
}
diff --git a/SGGL/BLL/HJGL/WeldingManage/WeldingDailyService.cs b/SGGL/BLL/HJGL/WeldingManage/WeldingDailyService.cs
index 1bc9641c..4cf1fddd 100644
--- a/SGGL/BLL/HJGL/WeldingManage/WeldingDailyService.cs
+++ b/SGGL/BLL/HJGL/WeldingManage/WeldingDailyService.cs
@@ -1362,11 +1362,10 @@ namespace BLL
public static DataTable GetRussianWeldJointExportData(IEnumerable weldJoints)
{
var joints = weldJoints.ToList();
- var unitWorkIds = joints.Select(x => x.UnitWorkId).Where(x => x != null && x != string.Empty).Distinct().ToList();
- var unitWorkCodes = (from x in Funs.DB.WBS_UnitWork
- where unitWorkIds.Contains(x.UnitWorkId)
- select new { x.UnitWorkId, x.UnitWorkCode })
- .ToDictionary(x => x.UnitWorkId, x => x.UnitWorkCode);
+ var consumableIds = joints.SelectMany(x => new[] { x.WeldingWire, x.WeldingRod })
+ .Where(x => !string.IsNullOrEmpty(x)).Distinct().ToList();
+ var consumableBrands = Funs.DB.Base_Consumables.Where(x => consumableIds.Contains(x.ConsumablesId))
+ .ToDictionary(x => x.ConsumablesId, x => x.ConsumablesName);
var weldJointIds = joints.Select(x => x.WeldJointId).Distinct().ToList();
var appearanceChecks = new List();
var materialRows = new List();
@@ -1377,16 +1376,20 @@ namespace BLL
appearanceChecks.AddRange(Funs.DB.HJGL_WeldAppearanceCheck
.Where(x => batchIds.Contains(x.WeldJointId) && x.ProjectId == joints[0].ProjectId)
.ToList());
- // 与焊口铭牌一致,米、个、片优先作为母材1。
+ // 未关联炉批号的导入材料也保留,仅按导入编码补充单位用于排序。
var batchMaterials = (from material in Funs.DB.HJGL_PipeLineMat
- join lib in Funs.DB.HJGL_MaterialCodeLib on material.MaterialCode equals lib.MaterialCode
+ join codeLib in Funs.DB.HJGL_MaterialCodeLib on material.MaterialCode equals codeLib.MaterialCode into matchedLibs
+ from lib in matchedLibs.DefaultIfEmpty()
where batchIds.Contains(material.WeldJointId)
- orderby lib.MaterialUnit == "米" ? 1 : lib.MaterialUnit == "个" ? 2 : lib.MaterialUnit == "片" ? 3 : 4
+ let materialUnit = lib.MaterialUnit ?? Funs.DB.HJGL_MaterialCodeLib
+ .Where(c => (c.ProjectId == joints[0].ProjectId || c.ProjectId == null) && c.Code == material.MaterialCode2)
+ .OrderBy(c => c.MaterialCode).Select(c => c.MaterialUnit).FirstOrDefault()
+ orderby materialUnit == "米" ? 1 : materialUnit == "个" ? 2 : materialUnit == "片" ? 3 : 4
select new { Material = material, Lib = lib }).ToList();
foreach (var material in batchMaterials)
{
materialRows.Add(material.Material);
- materialLibs[material.Lib.MaterialCode] = material.Lib;
+ materialLibs[material.Material.PipeLineMatId] = material.Lib;
}
}
var materialsByJoint = materialRows.ToLookup(x => x.WeldJointId);
@@ -1399,8 +1402,10 @@ namespace BLL
var rows = joints.Select(x =>
{
- string unitWorkCode;
- unitWorkCodes.TryGetValue(x.UnitWorkId ?? string.Empty, out unitWorkCode);
+ string wireBrand;
+ consumableBrands.TryGetValue(x.WeldingWire ?? string.Empty, out wireBrand);
+ string rodBrand;
+ consumableBrands.TryGetValue(x.WeldingRod ?? string.Empty, out rodBrand);
string checkCode;
checkCodes.TryGetValue(x.WeldJointId, out checkCode);
string[] methods = (x.WeldingMethodCode ?? string.Empty)
@@ -1412,8 +1417,8 @@ namespace BLL
string pipelineDetectionType = (x.DetectionTypeStr ?? string.Empty).ToUpperInvariant();
var material1 = materialsByJoint[x.WeldJointId].FirstOrDefault();
var material2 = materialsByJoint[x.WeldJointId].Skip(1).FirstOrDefault();
- var lib1 = material1 == null ? null : materialLibs[material1.MaterialCode];
- var lib2 = material2 == null ? null : materialLibs[material2.MaterialCode];
+ var lib1 = material1 == null ? null : materialLibs[material1.PipeLineMatId];
+ var lib2 = material2 == null ? null : materialLibs[material2.PipeLineMatId];
string componentName = string.Join("/", new[] { x.ComponentsCode1, x.ComponentsCode2 }
.Where(value => value != null && value != string.Empty));
string teamName = string.Join("/", new[] { x.BackingWelderTeamGroupName, x.CoverWelderTeamGroupName }
@@ -1423,7 +1428,7 @@ namespace BLL
{
MediumCode = x.MediumCode,
SheetNo = string.Empty,
- AreaNo = unitWorkCode,
+ AreaNo = x.UnitWorkName,
DrawingNo = x.SingleNumber,
PIDNo = string.Empty,
LineRevision = string.Empty,
@@ -1458,13 +1463,13 @@ namespace BLL
RTUTTrustCode = detectionType.Contains("RT") || detectionType.Contains("UT") ? x.TrustBatchCode : string.Empty,
PTTrustCode = detectionType.Contains("PT") ? x.TrustBatchCode : string.Empty,
PMITrustCode = detectionType.Contains("PMI") ? x.TrustBatchCode : string.Empty,
- PWHT = x.IsHotProess.HasValue ? (x.IsHotProess.Value ? "Yes" : "No") : string.Empty,
+ PWHT = x.IsHotProess == true ? "Yes" : "No",
PWHTTrustCode = string.Empty,
- WeldingMaterial1 = x.WeldingWireCode,
- WeldingMaterial2 = x.WeldingRodCode,
- ComponentCode1 = material1 == null ? string.Empty : string.IsNullOrEmpty(material1.MaterialCode2) ? lib1.Code : material1.MaterialCode2,
+ WeldingMaterial1 = wireBrand,
+ WeldingMaterial2 = rodBrand,
+ ComponentCode1 = material1 == null ? string.Empty : string.IsNullOrEmpty(material1.MaterialCode2) ? (lib1 == null ? material1.MaterialCode : lib1.Code) : material1.MaterialCode2,
HeatNo1 = lib1 == null ? string.Empty : string.Join("+", new[] { lib1.HeatNo, lib1.BatchNo }.Where(value => !string.IsNullOrEmpty(value))),
- ComponentCode2 = material2 == null ? string.Empty : string.IsNullOrEmpty(material2.MaterialCode2) ? lib2.Code : material2.MaterialCode2,
+ ComponentCode2 = material2 == null ? string.Empty : string.IsNullOrEmpty(material2.MaterialCode2) ? (lib2 == null ? material2.MaterialCode : lib2.Code) : material2.MaterialCode2,
HeatNo2 = lib2 == null ? string.Empty : string.Join("+", new[] { lib2.HeatNo, lib2.BatchNo }.Where(value => !string.IsNullOrEmpty(value))),
TeamName = teamName,
WeldCheckCode = checkCode,
diff --git a/SGGL/FineUIPro.Web/File/Fastreport/无损检测委托单_附件6.frx b/SGGL/FineUIPro.Web/File/Fastreport/无损检测委托单_附件6.frx
index e576c76c..8a0e765a 100644
--- a/SGGL/FineUIPro.Web/File/Fastreport/无损检测委托单_附件6.frx
+++ b/SGGL/FineUIPro.Web/File/Fastreport/无损检测委托单_附件6.frx
@@ -38,7 +38,7 @@ namespace FastReport
}
}
-
- 维护材料编码
+ 维护材料信息
@@ -30,6 +30,14 @@
+
+
+
+
+
+
- /// 保存材料主编码和材料编码。
+ /// 保存材料编码、数量和用途。
///
protected void btnSave_Click(object sender, EventArgs e)
{
- if (string.IsNullOrEmpty(this.PipeLineMatId))
+ Model.HJGL_PipeLineMat pipeLineMat = PipelineMatService.GetPipeLineMat(this.PipeLineMatId);
+ if (pipeLineMat == null)
{
Alert.ShowInTop("未找到材料记录!", MessageBoxIcon.Warning);
return;
}
+ decimal number;
+ if (!decimal.TryParse(this.txtNumber.Text.Trim(), out number)
+ || number < 0m || number > 9999999.99m || decimal.Round(number, 2) != number)
+ {
+ Alert.ShowInTop("数量请输入0至9999999.99之间的数值,最多保留两位小数!", MessageBoxIcon.Warning);
+ return;
+ }
+
string mainMaterialCode = GetMainMaterialCode();
if (!string.IsNullOrEmpty(mainMaterialCode) && MaterialCodeLibService.GetMaterialCodeLib(mainMaterialCode) == null)
{
@@ -117,11 +127,11 @@ namespace FineUIPro.Web.HJGL.DataImport
return;
}
- PipelineMatService.UpdateMaterialCodes(
- this.PipeLineMatId,
- mainMaterialCode,
- this.txtMaterialCode.Text.Trim());
- PipelineMatService.UpdatePipeArea(this.PipeLineMatId, this.drpPipeArea.SelectedValue);
+ pipeLineMat.MaterialCode = mainMaterialCode;
+ pipeLineMat.MaterialCode2 = this.txtMaterialCode.Text.Trim();
+ pipeLineMat.Number = number;
+ pipeLineMat.PipeArea = this.drpPipeArea.SelectedValue;
+ PipelineMatService.UpdatePipeLineMat(pipeLineMat);
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
diff --git a/SGGL/FineUIPro.Web/HJGL/DataImport/MaterialInformationEdit.aspx.designer.cs b/SGGL/FineUIPro.Web/HJGL/DataImport/MaterialInformationEdit.aspx.designer.cs
index 13bc9da0..a339e964 100644
--- a/SGGL/FineUIPro.Web/HJGL/DataImport/MaterialInformationEdit.aspx.designer.cs
+++ b/SGGL/FineUIPro.Web/HJGL/DataImport/MaterialInformationEdit.aspx.designer.cs
@@ -59,6 +59,11 @@ namespace FineUIPro.Web.HJGL.DataImport
///
protected global::FineUIPro.TextBox txtMaterialCode;
+ ///
+ /// txtNumber 控件。
+ ///
+ protected global::FineUIPro.NumberBox txtNumber;
+
///
/// txtHeatNo 控件。
///
diff --git a/SGGL/FineUIPro.Web/HJGL/PointTrust/TrustBatch.aspx.cs b/SGGL/FineUIPro.Web/HJGL/PointTrust/TrustBatch.aspx.cs
index f9a9cc5d..b2db4956 100644
--- a/SGGL/FineUIPro.Web/HJGL/PointTrust/TrustBatch.aspx.cs
+++ b/SGGL/FineUIPro.Web/HJGL/PointTrust/TrustBatch.aspx.cs
@@ -768,7 +768,7 @@ namespace FineUIPro.Web.HJGL.PointTrust
DataRow detailRow = detailTable.NewRow();
detailRow["Sequence"] = sequence++;
detailRow["PipelineCode"] = item.PipelineCode ?? string.Empty;
- detailRow["WeldJointCode"] = item.WeldJointCode ?? string.Empty;
+ detailRow["WeldJointCode"] = "S" + item.WeldJointCode;
detailRow["Specification"] = item.Specification ?? string.Empty;
detailRow["GrooveType"] = item.GrooveTypeCode ?? string.Empty;
detailRow["WeldingMethod"] = item.WeldingMethodCode ?? string.Empty;
diff --git a/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineListPDMSIn.aspx b/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineListPDMSIn.aspx
index 18fc50f5..f8ddc588 100644
--- a/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineListPDMSIn.aspx
+++ b/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineListPDMSIn.aspx
@@ -20,6 +20,7 @@
+
diff --git a/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineListPDMSIn.aspx.cs b/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineListPDMSIn.aspx.cs
index 6897a8a7..58dd111f 100644
--- a/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineListPDMSIn.aspx.cs
+++ b/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineListPDMSIn.aspx.cs
@@ -18,23 +18,30 @@ namespace FineUIPro.Web.HJGL.WeldingManage
private string initPath = Const.ExcelUrl;
///
- /// 安装组件集合
+ /// 每个导入窗口独立保存审核数据,避免同一用户多窗口或不同用户串用模板。
///
- public static List PipelineList = new List();
+ private sealed class ImportContext
+ {
+ public string ProjectId;
+ public string PersonId;
+ public string UnitWorkId;
+ public string FileName;
+ public string OriginalFileName;
+ public List Rows = new List();
+ public int State;
+ }
- ///
- /// 错误集合
- ///
- public static string errorInfos = string.Empty;
+ private ImportContext importContext;
+ private string ImportSessionKey { get { return "PipelineListPDMSIn:" + (string)ViewState["ImportToken"]; } }
+ private List PipelineList { get { return importContext.Rows; } }
+ private int State { get { return importContext.State; } set { importContext.State = value; } }
///
/// 导入数据分类(管线)
///
- public static string DataClassification = "Pipeline";
+ private const string DataClassification = "Pipeline";
public enum ButtonState { Check = 0, Import = 1, Save = 2 }
- public static int State;
-
#endregion
#region 加载
@@ -45,19 +52,40 @@ namespace FineUIPro.Web.HJGL.WeldingManage
///
protected void Page_Load(object sender, EventArgs e)
{
+ if (this.CurrUser == null)
+ {
+ throw new InvalidOperationException("登录已失效,请重新登录后打开导入窗口。");
+ }
+ var unitWorkId = Request.QueryString["UnitWorkId"];
+ var unitWork = BLL.UnitWorkService.GetUnitWorkByUnitWorkId(unitWorkId);
+ if (unitWork == null || unitWork.ProjectId != this.CurrUser.LoginProjectId)
+ {
+ throw new InvalidOperationException("单位工程不属于当前项目,不能导入或恢复数据。");
+ }
if (!IsPostBack)
{
- this.hdFileName.Text = string.Empty;
- State = (int)ButtonState.Check;
-
- if (PipelineList != null)
+ ViewState["ImportToken"] = Guid.NewGuid().ToString("N");
+ importContext = new ImportContext
{
- PipelineList.Clear();
- }
- errorInfos = string.Empty;
- lbVersion.Text = BLL.HJGL_DesignBasisDataImportService.GetNowVersionByUnitWorkId(Request.Params["UnitWorkId"], DataClassification).ToString();
+ ProjectId = this.CurrUser.LoginProjectId,
+ PersonId = this.CurrUser.PersonId,
+ UnitWorkId = unitWorkId
+ };
+ Session[ImportSessionKey] = importContext;
+ this.hdFileName.Text = string.Empty;
+ lbVersion.Text = BLL.HJGL_DesignBasisDataImportService.GetNowVersionByUnitWorkId(unitWorkId, DataClassification).ToString();
BindGrid2();
}
+ else
+ {
+ importContext = Session[ImportSessionKey] as ImportContext;
+ if (importContext == null || importContext.ProjectId != this.CurrUser.LoginProjectId
+ || importContext.PersonId != this.CurrUser.PersonId || importContext.UnitWorkId != unitWorkId
+ || importContext.FileName != (string)ViewState["ImportFileName"])
+ {
+ throw new InvalidOperationException("导入窗口已失效或数据已变更,请重新打开窗口审核文件。");
+ }
+ }
}
#endregion
void BindGrid2()
@@ -66,7 +94,8 @@ namespace FineUIPro.Web.HJGL.WeldingManage
,Import.ProjectId
,Import.UnitWorkId
,(Case Import.ImportType when '0' then '补充导入'
- when '1' then '更新导入' end) as ImportType
+ when '1' then '更新导入'
+ when '2' then '更新导入(管线)' end) as ImportType
,Import.FileName
,Import.FilePath
,Import.DataClassification
@@ -84,7 +113,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
order by Import.CreateDate";
List listStr = new List();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
- listStr.Add(new SqlParameter("@UnitWorkId", Request.Params["UnitWorkId"]));
+ listStr.Add(new SqlParameter("@UnitWorkId", importContext.UnitWorkId));
listStr.Add(new SqlParameter("@DataClassification", DataClassification));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
@@ -96,7 +125,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
var table = this.GetPagedDataTable(Grid2, tb);
Grid2.DataSource = table;
Grid2.DataBind();
- drpVersion.DataSource = BLL.HJGL_DesignBasisDataImportService.GetListVersionByUnitWorkId(Request.Params["UnitWorkId"], DataClassification);
+ drpVersion.DataSource = BLL.HJGL_DesignBasisDataImportService.GetListVersionByUnitWorkId(importContext.UnitWorkId, DataClassification);
drpVersion.DataBind();
}
@@ -110,6 +139,12 @@ namespace FineUIPro.Web.HJGL.WeldingManage
{
try
{
+ State = (int)ButtonState.Check;
+ PipelineList.Clear();
+ importContext.FileName = null;
+ importContext.OriginalFileName = null;
+ ViewState["ImportFileName"] = null;
+ hdFileName.Text = string.Empty;
if (this.fuAttachUrl.HasFile == false)
{
ShowNotify("请您选择Excel文件!", MessageBoxIcon.Warning);
@@ -121,14 +156,6 @@ namespace FineUIPro.Web.HJGL.WeldingManage
ShowNotify("只可以选择Excel文件!", MessageBoxIcon.Warning);
return;
}
- if (PipelineList != null)
- {
- PipelineList.Clear();
- }
- if (!string.IsNullOrEmpty(errorInfos))
- {
- errorInfos = string.Empty;
- }
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
if (!Directory.Exists(initFullPath))
@@ -136,10 +163,17 @@ namespace FineUIPro.Web.HJGL.WeldingManage
Directory.CreateDirectory(initFullPath);
}
- this.hdFileName.Text = BLL.Funs.GetNewFileName() + IsXls;
- string filePath = initFullPath + this.hdFileName.Text;
+ string uploadedFileName = Guid.NewGuid().ToString("N") + IsXls;
+ string filePath = initFullPath + uploadedFileName;
this.fuAttachUrl.PostedFile.SaveAs(filePath);
- ImportXlsToData(rootPath + initPath + this.hdFileName.Text);
+ var rows = ReadImportFile(filePath);
+ importContext.Rows = rows;
+ importContext.FileName = uploadedFileName;
+ importContext.OriginalFileName = this.fuAttachUrl.FileName;
+ ViewState["ImportFileName"] = uploadedFileName;
+ hdFileName.Text = uploadedFileName;
+ State = (int)ButtonState.Import;
+ ShowNotify("审核完成请点击导入");
}
catch (Exception ex)
{
@@ -156,36 +190,18 @@ namespace FineUIPro.Web.HJGL.WeldingManage
/// 从Excel提取数据--》Dataset
///
/// Excel文件路径名
- private void ImportXlsToData(string fileName)
+ private List ReadImportFile(string fileName)
{
- try
+ var rows = new List();
+ var ds = MiniExcel.Query(fileName).ToList();
+ var columns = MiniExcel.GetColumns(fileName);
+ var result = AddDatasetToSQL(ds, columns.Count, rows);
+ if (result.code != 1)
{
- var ds = MiniExcel.Query(fileName).ToList();
- var columns = MiniExcel.GetColumns(fileName);
- var cnt = columns.Count;
- var reposedata = AddDatasetToSQL(ds, cnt);
- if (reposedata.code == 1)
- {
- State = (int)ButtonState.Import;
- ShowNotify("审核完成请点击导入");
- }
- else
- {
- Alert alert = new Alert
- {
- Message = reposedata.message,
- Target = Target.Self
- };
- alert.Show();
- //ShowNotify(reposedata.message);
- }
- }
- catch (Exception exc)
- {
-
- ErrLogInfo.WriteLog("焊接基础数据上传失败!", exc);
-
+ throw new InvalidOperationException(result.message);
}
+ ValidatePipelineScope(rows, importContext.UnitWorkId);
+ return rows;
}
#endregion
@@ -198,7 +214,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
/// 数据集
/// 数据集行数
///
- private Model.ResponeData AddDatasetToSQL(List pds, int count)
+ private Model.ResponeData AddDatasetToSQL(List pds, int count, List rows)
{
Model.ResponeData responeData = new Model.ResponeData();
// string result = string.Empty;
@@ -227,7 +243,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
var getPaintCodeDict = from x in db.Tw_PaintCodeDict where x.IsUsed select x;
//var getComponents = from x in Funs.DB.Base_Components where x.ProjeceId == this.CurrUser.LoginProjectId select x;
- Model.WBS_UnitWork unitWork = BLL.UnitWorkService.GetUnitWorkByUnitWorkId(Request.Params["UnitWorkId"]);
+ Model.WBS_UnitWork unitWork = BLL.UnitWorkService.GetUnitWorkByUnitWorkId(importContext.UnitWorkId);
for (int i = 1; i < pds.Count; i++)
{
Model.View_HJGL_WeldJoint pipeline = new Model.View_HJGL_WeldJoint();
@@ -235,7 +251,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
if (unitWork != null)
{
- pipeline.UnitWorkId = Request.Params["UnitWorkId"];
+ pipeline.UnitWorkId = importContext.UnitWorkId;
pipeline.UnitId = unitWork.UnitId;
}
@@ -818,28 +834,21 @@ namespace FineUIPro.Web.HJGL.WeldingManage
if (!string.IsNullOrEmpty(pipeline.PipelineCode) && !string.IsNullOrEmpty(pipeline.WeldJointCode))
{
pipeline.ProjectId = this.CurrUser.LoginProjectId;
- PipelineList.Add(pipeline);
+ rows.Add(pipeline);
}
}
if (result.Count > 0)
{
- PipelineList.Clear();
+ rows.Clear();
// result = result.Substring(0, result.LastIndexOf("|"));
- errorInfos = string.Join("|", result.Distinct());
//Alert alert = new Alert();
//alert.Message = result;
//alert.Target = Target.Self;
//alert.Show();
responeData.code = 0;
- responeData.message = errorInfos;
- }
- else
- {
- errorInfos = string.Empty;
-
-
+ responeData.message = string.Join("|", result.Distinct());
}
}
@@ -870,28 +879,20 @@ namespace FineUIPro.Web.HJGL.WeldingManage
return;
}
- if (string.IsNullOrEmpty(errorInfos))
+ if (!string.IsNullOrEmpty(importContext.FileName))
{
- if (!string.IsNullOrEmpty(this.hdFileName.Text))
+ if (PipelineList.Count > 0)
{
- if (PipelineList.Count > 0)
- {
- this.Grid1.Hidden = false;
- this.Grid1.DataSource = PipelineList;
- this.Grid1.DataBind();
- Grid1.RecordCount = PipelineList.Count;
- State = (int)ButtonState.Save;
-
- }
- }
- else
- {
- ShowNotify("请先审核要导入的文件!", MessageBoxIcon.Warning);
+ this.Grid1.Hidden = false;
+ this.Grid1.DataSource = PipelineList;
+ this.Grid1.DataBind();
+ Grid1.RecordCount = PipelineList.Count;
+ State = (int)ButtonState.Save;
}
}
else
{
- ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
+ ShowNotify("请先审核要导入的文件!", MessageBoxIcon.Warning);
}
}
@@ -910,88 +911,119 @@ namespace FineUIPro.Web.HJGL.WeldingManage
return;
}
- if (string.IsNullOrEmpty(errorInfos))
+ string unitworkId = importContext.UnitWorkId;
+ ValidatePipelineScope(PipelineList, unitworkId);
+ if (DrpType.SelectedValue != "0" && DrpType.SelectedValue != "1" && DrpType.SelectedValue != "2")
+ {
+ throw new InvalidOperationException("导入类型无效。");
+ }
+ string rootPath = Server.MapPath("~/");
+ string oldefilePath = rootPath + initPath + importContext.FileName;
+ string filePath = rootPath + Const.DesignBasisDataImportPath + importContext.FileName;
+ if (!Directory.Exists(rootPath + Const.DesignBasisDataImportPath))
+ {
+ Directory.CreateDirectory(rootPath + Const.DesignBasisDataImportPath);
+ }
+ File.Move(oldefilePath, filePath);
+ // 消费服务端提交状态,旧页面回放不能重复执行清理。
+ State = (int)ButtonState.Check;
+ string FileName = importContext.OriginalFileName;
+
+
+ if (DrpType.SelectedValue == "1" || DrpType.SelectedValue == "2")//更新导入
{
- string rootPath = Server.MapPath("~/");
- string oldefilePath = rootPath + initPath + this.hdFileName.Text;
- string unitworkId = Request.Params["UnitWorkId"];
- string filePath = rootPath + Const.DesignBasisDataImportPath + this.hdFileName.Text;
- if (oldefilePath != string.Empty && System.IO.File.Exists(oldefilePath))
+ if (DrpType.SelectedValue == "2")
{
- if (!Directory.Exists(rootPath + Const.DesignBasisDataImportPath))
- {
- Directory.CreateDirectory(rootPath + Const.DesignBasisDataImportPath);
- }
- File.Move(oldefilePath, filePath);
- //System.IO.File.Delete(oldefilePath);//删除上传的XLS文件
+ DeleteImportedPipelines(unitworkId, PipelineList);
}
- string FileName = this.fuAttachUrl.FileName;
-
-
- if (DrpType.SelectedValue == "1")//更新导入
+ else
{
-
BLL.PipelineMatService.DeletePipeLineMatByUnitWorkId(unitworkId);//删除原有管线对应材料
BLL.WeldJointService.DeleteWeldJointByUnitWorkId(unitworkId);////删除原有管线对应焊口
BLL.PipelineService.DeletePipelineByUnitworkId(unitworkId);//删除原有管线
- AddView_HJGL_WeldJoint(PipelineList);//导入数据
-
- Model.HJGL_DesignBasisDataImport hJGL_DesignBasisDataImport = new Model.HJGL_DesignBasisDataImport();
- hJGL_DesignBasisDataImport.DesignBasisDataImportId = SQLHelper.GetNewID();
- hJGL_DesignBasisDataImport.ProjectId = this.CurrUser.LoginProjectId;
- hJGL_DesignBasisDataImport.UnitWorkId = unitworkId;
- hJGL_DesignBasisDataImport.ImportType = "1";
- hJGL_DesignBasisDataImport.DataClassification = DataClassification;
- hJGL_DesignBasisDataImport.FileName = FileName;
- hJGL_DesignBasisDataImport.FilePath = filePath.Replace(rootPath, "");
- hJGL_DesignBasisDataImport.FileType = BLL.HJGL_DesignBasisDataImportService.GetFileType(FileName);
- hJGL_DesignBasisDataImport.Version = BLL.HJGL_DesignBasisDataImportService.GetNewVersionByUnitWorkId(unitworkId, DataClassification);
- hJGL_DesignBasisDataImport.Remark = txtRemark.Text;
- hJGL_DesignBasisDataImport.CreateMan = this.CurrUser.PersonId;
- hJGL_DesignBasisDataImport.CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
- BLL.HJGL_DesignBasisDataImportService.AddHJGL_DesignBasisDataImport(hJGL_DesignBasisDataImport);
-
- BLL.HJGL_DesignBasisDataImportVerSionLogService.UpdateVersion(this.CurrUser.LoginProjectId, unitworkId, (decimal)hJGL_DesignBasisDataImport.Version, DataClassification);
-
-
}
- else //补充导入
- {
- AddView_HJGL_WeldJoint(PipelineList);
+ AddView_HJGL_WeldJoint(PipelineList);//导入数据
- Model.HJGL_DesignBasisDataImport hJGL_DesignBasisDataImport = new Model.HJGL_DesignBasisDataImport();
- hJGL_DesignBasisDataImport.DesignBasisDataImportId = SQLHelper.GetNewID();
- hJGL_DesignBasisDataImport.ProjectId = this.CurrUser.LoginProjectId;
- hJGL_DesignBasisDataImport.UnitWorkId = unitworkId;
- hJGL_DesignBasisDataImport.ImportType = "0";
- hJGL_DesignBasisDataImport.DataClassification = DataClassification;
- hJGL_DesignBasisDataImport.FileName = FileName;
- hJGL_DesignBasisDataImport.FilePath = filePath.Replace(rootPath, ""); ;
- hJGL_DesignBasisDataImport.FileType = BLL.HJGL_DesignBasisDataImportService.GetFileType(FileName);
- hJGL_DesignBasisDataImport.Version = BLL.HJGL_DesignBasisDataImportService.GetNowVersionByUnitWorkId(unitworkId, DataClassification);
- hJGL_DesignBasisDataImport.Remark = txtRemark.Text;
- hJGL_DesignBasisDataImport.CreateMan = this.CurrUser.PersonId;
- hJGL_DesignBasisDataImport.CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
- BLL.HJGL_DesignBasisDataImportService.AddHJGL_DesignBasisDataImport(hJGL_DesignBasisDataImport);
+ Model.HJGL_DesignBasisDataImport hJGL_DesignBasisDataImport = new Model.HJGL_DesignBasisDataImport();
+ hJGL_DesignBasisDataImport.DesignBasisDataImportId = SQLHelper.GetNewID();
+ hJGL_DesignBasisDataImport.ProjectId = this.CurrUser.LoginProjectId;
+ hJGL_DesignBasisDataImport.UnitWorkId = unitworkId;
+ hJGL_DesignBasisDataImport.ImportType = DrpType.SelectedValue;
+ hJGL_DesignBasisDataImport.DataClassification = DataClassification;
+ hJGL_DesignBasisDataImport.FileName = FileName;
+ hJGL_DesignBasisDataImport.FilePath = filePath.Replace(rootPath, "");
+ hJGL_DesignBasisDataImport.FileType = BLL.HJGL_DesignBasisDataImportService.GetFileType(FileName);
+ hJGL_DesignBasisDataImport.Version = BLL.HJGL_DesignBasisDataImportService.GetNewVersionByUnitWorkId(unitworkId, DataClassification);
+ hJGL_DesignBasisDataImport.Remark = txtRemark.Text;
+ hJGL_DesignBasisDataImport.CreateMan = this.CurrUser.PersonId;
+ hJGL_DesignBasisDataImport.CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
+ BLL.HJGL_DesignBasisDataImportService.AddHJGL_DesignBasisDataImport(hJGL_DesignBasisDataImport);
- BLL.HJGL_DesignBasisDataImportVerSionLogService.UpdateVersion(this.CurrUser.LoginProjectId, unitworkId, (decimal)hJGL_DesignBasisDataImport.Version, DataClassification);
+ BLL.HJGL_DesignBasisDataImportVerSionLogService.UpdateVersion(this.CurrUser.LoginProjectId, unitworkId, (decimal)hJGL_DesignBasisDataImport.Version, DataClassification);
- }
- ShowNotify("导入成功!", MessageBoxIcon.Success);
- PipelineService.RestPipelineAndJoints(this.CurrUser.LoginProjectId);
-
- PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
- else
+ else //补充导入
{
- ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
+ AddView_HJGL_WeldJoint(PipelineList);
+
+ Model.HJGL_DesignBasisDataImport hJGL_DesignBasisDataImport = new Model.HJGL_DesignBasisDataImport();
+ hJGL_DesignBasisDataImport.DesignBasisDataImportId = SQLHelper.GetNewID();
+ hJGL_DesignBasisDataImport.ProjectId = this.CurrUser.LoginProjectId;
+ hJGL_DesignBasisDataImport.UnitWorkId = unitworkId;
+ hJGL_DesignBasisDataImport.ImportType = "0";
+ hJGL_DesignBasisDataImport.DataClassification = DataClassification;
+ hJGL_DesignBasisDataImport.FileName = FileName;
+ hJGL_DesignBasisDataImport.FilePath = filePath.Replace(rootPath, ""); ;
+ hJGL_DesignBasisDataImport.FileType = BLL.HJGL_DesignBasisDataImportService.GetFileType(FileName);
+ hJGL_DesignBasisDataImport.Version = BLL.HJGL_DesignBasisDataImportService.GetNowVersionByUnitWorkId(unitworkId, DataClassification);
+ hJGL_DesignBasisDataImport.Remark = txtRemark.Text;
+ hJGL_DesignBasisDataImport.CreateMan = this.CurrUser.PersonId;
+ hJGL_DesignBasisDataImport.CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
+ BLL.HJGL_DesignBasisDataImportService.AddHJGL_DesignBasisDataImport(hJGL_DesignBasisDataImport);
+
+ BLL.HJGL_DesignBasisDataImportVerSionLogService.UpdateVersion(this.CurrUser.LoginProjectId, unitworkId, (decimal)hJGL_DesignBasisDataImport.Version, DataClassification);
+
+ }
+
+ ShowNotify("导入成功!", MessageBoxIcon.Success);
+ PipelineService.RestPipelineAndJoints(this.CurrUser.LoginProjectId);
+ Session.Remove(ImportSessionKey);
+ PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
+ }
+ ///
+ /// 在模板进入写入流程前校验所属范围,拒绝失效或混入其他工程的数据。
+ ///
+ private void ValidatePipelineScope(List rows, string unitworkId)
+ {
+ if (unitworkId != importContext.UnitWorkId || rows.Count == 0
+ || rows.Any(x => x.ProjectId != importContext.ProjectId || x.UnitWorkId != unitworkId
+ || string.IsNullOrWhiteSpace(x.PipelineCode) || string.IsNullOrWhiteSpace(x.WeldJointCode)))
+ {
+ throw new InvalidOperationException("模板为空或数据不属于当前项目、单位工程,请重新审核。");
}
}
+ ///
+ /// 只清理当前单位工程中本次模板涉及的管线及其组件、材料和焊口。
+ ///
+ private void DeleteImportedPipelines(string unitworkId, List rows)
+ {
+ var pipelineCodes = rows.Select(x => x.PipelineCode).Distinct().ToList();
+ var pipelines = BLL.PipelineService.GetPipelinesByUnitWordId(unitworkId)
+ .Where(x => x.ProjectId == importContext.ProjectId && pipelineCodes.Contains(x.PipelineCode)).ToList();
+ foreach (var pipeline in pipelines)
+ {
+ BLL.HJGL_PipelineComponentService.DeletePipelineComponentBypipelineId(pipeline.PipelineId);
+ BLL.PipelineMatService.DeletePipeLineMatBypipelineId(pipeline.PipelineId);
+ BLL.WeldJointService.DeleteWeldJointByPipelineId(pipeline.PipelineId);
+ BLL.PipelineService.DeletePipeline(pipeline.PipelineId);
+ }
+ }
+
public void AddView_HJGL_WeldJoint(List PipelineList)
{
- string unitworkId = Request.Params["UnitWorkId"];
+ string unitworkId = importContext.UnitWorkId;
addPipelines(PipelineList, unitworkId);
addHJGL_WeldJoints(PipelineList, unitworkId);
@@ -1298,22 +1330,35 @@ namespace FineUIPro.Web.HJGL.WeldingManage
///
private void RestoreVersion(string unitworkId, decimal version)
{
+ if (unitworkId != importContext.UnitWorkId)
+ {
+ throw new InvalidOperationException("恢复目标与当前导入窗口的单位工程不一致。");
+ }
var model = BLL.HJGL_DesignBasisDataImportService.GetDataByUnitWorkIdAndVersion(unitworkId, version, DataClassification);
if (model != null && model.Count > 0)
{
+ // 所有历史文件先校验成功,再进入清理流程;恢复不复用当前上传模板。
+ var batches = new List>>();
foreach (var item in model)
{
-
- string rootPath = Server.MapPath("~/");
- // initFullPath = rootPath + initPath;
- string filePath = rootPath + item.FilePath;
- ImportXlsToData(filePath);
- BLL.PipelineMatService.DeletePipeLineMatByUnitWorkId(unitworkId);//删除原有管线对应材料
- BLL.WeldJointService.DeleteWeldJointByUnitWorkId(unitworkId);////删除原有管线对应焊口
- BLL.PipelineService.DeletePipelineByUnitworkId(unitworkId);//删除原有管线
- AddView_HJGL_WeldJoint(PipelineList);//导入数据
- PipelineList.Clear();
-
+ if (item.ProjectId != importContext.ProjectId || item.UnitWorkId != unitworkId
+ || item.DataClassification != DataClassification
+ || (item.ImportType != "0" && item.ImportType != "1" && item.ImportType != "2"))
+ {
+ throw new InvalidOperationException("历史导入记录不属于当前项目、单位工程或导入类型无效,不能恢复。");
+ }
+ var rows = ReadImportFile(Server.MapPath("~/") + item.FilePath);
+ batches.Add(new KeyValuePair>(item.ImportType, rows));
+ }
+ // 仅重建本版本模板合集涉及的管线,保留模板外管线。
+ DeleteImportedPipelines(unitworkId, batches.SelectMany(x => x.Value).ToList());
+ foreach (var batch in batches)
+ {
+ if (batch.Key == "1" || batch.Key == "2")
+ {
+ DeleteImportedPipelines(unitworkId, batch.Value);
+ }
+ AddView_HJGL_WeldJoint(batch.Value);
}
BLL.HJGL_DesignBasisDataImportVerSionLogService.UpdateVersion(this.CurrUser.LoginProjectId, unitworkId, version, DataClassification);
PipelineService.RestPipelineAndJoints(this.CurrUser.LoginProjectId);
@@ -1333,7 +1378,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
}
else
{
- PageContext.RegisterStartupScript(Confirm.GetShowReference("确定恢复至该版本吗?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_Restore"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
+ PageContext.RegisterStartupScript(Confirm.GetShowReference("确定恢复该版本模板涉及的管线吗?模板外管线将保留。", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_Restore"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
@@ -1374,7 +1419,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
}
else if (e.EventArgument == "Confirm_Restore")
{
- var unitworkid = Request.Params["UnitWorkId"];
+ var unitworkid = importContext.UnitWorkId;
decimal version = decimal.Parse(drpVersion.SelectedValue);
RestoreVersion(unitworkid, version);
}
diff --git a/SGGL/FineUIPro.Web/HJGL/WeldingManage/WeldMatMatch.aspx.cs b/SGGL/FineUIPro.Web/HJGL/WeldingManage/WeldMatMatch.aspx.cs
index fa86fc85..55269d89 100644
--- a/SGGL/FineUIPro.Web/HJGL/WeldingManage/WeldMatMatch.aspx.cs
+++ b/SGGL/FineUIPro.Web/HJGL/WeldingManage/WeldMatMatch.aspx.cs
@@ -131,9 +131,6 @@ namespace FineUIPro.Web.HJGL.WeldingManage
drpWarehouse_SelectedIndexChanged(null, null);
}
- ///
- /// 清空材料库存缓存,避免首次加载沿用其他入口的区域缓存。
- ///
///
/// 绑定当前项目的流水段筛选项。
///
@@ -500,7 +497,8 @@ namespace FineUIPro.Web.HJGL.WeldingManage
{
Grid1.Rows[i].RowCssClass = "red";
}
- else if (IsMaterialCodeConfirmed(model, confirmedPipeLineMatIds))
+ else if (!string.IsNullOrEmpty(model.PipeLineMatId)
+ && confirmedPipeLineMatIds.Contains(model.PipeLineMatId))
{
Grid1.Rows[i].RowCssClass = "green";
}
@@ -601,20 +599,6 @@ namespace FineUIPro.Web.HJGL.WeldingManage
return new HashSet(confirmedIds);
}
- ///
- /// 判断单条材料明细是否已经反写材料主编码。
- ///
- /// 材料匹配明细。
- /// 已反写材料主编码的管线材料ID集合。
- /// 已反写返回 true,否则返回 false。
- private bool IsMaterialCodeConfirmed(Tw_PipeMatMatchOutput model, HashSet confirmedPipeLineMatIds)
- {
- return model != null
- && confirmedPipeLineMatIds != null
- && !string.IsNullOrEmpty(model.PipeLineMatId)
- && confirmedPipeLineMatIds.Contains(model.PipeLineMatId);
- }
-
///
/// 显示材料匹配颜色和任务单生成规则说明。
///
@@ -642,7 +626,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
private void RefreshMatchResult()
{
// 重新匹配库存会刷新管线汇总表,先暂存选择状态,绑定完成后再恢复。
- var keepSelectedPipelineIds = Grid2.SelectedRowIDArray == null ? new List() : Grid2.SelectedRowIDArray.ToList();
+ var keepSelectedPipelineIds = Grid2.SelectedRowIDArray?.ToList() ?? new List();
tw_PipeMatMatchOutputs = TwArrivalStatisticsService.GetPipeMatMatch(
this.CurrUser.LoginProjectId,
dicSeclectPipeLine.Keys.ToList(),
@@ -966,7 +950,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
}
// 优先焊口会触发重新匹配,当前管线也必须继续保持选中,方便后续生成任务单。
- var keepSelectedPipelineIds = Grid2.SelectedRowIDArray == null ? new List() : Grid2.SelectedRowIDArray.ToList();
+ var keepSelectedPipelineIds = Grid2.SelectedRowIDArray?.ToList() ?? new List();
if (!keepSelectedPipelineIds.Contains(selectedPipelineId))
{
keepSelectedPipelineIds.Add(selectedPipelineId);
@@ -976,6 +960,28 @@ namespace FineUIPro.Web.HJGL.WeldingManage
BindMaterialDetail();
}
+ private List GetSelectedPipelineMaterials()
+ {
+ if (tw_PipeMatMatchOutputs == null || !tw_PipeMatMatchOutputs.Any())
+ {
+ RefreshMatchResult();
+ }
+
+ var selectedPipelineIds = Grid2.SelectedRowIDArray.ToList();
+ return tw_PipeMatMatchOutputs
+ .Where(x => selectedPipelineIds.Contains(x.PipelineId))
+ .ToList();
+ }
+
+ private void RefreshMatchResultAndDetail()
+ {
+ RefreshMatchResult();
+ if (Grid2.SelectedRowIDArray.Any())
+ {
+ BindMaterialDetail();
+ }
+ }
+
///
/// 将当前选中管线的匹配结果反写到管线材料主编码。
///
@@ -989,15 +995,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
return;
}
- if (tw_PipeMatMatchOutputs == null || !tw_PipeMatMatchOutputs.Any())
- {
- RefreshMatchResult();
- }
-
- var selectedPipelineIds = Grid2.SelectedRowIDArray.ToList();
- var matchedMaterials = tw_PipeMatMatchOutputs
- .Where(x => selectedPipelineIds.Contains(x.PipelineId))
- .ToList();
+ var matchedMaterials = GetSelectedPipelineMaterials();
if (!matchedMaterials.Any())
{
ShowNotify("未找到保存的材料匹配明细!", MessageBoxIcon.Warning);
@@ -1006,11 +1004,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
int count = BLL.PipelineMatService.UpdateMaterialCodeByMatchOutputs(matchedMaterials);
ShowNotify("已保存材料主编码" + count.ToString() + "条!", MessageBoxIcon.Success);
- RefreshMatchResult();
- if (Grid2.SelectedRowIDArray.Any())
- {
- BindMaterialDetail();
- }
+ RefreshMatchResultAndDetail();
}
///
@@ -1026,14 +1020,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
return;
}
- if (tw_PipeMatMatchOutputs == null || !tw_PipeMatMatchOutputs.Any())
- {
- RefreshMatchResult();
- }
-
- var selectedPipelineIds = Grid2.SelectedRowIDArray.ToList();
- var pipeLineMatIds = tw_PipeMatMatchOutputs
- .Where(x => selectedPipelineIds.Contains(x.PipelineId))
+ var pipeLineMatIds = GetSelectedPipelineMaterials()
.Select(x => x.PipeLineMatId)
.Distinct()
.ToList();
@@ -1045,11 +1032,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
int count = BLL.PipelineMatService.ClearMaterialCodeByPipeLineMatIds(pipeLineMatIds);
ShowNotify("已清除材料主编码" + count.ToString() + "条,已生成任务单的焊口已跳过!", MessageBoxIcon.Success);
- RefreshMatchResult();
- if (Grid2.SelectedRowIDArray.Any())
- {
- BindMaterialDetail();
- }
+ RefreshMatchResultAndDetail();
}
///
@@ -1094,93 +1077,80 @@ namespace FineUIPro.Web.HJGL.WeldingManage
/// 生成成功返回 true;校验失败或无可生成焊口返回 false。
private bool SaveTask(HashSet selectedWeldJointIds)
{
- if (selectedWeldJointIds == null || !selectedWeldJointIds.Any())
- {
- ShowNotify("选中管线中没有已反写材料主编码的可生成任务单焊口!", MessageBoxIcon.Warning);
- return false;
- }
var weldingRods = from x in Funs.DB.Base_Consumables where x.ConsumablesType == WeldingRodConsumablesType select x;
var weldingWires = from x in Funs.DB.Base_Consumables where x.ConsumablesType == WeldingWireConsumablesType select x;
- var selectedWeldJointIdList = selectedWeldJointIds.ToList();
- var selectRowId = GetTaskableWeldJointRows(selectedWeldJointIdList);
+ var taskableWeldJoints = GetTaskableWeldJointRows(selectedWeldJointIds.ToList());
- Dictionary unitworkTaskCode = new Dictionary();
- Dictionary unitworkSerialNumber = new Dictionary();
- Dictionary matchPipeline = GetMatchPipelineOrder();
- if (!selectRowId.Any())
+ var taskCodesByUnitWorkId = new Dictionary();
+ var serialNumbersByUnitWorkId = new Dictionary();
+ var matchPipelineOrder = new Dictionary();
+ for (int rowIndex = 0; rowIndex < Grid2.Rows.Count; rowIndex++)
+ {
+ matchPipelineOrder.Add(rowIndex + 1, Grid2.Rows[rowIndex].RowID);
+ }
+ if (!taskableWeldJoints.Any())
{
ShowNotify("未找到可生成任务单的焊口!", MessageBoxIcon.Warning);
return false;
}
- foreach (var weldjoint in selectRowId)
+ foreach (var weldJointRow in taskableWeldJoints)
{
- Model.HJGL_WeldTask NewTask = new Model.HJGL_WeldTask();
- NewTask.ProjectId = this.CurrUser.LoginProjectId;
- NewTask.UnitWorkId = PipelineService.GetPipelineByPipelineId(weldjoint.PipelineId)?.UnitWorkId;
- NewTask.UnitId = this.CurrUser.UnitId;
- if (unitworkTaskCode.FirstOrDefault(x => x.Key == NewTask.UnitWorkId).Value != null)
+ var newTask = new Model.HJGL_WeldTask();
+ newTask.ProjectId = this.CurrUser.LoginProjectId;
+ newTask.UnitWorkId = PipelineService.GetPipelineByPipelineId(weldJointRow.PipelineId)?.UnitWorkId;
+ newTask.UnitId = this.CurrUser.UnitId;
+ var taskCode = taskCodesByUnitWorkId.FirstOrDefault(x => x.Key == newTask.UnitWorkId).Value;
+ if (taskCode != null)
{
- NewTask.TaskCode = unitworkTaskCode.FirstOrDefault(x => x.Key == NewTask.UnitWorkId).Value;
+ newTask.TaskCode = taskCode;
}
else
{
- NewTask.TaskCode = BLL.WeldTaskService.GetTaskCodeByDate(this.CurrUser.LoginProjectId, DateTime.Now.Date.ToString("yyyy-MM-dd"), NewTask.UnitWorkId, this.CurrUser.UnitId);
- unitworkTaskCode.Add(NewTask.UnitWorkId, NewTask.TaskCode);
+ newTask.TaskCode = BLL.WeldTaskService.GetTaskCodeByDate(this.CurrUser.LoginProjectId, DateTime.Now.Date.ToString("yyyy-MM-dd"), newTask.UnitWorkId, this.CurrUser.UnitId);
+ taskCodesByUnitWorkId.Add(newTask.UnitWorkId, newTask.TaskCode);
}
- if (unitworkSerialNumber.FirstOrDefault(x => x.Key == NewTask.UnitWorkId).Value != null)
+ var serialNumber = serialNumbersByUnitWorkId.FirstOrDefault(x => x.Key == newTask.UnitWorkId).Value;
+ if (serialNumber != null)
{
- NewTask.SerialNumber = unitworkSerialNumber.FirstOrDefault(x => x.Key == NewTask.UnitWorkId).Value;
+ newTask.SerialNumber = serialNumber;
}
else
{
- NewTask.SerialNumber = BLL.WeldTaskService.GetSerialNumberByDate(this.CurrUser.LoginProjectId, DateTime.Now.Date.ToString("yyyy-MM-dd"), NewTask.UnitWorkId, this.CurrUser.UnitId);
- unitworkSerialNumber.Add(NewTask.UnitWorkId, NewTask.SerialNumber);
+ newTask.SerialNumber = BLL.WeldTaskService.GetSerialNumberByDate(this.CurrUser.LoginProjectId, DateTime.Now.Date.ToString("yyyy-MM-dd"), newTask.UnitWorkId, this.CurrUser.UnitId);
+ serialNumbersByUnitWorkId.Add(newTask.UnitWorkId, newTask.SerialNumber);
}
- NewTask.WeldTaskId = SQLHelper.GetNewID();
- NewTask.WeldJointId = weldjoint.WeldJointId;
- var oldWeldTask = BLL.WeldTaskService.GetWeldTaskByWeldJointId(NewTask.WeldJointId);
- if (oldWeldTask != null)
+ newTask.WeldTaskId = SQLHelper.GetNewID();
+ newTask.WeldJointId = weldJointRow.WeldJointId;
+ var existingWeldTask = BLL.WeldTaskService.GetWeldTaskByWeldJointId(newTask.WeldJointId);
+ if (existingWeldTask != null)
{
ShowNotify("所选焊口已存在任务单,无法保存!", MessageBoxIcon.Warning);
return false;
}
- Model.HJGL_WeldJoint weldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(NewTask.WeldJointId);
+ var weldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(newTask.WeldJointId);
if (weldJoint != null)
{
- NewTask.PipeLineSortIndex = matchPipeline.FirstOrDefault(x => x.Value == weldJoint.PipelineId).Key;
- NewTask.WeldingRod = weldJoint.WeldingRod;
- NewTask.WeldingWire = weldJoint.WeldingWire;
- BLL.WeldTaskService.PopulateAlternativeConsumables(NewTask, weldJoint, weldingRods, weldingWires);
+ newTask.PipeLineSortIndex = matchPipelineOrder.FirstOrDefault(x => x.Value == weldJoint.PipelineId).Key;
+ newTask.WeldingRod = weldJoint.WeldingRod;
+ newTask.WeldingWire = weldJoint.WeldingWire;
+ BLL.WeldTaskService.PopulateAlternativeConsumables(newTask, weldJoint, weldingRods, weldingWires);
}
- NewTask.JointAttribute = weldJoint.JointAttribute;
+ newTask.JointAttribute = weldJoint.JointAttribute;
- NewTask.TaskDate = DateTime.Now.Date;
- NewTask.Tabler = this.CurrUser.PersonId;
- NewTask.TableDate = DateTime.Now;
+ newTask.TaskDate = DateTime.Now.Date;
+ newTask.Tabler = this.CurrUser.PersonId;
+ newTask.TableDate = DateTime.Now;
weldJoint.WeldingMode = ManualWeldingMode;
BLL.WeldJointService.UpdateWeldJoint(weldJoint);
- BLL.WeldTaskService.AddWeldTask(NewTask);
+ BLL.WeldTaskService.AddWeldTask(newTask);
}
return true;
}
- ///
- /// 获取当前管线汇总表中的显示顺序,供任务单保存管线排序使用。
- ///
- private Dictionary GetMatchPipelineOrder()
- {
- var matchPipeline = new Dictionary();
- for (int rowIndex = 0; rowIndex < Grid2.Rows.Count; rowIndex++)
- {
- matchPipeline.Add(rowIndex + 1, Grid2.Rows[rowIndex].RowID);
- }
- return matchPipeline;
- }
-
///
/// 按任务单实际生成规则过滤可生成任务单的焊口视图数据。
///
@@ -1257,7 +1227,8 @@ namespace FineUIPro.Web.HJGL.WeldingManage
var weldJointIds = materialDetails
.GroupBy(x => x.WeldJointId)
- .Where(x => x.All(y => IsMaterialCodeConfirmed(y, confirmedPipeLineMatIds)))
+ .Where(x => x.All(y => !string.IsNullOrEmpty(y.PipeLineMatId)
+ && confirmedPipeLineMatIds.Contains(y.PipeLineMatId)))
.Select(x => x.Key);
// 材料齐套后还要继续套用任务单视图条件,保证合计数量和点击生成按钮的实际范围一致。
return new HashSet(GetTaskableWeldJointRows(weldJointIds).Select(x => x.WeldJointId));