public ReturnValueInfo AddScheduleProject(ScheduleProjList_swl_Info data) { throw new NotImplementedException(); //ReturnValueInfo result = new ReturnValueInfo(); //try //{ // data.swl_RecordID = Guid.NewGuid(); // if (mScheduleProjectSqliteDA.Insert(data).boolValue) // { // result.boolValue = true; // result.ValueObject = data.swl_RecordID; // } // else // { // result.boolValue = false; // result.messageText = Resource.B0011; // } // return result; //} //catch (Exception ex) //{ // Common.General.BLLoger.Error(ex); // result.messageText = ex.Message; // result.ValueObject = ex; // result.isError = true; //} //return result; }
/// <summary> /// 1,savetoDBInterval等於0時,才將數據寫入數據庫,部分時間才重新計算 /// </summary> /// <param name="uow"></param> /// <param name="schProj"></param> /// <param name="printProj"></param> /// <param name="shiftProject"></param> /// <param name="data"></param> /// <param name="savetoDBInterval"></param> /// <returns></returns> public bool Producing(DBContext uow, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, PLCData_pda_Info data, int savetoDBInterval) { try { if (printProj.ppj_iSpeed > data.pda_iProductionSpeed * 60 && data.pda_iMachineSpeed != 0) { schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_SLOW.ToString(); } else { schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_IN.ToString(); } #region 更新生產工程信息 if (printProj != null) { DateTime dealtime = DateTime.Now; if (savetoDBInterval == 0) { var dinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == schProj.swl_RecordID); dinnerQuery.And(d => d.dsm_ppjID == printProj.ppj_RecordID); int dinnerTime = (int)dinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); printProj.ppj_iProdSumTime = printProj.ppj_iProjRunTime - printProj.ppj_iActualPrepairTime - printProj.ppj_iStopTime - printProj.ppj_iQCSumTime - dinnerTime; } printProj.ppj_iActualProdNum += data.pad_iQty - printProj.ppj_iCountProdNum; printProj.ppj_iCountProdNum = data.pad_iQty; printProj.ppj_fProdSpeed = data.pda_iProductionSpeed; printProj.ppj_fMachineSpeed = data.pda_iMachineSpeed; printProj.ppj_dLastDate = dealtime; if (printProj.ppj_dProdBeginTime == null) { printProj.ppj_dProdBeginTime = dealtime; } if (savetoDBInterval == 0) { uow.CurrentSession.Update(printProj); } #region 更新班次內工程信息 ///增加數量 int diffQTY = shiftProject.spl_iCalQTY - shiftProject.spl_iQTY; if (shiftProject.spl_iBeginQTY == 0 && shiftProject.spl_iCalQTY == 0) { shiftProject.spl_iBeginQTY = 0; shiftProject.spl_iQTY = 0; } shiftProject.spl_iEndQTY = data.pad_iQty; shiftProject.spl_iCalQTY = shiftProject.spl_iEndQTY - shiftProject.spl_iBeginQTY; shiftProject.spl_iQTY = shiftProject.spl_iCalQTY - diffQTY; shiftProject.spl_dLastDate = dealtime; if (shiftProject.spl_dProdBegin == null) { shiftProject.spl_dProdBegin = dealtime; } if (savetoDBInterval == 0) { var splDinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == schProj.swl_RecordID); splDinnerQuery.And(d => d.dsm_splID == shiftProject.spl_RecordID); int splDinnerTime = (int)splDinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); shiftProject.spl_iProdSumTime = shiftProject.spl_iRunTime - shiftProject.spl_iPrepairTime - shiftProject.spl_iStopTime - shiftProject.spl_iQCTime - splDinnerTime; uow.CurrentSession.Update(shiftProject); } #endregion } #endregion return true; } catch (Exception ex) { uow.CanCommit = false; mLog.Error("PLCBL.Producing" + ex); return false; } }
/// <summary> /// 生產中停機超時 /// </summary> /// <param name="uow"></param> /// <param name="schProj"></param> /// <param name="printProj"></param> /// <param name="shiftProject"></param> /// <param name="stopRecord"></param> /// <returns></returns> public bool ProduceStop2Long(DBContext uow, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, ProjectStopRecord_psrd_Info stopRecord) { try { int actualStopTime = (int)(DateTime.Now - stopRecord.psrd_dBeginTime.Value).TotalSeconds; if (actualStopTime > stopRecord.psrd_iPredictStopTime) { #region 更新印刷工程信息 schProj.swl_iIsByModify = true; schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_STOP_OT.ToString(); schProj.swl_dStatusChange = DateTime.Now; schProj.swl_dLastDate = DateTime.Now; uow.CurrentSession.Update(uow.CurrentSession.Merge(schProj)); #endregion } return true; } catch (Exception ex) { uow.CanCommit = false; mLog.Error("PLCBL.ProduceStop2Long" + ex); return false; } }
/// <summary> /// 生產中停機 /// </summary> /// <param name="uow"></param> /// <param name="schProj"></param> /// <param name="printProj"></param> /// <param name="shiftProject"></param> /// <param name="data"></param> /// <returns></returns> public bool ProduceStop(DBContext uow, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, PLCData_pda_Info data) { try { #region 停機記錄 ProjectStopRecord_psrd_Info psrd = new ProjectStopRecord_psrd_Info(); psrd.psrd_RecordID = Guid.NewGuid(); psrd.psrd_PPJID = shiftProject.spl_PPJID; psrd.psrd_SPLID = shiftProject.spl_RecordID; psrd.psrd_dBeginTime = schProj.PROD_STOP_Datetime; psrd.psrd_dAddDate = DateTime.Now; psrd.psrd_dLastDate = DateTime.Now; psrd.psrd_cTypeID = CustEnum.RecordType.NORMAL.ToString(); psrd.psrd_iPredictStopTime = 0; psrd.psrd_lSync = false; uow.CurrentSession.Save(psrd); #endregion #region 更新印刷工程信息 schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_STOP.ToString(); schProj.swl_dStatusChange = DateTime.Now; schProj.swl_dLastDate = DateTime.Now; schProj.swl_iIsByModify = true; uow.CurrentSession.Update(schProj); #endregion #region 生产工程 printProj.ppj_fMachineSpeed = data.pda_iMachineSpeed; printProj.ppj_iStopTimes += 1; uow.CurrentSession.Update(printProj); #endregion #region 班次內工程 shiftProject.spl_iStopTimes += 1; uow.CurrentSession.Update(shiftProject); #endregion #region 用餐記錄 //工程在生產中進入就餐,但由於工程進入生產中停機狀態有一定時間的約定延遲,如果超過這個時間,進入停機狀態,需要更新就餐時工程的狀態 var dinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == schProj.swl_RecordID); dinnerQuery.And(d => d.dsm_ppjID == printProj.ppj_RecordID); dinnerQuery.And(d => d.dsm_splID == shiftProject.spl_RecordID); dinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PROD_IN.ToString()); dinnerQuery = dinnerQuery.OrderBy(d => d.dnr_dBeginTime).Desc; var listDinner = dinnerQuery.And(d => d.dnr_DSMID != null).List(); if (listDinner.Count > 0) { DinnerRecord_dnr_Info dnr = listDinner[0]; if (dnr.dnr_dBeginTime >= psrd.psrd_dBeginTime)//用餐開始時間在停機開始時間之後,因此需要將用餐記錄的工程狀態更新為“PROD_STOP”,並更新停機記錄ID { dnr.dsm_cProjectStatus = CustEnum.ProjectStatus.PROD_STOP.ToString(); dnr.dsm_psrdID = psrd.psrd_RecordID; dnr.dnr_dLastDate = DateTime.Now; uow.CurrentSession.Update(dnr); } } #endregion return true; } catch (Exception ex) { uow.CanCommit = false; mLog.Error("PLCBL.ProduceStop" + ex); return false; } }
/// <summary> /// 重新開始生產,狀態改變規則:生產中停機-->生產中 /// </summary> /// <param name="uow"></param> /// <param name="schProj"></param> /// <param name="printProj"></param> /// <param name="shiftProject"></param> /// <param name="data"></param> /// <returns></returns> public bool ProduceRestart(DBContext uow, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, PLCData_pda_Info data) { try { #region 更新印刷工程信息 schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_IN.ToString(); schProj.swl_dStatusChange = DateTime.Now; schProj.swl_dLastDate = DateTime.Now; schProj.swl_iIsByModify = true; uow.CurrentSession.Update(schProj); #endregion #region 更新生產中停機的結束時間 ProjectStopRecord_psrd_Info psrd_old; var query = uow.CurrentSession.QueryOver<ProjectStopRecord_psrd_Info>(); query.And(d => d.psrd_SPLID == shiftProject.spl_RecordID); query.And(d => d.psrd_dEndTime == null); query.And(d => d.psrd_cTypeID == CustEnum.RecordType.NORMAL.ToString()); IList<ProjectStopRecord_psrd_Info> list = query.List<ProjectStopRecord_psrd_Info>(); if (list.Count > 0) { psrd_old = list[0]; psrd_old.psrd_dEndTime = DateTime.Now; psrd_old.psrd_dLastDate = DateTime.Now; //停機就餐時間 var stopDinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_ppjID == printProj.ppj_RecordID); stopDinnerQuery.And(d => d.dsm_splID == shiftProject.spl_RecordID); stopDinnerQuery.And(d => d.dsm_psrdID == psrd_old.psrd_RecordID); stopDinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PROD_STOP.ToString() || d.dsm_cProjectStatus == CustEnum.ProjectStatus.PROD_STOP_OT.ToString()); int stopDinnerTime = (int)stopDinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); psrd_old.psrd_iActualStopTime = (int)(psrd_old.psrd_dEndTime.Value - psrd_old.psrd_dBeginTime.Value).TotalSeconds - stopDinnerTime; uow.CurrentSession.Update(psrd_old); printProj.ppj_fMachineSpeed = data.pda_iMachineSpeed; printProj.ppj_iStopTime += psrd_old.psrd_iActualStopTime; //實際準備時間=生產結束時間-工程開始時間-就餐時間 // printProj.ppj_iActualPrepairTime = (int)(printProj.ppj_dProdBeginTime.Value - printProj.ppj_dProjBeginTime).TotalSeconds - stopDinnerTime; printProj.ppj_iProdSumTime = printProj.ppj_iProjRunTime - printProj.ppj_iStopTime - printProj.ppj_iActualPrepairTime - printProj.ppj_iQCSumTime - stopDinnerTime; uow.CurrentSession.Update(printProj); shiftProject.spl_iStopTime += psrd_old.psrd_iActualStopTime; //int totalPrepare; //if (shiftProject.spl_dProdBegin.HasValue) //{ // totalPrepare = (int)(shiftProject.spl_dProdBegin.Value - shiftProject.spl_dBeginTime).TotalSeconds; //} //else //{ // totalPrepare = (int)(shiftProject.spl_dEndTime.Value - shiftProject.spl_dBeginTime).TotalSeconds; //} //shiftProject.spl_iPrepairTime = totalPrepare - stopDinnerTime; shiftProject.spl_iProdSumTime = shiftProject.spl_iRunTime - shiftProject.spl_iPrepairTime - shiftProject.spl_iQCTime - shiftProject.spl_iStopTime - stopDinnerTime; uow.CurrentSession.Update(shiftProject); } #endregion return true; } catch (Exception ex) { uow.CanCommit = false; mLog.Error("PLCBL.ProduceRestart" + ex); return false; } }
/// <summary> /// 創建人:JustinLeung /// 描述:保存工程的準備工作項目,工程狀態由“準備中”轉換為“生產中” /// </summary> /// <param name="projectDetail"></param> /// <returns></returns> public ReturnValueInfo UpdateProjPreJobItem(ScheduleProjList_swl_Info project, ShiftProjList_spl_Info shiftProject, PrintProject_ppj_Info projectDetail) { ReturnValueInfo result = new ReturnValueInfo(); try { if (projectDetail.PrepareJobItems == null) { result.boolValue = false; result.messageText = "工程準備工作項目數據不存在。"; } else { DateTime dtDeal = DateTime.Now; using (DBContext uow = DBContext.Begin()) { try { uow.CurrentSession.CreateQuery("delete from ProjectPreJobItem_ppji_Info d where d.ppji_PPJID = ?").SetString(0, projectDetail.ppj_RecordID.ToString()).ExecuteUpdate(); projectDetail.ppj_iPredictPrepairTime = 0; foreach (var ppji in projectDetail.PrepareJobItems) { ppji.ppji_RecordID = Guid.NewGuid(); ppji.ppji_PPJID = projectDetail.ppj_RecordID; ppji.ppji_dLastDate = ppji.ppji_dAddDate = dtDeal; uow.CurrentSession.Save(ppji); PrepareProjectMaster_ppm_Info item = uow.CurrentSession.Get<PrepareProjectMaster_ppm_Info>(ppji.ppji_PPMID); if (!item.ppm_lIsParallelable) { projectDetail.ppj_iPredictPrepairTime += (int)(item.ppm_iPredictedTime * 60); } } projectDetail.ppj_dProdBeginTime = dtDeal; //就餐時間 var dinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_ppjID == projectDetail.ppj_RecordID); dinnerQuery.And(d => d.dsm_splID == shiftProject.spl_RecordID); dinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PREPARE.ToString() || d.dsm_cProjectStatus == CustEnum.ProjectStatus.PREPARE_OT.ToString()); int dinnerTime = (int)dinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); //實際準備時間=生產結束時間-工程開始時間-就餐時間 projectDetail.ppj_iActualPrepairTime = (int)(projectDetail.ppj_dProdBeginTime.Value - projectDetail.ppj_dProjBeginTime).TotalSeconds - dinnerTime; projectDetail.ppj_iProdSumTime = projectDetail.ppj_iProjRunTime - projectDetail.ppj_iStopTime - projectDetail.ppj_iActualPrepairTime - dinnerTime; projectDetail.ppj_dLastDate = dtDeal; uow.CurrentSession.Update(projectDetail); shiftProject.spl_dProdBegin = dtDeal; shiftProject.spl_dLastDate = dtDeal; int totalPrepare; if (shiftProject.spl_dProdBegin.HasValue) { totalPrepare = (int)(shiftProject.spl_dProdBegin.Value - shiftProject.spl_dBeginTime).TotalSeconds; } else { totalPrepare = (int)(shiftProject.spl_dEndTime.Value - shiftProject.spl_dBeginTime).TotalSeconds; } shiftProject.spl_iPrepairTime = totalPrepare - dinnerTime; shiftProject.spl_iProdSumTime = shiftProject.spl_iRunTime - shiftProject.spl_iPrepairTime - shiftProject.spl_iStopTime - dinnerTime; uow.CurrentSession.Update(shiftProject); if (projectDetail.ScheduleProject != null) { project.swl_cProjStatus = Common.CustEnum.ProjectStatus.PROD_IN.ToString(); project.swl_dLastDate = dtDeal; project.swl_dStatusChange = dtDeal; uow.CurrentSession.Update(project); } } catch (Exception) { uow.CanCommit = false; throw; } } } result.boolValue = true; } catch (Exception ex) { Common.General.BLLoger.Error(ex); result.boolValue = false; result.messageText = ex.Message; } return result; }
public List<ScheduleProjList_swl_Info> Search(int pageIndex, int pageSize, string orderby, ScheduleProjList_swl_Info cond, bool fuzzy) { throw new NotImplementedException(); }
/// <summary> /// 根據PLC返回數據,分析判斷幾臺狀態 /// </summary> /// <param name="data"></param> /// <returns></returns> private CustEnum.MachineStatus AnalysisStatus(ScheduleProjList_swl_Info schProj, PLCData_pda_Info data) { if (data.pda_lRunning) { schProj.PROD_STOP_Datetime = null; return CustEnum.MachineStatus.MACHINE_PRODUCTION; } else { if (!schProj.PROD_STOP_Datetime.HasValue) { schProj.PROD_STOP_Datetime = DateTime.Now; } return CustEnum.MachineStatus.MACHINE_SHUTDOWN; } }
public List<ScheduleProjList_swl_Info> GetScheProjList(ScheduleProjList_swl_Info cond) { try { string stopMachine = cond.swl_cMachineNO;//用於抽起的工程查詢 //查詢計劃幾台的工程 cond.swl_cProjStatus = CustEnum.ProjectStatus.SCHEDULE.ToString(); cond.swl_cMachineNO = string.Empty; List<ScheduleProjList_swl_Info> list_swl = mScheduleProjectSqliteDA.Search(10, 0, "swl_iProductionSeq", cond, true); //查詢實際幾台的抽起工程 cond.swl_cProjStatus = CustEnum.ProjectStatus.STOP.ToString(); cond.swl_cPlanMachineNO = string.Empty; cond.swl_cMachineNO = stopMachine; List<ScheduleProjList_swl_Info> list_stop = mScheduleProjectSqliteDA.Search(10, 0, "swl_iProductionSeq", cond, true); list_swl.AddRange(list_stop); return list_swl.OrderBy(d => d.swl_iProductionSeq).ToList(); } catch (Exception ex) { throw new Exception(Resource.B0003 + ex.Message); } }
public ReturnValueInfo FinishProject(ScheduleProjList_swl_Info project, PrintProject_ppj_Info projectDetail, ShiftProjList_spl_Info shiftProject) { //DateTime start = DateTime.Now; ReturnValueInfo result = new ReturnValueInfo(); try { using (DBContext uow = DBContext.Begin()) { try { DateTime dealTime = DateTime.Now; #region 更新前一個停機記錄的結束時間 var stopRec = uow.CurrentSession.QueryOver<ProjectStopRecord_psrd_Info>(); stopRec.And(d => d.psrd_dEndTime == null).And(d => d.psrd_SPLID == shiftProject.spl_RecordID).OrderBy(d => d.psrd_dBeginTime).Desc(); ProjectStopRecord_psrd_Info psrd = stopRec.Take(1).SingleOrDefault(); if (psrd != null) { psrd.psrd_dLastDate = dealTime; psrd.psrd_dEndTime = dealTime; psrd.psrd_iActualStopTime = TimeCalculater.ProjectStopRecordActualTime(uow, psrd); uow.CurrentSession.Update(psrd); projectDetail.ppj_iStopTime += psrd.psrd_iActualStopTime; shiftProject.spl_iStopTime += psrd.psrd_iActualStopTime; } #endregion #region 更新班次內工程 /// 更新班次內工程結束時間 if (project.swl_cProjStatus == CustEnum.ProjectStatus.PREPARE.ToString() || project.swl_cProjStatus == CustEnum.ProjectStatus.PREPARE_OT.ToString()) { shiftProject.spl_dProdBegin = dealTime; } shiftProject.spl_dEndTime = shiftProject.spl_dLastDate = dealTime; /// 準備時間計算 int totalPrepare = (int)(shiftProject.spl_dProdBegin.Value - shiftProject.spl_dBeginTime).TotalSeconds; shiftProject.spl_iPrepairTime = totalPrepare; /// 計算生產時間 shiftProject.spl_iProdSumTime = TimeCalculater.ShiftProjectProdTime(uow, shiftProject); uow.CurrentSession.Update(shiftProject); #endregion #region PPJ if (project.swl_cProjStatus == CustEnum.ProjectStatus.PREPARE.ToString() || project.swl_cProjStatus == CustEnum.ProjectStatus.PREPARE_OT.ToString()) { projectDetail.ppj_dProdBeginTime = dealTime; } projectDetail.ppj_dProdEndTime = dealTime; ///計算生產時間 projectDetail.ppj_iProdSumTime = TimeCalculater.PrintProjectProdTime(uow, projectDetail); uow.CurrentSession.Update(projectDetail); #endregion #region SWL project.swl_iCompletedQty += projectDetail.ppj_iActualProdNum; project.swl_cProjStatus = CustEnum.ProjectStatus.FINISH.ToString(); project.swl_dLastDate = dealTime; project.swl_iIsByModify = true; uow.CurrentSession.Update(project); #endregion #region 班次進入空閒狀態 SpareStatus_sst_Info info_new = new SpareStatus_sst_Info(); info_new.sst_RecordID = Guid.NewGuid(); info_new.sst_iSIFOID = shiftProject.spl_SIFOID; info_new.sst_dBeginTime = dealTime; info_new.sst_dAddDate = dealTime; info_new.sst_cMachineNO = project.swl_cMachineNO; IdleState_ism_Info ism = uow.CurrentSession.QueryOver<IdleState_ism_Info>().And(d => d.ism_lIsBuildin && d.ism_lIsAtive).Take(1).SingleOrDefault(); if (ism != null) { info_new.sst_cStatusName = ism.ism_cStateName; info_new.sst_StatusID = ism.ism_RecordID; } uow.CurrentSession.Save(info_new); #endregion result.boolValue = true; } catch (Exception) { uow.CanCommit = false; throw; } } } catch (Exception ex) { string message = "結束工程出錯,machineID=" + project.swl_cMachineNO; message += "ScheduleProjList_swl_Info=" + Common.Util.JsonUtil.JsonSerializer<ScheduleProjList_swl_Info>(project); message += "PrintProject_ppj_Info=" + Common.Util.JsonUtil.JsonSerializer<PrintProject_ppj_Info>(projectDetail); message += "ShiftProjList_spl_Info=" + Common.Util.JsonUtil.JsonSerializer<ShiftProjList_spl_Info>(shiftProject); Common.Util.MessageUtil.SendDevMail(message, ex); result.messageText = ex.Message; result.boolValue = false; throw new Exception(Resource.B0023 + ex.Message); } // DateTime end = DateTime.Now; // Common.General.BLLoger.Debug("結束工程,耗時" + (end - start).Milliseconds.ToString()); return result; }
public ReturnValueInfo CreateProdutionProject(ShiftInfo_sifo_Info shift, ScheduleProjList_swl_Info swl) { ReturnValueInfo result = new ReturnValueInfo(); try { using (DBContext uow = DBContext.Begin()) { try { swl.swl_cProjStatus = CustEnum.ProjectStatus.PREPARE.ToString(); #region 生成印刷工程數據 PrintProject_ppj_Info ppj = new PrintProject_ppj_Info(); ppj.ppj_RecordID = Guid.NewGuid(); ppj.ppj_SWLID = swl.swl_RecordID; //工程狀態轉換為準備中,設置工程開始時間為當前時間 ppj.ppj_dProjBeginTime = DateTime.Now; ppj.ppj_dLastDate = ppj.ppj_dAddDate = DateTime.Now; ppj.ppj_lActiveRecord = true; ppj.ppj_lSync = false; ppj.ppj_cRank = ""; #region 設置默認值 IList<CodeMaster_cmt_Info> cmts = uow.CurrentSession.QueryOver<CodeMaster_cmt_Info>().Where(d => d.cmt_cKey1 == CustEnum.KEY1.TYPEVALUE.ToString() && d.cmt_cKey2 == CustEnum.KEY2.DEFAULT.ToString() && d.cmt_cValue == CustEnum.DEFALUT.PERTIMEQTY.ToString()).List<CodeMaster_cmt_Info>(); if (cmts.Count == 1) { ppj.ppj_iPertimeProdNum = (int)cmts[0].cmt_fNumber; } //cmts = uow.CurrentSession.QueryOver<CodeMaster_cmt_Info>().Where(d => d.cmt_cKey1 == CustEnum.KEY1.TYPEVALUE.ToString() && d.cmt_cKey2 == CustEnum.KEY2.DEFAULT.ToString() && d.cmt_cValue == CustEnum.DEFALUT.PRODUTIONSPEED.ToString()).List<CodeMaster_cmt_Info>(); //if (cmts.Count == 1) //{ // ppj.ppj_iSpeed = (int)cmts[0].cmt_fNumber; //} IList<MachineMaster_mmt_Info> machineInfo = uow.CurrentSession.QueryOver<MachineMaster_mmt_Info>().Where(d => d.mmt_cMachineID == swl.swl_cMachineNO).List<MachineMaster_mmt_Info>(); if (machineInfo.Count == 1) { int produceSpeed = 0; int.TryParse(machineInfo[0].mmt_cModel, out produceSpeed);//由於數據庫暫時沒有目標車速的欄位,GISS用機台型號錄入數值代替 ppj.ppj_iSpeed = produceSpeed; } cmts = uow.CurrentSession.QueryOver<CodeMaster_cmt_Info>().Where(d => d.cmt_cKey1 == CustEnum.KEY1.TYPEVALUE.ToString() && d.cmt_cKey2 == CustEnum.KEY2.DEFAULT.ToString() && d.cmt_cValue == CustEnum.DEFALUT.QCINTERVAL.ToString()).List<CodeMaster_cmt_Info>(); if (cmts.Count == 1) { ppj.ppj_iQCInterval = (int)cmts[0].cmt_fNumber; } else { ppj.ppj_iQCInterval = 30; } cmts = uow.CurrentSession.QueryOver<CodeMaster_cmt_Info>().Where(d => d.cmt_cKey1 == CustEnum.KEY1.TYPEVALUE.ToString() && d.cmt_cKey2 == CustEnum.KEY2.DEFAULT.ToString() && d.cmt_cValue == CustEnum.DEFALUT.PROD_STOP_COND.ToString()).List<CodeMaster_cmt_Info>(); if (cmts.Count == 1) { swl.PROD_STOP_COND = (int)cmts[0].cmt_fNumber; } else { swl.PROD_STOP_COND = 8; } #endregion #endregion #region 工程附件信息 ProjectAdditionalInformation_pai_Info paiInfo = new ProjectAdditionalInformation_pai_Info(); paiInfo.pai_PPJRecordID = ppj.ppj_RecordID; paiInfo.pai_iFrontProcessDefectiveQty = 0; paiInfo.pai_iFrontProcessWasteQty = 0; paiInfo.pai_iGoldPaperTimes = 0; paiInfo.pai_iRevolution = 0; paiInfo.pai_iTemperature = 0; paiInfo.pai_cUnit = string.Empty; paiInfo.pai_iUnitLength = 0; paiInfo.pai_iUVLuminosity = 0; paiInfo.pai_iUnitWidth = 0; uow.CurrentSession.Save(paiInfo); ppj.AdditionalInformation = paiInfo; #endregion #region 生成印刷工程準備工作項 //IProjectPreJobItemDA projectPreJodItemDA = DAL.Factory.HBPMS.SQLiteDAFacotry.GetDAL<IProjectPreJobItemDA>(DAL.Factory.HBPMS.SQLiteDAFacotry.ProjectPreJodItemDA); //prol.PrepareJobItems = new List<ProjectPreJobItem_ppji_Info>(); #endregion #region 班次內工程 ShiftProjList_spl_Info shiftProject = new ShiftProjList_spl_Info(); shiftProject.spl_RecordID = Guid.NewGuid(); shiftProject.spl_SIFOID = shift.sifo_RecordID; shiftProject.spl_PPJID = ppj.ppj_RecordID; shiftProject.spl_dBeginTime = ppj.ppj_dProjBeginTime; shiftProject.spl_lSync = false; shiftProject.spl_dLastDate = shiftProject.spl_dAddDate = DateTime.Now; uow.CurrentSession.Save(shiftProject); #endregion #region 班次空閒狀態結束 SpareStatus_sst_Info info = uow.CurrentSession.QueryOver<SpareStatus_sst_Info>().And(d => d.sst_iSIFOID == shift.sifo_RecordID).And(d => d.sst_dEndTime == null).Take(1).SingleOrDefault(); if (info != null) { info.sst_dEndTime = DateTime.Now; info.sst_dLastDate = DateTime.Now; if (info.sst_StatusID == Guid.Empty) { IdleState_ism_Info ism = uow.CurrentSession.QueryOver<IdleState_ism_Info>().And(d => d.ism_lIsBuildin && d.ism_lIsAtive).Take(1).SingleOrDefault(); if (ism != null) { info.sst_cStatusName = ism.ism_cStateName; info.sst_StatusID = ism.ism_RecordID; } } var dinnerTime = (int)uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_sstID == info.sst_RecordID).And(d => d.dnr_dEndTime != null).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); if (info.sst_dEndTime.HasValue) { info.sst_iTime = (int)(info.sst_dEndTime.Value - info.sst_dBeginTime.Value).TotalSeconds - dinnerTime; } uow.CurrentSession.Update(info); } #endregion ppj.ShiftProjects = new List<ShiftProjList_spl_Info>(); ppj.ShiftProjects.Add(shiftProject); result.ValueObject = ppj; uow.CurrentSession.Save(ppj); uow.CurrentSession.Update(swl); } catch (Exception) { uow.CanCommit = false; throw; } } result.boolValue = true; } catch (Exception ex) { Common.General.BLLoger.Debug("call ProjectPPCBL.CreateProdutionProject", ex); result.boolValue = false; result.ValueObject = ex; result.messageText = ex.Message; } return result; }
public ReturnValueInfo CloseProject(ScheduleProjList_swl_Info project) { throw new NotImplementedException(); //ReturnValueInfo result = new ReturnValueInfo(); //try //{ // ScheduleProjList_swl_Info swl_local = mScheduleProjectSqliteDA.GetEntity<ScheduleProjList_swl_Info>(project.swl_RecordID); // swl_local.swl_cProjStatus = CustEnum.ProjectStatus.FINISH.ToString(); // swl_local.swl_lSync = true; // swl_local.swl_dLastDate = DateTime.Now; // swl_local.swl_dStatusChange = DateTime.Now; // swl_local.swl_cRemark = "PPC程式自動關閉此工程"; // result = mScheduleProjectSqliteDA.Update(swl_local); //} //catch (Exception ex) //{ // //throw; // result.isError = true; // result.messageText = ex.Message; // result.boolValue = false; //} //return result; }
public ReturnValueInfo UpdateScheduleProject(ScheduleProjList_swl_Info data) { ReturnValueInfo result = new ReturnValueInfo(); //if (mScheduleProjectSqliteDA.Update(data).boolValue) //{ // result.boolValue = true; //} //else //{ // result.boolValue = false; // result.messageText = Resource.B0012; //} return result; }
public CustEnum.ProductionStatus SaveData(CustEnum.ProductionStatus prodStatus, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, PLCData_pda_Info data, int savetoDBInterval) { DateTime start = DateTime.Now; ///工程生產狀態 CustEnum.ProductionStatus status; try { //暫時關閉這項功能,由於可能存在性能問題 //IPLCDataDA plcda = SQLiteDAFacotry.GetDAL<IPLCDataDA>(SQLiteDAFacotry.PLCDataDAL); //if (data != null && data.SaveToDB) //{ // //選擇工程後開始記錄機台PLC數據 // plcda.Insert(data); //} ///根據PLC返回數據,分析判斷機台狀態 CustEnum.MachineStatus mstatus = AnalysisStatus(schProj, data); using (DBContext uow = DBContext.Begin()) { // 根據印刷工程狀態 與 機台狀態,得出印刷工程生產狀態 status = AnalysisProdStatus(uow, mstatus, prodStatus, schProj, printProj, shiftProject); //Common.General.BLLoger.Debug("工程生產狀態--->" + status.ToString()); #region //生產開始 switch (status) { case CustEnum.ProductionStatus.PRO_PREPARE: //#region 更新印刷工程信息 //if (printProj.ppj_iPredictPrepairTime > 0) //{ // if (printProj.ppj_iActualPrepairTime > printProj.ppj_iPredictPrepairTime) // { // schProj.swl_cProjStatus = CustEnum.ProjectStatus.PREPARE_OT.ToString(); // schProj.swl_dStatusChange = DateTime.Now; // schProj.swl_dLastDate = DateTime.Now; // uow.CurrentSession.Update(uow.CurrentSession.Merge(schProj)); // } //} //#endregion break; case CustEnum.ProductionStatus.PROD_BEGIN: if (status != prodStatus) //狀態改變 { ProduceBegin(uow, schProj, printProj, shiftProject, data); } break; //生產中 case CustEnum.ProductionStatus.PROD_IN: Producing(uow, schProj, printProj, shiftProject, data, savetoDBInterval); break; //生產中停機 case CustEnum.ProductionStatus.PROD_STOP: #region 記錄生產中停機信息 if (prodStatus != status) //狀態改變 { ProduceStop(uow, schProj, printProj, shiftProject, data); } else { //判斷是否停機超時 IList<ProjectStopRecord_psrd_Info> psrd = uow.CurrentSession.QueryOver<ProjectStopRecord_psrd_Info>().And(d => d.psrd_PPJID == printProj.ppj_RecordID).And(d => d.psrd_dEndTime == null).OrderBy(d => d.psrd_dBeginTime).Desc.List(); if (psrd.Count > 0 && psrd[0].psrd_iPredictStopTime > 0) { ProduceStop2Long(uow, schProj, printProj, shiftProject, psrd[0]); for (int index = 1; index < psrd.Count; index++) { psrd[index].psrd_dEndTime = DateTime.Now; uow.CurrentSession.Update(psrd[index]); } } } #endregion break; //生產繼續 case CustEnum.ProductionStatus.PROD_RESART: ProduceRestart(uow, schProj, printProj, shiftProject, data); break; default: break; } #endregion } } catch (Exception ex) { Common.General.BLLoger.Debug(ex); throw new Exception(Resource.B0022); } DateTime end = DateTime.Now; if (savetoDBInterval == 0) { mLog.Debug("保存工程數據到數據庫,耗時" + (end - start).Milliseconds.ToString()); } else { //mLog.Debug("不保存工程數據到數據庫,耗時" + (end - start).Milliseconds.ToString()); } return status; }
public ReturnValueInfo CheckProjectStatus(ScheduleProjList_swl_Info project) { throw new NotImplementedException(); //ReturnValueInfo result = new ReturnValueInfo(); //try //{ // IScheduleProjListDA scheduleProjectSQLDA = BLL.Base.DataAccessMoudule.Sqlserver.Get<IScheduleProjListDA>(); // ScheduleProjList_swl_Info swl_server = scheduleProjectSQLDA.GetEntity<ScheduleProjList_swl_Info>(project.swl_RecordID); // if (swl_server != null) // { // ScheduleProjList_swl_Info swl_local = mScheduleProjectSqliteDA.GetEntity<ScheduleProjList_swl_Info>(project.swl_RecordID); // if (swl_server.swl_cProjStatus == CustEnum.ProjectStatus.FINISH.ToString() && swl_server.swl_cProjStatus != swl_local.swl_cProjStatus) // { // result.boolValue = false; // } // else // { // result.boolValue = true; // } // } // else // { // result.boolValue = false; // } //} //catch (Exception ex) //{ // result.boolValue = true; // result.messageText = ex.Message; // Common.General.BLLoger.Error(ex); // // throw; //} //return result; }
/// <summary> /// 分析工程生產狀態 /// </summary> /// <param name="machineStatus"></param> /// <param name="oldStatus"></param> /// <param name="schProj"></param> /// <returns></returns> private CustEnum.ProductionStatus AnalysisProdStatus(DBContext uow, CustEnum.MachineStatus machineStatus, CustEnum.ProductionStatus oldStatus, ScheduleProjList_swl_Info project, PrintProject_ppj_Info ppj, ShiftProjList_spl_Info spl) { CustEnum.ProductionStatus newStatus = CustEnum.ProductionStatus.STOP; if (project != null && (project.swl_cProjStatus == CustEnum.ProjectStatus.PREPARE.ToString() || project.swl_cProjStatus == CustEnum.ProjectStatus.PREPARE_OT.ToString())) { if (machineStatus == CustEnum.MachineStatus.MACHINE_PRODUCTION)//開始生產 { newStatus = CustEnum.ProductionStatus.PROD_BEGIN; } else if (machineStatus == CustEnum.MachineStatus.MACHINE_SHUTDOWN) { newStatus = CustEnum.ProductionStatus.PRO_PREPARE; } } else if (project != null && (project.swl_cProjStatus == CustEnum.ProjectStatus.PROD_IN.ToString() || project.swl_cProjStatus == CustEnum.ProjectStatus.PROD_SLOW.ToString() || project.swl_cProjStatus == CustEnum.ProjectStatus.PROD_STOP.ToString() || project.swl_cProjStatus == CustEnum.ProjectStatus.PROD_STOP_OT.ToString())) { if (machineStatus == CustEnum.MachineStatus.MACHINE_PRODUCTION)//開機 { if (oldStatus == CustEnum.ProductionStatus.PROD_STOP) { newStatus = CustEnum.ProductionStatus.PROD_RESART;//生產繼續 } else { newStatus = CustEnum.ProductionStatus.PROD_IN;//生產中 } } else if (machineStatus == CustEnum.MachineStatus.MACHINE_SHUTDOWN)//停機 { if (oldStatus == CustEnum.ProductionStatus.PROD_IN || project.swl_cProjStatus == CustEnum.ProjectStatus.PROD_SLOW.ToString()) { int totalTimes = (int)(DateTime.Now - project.PROD_STOP_Datetime.Value).TotalSeconds;//已經停機的時間 #region 停機期間是否存在用餐記錄 var dinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == project.swl_RecordID); dinnerQuery.And(d => d.dsm_ppjID == ppj.ppj_RecordID); dinnerQuery.And(d => d.dsm_splID == spl.spl_RecordID); dinnerQuery.And(d => d.dnr_dEndTime > project.PROD_STOP_Datetime);//停機在就餐結束前發生 dinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PROD_IN.ToString()); dinnerQuery.And(d => d.dnr_DSMID != Guid.Empty); var piDinnerRecord = dinnerQuery.List(); if (piDinnerRecord.Count > 0) { DinnerRecord_dnr_Info dnr = piDinnerRecord[0]; mLog.Debug("--------當前機台停機,就餐中,就餐時間=" + (int)(dnr.dnr_dEndTime.Value - dnr.dnr_dBeginTime.Value).TotalSeconds); totalTimes -= (int)(dnr.dnr_dEndTime.Value - dnr.dnr_dBeginTime.Value).TotalSeconds; } #endregion mLog.Debug("檢查到當前PLC 機台狀態是停機狀態,持續時間" + totalTimes.ToString()); if (totalTimes > project.PROD_STOP_COND * 60) //超出最長停機時間 { newStatus = CustEnum.ProductionStatus.PROD_STOP;//生產中停機 } else { newStatus = oldStatus; } } else if (oldStatus == CustEnum.ProductionStatus.PROD_STOP || project.swl_cProjStatus == CustEnum.ProjectStatus.PROD_STOP_OT.ToString()) { newStatus = oldStatus; } } } mLog.Debug("當前工程狀態=" + newStatus.ToString()); return newStatus; }
public ReturnValueInfo RemoveScheduleProject(ScheduleProjList_swl_Info data) { throw new NotImplementedException(); }
/// <summary> /// 獲取信號控制主檔 /// </summary> /// <returns></returns> //public List<SignalLightsStatus_sls_Info> GetSignalControls() //{ // List<SignalLightsStatus_sls_Info> result = null; // try // { // CRUD baseDal = new CRUD(); // result = baseDal.ExcuteHQL<SignalLightsStatus_sls_Info>("from SignalLightsStatus_sls_Info") as List<SignalLightsStatus_sls_Info>; // } // catch (Exception ex) // { // result = new List<SignalLightsStatus_sls_Info>(); // mLog.Error("PLCBL.GetSignalControls", ex); // // throw; // } // return result; //} /// <summary> /// 工程開始生產,狀態改變規則:準備中-->生產中 /// </summary> /// <param name="schProj"></param> /// <param name="printProj"></param> /// <param name="shiftProject"></param> /// <param name="data"></param> /// <returns></returns> public bool ProduceBegin(DBContext uow, ScheduleProjList_swl_Info schProj, PrintProject_ppj_Info printProj, ShiftProjList_spl_Info shiftProject, PLCData_pda_Info data) { try { //using (DBContext uow = DBContext.Begin()) //{ DateTime dealTime = DateTime.Now; #region 更新印刷工程信息 schProj.swl_iIsByModify = true; schProj.swl_cProjStatus = CustEnum.ProjectStatus.PROD_IN.ToString(); schProj.swl_dStatusChange = dealTime; schProj.swl_dLastDate = dealTime; uow.CurrentSession.Update(uow.CurrentSession.Merge(schProj)); #endregion #region 更新生產工程信息 if (printProj != null) { printProj.ppj_dProdBeginTime = dealTime; printProj.ppj_fMachineSpeed = data.pda_iMachineSpeed; printProj.ppj_iActualProdNum = data.pad_iQty; printProj.ppj_iCountProdNum = data.pad_iQty; printProj.ppj_dLastDate = dealTime; var projectDinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == schProj.swl_RecordID); projectDinnerQuery.And(d => d.dsm_ppjID == printProj.ppj_RecordID); projectDinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PREPARE.ToString()); int projectDinnerTime = (int)projectDinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); printProj.ppj_iActualPrepairTime = (int)(printProj.ppj_dProdBeginTime.Value - printProj.ppj_dProjBeginTime).TotalSeconds - projectDinnerTime; uow.CurrentSession.Update(printProj); } #endregion #region 更新班次內工程信息 #region 準備時間計算 shiftProject.spl_dProdBegin = printProj.ppj_dProdBeginTime; int prepairTime = (int)(shiftProject.spl_dProdBegin.Value - shiftProject.spl_dBeginTime).TotalSeconds; var dinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == schProj.swl_RecordID); dinnerQuery.And(d => d.dsm_ppjID == printProj.ppj_RecordID); dinnerQuery.And(d => d.dsm_splID == shiftProject.spl_RecordID); dinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PREPARE.ToString()); int dinnerTime = (int)dinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds); shiftProject.spl_iPrepairTime = prepairTime - dinnerTime; #endregion shiftProject.spl_dLastDate = dealTime; shiftProject.spl_iBeginQTY = 0; shiftProject.spl_iQTY = data.pad_iQty; shiftProject.spl_iEndQTY = data.pad_iQty; shiftProject.spl_iCalQTY = shiftProject.spl_iEndQTY - shiftProject.spl_iBeginQTY; uow.CurrentSession.Update(shiftProject); #endregion #region 更新生產中停機的結束時間 ProjectStopRecord_psrd_Info psrd_prepare; var query_pre = uow.CurrentSession.QueryOver<ProjectStopRecord_psrd_Info>(); query_pre.And(d => d.psrd_SPLID == shiftProject.spl_RecordID); query_pre.And(d => d.psrd_dEndTime == null); query_pre.And(d => d.psrd_cTypeID == CustEnum.RecordType.NORMAL.ToString()); IList<ProjectStopRecord_psrd_Info> list_pre = query_pre.List<ProjectStopRecord_psrd_Info>(); if (list_pre.Count > 0) { psrd_prepare = list_pre[0]; psrd_prepare.psrd_dEndTime = dealTime; psrd_prepare.psrd_dLastDate = dealTime; psrd_prepare.psrd_iActualStopTime = TimeCalculater.ProjectStopRecordActualTime(uow, psrd_prepare); uow.CurrentSession.Update(uow.CurrentSession.Merge(psrd_prepare)); printProj.ppj_iStopTime += psrd_prepare.psrd_iActualStopTime; uow.CurrentSession.Update(uow.CurrentSession.Merge(printProj)); shiftProject.spl_iStopTime += psrd_prepare.psrd_iActualStopTime; uow.CurrentSession.Update(uow.CurrentSession.Merge(shiftProject)); } #endregion // } return true; } catch (Exception ex) { uow.CanCommit = false; mLog.Error("PLCBL.ProduceBegin" + ex); return false; } }
public ReturnValueInfo RestartProject(ScheduleProjList_swl_Info schProject, ref PrintProject_ppj_Info project, ShiftInfo_sifo_Info shift) { ReturnValueInfo result = new ReturnValueInfo(); try { using (DBContext uow = DBContext.Begin()) { try { //工程状态轉化為準備中 schProject.swl_cProjStatus = CustEnum.ProjectStatus.PREPARE.ToString(); schProject.swl_lSync = false; uow.CurrentSession.Update(schProject); #region 重新創建一條印刷工程擴展信息記錄 PrintProject_ppj_Info ppj_restart = new PrintProject_ppj_Info(); ppj_restart.ppj_RecordID = Guid.NewGuid(); ppj_restart.ppj_SWLID = schProject.swl_RecordID; ppj_restart.ppj_lActiveRecord = true; ppj_restart.ppj_lSync = false; ppj_restart.ppj_dAddDate = DateTime.Now; ppj_restart.ppj_dProjBeginTime = DateTime.Now; ppj_restart.ppj_cRank = ""; ppj_restart.ppj_iSpeed = project.ppj_iSpeed; ppj_restart.ppj_iQCInterval = project.ppj_iQCInterval; ppj_restart.ppj_iPertimeProdNum = project.ppj_iPertimeProdNum; ppj_restart.ppj_lActiveRecord = true; #region 工程附件信息 ProjectAdditionalInformation_pai_Info paiInfo = new ProjectAdditionalInformation_pai_Info(); paiInfo.pai_PPJRecordID = ppj_restart.ppj_RecordID; paiInfo.pai_iFrontProcessDefectiveQty = 0; paiInfo.pai_iFrontProcessWasteQty = 0; paiInfo.pai_iGoldPaperTimes = 0; paiInfo.pai_iRevolution = 0; paiInfo.pai_iTemperature = 0; paiInfo.pai_cUnit = string.Empty; paiInfo.pai_iUnitLength = 0; paiInfo.pai_iUVLuminosity = 0; paiInfo.pai_iUnitWidth = 0; uow.CurrentSession.Save(paiInfo); ppj_restart.AdditionalInformation = paiInfo; #endregion #region 准备工作项目 var query = uow.CurrentSession.QueryOver<ProjectPreJobItem_ppji_Info>(); Guid ppjId = project.ppj_RecordID; query.And(d => d.ppji_PPJID == ppjId); IList<ProjectPreJobItem_ppji_Info> ppjis = query.List<ProjectPreJobItem_ppji_Info>(); ppj_restart.PrepareJobItems = ppjis; foreach (ProjectPreJobItem_ppji_Info item in ppjis) { item.ppji_PPJID = ppj_restart.ppj_RecordID; uow.CurrentSession.Save(item); } #endregion uow.CurrentSession.Save(ppj_restart); #endregion #region 創建新的班次內工程信息 ShiftProjList_spl_Info shiftProject = new ShiftProjList_spl_Info(); shiftProject.spl_RecordID = Guid.NewGuid(); shiftProject.spl_dBeginTime = DateTime.Now; shiftProject.spl_dAddDate = DateTime.Now; shiftProject.spl_SIFOID = shift.sifo_RecordID; shiftProject.spl_PPJID = ppj_restart.ppj_RecordID; uow.CurrentSession.Save(shiftProject); #endregion #region 班次空閒狀態結束 SpareStatus_sst_Info info = uow.CurrentSession.QueryOver<SpareStatus_sst_Info>().And(d => d.sst_iSIFOID == shift.sifo_RecordID).And(d => d.sst_dEndTime == null).Take(1).SingleOrDefault(); if (info != null) { info.sst_dEndTime = DateTime.Now; info.sst_dLastDate = DateTime.Now; uow.CurrentSession.Update(info); } #endregion if (ppj_restart.ShiftProjects == null) { ppj_restart.ShiftProjects = new List<ShiftProjList_spl_Info>(); } ppj_restart.ShiftProjects.Add(shiftProject); project = ppj_restart; } catch { uow.CanCommit = false; throw; } } result.boolValue = true; } catch (Exception ex) { result.boolValue = false; result.messageText = Resource.B0026 + ":" + ex.Message; Common.General.BLLoger.Error(result.messageText); } return result; }
//public bool ChangetShift(string machineID, ref ShiftProjList_spl_Info shiftProject) //{ // try // { // mLog.Debug("執行轉班邏輯"); // ShiftProjList_spl_Info newSpl = null; // ShiftProjList_spl_Info oldSpl = shiftProject; // using (Transaction uow = Transaction.Begin()) // { // mLog.Debug("更新班次內工程 ShiftProjList_spl_Info"); // oldSpl.spl_dLastDate = DateTime.Now; // oldSpl.spl_dEndTime = oldSpl.ShiftInfo.sifo_dEndTime; // oldSpl.spl_lSync = false; // uow.CurrentSession.Update(oldSpl); // #region // ShiftInfo_sifo_Info nextShift = null; // var query = uow.CurrentSession.QueryOver<ShiftInfo_sifo_Info>(); // query.And(d => d.sifo_dBeginTime >= DateTime.Now); // query.And(d => d.sifo_cMachineNO == machineID).OrderBy(d => d.sifo_dBeginTime); // IList<ShiftInfo_sifo_Info> list = query.List<ShiftInfo_sifo_Info>(); // if (list.Count > 0) // { // nextShift = list[0]; // } // else // { // //todo:creat new shift // } // mLog.Debug("創建新的班次內工程 ShiftProjList_spl_Info"); // newSpl = new ShiftProjList_spl_Info(); // newSpl.spl_RecordID = Guid.NewGuid(); // newSpl.spl_SIFOID = nextShift.sifo_RecordID; // newSpl.spl_PPJID = oldSpl.spl_PPJID; // newSpl.spl_dBeginTime = nextShift.sifo_dBeginTime.Value; // newSpl.spl_dProdBegin = nextShift.sifo_dBeginTime.Value; // newSpl.spl_dAddDate = DateTime.Now; // newSpl.spl_iBeginQTY = oldSpl.PrintProject.ppj_iCountProdNum; // newSpl.spl_iBeginQTY = shiftProject.spl_iEndQTY; // uow.CurrentSession.Save(newSpl); // uow.CurrentSession.Flush(); // newSpl.PrintProject = oldSpl.PrintProject; // newSpl.ShiftInfo = nextShift; // shiftProject = newSpl; // #endregion // #region 結束工程停機記錄 // ProjectStopRecord_psrd_Info psrd = uow.CurrentSession.QueryOver<ProjectStopRecord_psrd_Info>().And(d => d.psrd_SPLID == oldSpl.spl_RecordID).And(d => d.psrd_dEndTime == null).Take(1).SingleOrDefault(); // if (psrd != null) // { // psrd.psrd_dEndTime = oldSpl.ShiftInfo.sifo_dEndTime; // psrd.psrd_dLastDate = DateTime.Now; // psrd.psrd_lSync = false; // uow.CurrentSession.Update(psrd); // mLog.Debug("創建跨班次停機記錄 ProjectStopRecord_psrd_Info"); // ProjectStopRecord_psrd_Info nextPsrd = new ProjectStopRecord_psrd_Info(); // nextPsrd.psrd_RecordID = Guid.NewGuid(); // nextPsrd.psrd_dBeginTime = nextShift.sifo_dBeginTime.Value; // nextPsrd.psrd_dAddDate = DateTime.Now; // nextPsrd.psrd_PPJID = newSpl.spl_PPJID; // nextPsrd.psrd_SPLID = newSpl.spl_RecordID; // nextPsrd.psrd_cTypeID = CustEnum.RecordType.NORMAL.ToString(); // uow.CurrentSession.Save(nextPsrd); // } // #endregion // #region 結束幾臺空閒狀態 // SpareStatus_ssts_Info ssts = uow.CurrentSession.QueryOver<SpareStatus_ssts_Info>().And(d => d.sst_cMachineNO == machineID) // .And(d => d.sst_iSIFOID == oldSpl.spl_SIFOID).And(d => d.sst_dEndTime == null).Take(1).SingleOrDefault(); // if (ssts != null) // { // ssts.sst_dEndTime = oldSpl.ShiftInfo.sifo_dEndTime; // ssts.sst_dLastDate = DateTime.Now; // ssts.sst_lSync = false; // uow.CurrentSession.Update(ssts); // mLog.Debug("創建跨班次空閒記錄 SpareStatus_ssts_Info"); // SpareStatus_ssts_Info nextSsts = new SpareStatus_ssts_Info(); // nextSsts.sst_cMachineNO = machineID; // nextSsts.sst_dBeginTime = nextShift.sifo_dBeginTime.Value; // nextSsts.sst_iSIFOID = nextShift.sifo_RecordID; // nextSsts.sst_dAddDate = DateTime.Now; // uow.CurrentSession.Save(nextSsts); // } // #endregion // } // return true; // } // catch (Exception ex) // { // mLog.Error(ex); // } // return false; //} public bool ChangeShift(string machineID, ShiftInfo_sifo_Info currentShift, ShiftInfo_sifo_Info nextShift, ScheduleProjList_swl_Info scheduleProject, PrintProject_ppj_Info printProject, ShiftProjList_spl_Info shiftProject) { mLog.Info("班次轉換新邏輯"); try { if (currentShift == null) { throw new Exception("當前班次對象不能為空"); } if (nextShift == null) { throw new Exception("下一班次對象不能為空"); } using (DBContext uow = DBContext.Begin()) { try { if (printProject != null && shiftProject != null && shiftProject.spl_RecordID != Guid.Empty) { PrintProject_ppj_Info currentProject = printProject; ShiftProjList_spl_Info currentShiftProject = shiftProject; #region 更新班次內工程 mLog.Debug("更新班次內工程 ShiftProjList_spl_Info"); currentShiftProject.spl_dLastDate = DateTime.Now; currentShiftProject.spl_dEndTime = currentShift.sifo_dEndTime; currentShiftProject.spl_lSync = false; //就餐時間 #region 準備時間計算 if (currentShiftProject.spl_dProdBegin.HasValue)//沒有結束準備 { currentShiftProject.spl_iPrepairTime = TimeCalculater.ShiftProjectActualPrepairTime(uow, currentShiftProject); currentProject.ppj_iActualPrepairTime += currentShiftProject.spl_iPrepairTime; } #endregion #region 正常生產時間 currentShiftProject.spl_iProdSumTime = TimeCalculater.ShiftProjectProdTime(uow, currentShiftProject); #endregion uow.CurrentSession.Update(currentShiftProject); #endregion #region 創建新的班次內工程 mLog.Debug("創建新的班次內工程 ShiftProjList_spl_Info"); ShiftProjList_spl_Info newSpl = new ShiftProjList_spl_Info(); newSpl.spl_RecordID = Guid.NewGuid(); newSpl.spl_SIFOID = nextShift.sifo_RecordID; newSpl.spl_PPJID = currentShiftProject.spl_PPJID; newSpl.spl_dBeginTime = nextShift.sifo_dBeginTime.Value; newSpl.spl_dAddDate = DateTime.Now; newSpl.spl_iBeginQTY = currentShiftProject.spl_iEndQTY; newSpl.spl_iEndQTY = currentShiftProject.spl_iEndQTY; if (currentShiftProject.spl_dProdBegin != null) { newSpl.spl_dProdBegin = nextShift.sifo_dBeginTime.Value; } else { newSpl.spl_dProdBegin = null; } uow.CurrentSession.Save(newSpl); #endregion #region 結束工程停機記錄 ProjectStopRecord_psrd_Info psrd = uow.CurrentSession.QueryOver<ProjectStopRecord_psrd_Info>() .And(d => d.psrd_SPLID == currentShiftProject.spl_RecordID) .And(d => d.psrd_dEndTime == null).Take(1).SingleOrDefault(); if (psrd != null) { psrd.psrd_dEndTime = currentShift.sifo_dEndTime; psrd.psrd_dLastDate = DateTime.Now; psrd.psrd_lSync = false; psrd.psrd_iActualStopTime = TimeCalculater.ProjectStopRecordActualTime(uow, psrd); uow.CurrentSession.Update(psrd); mLog.Debug("更新跨更的班次內工程的停機時間"); currentShiftProject.spl_iStopTime += psrd.psrd_iActualStopTime; uow.CurrentSession.Update(currentShiftProject); currentProject.ppj_iStopTime += psrd.psrd_iActualStopTime; currentProject.ppj_iStopTimes++; uow.CurrentSession.Update(currentProject); //mLog.Debug("創建跨班次停機記錄 ProjectStopRecord_psrd_Info"); //ProjectStopRecord_psrd_Info nextPsrd = new ProjectStopRecord_psrd_Info(); //nextPsrd.psrd_RecordID = Guid.NewGuid(); //nextPsrd.psrd_dBeginTime = nextShift.sifo_dBeginTime.Value; //nextPsrd.psrd_dAddDate = DateTime.Now; //nextPsrd.psrd_PPJID = newSpl.spl_PPJID; //nextPsrd.psrd_SPLID = newSpl.spl_RecordID; //nextPsrd.psrd_cTypeID = CustEnum.RecordType.NORMAL.ToString(); //uow.CurrentSession.Save(nextPsrd); //newSpl.spl_iStopTimes++; //uow.CurrentSession.Update(newSpl); } #endregion } #region 結束機台空閒狀態 SpareStatus_sst_Info ssts = uow.CurrentSession.QueryOver<SpareStatus_sst_Info>().And(d => d.sst_cMachineNO == machineID) .And(d => d.sst_iSIFOID == currentShift.sifo_RecordID).And(d => d.sst_dEndTime == null).Take(1).SingleOrDefault(); if (ssts != null) { IdleState_ism_Info ism = null; if (ssts.sst_StatusID == Guid.Empty) { ism = uow.CurrentSession.QueryOver<IdleState_ism_Info>().And(d => d.ism_lIsBuildin && d.ism_lIsAtive).Take(1).SingleOrDefault(); if (ism != null) { ssts.sst_cStatusName = ism.ism_cStateName; ssts.sst_StatusID = ism.ism_RecordID; } } ssts.sst_dEndTime = currentShift.sifo_dEndTime; ssts.sst_dLastDate = DateTime.Now; ssts.sst_lSync = false; uow.CurrentSession.Update(ssts); mLog.Debug("創建跨班次空閒記錄 SpareStatus_ssts_Info"); SpareStatus_sst_Info nextSsts = new SpareStatus_sst_Info(); nextSsts.sst_RecordID = Guid.NewGuid(); nextSsts.sst_cMachineNO = machineID; nextSsts.sst_dBeginTime = nextShift.sifo_dBeginTime.Value; nextSsts.sst_iSIFOID = nextShift.sifo_RecordID; nextSsts.sst_dAddDate = DateTime.Now; if (ism != null) { nextSsts.sst_cStatusName = ism.ism_cStateName; nextSsts.sst_StatusID = ism.ism_RecordID; } uow.CurrentSession.Save(nextSsts); } #endregion } catch (Exception) { uow.CanCommit = false; throw; } } return true; } catch (Exception ex) { string message = "班次轉換新邏輯,machineID=" + machineID + "\r\n"; message += "PrintProject_ppj_Info=" + Common.Util.JsonUtil.JsonSerializer<PrintProject_ppj_Info>(printProject) + "\r\n"; message += "ShiftProjList_spl_Info=" + Common.Util.JsonUtil.JsonSerializer<ShiftProjList_spl_Info>(shiftProject) + "\r\n"; Common.Util.MessageUtil.SendDevMail(message, ex); mLog.Error(ex); return false; // throw; } }
public List<ScheduleProjList_swl_Info> Search(int pageIndex, int pageSize, string orderby, ScheduleProjList_swl_Info cond, bool fuzzy) { using (DBContext uow = new DBContext()) { var query = uow.CurrentSession.QueryOver<ScheduleProjList_swl_Info>(); #region 條件 if (!string.IsNullOrEmpty(cond.swl_cPlanMachineNO)) { query.And(d => d.swl_cPlanMachineNO == cond.swl_cPlanMachineNO); } if (cond.swl_RecordID != Guid.Empty) { query.And(d => d.swl_RecordID == cond.swl_RecordID); } if (!string.IsNullOrEmpty(cond.swl_cItemName)) { if (fuzzy) { query.AndRestrictionOn(d => d.swl_cItemName).IsLike("%" + cond.swl_cItemName + "%"); } else { query.And(d => d.swl_cItemName == cond.swl_cItemName); } } if (!string.IsNullOrEmpty(cond.swl_cItemNO)) { if (fuzzy) { query.AndRestrictionOn(d => d.swl_cItemNO).IsLike("%" + cond.swl_cItemNO + "%"); } else { query.And(d => d.swl_cItemNO == cond.swl_cItemNO); } } if (!string.IsNullOrEmpty(cond.swl_cProdName)) { if (fuzzy) { query.AndRestrictionOn(d => d.swl_cProdName).IsLike("%" + cond.swl_cProdName + "%"); } else { query.And(d => d.swl_cProdName == cond.swl_cProdName); } } if (!string.IsNullOrEmpty(cond.swl_cSONO)) { if (fuzzy) { query.AndRestrictionOn(d => d.swl_cSONO).IsLike("%" + cond.swl_cSONO + "%"); } else { query.And(d => d.swl_cSONO == cond.swl_cSONO); } } if (!string.IsNullOrEmpty(cond.swl_cProjStatus)) { query.And(d => d.swl_cProjStatus == cond.swl_cProjStatus); } if (!string.IsNullOrEmpty(cond.swl_cMachineNO)) { query.And(d => d.swl_cMachineNO == cond.swl_cMachineNO); } #endregion query.UnderlyingCriteria.AddOrder(Order.Asc(orderby)); if (pageSize == 0) { return query.List<ScheduleProjList_swl_Info>().ToList(); } else { return query.Take(pageSize).Skip((pageIndex - 1) * pageSize).List<ScheduleProjList_swl_Info>().ToList(); } } }