Exemplo n.º 1
0
        private void drawTableauPartOnTableauPart(XGraphics graphics, XFont font, FRCTableauPart tableauPart, double tableauWidth,
                                                  double tableauSpace, int partNumber, string title, double titleX, double titleY)
        {
            FRCMatch  match;
            FRCFencer fencer1, fencer2, winner;
            double    fontHeight        = font.GetHeight();
            int       endPointIdx       = 0;
            int       tableauSize       = tableauPart.Length;
            int       iterationsPerPage = tableauSize / tableauPageCounter;

            FRCFencer[] ft = fencerInTableau.ToArray();
            fencerInTableau.Clear();

            for (int i = 0; i < tableauSize; i += 2)
            {
                XPoint point = tableauEndPoint[endPointIdx];
                if ((i >= iterationsPerPage) && (i % iterationsPerPage == 0))
                {
                    graphics.Dispose();
                    pageIdx++;
                    graphics = XGraphics.FromPdfPage(document.Pages[pageIdx]);
                    graphics.DrawString(title, font, XBrushes.Black, titleX, titleY, XStringFormats.TopLeft);
                }

                fencer1 = ft[i];
                fencer2 = ft[i + 1];
                string name, score;

                tableauEndPoint[endPointIdx] = drawTableauLines(graphics, point, tableauSpace * Math.Pow(2, partNumber), tableauWidth, tableauWidth);
                XPoint endPoint = tableauEndPoint[endPointIdx];
                endPointIdx += (int)Math.Pow(2, partNumber);

                if (fencer1 == null && fencer2 == null)
                {
                    winner = null;
                    name   = "----------";
                    score  = "";
                }
                else if (fencer1 == null)
                {
                    winner = fencer2;
                    name   = fencer2.LastName.ToUpper() + " " + fencer2.FirstName;
                    score  = "";
                }
                else if (fencer2 == null)
                {
                    winner = fencer1;
                    name   = fencer1.LastName.ToUpper() + " " + fencer1.FirstName;
                    score  = "";
                }
                else
                {
                    match   = tableauPart.getNextMatch();
                    fencer1 = getFencerFromTableauMatchingID(match.FencerID1);
                    fencer2 = getFencerFromTableauMatchingID(match.FencerID2);
                    if (match.Fencer1Win)
                    {
                        winner = fencer1;
                        name   = fencer1.LastName.ToUpper() + " " + fencer1.FirstName;
                        if (match.Fencer2Abandon)
                        {
                            score = "by abandonment";
                        }
                        else if (match.Fencer2Forfait)
                        {
                            score = "by scratch";
                        }
                        else if (match.Fencer2Exclusion)
                        {
                            score = "by exclusion";
                        }
                        else
                        {
                            score = match.ScoreFencer1.ToString() + "/" + match.ScoreFencer2.ToString();
                        }
                    }
                    else
                    {
                        winner = fencer2;
                        name   = fencer2.LastName.ToUpper() + " " + fencer2.FirstName;
                        if (match.Fencer1Abandon)
                        {
                            score = "by abandonment";
                        }
                        else if (match.Fencer1Forfait)
                        {
                            score = "by scratch";
                        }
                        else if (match.Fencer1Exclusion)
                        {
                            score = "by exclusion";
                        }
                        else
                        {
                            score = match.ScoreFencer2.ToString() + "/" + match.ScoreFencer1.ToString();
                        }
                    }
                }

                if (name.Length > 18)
                {
                    name = name.Remove(18);
                }

                fencerInTableau.Add(winner);
                graphics.DrawString(name, font, XBrushes.Black, endPoint.X + 5, endPoint.Y - 2);
                graphics.DrawString(score, font, XBrushes.Black, endPoint.X + 15, endPoint.Y + fontHeight);
            }
            graphics.Dispose();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Should be used to draw the first tableau part.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="font"></param>
        /// <param name="fontClub"></param>
        /// <param name="tableauPart"></param>
        /// <param name="qualifiers"></param>
        /// <param name="tableauWidth"></param>
        /// <param name="tableauSpace"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="title"></param>
        /// <param name="titleY"></param>
        private void drawTableauPart(XGraphics graphics, XFont font, XFont fontClub, FRCTableauPart tableauPart, int qualifiers,
                                     double tableauWidth, double tableauSpace, double x, double y, string title, double titleY)
        {
            FRCMatch  match;
            FRCFencer fencer1, fencer2, winner;
            double    fontHeight = font.GetHeight();
            double    totalY;

            currentYCoordinate = y;
            int endPointIdx = 0;
            int rank1, rank2;
            int tableauSize = tableauPart.Length;

            interpreter.Tableau.calculateTableauNumbers(tableauSize);
            FRCFencer[] ft = fencerInTableau.ToArray();
            fencerInTableau.Clear();

            for (int i = 0; i < tableauSize; i += 2)
            {
                totalY              = currentYCoordinate + tableauSpace * 2;
                graphics            = checkYCoordinate(graphics, totalY);
                currentYCoordinate += tableauSpace;

                if (pageAdded)
                {
                    graphics.DrawString(title, font, XBrushes.Black, (x + tableauWidth) / 2, titleY, XStringFormats.TopLeft);
                    currentYCoordinate += fontHeight;
                    pageAdded           = false;
                }

                string name1, name2, name3, club1, club2, score;
                rank1 = interpreter.Tableau.getTableauNumber(i);
                rank2 = interpreter.Tableau.getTableauNumber(i + 1);
                if (!onlyOnce)
                {
                    fencer1 = getFencerFromTableauMatchingInitialRanking(rank1);
                    fencer2 = getFencerFromTableauMatchingInitialRanking(rank2);
                }
                else
                {
                    fencer1 = ft[i];
                    fencer2 = ft[i + 1];
                }

                if (fencer1 == null)
                {
                    name1 = "----------";
                    club1 = "";
                }
                else
                {
                    name1 = fencer1.LastName.ToUpper() + " " + fencer1.FirstName;
                    club1 = fencer1.Club;
                    if (name1.Length > 22)
                    {
                        name1 = name1.Remove(22);
                    }
                    if (club1.Length > 15)
                    {
                        club1 = club1.Remove(15);
                    }
                }
                if (fencer2 == null)
                {
                    name2 = "----------";
                    club2 = "";
                }
                else
                {
                    name2 = fencer2.LastName.ToUpper() + " " + fencer2.FirstName;
                    club2 = fencer2.Club;
                    if (name2.Length > 22)
                    {
                        name2 = name2.Remove(22);
                    }
                    if (club2.Length > 15)
                    {
                        club2 = club2.Remove(15);
                    }
                }

                if (fencer1 == null && fencer2 == null)
                {
                    winner = null;
                    name3  = "----------";
                    score  = "";
                }
                else if (fencer1 == null)
                {
                    winner = fencer2;
                    name3  = fencer2.LastName.ToUpper() + " " + fencer2.FirstName;
                    score  = "";
                }
                else if (fencer2 == null)
                {
                    winner = fencer1;
                    name3  = fencer1.LastName.ToUpper() + " " + fencer1.FirstName;
                    score  = "";
                }
                else
                {
                    match = tableauPart.getNextMatch();
                    //Skip matches with REF=0 in extended format of xml file.
                    while (match.FencerID1 == 0 || match.FencerID2 == 0)
                    {
                        match = tableauPart.getNextMatch();
                    }

                    fencer1 = getFencerFromTableauMatchingID(match.FencerID1);
                    fencer2 = getFencerFromTableauMatchingID(match.FencerID2);
                    if (match.Fencer1Win)
                    {
                        winner = fencer1;
                        name3  = fencer1.LastName.ToUpper() + " " + fencer1.FirstName;
                        if (match.Fencer2Abandon)
                        {
                            score = "by abandonment";
                        }
                        else if (match.Fencer2Forfait)
                        {
                            score = "by scratch";
                        }
                        else if (match.Fencer2Exclusion)
                        {
                            score = "by exclusion";
                        }
                        else
                        {
                            score = match.ScoreFencer1.ToString() + "/" + match.ScoreFencer2.ToString();
                        }
                    }
                    else
                    {
                        winner = fencer2;
                        name3  = fencer2.LastName.ToUpper() + " " + fencer2.FirstName;
                        if (match.Fencer1Abandon)
                        {
                            score = "by abandonment";
                        }
                        else if (match.Fencer1Forfait)
                        {
                            score = "by scratch";
                        }
                        else if (match.Fencer1Exclusion)
                        {
                            score = "by exclusion";
                        }
                        else
                        {
                            score = match.ScoreFencer2.ToString() + "/" + match.ScoreFencer1.ToString();
                        }
                    }
                }

                if (name3.Length > 18)
                {
                    name3 = name3.Remove(18);
                }

                fencerInTableau.Add(winner);

                tableauEndPoint.Add(drawTableauLines(graphics, new XPoint(x, currentYCoordinate), tableauSpace, tableauWidth,
                                                     tableauWidth * 0.7));
                graphics.DrawString(rank1.ToString(), font, XBrushes.Black, x, currentYCoordinate - 2);
                graphics.DrawString(name1, font, XBrushes.Black, x + 20, currentYCoordinate - 2);
                graphics.DrawString(club1, fontClub, XBrushes.Black, x + 20, currentYCoordinate + fontHeight * 0.8);
                currentYCoordinate += tableauSpace;
                graphics.DrawString(rank2.ToString(), font, XBrushes.Black, x, currentYCoordinate - 2);
                graphics.DrawString(name2, font, XBrushes.Black, x + 20, currentYCoordinate - 2);
                graphics.DrawString(club2, fontClub, XBrushes.Black, x + 20, currentYCoordinate + fontHeight * 0.8);

                XPoint point = tableauEndPoint[endPointIdx];
                endPointIdx++;
                graphics.DrawString(name3, font, XBrushes.Black, point.X + 5, point.Y - 2);
                graphics.DrawString(score, font, XBrushes.Black, point.X + 15, point.Y + fontHeight);
            }
            onlyOnce = true;
            graphics.Dispose();
        }