예제 #1
0
        /// <summary>
        /// 保存QC問題
        /// </summary>
        /// <param name="pqc"></param>
        /// <returns></returns>
        public ReturnValueInfo AddQCProblem(ProjectQCProblem_pqcp_Info problem, PrintProject_ppj_Info project, ShiftProjList_spl_Info shiftProject)
        {
            ReturnValueInfo result = new ReturnValueInfo();

            try
            {
                if (problem.pqcp_PQCID == Guid.Empty)
                {
                    result.boolValue = false;
                    result.messageText = "QC問題記錄沒有設置QC記錄ID,不能保存QC問題。";
                    return result;
                }
                if (problem.pqcp_iWasteQty == 0 && problem.pqcp_iDefectiveQty == 0)
                {
                    result.boolValue = false;
                    result.messageText = "QC廢品數量和次品數量不能同時為0。";
                    return result;
                }

                using (DBContext uow = DBContext.Begin())
                {
                    problem.pqcp_RecordID = Guid.NewGuid();
                    problem.pqcp_dAddDate = DateTime.Now;
                    problem.pqcp_dLastDate = DateTime.Now;

                    ProjectQCProblem_pqcp_Info pqcp_max = uow.CurrentSession.QueryOver<ProjectQCProblem_pqcp_Info>().And(d => d.pqcp_PQCID == problem.pqcp_PQCID).OrderBy(d => d.pqcp_iSeq).Desc.Take(1).SingleOrDefault();
                    if (pqcp_max != null)
                    {
                        problem.pqcp_iSeq = pqcp_max.pqcp_iSeq + 1;
                    }
                    else
                    {
                        problem.pqcp_iSeq = 1;
                    }
                    uow.CurrentSession.SaveOrUpdate(uow.CurrentSession.Merge(problem));
                    //CountSPLQCInfo(uow, project, shiftProject);
                }

                result.boolValue = true;

            }
            catch (Exception ex)
            {
                result.boolValue = false;
                result.messageText = ex.Message;
            }

            return result;
        }
예제 #2
0
파일: PLCBL.cs 프로젝트: Klutzdon/PBIMSN
        /// <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;
        }
예제 #3
0
파일: PLCBL.cs 프로젝트: Klutzdon/PBIMSN
        /// <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;
            }
        }
예제 #4
0
        /// <summary>
        /// 班次內工程總運作時間=當前時間-班次內工程開始時間
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public static int ShiftProjectRunTime(ShiftProjList_spl_Info project)
        {
            if (project.spl_dBeginTime != null)
            {
                if (project.spl_dEndTime == null)
                {
                    int total = (int)(DateTime.Now - project.spl_dBeginTime).TotalSeconds;

                    return total;
                }
                else
                {
                    int total = (int)(project.spl_dEndTime.Value - project.spl_dBeginTime).TotalSeconds;

                    return total;
                }
            }
            return 0;
        }
예제 #5
0
        public ReturnValueInfo StopProject(ProjectStopRec_psr_Info stopRecord, ShiftProjList_spl_Info spl)
        {
            // DateTime start = DateTime.Now;
            ReturnValueInfo result = new ReturnValueInfo();

            if (stopRecord == null || stopRecord.Project == null)
            {
                result.boolValue = false;
                result.messageText = "工程為空。";

            }
            else
            {

                try
                {

                    using (DBContext uow = DBContext.Begin())
                    {
                        try
                        {
                            DateTime dealTime = DateTime.Now;

                            #region 更新印刷工程記錄為無效的
                            if (stopRecord.PrintProject == null)
                            {
                                throw new Exception("不能抽起工程,工程數據信息缺失,請聯繫開發人員!");
                            }
                            else
                            {
                                stopRecord.PrintProject.ppj_lActiveRecord = false;
                                if (stopRecord.Project.swl_cProjStatus == CustEnum.ProjectStatus.PREPARE.ToString() || stopRecord.Project.swl_cProjStatus == CustEnum.ProjectStatus.PREPARE_OT.ToString())
                                {
                                    stopRecord.PrintProject.ppj_dProdBeginTime = dealTime;
                                }
                                stopRecord.PrintProject.ppj_dProdEndTime = dealTime;
                                stopRecord.PrintProject.ppj_dLastDate = dealTime;

                                var dinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == stopRecord.Project.swl_RecordID);
                                dinnerQuery.And(d => d.dsm_ppjID == stopRecord.PrintProject.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);

                                stopRecord.PrintProject.ppj_iProdSumTime = stopRecord.PrintProject.ppj_iProjRunTime - stopRecord.PrintProject.ppj_iActualPrepairTime - stopRecord.PrintProject.ppj_iStopTime - dinnerTime;

                                uow.CurrentSession.Update(stopRecord.PrintProject);
                            }
                            #endregion

                            #region 更新班次內工程結束時間

                            if (spl != null)
                            {
                                if (stopRecord.Project.swl_cProjStatus == CustEnum.ProjectStatus.PREPARE.ToString() || stopRecord.Project.swl_cProjStatus == CustEnum.ProjectStatus.PREPARE_OT.ToString())
                                {
                                    spl.spl_dProdBegin = dealTime;
                                }
                                spl.spl_dEndTime = dealTime;

                                #region 準備時間計算
                                int totalPrepare = (int)(spl.spl_dProdBegin.Value - spl.spl_dBeginTime).TotalSeconds;
                                spl.spl_iPrepairTime = totalPrepare;
                                #endregion

                                //計算正常生產時間,需優化
                                var dinnerQuery = uow.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_swlID == stopRecord.Project.swl_RecordID);
                                dinnerQuery.And(d => d.dsm_ppjID == stopRecord.PrintProject.ppj_RecordID);
                                dinnerQuery.And(d => d.dsm_splID == spl.spl_RecordID);
                                int dinnerTime = (int)dinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds);
                                spl.spl_iProdSumTime = spl.spl_iRunTime - spl.spl_iPrepairTime - spl.spl_iStopTime - dinnerTime;

                                var query_psrd = uow.CurrentSession.QueryOver<ProjectStopRecord_psrd_Info>();
                                query_psrd.And(d => d.psrd_dEndTime == null);
                                query_psrd.And(d => d.psrd_cTypeID == CustEnum.RecordType.NORMAL.ToString());
                                query_psrd.And(d => d.psrd_SPLID == spl.spl_RecordID);

                                ProjectStopRecord_psrd_Info psrd = query_psrd.Take(1).SingleOrDefault();
                                if (psrd != null)
                                {
                                    psrd.psrd_dEndTime = dealTime;
                                    psrd.psrd_dLastDate = dealTime;
                                    psrd.psrd_iActualStopTime = TimeCalculater.ProjectStopRecordActualTime(uow, psrd);
                                    uow.CurrentSession.Update(psrd);

                                    stopRecord.PrintProject.ppj_iStopTime += psrd.psrd_iActualStopTime;
                                    stopRecord.PrintProject.ppj_iStopTimes += 1;
                                    uow.CurrentSession.Update(stopRecord.PrintProject);

                                    spl.spl_iStopTime += psrd.psrd_iActualStopTime;
                                    spl.spl_iStopTimes += 1;

                                }
                                uow.CurrentSession.Update(spl);
                            }

                            #endregion

                            #region 保存抽起的記錄
                            stopRecord.psr_SWLID = stopRecord.Project.swl_RecordID;
                            stopRecord.psr_cRecordID = Guid.NewGuid();
                            stopRecord.psr_dAddDate = dealTime;
                            stopRecord.psr_lSync = false;
                            uow.CurrentSession.Save(stopRecord);
                            #endregion

                            #region 將印刷工程的生產順序排到最後

                            //int max_PrintOrder = 1;
                            //ScheduleProjList_swl_Info max_swl = uow.CurrentSession.QueryOver<ScheduleProjList_swl_Info>().OrderBy(d => d.swl_iPrintOrder).Desc().Take(1).SingleOrDefault();
                            //if (max_swl != null)
                            //{
                            //    max_PrintOrder = max_swl.swl_iPrintOrder;
                            //}

                            //ScheduleProjList_swl_Info swl = uow.CurrentSession.Get<ScheduleProjList_swl_Info>(data.Project.swl_RecordID);
                            //swl.swl_iPrintOrder = max_PrintOrder + 1;
                            //uow.CurrentSession.Update(swl);
                            #endregion

                            #region  班次進入空閒狀態
                            SpareStatus_sst_Info info_new = new SpareStatus_sst_Info();
                            info_new.sst_RecordID = Guid.NewGuid();
                            info_new.sst_iSIFOID = spl.spl_SIFOID;
                            info_new.sst_dBeginTime = dealTime;
                            info_new.sst_dAddDate = dealTime;
                            info_new.sst_cMachineNO = stopRecord.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

                            #region 更新工程狀態為抽起
                            stopRecord.Project.swl_iIsByModify = true;
                            stopRecord.Project.swl_iCompletedQty += stopRecord.PrintProject.ppj_iActualProdNum;
                            stopRecord.Project.swl_cProjStatus = CustEnum.ToString(CustEnum.ProjectStatus.STOP);
                            stopRecord.Project.swl_dLastDate = dealTime;
                            uow.CurrentSession.Update(stopRecord.Project);
                            #endregion

                            result.boolValue = true;
                        }
                        catch (Exception)
                        {
                            uow.CanCommit = false;
                            throw;
                        }

                    }

                    result.boolValue = true;

                }
                catch (Exception ex)
                {

                    string message = "抽起工程出現錯誤,machineID=" + stopRecord.Project.swl_cMachineNO;
                    message += "ScheduleProjList_swl_Info=" + Common.Util.JsonUtil.JsonSerializer<ScheduleProjList_swl_Info>(stopRecord.Project);
                    message += "PrintProject_ppj_Info=" + Common.Util.JsonUtil.JsonSerializer<PrintProject_ppj_Info>(stopRecord.PrintProject);
                    message += "ShiftProjList_spl_Info=" + Common.Util.JsonUtil.JsonSerializer<ShiftProjList_spl_Info>(spl);
                    Common.Util.MessageUtil.SendDevMail(message, ex);

                    result.boolValue = false;
                    result.messageText = Resource.B0017 + ":" + ex.Message;
                    Common.General.BLLoger.Error(result.messageText);
                }

            }
            // DateTime end = DateTime.Now;
            // Common.General.BLLoger.Debug("抽起工程,耗時" + (end - start).Milliseconds.ToString());

            return result;
        }
예제 #6
0
        //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;
            }
        }
예제 #7
0
        /// <summary>
        /// 班次內工程實際準備時間=生產開始時間-工程開始時間-就餐時間
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public static int ShiftProjectPrepairTime(ShiftProjList_spl_Info spl, PrintProject_ppj_Info ppj)
        {
            throw new NotImplementedException();

            //if (DateTime.MinValue == ppj.ppj_dProjBeginTime)
            //{
            //    return 0;
            //}
            //else
            //{
            //    int total = 0;
            //    var dinners = DinnerBL.GetDinnerRecord(null, null, ppj.ppj_RecordID.ToString(), spl.spl_RecordID.ToString(), "%" + CustEnum.ProjectStatus.PREPARE + "%");
            //    int dinnerTime = (int)dinners.Where(d => d.dnr_dEndTime.HasValue).Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds);

            //    if (spl.spl_dProdBegin.HasValue)
            //    {
            //        total = (int)(spl.spl_dProdBegin.Value - spl.spl_dBeginTime).TotalSeconds;
            //    }
            //    else
            //    {
            //        total = (int)(DateTime.Now - spl.spl_dBeginTime).TotalSeconds;
            //    }

            //    total = total - dinnerTime;
            //    return total;
            //}
        }
예제 #8
0
        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;
        }
예제 #9
0
파일: PLCBL.cs 프로젝트: Klutzdon/PBIMSN
        /// <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;
            }
        }
예제 #10
0
        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;
        }
예제 #11
0
        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;
        }
예제 #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="project">生產工程</param>
        /// <param name="shiftProject">班次內工程</param>
        /// <param name="reason">原因</param>
        /// <param name="CorrectQTY">糾正數量</param>
        /// <returns></returns>
        public ReturnValueInfo CorrectProjectQTY(PrintProject_ppj_Info project, ShiftProjList_spl_Info shiftProject, CodeMaster_cmt_Info reason, int CorrectQTY)
        {
            ReturnValueInfo result = new ReturnValueInfo();
            try
            {
                using (DBContext uow = DBContext.Begin())
                {
                    try
                    {
                        //保存糾正數量記錄
                        CorrectRecord_ctr_Info ctr = new CorrectRecord_ctr_Info();
                        ctr.ctr_RecordID = Guid.NewGuid();
                        ctr.ctr_cType = CustEnum.KEY2.CORRECTQTY.ToString();
                        ctr.ctr_cReasonID = reason.cmt_cValue;
                        ctr.ctr_cReason = reason.cmt_cRemark;
                        ctr.ctr_dLastDate = ctr.ctr_dAddDate = DateTime.Now;
                        ctr.ctr_iAdjustProdQTY = shiftProject.spl_iQTY + CorrectQTY;
                        ctr.ctr_iProdQTY = shiftProject.spl_iQTY;
                        ctr.ctr_lSync = false;
                        ctr.ctr_PPJID = shiftProject.spl_PPJID;
                        ctr.ctr_SPLID = shiftProject.spl_RecordID;
                        uow.CurrentSession.Save(ctr);

                        //更新班次內工程生產數量
                        shiftProject.spl_iQTY += CorrectQTY;
                        shiftProject.spl_dLastDate = DateTime.Now;
                        uow.CurrentSession.Update(shiftProject);

                        //更新工程生產數量
                        project.ppj_iActualProdNum += CorrectQTY;
                        uow.CurrentSession.Update(project);
                    }
                    catch (Exception)
                    {
                        uow.CanCommit = false;
                        throw;
                    }

                }

                result.boolValue = true;
            }
            catch (Exception ex)
            {
                result.boolValue = false;
                result.messageText = Resource.B0025 + ":" + ex.Message;
            }
            return result;
        }
예제 #13
0
        /// <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;
        }
예제 #14
0
        public ReturnValueInfo UpdateProjectPallet(PrintProject_ppj_Info project, ShiftProjList_spl_Info shiftProject, PalletLabelPrintRecord_plpr_Info palletLabel)
        {
            ReturnValueInfo result = new ReturnValueInfo();
            try
            {
                using (DBContext trans = DBContext.Begin())
                {
                    PrintProject_ppj_Info lProject = trans.CurrentSession.Load<PrintProject_ppj_Info>(project.ppj_RecordID);
                    ShiftProjList_spl_Info lShiftProject = trans.CurrentSession.Load<ShiftProjList_spl_Info>(shiftProject.spl_RecordID);

                    lProject.ppj_iPalletQty++;
                    lShiftProject.spl_iPalletQty++;
                    trans.CurrentSession.Update(lProject);
                    trans.CurrentSession.Update(lShiftProject);

                    palletLabel.plpr_RecordID = Guid.NewGuid();
                    palletLabel.plpr_SWLID = project.ScheduleProject.swl_RecordID;
                    palletLabel.plpr_cProductName = project.ScheduleProject.swl_cProdName;
                    palletLabel.plpr_cSONO = project.ScheduleProject.swl_cSONO;
                    palletLabel.plpr_iPredictPrintQTY = project.ScheduleProject.swl_iPlanProdQty;
                    palletLabel.plpr_dAddDate = DateTime.Now;
                    trans.CurrentSession.Save(palletLabel);

                }
                result.boolValue = true;
            }
            catch (Exception ex)
            {
                result.messageText = ex.Message;
            }

            return result;
        }
예제 #15
0
        public ReturnValueInfo QCPass(ProjectQCRecord_pqc_Info pqc, PrintProject_ppj_Info project, ShiftProjList_spl_Info shiftProject)
        {
            ReturnValueInfo result = new ReturnValueInfo();

            try
            {
                if (pqc == null || pqc.pqc_iQCQTY == 0)
                {
                    result.boolValue = false;
                    result.messageText = "抽查數量不能為零。";
                    return result;
                }
                else
                {
                    if (pqc.pqc_SPLID == null || pqc.pqc_SPLID == Guid.Empty)
                    {
                        result.boolValue = false;
                        result.messageText = "抽查數量不能為零。";
                        return result;
                    }

                    using (DBContext uow = DBContext.Begin())
                    {

                        ProjectQCRecord_pqc_Info pqc_old = uow.CurrentSession.Get<ProjectQCRecord_pqc_Info>(pqc.pqc_RecordID);
                        pqc_old.pqc_iQCQTY = pqc.pqc_iQCQTY;
                        pqc_old.pqc_dLastDate = DateTime.Now;
                        pqc_old.pqc_dQCEndTime = DateTime.Now;
                        uow.CurrentSession.Update(pqc_old);
                        //CountSPLQCInfo(uow, project, shiftProject);

                    }

                    result.boolValue = true;
                }
            }
            catch (Exception ex)
            {
                result.boolValue = false;
                result.messageText = ex.Message;
            }

            return result;
        }
예제 #16
0
파일: PLCBL.cs 프로젝트: Klutzdon/PBIMSN
        /// <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;
            }
        }
예제 #17
0
        /// <summary>
        /// 更新QC問題
        /// </summary>
        /// <param name="pqc"></param>
        /// <returns></returns>
        public ReturnValueInfo UpdateQCProblem(ProjectQCProblem_pqcp_Info problem, PrintProject_ppj_Info project, ShiftProjList_spl_Info shiftProject)
        {
            ReturnValueInfo result = new ReturnValueInfo();

            try
            {
                if (problem.pqcp_PQCID == Guid.Empty)
                {
                    result.boolValue = false;
                    result.messageText = "QC問題記錄沒有設置QC記錄ID,不能保存QC問題。";
                    return result;
                }
                if (problem.pqcp_iWasteQty == 0 && problem.pqcp_iDefectiveQty == 0)
                {
                    result.boolValue = false;
                    result.messageText = "QC廢品數量和次品數量不能同時為0。";
                    return result;
                }

                using (DBContext uow = DBContext.Begin())
                {
                    ProjectQCProblem_pqcp_Info pqcp_old = uow.CurrentSession.Get<ProjectQCProblem_pqcp_Info>(problem.pqcp_RecordID);
                    pqcp_old.pqcp_iProblemID = problem.pqcp_iProblemID;
                    pqcp_old.pqcp_iWasteQty = problem.pqcp_iWasteQty;
                    pqcp_old.pqcp_iDefectiveQty = problem.pqcp_iDefectiveQty;
                    pqcp_old.pqcp_dLastDate = DateTime.Now;
                    pqcp_old.pqcp_lSync = false;
                    uow.CurrentSession.Update(pqcp_old);
                    //CountSPLQCInfo(uow, project, shiftProject);
                }

                result.boolValue = true;

            }
            catch (Exception ex)
            {
                result.boolValue = false;
                result.messageText = ex.Message;
            }

            return result;
        }
예제 #18
0
파일: PLCBL.cs 프로젝트: Klutzdon/PBIMSN
        /// <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;
            }
        }
예제 #19
0
        public ShiftProjList_spl_Info SetCurrentShiftProj(PrintProject_ppj_Info project, ShiftInfo_sifo_Info shiftInfo)
        {
            ShiftProjList_spl_Info spl = null;
            try
            {
                if (project != null && project.ppj_RecordID != Guid.Empty)
                {
                    using (DBContext uow = DBContext.Begin())
                    {

                        if (shiftInfo != null && shiftInfo.sifo_RecordID != Guid.Empty)
                        {
                            spl = new ShiftProjList_spl_Info();
                            spl.spl_RecordID = Guid.NewGuid();
                            spl.spl_SIFOID = shiftInfo.sifo_RecordID;
                            spl.spl_PPJID = project.ppj_RecordID;
                            spl.spl_dBeginTime = DateTime.Now;
                            spl.spl_dAddDate = DateTime.Now;
                            spl.spl_iBeginQTY = project.ppj_iCountProdNum;
                            uow.CurrentSession.Save(spl);
                        }

                    }

                }
            }
            catch (Exception ex)
            {
                spl = null;
                Common.General.BLLoger.Info(ex);
            }
            return spl;
        }
예제 #20
0
파일: PLCBL.cs 프로젝트: Klutzdon/PBIMSN
        /// <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;
            }
        }
예제 #21
0
 /// <summary>
 /// 班次內工程正常生產時間=總運作時間-準備時間-停機時間-用餐時間
 /// </summary>
 /// <param name="db"></param>
 /// <param name="spl"></param>
 /// <returns></returns>
 public static int ShiftProjectProdTime(DBContext db, ShiftProjList_spl_Info spl)
 {
     int total = 0;
     if (db != null && spl != null)
     {
         var splDinnerQuery = db.CurrentSession.QueryOver<DinnerRecord_dnr_Info>();
         splDinnerQuery.And(d => d.dsm_splID == spl.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);
         total = ShiftProjectRunTime(spl) - spl.spl_iPrepairTime - spl.spl_iStopTime - splDinnerTime;
     }
     return total;
 }
예제 #22
0
파일: PLCBL.cs 프로젝트: Klutzdon/PBIMSN
        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;
        }
예제 #23
0
        /// <summary>
        /// 班次內工程合計生產時間
        /// </summary>
        /// <param name="db"></param>
        /// <param name="spl"></param>
        /// <returns></returns>
        public static int ShiftProjectActualPrepairTime(DBContext db, ShiftProjList_spl_Info spl)
        {
            int total = 0;
            if (db != null && spl != null && spl.spl_dProdBegin.HasValue)
            {
                int totalPrepare = (int)(spl.spl_dProdBegin.Value - spl.spl_dBeginTime).TotalSeconds;

                var prepareDinnerQuery = db.CurrentSession.QueryOver<DinnerRecord_dnr_Info>().And(d => d.dsm_ppjID == spl.spl_PPJID);
                prepareDinnerQuery.And(d => d.dsm_splID == spl.spl_RecordID);
                prepareDinnerQuery.And(d => d.dsm_cProjectStatus == CustEnum.ProjectStatus.PREPARE.ToString());
                total = totalPrepare - (int)prepareDinnerQuery.And(d => d.dnr_DSMID != Guid.Empty).List().Sum(d => (d.dnr_dEndTime.Value - d.dnr_dBeginTime.Value).TotalSeconds);
            }
            return total;
        }
예제 #24
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="shiftIDs"></param>
        /// <returns></returns>
        public List<ShiftProjList_spl_Info> GetShiftProjList(List<string> shiftIDs)
        {
            try
            {
                List<ShiftProjList_spl_Info> data = new List<ShiftProjList_spl_Info>();
                StringBuilder strSql = new StringBuilder();
                strSql.AppendLine("select ");
                strSql.AppendLine("spl_RecordID,spl_PPJID,spl_SIFOID,spl_dBeginTime,spl_dEndTime,spl_dProdBegin,spl_iBeginQTY,spl_iEndQTY,spl_iCalQTY,spl_iQTY,spl_iPrepairTime,spl_iStopTime,spl_iStopTimes,spl_iRunTime,spl_iProdSumTime,spl_iQCTime,spl_iQCTimes,spl_iWastQTY,spl_iPalletQty,spl_lSync,spl_dAddDate,spl_dLastDate,spl_iDefectiveQty ");
                strSql.AppendLine("from ShiftProjList_spl ");
                if (shiftIDs != null && shiftIDs.Count > 0)
                {
                    StringBuilder where = new StringBuilder();
                    where.AppendLine("where ");
                    foreach (string id in shiftIDs)
                    {
                        where.AppendLine("spl_SIFOID='" + id + "' or");
                    }
                    strSql.AppendLine(where.ToString().Remove(where.Length - 4));
                }
                using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString()))
                {
                    while (sdr.Read())
                    {
                        ShiftProjList_spl_Info model = new ShiftProjList_spl_Info();

                        if (sdr["spl_RecordID"] != null && sdr["spl_RecordID"].ToString() != "")
                        {
                            model.spl_RecordID = new Guid(sdr["spl_RecordID"].ToString());
                        }
                        if (sdr["spl_PPJID"] != null && sdr["spl_PPJID"].ToString() != "")
                        {
                            model.spl_PPJID = new Guid(sdr["spl_PPJID"].ToString());
                        }
                        if (sdr["spl_SIFOID"] != null && sdr["spl_SIFOID"].ToString() != "")
                        {
                            model.spl_SIFOID = new Guid(sdr["spl_SIFOID"].ToString());
                        }
                        if (sdr["spl_dBeginTime"] != null && sdr["spl_dBeginTime"].ToString() != "")
                        {
                            model.spl_dBeginTime = DateTime.Parse(sdr["spl_dBeginTime"].ToString());
                        }
                        if (sdr["spl_dEndTime"] != null && sdr["spl_dEndTime"].ToString() != "")
                        {
                            model.spl_dEndTime = DateTime.Parse(sdr["spl_dEndTime"].ToString());
                        }
                        if (sdr["spl_dProdBegin"] != null && sdr["spl_dProdBegin"].ToString() != "")
                        {
                            model.spl_dProdBegin = DateTime.Parse(sdr["spl_dProdBegin"].ToString());
                        }
                        if (sdr["spl_iBeginQTY"] != null && sdr["spl_iBeginQTY"].ToString() != "")
                        {
                            model.spl_iBeginQTY = int.Parse(sdr["spl_iBeginQTY"].ToString());
                        }
                        if (sdr["spl_iEndQTY"] != null && sdr["spl_iEndQTY"].ToString() != "")
                        {
                            model.spl_iEndQTY = int.Parse(sdr["spl_iEndQTY"].ToString());
                        }
                        if (sdr["spl_iCalQTY"] != null && sdr["spl_iCalQTY"].ToString() != "")
                        {
                            model.spl_iCalQTY = int.Parse(sdr["spl_iCalQTY"].ToString());
                        }
                        if (sdr["spl_iQTY"] != null && sdr["spl_iQTY"].ToString() != "")
                        {
                            model.spl_iQTY = int.Parse(sdr["spl_iQTY"].ToString());
                        }
                        if (sdr["spl_iPrepairTime"] != null && sdr["spl_iPrepairTime"].ToString() != "")
                        {
                            model.spl_iPrepairTime = int.Parse(sdr["spl_iPrepairTime"].ToString());
                        }
                        if (sdr["spl_iStopTime"] != null && sdr["spl_iStopTime"].ToString() != "")
                        {
                            model.spl_iStopTime = int.Parse(sdr["spl_iStopTime"].ToString());
                        }
                        if (sdr["spl_iStopTimes"] != null && sdr["spl_iStopTimes"].ToString() != "")
                        {
                            model.spl_iStopTimes = int.Parse(sdr["spl_iStopTimes"].ToString());
                        }
                        if (sdr["spl_iRunTime"] != null && sdr["spl_iRunTime"].ToString() != "")
                        {
                            model.spl_iRunTime = int.Parse(sdr["spl_iRunTime"].ToString());
                        }
                        if (sdr["spl_iProdSumTime"] != null && sdr["spl_iProdSumTime"].ToString() != "")
                        {
                            model.spl_iProdSumTime = int.Parse(sdr["spl_iProdSumTime"].ToString());
                        }
                        if (sdr["spl_iQCTime"] != null && sdr["spl_iQCTime"].ToString() != "")
                        {
                            model.spl_iQCTime = int.Parse(sdr["spl_iQCTime"].ToString());
                        }
                        if (sdr["spl_iQCTimes"] != null && sdr["spl_iQCTimes"].ToString() != "")
                        {
                            model.spl_iQCTimes = int.Parse(sdr["spl_iQCTimes"].ToString());
                        }
                        if (sdr["spl_iWastQTY"] != null && sdr["spl_iWastQTY"].ToString() != "")
                        {
                            model.spl_iWastQTY = int.Parse(sdr["spl_iWastQTY"].ToString());
                        }
                        if (sdr["spl_iPalletQty"] != null && sdr["spl_iPalletQty"].ToString() != "")
                        {
                            model.spl_iPalletQty = int.Parse(sdr["spl_iPalletQty"].ToString());
                        }
                        if (sdr["spl_lSync"] != null && sdr["spl_lSync"].ToString() != "")
                        {
                            if ((sdr["spl_lSync"].ToString() == "1") || (sdr["spl_lSync"].ToString().ToLower() == "true"))
                            {
                                model.spl_lSync = true;
                            }
                            else
                            {
                                model.spl_lSync = false;
                            }
                        }
                        if (sdr["spl_dAddDate"] != null && sdr["spl_dAddDate"].ToString() != "")
                        {
                            model.spl_dAddDate = DateTime.Parse(sdr["spl_dAddDate"].ToString());
                        }
                        if (sdr["spl_dLastDate"] != null && sdr["spl_dLastDate"].ToString() != "")
                        {
                            model.spl_dLastDate = DateTime.Parse(sdr["spl_dLastDate"].ToString());
                        }
                        if (sdr["spl_iDefectiveQty"] != null && sdr["spl_iDefectiveQty"].ToString() != "")
                        {
                            model.spl_iDefectiveQty = int.Parse(sdr["spl_iDefectiveQty"].ToString());
                        }
                        data.Add(model);
                    }
                }
                return data;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }