Beispiel #1
0
        /// <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);
        }