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);
        }
      }
    }
Exemple #2
0
        private void RegisterDeletePersonDialog(IPersonDataStore personDataStore)
        {
            _messenger.Register <DeletePersonDialogMessage>(this,
                                                            x =>
            {
                YesNoMessageBoxViewModel vm = new YesNoMessageBoxViewModel
                {
                    DefaultYes = false,
                    Caption    = "Person löschen?",
                    Message    =
                        string.Format("Möchtest du die Person '{0} {1}' wirklich löschen?",
                                      x.FirstName,
                                      x.LastName)
                };

                IWindow w   = _vs.ExecuteFunction <YesNoMessageBoxViewModel, IWindow>((IWindow)Current.MainWindow, vm);
                bool?result = w.ShowDialog();
                if (!result.HasValue || !result.Value)
                {
                    return;
                }

                Person person = personDataStore.FindById(x.PersonId);
                personDataStore.Delete(person);
                _messenger.Send(new RefreshDataFromRepositoriesMessage());
            });
        }
Exemple #3
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);
                }
            }
        }
        public static UiShooter FetchPerson(this UiShooter shooter, IPersonDataStore personDataStore)
        {
            if (shooter.PersonId != null)
            {
                shooter.FetchPerson(personDataStore.FindById((int)shooter.PersonId));
            }

            return(shooter);
        }
Exemple #5
0
        private void RegisterEditPersonDialog(IPersonDataStore personDataStore)
        {
            _messenger.Register <EditPersonDialogMessage>(this,
                                                          x =>
            {
                Person p = personDataStore.FindById(x.PersonId);
                var m    = new CreatePersonViewModel()
                {
                    Title       = "Person editieren",
                    PersonId    = p.PersonId,
                    FirstName   = p.FirstName,
                    LastName    = p.LastName,
                    DateOfBirth = p.DateOfBirth,
                    Address     = p.Address,
                    City        = p.City,
                    ZipCode     = p.ZipCode,
                    Email       = p.Email,
                    Phone       = p.Phone
                };

                IWindow w   = _vs.ExecuteFunction <CreatePersonViewModel, IWindow>((IWindow)Current.MainWindow, m);
                bool?result = w.ShowDialog();
                if (!result.HasValue || !result.Value)
                {
                    return;
                }

                personDataStore.Update(new Person
                {
                    PersonId    = m.PersonId,
                    FirstName   = m.FirstName,
                    LastName    = m.LastName,
                    DateOfBirth = m.DateOfBirth,
                    Address     = m.Address,
                    City        = m.City,
                    ZipCode     = m.ZipCode,
                    Email       = m.Email,
                    Phone       = m.Phone
                });

                _messenger.Send(new RefreshDataFromRepositoriesMessage());
                _messenger.Send(new SetSelectedPersonMessage(m.PersonId));
            });
        }
Exemple #6
0
        private void ExecuteSearchShooterCommand(string obj)
        {
            int shooterNumber;

            if (int.TryParse(obj, out shooterNumber))
            {
                Shooter shooter = _shooterDatastore.FindByShooterNumber(shooterNumber);
                if (shooter != null)
                {
                    if (shooter.PersonId != null)
                    {
                        UiShooter uiShooter = UiBusinessObjectMapper.ToUiShooter(shooter).FetchPerson(_personDatastore.FindById((int)shooter.PersonId));
                        CurrentShooterLabel = string.Format("{0} {1} ({2})", uiShooter.LastName, uiShooter.FirstName, uiShooter.ShooterNumber);
                    }
                    int shooterId            = shooter.ShooterId;
                    List <UiSession> session = _sessionDatastore.FindByShooterId(shooterId).Select(UiBusinessObjectMapper.ToUiSession).ToList();
                    session.ForEach(_ =>
                    {
                        if (_.ProgramItemId != null)
                        {
                            _.ProgramDescription = string.Format("{0}",
                                                                 _programItemDatastore.FindById((int)_.ProgramItemId).ProgramName);
                        }
                    });

                    UiSessions        = new ObservableCollection <UiSession>(session);
                    SelectedUiSession = UiSessions.FirstOrDefault();
                }
            }
        }
        private void ExecutePrintBarcodeCommand(UiShooter uiShooter)
        {
            try
            {
                bool isNachwuchs = (from sp in _shooterParticipationDataStore.GetAll()
                                    join p in _participationDataStore.GetAll() on sp.ParticipationId equals p.ParticipationId
                                    where p.ParticipationName == "Nachwuchsstich" && sp.ShooterId == uiShooter.ShooterId
                                    select p.ParticipationId).
                                   Any();

                bool isGruppe = (from sp in _shooterParticipationDataStore.GetAll()
                                 join p in _participationDataStore.GetAll() on sp.ParticipationId equals p.ParticipationId
                                 where p.ParticipationName == "Gruppenstich" && sp.ShooterId == uiShooter.ShooterId
                                 select p.ParticipationId).
                                Any();

                bool isSieUndEr = (from sp in _shooterParticipationDataStore.GetAll()
                                   join p in _participationDataStore.GetAll() on sp.ParticipationId equals p.ParticipationId
                                   where p.ParticipationName == "Sie & Er" && sp.ShooterId == uiShooter.ShooterId
                                   select p.ParticipationId).
                                  Any();

                bool isWorschtUndBrot = (from sp in _shooterParticipationDataStore.GetAll()
                                         join p in _participationDataStore.GetAll() on sp.ParticipationId equals p.ParticipationId
                                         where p.ParticipationName == "Worscht & Brot" && sp.ShooterId == uiShooter.ShooterId
                                         select p.ParticipationId).
                                        Any();

                string groupName = (from cs in _collectionShooterDataStore.GetAll()
                                    join sc in _shooterCollectionDataStore.GetAll() on cs.ShooterCollectionId equals sc.ShooterCollectionId
                                    join scp in _shooterCollectionParticipationDataStore.GetAll() on cs.ShooterCollectionId equals
                                    scp.ShooterCollectionId
                                    join p in _participationDataStore.GetAll() on scp.ParticipationId equals p.ParticipationId
                                    where p.ParticipationName == "Gruppenstich" && cs.ShooterId == uiShooter.ShooterId
                                    select sc.CollectionName).SingleOrDefault();

                string sieUndErName = (from cs in _collectionShooterDataStore.GetAll()
                                       join sc in _shooterCollectionDataStore.GetAll() on cs.ShooterCollectionId equals sc.ShooterCollectionId
                                       join scp in _shooterCollectionParticipationDataStore.GetAll() on cs.ShooterCollectionId equals
                                       scp.ShooterCollectionId
                                       join p in _participationDataStore.GetAll() on scp.ParticipationId equals p.ParticipationId
                                       where p.ParticipationName == "Sie & Er" && cs.ShooterId == uiShooter.ShooterId
                                       select sc.CollectionName).SingleOrDefault();

                Person person = uiShooter.PersonId == null
          ? new Person()
                {
                    FirstName = "unknown", LastName = "unknown"
                }
          : _personDataStore.FindById((int)uiShooter.PersonId);
                BarcodeHerbstschiessen barcodeInfo = new BarcodeHerbstschiessen
                {
                    FirstName        = person.FirstName,
                    LastName         = person.LastName,
                    DateOfBirth      = person.DateOfBirth,
                    Gruppenstich     = groupName ?? string.Empty,
                    SieUndEr         = sieUndErName ?? string.Empty,
                    Barcode          = _barcodeBuilderService.BuildBarcode(uiShooter.ShooterNumber, uiShooter.Legalization),
                    IsGruppenstich   = isGruppe,
                    IsNachwuchsstich = isNachwuchs,
                    IsWorschtUndBrot = isWorschtUndBrot,
                    IsSieUndEr       = isSieUndEr
                };

                _barcodePrintService.Print(barcodeInfo);
            }
            catch (Exception e)
            {
                ReportException(e);
            }
        }
        private void RegisterDeletePersonDialog(IPersonDataStore personDataStore)
        {
            _messenger.Register<DeletePersonDialogMessage>(this,
                x =>
                {
                    YesNoMessageBoxViewModel vm = new YesNoMessageBoxViewModel
                    {
                        DefaultYes = false,
                        Caption = "Person löschen?",
                        Message =
                            string.Format("Möchtest du die Person '{0} {1}' wirklich löschen?",
                                x.FirstName,
                                x.LastName)
                    };

                    IWindow w = _vs.ExecuteFunction<YesNoMessageBoxViewModel, IWindow>((IWindow) Current.MainWindow, vm);
                    bool? result = w.ShowDialog();
                    if (!result.HasValue || !result.Value) return;

                    Person person = personDataStore.FindById(x.PersonId);
                    personDataStore.Delete(person);
                    _messenger.Send(new RefreshDataFromRepositoriesMessage());
                });
        }
        private void RegisterEditPersonDialog(IPersonDataStore personDataStore)
        {
            _messenger.Register<EditPersonDialogMessage>(this,
                x =>
                {
                    Person p = personDataStore.FindById(x.PersonId);
                    var m = new CreatePersonViewModel()
                    {
                        Title = "Person editieren",
                        PersonId = p.PersonId,
                        FirstName = p.FirstName,
                        LastName = p.LastName,
                        DateOfBirth = p.DateOfBirth,
                        Address = p.Address,
                        City = p.City,
                        ZipCode = p.ZipCode,
                        Email = p.Email,
                        Phone = p.Phone
                    };

                    IWindow w = _vs.ExecuteFunction<CreatePersonViewModel, IWindow>((IWindow) Current.MainWindow, m);
                    bool? result = w.ShowDialog();
                    if (!result.HasValue || !result.Value) return;

                    personDataStore.Update(new Person
                    {
                        PersonId = m.PersonId,
                        FirstName = m.FirstName,
                        LastName = m.LastName,
                        DateOfBirth = m.DateOfBirth,
                        Address = m.Address,
                        City = m.City,
                        ZipCode = m.ZipCode,
                        Email = m.Email,
                        Phone = m.Phone
                    });

                    _messenger.Send(new RefreshDataFromRepositoriesMessage());
                    _messenger.Send(new SetSelectedPersonMessage(m.PersonId));
                });
        }
    public static UiShooter FetchPerson(this UiShooter shooter, IPersonDataStore personDataStore)
    {
      if (shooter.PersonId != null)
      {
        shooter.FetchPerson(personDataStore.FindById((int) shooter.PersonId));
      }

      return shooter;
    }
Exemple #11
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);
        }