/// <summary> /// 修改点检内容 /// </summary> /// <param name="inspectionContentSet">点检内容数据集</param> /// <param name="cvtTypeList">适用CVT型号数据列表</param> /// <param name="error">错误信息</param> /// <returns>成功返回True,失败返回False</returns> public bool UpdateContent(ZPX_InspectionContentSet inspectionContentSet, List <string> cvtTypeList, out string error) { error = null; DepotManagementDataContext dataContext = CommentParameter.DepotDataContext; dataContext.Connection.Open(); dataContext.Transaction = dataContext.Connection.BeginTransaction(); try { var varData = from a in dataContext.ZPX_InspectionContentSet where a.ID == inspectionContentSet.ID select a; if (varData.Count() != 1) { error = "数据为空或者不唯一"; throw new Exception(error); } else { ZPX_InspectionContentSet lnqContent = varData.Single(); lnqContent.InspectionContent = inspectionContentSet.InspectionContent; lnqContent.WorkBench = inspectionContentSet.WorkBench; lnqContent.Date = ServerTime.Time; lnqContent.WorkID = BasicInfo.LoginID; dataContext.SubmitChanges(); } var varDataCVT = from a in dataContext.ZPX_InspectionContentCVTType where a.ContentID == inspectionContentSet.ID select a; dataContext.ZPX_InspectionContentCVTType.DeleteAllOnSubmit(varDataCVT); foreach (string cvtType in cvtTypeList) { ZPX_InspectionContentCVTType lnqCVTType = new ZPX_InspectionContentCVTType(); lnqCVTType.ContentID = inspectionContentSet.ID; lnqCVTType.CVTType = cvtType; dataContext.ZPX_InspectionContentCVTType.InsertOnSubmit(lnqCVTType); } dataContext.SubmitChanges(); dataContext.Transaction.Commit(); return(true); } catch (Exception ex) { dataContext.Transaction.Rollback(); error = ex.Message; return(false); } }
/// <summary> /// 新增点检内容 /// </summary> /// <param name="inspectionContentSet">点检内容数据集</param> /// <param name="cvtTypeList">适用CVT型号数据列表</param> /// <param name="error">错误信息</param> /// <returns>成功返回True,失败返回False</returns> public bool AddContent(ZPX_InspectionContentSet inspectionContentSet, List <string> cvtTypeList, out string error) { error = null; DepotManagementDataContext dataContext = CommentParameter.DepotDataContext; dataContext.Connection.Open(); dataContext.Transaction = dataContext.Connection.BeginTransaction(); try { var varData = from a in dataContext.ZPX_InspectionContentSet where a.InspectionContent == inspectionContentSet.InspectionContent && a.WorkBench == inspectionContentSet.WorkBench select a; if (varData.Count() != 0) { error = "数据不唯一"; throw new Exception(error); } else { dataContext.ZPX_InspectionContentSet.InsertOnSubmit(inspectionContentSet); } dataContext.SubmitChanges(); int ContentID = (from a in dataContext.ZPX_InspectionContentSet where a.InspectionContent == inspectionContentSet.InspectionContent && a.WorkBench == inspectionContentSet.WorkBench select a).Single().ID; foreach (string cvtType in cvtTypeList) { ZPX_InspectionContentCVTType lnqCVTType = new ZPX_InspectionContentCVTType(); lnqCVTType.ContentID = ContentID; lnqCVTType.CVTType = cvtType; dataContext.ZPX_InspectionContentCVTType.InsertOnSubmit(lnqCVTType); } dataContext.SubmitChanges(); dataContext.Transaction.Commit(); return(true); } catch (Exception ex) { dataContext.Transaction.Rollback(); error = ex.Message; return(false); } }