public PEBagTrayCheckControl()
        {
            Command = new FAECInfo.BRAND_PEBAG_TRAY_CHECK_REQ();

            InitializeComponent();
        }
        private void MakeBarcodeScanProcess()
        {
            FAExtendECPart.ECResult ecResult = new FAExtendECPart.ECResult();

            var seq = BarcodeScanProcess;

            #region Regist Event
            seq.OnStart +=
                delegate
                {
                    JobStepIndex = 0;
                    RetryInfoScanRetry.ClearCount();
                    VisionJobNamePreFix = string.Empty;
                };
            #endregion

            #region Add Steps
            seq.Steps.Add("LoadJob", new StepInfo());
            seq.Steps.Add("GetStructOfBarcodes", new StepInfo());
            seq.Steps.Add("ChangeVisionJob", new StepInfo());
            seq.Steps.Add("Align", new StepInfo());
            seq.Steps.Add("ConfirmJobStepEnd", new StepInfo());
            seq.Steps.Add("ScanStep", new StepInfo());
            seq.Steps.Add("Scan", new StepInfo());
            seq.Steps.Add("IncreaseJobStep", new StepInfo());
            seq.Steps.Add("ConfirmScanResult", new StepInfo());
            seq.Steps.Add("ScanDataClear", new StepInfo());
            seq.Steps.Add("TurnOffLight", new StepInfo());
            seq.Steps.Add("ScanFailRetry", new StepInfo());
            seq.Steps.Add("StaticScanRetry", new StepInfo());
            #endregion

            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ProductInfo.VT8792ProductInfo.LotScanCompleted.ScanSuccess == false)
                        actor.NextStep("TurnOffLight");
                    else
                        actor.NextStep();
                });
            seq.Steps["LoadJob"].StepIndex = seq.AddItem(LoadJob);

            #region Action Before Scan
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ProductInfo.VT8792ProductInfo.TrayIndex == 1)
                    {
                        PassCount = 0;
                        FailCount = 0;
                        PEBagStartTime = DateTime.Now;

                        if (VT8792Equipment.GlobalConfigModule.UseGEMCommunication)
                        {
                            GEM.GEMFuncWrapper.SetPEBagStart(Equipment.Name,
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID,
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY,
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.PART_ID,
                                DateTime.Now);
                        }

                        JobStepIndex = 0;
                        Equipment.ProductOutput.TrackInLot(DateTime.Now, ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID);

                        if (AlwaysGetStructOfBarcodes)
                        {
                            LastPartIDOfProduct = string.Empty;
                            actor.NextStep("GetStructOfBarcodes");
                        }
                        else if (LastPartIDOfProduct == ProductInfo.ECInfo.PACKING_MASTER_INFO.PART_ID)
                        {
                            WriteTraceLog(string.Format("GetStructOfBarcodes Skip. LastPartID={0}, CurrentPartID{1}", LastPartIDOfProduct, ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID));
                            actor.NextStep("ChangeVisionJob");
                        }
                        else
                        {
                            WriteTraceLog(string.Format("GetStructOfBarcodes Start. LastPartID={0}, CurrentPartID{1}", LastPartIDOfProduct, ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID));
                            actor.NextStep("GetStructOfBarcodes");
                        }
                    }
                    else
                    {
                        if (CommonJobInfo.UsePositionCheck)
                            actor.NextStep("ChangeVisionJob");
                        else
                            actor.NextStep("Align");
                    }
                });
            seq.Steps["GetStructOfBarcodes"].StepIndex = seq.AddItem(GetStructOfBarcodes);
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (BarcodeStructScanFail)
                        actor.NextStep("TurnOffLight");
                    else
                        actor.NextStep();
                });
            seq.Steps["ChangeVisionJob"].StepIndex = seq.AddItem(ChangeVisionJob);
            seq.Steps["Align"].StepIndex = seq.AddItem(Aligner.Up.Sequence, Stopper.Up.Sequence);
            seq.AddItem(TimeAlignTime);
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ProductInfo.VT8792ProductInfo.TrayIndex > ProductInfo.VT8792ProductInfo.TrayCount)
                    {
                        Equipment.ProductOutput.TrackOutLot(DateTime.Now, ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID);
                        actor.NextTerminate();
                    }
                    else
                        actor.NextStep();
                });
            seq.AddItem(
                delegate(object obj)
                {
                    ProductInfo.SerialBarcodeInfo.SetBarcodeInfo(ProductInfo.ECInfo.LOT_CLOSE.SERIAL);
                    ProductInfo.PPIDBarcodeInfo.SetBarcodeInfo(ProductInfo.ECInfo.LOT_CLOSE.PPID);
                    ProductInfo.WWNBarcodeInfo.SetBarcodeInfo(ProductInfo.ECInfo.LOT_CLOSE.WWN);
                    ProductInfo.CSerialBarcodeInfo.SetBarcodeInfo(ProductInfo.ECInfo.LOT_CLOSE.C_SERIAL);
                    ProductInfo.PSIDBarcodeInfo.SetBarcodeInfo(ProductInfo.ECInfo.LOT_CLOSE.PSID);
                });

            seq.AddItem(VisionLight.DoTurnOn);
            seq.Steps["ScanDataClear"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    JobStepIndex = 0;
                    SSDScanFullResult.Clear();
                    SSDScanResultList.Clear();
                    ecResult.Clear();
                });
            #endregion

            seq.Steps["ConfirmJobStepEnd"].StepIndex = seq.AddItem(ConfirmJobStepEnd);
            seq.AddItem(SelectJobStepAction);

            #region ScanStep
            seq.Steps["ScanStep"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    SSDCountInTray = ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_X *
                        ProductInfo.ECInfo.PACKING_MASTER_INFO.TRAY_ARRAY_Y;

                    if (ProductInfo.VT8792ProductInfo.TrayIndex == ProductInfo.VT8792ProductInfo.TrayCount &&
                        ProductInfo.VT8792ProductInfo.RemainSSDCount != 0)
                    {
                        SSDCountInTray = ProductInfo.VT8792ProductInfo.RemainSSDCount;
                        actor.NextStep();
                    }
                    else
                        actor.NextStep();
                });
            seq.AddItem(SetRobotPositionFromJob);
            seq.AddItem(MoveRobot);
            #endregion

            seq.Steps["Scan"].StepIndex = seq.AddItem(Scan);
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN ||
                        Equipment.RunMode == FAFramework.Equipment.RunModeTypes.COLD_RUN)
                    {
                        actor.NextStep("IncreaseJobStep");
                    }
                    else
                        actor.NextStep();
                });

            #region ConfirmScanResult
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    var job = BarcodeScanJobInfo.Steps[JobStepIndex] as FASSDScanJobPositionMoveStep;
                    List<int> validCrossNumber, emptyPocketList;
                    GetValidCrossNumber(job.IndexList, SSDCountInTray, out validCrossNumber);
                    GetInvalidCrossNumber(job.IndexList, SSDCountInTray, out emptyPocketList);

                    var ssdScanResults = SSDScanResultList.Select(x => x).Where(x => validCrossNumber.Contains(x.Index));

                    ScanFailMessage = string.Empty;

                    if (validCrossNumber.Count == ssdScanResults.Count())
                    {
                        bool isScanFail = false;
                        List<SSDBarcodesInfo> barcodeInfoList = GetBarcodeInfoList(ssdScanResults, emptyPocketList, out isScanFail);

                        string emptyPocketCheckErrorMessage = string.Empty;
                        bool emptyPocketCheckResult = CheckEmptyPocketOfTray(SSDScanResultList, emptyPocketList, out emptyPocketCheckErrorMessage);

                        if (isScanFail || emptyPocketCheckResult == false)
                        {
                            if (RetryInfoScanRetry.IncreaseCount() == false)
                            {
                                ScanFailMessage += emptyPocketCheckErrorMessage;
                                actor.NextStep("ScanFailRetry");
                            }
                            else
                                actor.NextStep("StaticScanRetry");
                        }
                        else
                        {
                            foreach (var item in barcodeInfoList)
                            {
                                this.SSDScanFullResult.Add(item.Clone());
                            }

                            actor.NextStep();
                        }
                    }
                    else
                    {
                        ScanFailMessage = string.Format("Index Count Of Job is not match with scan result. Index count of job={0}, scan result index count={1}, JobStep={2}", validCrossNumber.Count, ssdScanResults.Count(), JobStepIndex);
                        WriteTraceLog(ScanFailMessage);

                        if (RetryInfoScanRetry.IncreaseCount() == false)
                        {
                            actor.NextStep("ScanFailRetry");
                        }
                        else
                            actor.NextStep("StaticScanRetry");
                    }
                });
            #endregion

            seq.AddItem("IncreaseJobStep");

            seq.Steps["IncreaseJobStep"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    if (BarcodeScanJobInfo.Steps.Count > JobStepIndex)
                    {
                        JobStepIndex++;
                    }
                });
            seq.AddItem("ConfirmJobStepEnd");

            seq.Steps["ConfirmScanResult"].StepIndex = seq.AddItem(ConfirmScanResult);

            #region PEBag
            seq.AddItem(
                delegate(object obj)
                {
                    FAECInfo.BRAND_PEBAG_TRAY_CHECK_REQ command = new FAECInfo.BRAND_PEBAG_TRAY_CHECK_REQ();
                    command.LOT_ID = ProductInfo.ECInfo.LOT_CLOSE.LOT_ID;
                    command.SSD_CNT = SSDCountInTray;

                    foreach (var item in this.SSDScanFullResult)
                    {
                        Utility.FAECInfo.PEBAG_TRAY_CHECK_ITEM info = new Utility.FAECInfo.PEBAG_TRAY_CHECK_ITEM();
                        info.PROD_SRLNO = item.PROD_SRLNO;
                        info.CUST_SRLNO = item.CUST_SRLNO;
                        info.WWN_SRLNO = item.WWN_SRLNO;
                        info.PIECE_PROD_ID = item.PIECE_PROD_ID;
                        info.PHYS_SECRTY_ID = item.PHYS_SECRTY_ID;
                        command.SERIAL_LIST.Add(info);
                    }

                    ecResult.Clear();
                    InterfaceUnit.ECPart.AddCommand(command, ecResult);
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ecResult.ReceiveOk)
                    {
                        if (ecResult.ParsingSuccess)
                        {
                            if (ecResult.ECInfo.BRAND_PEBAG_TRAY_CHECK.RESULT == FAECInfo.FAECResult.PASS)
                            {
                                WriteTraceLog("PACKING MASTER INFO RECEIVE OK");
                                ecResult.ECInfo.BRAND_PEBAG_TRAY_CHECK.CopyTo(ProductInfo.ECInfo.BRAND_PEBAG_TRAY_CHECK);
                                actor.NextStep();
                            }
                            else
                            {
                                ProductInfo.VT8792ProductInfo.LotScanCompleted.ScanCompleted = true;
                                ProductInfo.VT8792ProductInfo.LotScanCompleted.ScanSuccess = false;
                                ProductInfo.VT8792ProductInfo.LotScanCompleted.LotFailMessage = "EC PEBAG CHECK RESULT FAIL";

                                var msg = GetErrorMessageOfTrayPEBAGCheck(ProductInfo.VT8792ProductInfo.TrayIndex, ecResult.ECInfo.BRAND_PEBAG_TRAY_CHECK);
                                string windowName = string.Empty;
                                var alarm = Utility.AlarmUtility.GetAlarm(ecResult.LastAlarmNo, "[RF READER MODULE] PEBAG CHECK EC RESULT FAIL.");
                                Manager.MessageWindowManager.Instance.Show(Equipment,
                                    "TrayScanModuleECCommFail",
                                    out windowName,
                                    alarm,
                                    "[TRAY SCAN MODULE] TRAY SCAN FAIL\n" + msg,
                                    true);

                                actor.NextStep();
                            }
                        }
                        else
                        {
                            string windowName = string.Empty;
                            var alarm = Utility.AlarmUtility.GetAlarm(ecResult.LastAlarmNo, "[RF READER MODULE] EC PEBAG CHECK RECEIVE DATA PARSING FAIL.");
                            Manager.MessageWindowManager.Instance.Show(Equipment,
                                    "TrayScanModuleECCommFail",
                                    out windowName,
                                    alarm,
                                    string.Empty,
                                    true);
                            ProductInfo.VT8792ProductInfo.LotScanCompleted.ScanCompleted = true;
                            ProductInfo.VT8792ProductInfo.LotScanCompleted.ScanSuccess = false;
                            ProductInfo.VT8792ProductInfo.LotScanCompleted.LotFailMessage = "EC PEBAG CHECK RECEIVE DATA PARSING FAIL";
                            actor.NextStep();
                        }
                    }
                    else if (ecResult.LastAlarmNo != 0)
                    {
                        string windowName = string.Empty;
                        var alarm = Utility.AlarmUtility.GetAlarm(ecResult.LastAlarmNo, "[TRAY SCAN MODULE] EC PEBAG CHECK RECEIVE FAIL.");
                        Manager.MessageWindowManager.Instance.Show(Equipment,
                                    "TrayScanModuleECCommFail",
                                    out windowName,
                                    alarm,
                                    string.Empty,
                                    true);
                        ProductInfo.VT8792ProductInfo.LotScanCompleted.ScanCompleted = true;
                        ProductInfo.VT8792ProductInfo.LotScanCompleted.ScanSuccess = false;
                        ProductInfo.VT8792ProductInfo.LotScanCompleted.LotFailMessage = "EC PEBAG CHECK RECEIVE FAIL";
                        actor.NextStep();
                    }
                });
            #endregion

            #region Action Before Terminate
            seq.AddItem(
               delegate(object obj)
               {
                   PassCount += SSDCountInTray;

                   Equipment.ProductOutput.AddProduct(DateTime.Now,
                       ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID,
                       SSDCountInTray);
               });
            seq.Steps["TurnOffLight"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    VisionLight.DoTurnOff(obj);
                    Aligner.Down.Execute(obj);
                    Stopper.Down.Execute(obj);

                    if (ProductInfo.VT8792ProductInfo.TrayIndex == ProductInfo.VT8792ProductInfo.TrayCount)
                    {
                        if (VT8792Equipment.GlobalConfigModule.UseGEMCommunication)
                        {
                            FailCount = ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY - PassCount;
                            GEM.GEMFuncWrapper.SetPEBagEnd(Equipment.Name,
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID,
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_QTY,
                                ProductInfo.ECInfo.PACKING_MASTER_INFO.PART_ID,
                                PassCount,
                                FailCount,
                                DateTime.Now - PEBagStartTime,
                                DateTime.Now);
                        }

                        ProductInfo.VT8792ProductInfo.LotScanCompleted.ScanCompleted = true;
                    }
                });
            #endregion

            seq.AddTerminate();

            #region ScanFailRetry
            FAFramework.GUI.QuestionMessageBoxWindow questionWindow = null;
            seq.Steps["ScanFailRetry"].StepIndex = seq.AddItem(
                delegate(object obj)
                {
                    App.Current.Dispatcher.Invoke(
                        new Action(
                            delegate
                            {
                                questionWindow = new FAFramework.GUI.QuestionMessageBoxWindow();
                                questionWindow.Message = Utility.UtilityClass.GetStringResource(this, "VT8792.AreYouSureYouWantToScanRetry", "Are you sure you want to scan retry?") + "\n" + ScanFailMessage;
                                questionWindow.EquipmentInstance = Equipment;
                                questionWindow.Show();
                                Equipment.StateSignalModuleReferance.EquipmentStateConfigs.WarningStateConfig.CopyTo(
                                    Equipment.StateSignalModuleReferance.CustomState);
                                Equipment.StateSignalModuleReferance.CustomMode = true;

                            }), null);
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (questionWindow.Result == FAFramework.GUI.QuestionMessageBoxWindow.QuestionResult.Yes)
                    {
                        Equipment.StateSignalModuleReferance.CustomMode = false;
                        actor.NextStep();
                    }
                    else if (questionWindow.Result == FAFramework.GUI.QuestionMessageBoxWindow.QuestionResult.No)
                    {
                        Equipment.StateSignalModuleReferance.CustomMode = false;
                        ProductInfo.VT8792ProductInfo.LotScanCompleted.ScanCompleted = true;
                        ProductInfo.VT8792ProductInfo.LotScanCompleted.ScanSuccess = false;
                        actor.NextStep("TurnOffLight");
                    }
                });
            seq.AddItem(ChangeVisionJob);

            seq.Steps["StaticScanRetry"].StepIndex =
            seq.AddItem("Scan");
            #endregion
        }