Exemplo n.º 1
0
        private void ExecuteCancelCommand()
        {
            _windowService.CloseModalWindow(WindowType.UnloadCorrectionWindow);
            _windowService.CloseModalWindow(WindowType.WaitingForUnloadWindow);

            LoadingIncorrectModuleViewModel incorrectModuleVM = SimpleIoc.Default.GetInstance <LoadingIncorrectModuleViewModel>();

            incorrectModuleVM.ActiveListID = this.ActiveListID;
            incorrectModuleVM.ListName     = this.ListName;
            incorrectModuleVM.Client       = this.Client;
            incorrectModuleVM.Farm         = this.Farm;
            incorrectModuleVM.Field        = this.Field;

            var    module = BadSerials.LastOrDefault();
            string serial = module != null ? module.SerialNumber : "--";

            incorrectModuleVM.Initialize(true);
            foreach (var s in AggregateDataProvider.SerialNumbersOnTruck)
            {
                incorrectModuleVM.NewModuleLoaded(s, false);
            }
            //incorrectModuleVM.NewModuleLoaded(msg.SerialNumber, moduleOnList);
            _windowService.ShowModalWindow(WindowType.LoadingIncorrectModuleWindow, incorrectModuleVM);
            //Messenger.Default.Send<ManualUnloadCorrectionMessage>(new ManualUnloadCorrectionMessage());
        }
        private void ProcessTagLoadingMessage(TagLoadingMessage msg)
        {
            if (!_windowService.IsWindowOpen(WindowType.LoadingAtGin))
            {
                Task.Run(() =>
                {
                    Logging.Logger.Log("DEBUG", "Processing tag loading message from pickup list " + msg.SerialNumber);
                    using (var uow = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                    {
                        System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            DateTime gpsStart = DateTime.Now.ToUniversalTime().AddSeconds(-3);
                            DateTime gpsEnd   = DateTime.Now.ToUniversalTime();

                            double latitude  = GPSDataProvider.GetAverageLatitude(gpsStart, gpsEnd);
                            double longitude = GPSDataProvider.GetAverageLongitude(gpsStart, gpsEnd);

                            //if we're not at the gin yard or feeder - we must be loading in the field
                            //if (!uow.SettingsRepository.CoordsAtFeeder(latitude, longitude) && !uow.SettingsRepository.CoordsOnGinYard(latitude, longitude))
                            // {
                            bool moduleOnList = this.Modules.Any(m => m.SerialNumber.Trim().ToLower() == msg.SerialNumber.Trim().ToLower());

                            if (moduleOnList && !_windowService.IsWindowOpen(WindowType.LoadingIncorrectModuleWindow) && !_windowService.IsWindowOpen(WindowType.WaitingForUnloadWindow))
                            {
                                if (!_windowService.IsWindowOpen(WindowType.LoadingWindow))
                                {
                                    LoadingWindowViewModel vm = SimpleIoc.Default.GetInstance <LoadingWindowViewModel>();
                                    vm.SerialNumber           = msg.SerialNumber;
                                    vm.Initialize(this.ListID);
                                    _windowService.ShowModalWindow(WindowType.LoadingWindow, vm);
                                }
                                else //window is already open but another module passed under antenna view
                                {
                                    LoadingWindowViewModel vm = SimpleIoc.Default.GetInstance <LoadingWindowViewModel>();
                                    vm.NewModuleDetected(msg.SerialNumber);
                                }
                            }
                            else //we're in the incorrect module sequence or we detected an incorrect module previously
                            {
                                if (_windowService.IsWindowOpen(WindowType.LoadingWindow))
                                {
                                    _windowService.CloseModalWindow(WindowType.LoadingWindow);
                                }

                                if (!_windowService.IsWindowOpen(WindowType.LoadingIncorrectModuleWindow))
                                {
                                    if (_windowService.IsWindowOpen(WindowType.WaitingForUnloadWindow))
                                    {
                                        _windowService.CloseModalWindow(WindowType.WaitingForUnloadWindow);
                                    }

                                    if (_windowService.IsWindowOpen(WindowType.UnloadCorrectionWindow))
                                    {
                                        _windowService.CloseModalWindow(WindowType.UnloadCorrectionWindow);
                                    }

                                    incorrectModuleVM.ActiveListID = this.ListID;
                                    incorrectModuleVM.ListName     = this.ListName;
                                    incorrectModuleVM.Client       = this.Client;
                                    incorrectModuleVM.Farm         = this.Farm;
                                    incorrectModuleVM.Field        = this.Field;
                                    incorrectModuleVM.Initialize(false);
                                    incorrectModuleVM.NewModuleLoaded(msg.SerialNumber, moduleOnList);
                                    _windowService.ShowModalWindow(WindowType.LoadingIncorrectModuleWindow, incorrectModuleVM);
                                }
                                else //window is already open
                                {
                                    incorrectModuleVM.NewModuleLoaded(msg.SerialNumber, moduleOnList);
                                }
                            }


                            //}

                            Logging.Logger.Log("DEBUG", "Done Processing tag loading message from pickup list " + msg.SerialNumber);
                        }));
                    }
                });
            }
        }