using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BLL { /// /// 检测单明细 /// public static class Batch_NDEItemService { /// /// 根据主键获取检测单明细 /// /// /// public static Model.Batch_NDEItem GetNDEItemById(string ndeItemID) { return Funs.DB.Batch_NDEItem.FirstOrDefault(e => e.NDEItemID == ndeItemID); } /// /// 根据主键获取检测单明细视图信息 /// /// /// public static Model.View_Batch_NDEItem GetNDEItemViewById (string ndeItemID) { return Funs.DB.View_Batch_NDEItem.FirstOrDefault(e => e.NDEItemID == ndeItemID); } /// /// 根据检测单Id获取相关明细信息 /// /// /// public static List GetNDEItemByNDEID(string NDEID) { return (from x in Funs.DB.Batch_NDEItem where x.NDEID == NDEID select x).ToList(); } /// /// 添加检测单明细 /// /// public static void AddNDEItem(Model.Batch_NDEItem NDEItem) { Model.HJGLDB db = Funs.DB; Model.Batch_NDEItem newNDEItem = new Model.Batch_NDEItem(); newNDEItem.NDEItemID = NDEItem.NDEItemID; newNDEItem.NDEID = NDEItem.NDEID; newNDEItem.TrustBatchItemId = NDEItem.TrustBatchItemId; newNDEItem.DetectionTypeId = NDEItem.DetectionTypeId; newNDEItem.RequestDate = NDEItem.RequestDate; newNDEItem.RepairLocation = NDEItem.RepairLocation; newNDEItem.TotalFilm = NDEItem.TotalFilm; newNDEItem.PassFilm = NDEItem.PassFilm; newNDEItem.CheckResult = NDEItem.CheckResult; newNDEItem.NDEReportNo = NDEItem.NDEReportNo; newNDEItem.FilmDate = NDEItem.FilmDate; newNDEItem.ReportDate = NDEItem.ReportDate; newNDEItem.SubmitDate = NDEItem.SubmitDate; newNDEItem.CheckDefects = NDEItem.CheckDefects; newNDEItem.JudgeGrade = NDEItem.JudgeGrade; newNDEItem.Remark = NDEItem.Remark; db.Batch_NDEItem.InsertOnSubmit(newNDEItem); db.SubmitChanges(); } /// /// 修改检测单 /// /// public static void UpdateNDEItem(Model.Batch_NDEItem NDEItem) { Model.HJGLDB db = Funs.DB; Model.Batch_NDEItem newNDEItem = db.Batch_NDEItem.FirstOrDefault(e => e.NDEItemID == NDEItem.NDEItemID); if (newNDEItem != null) { newNDEItem.TrustBatchItemId = NDEItem.TrustBatchItemId; newNDEItem.DetectionTypeId = NDEItem.DetectionTypeId; newNDEItem.RequestDate = NDEItem.RequestDate; newNDEItem.RepairLocation = NDEItem.RepairLocation; newNDEItem.TotalFilm = NDEItem.TotalFilm; newNDEItem.PassFilm = NDEItem.PassFilm; newNDEItem.CheckResult = NDEItem.CheckResult; newNDEItem.NDEReportNo = NDEItem.NDEReportNo; newNDEItem.FilmDate = NDEItem.FilmDate; newNDEItem.ReportDate = NDEItem.ReportDate; newNDEItem.SubmitDate = NDEItem.SubmitDate; newNDEItem.CheckDefects = NDEItem.CheckDefects; newNDEItem.JudgeGrade = NDEItem.JudgeGrade; newNDEItem.Remark = NDEItem.Remark; db.SubmitChanges(); } } /// /// 根据检测单明细主键删除明细信息 /// /// public static void DeleteNDEItemByNDEItemID(string ndeItemID) { Model.HJGLDB db = Funs.DB; var ndeItem = (from x in db.Batch_NDEItem where x.NDEItemID == ndeItemID select x).FirstOrDefault(); if (ndeItem != null) { db.Batch_NDEItem.DeleteOnSubmit(ndeItem); db.SubmitChanges(); } } /// /// 根据检测单主键删除相关明细信息 /// /// public static void DeleteNDEItemById(string ndeId) { Model.HJGLDB db = Funs.DB; var ndeItem = (from x in db.Batch_NDEItem where x.NDEID == ndeId select x).ToList(); if (ndeItem != null) { db.Batch_NDEItem.DeleteAllOnSubmit(ndeItem); db.SubmitChanges(); } } /// /// 根据检测单Id获取相关明细视图信息 /// /// /// /// public static List GetViewNDEItem(string NDEID) { return (from x in Funs.DB.View_Batch_NDEItem where x.NDEID == NDEID select x).ToList(); } /// /// 根据焊口ID判断该焊口是否已检测并审核 /// /// 焊口ID /// true-已审核,false-未审核 public static bool IsCheckedByWeldJoint(string weldJointId) { Model.HJGLDB db = Funs.DB; bool isChecked = false; var ndtItemView = from x in db.View_Batch_NDEItem where x.WeldJointId == weldJointId && x.SubmitDate != null select x; if(ndtItemView.Count()>0) { isChecked = true; } return isChecked; } /// /// 根据日报ID判断该日报下是否有焊口已检测并审核 /// /// 日报ID /// true-已审核,false-未审核 public static bool IsCheckedByWeldingDaily(string weldingDailyId) { Model.HJGLDB db = Funs.DB; bool isChecked = false; var ndtItemView = from x in db.View_Batch_NDEItem where x.WeldingDailyId == weldingDailyId && x.SubmitDate != null select x; if (ndtItemView.Count() > 0) { isChecked = true; } return isChecked; } #region 删除焊口所在批和委托检测单里信息 /// /// 删除批中焊口信息 /// /// 焊口id public static void DeleteAllNDEInfoToWeldJoint(string weldJointId) { Model.HJGLDB db = Funs.DB; var pointBatchItems = from x in db.Batch_PointBatchItem where x.WeldJointId == weldJointId select x; if (pointBatchItems.Count() > 0) { foreach (var pointBatchItem in pointBatchItems) { Model.Batch_BatchTrustItem trustItem = db.Batch_BatchTrustItem.FirstOrDefault(x => x.PointBatchItemId == pointBatchItem.PointBatchItemId); string pointBatchItemId = pointBatchItem.PointBatchItemId; string pointBatchId = pointBatchItem.PointBatchId; if (trustItem != null) { Model.Batch_NDEItem checkItem = db.Batch_NDEItem.FirstOrDefault(x => x.TrustBatchItemId == trustItem.TrustBatchItemId); if (checkItem != null) { // 删除检测单里明细 DeleteNDEItemByNDEItemID(checkItem.NDEItemID); var ndeItem = from y in db.Batch_NDEItem where y.NDEID == checkItem.NDEID select y; // 当检测单没有明细时,删除检测单 if (ndeItem.Count() == 0) { BLL.Batch_NDEService.DeleteNDEById(checkItem.NDEID); } } // 删除委托单里明细 BLL.Batch_BatchTrustItemService.DeleteTrustItemByTrustBatchItemId(trustItem.TrustBatchItemId); var t = from y in db.Batch_BatchTrustItem where y.TrustBatchId == trustItem.TrustBatchId select y; // 当委托单只有没有明细时,删除委托单 if (t.Count() == 0) { BLL.Batch_BatchTrustService.DeleteBatchTrustById(trustItem.TrustBatchId); } else { // 去掉委托单里包含的点口单 string topoint = (from x in db.Batch_BatchTrust where x.TrustBatchId == trustItem.TrustBatchId select x.TopointBatch).FirstOrDefault(); if (!String.IsNullOrEmpty(topoint)) { topoint = topoint.Replace(pointBatchId + ",", "").Replace("," + pointBatchId, ""); Model.Batch_BatchTrust trust = db.Batch_BatchTrust.FirstOrDefault(x => x.TrustBatchId == trustItem.TrustBatchId); trust.TopointBatch = topoint; db.SubmitChanges(); } } } // 批明细 var pointBatchItemnews = from x in db.Batch_PointBatchItem where x.PointBatchId == pointBatchId select x; int count = pointBatchItemnews.Count(); BLL.Batch_PointBatchItemService.DeletePointBatchItemById(pointBatchItemId);// 删除此条明细 if (count == 1) ////批明细中只有一条焊口时 { BLL.Batch_PointBatchService.DeletePointBatchById(pointBatchId); // 删除批信息 } else // 批明细中存在多条时 { // 所在批 var pointBatch = db.Batch_PointBatch.FirstOrDefault(x => x.PointBatchId == pointBatchId && x.ClearDate == null); if (pointBatch != null) { var pointBatchItemUpdate = from x in Funs.DB.Batch_PointBatchItem where x.PointBatchId == pointBatchId && x.PointState != null && x.PointDate.HasValue select x; if (pointBatchItemUpdate.Count() == 0) { // 如果批里没有口被点中,则修改主表委托状态,这样就可重新生成委托 BLL.Batch_PointBatchService.UpdatePointTrustState(pointBatch.PointBatchId, null); } } } } } } #endregion #region 删除焊口所有业务信息 /// /// 删除批中焊口信息 /// /// 焊口id public static void DeleteWeldJointAllInfo(string weldJointId) { Model.HJGLDB db = Funs.DB; var trustItemList = from x in db.Batch_BatchTrustItem where x.WeldJointId==weldJointId select x; if (trustItemList.Count() > 0) { foreach (Model.Batch_BatchTrustItem trustItem in trustItemList) { if (trustItem != null) { Model.Batch_NDEItem checkItem = db.Batch_NDEItem.FirstOrDefault(x => x.TrustBatchItemId == trustItem.TrustBatchItemId); if (checkItem != null) { // 删除返修单 var repair = db.Repair_RepairRecord.FirstOrDefault(x => x.NDEItemID == checkItem.NDEItemID); if (repair != null) { db.Repair_RepairRecord.DeleteOnSubmit(repair); db.SubmitChanges(); } // 删除检测单里明细 DeleteNDEItemByNDEItemID(checkItem.NDEItemID); var ndeItem = from y in db.Batch_NDEItem where y.NDEID == checkItem.NDEID select y; // 当检测单没有明细时,删除检测单 if (ndeItem.Count() == 0) { BLL.Batch_NDEService.DeleteNDEById(checkItem.NDEID); } } // 删除委托单里明细 BLL.Batch_BatchTrustItemService.DeleteTrustItemByTrustBatchItemId(trustItem.TrustBatchItemId); var t = from y in db.Batch_BatchTrustItem where y.TrustBatchId == trustItem.TrustBatchId select y; // 当委托单只有没有明细时,删除委托单 if (t.Count() == 0) { BLL.Batch_BatchTrustService.DeleteBatchTrustById(trustItem.TrustBatchId); } var pointBatchItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(trustItem.PointBatchItemId); if (pointBatchItem != null) { string pointBatchItemId = pointBatchItem.PointBatchItemId; string pointBatchId = pointBatchItem.PointBatchId; if (t.Count() > 0) { // 去掉委托单里包含的点口单 string topoint = (from x in db.Batch_BatchTrust where x.TrustBatchId == trustItem.TrustBatchId select x.TopointBatch).FirstOrDefault(); if (!String.IsNullOrEmpty(topoint)) { topoint = topoint.Replace(pointBatchId + ",", "").Replace("," + pointBatchId, ""); Model.Batch_BatchTrust trust = db.Batch_BatchTrust.FirstOrDefault(x => x.TrustBatchId == trustItem.TrustBatchId); trust.TopointBatch = topoint; db.SubmitChanges(); } } // 批明细 var pointBatchItemnews = from x in db.Batch_PointBatchItem where x.PointBatchId == pointBatchId select x; int count = pointBatchItemnews.Count(); BLL.Batch_PointBatchItemService.DeletePointBatchItemById(pointBatchItemId);// 删除此条明细 if (count == 1) ////批明细中只有一条焊口时 { BLL.Batch_PointBatchService.DeletePointBatchById(pointBatchId); // 删除批信息 } else // 批明细中存在多条时 { // 所在批 var pointBatch = db.Batch_PointBatch.FirstOrDefault(x => x.PointBatchId == pointBatchId && x.ClearDate == null); if (pointBatch != null) { var pointBatchItemUpdate = from x in Funs.DB.Batch_PointBatchItem where x.PointBatchId == pointBatchId && x.PointState != null && x.PointDate.HasValue select x; if (pointBatchItemUpdate.Count() == 0) { // 如果批里没有口被点中,则修改主表委托状态,这样就可重新生成委托 BLL.Batch_PointBatchService.UpdatePointTrustState(pointBatch.PointBatchId, null); } } } } } } } else { // 未生成委托单 删除批 var pbItem = from x in Funs.DB.Batch_PointBatchItem where x.WeldJointId == weldJointId select x; if (pbItem.Count() > 0) { foreach (var q in pbItem) { string pointBathchId = q.PointBatchId; var pointItem = from x in db.Batch_PointBatchItem where x.PointBatchId == pointBathchId select x; int count = pointItem.Count(); BLL.Batch_PointBatchItemService.DeletePointBatchItemById(q.PointBatchItemId);// 删除此条明细 if (count == 1) ////批明细中只有一条焊口时 { BLL.Batch_PointBatchService.DeletePointBatchById(pointBathchId); // 删除批信息 } } } } // 热处理 var hotItem = db.HotProess_TrustItem.FirstOrDefault(x => x.WeldJointId == weldJointId); if (hotItem != null) { // 删除热处理报告 var hotReport = from x in db.HotProess_Report where x.HotProessTrustItemId == hotItem.HotProessTrustItemId select x; if (hotReport.Count() > 0) { db.HotProess_Report.DeleteAllOnSubmit(hotReport); } db.HotProess_TrustItem.DeleteOnSubmit(hotItem); db.SubmitChanges(); var hot = from y in db.HotProess_Trust where y.HotProessTrustId == hotItem.HotProessTrustId select y; // 当热处理委托单没有明细时,删除检测单 if (hot.Count() == 0) { db.HotProess_Trust.DeleteAllOnSubmit(hot); } db.SubmitChanges(); } // 硬度 var hardItem = db.Hard_TrustItem.FirstOrDefault(x => x.WeldJointId == weldJointId); if (hardItem != null) { // 删除硬度报告 var hardReport = from x in db.Hard_Report where x.HardTrustItemID == hardItem.HardTrustItemID select x; if (hardReport.Count() > 0) { db.Hard_Report.DeleteAllOnSubmit(hardReport); } db.Hard_TrustItem.DeleteOnSubmit(hardItem); db.SubmitChanges(); var hard = from y in db.Hard_Trust where y.HardTrustID == hardItem.HardTrustID select y; // 当硬度委托单没有明细时,删除检测单 if (hard.Count() == 0) { db.Hard_Trust.DeleteAllOnSubmit(hard); } db.SubmitChanges(); } // 删除焊口 BLL.Pipeline_WeldJointService.DeleteWeldJointById(weldJointId); } #endregion } }