public QM_IQC_MIDDLE submitIQCInspectionDetailResult(IList <CV_QM_IQC_BOTTOM> list) { int i = 0, len = list.Count; int badQua = 0; DateTime now = SSGlobalConfig.Now; QM_IQC_MIDDLE middle = null; using (TransactionScope ts = new TransactionScope()) { for (i = 0; i < len; i++) { CV_QM_IQC_BOTTOM cv_bottom = list[i]; if (cv_bottom.SingleResult.Equals("NG")) { badQua++; } QM_IQC_BOTTOM tmp = new QM_IQC_BOTTOM() { KID = cv_bottom.KID, Value = cv_bottom.Value, SingleResult = cv_bottom.SingleResult, Abnormality = cv_bottom.AbnormalityCode, Reason = cv_bottom.CauseCode }; iqc_bottom_bo.UpdateSome(tmp); } //更新中表 middle = new QM_IQC_MIDDLE() { MGuid = list[0].MGuid, ItemResult = badQua == 0 ? "OK" : "NG", AcceptQua = SafeConvert.ToString(len - badQua), BadQua = SafeConvert.ToString(badQua), ItemStatus = "已检", ItemDate = now }; iqc_middle_bo.UpdateSome(middle); ts.Complete(); } return(middle); }
//返回值 -1 没有需要同步的数据 0 同步成功 1同步失败 public int syncIQCInspection() { bool middleNew = false; Dictionary <string, List <string> > dictionary = new Dictionary <string, List <string> >(); DateTime now = DateTime.Now; Guid TGuid = Guid.Empty, MGuid = Guid.Empty; //获得中间表中获得数据 IList <QM_TEMP_IQC_INSPECTION> tmpList = temp_iqc_inspection_bo.getTempIQCInspection(); if (tmpList != null && tmpList.Count > 0) { using (TransactionScope ts = new TransactionScope()) { //遍历 foreach (QM_TEMP_IQC_INSPECTION tempIqc in tmpList) { middleNew = false; //先获得中间表的检验批状态 if (tempIqc.STATUSTEXT.Equals("REL")) { //判断是否为同一批检验批 if (!dictionary.ContainsKey(tempIqc.PRUEFOS)) { #region 主表 //检验批来源,检验批,检验批状态,采购订单号,采购订单项目号,供应商编号,批量数量,抽样大小,物料号, //物料描述,检验开始日期,检验结束日期,工厂,局号起,局号止,出厂号起,出厂号止,模块条码号起, //模块条码号止,备注,同步时间 TGuid = Guid.NewGuid(); QM_IQC_TOP top = new QM_IQC_TOP() { TGuid = TGuid, Source = tempIqc.HERKUNFT, //检验批来源 OrderID = tempIqc.PRUEFOS, //检验批 OrderStatus = "新建", //检验批状态 PurchaseOrderID = tempIqc.EBELN, //采购订单号 PurchaseOrderSeq = tempIqc.EBELP, //采购订单项目号 Supplier = tempIqc.SELLIFNR, //供应商编号 OrderQua = tempIqc.LOSMENGE, //批量数量 SampleQua = tempIqc.GESSTICHPR, //抽样大小 MaterielID = tempIqc.SELMATNR, //物料号 MaterielDes = tempIqc.KTEXTMAT, //物料描述 PlanStartDate = tempIqc.PASTRTERM, //检验开始日期 PlanEndDate = tempIqc.PAENDTERM, //检验结束日期 Plant = tempIqc.WERK, //工厂 BureauStart = tempIqc.ZJH1, //局号起 BureauEnd = tempIqc.ZJH2, //局号止 ExitStart = tempIqc.ZCC1, //出厂号起 ExitEnd = tempIqc.ZCC2, //出厂号止 LabelStart = tempIqc.ZMK1, //模块条码号 LabelEnd = tempIqc.ZMK2, //模块条码号止 remark = tempIqc.ZBZ, //备注 SyncTime = now, //同步时间 PartVocher = tempIqc.MBLNR, //物料凭证 PartVocherYear = tempIqc.MJAHR //物料凭证年份 }; iqc_top_bo.Insert(top); #endregion List <string> middleList = new List <string>(); middleList.Add(tempIqc.MERKNR); middleNew = true; dictionary.Add(tempIqc.PRUEFOS, middleList); } //新检验批或者还没插入中表的检验特性项目 if (middleNew || !dictionary[tempIqc.PRUEFOS].Contains(tempIqc.MERKNR)) { #region 中表 MGuid = Guid.NewGuid(); //检验批号,检验特性序号,检验特性描述,检验项目属性,检验项目目标值,检验上限,检验下限,抽样数量 QM_IQC_MIDDLE middle = new QM_IQC_MIDDLE() { MGuid = MGuid, TGuid = TGuid, OrderID = tempIqc.PRUEFOS, //检验批 ItemID = tempIqc.MERKNR, //检验特性序号 ItemDes = tempIqc.KURZTEXT, //检验特性描述 ItemProperty = tempIqc.ATTRIBUTE.Equals("1") ? dingxing : dingliang, //检验项目属性 ItemStatus = "待检", //检验状态 Target = tempIqc.SOLLWERT, //检验项目目标值 UpperBound = tempIqc.TOLERANZOB, //检验上限 LowerBound = tempIqc.TOLERANZUN, //检验下限 SampleSize = tempIqc.PRUEFEINH //抽样数量 }; iqc_middle_bo.Insert(middle); #endregion #region 明细表 log.Info("SampleSize--->" + tempIqc.PRUEFEINH); for (int i = 0; i < tempIqc.PRUEFEINH; i++) { QM_IQC_BOTTOM bottom = new QM_IQC_BOTTOM() { MGuid = MGuid, OrderID = tempIqc.PRUEFOS, //检验批 ItemID = tempIqc.MERKNR, //检验特性序号 ItemProperty = tempIqc.ATTRIBUTE.Equals("1") ? dingxing : dingliang, //检验项目属性 IndexNum = i + 1 //序号 }; iqc_bottom_bo.Insert(bottom); } #endregion dictionary[tempIqc.PRUEFOS].Add(tempIqc.MERKNR); } } else { //判断是否为同一批检验批 if (!dictionary.ContainsKey(tempIqc.PRUEFOS)) { //先查询是否存在该检验批 QM_IQC_TOP_QueryParam param = new QM_IQC_TOP_QueryParam() { OrderID = tempIqc.PRUEFOS }; QM_Page_Return ret = iqc_top_bo.filterIQCInspectionBathPage(param); log.Info("ret.totalRecords--->" + ret.totalRecords); if (ret.totalRecords == 0) { //不存在,不作任何处理 } else { QM_IQC_TOP top = new QM_IQC_TOP() { TGuid = ((IList <QM_IQC_TOP>)ret.dataList)[0].TGuid, OrderID = tempIqc.PRUEFOS, OrderStatus = "取消" }; iqc_top_bo.UpdateSome(top); } List <string> middleList = new List <string>(); middleList.Add(tempIqc.MERKNR); middleNew = true; dictionary.Add(tempIqc.PRUEFOS, middleList); } } #region 更新中间表的状态 tempIqc.MESSYNC = 1; temp_iqc_inspection_bo.UpdateSome(tempIqc); #endregion } ts.Complete(); return(0); } } return(-1); }