public EditPassViewModel()
    {
      if (!DesignTimeHelper.IsInDesignMode)
      {
        IConfiguration config = ConfigurationSource.Configuration;
        _shooterDatastore = config.GetShooterDataStore();
        _sessionDatastore = config.GetSessionDataStore();
        _programItemDatastore = config.GetProgramItemDataStore();
        _personDatastore = config.GetPersonDataStore();
        _windowService = config.GetWindowService();
        _events = config.GetUIEvents();

        List<UiShooter> shooters = _shooterDatastore.GetAll().Select(UiBusinessObjectMapper.ToUiShooter).ToList();
        shooters.ForEach(_ => { if (_.PersonId != null) _.FetchPerson(_personDatastore.FindById((int) _.PersonId)); });
        UiShooters = new ObservableCollection<UiShooter>(shooters.OrderBy(_ => _.LastName).ThenBy(_ => _.FirstName));

        SearchShooterCommand = new RelayCommand<string>(ExecuteSearchShooterCommand, CanExecuteSearchShooterCommand);
        DeleteCommand = new RelayCommand<UiSession>(ExecuteDeleteCommand, CanExecuteDeleteCommand);
        CancelCommand = new RelayCommand<object>(ExecuteCancelCommand);
        SaveCommand = new RelayCommand<UiShooter>(ExecuteSaveCommand, CanExecuteSaveCommand);
        UiShooter selectedUiShooter = _events.FetchSelectedShooter();

        if (selectedUiShooter != null)
        {
          ShooterNumber = string.Format("{0}", selectedUiShooter.ShooterNumber);
          ExecuteSearchShooterCommand(ShooterNumber);
        }
      }
    }
Esempio n. 2
0
        public EditPassViewModel()
        {
            if (!DesignTimeHelper.IsInDesignMode)
            {
                IConfiguration config = ConfigurationSource.Configuration;
                _shooterDatastore     = config.GetShooterDataStore();
                _sessionDatastore     = config.GetSessionDataStore();
                _programItemDatastore = config.GetProgramItemDataStore();
                _personDatastore      = config.GetPersonDataStore();
                _windowService        = config.GetWindowService();
                _events = config.GetUIEvents();

                List <UiShooter> shooters = _shooterDatastore.GetAll().Select(UiBusinessObjectMapper.ToUiShooter).ToList();
                shooters.ForEach(_ => { if (_.PersonId != null)
                                        {
                                            _.FetchPerson(_personDatastore.FindById((int)_.PersonId));
                                        }
                                 });
                UiShooters = new ObservableCollection <UiShooter>(shooters.OrderBy(_ => _.LastName).ThenBy(_ => _.FirstName));

                SearchShooterCommand = new RelayCommand <string>(ExecuteSearchShooterCommand, CanExecuteSearchShooterCommand);
                DeleteCommand        = new RelayCommand <UiSession>(ExecuteDeleteCommand, CanExecuteDeleteCommand);
                CancelCommand        = new RelayCommand <object>(ExecuteCancelCommand);
                SaveCommand          = new RelayCommand <UiShooter>(ExecuteSaveCommand, CanExecuteSaveCommand);
                UiShooter selectedUiShooter = _events.FetchSelectedShooter();

                if (selectedUiShooter != null)
                {
                    ShooterNumber = string.Format("{0}", selectedUiShooter.ShooterNumber);
                    ExecuteSearchShooterCommand(ShooterNumber);
                }
            }
        }
Esempio n. 3
0
        private void LoadShooterList()
        {
            try
            {
                int selectedShooterId = default(int);
                if (SelectedUiShooter != null)
                {
                    selectedShooterId = SelectedUiShooter.ShooterId;
                }

                Func <Shooter, UiShooter> selector = shooter => new UiShooter
                {
                    PersonId      = shooter.PersonId,
                    ShooterNumber = shooter.ShooterNumber,
                    ShooterId     = shooter.ShooterId
                };

                List <UiShooter> shooterListItems;
                if (SelectedUiPerson != null)
                {
                    shooterListItems = _shooterDataStore.FindByPersonId(SelectedUiPerson.PersonId).Select(selector).ToList();
                }
                else
                {
                    shooterListItems = _shooterDataStore.GetAll().Select(selector).ToList();
                }

                ShooterListItems  = new ObservableCollection <UiShooter>(shooterListItems.Select(_ => _.FetchPerson(_personDataStore)));
                SelectedUiShooter = ShooterListItems.SingleOrDefault(_ => _.ShooterId == selectedShooterId);
            }
            catch (Exception e)
            {
                ReportException(e);
            }
        }
        private void LoadShooterCollections(int programNumber)
        {
            IShooterCollectionDataStore shooterCollectionDataStore = ServiceLocator.Current.GetInstance <IShooterCollectionDataStore>();
            ICollectionShooterDataStore collectionShooterDataStore = ServiceLocator.Current.GetInstance <ICollectionShooterDataStore>();
            IShooterDataStore           shooterDataStore           = ServiceLocator.Current.GetInstance <IShooterDataStore>();
            IPersonDataStore            personDataStore            = ServiceLocator.Current.GetInstance <IPersonDataStore>();

            IEnumerable <ShooterCollectionViewModel> scvm = from sc in shooterCollectionDataStore.GetAll()
                                                            where sc.ProgramNumber == programNumber
                                                            select new ShooterCollectionViewModel
            {
                CollectionName      = sc.CollectionName,
                ShooterCollectionId = sc.ShooterCollectionId,
                Shooters            =
                    new ObservableCollection <UiCollectionShooter>(from cs in collectionShooterDataStore.GetAll()
                                                                   where cs.ShooterCollectionId == sc.ShooterCollectionId
                                                                   join s in shooterDataStore.GetAll() on cs.ShooterId equals s.ShooterId
                                                                   join p in personDataStore.GetAll() on s.PersonId equals p.PersonId
                                                                   orderby p.FirstName
                                                                   orderby p.LastName
                                                                   select new UiCollectionShooter
                {
                    ShooterId     = s.ShooterId,
                    PersonId      = p.PersonId,
                    FirstName     = p.FirstName,
                    LastName      = p.LastName,
                    ShooterNumber = s.ShooterNumber
                })
            };

            ShooterCollections = new ObservableCollection <ShooterCollectionViewModel>(scvm.OrderBy(_ => _.CollectionName));
        }
        public void Initialize(int shooterId)
        {
            ServiceDeskConfiguration serviceDeskConfiguration =
                ServiceLocator.Current.GetInstance <ServiceDeskConfiguration>();
            IShooterDataStore           shooterDataStore           = ServiceLocator.Current.GetInstance <IShooterDataStore>();
            IPersonDataStore            personDataStore            = ServiceLocator.Current.GetInstance <IPersonDataStore>();
            ICollectionShooterDataStore collectionShooterDataStore =
                ServiceLocator.Current.GetInstance <ICollectionShooterDataStore>();
            IShooterCollectionDataStore shooterCollectionDataStore =
                ServiceLocator.Current.GetInstance <IShooterCollectionDataStore>();
            IShooterParticipationDataStore shooterParticipationDataStore =
                ServiceLocator.Current.GetInstance <IShooterParticipationDataStore>();

            // Get PrgramNumbers in which the shooter is enroled.
            List <int> programNumbers = (from sp in shooterParticipationDataStore.FindByShooterId(shooterId)
                                         select sp.ProgramNumber).ToList();

            // Get all CollectionShooters grouped by their ShooterCollections Participation ProgramNumber
            IEnumerable <IGrouping <int, CollectionShooter> > collectionShootersGroupedByProgramNumber =
                from p in programNumbers
                join sc in shooterCollectionDataStore.GetAll() on p equals sc.ProgramNumber
                join
                cs in collectionShooterDataStore.GetAll() on sc.ShooterCollectionId equals cs.ShooterCollectionId
                group cs by p;

            // Program Numbers with which the current shooter is not yet enroled as a CollectionShooter
            IEnumerable <int> programNumbersAlreadyEnroled = from scg in collectionShootersGroupedByProgramNumber
                                                             where scg.Any(x => x.ShooterId == shooterId)
                                                             select scg.Key;

            // Final list of ShooterCollections which are relevant for the current shooter
            IEnumerable <ShooterCollection> shooterCollectionsFinal = from p in programNumbers
                                                                      join sc in shooterCollectionDataStore.GetAll() on p equals sc.ProgramNumber
                                                                      where !programNumbersAlreadyEnroled.Contains(p)
                                                                      select sc;

            IEnumerable <GroupingViewModel> groupingViewModels = from sc in shooterCollectionsFinal
                                                                 join p in serviceDeskConfiguration.ParticipationDescriptions.GetAll() on sc.ProgramNumber.ToString()
                                                                 equals
                                                                 p.ProgramNumber
                                                                 select new GroupingViewModel
            {
                ShooterCollectionId = sc.ShooterCollectionId,
                GroupingName        = sc.CollectionName,
                ParticipationName   = p.ProgramName,
                Shooters            =
                    new ObservableCollection <PersonShooterViewModel>(from cs in collectionShooterDataStore.GetAll()
                                                                      join s in shooterDataStore.GetAll() on cs.ShooterId equals s.ShooterId
                                                                      join person in personDataStore.GetAll() on s.PersonId equals person.PersonId
                                                                      where cs.ShooterCollectionId == sc.ShooterCollectionId
                                                                      select new PersonShooterViewModel(person, s))
            };

            Groupings = new ObservableCollection <GroupingViewModel>(groupingViewModels);
        }
 public void Configure(IShooterDataStore shooterDataStore)
 {
   IEnumerable<Shooter> shooters = shooterDataStore.GetAll().ToArray();
   if (shooters.Any())
   {
     int highestShooterNumber = shooters.Max(_ => _.ShooterNumber);
     ShooterNumberConfig config = _shooterNumberConfigDataStore.FindById(ConfigId);
     config.LastGivenShooterNumber = highestShooterNumber;
     _shooterNumberConfigDataStore.Update(config);
   }
 }
        public void Initialize(int sessionId)
        {
            IPersonDataStore  personDataStore  = ServiceLocator.Current.GetInstance <IPersonDataStore>();
            IShooterDataStore shooterDataStore = ServiceLocator.Current.GetInstance <IShooterDataStore>();

            Shooters = new ObservableCollection <PersonShooterViewModel>(
                from p in personDataStore.GetAll()
                join s in shooterDataStore.GetAll() on p.PersonId equals s.PersonId orderby p.FirstName orderby p.LastName
                select new PersonShooterViewModel(p, s)
                );
        }
Esempio n. 8
0
        public void Configure(IShooterDataStore shooterDataStore)
        {
            IEnumerable <Shooter> shooters = shooterDataStore.GetAll().ToArray();

            if (shooters.Any())
            {
                int highestShooterNumber   = shooters.Max(_ => _.ShooterNumber);
                ShooterNumberConfig config = _shooterNumberConfigDataStore.FindById(ConfigId);
                config.LastGivenShooterNumber = highestShooterNumber;
                _shooterNumberConfigDataStore.Update(config);
            }
        }
Esempio n. 9
0
        private void LoadPersons()
        {
            IEnumerable <PersonShooterViewModel> shooters = from shooter in _shooterDataStore.GetAll()
                                                            join person in _personDataStore.GetAll() on shooter.PersonId equals person.PersonId
                                                            orderby person.FirstName
                                                            orderby person.LastName
                                                            select new PersonShooterViewModel
            {
                FirstName     = person.FirstName,
                LastName      = person.LastName,
                DateOfBirth   = person.DateOfBirth,
                PersonId      = person.PersonId,
                ShooterId     = shooter.ShooterId,
                ShooterNumber = shooter.ShooterNumber
            };

            AllPersons = shooters.ToList();
            UpdateFilteredPersons();
        }
        public void Initialize(int programNumber)
        {
            IPersonDataStore               personDataStore               = ServiceLocator.Current.GetInstance <IPersonDataStore>();
            IShooterDataStore              shooterDataStore              = ServiceLocator.Current.GetInstance <IShooterDataStore>();
            ICollectionShooterDataStore    collectionShooterDataStore    = ServiceLocator.Current.GetInstance <ICollectionShooterDataStore>();
            IShooterCollectionDataStore    shooterCollectionDataStore    = ServiceLocator.Current.GetInstance <IShooterCollectionDataStore>();
            IShooterParticipationDataStore shooterParticipationDataStore =
                ServiceLocator.Current.GetInstance <IShooterParticipationDataStore>();

            // ShooterIds enroled in ProgramNumber
            IEnumerable <int> shooters = from sp in shooterParticipationDataStore.FindByProgramNumber(programNumber)
                                         select sp.ShooterId;

            // ShooterIds with a ShooterCollection participating in ProgramNumber
            IEnumerable <int> shootersWithCollectionInProgramNumber = from cs in collectionShooterDataStore.GetAll()
                                                                      join sc in shooterCollectionDataStore.GetAll() on cs.ShooterCollectionId equals sc.ShooterCollectionId
                                                                      where sc.ProgramNumber == programNumber
                                                                      select cs.ShooterId;

            IEnumerable <int> shootersFinal = shooters.Except(shootersWithCollectionInProgramNumber);

            IEnumerable <PersonShooterViewModel> result = from shooterId in shootersFinal
                                                          join s in shooterDataStore.GetAll() on shooterId equals s.ShooterId
                                                          join p in personDataStore.GetAll() on s.PersonId equals p.PersonId
                                                          select
                                                          new PersonShooterViewModel
            {
                PersonId      = p.PersonId,
                FirstName     = p.FirstName,
                LastName      = p.LastName,
                DateOfBirth   = p.DateOfBirth,
                ShooterId     = s.ShooterId,
                ShooterNumber = s.ShooterNumber
            };

            Shooters = new ObservableCollection <PersonShooterViewModel>(result);
        }
        private void PrintBarcode()
        {
            if (SelectedShooter != null)
            {
                var personShooter = (from shooter in _shooterDataStore.GetAll()
                                     join person in _personDataStore.GetAll() on shooter.PersonId equals person.PersonId
                                     where shooter.ShooterId == SelectedShooter.Shooter.ShooterId
                                     select new
                {
                    person.FirstName,
                    person.LastName,
                    person.DateOfBirth,
                    shooter.ShooterNumber
                }).Single();

                IBarcodeBuilderService barcodeBuilderService = ServiceLocator.Current.GetInstance <IBarcodeBuilderService>();
                string barcode = barcodeBuilderService.BuildBarcode(personShooter.ShooterNumber, 0);


                var shooterCollections = from sc in _shooterCollectionDataStore.GetAll()
                                         join cs in _collectionShooterDataStore.GetAll() on
                                         sc.ShooterCollectionId equals cs.ShooterCollectionId
                                         join p in _serviceDeskConfiguration.ParticipationDescriptions.GetAll() on
                                         sc.ProgramNumber.ToString() equals p.ProgramNumber
                                             where p.AllowShooterCollectionParticipation && cs.ShooterId == SelectedShooter.Shooter.ShooterId
                                         select new
                {
                    sc.CollectionName,
                    p.ProgramName,
                    p.ProgramNumber
                };

                Dictionary <string, Tuple <string, string> > grouped = (from sc in shooterCollections
                                                                        group sc by sc.ProgramNumber
                                                                        into g
                                                                        select new
                {
                    ProgramNumber = g.Key,
                    CollectionName = g.Single().CollectionName,
                    ProgramName = g.Single().ProgramName
                }).ToDictionary(x => x.ProgramNumber,
                                x => new Tuple <string, string>(x.ProgramName, x.CollectionName));

                IBarcodePrintService barcodeService = ServiceLocator.Current.GetInstance <IBarcodePrintService>();

                GenericBarcode_20150909 genericBarcode = new GenericBarcode_20150909
                {
                    FirstName   = personShooter.FirstName,
                    LastName    = personShooter.LastName,
                    DateOfBirth = personShooter.DateOfBirth,
                    Barcode     = barcode,
                    ParticipationTypeToCollectionName = grouped.Values.Take(2).ToList(),
                    Participations = _serviceDeskConfiguration.ParticipationDescriptions.GetAll().Select(x => x.ProgramName).Take(5).ToList()
                };

                try
                {
                    barcodeService.Print(genericBarcode);
                }
                catch (Exception e)
                {
                    MessengerInstance.Send(new DialogMessage("Barcode Print Error",
                                                             "Fehler beim Drucken des Barcodes.\r\n\r\n" + e.ToString(),
                                                             MessageIcon.Error));
                }
            }
        }
Esempio n. 12
0
        private IEnumerable <Tuple <Person, int, decimal, decimal> > GetBestResults(int programNumber)
        {
            IShooterDataStore shooterDataStore = ServiceLocator.Current.GetInstance <IShooterDataStore>();
            IShooterParticipationDataStore shooterParticipationDataStore =
                ServiceLocator.Current.GetInstance <IShooterParticipationDataStore>();
            ISessionDataStore         sessionDataStore         = ServiceLocator.Current.GetInstance <ISessionDataStore>();
            ISessionSubtotalDataStore sessionSubtotalDataStore =
                ServiceLocator.Current.GetInstance <ISessionSubtotalDataStore>();
            IShotDataStore   shotDataStore   = ServiceLocator.Current.GetInstance <IShotDataStore>();
            IPersonDataStore personDataStore = ServiceLocator.Current.GetInstance <IPersonDataStore>();

            List <Shooter> shooters = (from s in shooterDataStore.GetAll()
                                       join sp in shooterParticipationDataStore.GetAll() on s.ShooterId equals sp.ShooterId
                                       where sp.ProgramNumber == programNumber
                                       select s).ToList();

            // Person, ShooterId, TotalScore, DeepShot
            List <Tuple <Person, int, decimal, decimal> > result = new List <Tuple <Person, int, decimal, decimal> >();

            foreach (Shooter shooter in shooters)
            {
                // Get the relevant sessions
                var lShooter = shooter;
                IEnumerable <Session> sessions = from s in sessionDataStore.GetAll()
                                                 where s.ShooterId == lShooter.ShooterId && s.ProgramNumber == programNumber
                                                 select s;

                // Get the results to the sessions
                var maxScoreGrouping = from session in sessions
                                       join subTotal in sessionSubtotalDataStore.GetAll() on session.SessionId equals subTotal.SessionId
                                       join shot in shotDataStore.GetAll() on subTotal.SessionSubtotalId equals shot.SubtotalId
                                       group shot by session
                                       into grouping
                                       select new
                {
                    Session    = grouping.Key,
                    TotalScore = grouping.Sum(x => x.PrimaryScore)
                };

                // Get the max scores of each session
                var bestGrouping = maxScoreGrouping.OrderByDescending(x => x.TotalScore).FirstOrDefault();

                if (bestGrouping != null)
                {
                    // select the max score as the result which shall go into ranking
                    decimal maxScore = bestGrouping.TotalScore;
                    decimal?deepShot = (from subTotal in sessionSubtotalDataStore.GetAll()
                                        join shot in shotDataStore.GetAll() on subTotal.SessionSubtotalId equals shot.SubtotalId
                                        where subTotal.SessionId == bestGrouping.Session.SessionId
                                        orderby shot.SecondaryScore descending
                                        select shot.SecondaryScore).FirstOrDefault();

                    if (lShooter.PersonId.HasValue)
                    {
                        Person person = personDataStore.FindById(lShooter.PersonId.Value);
                        result.Add(new Tuple <Person, int, decimal, decimal>(person, shooter.ShooterId, maxScore, deepShot ?? 0));
                    }
                }
            }

            return(result);
        }