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. 2
0
        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);
            }
        }