private void FindAndSetToLoadCarrierToPackAndSort(string pickZoneId, string empId)
        {
            GetToLoadCarrierPackAndSortResponse serviceResponse = null;
            GetToLoadCarrierPackAndSortRequest  serviceRequest  = new GetToLoadCarrierPackAndSortRequest();

            serviceRequest.GetToLoadCarrierPackAndSortParameters             = new GetToLoadCarrierPackAndSortParameters();
            serviceRequest.GetToLoadCarrierPackAndSortParameters.PickZoneId  = pickZoneId;
            serviceRequest.GetToLoadCarrierPackAndSortParameters.UserId      = empId;
            serviceRequest.GetToLoadCarrierPackAndSortParameters.WarehouseId = UserSessionService.WarehouseId;
            serviceResponse = Service.GetToLoadCarrierPackAndSort(serviceRequest);
            if ((serviceResponse != null) && (serviceResponse.GetToLoadCarrierPackAndSortResult != null))
            {
                ToLoadCarrierId = serviceResponse.GetToLoadCarrierPackAndSortResult.LoadCarrierId;

                View.EnableComponent("ToLoadCarrier", false);
                View.EnableComponent("FromLoadCarrier", false);

                PackStationSearchPanelView searchPanel = null;
                if (WorkItem.Items.FindByType <PackStationSearchPanelView>().Count > 0)
                {
                    searchPanel = WorkItem.Items.FindByType <PackStationSearchPanelView>().Last();
                }

                if (searchPanel != null)
                {
                    searchPanel.DepartureId.Text      = serviceResponse.GetToLoadCarrierPackAndSortResult.DepartureId;
                    searchPanel.ShipToCustomerId.Text = serviceResponse.GetToLoadCarrierPackAndSortResult.ShipToCustomerId;
                    searchPanel.UserId.Text           = empId;
                    PackStationSearchPanelViewResult searchPanelResult = new PackStationSearchPanelViewResult();
                    searchPanelResult.DepartureId      = serviceResponse.GetToLoadCarrierPackAndSortResult.DepartureId;
                    searchPanelResult.ShipToCustomerId = serviceResponse.GetToLoadCarrierPackAndSortResult.ShipToCustomerId;
                    searchPanelResult.UserId           = empId;
                    searchPanelResult.PickZoneId       = pickZoneId;
                    searchPanel.PresentData(searchPanelResult);
                    viewParameters.DepartureId      = serviceResponse.GetToLoadCarrierPackAndSortResult.DepartureId;
                    viewParameters.ClientId         = UserSessionService.ClientId;
                    viewParameters.UserId           = empId;
                    viewParameters.ShipToCustomerId = serviceResponse.GetToLoadCarrierPackAndSortResult.ShipToCustomerId;
                    viewParameters.PickZoneId       = pickZoneId;
                }

                View.SetFocus();
            }
        }
        public void PackWithEAN(string eanCode)
        {
            if (!string.IsNullOrEmpty(ToLoadCarrierId))
            {
                if (WorkItem.Items.FindByType <IPackStationFromLCView>().Count > 0)
                {
                    IPackStationFromLCView detailView            = WorkItem.Items.FindByType <IPackStationFromLCView>().LastOrDefault();
                    List <string>          productNumbersFromEAN = UpdateDataSourceFindArtIdFromEAN(eanCode);

                    string productNumber = string.Empty;

                    if (productNumbersFromEAN.Count == 1)
                    {
                        productNumber = productNumbersFromEAN[0];
                    }
                    else
                    {
                        productNumber = eanCode;
                    }

                    //else
                    //{
                    //    Console.Beep(350, 1000);
                    //    if (productNumbersFromEAN.Count == 0)
                    //    {
                    //        ShellInteractionService.ShowMessageBox(ResourceManager.str_EANPack_Error_Title, GetAlarmText("PACK006"), string.Empty, MessageBoxButton.Ok, MessageBoxImage.Warning);
                    //    }
                    //    else
                    //    {
                    //        ShellInteractionService.ShowMessageBox(ResourceManager.str_EANPack_Error_Title, GetAlarmText("PACK005"), string.Empty, MessageBoxButton.Ok, MessageBoxImage.Warning);
                    //    }
                    //}

                    if (productNumber != string.Empty)
                    {
                        List <PackStationFromLCViewResult> pickOrderLines = detailView.GetData;

                        List <PackStationFromLCViewResult> foundProductLines = FindPickOrderLineWithProductNumber(pickOrderLines, productNumber);

                        if (foundProductLines.Count > 0)
                        {
                            if (foundProductLines.Count == 1)
                            {
                                PackStationFromLCViewResult foundProductLine = foundProductLines[0];

                                if (ScanEachPickPackage)
                                {
                                    if (foundProductLine.PickedQuantity <= MaxNoOfScans || !string.IsNullOrEmpty(viewParameters.PickZoneId)) //Override MaxNoOfScans if Pack & Sort
                                    {
                                        detailView.CurrentItem = foundProductLine;
                                        PackPickOrderLine(foundProductLine, 1);
                                    }
                                    else
                                    {
                                        Console.Beep(350, 1000);
                                        ShellInteractionService.ShowMessageBox(ResourceManager.str_EANPack_Error_Title, GetAlarmText("PACK002"), string.Empty, MessageBoxButton.Ok, MessageBoxImage.Warning);
                                        //Error message "The pick quantity is greater the max number of scans. Please pack the line manualy"

                                        detailView.CurrentItem = foundProductLine;
                                        detailView.Refresh();
                                        detailView.SetFocus();
                                    }
                                }
                                else
                                {
                                    PackPickOrderLine(foundProductLine, foundProductLine.PickedQuantity.Value);
                                }
                            }
                            else
                            {
                                Console.Beep(350, 1000);
                                ShellInteractionService.ShowMessageBox(ResourceManager.str_EANPack_Error_Title, GetAlarmText("PACK003"), string.Empty, MessageBoxButton.Ok, MessageBoxImage.Warning);
                                //Error message "The product can´t be packed with EAN since there are several pick order lines for this product"
                            }
                        }
                        else
                        {
                            Console.Beep(350, 1000);
                            ShellInteractionService.ShowMessageBox(ResourceManager.str_EANPack_Error_Title, GetAlarmText("PACK004"), string.Empty, MessageBoxButton.Ok, MessageBoxImage.Warning);
                            //Error messaga "No product corresponds to this EAN code"
                        }
                    }
                }
            }
            else //Start Pack & Sort
            {
                PackStationSearchPanelView searchPanel = null;
                if (WorkItem.Items.FindByType <PackStationSearchPanelView>().Count > 0)
                {
                    searchPanel = WorkItem.Items.FindByType <PackStationSearchPanelView>().Last();
                }

                string empId      = string.Empty;
                string pickZoneId = string.Empty;

                if (viewParameters != null)
                {
                    if (!string.IsNullOrEmpty(viewParameters.PickZoneId))
                    {
                        pickZoneId = viewParameters.PickZoneId;
                    }

                    if (!string.IsNullOrEmpty(viewParameters.UserId))
                    {
                        empId = viewParameters.UserId;
                    }
                }

                if (searchPanel != null)
                {
                    if (string.IsNullOrEmpty(empId))
                    {
                        empId = searchPanel.CurrentItem.UserId;
                    }

                    if (string.IsNullOrEmpty(pickZoneId))
                    {
                        pickZoneId = searchPanel.CurrentItem.PickZoneId;
                    }
                }

                if (!string.IsNullOrEmpty(pickZoneId))
                {
                    if (!string.IsNullOrEmpty(empId))
                    {
                        ScanEachPickPackage = true;

                        StartPackAndSortArtResponse serviceResponse = null;
                        //try
                        //{
                        StartPackAndSortArtRequest serviceRequest = new StartPackAndSortArtRequest();
                        serviceRequest.StartPackAndSortArtParameters               = new StartPackAndSortArtParameters();
                        serviceRequest.StartPackAndSortArtParameters.UserId        = empId;
                        serviceRequest.StartPackAndSortArtParameters.PickZoneId    = pickZoneId;
                        serviceRequest.StartPackAndSortArtParameters.BarCodeNumber = eanCode;
                        serviceRequest.StartPackAndSortArtParameters.WarehouseId   = UserSessionService.WarehouseId;
                        serviceRequest.StartPackAndSortArtParameters.ClientId      = UserSessionService.ClientId;
                        serviceResponse = Service.StartPackAndSortArt(serviceRequest);
                        if ((serviceResponse != null) && (serviceResponse.StartPackAndSortArtResult != null))
                        {
                            ToLoadCarrierId = serviceResponse.StartPackAndSortArtResult.LoadCarrierId;
                            View.EnableComponent("ToLoadCarrier", false);
                            View.EnableComponent("FromLoadCarrier", false);

                            if (searchPanel != null)
                            {
                                searchPanel.DepartureId.Text      = serviceResponse.StartPackAndSortArtResult.DepartureId;
                                searchPanel.ShipToCustomerId.Text = serviceResponse.StartPackAndSortArtResult.ShipToCustomerId;
                                searchPanel.UserId.Text           = empId;
                                PackStationSearchPanelViewResult searchPanelResult = new PackStationSearchPanelViewResult();
                                searchPanelResult.DepartureId      = serviceResponse.StartPackAndSortArtResult.DepartureId;
                                searchPanelResult.ShipToCustomerId = serviceResponse.StartPackAndSortArtResult.ShipToCustomerId;
                                searchPanelResult.PickZoneId       = pickZoneId;
                                searchPanelResult.UserId           = empId;
                                searchPanel.PresentData(searchPanelResult);
                                PackStationOverviewViewParameters parameters = new PackStationOverviewViewParameters();
                                parameters.DepartureId      = serviceResponse.StartPackAndSortArtResult.DepartureId;
                                parameters.ClientId         = UserSessionService.ClientId;
                                parameters.PickZoneId       = pickZoneId;
                                parameters.UserId           = empId;
                                parameters.ShipToCustomerId = serviceResponse.StartPackAndSortArtResult.ShipToCustomerId;
                                View.Update(parameters);
                            }
                        }
                        //}
                        //catch (FaultException<ApplicationFault> ex)
                        //{
                        //    if (ShellInteractionService.ShowMessageBox(ResourceManager.str_ResetPackStatio_Title, GetAlarmText(ex.Detail.ErrorCode), null, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Ok)
                        //    {
                        //    }
                        //}
                    }
                }
                else
                {
                    Console.Beep(350, 1000);
                    ShellInteractionService.ShowMessageBox(ResourceManager.str_EANPack_Error_Title, GetAlarmText("PACK007"), string.Empty, MessageBoxButton.Ok, MessageBoxImage.Warning);
                }
            }
        }
        public bool SelectToLoadCarrier(string loadCarrierId)
        {
            PackStationSearchPanelView searchPanel = null;

            if (WorkItem.Items.FindByType <PackStationSearchPanelView>().Count > 0)
            {
                searchPanel = WorkItem.Items.FindByType <PackStationSearchPanelView>().Last();
            }
            string customerId  = string.Empty;
            string departureId = string.Empty;
            string empId       = string.Empty;
            bool   firstCarId  = false;

            if (viewParameters != null)
            {
                if (!string.IsNullOrEmpty(viewParameters.DepartureId))
                {
                    departureId = viewParameters.DepartureId;
                }
                if (!string.IsNullOrEmpty(viewParameters.ShipToCustomerId))
                {
                    customerId = viewParameters.ShipToCustomerId;
                }
                if (!string.IsNullOrEmpty(viewParameters.UserId))
                {
                    empId = viewParameters.UserId;
                }
            }
            if (string.IsNullOrEmpty(empId))
            {
                if (searchPanel != null)
                {
                    empId = searchPanel.CurrentItem.UserId;
                }
            }
            if (string.IsNullOrEmpty(departureId) || string.IsNullOrEmpty(customerId))
            {
                firstCarId = true;
            }
            SelectToLoadCarrierForPackStationResponse serviceResponse = null;

            try
            {
                SelectToLoadCarrierForPackStationRequest serviceRequest = new SelectToLoadCarrierForPackStationRequest();
                serviceRequest.SelectToLoadCarrierForPackStationParameters                  = new SelectToLoadCarrierForPackStationParameters();
                serviceRequest.SelectToLoadCarrierForPackStationParameters.ClientId         = UserSessionService.ClientId;
                serviceRequest.SelectToLoadCarrierForPackStationParameters.DepartureId      = departureId;
                serviceRequest.SelectToLoadCarrierForPackStationParameters.LoadCarrierId    = loadCarrierId;
                serviceRequest.SelectToLoadCarrierForPackStationParameters.ShipToCustomerId = customerId;
                serviceRequest.SelectToLoadCarrierForPackStationParameters.UserId           = empId;
                serviceRequest.SelectToLoadCarrierForPackStationParameters.WarehouseId      = UserSessionService.WarehouseId;
                serviceResponse = Service.SelectToLoadCarrierForPackStation(serviceRequest);
                if ((serviceResponse == null) || (serviceResponse.SelectToLoadCarrierForPackStationResult == null))
                {
                    return(false);
                }
            }
            catch (FaultException <ApplicationFault> ex)
            {
                if (ex.Detail.ErrorCode == "PBCAR078" || ex.Detail.ErrorCode == "PBCAR048")
                {
                    if (ShellInteractionService.ShowMessageBox(ResourceManager.str_ResetPackStatio_Title, GetAlarmText("PACK001"), null, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        if (StopPacking != null)
                        {
                            StopPacking(this, null);
                        }
                        viewParameters.DepartureId      = string.Empty;
                        viewParameters.ShipToCustomerId = string.Empty;
                        SelectToLoadCarrier(loadCarrierId);
                        return(true);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(ToLoadCarrierId))
                        {
                            ToLoadCarrierId = ToLoadCarrierId;
                        }
                        else
                        {
                            ToLoadCarrierId = string.Empty;
                        }
                        return(false);
                    }
                }
                else
                {
                    if (firstCarId)
                    {
                        if (viewParameters != null)
                        {
                            viewParameters.UserId = string.Empty;
                        }
                    }
                    ToLoadCarrierId = string.Empty;
                    throw;
                }
            }
            if (firstCarId)
            {
                if (searchPanel != null)
                {
                    searchPanel.DepartureId.Text      = serviceResponse.SelectToLoadCarrierForPackStationResult.DepartureId;
                    searchPanel.ShipToCustomerId.Text = serviceResponse.SelectToLoadCarrierForPackStationResult.ShipToCustomerId;
                    searchPanel.UserId.Text           = empId;
                    PackStationSearchPanelViewResult searchPanelResult = new PackStationSearchPanelViewResult();
                    searchPanelResult.DepartureId      = serviceResponse.SelectToLoadCarrierForPackStationResult.DepartureId;
                    searchPanelResult.ShipToCustomerId = serviceResponse.SelectToLoadCarrierForPackStationResult.ShipToCustomerId;
                    searchPanelResult.UserId           = empId;
                    searchPanel.PresentData(searchPanelResult);
                    PackStationOverviewViewParameters parameters = new PackStationOverviewViewParameters();
                    parameters.DepartureId      = serviceResponse.SelectToLoadCarrierForPackStationResult.DepartureId;
                    parameters.ClientId         = UserSessionService.ClientId;
                    parameters.UserId           = empId;
                    parameters.ShipToCustomerId = serviceResponse.SelectToLoadCarrierForPackStationResult.ShipToCustomerId;
                    viewParameters = parameters;
                }
            }

            ScanEachPickPackage = serviceResponse.SelectToLoadCarrierForPackStationResult.ScanEachPickPackage.Value;
            MaxNoOfScans        = serviceResponse.SelectToLoadCarrierForPackStationResult.MaxNoOfScans.GetValueOrDefault(0);

            ToLoadCarrierId = loadCarrierId;
            return(true);
        }
        public bool SelectFromLoadCarrier(string loadCarrierId)
        {
            PackStationSearchPanelView searchPanel = null;

            if (WorkItem.Items.FindByType <PackStationSearchPanelView>().Count > 0)
            {
                searchPanel = WorkItem.Items.FindByType <PackStationSearchPanelView>().Last();
            }
            string customerId  = string.Empty;
            string departureId = string.Empty;
            string empId       = string.Empty;
            bool   firstCarId  = false;

            string shipToCustomerId = string.Empty;
            string pickZoneId       = string.Empty;

            if (viewParameters != null)
            {
                if (!string.IsNullOrEmpty(viewParameters.DepartureId))
                {
                    departureId = viewParameters.DepartureId;
                }
                if (!string.IsNullOrEmpty(viewParameters.ShipToCustomerId))
                {
                    customerId = viewParameters.ShipToCustomerId;
                }
                if (!string.IsNullOrEmpty(viewParameters.UserId))
                {
                    empId = viewParameters.UserId;
                }
                if (!string.IsNullOrEmpty(viewParameters.PickZoneId))
                {
                    pickZoneId = viewParameters.PickZoneId;
                }
            }

            if (searchPanel != null)
            {
                if (string.IsNullOrEmpty(empId))
                {
                    empId = searchPanel.CurrentItem.UserId;
                    if (viewParameters != null)
                    {
                        viewParameters.UserId = empId;
                    }
                }

                if (string.IsNullOrEmpty(pickZoneId))
                {
                    pickZoneId = searchPanel.CurrentItem.PickZoneId;
                }
            }

            if (string.IsNullOrEmpty(departureId) || string.IsNullOrEmpty(customerId))
            {
                firstCarId = true;
            }


            if (firstCarId && !string.IsNullOrEmpty(pickZoneId) && string.IsNullOrEmpty(toLoadCarrierId)) //Start Pack & Sort
            {
                StartPackAndSortCarResponse serviceResponse = null;
                StartPackAndSortCarRequest  serviceRequest  = new StartPackAndSortCarRequest();
                serviceRequest.StartPackAndSortCarParameters               = new StartPackAndSortCarParameters();
                serviceRequest.StartPackAndSortCarParameters.UserId        = empId;
                serviceRequest.StartPackAndSortCarParameters.LoadCarrierId = loadCarrierId;
                serviceResponse = Service.StartPackAndSortCar(serviceRequest);
                if ((serviceResponse == null) || (serviceResponse.StartPackAndSortCarResult == null))
                {
                    return(false);
                }
                else
                {
                    departureId      = serviceResponse.StartPackAndSortCarResult.DepartureId;
                    shipToCustomerId = serviceResponse.StartPackAndSortCarResult.ShipToCustomerId;

                    ToLoadCarrierId = loadCarrierId;
                    View.EnableComponent("ToLoadCarrier", false);
                    View.EnableComponent("FromLoadCarrier", false);
                }
            }
            else
            {
                SelectFromLoadCarrierForPackStationResponse serviceResponse = null;
                try
                {
                    SelectFromLoadCarrierForPackStationRequest serviceRequest = new SelectFromLoadCarrierForPackStationRequest();
                    serviceRequest.SelectFromLoadCarrierForPackStationParameters                  = new SelectFromLoadCarrierForPackStationParameters();
                    serviceRequest.SelectFromLoadCarrierForPackStationParameters.ClientId         = UserSessionService.ClientId;
                    serviceRequest.SelectFromLoadCarrierForPackStationParameters.DepartureId      = departureId;
                    serviceRequest.SelectFromLoadCarrierForPackStationParameters.LoadCarrierId    = loadCarrierId;
                    serviceRequest.SelectFromLoadCarrierForPackStationParameters.ShipToCustomerId = customerId;
                    serviceRequest.SelectFromLoadCarrierForPackStationParameters.UserId           = empId;
                    serviceRequest.SelectFromLoadCarrierForPackStationParameters.WarehouseId      = UserSessionService.WarehouseId;
                    serviceResponse = Service.SelectFromLoadCarrierForPackStation(serviceRequest);
                    if ((serviceResponse == null) || (serviceResponse.SelectFromLoadCarrierForPackStationResult == null))
                    {
                        return(false);
                    }
                    else
                    {
                        departureId      = serviceResponse.SelectFromLoadCarrierForPackStationResult.DepartureId;
                        shipToCustomerId = serviceResponse.SelectFromLoadCarrierForPackStationResult.ShipToCustomerId;
                    }
                }
                catch (FaultException <ApplicationFault> ex)
                {
                    if (ex.Detail.ErrorCode == "PBCAR078" || ex.Detail.ErrorCode == "PBCAR048")
                    {
                        if (ShellInteractionService.ShowMessageBox(ResourceManager.str_ResetPackStatio_Title, GetAlarmText("PACK001"), null, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                        {
                            if (StopPacking != null)
                            {
                                StopPacking(this, null);
                            }
                            viewParameters.DepartureId      = string.Empty;
                            viewParameters.ShipToCustomerId = string.Empty;
                            ToLoadCarrierId = string.Empty;
                            SelectFromLoadCarrier(loadCarrierId);
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (ex.Detail.ErrorCode == "PBCAR083")
                    {
                        if (ShellInteractionService.ShowMessageBox(StringResources.ActionException_Text, ex.Message, null, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                        {
                            ForceSelectFromLoadCarrierForPackStationRequest forceSelectServiceRequest = new ForceSelectFromLoadCarrierForPackStationRequest();
                            forceSelectServiceRequest.ForceSelectFromLoadCarrierForPackStationParameters = new ForceSelectFromLoadCarrierForPackStationParameters();
                            forceSelectServiceRequest.ForceSelectFromLoadCarrierForPackStationParameters.LoadCarrierId = loadCarrierId;
                            forceSelectServiceRequest.ForceSelectFromLoadCarrierForPackStationParameters.UserId        = empId;
                            ForceSelectFromLoadCarrierForPackStationResponse forceResponce = Service.ForceSelectFromLoadCarrierForPackStation(forceSelectServiceRequest);
                            if ((forceResponce == null) || (forceResponce.ForceSelectFromLoadCarrierForPackStationResult == null))
                            {
                                return(false);
                            }
                            else
                            {
                                departureId      = forceResponce.ForceSelectFromLoadCarrierForPackStationResult.DepartureId;
                                shipToCustomerId = forceResponce.ForceSelectFromLoadCarrierForPackStationResult.ShipToCustomerId;
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (firstCarId)
                        {
                            if (viewParameters != null)
                            {
                                viewParameters.UserId = string.Empty;
                            }
                        }
                        ShellInteractionService.ShowMessageBox(StringResources.ActionException_Text, ex.Message, null, MessageBoxButton.Ok, MessageBoxImage.Error);
                        return(false);
                    }
                }
            }

            if (firstCarId)
            {
                if (searchPanel != null)
                {
                    searchPanel.DepartureId.Text      = departureId;
                    searchPanel.ShipToCustomerId.Text = shipToCustomerId;
                    searchPanel.UserId.Text           = empId;
                    PackStationSearchPanelViewResult searchPanelResult = new PackStationSearchPanelViewResult();
                    searchPanelResult.DepartureId      = departureId;
                    searchPanelResult.ShipToCustomerId = shipToCustomerId;
                    searchPanelResult.UserId           = empId;
                    searchPanelResult.PickZoneId       = pickZoneId;
                    searchPanel.PresentData(searchPanelResult);
                    PackStationOverviewViewParameters parameters = new PackStationOverviewViewParameters();
                    parameters.DepartureId      = departureId;
                    parameters.ClientId         = UserSessionService.ClientId;
                    parameters.UserId           = empId;
                    parameters.ShipToCustomerId = shipToCustomerId;
                    parameters.PickZoneId       = pickZoneId;
                    View.Update(parameters);
                }
            }
            else
            {
                View.Update(viewParameters); // View.OnViewUpdated();
            }
            return(true);
        }