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); } } }
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 ExecuteSaveCommand(UiShooter obj) { _selectedUiSession.ShooterId = obj.ShooterId; _sessionDatastore.Update(UiBusinessObjectMapper.ToSession(SelectedUiSession)); ExecuteSearchShooterCommand(ShooterNumber); _events.ShooterDataStoreChanged(); }
public static UiShooter FetchPerson(this UiShooter shooter, IPersonDataStore personDataStore) { if (shooter.PersonId != null) { shooter.FetchPerson(personDataStore.FindById((int)shooter.PersonId)); } return(shooter); }
public static Shooter ToShooter(this UiShooter uiShooter) { return(new Shooter() { ShooterId = uiShooter.ShooterId, ShooterNumber = uiShooter.ShooterNumber, PersonId = uiShooter.PersonId }); }
private void ExecuteRemoveCommand(UiShooter obj) { IEnumerable <CollectionShooter> collectionShooters = _collectionShooterDataStore.FindByShooterCollectionId(SelectedUiShooterCollection.ShooterCollectionId); CollectionShooter collectionShooter = collectionShooters.FirstOrDefault(_ => _.ShooterId == obj.ShooterId); _collectionShooterDataStore.Delete(collectionShooter); LoadData(); }
private void ExecuteAssignCommand(UiShooter obj) { CollectionShooter collectionShooter = new CollectionShooter { ShooterCollectionId = SelectedUiShooterCollection.ShooterCollectionId, ShooterId = obj.ShooterId }; _collectionShooterDataStore.Create(collectionShooter); LoadData(); }
private void ExecuteEditShooterCommand(UiShooter uiShooter) { try { _windowService.ShowEditShooterWindow(); _uiEvents.ShooterDataStoreChanged(); } catch (Exception e) { ReportException(e); } }
private void ExecuteDeleteShooterCommand(UiShooter uiShooter) { try { bool yes = _windowService.ShowYesNoMessasge("Schütze löschen", string.Format("Möchtest du den Schützen mit der Nummer '{0}' wirklich löschen?", uiShooter.ShooterNumber)); if (yes) { _shooterDataStore.Delete(uiShooter.ToShooter()); } } catch (Exception e) { ReportException(e); _shooterDataStore.Revert(); } finally { _uiEvents.ShooterDataStoreChanged(); } }
public static UiShooter FetchPerson(this UiShooter shooter, Person person) { shooter.FirstName = person.FirstName; shooter.LastName = person.LastName; return(shooter); }
private bool CanExecuteSaveCommand(UiShooter uiShooter) { return uiShooter != null && _selectedUiSession != null; }
private bool CanExecuteDeleteShooterCommand(UiShooter uiShooter) { return uiShooter != null; }
private bool CanExecuteSaveCommand(UiShooter uiShooter) { return(uiShooter != null && _selectedUiSession != null); }
private bool CanExecutePrintBarcodeCommand(UiShooter uiShooter) { return uiShooter != null; }
private void OnSelectedShooterItemChanged(UiShooter selectedUiShooter) { try { LoadParticipationList(); if (selectedUiShooter != null) { StringBuilder detailsStringBuilder = new StringBuilder(); Person person = selectedUiShooter.PersonId == null ? new Person() { FirstName = "unknown", LastName = "unknown" } : _personDataStore.FindById((int)selectedUiShooter.PersonId); detailsStringBuilder.AppendFormat("{0}, {1} [{2}] : {3} [{4}]\r\n{5}\r\n", person.LastName, person.FirstName, person.PersonId, selectedUiShooter.ShooterNumber, selectedUiShooter.ShooterId, person.DateOfBirth != null ? ((DateTime)person.DateOfBirth).ToString("dd.MM.yyyy") : string.Empty); detailsStringBuilder.AppendLine(); IEnumerable <SessionDetails> sessionDetails = _sessionDetailsView.FindByShooterId(selectedUiShooter.ShooterId).OrderBy(_ => _.ProgramNumber).ToList(); detailsStringBuilder.AppendLine("\r\n----------------------------------"); detailsStringBuilder.Append("Geschossene Stiche:"); detailsStringBuilder.AppendLine("\r\n----------------------------------"); foreach (SessionDetails sessionDetail in sessionDetails) { detailsStringBuilder.AppendFormat("{0} [{1}] = {2}\r\n", sessionDetail.SessionDescription, sessionDetail.SessionId, sessionDetail.SubSessions.Sum(sd => sd.Shots.Sum(_ => _.PrimaryScore))); } detailsStringBuilder.AppendLine("\r\n----------------------------------"); detailsStringBuilder.Append("Wettkampfteilnahmen:"); detailsStringBuilder.AppendLine("\r\n----------------------------------"); foreach (ShooterParticipationListItem listItem in Participations) { detailsStringBuilder.AppendLine(listItem.ParticipationName); } detailsStringBuilder.AppendLine("\r\n----------------------------------"); detailsStringBuilder.Append("Gruppenzuteilung:"); detailsStringBuilder.AppendLine("\r\n----------------------------------"); List <ShooterParticipationDetails> shooterParticipationDetails = (from cs in _collectionShooterDataStore.GetAll() join sc in _shooterCollectionDataStore.GetAll() on cs.ShooterCollectionId equals sc.ShooterCollectionId join scp in _shooterCollectionParticipationDataStore.GetAll() on sc.ShooterCollectionId equals scp.ShooterCollectionId join p in _participationDataStore.GetAll() on scp.ParticipationId equals p.ParticipationId where cs.ShooterId == selectedUiShooter.ShooterId select new ShooterParticipationDetails { ParticipationName = p.ParticipationName, CollectionName = sc.CollectionName }).ToList(); foreach (ShooterParticipationDetails spd in shooterParticipationDetails) { detailsStringBuilder.AppendLine(string.Format("{1}: {0}", spd.CollectionName, spd.ParticipationName)); } DetailsView = detailsStringBuilder.ToString(); SessionTreeViewItems = new ObservableCollection <SessionTreeViewItem>(sessionDetails.Select(sd => new SessionTreeViewItem { SessionHeader = sd.SessionDescription + " (" + sd.SubSessions.Sum(_ => _.Shots.Count()) + "): " + sd.SubSessions.Sum(_ => _.Shots.Sum(shot => shot.PrimaryScore)), Subsessions = sd.SubSessions.Select( ss => new Subsession { Shots = ss.Shots.OrderBy(shot => shot.Ordinal) .Select(shot => string.Format("{0}\t{1}", shot.Ordinal, shot.PrimaryScore)), SubsessionHeader = string.Format("Gruppe {0} | T={1}", ss.Ordinal, ss.Shots.Sum(_ => _.PrimaryScore)) }) })); } else { DetailsView = string.Empty; SessionTreeViewItems.Clear(); } } catch (Exception e) { ReportException(e); } }
private void ExecuteRemoveCommand(UiShooter obj) { IEnumerable<CollectionShooter> collectionShooters = _collectionShooterDataStore.FindByShooterCollectionId(SelectedUiShooterCollection.ShooterCollectionId); CollectionShooter collectionShooter = collectionShooters.FirstOrDefault(_ => _.ShooterId == obj.ShooterId); _collectionShooterDataStore.Delete(collectionShooter); LoadData(); }
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 OnSelectedShooterItemChanged(UiShooter selectedUiShooter) { try { LoadParticipationList(); if (selectedUiShooter != null) { StringBuilder detailsStringBuilder = new StringBuilder(); Person person = selectedUiShooter.PersonId == null ? new Person() {FirstName = "unknown", LastName = "unknown"} : _personDataStore.FindById((int) selectedUiShooter.PersonId); detailsStringBuilder.AppendFormat("{0}, {1} [{2}] : {3} [{4}]\r\n{5}\r\n", person.LastName, person.FirstName, person.PersonId, selectedUiShooter.ShooterNumber, selectedUiShooter.ShooterId, person.DateOfBirth != null ? ((DateTime) person.DateOfBirth).ToString("dd.MM.yyyy") : string.Empty); detailsStringBuilder.AppendLine(); IEnumerable<SessionDetails> sessionDetails = _sessionDetailsView.FindByShooterId(selectedUiShooter.ShooterId).OrderBy(_ => _.ProgramNumber).ToList(); detailsStringBuilder.AppendLine("\r\n----------------------------------"); detailsStringBuilder.Append("Geschossene Stiche:"); detailsStringBuilder.AppendLine("\r\n----------------------------------"); foreach (SessionDetails sessionDetail in sessionDetails) { detailsStringBuilder.AppendFormat("{0} [{1}] = {2}\r\n", sessionDetail.SessionDescription, sessionDetail.SessionId, sessionDetail.SubSessions.Sum(sd => sd.Shots.Sum(_ => _.PrimaryScore))); } detailsStringBuilder.AppendLine("\r\n----------------------------------"); detailsStringBuilder.Append("Wettkampfteilnahmen:"); detailsStringBuilder.AppendLine("\r\n----------------------------------"); foreach (ShooterParticipationListItem listItem in Participations) { detailsStringBuilder.AppendLine(listItem.ParticipationName); } detailsStringBuilder.AppendLine("\r\n----------------------------------"); detailsStringBuilder.Append("Gruppenzuteilung:"); detailsStringBuilder.AppendLine("\r\n----------------------------------"); List<ShooterParticipationDetails> shooterParticipationDetails = (from cs in _collectionShooterDataStore.GetAll() join sc in _shooterCollectionDataStore.GetAll() on cs.ShooterCollectionId equals sc.ShooterCollectionId join scp in _shooterCollectionParticipationDataStore.GetAll() on sc.ShooterCollectionId equals scp.ShooterCollectionId join p in _participationDataStore.GetAll() on scp.ParticipationId equals p.ParticipationId where cs.ShooterId == selectedUiShooter.ShooterId select new ShooterParticipationDetails { ParticipationName = p.ParticipationName, CollectionName = sc.CollectionName }).ToList(); foreach (ShooterParticipationDetails spd in shooterParticipationDetails) { detailsStringBuilder.AppendLine(string.Format("{1}: {0}", spd.CollectionName, spd.ParticipationName)); } DetailsView = detailsStringBuilder.ToString(); SessionTreeViewItems = new ObservableCollection<SessionTreeViewItem>(sessionDetails.Select(sd => new SessionTreeViewItem { SessionHeader = sd.SessionDescription + " (" + sd.SubSessions.Sum(_ => _.Shots.Count()) + "): " + sd.SubSessions.Sum(_ => _.Shots.Sum(shot => shot.PrimaryScore)), Subsessions = sd.SubSessions.Select( ss => new Subsession { Shots = ss.Shots.OrderBy(shot => shot.Ordinal) .Select(shot => string.Format("{0}\t{1}", shot.Ordinal, shot.PrimaryScore)), SubsessionHeader = string.Format("Gruppe {0} | T={1}", ss.Ordinal, ss.Shots.Sum(_ => _.PrimaryScore)) }) })); } else { DetailsView = string.Empty; SessionTreeViewItems.Clear(); } } catch (Exception e) { ReportException(e); } }
private bool CanExecuteDeleteShooterCommand(UiShooter uiShooter) { return(uiShooter != null); }
private bool CanExecuteRemoveCommand(UiShooter obj) { return(obj != null && SelectedUiShooterCollection != null); }
private bool CanExecutePrintBarcodeCommand(UiShooter uiShooter) { return(uiShooter != null); }
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 bool CanExecuteRemoveCommand(UiShooter obj) { return obj != null && SelectedUiShooterCollection != null; }