/// <summary> /// 同步卸样命令 /// </summary> /// <param name="output"></param> /// <returns></returns> public void SyncJXCYControlUnloadCMD(Action <string, eOutputType> output) { int res = 0; // 集中管控 > 第三方 foreach (InfQCJXCYUnLoadCMD entity in CarSamplerDAO.GetInstance().GetWaitForSyncJXCYSampleUnloadCmd(MachineCode)) { bool isSuccess = false; //同步卸样命令 KY_CYJ_OutRun outrun = this.EquDber.Entity <KY_CYJ_OutRun>(" where CYJ_Machine=@CYJ_Machine", new { CYJ_Machine = DataToKYMachine(this.MachineCode) }); if (outrun == null) { outrun = new KY_CYJ_OutRun(); outrun.CYJ_Machine = DataToKYMachine(this.MachineCode); outrun.CY_Code = entity.SampleCode; outrun.CY_Type = "机械采样"; outrun.CY_Control = (int)eSamplingControl.卸料指令; outrun.Send_Time = DateTime.Now; isSuccess = this.EquDber.Insert(outrun) > 0; } else { outrun.CY_Code = entity.SampleCode; outrun.CY_Type = "机械采样"; outrun.CY_Control = (int)eSamplingControl.卸料指令; outrun.Send_Time = DateTime.Now; isSuccess = this.EquDber.Update(outrun) > 0; } string SqlWhere = "where CY_Code=@CY_Code"; if (entity.UnLoadType != "到制样机") { SqlWhere += " and Barrel_Code=@Barrel_Code"; } IList <KY_CYJ_BarrelStatus> barrel_codes = this.EquDber.Entities <KY_CYJ_BarrelStatus>(SqlWhere, new { CY_Code = entity.SampleCode, Barrel_Code = entity.BarrelNumber }); foreach (var item in barrel_codes) { KY_CYJ_Down down = this.EquDber.Entity <KY_CYJ_Down>("where Barrel_Code=@Barrel_Code", new { Barrel_Code = item.Barrel_Code }); if (down != null) { down.XL_Start = 1; down.XL_Finish = 0; down.Down_Type = entity.UnLoadType == "到制样机" ? "0" : "1"; this.EquDber.Update(down); } } if (isSuccess) { entity.SyncFlag = 1; Dbers.GetInstance().SelfDber.Update(entity); res++; } } output(string.Format("同步卸样命令 {0} 条(集中管控 > 第三方)-{1}", res, this.MachineCode), eOutputType.Normal); }
/// <summary> /// 同步卸样操作结果 /// </summary> /// <param name="output"></param> public void SyncResult(Action <string, eOutputType> output) { int res = 0, res2 = 0; // 第三方 > 集中管控 卸样结果 foreach (InfQCJXCYUnLoadCMD item in Dbers.GetInstance().SelfDber.Entities <InfQCJXCYUnLoadCMD>("where MachineCode=:MachineCode and DataFlag=0", new { MachineCode = this.MachineCode })) { if (item.UnLoadType == "到制样机") { IList <KY_CYJ_BarrelStatus> barrelstatus = this.EquDber.Entities <KY_CYJ_BarrelStatus>("where CY_Code=@CY_Code order by Barrel_Code", new { CY_Code = item.SampleCode }); IList <KY_CYJ_Down> downlist = new List <KY_CYJ_Down>(); foreach (KY_CYJ_BarrelStatus barrel in barrelstatus) { KY_CYJ_Down down = this.EquDber.Entity <KY_CYJ_Down>("where Barrel_Code=@Barrel_Code and XL_Finish=1", new { Barrel_Code = barrel.Barrel_Code }); if (down != null) { downlist.Add(down); } } if (downlist.Count == barrelstatus.Count) { foreach (KY_CYJ_Down entity in downlist) { //历史卸样结果 InfQCJXCYJUnloadResult oldUnloadResult = commonDAO.SelfDber.Entity <InfQCJXCYJUnloadResult>("where SampleCode=:SampleCode and BarrelCode=:BarrelCode and UnLoadType=:UnLoadType and DataFlag=0", new { SampleCode = item.SampleCode, UnLoadType = item.UnLoadType, BarrelCode = entity.Barrel_Code }); if (oldUnloadResult == null) { // 生成采样桶记录 CmcsRCSampleBarrel rCSampleBarrel = new CmcsRCSampleBarrel(); rCSampleBarrel.BarrelCode = item.SampleCode; rCSampleBarrel.BarrellingTime = entity.LastDateTime; rCSampleBarrel.SampleCode = item.SampleCode; rCSampleBarrel.SampleMachine = this.MachineCode.Contains("#1") ? "#1汽车机械采样机" : "#2汽车机械采样机"; rCSampleBarrel.SampleType = eSamplingType.机械采样.ToString(); rCSampleBarrel.SampSecondCode = commonDAO.CreateSampleDetailCode(rCSampleBarrel.SampleCode); rCSampleBarrel.SamplingId = commonDAO.GetSamplingIdBySamplingCode(item.SampleCode); rCSampleBarrel.InFactoryBatchId = commonDAO.GetBatchIdByRCSamplingId(rCSampleBarrel.SamplingId); if (commonDAO.SelfDber.Insert(rCSampleBarrel) > 0) { if (commonDAO.SelfDber.Insert(new InfQCJXCYJUnloadResult { SampleCode = item.SampleCode, BarrelCode = entity.Barrel_Code, UnloadTime = entity.LastDateTime, UnLoadType = item.UnLoadType, DataFlag = 0 }) > 0) { res++; } } } } item.ResultCode = eEquInfCmdResultCode.成功.ToString(); item.DataFlag = 1; if (Dbers.GetInstance().SelfDber.Update(item) > 0) { // 我方已读 this.EquDber.Execute(string.Format("update {0} set XL_Start = 0,XL_Finish = 0,Read_Flag = 0 where XL_Finish=1", CMCS.DapperDber.Util.EntityReflectionUtil.GetTableName <KY_CYJ_Down>())); res2++; } } } else if (item.UnLoadType == "到归批机") { KY_CYJ_Down down = this.EquDber.Entity <KY_CYJ_Down>("where Barrel_Code=@Barrel_Code and XL_Finish=1", new { Barrel_Code = item.BarrelNumber }); if (down != null) { //历史卸样结果 InfQCJXCYJUnloadResult oldUnloadResult = commonDAO.SelfDber.Entity <InfQCJXCYJUnloadResult>("where SampleCode=:SampleCode and BarrelCode=:BarrelCode and UnLoadType=:UnLoadType and DataFlag=0", new { SampleCode = item.SampleCode, UnLoadType = item.UnLoadType, BarrelCode = item.BarrelNumber }); if (oldUnloadResult == null) { // 生成采样桶记录 CmcsRCSampleBarrel rCSampleBarrel = new CmcsRCSampleBarrel(); rCSampleBarrel.BarrelCode = item.SampleCode; rCSampleBarrel.SampSecondCode = commonDAO.CreateSampleDetailCode(item.SampleCode);; rCSampleBarrel.BarrellingTime = down.LastDateTime; rCSampleBarrel.SampleCode = item.SampleCode; rCSampleBarrel.SampSecondCode = commonDAO.CreateSampleDetailCode(rCSampleBarrel.SampleCode); rCSampleBarrel.SampleMachine = this.MachineCode.Contains("#1") ? "#1汽车机械采样机" : "#2汽车机械采样机"; rCSampleBarrel.SampleType = eSamplingType.机械采样.ToString(); rCSampleBarrel.SamplingId = commonDAO.GetSamplingIdBySamplingCode(item.SampleCode); rCSampleBarrel.InFactoryBatchId = commonDAO.GetBatchIdByRCSamplingId(rCSampleBarrel.SamplingId); if (commonDAO.SelfDber.Insert(rCSampleBarrel) > 0) { InfQCJXCYJUnloadResult unload = new InfQCJXCYJUnloadResult { SampleCode = item.SampleCode, BarrelCode = down.Barrel_Code, UnloadTime = down.LastDateTime, DataFlag = 0 }; if (commonDAO.SelfDber.Insert(unload) > 0) { res++; } } } item.ResultCode = eEquInfCmdResultCode.成功.ToString(); item.DataFlag = 1; if (Dbers.GetInstance().SelfDber.Update(item) > 0) { // 我方已读 this.EquDber.Execute(string.Format("update {0} set XL_Start = 0,XL_Finish = 0,Read_Flag = 0 where XL_Finish=1 and Barrel_Code='{1}'", CMCS.DapperDber.Util.EntityReflectionUtil.GetTableName <KY_CYJ_Down>(), item.BarrelNumber)); res2++; } } } } output(string.Format("同步历史卸样结果 {0} 条(第三方 > 集中管控)", res), eOutputType.Normal); output(string.Format("同步卸样结果 {0} 条(第三方 > 集中管控)", res2), eOutputType.Normal); }