Example #1
0
        private void BtnAddToMatch_Click(object sender, RoutedEventArgs e)
        {
            if (ShootersGrid.SelectedItems == null)
            {
                MessageBox.Show("Please select a Shooter first.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            foreach (Shooter s in ShootersGrid.SelectedItems)
            {
                MatchParticipation mp = new MatchParticipation()
                {
                    ShooterID = s.ShooterID,
                    MatchID   = _m.MatchID,
                    Category  = s.Category
                };

                _ctx.MatchParticipations.Attach(mp);


                if (!_ctx.MatchParticipations.Any(x => x.Match.MatchID.Equals(_m.MatchID) && x.Shooter.ShooterID.Equals(s.ShooterID)))
                {
                    _ctx.MatchParticipations.Add(mp);
                }

                _ctx.SaveChanges();
                Refresh();
            }
        }
Example #2
0
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            if (!(dropInfo.VisualTarget is DataGrid))
            {
                return;
            }

            if (dropInfo.TargetGroup == null)
            {
                HandleEx(dropInfo);
                return;
            }

            int    target_posse_id;
            string target_group_name = dropInfo.TargetGroup.Name.ToString();

            if (Int32.TryParse(target_group_name, out target_posse_id))
            {
                var shooters           = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <Shooter>().ToList();
                var match_participants = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <MatchParticipation>().ToList();

                if ((shooters != null) && (shooters.Count > 0))
                {
                    foreach (Shooter s in shooters)
                    {
                        MatchParticipation mp = new MatchParticipation()
                        {
                            ShooterID = s.ShooterID,
                            MatchID   = _m.MatchID,
                            Posse     = (int)target_posse_id,
                            Category  = s.Category
                        };

                        _ctx.MatchParticipations.Attach(mp);

                        if (!_ctx.MatchParticipations.Any(x => x.Match.MatchID.Equals(_m.MatchID) && x.Shooter.ShooterID.Equals(s.ShooterID)))
                        {
                            _ctx.MatchParticipations.Add(mp);
                        }

                        _ctx.SaveChanges();
                    }
                }
                else if ((match_participants != null) && (match_participants.Count > 0))
                {
                    foreach (MatchParticipation mp in match_participants)
                    {
                        _ctx.MatchParticipations.Where(x => x.MatchParticipationId.Equals(mp.MatchParticipationId)).First().Posse = (int)target_posse_id;
                    }

                    _ctx.SaveChanges();
                }

                Refresh();
            }
        }
Example #3
0
        /// <summary>
        /// Remove Participants
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnRemoveFromMatch_Click(object sender, RoutedEventArgs e)
        {
            if (FocusedGrid == null)
            {
                return;
            }
            if (!(FocusedGrid is DataGrid))
            {
                return;
            }

            var selected_items = ((DataGrid)FocusedGrid).SelectedItems;

            if (selected_items == null)
            {
                return;
            }
            if (selected_items.Count.Equals(0))
            {
                return;
            }

            List <int> selected_match_participations_ids = new List <int>();

            foreach (MatchParticipation mp in selected_items)
            {
                selected_match_participations_ids.Add(mp.MatchParticipationId);
            }

            foreach (int match_participation_id in selected_match_participations_ids)
            {
                MatchParticipation mp = _ctx.MatchParticipations.Where(x => x.MatchParticipationId == match_participation_id).First();

                _ctx.MatchParticipations.Remove(mp);
                _ctx.SaveChanges();
                Refresh();
            }
        }
Example #4
0
        void HandleEx(IDropInfo di)
        {
            DataGrid t = di.VisualTarget as DataGrid;

            var shooters = DefaultDropHandler.ExtractData(di.Data).OfType <Shooter>().ToList();

            if ((shooters != null) && (shooters.Count > 0))
            {
                foreach (Shooter s in shooters)
                {
                    MatchParticipation mp = new MatchParticipation()
                    {
                        ShooterID = s.ShooterID,
                        MatchID   = _m.MatchID,
                        Posse     = 0,
                        Category  = s.Category
                    };

                    if (t.Name.Equals("SpeedTicketGrid"))
                    {
                        mp.IsSpeedTicket = true;
                    }

                    _ctx.MatchParticipations.Attach(mp);

                    if (!_ctx.MatchParticipations.Any(x => x.Match.MatchID.Equals(_m.MatchID) && x.Shooter.ShooterID.Equals(s.ShooterID)))
                    {
                        _ctx.MatchParticipations.Add(mp);
                    }

                    _ctx.SaveChanges();
                }
                Refresh();
                return;
            }
        }
Example #5
0
        /// <summary>
        /// Print one Speed Ticket Rating Sheet
        /// </summary>
        /// <param name="mp_id"></param>
        /// <returns></returns>
        string PrintSpeedTicket(MatchParticipation mp)
        {
            var fn = tfh.get("pdf");

            using (MemoryStream myMemoryStream = new MemoryStream())
            {
                Document document = PdfPages.get();

                PdfWriter w = PdfWriter.GetInstance(document, new FileStream(fn, FileMode.Create));
                w.PageEvent = new PdfHeaderFooter($"Speed Ticket Rating Sheet\n{mp.Shooter.ToString()}", Global.CurrentMatch.ToString());

                document.Open();

                Font fnt = new Font(Font.FontFamily.HELVETICA, 11f, Font.BOLD);

                PdfPTable s = new PdfPTable(10);
                s.DefaultCell.Border = 0;
                s.HeaderRows         = 1;

                s.WidthPercentage = 100;
                int[] pw2 = { 10, 10, 10, 5, 5, 5, 5, 5, 5, 25 };
                s.SetWidths(pw2);

                PdfPCell[] hc = new PdfPCell[]
                {
                    new PdfPCell(new Phrase(new Chunk("Stage #\n ", fnt)))
                    {
                        Border = 0
                    },
                    new PdfPCell(new Phrase(new Chunk("Time", fnt)))
                    {
                        Border = 0
                    },
                    new PdfPCell(new Phrase(new Chunk("Error", fnt)))
                    {
                        Border = 0
                    },
                    new PdfPCell(new Phrase(new Chunk("Ablauff.", fnt)))
                    {
                        Border = 0
                    },
                    new PdfPCell(new Phrase(new Chunk("MSV", fnt)))
                    {
                        Border = 0
                    },
                    new PdfPCell(new Phrase(new Chunk("Bonus", fnt)))
                    {
                        Border = 0
                    },
                    new PdfPCell(new Phrase(new Chunk("Spirit", fnt)))
                    {
                        Border = 0
                    },
                    new PdfPCell(new Phrase(new Chunk("S-DQ", fnt)))
                    {
                        Border = 0
                    },
                    new PdfPCell(new Phrase(new Chunk("M-DQ", fnt)))
                    {
                        Border = 0
                    },
                    new PdfPCell(new Phrase(new Chunk("Signature", fnt)))
                    {
                        Border = 0
                    },
                };

                foreach (var c in hc)
                {
                    c.PaddingBottom = 5;
                }

                s.Rows.Add(new PdfPRow(hc));

                fnt = new Font(Font.FontFamily.HELVETICA, 12f, Font.NORMAL);

                for (int i = 1; i <= Global.CurrentMatch.NumberOfStages; i++)
                {
                    PdfPCell[] lc = new PdfPCell[]
                    {
                        new PdfPCell(new Phrase(new Chunk(i.ToString(), fnt))),
                        new PdfPCell(new Phrase(new Chunk("", fnt))),
                        new PdfPCell(new Phrase(new Chunk("", fnt))),
                        new PdfPCell(new Phrase(new Chunk("", fnt))),
                        new PdfPCell(new Phrase(new Chunk("", fnt))),
                        new PdfPCell(new Phrase(new Chunk("", fnt))),
                        new PdfPCell(new Phrase(new Chunk("", fnt))),
                        new PdfPCell(new Phrase(new Chunk("", fnt))),
                        new PdfPCell(new Phrase(new Chunk("", fnt))),
                        new PdfPCell(new Phrase(new Chunk("", fnt)))
                    };

                    s.Rows.Add(new PdfPRow(lc));
                }

                document.Add(s);
                document.Close();

                return(fn);
            }
        }