private void ExecuteDirectionsCommand()
        {
            var currentCoords = GPSDataProvider.GetLastCoords();

            double?destLat = null;
            double?destLng = null;
            double?myLat   = null;
            double?myLong  = null;

            if (Modules.Count() > 0)
            {
                destLat = Modules[0].Latitude;
                destLng = Modules[0].Longitude;
            }
            else
            {
                destLat = FieldLat;
                destLng = FieldLong;
            }

            if (currentCoords != null)
            {
                myLat  = currentCoords.Latitude;
                myLong = currentCoords.Longitude;
            }
            else
            {
                myLat  = 33.5779;
                myLong = -101.8552;
            }

            _windowService.LaunchDirections(destLat, destLng, myLat, myLong);
        }
Пример #2
0
        public void Refresh()
        {
            //initialize using ActiveListID to lookup info
            ModulesOnTruck = new ObservableCollection <ModuleViewModel>();
            foreach (var sn in AggregateDataProvider.SerialNumbersOnTruck)
            {
                ModulesOnTruck.Add(new ViewModels.ModuleViewModel {
                    SerialNumber = sn
                });
            }

            var    coords = GPSDataProvider.GetLastCoords();
            double lat    = 0.00;
            double lng    = 0.00;

            if (coords != null)
            {
                lat = coords.NonNullLatitude;
                lng = coords.NonNullLongitude;
            }

            using (var uow = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                if (uow.SettingsRepository.CoordsAtFeeder(lat, lng))
                {
                    Location = "Gin Feeder";
                }
                else if (uow.SettingsRepository.CoordsOnGinYard(lat, lng))
                {
                    Location = "Gin Yard";
                }
            }
        }
        public void Initialize()
        {
            MapVisible = defaultToMap;
            var lastCoords = GPSDataProvider.GetLastCoords(DateTime.Now.ToUniversalTime().AddSeconds(-5), DateTime.Now.ToUniversalTime());

            CurrentLat  = CottonDBMS.DataModels.Helpers.GPSHelper.SafeLat(lastCoords);
            CurrentLong = CottonDBMS.DataModels.Helpers.GPSHelper.SafeLong(lastCoords);

            FieldLat          = 0.000;
            FieldLong         = 0.000;
            HasCheckedModules = false;

            using (var uow = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                if (InitiatingEvent != null)  //find the list based on serial number
                {
                    PickupListDestination dest = PickupListDestination.GIN_YARD;
                    if (uow.SettingsRepository.CoordsOnGinYard(CurrentLat, CurrentLong) || uow.SettingsRepository.CoordsAtFeeder(CurrentLat, CurrentLong))
                    {
                        dest = PickupListDestination.GIN_FEEDER;
                    }
                    ListID = uow.PickupListRepository.GetListIDWithSerialNumber(InitiatingEvent.SerialNumber, CurrentLat, CurrentLong, dest);
                }
            }
            LoadData(ListID);

            Messenger.Default.Register <GPSEventMessage>(this, (action) => ProcessGPSMessage(action));
            Messenger.Default.Register <TagLoadingMessage>(this, (action) => ProcessTagLoadingMessage(action));
            Messenger.Default.Register <AggregateEvent>(this, (action) => ProcessAggregatedEvent(action));

            if (InitiatingEvent != null)
            {
                ProcessTagLoadingMessage(InitiatingEvent);
            }

            Task.Run(() =>
            {
                checkForInternet();
                timer = new System.Threading.Timer(timerCallback, null, 500, 1000);
            });
        }
        private string getInitScript()
        {
            StringBuilder sb = new StringBuilder();
            string        parmLat;
            string        parmLong;
            var           coords = GPSDataProvider.GetLastCoords(DateTime.UtcNow.AddMinutes(-1), DateTime.UtcNow);

            if (vm.FieldLat != 0.000 && vm.FieldLong != 0.000)
            {
                parmLat  = vm.FieldLat.ToString();
                parmLong = vm.FieldLong.ToString();
            }
            else if (coords != null)
            {
                parmLat  = coords.Latitude.ToString();
                parmLong = coords.Longitude.ToString();
            }
            else
            {
                parmLat  = "33.5749";
                parmLong = "-101.8572";
            }

            //browser.InvokeScript("setMyLocation", parms.ToArray());
            sb.AppendLine(string.Format("setMyLocation('{0}', '{1}');", parmLat, parmLong));
            foreach (var point in vm.Modules.Where(m => m.ShowOnMap && !m.Loaded))
            {
                sb.AppendLine(string.Format("addModule('{0}', '{1}', '{2}');", point.Latitude.ToString(), point.Longitude.ToString(), point.SerialNumber));
            }

            if (vm.Modules.Count() == 0)
            {
                sb.AppendLine(string.Format("addModule('{0}', '{1}', '{2}');", parmLat.ToString(), parmLong.ToString(), vm.Client + " - " + vm.Farm + " - " + vm.Field));
            }

            return(sb.ToString());
        }
Пример #5
0
        private void ExecuteSaveCommand()
        {
            refreshErrorState();
            if (!HasErrors)
            {
                try
                {
                    using (var uow = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                    {
                        //get this truck
                        var         syncedSetting = uow.SyncedSettingsRepo.GetAll().FirstOrDefault();
                        TruckEntity thisTruck     = uow.SettingsRepository.GetCurrentTruck();

                        string clientName = "";
                        if (_selectedProducer.ID == "")
                        {
                            clientName = _NewProducerText.Trim();
                        }
                        else
                        {
                            clientName = _selectedProducer.DisplayText.Trim();
                        }

                        string farmName = "";
                        if (ShowNewFarmText)
                        {
                            farmName = _NewFarmText.Trim();
                        }
                        else
                        {
                            farmName = _selectedFarm.DisplayText.Trim();
                        }

                        string fieldName = "";
                        if (ShowFieldText)
                        {
                            fieldName = _NewFieldText.Trim();
                        }
                        else
                        {
                            fieldName = _selectedField.DisplayText.Trim();
                        }

                        ClientEntity client = uow.ClientRepository.EnsureClientCreated(clientName, InputSource.TRUCK);
                        uow.SaveChanges();
                        FarmEntity farm = uow.FarmRepository.EnsureFarmCreated(client, farmName, InputSource.TRUCK);
                        uow.SaveChanges();
                        FieldEntity field = uow.FieldRepository.EnsureFieldCreated(farm, fieldName, InputSource.TRUCK);
                        uow.SaveChanges();

                        var    coords = GPSDataProvider.GetLastCoords();
                        double lat    = CottonDBMS.DataModels.Helpers.GPSHelper.SafeLat(coords);
                        double lng    = CottonDBMS.DataModels.Helpers.GPSHelper.SafeLong(coords);

                        PickupListEntity list = new PickupListEntity();
                        list.Id                 = Guid.NewGuid().ToString();
                        list.Name               = _listName.Trim();
                        list.Source             = InputSource.TRUCK;
                        list.AssignedModules    = new List <ModuleEntity>();
                        list.AssignedTrucks     = new List <TruckEntity>();
                        list.DownloadedToTrucks = new List <TruckEntity>();
                        list.FieldId            = field.Id;
                        list.PickupListStatus   = PickupListStatus.OPEN;
                        list.ModulesPerLoad     = (syncedSetting != null) ? syncedSetting.ModulesPerLoad : 4;

                        if (uow.SettingsRepository.CoordsOnGinYard(lat, lng) || uow.SettingsRepository.CoordsAtFeeder(lat, lng))
                        {
                            list.Destination = PickupListDestination.GIN_FEEDER;
                        }
                        else
                        {
                            list.Destination = PickupListDestination.GIN_YARD;
                        }

                        if (thisTruck != null)
                        {
                            list.AssignedTrucks.Add(thisTruck);
                            list.DownloadedToTrucks.Add(thisTruck);
                        }

                        uow.PickupListRepository.Add(list);
                        uow.SaveChanges();

                        GalaSoft.MvvmLight.Messaging.Messenger.Default.Send <PickupListAddedMessage>(new PickupListAddedMessage {
                            Id = list.Id
                        });
                    }
                    _windowService.CloseModalWindow(WindowType.AddFieldWindow);
                }
                catch (Exception exc)
                {
                    Logging.Logger.Log(exc);
                    System.Windows.MessageBox.Show("An error occured trying to save list. " + exc.Message);
                }
            }
        }
Пример #6
0
        private void ExecuteSaveCommand()
        {
            refreshErrorState();

            if (!HasErrors)
            {
                using (var uow = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                {
                    string clientName = "";
                    if (ShowNewProducerText)
                    {
                        clientName = NewProducerText.Trim();
                    }
                    else
                    {
                        clientName = SelectedProducer.DisplayText;
                    }

                    string farmName = "";
                    if (ShowNewFarmText)
                    {
                        farmName = NewFarmText.Trim();
                    }
                    else
                    {
                        farmName = SelectedFarm.DisplayText;
                    }

                    string fieldName = "";
                    if (ShowFieldText)
                    {
                        fieldName = NewFieldText.Trim();
                    }
                    else
                    {
                        fieldName = SelectedField.DisplayText.Trim();
                    }

                    var    coords = GPSDataProvider.GetLastCoords();
                    double lat    = CottonDBMS.DataModels.Helpers.GPSHelper.SafeLat(coords);
                    double lng    = CottonDBMS.DataModels.Helpers.GPSHelper.SafeLong(coords);

                    var client = uow.ClientRepository.EnsureClientCreated(clientName, InputSource.TRUCK);
                    uow.SaveChanges();
                    var farm = uow.FarmRepository.EnsureFarmCreated(client, farmName, InputSource.TRUCK);
                    uow.SaveChanges();
                    var field = uow.FieldRepository.EnsureFieldCreated(farm, fieldName, InputSource.TRUCK);
                    field.Latitude  = lat;
                    field.Longitude = lng;
                    uow.SaveChanges();

                    var currentTruck      = uow.SettingsRepository.GetCurrentTruck();
                    PickupListEntity list = null;

                    if (ShowListText)
                    {
                        list                    = new PickupListEntity();
                        list.Id                 = Guid.NewGuid().ToString();
                        list.Created            = DateTime.UtcNow;
                        list.FieldId            = field.Id;
                        list.Latitude           = lat;
                        list.Longitude          = lng;
                        list.Name               = ListName;
                        list.PickupListStatus   = PickupListStatus.OPEN;
                        list.Source             = InputSource.TRUCK;
                        list.SyncedToCloud      = false;
                        list.AssignedModules    = new List <ModuleEntity>();
                        list.AssignedTrucks     = new List <TruckEntity>();
                        list.DownloadedToTrucks = new List <TruckEntity>();

                        if (uow.SettingsRepository.CoordsOnGinYard(lat, lng) || uow.SettingsRepository.CoordsAtFeeder(lat, lng))
                        {
                            list.Destination = PickupListDestination.GIN_FEEDER;
                        }
                        else
                        {
                            list.Destination = PickupListDestination.GIN_YARD;
                        }

                        if (currentTruck != null)
                        {
                            list.AssignedTrucks.Add(currentTruck);
                            list.DownloadedToTrucks.Add(currentTruck);
                        }
                        uow.PickupListRepository.Add(list);
                        uow.SaveChanges();
                    }
                    else
                    {
                        list = uow.PickupListRepository.GetById(SelectedPickupList.ID, "Field.Farm.Client", "AssignedModules", "DownloadedToTrucks", "AssignedTrucks");
                    }

                    GalaSoft.MvvmLight.Messaging.Messenger.Default.Send <PickupListAddedMessage>(new PickupListAddedMessage {
                        Id = list.Id
                    });

                    //assign all serial numbers on truck to the new list
                    uow.PickupListRepository.MoveModulesToList(list, AggregateDataProvider.SerialNumbersOnTruck, lat, lng);
                    _windowService.CloseModalWindow(WindowType.ChangeListWindow);
                    _windowService.CloseModalWindow(WindowType.LoadingIncorrectModuleWindow);
                    _windowService.CloseModalWindow(WindowType.PickupWindow);

                    //re-open pickup window with new list assignment
                    PickUpListViewModel vm = SimpleIoc.Default.GetInstance <PickUpListViewModel>();
                    vm.ListID          = list.Id;
                    vm.InitiatingEvent = null;
                    _windowService.ShowModalWindow(WindowType.PickupWindow, vm);
                }
            }
        }