private void CmdHandle(EquPDCYJUnloadCmd input) { Task task = new Task((state) => { EquPDCYJUnloadCmd pDCYJUnloadCmd = state as EquPDCYJUnloadCmd; OutputRunInfo(rtxtOutput, "处理卸样命令,采样码:" + pDCYJUnloadCmd.SampleCode); // 更新系统状态为正在卸样 dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJSignal>() + " set TagValue=@TagValue where MachineCode=@MachineCode and TagName=@TagName", new { MachineCode = pDCYJUnloadCmd.MachineCode, TagName = eSignalDataName.设备状态.ToString(), TagValue = eEquInfSamplerSystemStatus.正在卸样.ToString() }); Thread.Sleep(3000); foreach (EquPDCYJBarrel pDCYJBarrel in dber.Entities <EquPDCYJBarrel>("where SampleCode=@SampleCode", new { SampleCode = pDCYJUnloadCmd.SampleCode })) { // 生成卸样结果 dber.Insert(new EquPDCYJUnloadResult { DataFlag = 0, SampleCode = pDCYJUnloadCmd.SampleCode, UnloadTime = DateTime.Now, //BarrelNumber = pDCYJBarrel.BarrelNumber, BarrelCode = Guid.NewGuid().ToString().Substring(0, 8).ToUpper(), //SamplingId = pDCYJUnloadCmd.SamplingId, MachineCode = pDCYJBarrel.MachineCode }); pDCYJBarrel.SampleCount = 0; pDCYJBarrel.InFactoryBatchId = string.Empty; pDCYJBarrel.SampleCode = string.Empty; pDCYJBarrel.BarrelStatus = eSampleBarrelStatus.空桶.ToString(); pDCYJBarrel.UpdateTime = DateTime.Now; pDCYJBarrel.DataFlag = 0; if (dber.Update(pDCYJBarrel) > 0) { OutputRunInfo(rtxtOutput, "卸样完成,罐号:" + pDCYJBarrel.BarrelNumber.ToString() + " " + pDCYJBarrel.BarrelType.ToString()); } Thread.Sleep(1500); } // 更新命令 pDCYJUnloadCmd.ResultCode = eEquInfCmdResultCode.成功.ToString(); pDCYJUnloadCmd.DataFlag = 2; dber.Update(pDCYJUnloadCmd); OutputRunInfo(rtxtOutput, "卸样完成"); autoResetEvent.Set(); }, input); task.Start(); }
private void btnUnLoad_Click(object sender, EventArgs e) { try { EquPDCYJUnloadCmd cmd = new EquPDCYJUnloadCmd(); cmd.MachineCode = cmbBeltSampler.Text; cmd.SampleCode = txt_SampleCode.Text; cmd.ResultCode = "默认"; cmd.DataFlag = 0; if (this.dber.Insert(cmd) > 0) { OutputRunInfo(rtxtOutput, "发送成功"); } } catch (Exception ex) { OutputRunInfo(rtxtOutput, "发送失败:" + ex.Message, eOutputType.Error); } }
private void CreateMainTask() { taskSimpleScheduler = new TaskSimpleScheduler(); autoResetEvent.Reset(); taskSimpleScheduler.StartNewTask("模拟业务", () => { if (!this.IsStartSimulator) { return; } // 心跳 dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJSignal>() + " set TagValue=@TagValue where TagName=@TagName", new { TagName = GlobalVars.EquHeartbeatName, TagValue = DateTime.Now.ToString() }); // 更新采样计划 dber.Execute("update " + EntityReflectionUtil.GetTableName <EquPDCYJPlan>() + " set DataFlag=1 where DataFlag=0"); // 控制命令 EquPDCYJCmd pDCYJCmd = dber.Entity <EquPDCYJCmd>("where DataFlag=0 order by CreateDate desc"); if (pDCYJCmd != null) { CmdHandle(pDCYJCmd); autoResetEvent.WaitOne(); } // 卸样命令 EquPDCYJUnloadCmd pDCYJUnloadCmd = dber.Entity <EquPDCYJUnloadCmd>("where DataFlag=0 order by CreateDate desc"); if (pDCYJUnloadCmd != null) { CmdHandle(pDCYJUnloadCmd); autoResetEvent.WaitOne(); } }, 3000); }
/// <summary> /// 同步卸样命令 /// </summary> /// <param name="output"></param> /// <returns></returns> public void SyncUnloadCmd(Action <string, eOutputType> output) { int res = 0; // 集中管控 > 第三方 foreach (InfBeltSampleUnloadCmd entity in BeltSamplerDAO.GetInstance().GetWaitForSyncBeltSampleUnloadCmd(Type == "入场" ? GlobalVars.InterfaceType_PDCYJ_In : GlobalVars.InterfaceType_PDCYJ_Out)) { bool isSuccess = false; EquPDCYJUnloadCmd pDCYUnloadCMD = this.EquDber.Get <EquPDCYJUnloadCmd>(entity.Id); if (pDCYUnloadCMD == null) { isSuccess = this.EquDber.Insert(new EquPDCYJUnloadCmd { // 保持相同的Id Id = entity.Id, DataFlag = 0, CreateDate = entity.CreateDate, SampleCode = entity.SampleCode, MachineCode = ConvertToInfMachineCode(entity.MachineCode), ResultCode = eEquInfCmdResultCode.默认.ToString(), SamplingId = entity.SamplingId }) > 0; } else { isSuccess = true; } if (isSuccess) { entity.SyncFlag = 1; Dbers.GetInstance().SelfDber.Update(entity); res++; } } output(string.Format("同步卸样命令 {0} 条(集中管控 > 第三方)", res), eOutputType.Normal); res = 0; // 第三方 > 集中管控 foreach (EquPDCYJUnloadCmd entity in this.EquDber.Entities <EquPDCYJUnloadCmd>("where DataFlag=2 and datediff(dd,CreateDate,getdate())=0")) { InfBeltSampleUnloadCmd beltSampleUnloadCmd = commonDAO.SelfDber.Get <InfBeltSampleUnloadCmd>(entity.Id); if (beltSampleUnloadCmd == null) { continue; } // 更新执行结果等 beltSampleUnloadCmd.ResultCode = entity.ResultCode; beltSampleUnloadCmd.DataFlag = 3; if (Dbers.GetInstance().SelfDber.Update(beltSampleUnloadCmd) > 0) { // 我方已读 entity.DataFlag = 3; this.EquDber.Update(entity); res++; } } output(string.Format("同步卸样命令 {0} 条(第三方 > 集中管控)", res), eOutputType.Normal); }