protected bool UploadMesbasicData(LOCAL_MES_STEP_INFOModel m) { //if (mesDA.MesBaseExist(m.RECID)) //? //{ // m.RECID = System.Guid.NewGuid().ToString(); //} FT_MES_STEP_INFOModel ftM = new FT_MES_STEP_INFOModel(); ftM.CHECK_RESULT = m.CHECK_RESULT; ftM.DEFECT_CODES = m.DEFECT_CODES; ftM.LAST_MODIFY_TIME = m.LAST_MODIFY_TIME; ftM.REASON = m.REASON; ftM.RECID = m.RECID; ftM.SERIAL_NUMBER = m.SERIAL_NUMBER; ftM.STATUS = m.STATUS; ftM.STEP_MARK = m.STEP_MARK; ftM.STEP_NUMBER = m.STEP_NUMBER; ftM.TRX_TIME = m.TRX_TIME; ftM.USER_NAME = m.USER_NAME; try { int reTryMax = 10; int reTryCounter = 0; while (!mesDA.AddMesBaseinfo(ftM)) { Thread.Sleep(1000); reTryCounter++; if (reTryCounter > reTryMax) { logRecorder.AddDebugLog(this.nodeName, string.Format("上传基本数据到MES失败,条码:{0},工位:{1}", ftM.SERIAL_NUMBER, ftM.STEP_NUMBER)); return(false); } } logRecorder.AddDebugLog(this.nodeName, string.Format("上传基本数据到MES成功,条码:{0},工位:{1}", ftM.SERIAL_NUMBER, ftM.STEP_NUMBER)); if (!mesDA.MesBaseExist(ftM.RECID)) { logRecorder.AddDebugLog(this.nodeName, string.Format("MES数据未存在,条码:{0},工位:{1}", ftM.SERIAL_NUMBER, ftM.STEP_NUMBER)); } return(true); } catch (Exception ex) { logRecorder.AddDebugLog(this.nodeName, string.Format("上传基本数据到MES,数据库访问异常,条码:{0},工位:{1},{2}", ftM.SERIAL_NUMBER, ftM.STEP_NUMBER, ex.Message)); return(false); } }
protected int ReDetectQuery(string barcode) { int re = 0; string strWhere = string.Format("SERIAL_NUMBER='{0}' and AutoStationName='{1}'", barcode, this.nodeName); LOCAL_MES_STEP_INFOModel preCheckModel = localMesBasebll.GetLatestModel(strWhere); if (preCheckModel != null) { if (0 == preCheckModel.CHECK_RESULT) { re = 0; } else { re = 1; } } else { re = 2;//不存在记录 } return(re); }
public override bool ExeBusiness(ref string reStr) { if (!base.ExeBusiness(ref reStr)) { return(false); } if (!NodeStatParse(ref reStr)) { return(false); } if (!checkEnable) { return(true); } switch (currentTaskPhase) { case 1: { db1ValsToSnd[1] = 1; //流程锁定 if (this.currentStat.Status == EnumNodeStatus.设备故障) { break; } this.currentStat.Status = EnumNodeStatus.设备使用中; this.currentStat.ProductBarcode = ""; this.currentStat.StatDescribe = "设备使用中"; //开始读卡 if (string.IsNullOrWhiteSpace(rfidUID)) { if (SysCfgModel.SimMode) { rfidUID = SimRfidUID; } else { rfidUID = rfidRW.ReadUID(); } } currentTaskDescribe = "开始读RFID"; if (string.IsNullOrWhiteSpace(rfidUID)) { this.currentStat.StatDescribe = "读RFID卡失败"; if (db1ValsToSnd[0] != db1StatRfidFailed) { logRecorder.AddDebugLog(nodeName, "读RFID卡失败"); } db1ValsToSnd[0] = db1StatRfidFailed; break; } this.currentTask.TaskPhase = this.currentTaskPhase; this.currentTask.TaskParam = rfidUID; this.ctlTaskBll.Update(this.currentTask); db1ValsToSnd[0] = 0; this.currentStat.StatDescribe = "RFID识别完成"; //根据绑定,查询条码,赋条码 OnlineProductsModel productBind = productBindBll.GetModelByrfid(rfidUID); if (productBind == null) { db1ValsToSnd[0] = 4; this.currentStat.StatDescribe = "未投产"; logRecorder.AddDebugLog(nodeName, "未投产,rfid:" + rfidUID); checkEnable = false; break; } this.currentStat.ProductBarcode = productBind.productBarcode; productBind.currentNode = this.nodeName; productBindBll.Update(productBind); BarcodeFillDB1(productBind.productBarcode, 2); currentTaskPhase++; this.currentTask.TaskPhase = this.currentTaskPhase; this.ctlTaskBll.Update(this.currentTask); break; } case 2: { currentTaskDescribe = "开始判断是否需要进维修"; Int16 checkStat = 0; for (int i = 0; i < SysCfgModel.checkStations.Count(); i++) { string checkNodeName = SysCfgModel.checkStations[i]; string strSql = string.Format("SERIAL_NUMBER='{0}' and AutoStationName='{1}'", this.currentStat.ProductBarcode, checkNodeName); LOCAL_MES_STEP_INFOModel localCheckModel = localMesBasebll.GetLatestModel(strSql); if (localCheckModel == null || (localCheckModel.CHECK_RESULT == 1)) { checkStat |= (Int16)(1 << i); } } int mesRe = 0; string logStr = ""; if (checkStat > 0) { this.db1ValsToSnd[0] = 3; logStr = string.Format("{0} 进入维修分流线,因为有检测NG项", this.currentStat.ProductBarcode); logRecorder.AddDebugLog(nodeName, logStr); } else { if (!SysCfgModel.MesOfflineMode && PLProcessModel.SysCfgModel.MesCheckEnable) { logRecorder.AddDebugLog(nodeName, "MES下线查询开始:" + this.currentStat.ProductBarcode); mesRe = mesDA.MesAssemDown(new string[] { this.currentStat.ProductBarcode, PLProcessModel.SysCfgModel.mesLineID }, ref reStr); //string mesDownQueryMesID = "";// "DQ-F-0080"; //MES下线许可的MES工位id //if(SysCfgModel.mesLineID=="L10") //{ // mesDownQueryMesID = "DQ-G-0104"; //} //else //{ // // throw new NotImplementedException(); // mesDownQueryMesID = "DQ-H-0104"; //} //mesRe = mesDA.MesDownEnabled(PLProcessModel.SysCfgModel.mesLineID, this.currentStat.ProductBarcode, mesDownQueryMesID, ref reStr); } if (mesRe == 0) { logStr = string.Format("{0} MES下线允许,进入下线位", this.currentStat.ProductBarcode); logRecorder.AddDebugLog(nodeName, logStr); this.db1ValsToSnd[0] = 1; } else if (mesRe == 1) { if (this.db1ValsToSnd[0] != 3) { logStr = string.Format("{0} 进入维修分流线,因为:mes禁止下线,{1}", this.currentStat.ProductBarcode, reStr); logRecorder.AddDebugLog(nodeName, logStr); } this.db1ValsToSnd[0] = 3; } else if (reStr.Contains("已下线")) { if (this.db1ValsToSnd[0] != 3) { logStr = string.Format("{0} ,{1},进入维修分流线", this.currentStat.ProductBarcode, reStr); logRecorder.AddDebugLog(nodeName, logStr); } this.db1ValsToSnd[0] = 3; } else { break; } } //判断MES网络是否断开 if (mesRe != 0) { checkStat |= (1 << 4); } this.db1ValsToSnd[32] = checkStat; currentTaskPhase++; this.currentTask.TaskPhase = this.currentTaskPhase; this.ctlTaskBll.Update(this.currentTask); break; } case 3: { currentTaskDescribe = "维修分流完成"; this.currentStat.StatDescribe = "流程完成"; break; } default: break; } return(true); }
protected bool AsyUploadMesdata(string productBarcode, string[] mesProcessSeq, ref string reStr) { try { // int uploadDelay = 2000;//上传延迟5秒 List <string> strConditions = new List <string>(); for (int i = 0; i < mesProcessSeq.Count(); i++) { strConditions.Add(string.Format("SERIAL_NUMBER='{0}' and UPLOAD_FLAG = 0 and STEP_NUMBER='{1}' order by TRX_TIME asc", productBarcode, mesProcessSeq[i])); string strWhere = strConditions[i]; List <LOCAL_MES_STEP_INFOModel> models = localMesBasebll.GetModelList(strWhere); if (models == null || models.Count() < 1) { continue; } string process = mesProcessSeq[i]; if (process == "RQ-ZA240") { if (models.Count() > 1) { LOCAL_MES_STEP_INFOModel model1 = models[0]; LOCAL_MES_STEP_INFOModel model2 = models[1]; LOCAL_MES_STEP_INFOModel uploadM = model1.Clone() as LOCAL_MES_STEP_INFOModel; if (model1.CHECK_RESULT == 1 || model2.CHECK_RESULT == 1) { uploadM.CHECK_RESULT = 1; if (model1.CHECK_RESULT == 1 && model2.CHECK_RESULT == 1) { uploadM.DEFECT_CODES += (";" + model2.DEFECT_CODES); } else if (model2.CHECK_RESULT == 1) { uploadM.DEFECT_CODES = model2.DEFECT_CODES; } } if (!UploadMesbasicData(uploadM)) { return(false); } model1.UPLOAD_FLAG = true; model2.UPLOAD_FLAG = true; localMesBasebll.Update(model1); localMesBasebll.Update(model2); //Thread.Sleep(uploadDelay); } else if (models.Count() == 1) { if (!UploadMesbasicData(models[0])) { return(false); } models[0].UPLOAD_FLAG = true; localMesBasebll.Update(models[0]); // Thread.Sleep(uploadDelay); } } else { foreach (LOCAL_MES_STEP_INFOModel m in models) { if (!UploadMesbasicData(m)) { return(false); } m.UPLOAD_FLAG = true; localMesBasebll.Update(m); // Thread.Sleep(uploadDelay); } } } //for (int i = 0; i < strConditions.Count; i++) //{ //} for (int i = 0; i < strConditions.Count; i++) { string strWhere = strConditions[i]; List <LOCAL_MES_STEP_INFO_DETAILModel> models = localMesDetailbll.GetModelList(strWhere); if (models == null || models.Count() < 1) { continue; } string process = mesProcessSeq[i]; if (process == "RQ-ZA240") { if (models.Count() > 1) { LOCAL_MES_STEP_INFO_DETAILModel model1 = models[0]; LOCAL_MES_STEP_INFO_DETAILModel model2 = models[1]; LOCAL_MES_STEP_INFO_DETAILModel uploadM = model1.Clone() as LOCAL_MES_STEP_INFO_DETAILModel; uploadM.DATA_VALUE += (";" + model2.DATA_VALUE); if (!UploadMesdetailData(uploadM)) { return(false); } model1.UPLOAD_FLAG = true; model2.UPLOAD_FLAG = true; localMesDetailbll.Update(model1); localMesDetailbll.Update(model2); // Thread.Sleep(uploadDelay); } else if (models.Count() == 1) { if (!UploadMesdetailData(models[0])) { return(false); } models[0].UPLOAD_FLAG = true; localMesDetailbll.Update(models[0]); // Thread.Sleep(uploadDelay); } } else { foreach (LOCAL_MES_STEP_INFO_DETAILModel m in models) { if (!UploadMesdetailData(m)) { return(false); } m.UPLOAD_FLAG = true; localMesDetailbll.Update(m); // Thread.Sleep(uploadDelay); } } } return(true); } catch (Exception ex) { reStr = ex.ToString(); this.ThrowErrorStat(ex.ToString(), EnumNodeStatus.设备故障); return(false); } }
protected virtual bool MesDatalocalSave(string productBarcode, int checkResult, string detectCodes, string dataValues, int step_mark) { string strWhere = string.Format("SERIAL_NUMBER='{0}' and AutoStationName='{1}' and UPLOAD_FLAG=0", productBarcode, this.nodeName); List <LOCAL_MES_STEP_INFOModel> unuploads = mesInfoBllLocal.GetModelList(strWhere); if (unuploads != null && unuploads.Count > 0) { foreach (LOCAL_MES_STEP_INFOModel m in unuploads) { if (!mesInfoBllLocal.Delete(m.RECID)) { return(false); } } } //1 存储基本信息 LOCAL_MES_STEP_INFOModel infoModel = new LOCAL_MES_STEP_INFOModel(); infoModel.CHECK_RESULT = checkResult; infoModel.DEFECT_CODES = detectCodes; infoModel.LAST_MODIFY_TIME = System.DateTime.Now; infoModel.RECID = System.Guid.NewGuid().ToString(); infoModel.SERIAL_NUMBER = productBarcode; infoModel.STEP_NUMBER = this.mesNodeID; //mes工位号 infoModel.TRX_TIME = System.DateTime.Now; infoModel.UPLOAD_FLAG = false; infoModel.USER_NAME = ""; infoModel.STATUS = 0; infoModel.STEP_MARK = step_mark; infoModel.AutoStationName = this.nodeName; if (!mesInfoBllLocal.Add(infoModel)) { return(false); } //2存储细节数据 List <LOCAL_MES_STEP_INFO_DETAILModel> unuploadsDetial = mesDetailBllLocal.GetModelList(strWhere); if (unuploadsDetial != null && unuploadsDetial.Count > 0) { foreach (LOCAL_MES_STEP_INFO_DETAILModel m in unuploadsDetial) { mesDetailBllLocal.Delete(m.RECID); } } LOCAL_MES_STEP_INFO_DETAILModel detailModel = new LOCAL_MES_STEP_INFO_DETAILModel(); detailModel.DATA_NAME = this.mesNodeName; // detailModel.DATA_VALUE = dataValues; detailModel.LAST_MODIFY_TIME = System.DateTime.Now; detailModel.RECID = System.Guid.NewGuid().ToString(); detailModel.SERIAL_NUMBER = currentStat.ProductBarcode; detailModel.STATUS = 0; detailModel.STEP_NUMBER = this.mesNodeID; // detailModel.TRX_TIME = System.DateTime.Now; detailModel.UPLOAD_FLAG = false; detailModel.AutoStationName = this.nodeName; if (!mesDetailBllLocal.Add(detailModel)) { return(false); } return(true); }