using System; using System.Collections.Generic; using System.Linq; namespace BLL { public static class WeldJointService { /// /// 根据焊口Id获取焊口信息 /// /// /// public static Model.HJGL_WeldJoint GetWeldJointByWeldJointId(string weldJointId) { return Funs.DB.HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == weldJointId); } /// /// 判断焊口号是否已存在 /// /// /// public static bool IsExistWeldJointCode(string weldJointCode, string pipelineId, string weldJointId) { Model.SGGLDB db = Funs.DB; Model.HJGL_WeldJoint jot = null; if (!string.IsNullOrEmpty(weldJointId)) { jot = Funs.DB.HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointCode == weldJointCode && x.PipelineId == pipelineId && x.WeldJointId != weldJointId); } else { jot = Funs.DB.HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointCode == weldJointCode && x.PipelineId == pipelineId); } if (jot != null) { return true; } else { return false; } } /// /// 根据焊接日报获取焊口数 /// /// /// public static List GetWeldlinesByWeldingDailyId(string weldingDailyId) { var q = (from x in Funs.DB.HJGL_WeldJoint where x.WeldingDailyId == weldingDailyId orderby x.PipelineId, x.WeldJointCode select x).ToList(); return q; } /// /// 添加 /// /// public static void AddWeldJoint(Model.HJGL_WeldJoint weldJoint) { Model.SGGLDB db = Funs.DB; Model.HJGL_WeldJoint newWeldJoint = new Model.HJGL_WeldJoint { WeldJointId = SQLHelper.GetNewID(typeof(Model.HJGL_WeldJoint)), ProjectId = weldJoint.ProjectId, PipelineId = weldJoint.PipelineId, PipelineCode = weldJoint.PipelineCode, WeldJointCode = weldJoint.WeldJointCode, WeldTypeId = weldJoint.WeldTypeId, Material1Id = weldJoint.Material1Id, Material2Id = weldJoint.Material2Id, Thickness = weldJoint.Thickness, Dia = weldJoint.Dia, Size = weldJoint.Size, DetectionTypeId = weldJoint.DetectionTypeId, JointArea = weldJoint.JointArea, WeldingMethodId = weldJoint.WeldingMethodId, WeldingLocationId = weldJoint.WeldingLocationId, JointAttribute = weldJoint.JointAttribute, IsHotProess = weldJoint.IsHotProess, WeldingWire = weldJoint.WeldingWire, WeldingRod = weldJoint.WeldingRod, DesignIsHotProess = weldJoint.DesignIsHotProess, GrooveTypeId = weldJoint.GrooveTypeId, Specification = weldJoint.Specification, WPQId = weldJoint.WPQId, HeartNo1 = weldJoint.HeartNo1, HeartNo2 = weldJoint.HeartNo2, BaseWeldJointId = weldJoint.BaseWeldJointId, Components1Id = weldJoint.Components1Id, Components2Id = weldJoint.Components2Id, PreTemperature = weldJoint.PreTemperature, Remark = weldJoint.Remark, IsTwoJoint = weldJoint.IsTwoJoint, SubmitMan = weldJoint.SubmitMan }; db.HJGL_WeldJoint.InsertOnSubmit(newWeldJoint); db.SubmitChanges(); } /// /// 修改 /// /// public static void UpdateWeldJoint(Model.HJGL_WeldJoint weldJoint) { Model.SGGLDB db = Funs.DB; Model.HJGL_WeldJoint newWeldJoint = db.HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == weldJoint.WeldJointId); if (newWeldJoint != null) { newWeldJoint.WeldJointCode = weldJoint.WeldJointCode; newWeldJoint.ProjectId = weldJoint.ProjectId; newWeldJoint.PipelineCode = weldJoint.PipelineCode; newWeldJoint.WPQId = weldJoint.WPQId; newWeldJoint.WeldTypeId = weldJoint.WeldTypeId; newWeldJoint.Material1Id = weldJoint.Material1Id; newWeldJoint.Material2Id = weldJoint.Material2Id; newWeldJoint.Thickness = weldJoint.Thickness; newWeldJoint.Dia = weldJoint.Dia; newWeldJoint.Size = weldJoint.Size; newWeldJoint.DetectionTypeId = weldJoint.DetectionTypeId; newWeldJoint.JointArea = weldJoint.JointArea; newWeldJoint.WeldingMethodId = weldJoint.WeldingMethodId; newWeldJoint.IsHotProess = weldJoint.IsHotProess; newWeldJoint.WeldingLocationId = weldJoint.WeldingLocationId; newWeldJoint.JointAttribute = weldJoint.JointAttribute; newWeldJoint.DesignIsHotProess = weldJoint.DesignIsHotProess; newWeldJoint.WeldingWire = weldJoint.WeldingWire; newWeldJoint.WeldingRod = weldJoint.WeldingRod; newWeldJoint.GrooveTypeId = weldJoint.GrooveTypeId; newWeldJoint.HeartNo1 = weldJoint.HeartNo1; newWeldJoint.HeartNo2 = weldJoint.HeartNo2; newWeldJoint.Components1Id = weldJoint.Components1Id; newWeldJoint.Components2Id = weldJoint.Components2Id; newWeldJoint.BackingWelderId = weldJoint.BackingWelderId; newWeldJoint.CoverWelderId = weldJoint.CoverWelderId; newWeldJoint.WeldingDailyId = weldJoint.WeldingDailyId; newWeldJoint.WeldingMode = weldJoint.WeldingMode; newWeldJoint.WeldingDailyCode = weldJoint.WeldingDailyCode; newWeldJoint.Specification = weldJoint.Specification; newWeldJoint.PreTemperature = weldJoint.PreTemperature; newWeldJoint.Remark = weldJoint.Remark; newWeldJoint.AttachUrl = weldJoint.AttachUrl; newWeldJoint.SubmitMan = weldJoint.SubmitMan; db.SubmitChanges(); } } /// /// 更新施工焊口信息 /// /// public static void UpdateConWeldJoint(Model.HJGL_WeldJoint weldJoint) { Model.SGGLDB db = Funs.DB; Model.HJGL_WeldJoint newWeldJoint = db.HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == weldJoint.WeldJointId); if (newWeldJoint != null) { newWeldJoint.WPQId = weldJoint.WPQId; newWeldJoint.MatchableWPQ = weldJoint.MatchableWPQ; newWeldJoint.WeldingMethodId = weldJoint.WeldingMethodId; newWeldJoint.IsHotProess = weldJoint.IsHotProess; newWeldJoint.WeldingWire = weldJoint.WeldingWire; newWeldJoint.WeldingRod = weldJoint.WeldingRod; newWeldJoint.GrooveTypeId = weldJoint.GrooveTypeId; newWeldJoint.PreTemperature = weldJoint.PreTemperature; newWeldJoint.Remark = weldJoint.Remark; db.SubmitChanges(); } } /// /// 回写焊口信息 /// /// public static void WriteBackWeldJoint(Model.HJGL_WeldJoint weldJoint) { Model.SGGLDB db = Funs.DB; Model.HJGL_WeldJoint newWeldJoint = db.HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == weldJoint.WeldJointId); if (newWeldJoint != null) { newWeldJoint.BackingWelderId = weldJoint.BackingWelderId; newWeldJoint.CoverWelderId = weldJoint.CoverWelderId; newWeldJoint.WeldingDailyId = weldJoint.WeldingDailyId; newWeldJoint.WeldingDailyCode = weldJoint.WeldingDailyCode; newWeldJoint.WeldingLocationId = weldJoint.WeldingLocationId; newWeldJoint.JointAttribute = weldJoint.JointAttribute; } } /// /// 二次焊口审核 /// /// /// /// public static void UpdateJointAudit(string jointId, string auditMan, DateTime? auditDate) { Model.SGGLDB db = Funs.DB; Model.HJGL_WeldJoint newWeldJoint = db.HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == jointId); if (newWeldJoint != null) { newWeldJoint.AuditMan = auditMan; newWeldJoint.AuditDate = auditDate; db.SubmitChanges(); } } /// /// 根据主键删除焊口信息 /// /// public static void DeleteWeldJointById(string weldJointId) { Model.SGGLDB db = Funs.DB; Model.HJGL_WeldJoint weldline = db.HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == weldJointId); if (weldline != null) { db.HJGL_WeldJoint.DeleteOnSubmit(weldline); db.SubmitChanges(); } } /// /// 根据管线删除焊口信息 /// /// public static void DeleteWeldJointByPipelineId(string pipelineId) { Model.SGGLDB db = Funs.DB; var weldline = db.HJGL_WeldJoint.Where(e => e.PipelineId == pipelineId); if (weldline != null) { db.HJGL_WeldJoint.DeleteAllOnSubmit(weldline); db.SubmitChanges(); } } /// /// 根据unitworkid删除焊口 /// /// public static void DeleteWeldJointByUnitWorkId(string unitworkId) { var oldPipeline = BLL.PipelineService.GetPipelinesByUnitWordId(unitworkId); if (oldPipeline != null) { foreach (var pipeline in oldPipeline) { BLL.WeldJointService.DeleteWeldJointByPipelineId(pipeline.PipelineId); //删除原有管线对应焊口 } } } /// /// 更新焊口号 固定焊口号后 +G /// /// 焊口id /// 焊口属性 /// 日报操作(增加、删除) public static void UpdateWeldJointAddG(string weldJointId, string jointAttribute, string operateState) { Model.SGGLDB db = Funs.DB; if (operateState == Const.BtnDelete || jointAttribute != "安装口") { Model.HJGL_WeldJoint deleteWeldJoint = db.HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == weldJointId); if (deleteWeldJoint.WeldJointCode.Last() == 'G') { deleteWeldJoint.WeldJointCode = deleteWeldJoint.WeldJointCode.Substring(0, deleteWeldJoint.WeldJointCode.Length - 1); db.SubmitChanges(); } } else { Model.HJGL_WeldJoint addJointInfo = db.HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == weldJointId); if (addJointInfo.WeldJointCode.Last() != 'G') { addJointInfo.WeldJointCode += "G"; } db.SubmitChanges(); } } /// /// 根据主键获取焊口信息视图 /// /// /// public static Model.View_HJGL_WeldJoint GetViewWeldJointById(string weldJointId) { Model.SGGLDB db = Funs.DB; return db.View_HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == weldJointId); } /// /// 根据焊口Id获取插入焊口数 /// /// /// public static List GetBaseWeldJointsByWeldJointId(string weldJointId) { var q = (from x in Funs.DB.HJGL_WeldJoint where x.BaseWeldJointId == weldJointId orderby x.WeldJointCode select x).ToList(); return q; } /// /// 根据焊接日报获取焊口数 /// /// /// public static List GetWeldJointsByWeldingDailyId(string weldingDailyId) { var q = (from x in Funs.DB.HJGL_WeldJoint where x.WeldingDailyId == weldingDailyId orderby x.PipelineId, x.WeldJointCode select x).ToList(); return q; } /// /// 根据焊接日报获取焊口数 /// /// /// public static List GetViewWeldJointsByWeldingDailyId(string weldingDailyId) { var q = (from x in Funs.DB.View_HJGL_WeldJoint where x.WeldingDailyId == weldingDailyId orderby x.PipelineCode, x.WeldJointCode select x).ToList(); return q; } /// /// 获取当前焊工工作量是否超过60寸的焊接人员 /// /// 项目id /// 单位id /// 焊口ID /// 焊接日期 /// public static bool GetWelderLimitDN(string projectId, string welderId, DateTime weldingDate) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var jots = from x in db.HJGL_WeldJoint join y in db.HJGL_WeldingDaily on x.WeldingDailyId equals y.WeldingDailyId where x.ProjectId == projectId && y.WeldingDate == weldingDate && (welderId == x.CoverWelderId || welderId == x.BackingWelderId) select x; decimal? count = jots.Sum(x => x.Size); if (count >= 60) { return true; } else { return false; } } } /// /// 根据管线ID获取焊口信息 /// /// /// public static List GetViewWeldJointsByPipelineId(string pipelineId) { var q = (from x in Funs.DB.View_HJGL_WeldJoint where x.PipelineId == pipelineId orderby x.WeldJointCode select x).ToList(); return q; } public static List GetViewWeldJointsBymodel(Model.View_HJGL_WeldJoint model) { var q = (from x in Funs.DB.View_HJGL_WeldJoint where (string.IsNullOrEmpty(model.ProjectId) || x.ProjectId.Contains(model.ProjectId)) && (string.IsNullOrEmpty(model.UnitWorkId) || x.UnitWorkId.Contains(model.UnitWorkId)) && (string.IsNullOrEmpty(model.PipelineId) || x.PipelineId.Contains(model.PipelineId)) && (string.IsNullOrEmpty(model.PipelineCode) || x.PipelineCode.Contains(model.PipelineCode)) && (string.IsNullOrEmpty(model.WeldJointCode) || x.WeldJointCode.Contains(model.WeldJointCode)) orderby x.WeldJointCode select x).ToList(); return q; } /// /// 根据壁厚计算焊口达因 /// /// /// public static double GetSizeByThickness(decimal? size, decimal thickness) { double n = 0; if (thickness <= 8) { n = 1; } else if (thickness > 8 && thickness < 12) { n = 1.2; } else if (thickness >= 12 && thickness < 16) { n = 1.3; } else if (thickness >= 16 && thickness < 19) { n = 1.5; } else if (thickness >= 19 && thickness < 23) { n = 2; } else if (thickness >= 23 && thickness < 27) { n = 3; } else if (thickness >= 27 && thickness < 31) { n = 4; } else if (thickness >= 31 && thickness < 35) { n = 5; } else if (thickness >= 35 && thickness < 39) { n = 6; } else if (thickness >= 39 && thickness < 43) { n = 7; } else if (thickness >= 43 && thickness < 47) { n = 8; } else if (thickness >= 47 && thickness < 51) { n = 9; } else if (thickness >= 51 && thickness < 55) { n = 10; } else if (thickness >= 55 && thickness < 59) { n = 11; } else if (thickness >= 59 && thickness < 63) { n = 12; } return Convert.ToDouble(size) * n; } } }