public LBoxIssueControl()
        {
            Command = new FAECInfo.OEM_LBOX_ISSUE_REQ();

            InitializeComponent();
        }
        private void MakeAttachLabelToFoamPad()
        {
            #region SubAction
            List<Func<bool>> scanLabelActionList = new List<Func<bool>>();
            TimeSpan scanTimeout = new TimeSpan(0, 0, 2);
            DateTime scanStartTime = DateTime.Now;
            TimeSpan scanResultDelayTime = new TimeSpan(0, 0, 0, 0, 300);
            DateTime scanResultDelayStartTime = DateTime.Now;

            scanLabelActionList.Add(
                delegate
                {
                    BarcodeScanSuccess = false;
                    RobotUnit.BarcodeScanCompleted.DoTurnOff(this);
                    RobotUnit.ImageSensorScanSuccess.DoTurnOff(this);
                    RobotUnit.ImageSensorScanFail.DoTurnOff(this);
                    return true;
                });
            scanLabelActionList.Add(
                delegate
                {
                    if (PrinterControlModule.SelectedPrinter == FAPrinterControlModule.PrinterPosition.FrontPrinter)
                    {
                        if (RobotUnit.MovedToScanPosOnThePrinter2.IsOn)
                        {
                            scanStartTime = DateTime.Now;
                            RobotUnit.BarcodeScanner.TriggerOn(this);
                            return true;
                        }
                    }
                    else if (PrinterControlModule.SelectedPrinter == FAPrinterControlModule.PrinterPosition.RearPrinter)
                    {
                        if (RobotUnit.MovedToScanPosOnThePrinter1.IsOn)
                        {
                            scanStartTime = DateTime.Now;
                            RobotUnit.BarcodeScanner.TriggerOn(this);
                            return true;
                        }
                    }

                    return false;
                });
            scanLabelActionList.Add(
                delegate
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN ||
                        Equipment.RunMode == FAFramework.Equipment.RunModeTypes.COLD_RUN)
                    {
                        BarcodeScanSuccess = true;
                        RobotUnit.BarcodeScanCompleted.DoTurnOn(this);
                        return true;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(RobotUnit.BarcodeScanner.SmallBoxBarcode.Barcode) == false)
                        {
                            scanResultDelayStartTime = DateTime.Now;
                            BarcodeScanSuccess = true;
                            SmallBoxBarcode = RobotUnit.BarcodeScanner.SmallBoxBarcode.Barcode;
                            RobotUnit.ImageSensorScanSuccess.DoTurnOn(this);
                            return true;
                        }
                        else if (DateTime.Now - scanStartTime > scanTimeout)
                        {
                            scanResultDelayStartTime = DateTime.Now;
                            BarcodeScanSuccess = false;
                            RobotUnit.ImageSensorScanFail.DoTurnOn(this);
                            return true;
                        }

                        return false;
                    }
                });
            scanLabelActionList.Add(
                delegate
                {
                    if (DateTime.Now - scanResultDelayStartTime > scanResultDelayTime)
                    {
                        RobotUnit.BarcodeScanCompleted.DoTurnOn(this);
                        return true;
                    }

                    return false;
                });
            #endregion

            #region ScanAfterAttach
            string barcodeAfterAttachOnFoamPad = string.Empty;
            List<Func<bool>> scanLabelAfterAttachActionList = new List<Func<bool>>();
            TimeSpan scanLabelAfterAttachTimeout = new TimeSpan(0, 0, 2);
            DateTime scanLabelAfterAttachStartTime = DateTime.Now;

            scanLabelAfterAttachActionList.Add(
                delegate
                {
                    BarcodeScanSuccess = false;
                    barcodeAfterAttachOnFoamPad = string.Empty;
                    return true;
                });
            scanLabelAfterAttachActionList.Add(
                delegate
                {
                    if (RobotUnit.MovedToScanPosOnThePrinter1.IsOn)
                    {
                        scanLabelAfterAttachStartTime = DateTime.Now;
                        RobotUnit.BarcodeScanner.TriggerOn(this);
                        return true;
                    }
                    else if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN ||
                        Equipment.RunMode == FAFramework.Equipment.RunModeTypes.COLD_RUN)
                    {
                        return true;
                    }

                    return false;
                });
            scanLabelAfterAttachActionList.Add(
                delegate
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.DRY_RUN ||
                        Equipment.RunMode == FAFramework.Equipment.RunModeTypes.COLD_RUN)
                    {
                        BarcodeScanSuccess = true;
                        return true;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(RobotUnit.BarcodeScanner.SmallBoxBarcode.Barcode) == false)
                        {
                            BarcodeScanSuccess = true;
                            barcodeAfterAttachOnFoamPad = RobotUnit.BarcodeScanner.SmallBoxBarcode.Barcode;
                            return true;
                        }
                        else if (DateTime.Now - scanLabelAfterAttachStartTime > scanLabelAfterAttachTimeout)
                        {
                            BarcodeScanSuccess = false;
                            return true;
                        }

                        return false;
                    }
                });
            #endregion

            FAExtendECPart.ECResult ecResult = new FAExtendECPart.ECResult();

            var seq = AttachLabelToFoamPad;

            seq.OnStart +=
               delegate
               {
                   RetryInfoFoamPadLabel.ClearCount();
                   RetryInfoFoamPadLabelRemove.ClearCount();
                   RetryInfoCheckLabelAlign.ClearCount();
               };

            seq.Steps.Add("Start", new StepInfo());
            seq.Steps.Add("SetBarcodeScanActionCode", new StepInfo());
            seq.Steps.Add("RequestLBoxInfo", new StepInfo());
            seq.Steps.Add("LabelUnloadingCompleted", new StepInfo());
            seq.Steps.Add("AttachLabel", new StepInfo());
            seq.Steps.Add("RemoveLabel", new StepInfo());
            seq.Steps.Add("Retry", new StepInfo());

            seq.AddItem(MoveHomeToLabelPrinterPos);

            seq.Steps["Start"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (PrinterControlModule.UnloadingStandby && PrinterControlModule.LabelStep == FAPrinterControlModule.ELabelStep.SmallBoxLabel)
                    {
                        string sensorStatus = string.Empty;
                        if (PrinterControlModule.GetLabelAlignStatus(out sensorStatus) == true)
                            actor.NextStep("SetBarcodeScanActionCode");
                        else
                        {
                            WriteTraceLog("Small Box Label Align Fail. " + sensorStatus);
                            actor.NextStep();
                        }
                    }
                    else if (PrinterControlModule.LabelIssueFail && PrinterControlModule.ForceOutWhenLabelIssueFail)
                    {
                        ProductInfo.VT5081ProductInfo.ProductStatus = EProductStatus.Fail;
                        ProductInfo.VT5081ProductInfo.FailMessage = "Small Box Label Issue Fail";
                        actor.NextTerminate();
                    }
                });
            seq.AddItem(RemoveLabel);
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (RetryInfoCheckLabelAlign.IncreaseCount() == false)
                        RaiseAlarm(actor, AlarmLabelAlignCheckFail);

                    actor.NextStep();
                });
            seq.AddItem(
                delegate(object obj)
                {
                    PrinterControlModule.LabelScanSuccess = false;
                    PrinterControlModule.UnloadingCompleted = true;
                });
            seq.AddItem("Start");

            seq.Steps["SetBarcodeScanActionCode"].StepIndex = seq.AddItem(
                (object obj) =>
                {
                    RobotUnit.ImageSensorScanSuccess.DoTurnOff(this);
                    RobotUnit.ImageSensorScanFail.DoTurnOff(this);
                    RobotUnit.BarcodeScanCompleted.DoTurnOff(this);
                    RobotModule.SubActionList = scanLabelActionList;

                    if (PrinterControlModule.SelectedPrinter == FAPrinterControlModule.PrinterPosition.FrontPrinter)
                        RobotModule.SendData.ActionCode = (byte)FAKukaRobotCommandList.LabelActionList.EAction.PickLabelOnThePrinter2;
                    else
                        RobotModule.SendData.ActionCode = (byte)FAKukaRobotCommandList.LabelActionList.EAction.PickLabelOnThePrinter1;

                    RobotModule.UseFailReturn = true;
                });
            seq.AddItem(new FASequenceAtomicInfo(RobotModule.ExecuteAction, true));
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (BarcodeScanSuccess)
                    {
                        PrinterControlModule.LabelScanSuccess = true;
                        actor.NextStep();
                    }
                    else
                    {
                        actor.NextStep("RemoveLabel");
                    }
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (RobotModule.ReceiveData.ActionSuccess)
                    {
                        WriteTraceLog(string.Format("Small Box Scan Success. {0}", SmallBoxBarcode));
                        actor.NextStep();
                    }
                    else
                    {
                        WriteTraceLog("Small Box Scan Action Fail.");
                        actor.NextStep("RemoveLabel");
                    }
                });
            seq.Steps["RequestLBoxInfo"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.HOT_RUN)
                    {
                        FAECInfo.OEM_LBOX_ISSUE_REQ command = new FAECInfo.OEM_LBOX_ISSUE_REQ();
                        command.LOT_ID = ProductInfo.ECInfo.PACKING_MASTER_INFO.LOT_ID;
                        command.S_BOX_CNT = 1;
                        command.GATE = ProductInfo.ECInfo.PACKING_MASTER_INFO.GATE_NO;
                        command.S_BOX_LABEL_SERIAL = SmallBoxBarcode;
                        ecResult.Clear();
                        InterfaceUnit.ECPart.AddCommand(command, ecResult);
                        actor.NextStep();
                    }
                    else
                    {
                        actor.NextStep("LabelUnloadingCompleted");
                    }
                });
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (ecResult.ReceiveOk)
                    {
                        if (ecResult.ParsingSuccess)
                        {
                            if (ecResult.ECInfo.OEM_LBOX_ISSUE.RESULT == FAECInfo.FAECResult.PASS)
                            {
                                LargeBoxLabelIssueFail = false;
                                ecResult.ECInfo.OEM_LBOX_ISSUE.CopyTo(ProductInfo.ECInfo.OEM_LBOX_ISSUE);
                                ProductInfo.ECInfo.OEM_LBOX_ISSUE.CopyTo(PrinterControlModule.ProductInfo.ECInfo.OEM_LBOX_ISSUE);
                                actor.NextStep();
                            }
                            else
                            {
                                LargeBoxLabelIssueFail = true;

                                string msg = string.Format("MSG = {0}, Parsing Fail Message = {1}", ecResult.ECInfo.OEM_SBOX_ISSUE.MSG, ecResult.ParsingFailMessage);

                                if (PrinterControlModule.ForceOutWhenLabelIssueFail)
                                {
                                    ProductInfo.VT5081ProductInfo.ProductStatus = EProductStatus.Fail;
                                    ProductInfo.VT5081ProductInfo.FailMessage = msg;
                                    actor.NextStep();
                                }
                                else
                                {
                                    RaiseAlarm(actor, AlarmLargeBoxLabelIssueFail, msg);
                                    actor.NextStep("RequestLBoxInfo");
                                }
                            }
                        }
                        else
                        {
                            LargeBoxLabelIssueFail = true;

                            string msg = string.Format("Result Fail, Parsing Fail Message = {0}", ecResult.ParsingFailMessage);

                            if (PrinterControlModule.ForceOutWhenLabelIssueFail)
                            {
                                ProductInfo.VT5081ProductInfo.ProductStatus = EProductStatus.Fail;
                                ProductInfo.VT5081ProductInfo.FailMessage = msg;
                                actor.NextStep();
                            }
                            else
                            {
                                RaiseAlarm(actor, AlarmLargeBoxLabelIssueFail, msg);
                                actor.NextStep("RequestLBoxInfo");
                            }
                        }
                    }
                    else if (ecResult.LastAlarmNo != 0)
                    {
                        LargeBoxLabelIssueFail = true;

                        string msg = "Data Receive Fail";

                        if (PrinterControlModule.ForceOutWhenLabelIssueFail)
                        {
                            ProductInfo.VT5081ProductInfo.ProductStatus = EProductStatus.Fail;
                            ProductInfo.VT5081ProductInfo.FailMessage = msg;
                            actor.NextStep();
                        }
                        else
                        {
                            RaiseAlarm(actor, AlarmLargeBoxLabelIssueFail, "Data Receive Fail");
                            actor.NextStep("RequestLBoxInfo");
                        }
                    }
                });
            seq.Steps["LabelUnloadingCompleted"].StepIndex = seq.AddItem((object obj) => PrinterControlModule.UnloadingCompleted = true);
            seq.Steps["AttachLabel"].StepIndex = seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (BoxPuttingModule.LabelLoadingStandby)
                        actor.NextStep();
                });
            seq.AddItem(
                (object obj) =>
                {
                    BarcodeScanSuccess = false;
                    RobotModule.UseFailReturn = true;
                    RobotModule.SubActionList = scanLabelAfterAttachActionList;
                    RobotModule.SendData.Parameter = (byte)PrinterControlModule.SelectedPrinter;
                    RobotModule.SendData.ActionCode = (byte)FAKukaRobotCommandList.LabelActionList.EAction.AttachLabelToFoamPad;
                });
            seq.AddItem(new FASequenceAtomicInfo(RobotModule.ExecuteAction, true));
            seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (BarcodeScanSuccess)
                    {
                        if (barcodeAfterAttachOnFoamPad == SmallBoxBarcode)
                        {
                            WriteTraceLog(string.Format("Small Box Barcode On FoamPad Scan Success. {0}", barcodeAfterAttachOnFoamPad));
                            actor.NextStep();
                        }
                        else if (Equipment.RunMode == FAFramework.Equipment.RunModeTypes.HOT_RUN)
                        {
                            string msg = string.Format("Small Box Barcode Match Fail. Scan On The Label Block = {0}, Scan On The FoamPad = {1}",
                                SmallBoxBarcode, barcodeAfterAttachOnFoamPad);
                            WriteTraceLog(msg);
                            RaiseAlarm(actor, AlarmSmallBoxBarcodeMatchFail, msg);
                            actor.NextStep("AttachLabel");
                        }
                        else
                        {
                            WriteTraceLog(string.Format("Small Box Barcode On FoamPad Scan Success. {0}", barcodeAfterAttachOnFoamPad));
                            actor.NextStep();
                        }
                    }
                    else
                    {
                        RaiseAlarm(actor, AlarmScanFailSmallBoxBarcodeOnTheFoamPad);
                        actor.NextStep("AttachLabel");
                    }
                });
            seq.AddTerminate();

            seq.Steps["RemoveLabel"].StepIndex =seq.AddItem(
                delegate(FASequence actor, TimeSpan time)
                {
                    if (RetryInfoFoamPadLabelRemove.IncreaseCount() == false)
                    {
                        RaiseAlarm(actor, AlarmAttachLabelToFoamPad);
                        actor.NextStep();
                    }
                    else
                    {
                        actor.NextStep();
                    }
                });
            seq.AddItem(
                delegate(object obj)
                {
                    try
                    {
                        RobotUnit.BarcodeScanner.Disconnect(this);
                    }
                    catch
                    {
                    }
                });
            seq.AddItem(new FATime(FATimeType.second, 1));
            seq.AddItem(
                delegate(object obj)
                {
                    try
                    {
                        RobotUnit.BarcodeScanner.Connect(this);
                    }
                    catch
                    {
                    }
                });
            seq.AddItem(new FATime(FATimeType.second, 1));
            seq.AddItem(RemoveLabel);
            seq.AddItem((object obj) =>
            {
                PrinterControlModule.LabelScanSuccess = false;
                PrinterControlModule.UnloadingCompleted = true;
            });
            seq.AddItem("Start");
        }