/// <summary> /// 为指定Repair更新一个RepairDefect /// </summary> /// <param name="repairId">指定Repair的Id</param> /// <param name="defect">指定RepairDefect</param> public void UpdateTestLogDefect(int testLogId, TestLogDefect defect) { lock (_syncObj_testLogs) { object naught = this.TestLogs; if (this._testLogs != null && defect != null) { foreach (TestLog tl in this._testLogs) { if (tl.Key.Equals(testLogId)) { tl.UpdateTestLogDefect(defect); tl.Tracker.MarkAsModified(tl); this._tracker.MarkAsModified(this); break; } } } } }
/// <summary> /// insert into pcbtestlog /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { var mb = (IMB)CurrentSession.GetValue(Session.SessionKeys.MB); IMBRepository mbRepository = RepositoryFactory.GetInstance().GetRepository<IMBRepository, IMB>(); IList<string> defectList = (IList<string>)CurrentSession.GetValue(Session.SessionKeys.DefectList); IList<TestLogDefect> defects = new List<TestLogDefect>(); if (defectList != null) { foreach (string item in defectList) { //add defect TestLogDefect defectItem = new TestLogDefect(0, 0, item, this.Editor, DateTime.Now); defects.Add(defectItem); } } //get 111 type string type = "MB";// mb.ModelObj.Type; string line = this.Line; if (string.IsNullOrEmpty(line)) { line = mb.MBStatus.Line; } string fixid = (string)CurrentSession.GetValue(Session.SessionKeys.FixtureID); if (string.IsNullOrEmpty(fixid)) { fixid = string.Empty; } string actionName = (string)CurrentSession.GetValue(ExtendSession.SessionKeys.TestLogActionName); if (string.IsNullOrEmpty(actionName)) { actionName = string.Empty; } string errorCode = (string)CurrentSession.GetValue(ExtendSession.SessionKeys.TestLogErrorCode); if (string.IsNullOrEmpty(errorCode)) { errorCode = string.Empty; } string descr = (string)CurrentSession.GetValue(ExtendSession.SessionKeys.TestLogDescr); if (string.IsNullOrEmpty(descr)) { descr = string.Empty; } string remark = (string)CurrentSession.GetValue(ExtendSession.SessionKeys.TestLogRemark); if (string.IsNullOrEmpty(remark)) { remark = string.Empty; } TestLog tItem; string AllowPass = ""; string DefectStation = ""; if (CurrentSession.GetValue(ExtendSession.SessionKeys.AllowPass) != null) { AllowPass = (string)CurrentSession.GetValue(ExtendSession.SessionKeys.AllowPass); } if (CurrentSession.GetValue(ExtendSession.SessionKeys.DefectStation) != null) { DefectStation = (string)CurrentSession.GetValue(ExtendSession.SessionKeys.DefectStation); } if (defectList == null || defectList.Count == 0) { tItem = new TestLog(0, mb.Sn, line, fixid, this.Station, new List<TestLogDefect>(), TestLog.TestLogStatus.Pass, "", actionName, errorCode, descr, this.Editor, type, DateTime.Now); } else { if (AllowPass == "N")//Check AllowPass =N Dean 20110625 { tItem = new TestLog(0, mb.Sn, line, fixid, DefectStation, defects, TestLog.TestLogStatus.Fail, "", actionName, errorCode, descr, this.Editor, type, DateTime.Now); } else //Normal Flow { tItem = new TestLog(0, mb.Sn, line, fixid, this.Station, defects, TestLog.TestLogStatus.Fail, "", actionName, errorCode, descr, this.Editor, type, DateTime.Now); } } tItem.Remark = remark; mb.AddTestLog(tItem); mbRepository.Update(mb, CurrentSession.UnitOfWork); return base.DoExecute(executionContext); }
/// <summary> /// 檢查QTime 及設定QTime Action /// </summary> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { IProductRepository prodRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IQTimeRepository qTimeRep = RepositoryFactory.GetInstance().GetRepository<IQTimeRepository, QTime>(); ILineRepository lineRep = RepositoryFactory.GetInstance().GetRepository<ILineRepository, Line>(); DateTime now = DateTime.MinValue; #region 檢查 Product ,QTime及LineEx 設置資料,若無,則不做 string pdline = this.Line; var prod = (Product)CurrentSession.GetValue(Session.SessionKeys.Product); if (string.IsNullOrEmpty(pdline)) { pdline = prod.Status.Line; if (string.IsNullOrEmpty(pdline)) { IList<ProductStatusExInfo> preStatusList = prodRep.GetProductPreStation(new List<string> { prod.ProId }); if (preStatusList.Count > 0) { pdline = preStatusList[0].PreLine; } } } Line line = lineRep.Find(pdline); if (prod == null || line == null || line.LineEx == null || string.IsNullOrEmpty(line.LineEx.AliasLine)) { //throw new FisException(); return base.DoExecute(executionContext); } string aliasLine = line.LineEx.AliasLine; //QTime qTime = qTimeRep.Find(new string[] { aliasLine, this.Station, prod.ProId }); QTime qTime = qTimeRep.GetPriorityQTime(aliasLine, this.Station, prod.ProId, prod.Model, prod.Family); if (qTime == null) { return base.DoExecute(executionContext); } #endregion #region 檢查QTime.StopTime,計算是否紀錄停線,不做DB事務 if (qTime != null && qTime.StopTime > 0) { LineStationLastProcessTime processTime = qTimeRep.GetLastProcessTime(aliasLine, this.Station); if (processTime != null) { now = processTime.Now; if (processTime.SpeedTime >= qTime.StopTime) { LineStationStopPeriodLog periodLog = new LineStationStopPeriodLog { Line = aliasLine, Station = this.Station, StartTime = processTime.ProcessTime, EndTime = now, Editor = this.Editor }; qTimeRep.AddLineStationStopPeriodLog(periodLog); } } // 沒有最後一次Process Time 不考慮Check TimeOut else { now = SqlHelper.GetDateTime(); } processTime = new LineStationLastProcessTime { Line = aliasLine, Station = this.Station, ProductID = prod.ProId, ProcessTime = now, Editor = this.Editor }; qTimeRep.UpdateLineStationLastProcessTime(processTime); //刪除過時的停線紀錄 qTimeRep.RemoveStationStopPeriodLog(aliasLine, this.Station, this.RemainLogDay); } #endregion #region 檢查TimeOut ,計算是否QTime逾時並執行QTime Action IUnitOfWork uow = new UnitOfWork(); bool isDoDefect = false; bool isDoHoldStation = false; string defectStation = this.Station; int timeOut = 0; //int stopTime = 0; bool isCheckTimeOutStation = true; bool isTimeOut = false; string preStation = prod.Status.StationId.Trim(); TestLog.TestLogStatus defectStatus = TestLog.TestLogStatus.Fail; //檢查TimeOut例外站點 if (!string.IsNullOrEmpty(qTime.ExceptStation)) { string[] exceptStations = qTime.ExceptStation.Split(new char[] { ',', ';', '~' }); isCheckTimeOutStation = !exceptStations.Contains(preStation); } if (qTime != null && qTime.TimeOut > 0 && isCheckTimeOutStation) { if (now == DateTime.MinValue) { now = SqlHelper.GetDateTime(); } //計算TimeOut //IList<int> timeOutList = qTimeRep.CalLineStopTime(aliasLine, "69", prod.Status.Udt, now); //stopTime = timeOutList[0]; //timeOut = (timeOutList[1] - timeOutList[0]) ; IList<LineStopLogInfo> logs = qTimeRep.CalLineStopMillionSecond(aliasLine, this.Station, prod.Status.Udt, now); double stopMillionSecond = 0; foreach (LineStopLogInfo item in logs) { stopMillionSecond = stopMillionSecond + (item.EndTime - item.StartTime).TotalMilliseconds; } timeOut = (int)(((now - prod.Status.Udt).TotalMilliseconds - stopMillionSecond) / 1000); // 判別有沒有TimeOut if ((qTime.Category == QTimeCategoryEnum.Max && timeOut >= qTime.TimeOut) || (qTime.Category == QTimeCategoryEnum.Min && timeOut <= qTime.TimeOut)) { isTimeOut = true; if (!string.IsNullOrEmpty(qTime.DefectCode)) { isDoDefect = true; } if (!string.IsNullOrEmpty(qTime.HoldStation)) { defectStation = qTime.HoldStation; defectStatus = (qTime.HoldStatus == QTimeStationStatusEnum.Fail ? TestLog.TestLogStatus.Fail : TestLog.TestLogStatus.Pass); isDoHoldStation = true; } } //執行QTime Action if (isDoDefect || isDoHoldStation) { #region record previous product Status //System.Data.DataTable preStatus = CreateDataTable.CreateProductStatusTb(); //preStatus.Rows.Add(prod.ProId, // prod.Status.StationId, // prod.Status.Status == StationStatus.Pass ? 1 : 0, // prod.Status.ReworkCode, // prod.Status.Line, // prod.Status.TestFailCount, // prod.Status.Editor, // prod.Status.Udt // ); //System.Data.DataTable curStatus = CreateDataTable.CreateProductStatusTb(); prod.UpdateStatus(new IMES.FisObject.FA.Product.ProductStatus() { Line = pdline, ProId = prod.ProId, TestFailCount = 0, ReworkCode = "", StationId = defectStation, Status = (defectStatus == TestLog.TestLogStatus.Fail ? StationStatus.Fail : StationStatus.Pass), Editor = this.Editor, Udt = now }); //prod.Status.Line = pdline; //prod.Status.StationId = defectStation; //prod.Status.Status = (defectStatus == TestLog.TestLogStatus.Fail ? // StationStatus.Fail : StationStatus.Pass); //prod.Status.Editor = this.Editor; //prod.Status.Udt = now; //curStatus.Rows.Add(prod.ProId, // defectStation, // (defectStatus == TestLog.TestLogStatus.Fail ? // 0 : 1), // prod.Status.ReworkCode, // this.Line, // prod.Status.TestFailCount, // this.Editor, // prod.Status.Udt // ); //SqlParameter para1 = new SqlParameter("PreStatus", System.Data.SqlDbType.Structured); //para1.Direction = System.Data.ParameterDirection.Input; //para1.Value = preStatus; //SqlParameter para2 = new SqlParameter("Status", System.Data.SqlDbType.Structured); //para2.Direction = System.Data.ParameterDirection.Input; //para2.Value = curStatus; //prodRep.ExecSpForNonQueryDefered(uow, // IMES.Infrastructure.Repository._Schema.SqlHelper.ConnectionString_FA, // "IMES_UpdateProductStatus", // para1, // para2); IList<IMES.DataModel.TbProductStatus> stationList = prodRep.GetProductStatus(new List<string> { prod.ProId }); prodRep.UpdateProductPreStationDefered(uow, stationList); #endregion #region write Productlog ProductLog productLog = new ProductLog { Model = prod.Model, Status = (defectStatus == TestLog.TestLogStatus.Fail ? StationStatus.Fail : StationStatus.Pass), Editor = this.Editor, Line = pdline, Station = defectStation, Cdt = now }; prod.AddLog(productLog); #endregion } //unpack Pizza part if (isDoHoldStation && defectStation == "UnPizza") { ActivityCommonImpl utl = ActivityCommonImpl.Instance; utl.UnPack.unPackPizzaPart(CurrentSession, uow, this.Editor); utl.UnPack.unPackPAKProductPart(CurrentSession, uow, this.Editor); prodRep.DeleteProductPartByProductIDAndStationDefered(uow, new List<string>() { prod.ProId }, new List<string>() { "68", "8C", "PK01", "PK02", "PK03", "PK04", "PK05", "PKOK" }, this.Editor); } if (isDoDefect) { #region add test log string actionName = qTime.Category.ToString() + "QTime"; string errorCode = ""; string descr = "PreStation:" + preStation + "~CurStation:" + this.Station + "~TimeOut:" + timeOut.ToString(); //TestLog testLog = new TestLog(0, prod.ProId, this.Line, "", defectStation, defectStatus, "", this.Editor, "PRD", DateTime.Now); TestLog testLog = new TestLog(0, prod.ProId, pdline, "", defectStation, defectStatus, "", actionName, errorCode, descr, this.Editor, "PRD", now); prod.AddTestLog(testLog); //add defect TestLogDefect defectItem = new TestLogDefect(0, 0, qTime.DefectCode, this.Editor, now); testLog.AddTestLogDefect(defectItem); #endregion } if (isDoDefect || isDoHoldStation) { prodRep.Update(prod, uow); uow.Commit(); if (qTime.Category == QTimeCategoryEnum.Min) { int diffTime = (timeOut - qTime.TimeOut) / 60; throw new FisException("CHK093", new string[] { diffTime.ToString() }); } else { throw new FisException("QTM001", new string[] { prod.ProId, qTime.Category.ToString() + "QTime", timeOut.ToString() }); } } //Min QTime Warning message nothing to do if (isTimeOut && qTime.Category == QTimeCategoryEnum.Min) { int diffTime = (timeOut - qTime.TimeOut) / 60; throw new FisException("CHK093", new string[] { diffTime.ToString() }); } } #endregion return base.DoExecute(executionContext); }
internal void UpdateTestLogDefect(TestLogDefect tldfct) { if (tldfct == null) return; lock (_syncObj_defects) { object naught = this.Defects; if (this._defects == null) return; int idx = 0; bool find = false; foreach (TestLogDefect dfct in this._defects) { if (dfct.Key.Equals(tldfct.Key)) { find = true; break; } idx++; } if (find) { this._defects[idx] = tldfct; this._tracker.MarkAsModified(this._defects[idx]); } } }
/// <summary> /// /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { IProductRepository prodRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IQTimeRepository qTimeRep = RepositoryFactory.GetInstance().GetRepository<IQTimeRepository, QTime>(); ILineRepository lineRep = RepositoryFactory.GetInstance().GetRepository<ILineRepository, Line>(); DateTime now = DateTime.MinValue; var prod = (Product)CurrentSession.GetValue(Session.SessionKeys.Product); string pdline = prod.Status.Line; IUnitOfWork uow = new UnitOfWork(); string defectStation = this.Station; string preStation = prod.Status.StationId.Trim(); string defctcode= (string)CurrentSession.GetValue(Session.SessionKeys.DefectList); TestLog.TestLogStatus defectStatus = TestLog.TestLogStatus.Fail; prod.UpdateStatus(new IMES.FisObject.FA.Product.ProductStatus() { Line = pdline, ProId = prod.ProId, TestFailCount = 0, ReworkCode = "", StationId = this.Station, Status = StationStatus.Fail , Editor = this.Editor, Udt = now }); IList<IMES.DataModel.TbProductStatus> stationList = prodRep.GetProductStatus(new List<string> { prod.ProId }); prodRep.UpdateProductPreStationDefered(uow, stationList); #region write Productlog ProductLog productLog = new ProductLog { Model = prod.Model, Status =StationStatus.Fail , Editor = this.Editor, Line = pdline, Station = defectStation, Cdt = now }; prod.AddLog(productLog); #endregion #region add test log string actionName = "OfflineQTime"; string errorCode = ""; string descr = "PreStation:" + preStation + "~CurStation:" + this.Station + "~TimeOut:" ; //TestLog testLog = new TestLog(0, prod.ProId, this.Line, "", defectStation, defectStatus, "", this.Editor, "PRD", DateTime.Now); TestLog testLog = new TestLog(0, prod.ProId, pdline, "", defectStation, defectStatus, "", actionName, errorCode, descr, this.Editor, "PRD", now); prod.AddTestLog(testLog); //add defect TestLogDefect defectItem = new TestLogDefect(0, 0, defctcode, this.Editor, now); testLog.AddTestLogDefect(defectItem); #endregion prodRep.Update(prod, uow); uow.Commit(); return base.DoExecute(executionContext); }
/// <summary> /// 为测试log增加defect /// </summary> /// <param name="tldfct">defect</param> public void AddTestLogDefect(TestLogDefect tldfct) { if (tldfct == null) return; lock (_syncObj_defects) { //if (this._defects == null) // this._defects = new List<TestLogDefect>(); object naught = this.Defects; if (this._defects.Contains(tldfct)) return; tldfct.Tracker = this._tracker.Merge(tldfct.Tracker); this._defects.Add(tldfct); this._tracker.MarkAsAdded(tldfct); this._tracker.MarkAsModified(this); } }
/// <summary> /// Wrint Product Log /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { var productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IProduct currentProduct = null; RepairDefect defect = null; var newStatus = new ProductStatus(); string ProductID = ""; defect = (RepairDefect)CurrentSession.GetValue(Session.SessionKeys.CurrentRepairdefect); if (defect == null) { List<string> errpara = new List<string>(); errpara.Add("CurrentRepairdefect"); FisException e = new FisException("CHK194", errpara); e.stopWF = this.IsStopWF; throw e; } if (IsNewProID) { ProductID = defect.NewPartSno;//NEW } else { ProductID = defect.OldPartSno;//OLD } //Vincent modify this for CQ CleanRoom trace maijor id is CT //currentProduct = productRepository.Find(ProductID); currentProduct = productRepository.GetProductByIdOrSn(ProductID); if (currentProduct==null) { List<string> errpara = new List<string>(); errpara.Add(ProductID); FisException e = new FisException("SFC002", errpara); e.stopWF=this.IsStopWF; throw e; } ProductID = currentProduct.ProId; //UnpackCarton if (!IsNewProID) { //var currentProductObject = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); //String cartonSN = currentProduct.CartonSN; //String palletNo = currentProduct.PalletNo; //String dn = currentProduct.DeliveryNo; //if (currentProduct != null) //{ // productId = currentProduct.ProId; //} productRepository.BackUpProduct(ProductID, this.Editor); //productRepository.CopyProductToUnpackDefered(CurrentSession.UnitOfWork, cartonSN, palletNo, dn, productId, this.Editor); currentProduct.CartonSN = ""; } //write ProductStatusEx IList<IMES.DataModel.TbProductStatus> stationList = productRepository.GetProductStatus(new List<string> { currentProduct.ProId }); productRepository.UpdateProductPreStationDefered(CurrentSession.UnitOfWork, stationList); //write ProductStatus newStatus.ProId = currentProduct.ProId; newStatus.Status = Status; newStatus.StationId = Station; newStatus.Editor = Editor; newStatus.Line = currentProduct.Status.Line ; newStatus.TestFailCount = 0; newStatus.ReworkCode = ""; currentProduct.UpdateStatus(newStatus); //write productLog var productLog = new ProductLog { Model = currentProduct.Model, Status = Status, Editor = Editor, Line = currentProduct.Status.Line, Station = Station, Cdt = DateTime.Now }; currentProduct.AddLog(productLog); //write ProductTestLog if (this.IsWriteTestLog) { TestLog.TestLogStatus status = (Status== StationStatus.Pass? TestLog.TestLogStatus.Pass: TestLog.TestLogStatus.Fail); TestLogDefect defectItem = new TestLogDefect(0, 0,defect.DefectCodeID, this.Editor, DateTime.Now); //TestLog item = new TestLog(0, currentProduct.ProId, string.IsNullOrEmpty(Line) ? currentProduct.Status.Line : Line, // "", Station, status, "", this.TestLogAction, "", "", this.Editor, "PRD", DateTime.Now); IList<TestLogDefect> defectItemList = new List<TestLogDefect>(); defectItemList.Add(defectItem); TestLog item = new TestLog(0, currentProduct.ProId, currentProduct.Status.Line , "", Station, defectItemList, status, "", this.TestLogAction, "", "", this.Editor, "PRD", DateTime.Now); //item.AddTestLogDefect(defectItem); currentProduct.AddTestLog(item); } productRepository.Update(currentProduct, CurrentSession.UnitOfWork); return base.DoExecute(executionContext); }
/// <summary> /// 记录到ProductTestLog,ProductTestLog_DefectInfo表 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { Session session = CurrentSession; var prod = (IProduct)session.GetValue(Session.SessionKeys.Product); IProductRepository productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IList<string> defectList = (IList<string>)CurrentSession.GetValue(Session.SessionKeys.DefectList); //Dean 20110625 string AllowPass = ""; string DefectStation = ""; string InsertStation = ""; // string logDescr=(string)CurrentSession.GetValue("ProductTestLogDescr")??""; // string logAction = (string)CurrentSession.GetValue("ProductTestLogAction") ?? ""; //Benson string fixid = (string)session.GetValue(Session.SessionKeys.FixtureID); if (string.IsNullOrEmpty(fixid)) { fixid = string.Empty; } string actionName = (string)session.GetValue(ExtendSession.SessionKeys.TestLogActionName); if (string.IsNullOrEmpty(actionName)) { actionName = string.Empty; } string errorCode = (string)session.GetValue(ExtendSession.SessionKeys.TestLogErrorCode); if (string.IsNullOrEmpty(errorCode)) { errorCode = string.Empty; } string descr = (string)session.GetValue(ExtendSession.SessionKeys.TestLogDescr); if (string.IsNullOrEmpty(descr)) { descr = string.Empty; } string remark = (string)session.GetValue(ExtendSession.SessionKeys.TestLogRemark); if (string.IsNullOrEmpty(remark)) { remark = string.Empty; } string testLogJoinId = (string)session.GetValue(ExtendSession.SessionKeys.TestLogJoinId) ?? string.Empty; //Benson if (session.GetValue(ExtendSession.SessionKeys.AllowPass) != null) { AllowPass = (string)session.GetValue(ExtendSession.SessionKeys.AllowPass); } if (session.GetValue(ExtendSession.SessionKeys.DefectStation) != null) { DefectStation = (string)session.GetValue(ExtendSession.SessionKeys.DefectStation); } //Dean 20110625 string line = this.Line; if (string.IsNullOrEmpty(line)) { line = prod.Status.Line; } TestLog.TestLogStatus status = TestLog.TestLogStatus.Fail; if (IsPass) { status = TestLog.TestLogStatus.Pass; } if (AllowPass == "N")//Check AllowPass =N Dean 20110625 { InsertStation = DefectStation; } else //Normal Flow { InsertStation = this.Station; } TestLog tItem; /* if (string.IsNullOrEmpty(logDescr) && string.IsNullOrEmpty(logAction)) { tItem = new TestLog(0, prod.ProId, line, "", InsertStation, status, "", this.Editor, "PRD", DateTime.Now);//Dean 20110625 this.Station==>InsertStation } else { tItem = new TestLog(0, prod.ProId, line, "", InsertStation, status, "",logAction,"",logDescr, this.Editor, "PRD", DateTime.Now);//Dean 20110625 this.Station==>InsertStation }*/ string type = "PRD"; if (defectList == null || defectList.Count == 0) { tItem = new TestLog(0, prod.ProId, line, fixid, InsertStation, new List<TestLogDefect>(), status, testLogJoinId, actionName, errorCode, descr, this.Editor, type, DateTime.Now); } else { IList<TestLogDefect> defects = new List<TestLogDefect>(); if (defectList != null) { foreach (string item in defectList) { //add defect TestLogDefect defectItem = new TestLogDefect(0, 0, item, this.Editor, DateTime.Now); defects.Add(defectItem); } } if (AllowPass == "N")//Check AllowPass =N Dean 20110625 { tItem = new TestLog(0, prod.ProId, line, fixid, InsertStation, defects, status, testLogJoinId, actionName, errorCode, descr, this.Editor, type, DateTime.Now); } else //Normal Flow { tItem = new TestLog(0, prod.ProId, line, fixid, InsertStation, defects, status, testLogJoinId, actionName, errorCode, descr, this.Editor, type, DateTime.Now); } } tItem.Remark = remark; prod.AddTestLog(tItem); productRepository.Update(prod, session.UnitOfWork); return base.DoExecute(executionContext); }
/// <summary> /// 檢查QTime 及設定QTime Action /// </summary> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { Session session = CurrentSession; ActivityCommonImpl utl = ActivityCommonImpl.Instance; IProductRepository prodRep = utl.prodRep; //RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IMBRepository mbRep = utl.mbRep; IQTimeRepository qTimeRep = RepositoryFactory.GetInstance().GetRepository<IQTimeRepository, QTime>(); ILineRepository lineRep = utl.lineRep; //RepositoryFactory.GetInstance().GetRepository<ILineRepository, Line>(); DateTime now=DateTime.MinValue; #region 檢查 Product ,QTime及LineEx 設置資料,若無,則不做 string pdline = this.Line; IProduct prod =null; IMB mb =null; string SN = null; string modelName = null; string familyName = null; DateTime udt = DateTime.Now; string preStation = null; if (this.ProcessType == ProcessTypeEnum.Product) { prod = utl.IsNull<IProduct>(session,Session.SessionKeys.Product); modelName = prod.Model; SN = prod.ProductID; familyName = prod.Family; udt = prod.Status.Udt; preStation = prod.Status.StationId.Trim(); if (string.IsNullOrEmpty(pdline)) { pdline = prod.Status.Line; if (string.IsNullOrEmpty(pdline)) { IList<ProductStatusExInfo> preStatusList = prodRep.GetProductPreStation(new List<string> { prod.ProId }); if (preStatusList.Count > 0) { pdline = preStatusList[0].PreLine; } } } } else { mb = utl.IsNull<IMB>(session, Session.SessionKeys.MB); modelName = mb.Model; SN = mb.Sn; familyName = mb.Family; udt = mb.MBStatus.Udt; preStation = mb.MBStatus.Station; if (string.IsNullOrEmpty(pdline)) { pdline = mb.MBStatus.Line; if (string.IsNullOrEmpty(pdline)) { IList<PCBStatusExInfo> preStatusList = mbRep.GetPCBPreStation(new List<string> { mb.Sn }); if (preStatusList.Count > 0) { pdline = preStatusList[0].PreLine; } } } } Line line = lineRep.Find(pdline); if (prod==null || line == null || line.LineEx == null || string.IsNullOrEmpty(line.LineEx.AliasLine)) { //throw new FisException(); return base.DoExecute(executionContext); } string aliasLine = line.LineEx.AliasLine; //QTime qTime = qTimeRep.Find(new string[] { aliasLine, this.Station, prod.ProId }); QTime qTime = qTimeRep.GetPriorityQTime(aliasLine, this.Station, SN,modelName, familyName); if (qTime == null ) { return base.DoExecute(executionContext); } #endregion #region 檢查QTime.StopTime,計算是否紀錄停線,不做DB事務 if (qTime != null && qTime.StopTime > 0) { LineStationLastProcessTime processTime= qTimeRep.GetLastProcessTime(aliasLine, this.Station); if (processTime != null) { now = processTime.Now; if (processTime.SpeedTime >= qTime.StopTime) { LineStationStopPeriodLog periodLog = new LineStationStopPeriodLog { Line = aliasLine, Station = this.Station, StartTime = processTime.ProcessTime, EndTime = now, Editor = this.Editor }; qTimeRep.AddLineStationStopPeriodLog(periodLog); } } // 沒有最後一次Process Time 不考慮Check TimeOut else { now = SqlHelper.GetDateTime(); } processTime = new LineStationLastProcessTime { Line = aliasLine, Station = this.Station, ProductID = SN, ProcessTime = now, Editor = this.Editor }; qTimeRep.UpdateLineStationLastProcessTime(processTime); //刪除過時的停線紀錄 qTimeRep.RemoveStationStopPeriodLog(aliasLine, this.Station, this.RemainLogDay); } #endregion #region 檢查TimeOut ,計算是否QTime逾時並執行QTime Action IUnitOfWork uow = new UnitOfWork(); bool isDoDefect = false; bool isDoHoldStation = false; string defectStation = this.Station; int timeOut = 0; //int stopTime = 0; bool isCheckTimeOutStation = true; bool isTimeOut = false; //string preStation = prod.Status.StationId.Trim(); TestLog.TestLogStatus defectStatus = TestLog.TestLogStatus.Fail; //檢查TimeOut例外站點 if (!string.IsNullOrEmpty(qTime.ExceptStation)) { string[] exceptStations = qTime.ExceptStation.Split(Delimiter); isCheckTimeOutStation = !exceptStations.Contains(preStation); } if (qTime != null && qTime.TimeOut > 0 && isCheckTimeOutStation) { if (now == DateTime.MinValue) { now = SqlHelper.GetDateTime(); } //計算TimeOut //IList<int> timeOutList = qTimeRep.CalLineStopTime(aliasLine, "69", prod.Status.Udt, now); //stopTime = timeOutList[0]; //timeOut = (timeOutList[1] - timeOutList[0]) ; IList<LineStopLogInfo> logs = qTimeRep.CalLineStopMillionSecond(aliasLine, this.Station, udt, now); double stopMillionSecond = 0; foreach( LineStopLogInfo item in logs) { stopMillionSecond = stopMillionSecond + (item.EndTime - item.StartTime).TotalMilliseconds; } timeOut = (int)(((now - udt).TotalMilliseconds - stopMillionSecond) / 1000); // 判別有沒有TimeOut if ((qTime.Category == QTimeCategoryEnum.Max && timeOut >= qTime.TimeOut) || (qTime.Category == QTimeCategoryEnum.Min && timeOut <= qTime.TimeOut)) { isTimeOut = true; if (!string.IsNullOrEmpty(qTime.DefectCode)) { isDoDefect = true; } if (!string.IsNullOrEmpty(qTime.HoldStation)) { defectStation = qTime.HoldStation; defectStatus = (qTime.HoldStatus == QTimeStationStatusEnum.Fail ? TestLog.TestLogStatus.Fail : TestLog.TestLogStatus.Pass); isDoHoldStation = true; } } //執行QTime Action if (isDoDefect || isDoHoldStation) { if (this.ProcessType == ProcessTypeEnum.Product) { prod.UpdateStatus(new IMES.FisObject.FA.Product.ProductStatus() { Line = pdline, ProId = SN, TestFailCount = 0, ReworkCode = string.Empty, StationId = defectStation, Status = (defectStatus == TestLog.TestLogStatus.Fail ? StationStatus.Fail : StationStatus.Pass), Editor = this.Editor, Udt = now }); IList<IMES.DataModel.TbProductStatus> stationList = prodRep.GetProductStatus(new List<string> { prod.ProId }); prodRep.UpdateProductPreStationDefered(uow, stationList); #region write Productlog ProductLog productLog = new ProductLog { Model = prod.Model, Status = (defectStatus == TestLog.TestLogStatus.Fail ? StationStatus.Fail : StationStatus.Pass), Editor = this.Editor, Line = pdline, Station = defectStation, Cdt = now }; prod.AddLog(productLog); } else { MBStatus mbStatus= new MBStatus(SN, defectStation, (defectStatus == TestLog.TestLogStatus.Fail ? MBStatusEnum.Fail : MBStatusEnum.Pass), this.Editor, pdline, now, now); mb.MBStatus = mbStatus; IList<TbProductStatus> preStatusList = mbRep.GetMBStatus(new List<string>() { SN }); mbRep.UpdatePCBPreStationDefered(uow, preStatusList); #region Write MBlog var mbLog = new MBLog( 0, mb.Sn, mb.Model, defectStation, (defectStatus == TestLog.TestLogStatus.Fail ? 0 : 1), pdline, this.Editor, now); mb.AddLog(mbLog); #endregion } #endregion } //unpack Pizza part if (this.ProcessType == ProcessTypeEnum.Product && isDoHoldStation && defectStation == UnPizzaDefectStation) { utl.UnPack.unPackPizzaPart(session, uow, this.Editor); utl.UnPack.unPackPAKProductPart(session, uow, this.Editor); prodRep.DeleteProductPartByProductIDAndStationDefered(uow, new List<string>() { SN }, UnpackPizzaStationList, this.Editor); } if (isDoDefect) { #region add test log string actionName = qTime.Category.ToString() + QTIMEName; string errorCode = string.Empty; string descr = string.Format(DefectDescrFormat, preStation, this.Station, timeOut.ToString()); //"PreStation:"+preStation+ "~CurStation:"+this.Station +"~TimeOut:"+ timeOut.ToString(); //TestLog testLog = new TestLog(0, prod.ProId, this.Line, "", defectStation, defectStatus, "", this.Editor, "PRD", DateTime.Now); TestLog testLog = new TestLog(0, SN, pdline, string.Empty, defectStation, defectStatus, string.Empty, actionName, errorCode, descr, this.Editor, DefectType, now); if (this.ProcessType == ProcessTypeEnum.Product) { prod.AddTestLog(testLog); //add defect TestLogDefect defectItem = new TestLogDefect(0, 0, qTime.DefectCode, this.Editor, now); testLog.AddTestLogDefect(defectItem); } else { mb.AddTestLog(testLog); TestLogDefect defectItem = new TestLogDefect(0, 0, qTime.DefectCode, this.Editor, now); testLog.AddTestLogDefect(defectItem); } #endregion } if (isDoDefect || isDoHoldStation) { if (this.ProcessType == ProcessTypeEnum.Product) { prodRep.Update(prod, uow); } else { mbRep.Update(mb, uow); } uow.Commit(); if (qTime.Category == QTimeCategoryEnum.Min) { int diffTime = (timeOut - qTime.TimeOut) / 60; throw new FisException("CHK093", new string[] { diffTime.ToString() }); } else { throw new FisException("QTM001", new string[] { SN, qTime.Category.ToString() + QTIMEName, timeOut.ToString() }); } } //Min QTime Warning message nothing to do if (isTimeOut && qTime.Category == QTimeCategoryEnum.Min) { int diffTime = (timeOut - qTime.TimeOut) / 60; throw new FisException("CHK093", new string[]{diffTime.ToString()}); } } #endregion return base.DoExecute(executionContext); }
/// <summary> /// 记录到ProductTestLog,ProductTestLog_DefectInfo表 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { var prod = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); IProductRepository productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IList<string> defectList = (IList<string>)CurrentSession.GetValue(Session.SessionKeys.DefectList); //Dean 20110625 string AllowPass = ""; string DefectStation = ""; string InsertStation = ""; if (CurrentSession.GetValue(ExtendSession.SessionKeys.AllowPass) != null) { AllowPass = (string)CurrentSession.GetValue(ExtendSession.SessionKeys.AllowPass); } if (CurrentSession.GetValue(ExtendSession.SessionKeys.DefectStation) != null) { DefectStation = (string)CurrentSession.GetValue(ExtendSession.SessionKeys.DefectStation); } //Dean 20110625 string line = this.Line; if (string.IsNullOrEmpty(line)) { line = prod.Status.Line; } TestLog.TestLogStatus status = TestLog.TestLogStatus.Fail; if (IsPass) { status = TestLog.TestLogStatus.Pass; } if (AllowPass == "N")//Check AllowPass =N Dean 20110625 { InsertStation = DefectStation; } else //Normal Flow { InsertStation = this.Station; } TestLog tItem = new TestLog(0, prod.ProId, line, "", InsertStation, status, "", this.Editor, "PRD", DateTime.Now);//Dean 20110625 this.Station==>InsertStation prod.AddTestLog(tItem); if (defectList != null) { foreach (string item in defectList) { //add defect TestLogDefect defectItem = new TestLogDefect(0, 0, item, this.Editor, DateTime.Now); tItem.AddTestLogDefect(defectItem); } } productRepository.Update(prod, CurrentSession.UnitOfWork); return base.DoExecute(executionContext); }