Example #1
0
        private void refresh()
        {
            Task.Run(() => {
                try
                {
                    using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                    {
                        var drivers = dp.DriverRepository.GetAll().OrderBy(t => t.Name);
                        System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            Drivers.Clear();
                            foreach (var driver in drivers)
                            {
                                Drivers.Add(new ViewModels.ComboBoxItemViewModel {
                                    DisplayText = driver.Name, ID = driver.Id
                                });
                            }

                            var driverSetting = dp.SettingsRepository.FindSingle(s => s.Key == TruckClientSettingKeys.DRIVER_ID);
                            if (driverSetting != null)
                            {
                                var savedDriver = Drivers.FirstOrDefault(d => d.ID == driverSetting.Value);
                                if (savedDriver != null)
                                {
                                    SelectedDriver = savedDriver;
                                }
                                else
                                {
                                    SelectedDriver = Drivers[0];
                                }
                            }
                            else
                            {
                                SelectedDriver = Drivers[0];
                            }
                        }));
                    }
                }
                catch (Exception exc)
                {
                    Logging.Logger.Log(exc);
                }
            });
        }
Example #2
0
        private void refresh()
        {
            using (var _unitOfWork = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                Producers.Clear();
                Farms.Clear();
                Fields.Clear();

                Lists     = new ObservableCollection <PickupListGridItem>();
                Producers = new ObservableCollection <ComboBoxItemViewModel>();
                Producers.Add(new ComboBoxItemViewModel {
                    ID = "", DisplayText = "All Clients"
                });
                Farms = new ObservableCollection <FarmComboBoxItemViewModel>();
                Farms.Add(new FarmComboBoxItemViewModel {
                    ID = "", DisplayText = "All Farms"
                });
                Fields = new ObservableCollection <FieldComboBoxItemViewModel>();
                Fields.Add(new FieldComboBoxItemViewModel {
                    ID = "", DisplayText = "All Fields"
                });

                var clients = _unitOfWork.ClientRepository.GetAll(new string[] { "Farms.Fields" }).OrderBy(c => c.Name);
                foreach (var c in clients.Where(x => x.Id != GUIDS.UNASSIGNED_CLIENT_ID))
                {
                    var producer = new ComboBoxItemViewModel {
                        ID = c.Id, DisplayText = c.Name
                    };
                    Producers.Add(producer);

                    foreach (var farm in c.Farms.OrderBy(f => f.Name))
                    {
                        var item = new FarmComboBoxItemViewModel {
                            ClientID = c.Id, ID = farm.Id, DisplayText = farm.Name
                        };
                        Farms.Add(item);

                        foreach (var field in farm.Fields.OrderBy(f => f.Name))
                        {
                            var fieldItem = new FieldComboBoxItemViewModel {
                                ClientID = farm.ClientId, FarmID = farm.Id, ID = field.Id, DisplayText = field.Name
                            };
                            Fields.Add(fieldItem);
                        }
                    }
                }

                var    truck   = _unitOfWork.SettingsRepository.GetCurrentTruck();
                string truckID = "";
                if (truck != null)
                {
                    truckID = truck.Id;
                }

                foreach (var list in _unitOfWork.PickupListRepository.FindMatching(p => p.Id != GUIDS.UNASSIGNED_LIST_ID && p.AssignedTrucks.Any(t => t.Id == truckID), new string[] { "Field.Farm.Client", "AssignedTrucks" }).OrderBy(p => p.Name))
                {
                    Lists.Add(new PickupListGridItem {
                        Client = list.Field.Client.Name, Farm = list.Field.Farm.Name, Field = list.Field.Name, ListID = list.Id, ListName = list.Name
                    });
                }
            }
        }
Example #3
0
        public void Initialize()
        {
            using (var uow = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                NewFarmText     = "";
                ListName        = "";
                NewProducerText = "";
                NewFieldText    = "";

                ShowFarmCombo  = false;
                ShowFieldCombo = false;
                ShowListCombo  = false;

                var list = uow.PickupListRepository.GetById(ActiveListID, "Field.Farm.Client");


                var clients = uow.ClientRepository.GetAll(new string[] { "Farms.Fields" }).OrderBy(t => t.Name);
                var lists   = uow.PickupListRepository.GetAll();

                ErrorMessages = new ObservableCollection <string>();
                Producers     = new ObservableCollection <ComboBoxItemViewModel>();
                Producers.Add(new ComboBoxItemViewModel {
                    ID = "-1", DisplayText = "-- Select One --"
                });
                Producers.Add(new ComboBoxItemViewModel {
                    ID = "", DisplayText = "-- Add New --"
                });

                Farms = new ObservableCollection <FarmComboBoxItemViewModel>();
                Farms.Add(new FarmComboBoxItemViewModel {
                    ID = "-1", ClientID = "", DisplayText = "-- Select One --"
                });
                Farms.Add(new FarmComboBoxItemViewModel {
                    ID = "", ClientID = "", DisplayText = "-- Add New --"
                });

                Fields = new ObservableCollection <FieldComboBoxItemViewModel>();
                Fields.Add(new FieldComboBoxItemViewModel {
                    ID = "-1", ClientID = "", DisplayText = "-- Select One --"
                });
                Fields.Add(new FieldComboBoxItemViewModel {
                    ID = "", ClientID = "", DisplayText = "-- Add New --"
                });

                PickupLists   = new ObservableCollection <PickupListComboBoxItemViewModel>();
                CurrentClient = list.Field.Farm.Client.Name;
                CurrentFarm   = list.Field.Farm.Name;
                CurrentField  = list.Field.Name;
                CurrentList   = list.Name;

                if (list.Id == GUIDS.UNASSIGNED_LIST_ID)
                {
                    CurrentClient = "Unassigned";
                    CurrentFarm   = "";
                    CurrentField  = "";
                    CurrentList   = "";
                }

                foreach (var client in clients.Where(c => c.Id != GUIDS.UNASSIGNED_CLIENT_ID))
                {
                    var producer = new ComboBoxItemViewModel {
                        ID = client.Id, DisplayText = client.Name
                    };
                    Producers.Add(producer);
                }

                SelectedProducer = Producers[0];

                ModulesOnTruck.Clear();

                foreach (var sn in AggregateDataProvider.SerialNumbersOnTruck)
                {
                    ModulesOnTruck.Add(new ViewModels.ModuleViewModel {
                        SerialNumber = sn
                    });
                }
            }
        }