Esempio n. 1
0
 private void btnSendPlan_Click(object sender, EventArgs e)
 {
     try
     {
         EquPDCYJPlan plan = this.dber.Entity <EquPDCYJPlan>("where SampleCode=@SampleCode order by CreateDate desc", new { SampleCode = this.txt_SampleCode.Text });
         if (plan != null)
         {
             OutputRunInfo(rtxtOutput, "该采样编码计划已存在");
             return;
         }
         plan            = new EquPDCYJPlan();
         plan.SampleCode = txt_SampleCode.Text;
         plan.GatherType = cmbSampleType.Text;
         plan.StartTime  = DateTime.Now;
         plan.SampleUser = "******";
         plan.DataFlag   = 0;
         if (this.dber.Insert(plan) > 0)
         {
             OutputRunInfo(rtxtOutput, "发送成功");
         }
     }
     catch (Exception ex)
     {
         OutputRunInfo(rtxtOutput, "发送失败:" + ex.Message, eOutputType.Error);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 同步卸样结果,根据卸样信息生成集控采样桶记录
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public void SyncUnloadResult(Action <string, eOutputType> output)
        {
            int res = 0;

            foreach (EquPDCYJUnloadResult pDCYJUnloadResult in this.EquDber.Entities <EquPDCYJUnloadResult>("where DataFlag=0"))
            {
                InfBeltSamplerUnloadResult oldUnloadResult = commonDAO.SelfDber.Get <InfBeltSamplerUnloadResult>(pDCYJUnloadResult.Id);
                if (oldUnloadResult == null)
                {
                    // 查找采样计划
                    EquPDCYJPlan pDCYJPlan = this.EquDber.Entity <EquPDCYJPlan>("where SampleCode=@SampleCode", new { SampleCode = pDCYJUnloadResult.SampleCode });
                    if (pDCYJPlan != null)
                    {
                        // 生成采样桶记录
                        CmcsRCSampleBarrel rCSampleBarrel = new CmcsRCSampleBarrel()
                        {
                            SampleCode       = pDCYJUnloadResult.SampleCode,
                            BarrelCode       = pDCYJUnloadResult.BarrelCode,
                            BarrellingTime   = pDCYJUnloadResult.UnloadTime,
                            InFactoryBatchId = pDCYJPlan.InFactoryBatchId,
                            SampleMachine    = commonDAO.GetMachineNameByCode(ConvertToCmcsMachineCode(pDCYJUnloadResult.MachineCode)),
                            SampleType       = eSamplingType.皮带采样.ToString(),
                            SamplingId       = pDCYJUnloadResult.SamplingId
                        };

                        if (commonDAO.SelfDber.Insert(rCSampleBarrel) > 0)
                        {
                            // 同步卸样结果
                            if (commonDAO.SelfDber.Insert(new InfBeltSamplerUnloadResult
                            {
                                MachineCode = ConvertToCmcsMachineCode(pDCYJUnloadResult.MachineCode),
                                SampleCode = pDCYJUnloadResult.SampleCode,
                                DataFlag = pDCYJUnloadResult.DataFlag,
                                BarrelCode = pDCYJUnloadResult.BarrelCode,
                                UnloadTime = pDCYJUnloadResult.UnloadTime,
                                SamplingId = pDCYJUnloadResult.SamplingId
                            }) > 0)
                            {
                                pDCYJUnloadResult.DataFlag = 1;
                                this.EquDber.Update(pDCYJUnloadResult);

                                res++;
                            }
                        }
                    }
                }
            }

            output(string.Format("同步卸样结果 {0} 条", res), eOutputType.Normal);
        }
Esempio n. 3
0
        private void CmdHandle(EquPDCYJCmd input)
        {
            Task task = new Task((state) =>
            {
                EquPDCYJCmd pDCYJCmd = state as EquPDCYJCmd;
                OutputRunInfo(rtxtOutput, "处理命令,命令代码:" + pDCYJCmd.CmdCode + "  采样码:" + pDCYJCmd.SampleCode);

                if (pDCYJCmd.CmdCode == eEquInfSamplerCmd.开始采样.ToString())
                {
                    EquPDCYJPlan pDCYJPlan = dber.Entity <EquPDCYJPlan>("where SampleCode=@SampleCode", new { SampleCode = pDCYJCmd.SampleCode });
                    if (pDCYJPlan != null)
                    {
                        Thread.Sleep(3000);
                        OutputRunInfo(rtxtOutput, "启动采样机");
                        // 更新系统状态为正在运行
                        dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJSignal>() + " set TagValue=@TagValue where MachineCode=@MachineCode and TagName=@TagName", new { MachineCode = pDCYJCmd.MachineCode, TagName = eSignalDataName.设备状态.ToString(), TagValue = eEquInfSamplerSystemStatus.正在运行.ToString() });

                        // 更新集样罐
                        dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJBarrel>() + " set IsCurrent=0 where MachineCode=@MachineCode and BarrelType=@BarrelType", new { MachineCode = pDCYJCmd.MachineCode, BarrelType = pDCYJPlan.GatherType });
                        EquPDCYJBarrel pDCYJBarrel = dber.Entity <EquPDCYJBarrel>("where MachineCode=@MachineCode and SampleCode=@SampleCode and BarrelType=@BarrelType and SampleCount<3", new { MachineCode = pDCYJCmd.MachineCode, SampleCode = pDCYJCmd.SampleCode, BarrelType = pDCYJPlan.GatherType });
                        if (pDCYJBarrel == null)
                        {
                            pDCYJBarrel = dber.Entity <EquPDCYJBarrel>("where MachineCode=@MachineCode and SampleCode='' and BarrelType=@BarrelType", new { MachineCode = pDCYJCmd.MachineCode, BarrelType = pDCYJPlan.GatherType });
                            if (pDCYJBarrel != null)
                            {
                                OutputRunInfo(rtxtOutput, "分配集样罐,罐号:" + pDCYJBarrel.BarrelNumber + "  " + pDCYJBarrel.BarrelType);

                                pDCYJBarrel.SampleCount      = 1;
                                pDCYJBarrel.SampleCode       = pDCYJCmd.SampleCode;
                                pDCYJBarrel.InFactoryBatchId = pDCYJPlan.InFactoryBatchId;
                                pDCYJBarrel.IsCurrent        = 1;
                                pDCYJBarrel.BarrelStatus     = eSampleBarrelStatus.未满.ToString();
                                pDCYJBarrel.UpdateTime       = DateTime.Now;
                                pDCYJBarrel.DataFlag         = 0;
                                dber.Update(pDCYJBarrel);
                            }
                        }
                        else
                        {
                            OutputRunInfo(rtxtOutput, "分配集样罐,罐号:" + pDCYJBarrel.BarrelNumber + " " + pDCYJBarrel.BarrelType);

                            pDCYJBarrel.SampleCount++;
                            pDCYJBarrel.IsCurrent    = 1;
                            pDCYJBarrel.BarrelStatus = eSampleBarrelStatus.未满.ToString();
                            pDCYJBarrel.UpdateTime   = DateTime.Now;
                            pDCYJBarrel.DataFlag     = 0;
                            dber.Update(pDCYJBarrel);
                        }

                        // 更新计划
                        pDCYJPlan.StartTime = DateTime.Now;
                        dber.Update(pDCYJPlan);

                        // 更新命令
                        pDCYJCmd.ResultCode = eEquInfCmdResultCode.成功.ToString();
                        pDCYJCmd.DataFlag   = 2;
                        dber.Update(pDCYJCmd);
                    }
                    else
                    {
                        OutputRunInfo(rtxtOutput, "未找到采样计划,采样码:" + pDCYJCmd.SampleCode);

                        pDCYJCmd.ResultCode = eEquInfCmdResultCode.失败.ToString();
                        pDCYJCmd.DataFlag   = 1;
                        dber.Update(pDCYJCmd);
                    }
                }
                else if (pDCYJCmd.CmdCode == eEquInfSamplerCmd.结束采样.ToString())
                {
                    Thread.Sleep(3000);
                    OutputRunInfo(rtxtOutput, "停止采样机");

                    // 更新系统状态为就绪待机
                    dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJSignal>() + " set TagValue=@TagValue where MachineCode=@MachineCode and TagName=@TagName", new { MachineCode = pDCYJCmd.MachineCode, TagName = eSignalDataName.序状态.ToString(), TagValue = eEquInfSamplerSystemStatus.就绪待机.ToString() });

                    EquPDCYJPlan pDCYJPlan = dber.Entity <EquPDCYJPlan>("where SampleCode=@SampleCode", new { SampleCode = pDCYJCmd.SampleCode });
                    if (pDCYJPlan != null)
                    {
                        // 更新计划
                        pDCYJPlan.SampleUser = "******";
                        pDCYJPlan.StartTime  = DateTime.Now.AddSeconds(10);
                        pDCYJPlan.EndTime    = DateTime.Now;
                        dber.Update(pDCYJPlan);
                    }

                    // 更新命令
                    pDCYJCmd.ResultCode = eEquInfCmdResultCode.成功.ToString();
                    pDCYJCmd.DataFlag   = 2;
                    dber.Update(pDCYJCmd);
                }

                autoResetEvent.Set();
            }, input);

            task.Start();
        }
Esempio n. 4
0
        /// <summary>
        /// 同步采样计划
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public void SyncPlan(Action <string, eOutputType> output)
        {
            int res = 0;

            // 集中管控 > 第三方
            foreach (InfBeltSamplePlan entity in BeltSamplerDAO.GetInstance().GetWaitForSyncBeltSamplePlan(Type == "入场" ? GlobalVars.InterfaceType_PDCYJ_In : GlobalVars.InterfaceType_PDCYJ_Out))
            {
                bool isSuccess = false;

                EquPDCYJPlan pDCYPlan = this.EquDber.Get <EquPDCYJPlan>(entity.Id);
                if (pDCYPlan == null)
                {
                    isSuccess = this.EquDber.Insert(new EquPDCYJPlan
                    {
                        // 保持相同的Id
                        Id               = entity.Id,
                        CarCount         = entity.CarCount,
                        DataFlag         = 0,
                        CreateDate       = entity.CreateDate,
                        InFactoryBatchId = entity.InFactoryBatchId,
                        Mt               = ConvertToInfMt(entity.Mt),
                        SampleCode       = entity.SampleCode,
                        GatherType       = entity.GatherType,
                        TicketWeight     = entity.TicketWeight
                    }) > 0;
                }
                else
                {
                    pDCYPlan.CarCount         = entity.CarCount;
                    pDCYPlan.DataFlag         = 0;
                    pDCYPlan.CreateDate       = entity.CreateDate;
                    pDCYPlan.InFactoryBatchId = entity.InFactoryBatchId;
                    pDCYPlan.Mt           = ConvertToInfMt(entity.Mt);
                    pDCYPlan.SampleCode   = entity.SampleCode;
                    pDCYPlan.GatherType   = entity.GatherType;
                    pDCYPlan.TicketWeight = entity.TicketWeight;

                    isSuccess = this.EquDber.Update(pDCYPlan) > 0;
                }

                if (isSuccess)
                {
                    entity.SyncFlag = 1;
                    Dbers.GetInstance().SelfDber.Update(entity);

                    res++;
                }
            }
            output(string.Format("同步采样计划 {0} 条(集中管控 > 第三方)", res), eOutputType.Normal);

            res = 0;
            // 第三方 > 集中管控
            foreach (EquPDCYJPlan entity in this.EquDber.Entities <EquPDCYJPlan>("where DataFlag=2 and datediff(dd,CreateDate,getdate())=0"))
            {
                InfBeltSamplePlan beltSamplePlan = Dbers.GetInstance().SelfDber.Get <InfBeltSamplePlan>(entity.Id);
                if (beltSamplePlan == null)
                {
                    continue;
                }

                // 更新采样开始、结束时间、采样员等
                beltSamplePlan.StartTime  = entity.StartTime;
                beltSamplePlan.EndTime    = entity.EndTime;
                beltSamplePlan.SampleUser = entity.SampleUser;

                if (Dbers.GetInstance().SelfDber.Update(beltSamplePlan) > 0)
                {
                    // 我方已读
                    entity.DataFlag = 3;
                    this.EquDber.Update(entity);

                    res++;
                }
            }
            output(string.Format("同步采样计划 {0} 条(第三方 > 集中管控)", res), eOutputType.Normal);
        }