456 lines
21 KiB
C#
456 lines
21 KiB
C#
using Model;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace BLL
|
||
{
|
||
/// <summary>
|
||
/// 焊接工艺评定台账
|
||
/// </summary>
|
||
public static class WPQListServiceService
|
||
{
|
||
/// <summary>
|
||
/// 根据主键获取焊接工艺评定台账
|
||
/// </summary>
|
||
/// <param name="WPQId"></param>
|
||
/// <returns></returns>
|
||
public static Model.WPQ_WPQList GetWPQById(string wpqId)
|
||
{
|
||
return Funs.DB.WPQ_WPQList.FirstOrDefault(e => e.WPQId == wpqId);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加焊接工艺评定台账
|
||
/// </summary>
|
||
/// <param name="WPQ"></param>
|
||
public static void AddWPQ(Model.WPQ_WPQList WPQ)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
Model.WPQ_WPQList newWPQ = new Model.WPQ_WPQList();
|
||
newWPQ.WPQId = WPQ.WPQId;
|
||
newWPQ.WPQCode = WPQ.WPQCode;
|
||
newWPQ.ProjectId = WPQ.ProjectId;
|
||
newWPQ.UnitId = WPQ.UnitId;
|
||
newWPQ.CompileMan = WPQ.CompileMan;
|
||
newWPQ.CompileDate = WPQ.CompileDate;
|
||
newWPQ.MaterialId1 = WPQ.MaterialId1;
|
||
newWPQ.MaterialId2 = WPQ.MaterialId2;
|
||
newWPQ.Material1Class = WPQ.Material1Class;
|
||
newWPQ.Material2Class = WPQ.Material2Class;
|
||
newWPQ.Material1Group = WPQ.Material1Group;
|
||
newWPQ.Material2Group = WPQ.Material2Group;
|
||
|
||
newWPQ.Specifications = WPQ.Specifications;
|
||
newWPQ.WeldingRod = WPQ.WeldingRod;
|
||
newWPQ.WeldingWire = WPQ.WeldingWire;
|
||
newWPQ.GrooveType = WPQ.GrooveType;
|
||
newWPQ.WeldingPosition = WPQ.WeldingPosition;
|
||
newWPQ.WeldingMethodId = WPQ.WeldingMethodId;
|
||
newWPQ.MinImpactDia = WPQ.MinImpactDia;
|
||
newWPQ.MaxImpactDia = WPQ.MaxImpactDia;
|
||
|
||
newWPQ.MinCImpactDia = WPQ.MinCImpactDia;
|
||
newWPQ.MaxCImpactDia = WPQ.MaxCImpactDia;
|
||
newWPQ.MinImpactThickness = WPQ.MinImpactThickness;
|
||
newWPQ.MaxImpactThickness = WPQ.MaxImpactThickness;
|
||
newWPQ.NoMinImpactThickness = WPQ.NoMinImpactThickness;
|
||
newWPQ.NoMaxImpactThickness = WPQ.NoMaxImpactThickness;
|
||
newWPQ.IsHotProess = WPQ.IsHotProess;
|
||
newWPQ.WPQStandard = WPQ.WPQStandard;
|
||
newWPQ.PreTemperature = WPQ.PreTemperature;
|
||
newWPQ.Remark = WPQ.Remark;
|
||
newWPQ.JointType = WPQ.JointType;
|
||
newWPQ.Motorization = WPQ.Motorization;
|
||
newWPQ.ProtectiveGas = WPQ.ProtectiveGas;
|
||
newWPQ.Stretching = WPQ.Stretching;
|
||
newWPQ.Bend = WPQ.Bend;
|
||
newWPQ.ToAttack = WPQ.ToAttack;
|
||
newWPQ.Others = WPQ.Others;
|
||
newWPQ.State = WPQ.State;
|
||
newWPQ.ApproveManId = WPQ.ApproveManId;
|
||
newWPQ.RequiredT = WPQ.RequiredT;
|
||
newWPQ.RequestTime = WPQ.RequestTime;
|
||
newWPQ.WeldingWireSpecification = WPQ.WeldingWireSpecification;
|
||
newWPQ.WeldingRodSpecification = WPQ.WeldingRodSpecification;
|
||
newWPQ.GasProtectionModeId = WPQ.GasProtectionModeId;
|
||
newWPQ.ProtectionGasId = WPQ.ProtectionGasId;
|
||
db.WPQ_WPQList.InsertOnSubmit(newWPQ);
|
||
db.SubmitChanges();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改焊接工艺评定台账
|
||
/// </summary>
|
||
/// <param name="WPQ"></param>
|
||
public static void UpdateWPQ(Model.WPQ_WPQList WPQ)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
Model.WPQ_WPQList newWPQ = db.WPQ_WPQList.FirstOrDefault(e => e.WPQId == WPQ.WPQId);
|
||
if (newWPQ != null)
|
||
{
|
||
newWPQ.WPQCode = WPQ.WPQCode;
|
||
newWPQ.UnitId = WPQ.UnitId;
|
||
newWPQ.CompileDate = WPQ.CompileDate;
|
||
newWPQ.MaterialId1 = WPQ.MaterialId1;
|
||
newWPQ.MaterialId2 = WPQ.MaterialId2;
|
||
newWPQ.Material1Class = WPQ.Material1Class;
|
||
newWPQ.Material2Class = WPQ.Material2Class;
|
||
newWPQ.Material1Group = WPQ.Material1Group;
|
||
newWPQ.Material2Group = WPQ.Material2Group;
|
||
newWPQ.Specifications = WPQ.Specifications;
|
||
newWPQ.WeldingRod = WPQ.WeldingRod;
|
||
newWPQ.WeldingWire = WPQ.WeldingWire;
|
||
newWPQ.GrooveType = WPQ.GrooveType;
|
||
newWPQ.WeldingPosition = WPQ.WeldingPosition;
|
||
newWPQ.WeldingMethodId = WPQ.WeldingMethodId;
|
||
newWPQ.MinImpactDia = WPQ.MinImpactDia;
|
||
newWPQ.MaxImpactDia = WPQ.MaxImpactDia;
|
||
newWPQ.MinImpactThickness = WPQ.MinImpactThickness;
|
||
newWPQ.MaxImpactThickness = WPQ.MaxImpactThickness;
|
||
newWPQ.NoMinImpactThickness = WPQ.NoMinImpactThickness;
|
||
newWPQ.NoMaxImpactThickness = WPQ.NoMaxImpactThickness;
|
||
newWPQ.IsHotProess = WPQ.IsHotProess;
|
||
newWPQ.WPQStandard = WPQ.WPQStandard;
|
||
newWPQ.PreTemperature = WPQ.PreTemperature;
|
||
newWPQ.Remark = WPQ.Remark;
|
||
newWPQ.JointType = WPQ.JointType;
|
||
newWPQ.Motorization = WPQ.Motorization;
|
||
newWPQ.ProtectiveGas = WPQ.ProtectiveGas;
|
||
newWPQ.Stretching = WPQ.Stretching;
|
||
newWPQ.Bend = WPQ.Bend;
|
||
newWPQ.ToAttack = WPQ.ToAttack;
|
||
newWPQ.Others = WPQ.Others;
|
||
newWPQ.State = WPQ.State;
|
||
newWPQ.ApproveManId = WPQ.ApproveManId;
|
||
newWPQ.ApproveTime = WPQ.ApproveTime;
|
||
newWPQ.RequiredT = WPQ.RequiredT;
|
||
newWPQ.RequestTime = WPQ.RequestTime;
|
||
newWPQ.WeldingWireSpecification = WPQ.WeldingWireSpecification;
|
||
newWPQ.WeldingRodSpecification = WPQ.WeldingRodSpecification;
|
||
newWPQ.GasProtectionModeId = WPQ.GasProtectionModeId;
|
||
newWPQ.ProtectionGasId = WPQ.ProtectionGasId;
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据主键删除焊接工艺评定台账
|
||
/// </summary>
|
||
/// <param name="WPQId"></param>
|
||
public static void DeleteWPQById(string WPQId)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
Model.WPQ_WPQList WPQ = db.WPQ_WPQList.FirstOrDefault(e => e.WPQId == WPQId);
|
||
if (WPQ != null)
|
||
{
|
||
var flow = db.WPQ_WPQListFlowOperate.Where(x => x.WPQId == WPQId);
|
||
if (flow.Count() > 0)
|
||
{
|
||
db.WPQ_WPQListFlowOperate.DeleteAllOnSubmit(flow);
|
||
db.SubmitChanges();
|
||
}
|
||
AttachFileService.DeleteAttachFile(Funs.RootPath, WPQId, Const.WPQListMenuId);//删除附件
|
||
db.WPQ_WPQList.DeleteOnSubmit(WPQ);
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断是否存在相同评定编号
|
||
/// </summary>
|
||
/// <param name="WPQId"></param>
|
||
/// <param name="code"></param>
|
||
/// <returns></returns>
|
||
public static bool IsWPQCode(string WPQId, string code)
|
||
{
|
||
var q = Funs.DB.WPQ_WPQList.FirstOrDefault(x => (x.WPQId != WPQId || (WPQId == null && x.WPQId != null)) && x.WPQCode == code);
|
||
if (q != null)
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
#region 匹配wpq
|
||
public static List<View_HJGL_WPQ> GetMatchWPQ(HJGL_WeldJoint jot, string projectid, string unitid)
|
||
{
|
||
var pipe = BLL.PipelineService.GetPipelineByPipelineId(jot.PipelineId);
|
||
var weldT = BLL.Base_WeldTypeService.GetWeldTypeByWeldTypeId(jot.WeldTypeId);
|
||
string material1 = jot.Material1Id;
|
||
string material2 = jot.Material2Id;
|
||
decimal dia = jot.Dia.HasValue ? jot.Dia.Value : 0;
|
||
decimal sch = jot.Thickness.HasValue ? jot.Thickness.Value : 0;
|
||
string unitId = string.Empty;
|
||
if (unitid != Const._Null)
|
||
{
|
||
unitId = unitid;
|
||
}
|
||
else
|
||
{
|
||
unitId = pipe.UnitId;
|
||
}
|
||
|
||
string weldType = string.Empty;
|
||
if (weldT != null)
|
||
{
|
||
weldType = weldT.WeldTypeCode;
|
||
}
|
||
|
||
var mat1 = BLL.Base_MaterialService.GetMaterialByMaterialId(material1);
|
||
var mat2 = BLL.Base_MaterialService.GetMaterialByMaterialId(material2);
|
||
if (mat1.MaterialCode == "No matl" || mat2.MaterialCode == "No matl") //材质1或材质2有一种为无材质,则匹配不了wpq
|
||
{
|
||
return null;
|
||
}
|
||
int m1 = SNClass(mat1.MaterialClass);
|
||
int m2 = SNClass(mat2.MaterialClass);
|
||
|
||
int g1 = SNGroup(mat1.MaterialGroup);
|
||
int g2 = SNGroup(mat2.MaterialGroup);
|
||
|
||
string preGroup1 = PreGroup(mat1.MaterialGroup);
|
||
string preGroup2 = PreGroup(mat2.MaterialGroup);
|
||
List<Model.View_HJGL_WPQ> list = new List<Model.View_HJGL_WPQ>();
|
||
// 单位、接头形式、材质的覆盖
|
||
var wpq = from x in Funs.DB.View_HJGL_WPQ
|
||
where x.UnitId == unitId && x.State == BLL.Const.State_2 && x.ProjectId == projectid
|
||
//&& (x.JointType == "对接焊缝" || (x.JointType != "对接焊缝" && weldType != "B"))
|
||
//&& ((x.Material1Group == mat1.MaterialGroup && x.Material2Group == mat2.MaterialGroup)
|
||
//|| (x.Material1Group == mat2.MaterialGroup && x.Material2Group == mat1.MaterialGroup))
|
||
select x;
|
||
|
||
// 根据接头形式判断外径和壁厚的覆盖
|
||
if (weldType.Contains("B"))
|
||
{
|
||
wpq = from x in wpq
|
||
where dia >= x.MinImpactDia && dia <= x.MaxImpactDia
|
||
&& sch >= x.MinImpactThickness && sch <= x.MaxImpactThickness
|
||
select x;
|
||
}
|
||
else
|
||
{
|
||
wpq = from x in wpq
|
||
where dia >= x.MinCImpactDia && dia <= x.MaxCImpactDia
|
||
&& sch >= x.NoMinImpactThickness && sch <= x.NoMaxImpactThickness
|
||
select x;
|
||
}
|
||
|
||
// 一、材质类别相等
|
||
var wpq1 = from x in wpq where x.Material1Class == x.Material2Class select x;
|
||
foreach (var item in wpq1)
|
||
{
|
||
try
|
||
{
|
||
// 满足WPS第一个条件:焊接方法为“PAW、SMAW、SAW、GMAW、FCAW、GTAW”且材质类别属于Fe-1~Fe-5A
|
||
if ((item.WeldingMethodCode == "PAW" || item.WeldingMethodCode == "SMAW" || item.WeldingMethodCode == "SAW" || item.WeldingMethodCode == "GMAW" || item.WeldingMethodCode == "FCAW" || item.WeldingMethodCode == "GTAW")
|
||
&& (item.SNClass1 == "1" || item.SNClass1 == "2" || item.SNClass1 == "3" || item.SNClass1 == "4" || item.SNClass1 == "5A"))
|
||
{
|
||
// 满足:焊口材质1”等于且“焊口材质2”小于WPS材质类别
|
||
if (item.Material1Class == mat1.MaterialClass && Convert.ToInt32(item.SNClass2) > m2)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
// 满足:焊口“材质2”等于且“焊口材质1”小于WPS材质类别
|
||
else if (item.Material2Class == mat2.MaterialClass && Convert.ToInt32(item.SNClass1) > m1)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
else
|
||
{
|
||
// WPS“材质1”与“材质2”“组别”相等
|
||
if (item.Material1Group == item.Material2Group)
|
||
{
|
||
//≠“Fe-1-2”
|
||
if (item.Material1Group != "Fe-1-2")
|
||
{
|
||
//焊口“材质1”与“材质2”组别关系
|
||
//相等且等于WPS材质组别
|
||
if (mat1.MaterialGroup == mat2.MaterialGroup && mat1.MaterialGroup == item.Material1Group)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
//“材质1”等于且“材质2”小于WPS材质组别
|
||
else if (mat1.MaterialGroup == item.Material1Group && item.PreGroup1 == preGroup2 && Convert.ToInt32(item.SNGroup1) > g2)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
//“材质2”等于且“材质1”小于WPS材质组别
|
||
else if (mat2.MaterialGroup == item.Material1Group && item.PreGroup1 == preGroup1 && Convert.ToInt32(item.SNGroup1) > g1)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
}
|
||
//=“Fe-1-2”
|
||
else
|
||
{
|
||
//=“Fe-1-2”
|
||
if (mat1.MaterialGroup == "Fe-1-2" && mat2.MaterialGroup == "Fe-1-2")
|
||
{
|
||
list.Add(item);
|
||
}
|
||
//=“Fe-1-1”
|
||
else if (mat1.MaterialGroup == "Fe-1-1" && mat2.MaterialGroup == "Fe-1-1")
|
||
{
|
||
list.Add(item);
|
||
}
|
||
//“材质1”等于且“材质2”小于WPS材质组别
|
||
else if (mat1.MaterialGroup == item.Material1Group && item.PreGroup1 == preGroup2 && Convert.ToInt32(item.SNGroup1) > g2)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
//“材质2”等于且“材质1”小于WPS材质组别
|
||
else if (mat2.MaterialGroup == item.Material1Group && item.PreGroup1 == preGroup1 && Convert.ToInt32(item.SNGroup1) > g1)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
}
|
||
}
|
||
//WPS“材质1”与“材质2”“组别”不相等
|
||
else
|
||
{
|
||
//"与WPS一致(材1 = WPS材1,且材2 = WPS材2或材2 = WPS材1,且材1 = WPS材2)"
|
||
if ((mat1.MaterialGroup == item.Material1Group && mat2.MaterialGroup == item.Material2Group) || (mat2.MaterialGroup == item.Material1Group && mat1.MaterialGroup == item.Material2Group))
|
||
{
|
||
list.Add(item);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//其他
|
||
else
|
||
{
|
||
// WPS“材质1”与“材质2”“组别”相等
|
||
if (item.Material1Group == item.Material2Group)
|
||
{
|
||
//≠“Fe-1-2”
|
||
if (item.Material1Group != "Fe-1-2")
|
||
{
|
||
//焊口“材质1”与“材质2”组别关系
|
||
//相等且等于WPS材质组别
|
||
if (mat1.MaterialGroup == mat2.MaterialGroup && mat1.MaterialGroup == item.Material1Group)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
//“材质1”等于且“材质2”小于WPS材质组别
|
||
else if (mat1.MaterialGroup == item.Material1Group && item.PreGroup1 == preGroup2 && Convert.ToInt32(item.SNGroup1) > g2)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
//“材质2”等于且“材质1”小于WPS材质组别
|
||
else if (mat2.MaterialGroup == item.Material1Group && item.PreGroup1 == preGroup1 && Convert.ToInt32(item.SNGroup1) > g1)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
}
|
||
//=“Fe-1-2”
|
||
else
|
||
{
|
||
//=“Fe-1-2”
|
||
if (mat1.MaterialGroup == "Fe-1-2" && mat2.MaterialGroup == "Fe-1-2")
|
||
{
|
||
list.Add(item);
|
||
}
|
||
//=“Fe-1-1”
|
||
else if (mat1.MaterialGroup == "Fe-1-1" && mat2.MaterialGroup == "Fe-1-1")
|
||
{
|
||
list.Add(item);
|
||
}
|
||
//“材质1”等于且“材质2”小于WPS材质组别
|
||
else if (mat1.MaterialGroup == item.Material1Group && item.PreGroup1 == preGroup2 && Convert.ToInt32(item.SNGroup1) > g2)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
//“材质2”等于且“材质1”小于WPS材质组别
|
||
else if (mat2.MaterialGroup == item.Material1Group && item.PreGroup1 == preGroup1 && Convert.ToInt32(item.SNGroup1) > g1)
|
||
{
|
||
list.Add(item);
|
||
}
|
||
}
|
||
}
|
||
//WPS“材质1”与“材质2”“组别”不相等
|
||
else
|
||
{
|
||
//"与WPS一致(材1 = WPS材1,且材2 = WPS材2或材2 = WPS材1,且材1 = WPS材2)"
|
||
if ((mat1.MaterialGroup == item.Material1Group && mat2.MaterialGroup == item.Material2Group) || (mat2.MaterialGroup == item.Material1Group && mat1.MaterialGroup == item.Material2Group))
|
||
{
|
||
list.Add(item);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrLogInfo.WriteLog(ex.ToString());
|
||
continue;
|
||
}
|
||
|
||
}
|
||
// 一、材质类别不相等
|
||
var wpq2 = from x in wpq where x.Material1Class != x.Material2Class select x;
|
||
foreach (var item in wpq2)
|
||
{
|
||
//与WPS一致(材1 = WPS材1,且材2 = WPS材2或材2 = WPS材1,且材1 = WPS材2)
|
||
if ((mat1.MaterialClass == item.Material1Class && mat2.MaterialClass == item.Material2Class) || (mat2.MaterialClass == item.Material1Class && mat1.MaterialClass == item.Material2Class))
|
||
{
|
||
list.Add(item);
|
||
}
|
||
}
|
||
//list = list.Distinct().ToList();
|
||
if (list != null && list.Count() > 0)
|
||
{
|
||
return list.Distinct().ToList();
|
||
}
|
||
else
|
||
{
|
||
return null;
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 返回组别的序号
|
||
/// </summary>
|
||
/// <param name="matClass"></param>
|
||
/// <returns></returns>
|
||
public static int SNClass(string matClass)
|
||
{
|
||
int sn = 0;
|
||
if (!string.IsNullOrEmpty(matClass))
|
||
{
|
||
int m = matClass.IndexOf("-");
|
||
string mat = matClass.Substring(m + 1, 1);
|
||
sn = Funs.GetNewInt(mat).HasValue ? Funs.GetNewInt(mat).Value : 0;
|
||
}
|
||
return sn;
|
||
}
|
||
|
||
|
||
public static int SNGroup(string matGroup)
|
||
{
|
||
int sn = 0;
|
||
if (!string.IsNullOrEmpty(matGroup) && matGroup.Length > 1)
|
||
{
|
||
string mat = matGroup.Substring(matGroup.Length - 1, 1);
|
||
sn = Funs.GetNewInt(mat).HasValue ? Funs.GetNewInt(mat).Value : 0;
|
||
}
|
||
return sn;
|
||
}
|
||
|
||
public static string PreGroup(string matGroup)
|
||
{
|
||
string pre = string.Empty;
|
||
if (!string.IsNullOrEmpty(matGroup) && matGroup.Length >= 2)
|
||
{
|
||
pre = matGroup.Substring(0, matGroup.Length - 2);
|
||
}
|
||
return pre;
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|