private Models.RingDetails CreateRing(ShowDetails day, Rings ring)
        {
            RingDetails rd = new RingDetails
            {
                RingId = ring.ID,
                RingNo = ring.RingNo,
                JudgeDetails = new List<JudgeDetails>(),
                ShowDetailsId = ring.ShowDetailsID
            };
            DataSet judgesDS = Rings.GetJudgesForRing(ring.ID);
            if (judgesDS.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow judgeRow in judgesDS.Tables[0].Rows)
                {
                    Judge judge = new Judge(judgeRow);
                    var judgeDetails = new JudgeDetails
                    {
                        JudgeId = judge.ID,
                        JudgeName = judge.Name,
                        RingOrder = judge.RingOrder,
                        ClassDetails = new List<ClassDetails>(),
                        HelperDetails = new List<Helper>()
                    };

                    var helperDS = Business.Helpers.GetHelpersForRing(day, ring.ID);
                    if (helperDS.Tables.Count > 0)
                    {
                        foreach (DataRow helperRow in helperDS.Tables[0].Rows)
                        {
                            Business.Helpers h = new Business.Helpers(helperRow);
                            String job = Fpp.Core.Utils.expandJob(h.Job, h.JobDetails);

                            Helper hd = new Helper
                            {
                                HelperId = h.ID,
                                HelperName = h.Name,
                                JobDescription = Business.Helpers.expandHelper(h)
                            };
                            judgeDetails.HelperDetails.Add(hd);
                        }
                    }

                    DataSet classesDS = judge.getClassesForJudge();
                    if (classesDS.Tables.Count > 0)
                    {
                        foreach (DataRow classRow in classesDS.Tables[0].Rows)
                        {
                            ShowClasses sc = new ShowClasses(classRow);
                            var Part = Convert.ToInt32(classRow["Part"]);
                            var PartNo = "";
                            var ClassName = classRow["ShortName"].ToString();
                            if (sc.EntryType == 10)
                            {
                                ClassName = classRow["Name"].ToString();
                                if (ClassName.Contains("Jumping"))
                                    ClassName = "Jumping";
                                else if (ClassName.Contains("Agility"))
                                    ClassName = "Agility";
                                else if (ClassName.Contains("Final"))
                                    ClassName = "Final";
                                ClassName = string.Format("{0} {1} {2}",
                                    ShowClasses.expandHeightShort(classRow),
                                    sc.ShortClassName,
                                    ClassName);
                            }
                            else
                            {
                                PartNo = (Part == 0 ? "" : string.Format("Pt {0}", Part));
                                ClassName = string.Format("{0} {1} {2} {3} {4} {5}",
                                    ShowClasses.expandHeightShort(classRow),
                                    ShowClasses.expandCatagoryShort(classRow),
                                    ClassName,
                                    ShowClasses.shortenName(classRow),
                                    ShowClasses.shortenGrades(classRow),
                                    PartNo);
                            }
                            judgeDetails.ClassDetails.Add(new ClassDetails
                            {
                                ClassId = sc.ID,
                                ClassNo = sc.ClassNo,
                                PartNo = Part,
                                DogsInClass = Fpp.Core.Utils.CalcDogsInCalc(classRow),
                                ClassName = ClassName,
                                Height = sc.Height
                            });
                        }
                    }
                    rd.JudgeDetails.Add(judgeDetails);
                }
            }
            return rd;
        }
        private void printRingForUser(UserShows userShow, int UserID, Document doc, ref List<int> defaultUsers, ref int pageCount)
        {
            float[] ringColumns = new float[] { 300, 300, 300, 300 };

            User currentUser = new User(userShow.Userid);
            Shows show = new Shows(userShow.ShowID);

            List<ShowDetails> showDetailsList = ShowDetails.GetShowDetails(userShow.ShowID);

            Rings r = new Rings();
            DataSet ringList = r.GetAllRingsForShow(userShow.ShowID, "ShowDate");

            Dogs d = new Dogs();

            DogClasses dc = new DogClasses();
            DateTime dt = DateTime.Now;
            string currentJudge = "";
            int currentRingID = 0;
            int ShowDetailsID = -1;
            int PrevShowDetailsID = -1;
            PdfPTable rings = new PdfPTable(ringColumns);

            int ringCnt = 0;
            PdfPCell cell = null;
            PdfPTable ringDetails = null;
            PdfPTable classDetailsTable = null;
            List<int> dogsRunningToday = new List<int>();
            PdfPTable headerPage = null;
            List<TeamPairsTrioDto> pairsTeams = new List<TeamPairsTrioDto>();
            try
            {
                foreach (DataRow ringRow in ringList.Tables[0].Rows)
                {
                    Rings ring = new Rings(ringRow);
                    int RingID = Convert.ToInt32(ringRow["RingID"]);
                    int EntryType = Convert.ToInt32(ringRow["EntryType"]);
                    int Lho = Convert.ToInt32(ringRow["Lho"]);
                    ShowDetailsID = Convert.ToInt32(ringRow["ShowDetailsID"]);

                    if (ringRow.IsNull("ClassID"))
                    {
                        continue;
                    }
                    int ClassID = Convert.ToInt32(ringRow["ClassID"]);
                    int ClassNo = Convert.ToInt32(ringRow["ClsNo"]);
                    DateTime rowDT = Convert.ToDateTime(ringRow["ShowDate"]);
                    if (rowDT != dt)
                    {
                        if (currentRingID != 0)
                        {
                            if (ringCnt % MaxColumns != 0)
                            {
                                var remind = ringCnt % MaxColumns;
                                while (remind-- > 0)
                                {
                                    cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                                    cell.BorderWidth = 0;
                                    rings.AddCell(cell);
                                }
                            }
                            if (dogsRunningToday.Count() > 0 || UserID == -1)
                            {
                                doc.Add(headerPage);
                                doc.Add(rings);
                                if (UserID > -1)
                                {
                                    if (currentUser.UserID != UserID)
                                    {
                                        User defaultHandler = new User(UserID);
                                    }
                                }

                                doc.NewPage();
                                pageCount++;
                            }
                        }

                        dogsRunningToday.Clear();
                        if (UserID > -1)
                        {
                            if (currentUser.UserID == UserID)
                            {
                                headerPage = DrawHeader(show, rowDT, currentUser, userShow);
                            }
                            else
                            {
                                User defaultHandler = new User(UserID);
                                headerPage = DrawHeader(show, rowDT, defaultHandler, userShow);
                            }
                        }
                        else
                        {
                            headerPage = DrawHeader(show, rowDT, null, null);

                        }
                        dt = rowDT;
                        rings = new PdfPTable(ringColumns);
                        rings.WidthPercentage = 100;
                        ringCnt = 0;
                    }

                    if (currentRingID != RingID)
                    {
                        currentJudge = "";
                        ringCnt++;
                        ringDetails = new PdfPTable(1);
                        rings.AddCell(new PdfPCell(ringDetails));

                        //List<Judge> judgeList = Judge.getJudgesForRingList(RingID);
                        string JudgeName = Judge.getJudgeForClass(ClassID).Name;
                        int ClsCount = DogClasses.GetDogsInRing(RingID);

                        cell = new PdfPCell(new Phrase(new Chunk(string.Format("Ring No {0} ({1})", ringRow["RingNo"].ToString(), ClsCount), judgeFont)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        ringDetails.AddCell(cell);

                        if (currentJudge != JudgeName)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(JudgeName), judgeFont)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            ringDetails.AddCell(cell);
                            currentJudge = JudgeName;
                        }
                        currentRingID = RingID;
                        classDetailsTable = new PdfPTable(DetailsColWidths);
                        classDetailsTable.DefaultCell.BorderWidth = 0;
                        ringDetails.AddCell(classDetailsTable);
                    }
                    else
                    {
                        string JudgeName = Judge.getJudgeForClass(ClassID).Name;
                        if (currentJudge != JudgeName)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk("  ", judgeFont)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            ringDetails.AddCell(cell);
                            cell = new PdfPCell(new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(JudgeName), judgeFont)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            ringDetails.AddCell(cell);

                            classDetailsTable = new PdfPTable(DetailsColWidths);
                            classDetailsTable.DefaultCell.BorderWidth = 0;
                            ringDetails.AddCell(classDetailsTable);
                            currentJudge = JudgeName;
                        }
                    }
                    DataSet dogsList = d.GetDogsInClass(userShow.Userid, ClassID);
                    int dogsInClass = d.dogsInClassCount(ClassID);
                    List<DogClassCount> dcCounts = DogClasses.GetEntryCountsByClassId(userShow.ShowID, ClassID);

                    String clsName;
                    var part = Convert.ToInt32(ringRow["Part"]);
                    var lhoInd = "";
                    var dogsInClassDisplay = "";
                    if (dcCounts.Count > 1)
                    {
                        if (Lho == 1) {
                            dogsInClassDisplay = String.Format("({0}/{1})", dcCounts[0].Count, dcCounts[1].Count);
                        }
                        else
                        {
                            dogsInClassDisplay = String.Format("({0}/{1})", dcCounts[1].Count, dcCounts[0].Count);
                        }
                    }
                    else
                    {
                        dogsInClassDisplay = String.Format("({0})", dogsInClass);
                    }

                    if (Lho == 1)
                    {
                        lhoInd = "(FH 1st)";
                    }
                    else if (Lho == 2)
                    {
                        lhoInd = "(LHO 1st)";
                    }
                    if (EntryType != 10)
                    {
                        clsName = new ShowClasses(ClassID).NormalName(withClassNo:false, useAbbrFlag:true);
                    }
                    else
                    {
                        clsName = String.Format("{0} {1} {2} ",
                                        ShowClasses.expandHeight(ringRow),
                                        ringRow["LongName"].ToString().Trim(),
                                        ringRow["name"].ToString().Trim());
                    }
                    clsName = clsName.Replace("(Special Class", "S");
                    clsName = clsName.Replace("(Money Class", "Money");
                    clsName = clsName.Replace("First Place Processing", "FPP");
                    clsName = clsName.Replace("First Contact", "FC");
                    clsName = clsName.Replace("Qualifier", "Q");

                    if (part > 0 && EntryType != 10)
                    {
                        clsName += "Pt " + part;
                    }

                    if (dogsList.Tables[0].Rows.Count > 0)
                    {
                        /*
                        Combined 1-7 All Allsorts Agility sponsored by paws for a walk
                        Combined 6-7 Medium Agility

                            * */
                        var WrapClassDescription = clsName.Length > 45;
                        Phrase[] tmpCells = new Phrase[3];
                        tmpCells[0] = new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogInClass));
                        tmpCells[1] = new Phrase(new Chunk(clsName, dogInClass));
                        tmpCells[2] = new Phrase(new Chunk(dogsInClassDisplay, dogNotInClass ));

                        int countDogs = 0;
                        int DefaultHandler;

                        Paragraph p = new Paragraph();
                        List<Paragraph> allDogsInClass = new List<Paragraph>();
                        foreach (DataRow dogRow in dogsList.Tables[0].Rows)
                        {
                            var dogLho = Convert.ToInt32(dogRow["Lho"]);
                            int DogID = Convert.ToInt32(dogRow["DogID"]);
                            DefaultHandler = Convert.ToInt32(dogRow["DefaultHandler"]);
                            if (DefaultHandler == 0) DefaultHandler = -1;
                            if ((DefaultHandler == -1 && currentUser.UserID == UserID) ||
                                (DefaultHandler == UserID)
                                )
                            {
                                if (countDogs == 0)
                                {
                                    cell = new PdfPCell(tmpCells[0]);
                                    cell.BorderWidth = 0;
                                    cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                    classDetailsTable.AddCell(cell);
                                    var namePara = new Paragraph();
                                    namePara.Add(tmpCells[1]);
                                    namePara.Add(new Phrase(new Chunk(lhoInd, lhoFontBold)));
                                    p.Add(namePara);
                                }
                                if (!dogsRunningToday.Contains(DogID))
                                {
                                    dogsRunningToday.Add(DogID);
                                }
                                String dogName = dogRow["DogName"].ToString();
                                if (dogName.Length == 0)
                                {
                                    dogName = dogRow["KCName"].ToString();
                                }
                                var chunk = new Chunk("   ", dogDetailsInClass);
                                chunk.SetBackground(new Color(System.Drawing.ColorTranslator.FromHtml(dogRow["DogColour"].ToString())));

                                var dogPara = new Paragraph();
                                dogPara.Add(new Phrase(chunk));

                                if (TeamPairsManager.isMultiDog( EntryType ))
                                {
                                    pairsTeams.Add(new TeamPairsTrioDto
                                    {
                                        ClassId = ClassID,
                                        ClassNo = ClassNo,
                                        DogId = DogID,
                                        DogName = dogName,
                                        RO = -1
                                    });
                                }
                                dogPara.Add(new Phrase(new Chunk(String.Format(" [{1}] {0}", Fpp.Core.Utils.TitleCaseString(dogName), dogRow["RO"]), dogDetailsInClass)));
                                dogPara.Add(new Phrase(new Chunk(String.Format("{0}", (dogLho == 0 ? "" : " (LHO)")), font8)));
                                dogPara.Add(Chunk.NEWLINE);

                                int AltHandler = Convert.ToInt32(dogRow["AltHandler"]);
                                String HandlerName = "";
                                if (AltHandler > 0)
                                {
                                    User u = new User(AltHandler);
                                    HandlerName = u.Name;
                                    dogPara.Add(new Phrase(new Chunk(String.Format("Handler:{0}", Fpp.Core.Utils.TitleCaseString(HandlerName)), dogInClass)));
                                }
                                allDogsInClass.Add(dogPara);
                                countDogs++;
                            }
                            else
                            {
                                if (defaultUsers != null && defaultUsers.IndexOf(DefaultHandler) == -1)
                                {
                                    defaultUsers.Add(DefaultHandler);
                                }
                            }
                        }
                        if (countDogs == 0)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogNotInClass)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                            classDetailsTable.AddCell(cell);

                            var namePara = new Paragraph();
                            namePara.Add(new Phrase(new Chunk(clsName, dogNotInClass)));
                            namePara.Add(new Phrase(new Chunk(lhoInd, lhoFontBold)));
                            p.Add(namePara);
                            cell = new PdfPCell(p);
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.NoWrap = false;
                            classDetailsTable.AddCell(cell);

                            cell = new PdfPCell(new Phrase(new Chunk(dogsInClassDisplay, dogNotInClass)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                            classDetailsTable.AddCell(cell);
                        }
                        else
                        {

                            cell = new PdfPCell(p);
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.NoWrap = false;

                            classDetailsTable.AddCell(cell);

                            cell = new PdfPCell(tmpCells[2]);
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                            classDetailsTable.AddCell(cell);

                            cell = new PdfPCell(new Phrase(new Chunk("", dogDetailsInClass)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.NoWrap = false;
                            classDetailsTable.AddCell(cell);

                            var tbl4Dogs = new PdfPTable(1);
                            foreach (var item in allDogsInClass)
                            {
                                cell = new PdfPCell(new Phrase(item));
                                cell.BorderWidth = 0;
                                cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                                tbl4Dogs.AddCell(cell);
                            }
                            cell = new PdfPCell();
                            cell.BorderWidth = 0;
                            cell.FixedHeight = 4f;
                            tbl4Dogs.AddCell(cell);

                            cell = new PdfPCell(tbl4Dogs);
                            cell.BorderWidth = 0;
                            cell.Colspan = 2;
                            classDetailsTable.AddCell(cell);
                        }
                    }
                    else
                    {
                        cell = new PdfPCell(new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogNotInClass)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        classDetailsTable.AddCell(cell);

                        var namePara = new Paragraph();
                        namePara.Add(new Phrase(new Chunk(clsName, dogNotInClass)));
                        namePara.Add(new Phrase(new Chunk(lhoInd, lhoFontBold)));
                        cell = new PdfPCell(namePara);
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        cell.NoWrap = false;
                        classDetailsTable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk(dogsInClassDisplay, dogNotInClass)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        classDetailsTable.AddCell(cell);

                    }

                    PrevShowDetailsID = ShowDetailsID;
                }

                if (dogsRunningToday.Count() > 0 || UserID == -1)
                {
                    if (ringCnt % MaxColumns != 0)
                    {
                        var remind = ringCnt % MaxColumns;
                        while (remind-- > 0)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                            cell.BorderWidth = 0;
                            rings.AddCell(cell);
                        }
                        doc.Add(headerPage);
                        doc.Add(rings);
                    }

                    if (UserID > -1)
                    {
                        if (currentUser.UserID != UserID)
                        {
                            User defaultHandler = new User(UserID);
                        }
                    }
                    doc.NewPage();
                    pageCount++;
                }
                else
                {
                    if (dogsRunningToday.Count() > 0)
                    {
                        if (ringCnt % MaxColumns != 0)
                        {
                            var remind = ringCnt % MaxColumns;
                            while (remind-- > 0)
                            {
                                cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                                cell.BorderWidth = 0;
                                rings.AddCell(cell);
                            }
                            doc.Add(headerPage);
                            doc.Add(rings);
                        }

                        if (UserID > -1)
                        {
                            if (currentUser.UserID != UserID)
                            {
                                User defaultHandler = new User(UserID);
                            }
                        }
                        doc.NewPage();
                        pageCount++;
                    }
                }
            }
            catch (Exception e)
            {
                AppException.LogError($"Error Running Plan:{e.Message},{e.StackTrace}");
            }
        }
        private Models.RingDetails CreateRing(ShowDetails day, Rings ring)
        {
            RingDetails rd = new RingDetails
            {
                JudgeDetails = new List<JudgeDetails>(),
                ShowDetailsId = ring.ShowDetailsID
            };
            DataSet judgesDS = Rings.GetJudgesForRing(ring.ID);
            if (judgesDS.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow judgeRow in judgesDS.Tables[0].Rows)
                {
                    Judge judge = new Judge(judgeRow);
                    var judgeDetails = new JudgeDetails
                    {
                        JudgeId = judge.ID,
                        JudgeName = judge.Name,
                        ClassDetails = new List<ClassDetails>(),
                        HelperDetails = new List<Helper>()
                    };

                    var helperDs = Business.Helpers.GetHelpersForRing(day, ring.ID);
                    if (helperDs.Tables.Count > 0)
                    {
                        foreach (DataRow helperRow in helperDs.Tables[0].Rows)
                        {
                            var h = new Business.Helpers(helperRow);
                            var hd = new Helper
                            {
                                HelperId = h.ID,
                                HelperName = h.Name,
                                JobDescription = h.Job
                            };
                            judgeDetails.HelperDetails.Add(hd);
                        }
                    }

                    DataSet classesDS = Rings.GetClassesForRing(ring.ID);
                    classesDS = judge.getClassesForJudge();
                    if (classesDS.Tables.Count > 0)
                    {
                        foreach (DataRow classRow in classesDS.Tables[0].Rows)
                        {

                            ShowClasses sc = new ShowClasses(classRow);
                            judgeDetails.ClassDetails.Add(new ClassDetails
                            {
                                ClassId = sc.ID,
                                ClassNo = sc.ClassNo,
                                DogsInClass = Fpp.Core.Utils.CalcDogsInCalc(classRow),
                                ClassName =
                                    $"{ShowClasses.expandHeightShort(classRow)} {ShowClasses.expandCatagoryShort(classRow)} {classRow["ShortName"]} {classRow["Name"]} {ShowClasses.shortenGrades(classRow)}"
                            });
                        }
                    }
                    rd.JudgeDetails.Add(judgeDetails);
                }
            }
            return rd;
        }
        public void RingBoards(Document doc, int ShowId, int RingId)
        {
            Font smallFont = new Font(Font.COURIER, 8, Font.NORMAL, Color.BLACK);
            Font normalFont = new Font(Font.COURIER, 10, Font.NORMAL, Color.BLACK);
            Font mediumFont = new Font(Font.HELVETICA, 20, Font.NORMAL, Color.BLACK);
            ShowClasses sc = new ShowClasses();

            List<Rings> AllRings = new List<Rings>();
            if (RingId == -1)
            {
                AllRings = Rings.GetAllRingsForShow(ShowId);
            }
            else
            {
                AllRings.Add(new Rings(RingId));
            }
            var showDetailsList = ShowDetails.GetShowDetails(ShowId);
            Shows show = new Shows(ShowId);
            foreach (var showDetails in showDetailsList)
            {
                Rings rings = new Rings();
                var ringsForDays = Rings.GetRingsForShowDayList(showDetails.ID);
                //            var groupByRing = ringsForDays.GroupBy(x => x.RingNo);
                int lastRingNo = 0;
                foreach (Rings ring in ringsForDays)
                {
                    if (ring.ID > -1 && lastRingNo != ring.RingNo)
                    {
                        lastRingNo = ring.RingNo;
                        doc.NewPage();

                        DataSet judgesDS = Rings.GetJudgesForRing(ring.ID);
                        if (judgesDS.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow judgeRow in judgesDS.Tables[0].Rows)
                            {
                                Judge judge = new Judge(judgeRow);
                                CreateRing(doc, show, showDetails, ring, judge, "", lastRingNo);
                            }
                        }
                    }
                }
            }
            doc.NewPage();
        }
        public int ScoreBoards(Document doc, int showId, int ringId, int position = -1)
        {
            var ret = 0;
            var bigBoyFont = new Font(Font.HELVETICA, 20, Font.BOLD, Color.BLACK);
            var sc = new ShowClasses();
            var currentRing = new Rings(ringId);
            var showClasses = ShowClasses.GetAllClassesForShowRing(showId, ringId, position);
            ret = showClasses.Count;
            float[] colWidthsTeam = { 30, 150, 150, 50, 50, 50 };
            float[] colWidths = { 30, 50, 150, 150, 50, 50, 50 };
            PdfPTable callingListTbl = null;
            var currentClassNo = 0;
            var multiClasses = TeamPairsManager.GetTeamPairClasses(showId);
            var multiTeams = TeamPairsManager.GetTeamPairsForShow(showId, multiClasses);

            foreach (var showClass in showClasses)
            {
                var grades = showClass.Grades;
                var gradeIdx = 0;

                do
                {
                    if (currentClassNo != showClass.ClassNo)
                    {
                        callingListTbl = TeamPairsManager.isMultiDog(showClass.EntryType) ? new PdfPTable(colWidthsTeam) : new PdfPTable(colWidths);
                        callingListTbl.HeaderRows = 2;
                    }

                    var currentGrade = Convert.ToInt32(showClass.Grades[gradeIdx]) - 48;
                    string tmp;
                    if (showClass.EntryType == 10)
                    {
                        grades = "";
                        tmp = string.Format("Ring {4} - Class {0}: {1} {2} {3}",
                            showClass.ClassNo, showClass.longHeight, showClass.LongClassName,
                            showClass.ClassName, currentRing.RingNo);
                    }
                    else
                    {
                        if (grades.Length == 1)
                        {
                            grades = "Grade " + grades;
                        }
                        else
                        {
                            grades = "Grades " + grades[0] + "-" + grades[grades.Length - 1];
                        }
                        tmp = showClass.Catagory == 0 ?
                            $"Ring {currentRing.RingNo} - Class {showClass.ClassNo}: {showClass.longHeight} Graded {showClass.LongClassName} Grade {currentGrade} {showClass.ClassName}{(showClass.Part > 0 ? " Part " + showClass.Part : "")}"
                            : $"Ring {currentRing.RingNo} - Class {showClass.ClassNo}: {showClass.NormalName(false)} {(showClass.Part > 0 ? " Part " + showClass.Part : "")}";
                    }
                    var cell = new PdfPCell(new Phrase(new Chunk(tmp, bigBoyFont)))
                    {
                        Colspan = 7,
                        BorderWidth = 0
                    };
                    callingListTbl.AddCell(cell);
                    doc.Add(callingListTbl);
                    DrawCourseBoxes(doc);

                    var callingList = showClass.Catagory == 0 ? sc.GetCallingList(showId, showClass.ID, currentGrade) : sc.GetCallingList(showId, showClass.ID);

                    ScoreBoardColumnHeaders(showClass, callingListTbl, callingList, colWidths);

                    if (TeamPairsManager.isMultiDog(showClass.EntryType))
                    {
                        TeamScoreBoard(multiTeams, showClass, callingListTbl);
                    }
                    else
                    {
                        var lhoCurrent = callingList.Any() ? callingList.First().Lho : 0;
                        var lineCnt = 0;
                        foreach (var item in callingList)
                        {

                            if (item.Lho != lhoCurrent)
                            {
                                doc.Add(callingListTbl);
                                doc.NewPage();
                                callingListTbl = new PdfPTable(colWidths);
                                lhoCurrent = item.Lho;

                                ScoreBoardColumnHeaders(showClass, callingListTbl, callingList, colWidths);
                                //var cnt = callingList.Count(x => x.Lho == item.Lho);
                                //var title = $"{(item.Lho == 0 ? "Full Height " : "Lower Height")} ({cnt})";
                                //callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk(title, headerHFont)))
                                //{
                                //    BorderWidth = 0,
                                //    Colspan = colWidths.Length,
                                //    BackgroundColor = Color.LIGHT_GRAY,
                                //    HorizontalAlignment = Element.ALIGN_CENTER,
                                //    FixedHeight = 20,
                                //    BorderColorBottom = Color.BLACK,
                                //    BorderWidthBottom = 2
                                //});
                            }

                            var altColor = (lineCnt % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY);
                            cell = new PdfPCell(new Phrase(new Chunk($"{item.Ro}", _normal10Black)))
                            {
                                BorderWidth = 0,
                                FixedHeight = 20f,
                                BackgroundColor = altColor,
                                HorizontalAlignment = Element.ALIGN_RIGHT
                            };
                            callingListTbl.AddCell(cell);

                            int borderWidth = 0;
                            if (showClass.EntryType == 5 || showClass.EntryType == 9) borderWidth = 1;
                            callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk($"{item.RingNumber}", _normal10Black)))
                            {
                                HorizontalAlignment = Element.ALIGN_RIGHT,
                                BackgroundColor = altColor,
                                BorderWidth = borderWidth
                            });

                            var handlerName = item.Name;
                            User user;
                            if (item.DefaultHandlerId > 0)
                            {
                                user = new User(item.DefaultHandlerId);
                                handlerName = user.Name;
                            }
                            if (item.AltHandlerId > 0)
                            {
                                user = new User(item.AltHandlerId);
                                handlerName = user.Name;
                            }

                            cell = new PdfPCell(new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(handlerName), _normal10Black)))
                            {
                                BackgroundColor = altColor,
                                BorderWidth = borderWidth
                            };
                            callingListTbl.AddCell(cell);

                            cell =
                                new PdfPCell(
                                    new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(item.KcName), _normal10Black)))
                                {
                                    BackgroundColor = altColor,
                                    BorderWidth = borderWidth
                                };
                            callingListTbl.AddCell(cell);

                            cell = new PdfPCell(new Phrase(""));
                            cell.BorderWidth = 1;
                            if (showClass.EntryType == 4)
                            {
                                cell.BorderWidthBottom = 0;
                            }
                            callingListTbl.AddCell(cell);
                            cell = new PdfPCell(new Phrase(""));
                            cell.BackgroundColor = Color.WHITE;
                            cell.BorderWidth = 1;
                            if (showClass.EntryType == 4)
                            {
                                cell.BorderWidthBottom = 0;
                            }
                            callingListTbl.AddCell(cell);
                            callingListTbl.AddCell(cell);
                            lineCnt++;
                        }
                        cell = new PdfPCell(new Phrase(""));
                        cell.BorderWidth = 0;
                        cell.Colspan = 7;
                        cell.FixedHeight = 50f;
                        callingListTbl.AddCell(cell);
                    }

                    doc.Add(callingListTbl);
                    gradeIdx++;

                } while (showClass.Catagory == 0 && gradeIdx < showClass.Grades.Length);
                doc.NewPage();
            }

            return ret;
        }
        public int CallingSheets(Document doc, int showId, int ringId, PdfWriter writer, int position = -1)
        {
            doc.Open();
            var font = new Font(Font.COURIER, 10, Font.NORMAL, Color.BLACK);
            var fontBold = new Font(Font.COURIER, 10, Font.BOLD, Color.BLACK);
            var sc = new ShowClasses();
            var currentRing = new Rings(ringId);
            var showClasses = ShowClasses.GetAllClassesForShowRing(showId, ringId, position);
            var ret = showClasses.Count;
            float[] colWidthsStandard = { 35, 35, 50, 200, 200 };
            float[] colWidthsTeam = { 35, 200, 200 };
            PdfPTable callingListTbl = null;
            var currentClassNo = 0;
            var multiClasses = TeamPairsManager.GetTeamPairClasses(showId);
            var multiTeams = TeamPairsManager.GetTeamPairsForShow(showId, multiClasses);
            foreach (var showClass in showClasses)
            {
                var colWidths = (TeamPairsManager.isMultiDog(showClass.EntryType) ? colWidthsTeam : colWidthsStandard);
                if (currentClassNo != showClass.ClassNo)
                {
                    if (currentClassNo != 0)
                    {

                    }
                    callingListTbl =
                        new PdfPTable(colWidths)
                        {
                            HeaderRows = 2
                        };
                }
                string tmp;
                if (TeamPairsManager.isMultiDog(showClass.EntryType) || showClass.EntryType == 10)
                {
                    tmp =
                        $"Ring No:{currentRing.RingNo}   Class No:{showClass.ClassNo} {showClass.longHeight} {showClass.LongClassName} {showClass.ClassName}";
                }
                else
                {
                    //                    tmp = String.Format("Ring No:{5}   Class No:{0} {1} {2} {3} {6} {7} {4}", showClass.ClassNo, showClass.longHeight, showClass.longCatagory, showClass.LongClassName, grades, currentRing.RingNo, showClass.ClassName, (showClass.Part > 0 ? "Part " + showClass.Part : ""));
                    tmp = $"Ring No:{currentRing.RingNo}   Class No:{showClass.NormalName()}";
                    tmp += $" {(showClass.Part > 0 ? "Part " + showClass.Part : "")}";
                }
                var cell = new PdfPCell(new Phrase(new Chunk(tmp, ClassTitleFont)))
                {
                    Colspan = colWidths.Length,
                    BorderWidth = 0,
                    FixedHeight = 40F
                };
                callingListTbl.AddCell(cell);

                cell = new PdfPCell(new Phrase(new Chunk("", ClassTitleFont)))
                {
                    Colspan = colWidths.Length,
                    BorderWidth = 0
                };
                callingListTbl.AddCell(cell);
                doc.Add(callingListTbl);
                callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("RO", headerFont))) { BorderWidth = 0, HorizontalAlignment = Element.ALIGN_RIGHT});

                if (!TeamPairsManager.isMultiDog(showClass.EntryType))
                {
                    callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk(" ", headerFont))) { BorderWidth = 0 });
                    callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Ring No", headerFont))) { BorderWidth = 0, HorizontalAlignment =  Element.ALIGN_RIGHT});
                }
                callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Handler", headerFont))) { BorderWidth = 0 });
                callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Dog Name", headerFont))) { BorderWidth = 0 });
                doc.Add(callingListTbl);
                int altFlag = 0;
                Color altLine = Color.LIGHT_GRAY;
                callingListTbl = new PdfPTable((TeamPairsManager.isMultiDog(showClass.EntryType) ? colWidthsTeam : colWidths));
                if (TeamPairsManager.isMultiDog(showClass.EntryType))
                {
                    var teamsForClass = multiTeams.Where(t => t.ClassId == showClass.ID).OrderBy(t => t.RO);

                    foreach (var team in teamsForClass)
                    {
                        var altColor = Color.WHITE;
                        if (altFlag % 2 == 0 && showClass.EntryType != 5)
                        {
                            altColor = altLine;
                        }

                        cell = new PdfPCell(new Phrase(new Chunk(team.RO.ToString(), headerHFont)))
                        {
                            BorderWidth = 0,
                            BackgroundColor = altColor
                        };
                        callingListTbl.AddCell(cell);

                        if (TeamPairsManager.isTeam(showClass.EntryType))
                        {
                            cell =
                                new PdfPCell(
                                    new Phrase(new Chunk("Team Name:" + team.TeamDetails.TeamName.Replace("&#39;", "'"),
                                        headerHFont)))
                                {
                                    BackgroundColor = altColor,
                                    BorderWidth = 0
                                };
                            callingListTbl.AddCell(cell);

                            cell =
                                new PdfPCell(
                                    new Phrase(new Chunk("Captain:" + team.TeamDetails.Captain.Replace("&#39;", "'"),
                                        headerHFont)))
                                {
                                    BackgroundColor = altColor,
                                    BorderWidth = 0
                                };
                            callingListTbl.AddCell(cell);

                            cell = new PdfPCell(new Phrase(new Chunk("", headerHFont)))
                            {
                                BackgroundColor = altColor,
                                BorderWidth = 0
                            };
                            callingListTbl.AddCell(cell);
                        }

                        var dogCnt = 0;
                        var handlerPara = new Paragraph();
                        var dogPara = new Paragraph();
                        foreach (var member in team.Members)
                        {
                            if (dogCnt < team.DogCount)
                            {
                                if (dogCnt > 0)
                                {
                                    handlerPara.Add(new Phrase(Chunk.NEWLINE));
                                    dogPara.Add(new Phrase(Chunk.NEWLINE));
                                }

                                handlerPara.Add(new Phrase(new Chunk(Utils.TitleCaseString(member.HandlerName).Replace("&#39;", "'"), font)));
                                dogPara.Add(new Phrase(new Chunk(Utils.TitleCaseString(member.DogName).Replace("&#39;", "'"), font)));
                            }
                            dogCnt++;
                        }
                        cell = new PdfPCell(handlerPara)
                        {
                            BorderWidth = 0,
                            BorderWidthTop = 0,
                            BackgroundColor = altColor
                        };
                        callingListTbl.AddCell(cell);

                        cell = new PdfPCell(dogPara)
                        {
                            BorderWidth = 0,
                            BorderWidthTop = 0,
                            BackgroundColor = altColor
                        };
                        callingListTbl.AddCell(cell);
                        doc.Add(callingListTbl);

                        altFlag++;
                        callingListTbl = new PdfPTable((TeamPairsManager.isMultiDog(showClass.EntryType) ? colWidthsTeam : colWidths));

                        var lineLeft = writer.GetVerticalPosition(false) - doc.BottomMargin;
                        if (lineLeft < 50)
                        {
                            doc.NewPage();
                        }
                    }
                }
                else
                {
                    var callingList = sc.GetCallingList(showId, showClass.ID);
                    foreach (var item in callingList)
                    {

                        Color altColor = Color.WHITE;
                        if (altFlag % 2 == 0 && showClass.EntryType != 5)
                        {
                            altColor = altLine;
                        }

                        callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk($"{item.Ro}", font)))
                        {
                            BorderWidth = 0,
                            BackgroundColor = altColor,
                            HorizontalAlignment = Element.ALIGN_RIGHT
                        });

                        var borderWidth = 0;
                        callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk(item.Lho == 0 ? "" : "LHO", font)))
                        {
                            HorizontalAlignment = Element.ALIGN_RIGHT,
                            BackgroundColor = altColor,
                            BorderWidth = borderWidth
                        });
                        callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk($"{item.RingNumber}", font)))
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER,
                            BackgroundColor = altColor,
                            BorderWidth = borderWidth
                        });

                        var handlerName = Utils.TitleCaseString(item.Name);
                        User user;
                        var namePhrase = new Phrase();
                        var us = new UserShows(item.UserId, showId);
                        if (item.DefaultHandlerId > 0)
                        {
                            user = new User(item.DefaultHandlerId);
                            handlerName = user.Name;
                        }
                        if (item.AltHandlerId > 0)
                        {
                            user = new User(item.AltHandlerId);
                            handlerName = user.Name;
                        }

                        if (us.HandlerType == (int)Core.Enums.DiscountTypes.Member)
                        {
                            namePhrase.Add(new Chunk("(M)", fontBold));
                            namePhrase.Add(new Chunk(Utils.TitleCaseString(handlerName), fontBold));
                        }
                        else
                        {
                            namePhrase.Add(new Chunk(Utils.TitleCaseString(handlerName), font));
                        }
                        cell = new PdfPCell(namePhrase)
                        {
                            BackgroundColor = altColor,
                            BorderWidth = borderWidth
                        };
                        callingListTbl.AddCell(cell);

                        cell =
                            new PdfPCell(
                                new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(item.KcName), font)))
                            {
                                BackgroundColor = altColor,
                                BorderWidth = borderWidth
                            };
                        callingListTbl.AddCell(cell);

                        altFlag++;
                    }
                    doc.Add(callingListTbl);
                }
                doc.NewPage();
            }
            return ret;
        }
        public int ResultSheets(Document doc, int ShowID, int RingID, int Position , bool pagePerClass, PdfWriter writer )
        {
            int ret = 0;
            Font smallFont = new Font(Font.COURIER, 8, Font.NORMAL, Color.BLACK);
            Font normalFont = new Font(Font.COURIER, 10, Font.NORMAL, Color.BLACK);
            Font bigFont = new Font(Font.HELVETICA, 25, Font.NORMAL, Color.BLACK);
            Font mediumFont = new Font(Font.HELVETICA, 20, Font.NORMAL, Color.BLACK);
            ShowClasses sc = new ShowClasses();
            Rings currentRing = new Rings(RingID);
            List<ShowClasses> showClasses = ShowClasses.GetAllClassesForShowRing(ShowID, RingID, Position);
            var storedResults = Business.TrophiesRosettes.getTandRForShow(ShowID);
            var lineLeft = writer.GetVerticalPosition(false) - doc.BottomMargin;

            ret = showClasses.Count;
            PdfPTable callingListTbl = null;
            foreach (ShowClasses showClass in showClasses)
            {
                var resultCnts = storedResults.Where(x => x.ClsNo == showClass.ClassNo);

                int gradeidx = 0;
                foreach (var totals in resultCnts)
                {
                    PdfPTable ptable = new PdfPTable(3);
                    PdfPCell cell;

                    String grades;
                    String subTitle;

                    if (_writer != null)
                    {
                        _writer.GetVerticalPosition(false);
                    }

                    if (showClass.Catagory == 0)
                    {
                        if (gradeidx < showClass.Grades.Length)
                        {
                            grades = "Grade " + showClass.Grades[gradeidx];
                        }
                        else
                        {
                            grades = showClass.Grades;
                        }
                        subTitle = String.Format("{0} {1} {2} {3} {5}{6} Judge: {4}", showClass.longHeight, showClass.longCatagory, showClass.LongClassName, grades, Judge.getJudgeForClass(showClass.ID).JudgeName, showClass.ClassName, (showClass.Part > 0 ? "Part " + showClass.Part : ""));
                    }
                    else
                    {
                        if (showClass.Grades.Length == 1)
                        {
                            grades = showClass.Grades;
                        }
                        else
                        {
                            grades = showClass.Grades[0] + " - " + showClass.Grades[showClass.Grades.Length - 1];
                        }
                        subTitle = String.Format("{0} {1} Judge: {2}", showClass.NormalName(withClassNo:false), (showClass.Part > 0 ? "Part " + showClass.Part : ""), Judge.getJudgeForClass(showClass.ID).JudgeName);

                    }
                    String tmp = String.Format("Ring No:{0} - Result Sheet ", currentRing.RingNo);
                    cell = new PdfPCell(new Phrase(new Chunk(tmp, bigFont)));
                    cell.Colspan = 2;
                    cell.BorderWidth = 0;
                    ptable.AddCell(cell);

                    tmp = String.Format("Class No:{0}", showClass.ClassNo);
                    cell = new PdfPCell(new Phrase(new Chunk(tmp, bigFont)));
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    cell.BorderWidth = 2;
                    cell.Padding = 5;
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase(new Chunk(subTitle, mediumFont)));
                    cell.Colspan = 3;
                    cell.BorderWidth = 0;
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase(new Chunk("", ClassTitleFont)));
                    cell.Colspan = 3;
                    cell.BorderWidth = 0;
                    ptable.AddCell(cell);
                    ptable.AddCell(cell);
                    ptable.AddCell(cell);
                    doc.Add(ptable);
                    DrawCourseBoxes(doc);

                    float[] colWidths = { 75, 75, 200, 200, 50, 75 };
                    callingListTbl = new PdfPTable(colWidths);

                    cell = new PdfPCell(new Phrase(new Chunk("Place", headerHFont)));
                    cell.BorderWidth = 1;
                    cell.BorderWidthBottom = 0;
                    cell.FixedHeight = 35f;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    callingListTbl.AddCell(cell);

                    if (TeamPairsManager.isMultiDog(showClass.EntryType))
                    {
                        if (TeamPairsManager.isTeam(showClass.EntryType))
                        {
                            cell = new PdfPCell(new Phrase(new Chunk("Team Name", headerHFont)));
                        }
                        else
                        {
                            cell = new PdfPCell(new Phrase(new Chunk("Handler/Dog", headerHFont)));
                        }
                        cell.BorderWidth = 1;
                        cell.BorderWidthBottom = 0;
                        cell.Colspan = 3;
                        callingListTbl.AddCell(cell);
                    } else
                    {
                        cell = new PdfPCell(new Phrase(new Chunk("Ring Number", headerHFont)));
                        cell.BorderWidth = 1;
                        cell.BorderWidthBottom = 0;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        callingListTbl.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk("Handler", headerHFont)));
                        cell.BorderWidth = 1;
                        cell.BorderWidthBottom = 0;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        callingListTbl.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk("Dog Name", headerHFont)));
                        cell.BorderWidth = 1;
                        cell.BorderWidthBottom = 0;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        callingListTbl.AddCell(cell);

                    }

                    cell = new PdfPCell(new Phrase(new Chunk("Clear/ Faults", headerHFont)));
                    cell.BorderWidth = 1;
                    cell.BorderWidthBottom = 0;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    callingListTbl.AddCell(cell);

                    cell = new PdfPCell(new Phrase(new Chunk("Time", headerHFont)));
                    cell.BorderWidth = 1;
                    cell.BorderWidthBottom = 0;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    callingListTbl.AddCell(cell);

                    int maxRosettes = totals.Rosettes;// Utils.calcRosettes(dogCounts);
                    int maxTrophies = totals.Trophies; // Utils.calcTrophies(dogCounts);
                    float rowHeight = 25f;
                    if (TeamPairsManager.isMultiDog(showClass.EntryType)  )
                    {
                        rowHeight = (TeamPairsManager.isTeam(showClass.EntryType)) ? 120f : 65f;
                    }

                    for (int resultRow = 0; resultRow < maxRosettes; resultRow++)
                    {
                        int bwb = 0;
                        if (resultRow == maxRosettes - 1)
                        {
                            bwb = 1;
                        }
                        Color background = Color.WHITE;
                        if (maxTrophies > 0)
                        {
                            background = Color.LIGHT_GRAY;
                        }
                        maxTrophies--;
                        cell = new PdfPCell(new Phrase(new Chunk(calcPlace(resultRow + 1), normalFont)));
                        cell.BorderWidth = 1;
                        cell.BorderWidthBottom = bwb;
                        cell.FixedHeight = rowHeight;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        cell.BackgroundColor = background;
                        callingListTbl.AddCell(cell);

                        if (TeamPairsManager.isMultiDog(showClass.EntryType))
                        {
                            cell = new PdfPCell(new Phrase(new Chunk("", normalFont)));
                            cell.BorderWidth = 1;
                            cell.BackgroundColor = background;
                            cell.BorderWidthBottom = bwb;
                            cell.Colspan = 3;
                            callingListTbl.AddCell(cell);
                            cell = new PdfPCell(new Phrase(new Chunk("", normalFont)));
                            cell.BorderWidth = 1;
                            cell.BackgroundColor = background;
                            cell.BorderWidthBottom = bwb;
                            callingListTbl.AddCell(cell);
                            callingListTbl.AddCell(cell);

                        }
                        else
                        {
                            cell = new PdfPCell(new Phrase(new Chunk("", normalFont)));
                            cell.BorderWidth = 1;
                            cell.BackgroundColor = background;
                            cell.BorderWidthBottom = bwb;

                            callingListTbl.AddCell(cell);
                            callingListTbl.AddCell(cell);
                            callingListTbl.AddCell(cell);
                            callingListTbl.AddCell(cell);
                            callingListTbl.AddCell(cell);
                        }

                    }
                    doc.Add(callingListTbl);

                    ptable = new PdfPTable(3);
                    cell = new PdfPCell(new Phrase(new Chunk("", ClassTitleFont)));
                    cell.Colspan = 3;
                    cell.BorderWidth = 0;
                    cell.FixedHeight = 60f;
                    ptable.AddCell(cell);
                    doc.Add(ptable);

                    lineLeft = writer.GetVerticalPosition(false) - doc.BottomMargin;
                    if (lineLeft < 200)
                    {
                        doc.NewPage();
                    }
                    //doc.NewPage();
                    gradeidx++;
                }
            }

            return ret;
        }
        private void CreateRing(Document doc, Shows show, ShowDetails showDetails, Rings ring, Judge judge, String ringTemplate, int lastRingNo)
        {
            var ptable = new PdfPTable(1);

            var cell = new PdfPCell(new Phrase(new Chunk($"Ring {ring.RingNo}", extremeFont)))
            {
                BorderWidth = 0,
                FixedHeight = 75f,
                HorizontalAlignment = Element.ALIGN_CENTER
            };
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase(new Chunk($"{judge.Name}", extremeFont)))
            {
                BorderWidth = 0,
                HorizontalAlignment = Element.ALIGN_CENTER,
                FixedHeight = 75f
            };
            ptable.AddCell(cell);

            cell = new PdfPCell(new Phrase(new Chunk(string.Format("{0}", show.ShowName), bigFont)));
            cell.BorderWidth = 0;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            ptable.AddCell(cell);

            cell = new PdfPCell(new Phrase(new Chunk(string.Format("{0:dd MMM yyyy}", showDetails.ShowDate), bigFont)));
            cell.BorderWidth = 0;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.FixedHeight = 75f;
            ptable.AddCell(cell);

            doc.Add(ptable);

            ptable = new PdfPTable(new float[] { 50, 25, 400, 100 });
            DataSet classesDS = Rings.GetClassesForRing(ring.ID);
            classesDS = judge.getClassesForJudge();

            cell = new PdfPCell(new Phrase(new Chunk("Cls No", headerHFont)));
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            cell.BorderWidth = 0;
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase(new Chunk("")));
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            cell.BorderWidth = 0;
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase(new Chunk("Class Name", headerHFont)));
            cell.HorizontalAlignment = Element.ALIGN_LEFT;
            cell.BorderWidth = 0;
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase(new Chunk("Dogs In Class", headerHFont)));
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            cell.BorderWidth = 0;
            ptable.AddCell(cell);

            if (classesDS.Tables.Count > 0)
            {
                foreach (DataRow classRow in classesDS.Tables[0].Rows)
                {
                    var part = Convert.ToInt32(classRow["Part"]);
                    cell = new PdfPCell(new Phrase(new Chunk(
                            string.Format("{0}", classRow["ClsNo"]), bigFont)));
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.BorderWidth = 0;
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase(new Chunk("")));
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.BorderWidth = 0;
                    ptable.AddCell(cell);
                    int clsHeight  = Convert.ToInt32(classRow["Height"]);
                    var partstr = "";
                    if (Convert.ToInt32(classRow["EntryTypeID"]) == 10)
                    {
                        cell = new PdfPCell(new Phrase(new Chunk(
                                string.Format("{0} {1} {2} {3}", ShowClasses.expandHeight(classRow),
                                                         classRow["LongName"], classRow["Name"],
                                                         ShowClasses.shortenGrades(classRow))
                                        , bigSmallFont)));
                    }
                    else
                    {
                        partstr = (part > 0 ? " - Pt " + part : "");
                        if (clsHeight == 0)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(
                                    string.Format("{0} {1} {2}{3}", classRow["LongName"], classRow["Name"],
                                                             ShowClasses.shortenGrades(classRow)
                                                             , partstr)
                                            , bigSmallFont)));
                        }
                        else
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(
                                    string.Format("{0} {1} {2} {3} {4}{5}", ShowClasses.expandHeight(classRow),
                                                            ShowClasses.expandCatagory(classRow),
                                                             classRow["LongName"], classRow["Name"],
                                                             ShowClasses.shortenGrades(classRow), partstr)
                                            , bigSmallFont)));
                        }
                    }
                    cell.Colspan = 1;
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    cell.BorderWidth = 0;
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase(new Chunk(string.Format("{0, 5}", Fpp.Core.Utils.CalcDogsInCalc(classRow)), bigFont)));
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.BorderWidth = 0;
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase(new Chunk("", bigFont)));
                    cell.Colspan = 4;
                    //cell.FixedHeight = 25f;
                    cell.BorderWidth = 0;
                    ptable.AddCell(cell);
                }
                doc.Add(ptable);
            }
        }
        private void TrailerSheetRing(Document doc, Shows show, ShowDetails showDetails, Rings ring, Judge judge, String ringTemplate, int lastRingNo)
        {
            var trailerColumns = new float[] { 30, 150, 15, 35, 40, 20, 20, 20, 10 };
            var cellHeight = 18;
            var ptable = new PdfPTable(trailerColumns);

            AddCellToHeader(ptable, string.Format("Ring {0}", ring.RingNo));
            AddCellToHeader(ptable, string.Format("{0}", judge.Name));
            AddCellToHeader(ptable, "");
            AddCellToHeader(ptable, "Walking");
            AddCellToHeader(ptable, "Calling up to");
            AddCellToHeader(ptable, "End");
            AddCellToHeader(ptable, "Final");
            AddCellToHeader(ptable, "Closed");
            AddCellToHeader(ptable, "P");
            doc.Add(ptable);
            ptable = new PdfPTable(trailerColumns);

            DataSet classesDS = Rings.GetClassesForRing(ring.ID);
            classesDS = judge.getClassesForJudge();
            var ringTotal = 0;
            PdfPCell cell;
            var altRow = Color.LIGHT_GRAY;
            var topBorderColor = altRow;
            if (classesDS.Tables.Count > 0)
            {
                foreach (DataRow classRow in classesDS.Tables[0].Rows)
                {
                    var cls = new ShowClasses(Convert.ToInt32(classRow["ClassId"]));
                    altRow = altRow == Color.WHITE ? Color.LIGHT_GRAY : Color.WHITE;
                    topBorderColor = Color.BLACK;
                    var part = Convert.ToInt32(classRow["Part"]);
                    cell = new PdfPCell(new Phrase(new Chunk(
                            string.Format("Class {0}", classRow["ClsNo"]), headerHFont)));
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    cell.BackgroundColor = altRow;
                    ptable.AddCell(cell);

                    var lhoTableInd = new PdfPTable(1);

                    int clsHeight = Convert.ToInt32(classRow["Height"]);
                    var className = "";
                    if (clsHeight == 0)
                    {
                        className = string.Format("{0} {1} {2}{3}", classRow["LongName"], classRow["Name"],
                                                         ShowClasses.shortenGrades(classRow)
                                                         , (part > 0 ? " - Pt " + part : ""));
                    }
                    else
                    {
                        className = string.Format("{0} {1} {2} {3} {4}{5}", ShowClasses.expandHeight(classRow),
                                                        ShowClasses.expandCatagory(classRow),
                                                         classRow["LongName"], classRow["Name"],
                                                         ShowClasses.shortenGrades(classRow), (part > 0 ? " - Pt " + part : ""));
                    }

                    if (cls.Lho == 1 || cls.Lho == 2  )
                    {
                        var dcCounts = DogClasses.GetEntryCountsByClassId(show.ID, cls.ID);

                        var innerTable = new PdfPTable(1);
                        var classNameTable = new PdfPTable(2);
                        className = className.Replace("sponsored by", "sp by");
                        classNameTable.AddCell(new PdfPCell(new Phrase(new Chunk(className, headerHFont)))
                        {
                            HorizontalAlignment = Element.ALIGN_LEFT,
                            BackgroundColor = altRow,
                            NoWrap = true,
                            BorderWidth = 0,
                        });
                        classNameTable.AddCell(new PdfPCell(new Phrase(new Chunk(dcCounts[0].Lho == 0 ? "Full Height" : "Lower Height", headerHFont)))
                        {
                            HorizontalAlignment = Element.ALIGN_RIGHT,
                            BackgroundColor = altRow,
                            NoWrap = true,
                            BorderWidth = 0,
                        });
                        innerTable.AddCell(new PdfPCell(classNameTable)
                        {
                            BackgroundColor = altRow,
                            NoWrap = false,
                            BorderWidth = 0,
                            BorderColorBottom = Color.GRAY,
                            BorderWidthBottom = 1
                        });

                        innerTable.AddCell(new PdfPCell(new Phrase(new Chunk((dcCounts[1].Lho == 0 ? "Full Height" : "Lower Height"), headerHFont)))
                        {
                            HorizontalAlignment = Element.ALIGN_RIGHT,
                            PaddingRight = 5,
                            BackgroundColor = altRow,
                            NoWrap = false,
                            BorderWidth = 0,
                        });
                        ptable.AddCell(new PdfPCell(innerTable) { });

                        innerTable = new PdfPTable(1);
                        foreach (var dcc in dcCounts)
                        {
                            innerTable.AddCell(new PdfPCell(new Phrase(new Chunk(string.Format("{0}", dcc.Count), headerHFont)))
                            {
                                HorizontalAlignment = Element.ALIGN_RIGHT,
                                BackgroundColor = altRow,
                                NoWrap = false,
                                BorderWidth = 0,
                                BorderWidthBottom = 1,
                                BorderColorBottom = Color.GRAY
                            });

                        }
                        ptable.AddCell(new PdfPCell(innerTable) { HorizontalAlignment = Element.ALIGN_RIGHT});

                        lhoTableInd.AddCell(new PdfPCell(new Phrase("  ")) { BorderWidth = 0, BorderWidthBottom = 1, BorderColorBottom = Color.GRAY });
                        lhoTableInd.AddCell(new PdfPCell(new Phrase("  ")) { BorderWidth = 0});
                    }
                    else
                    {
                        ptable.AddCell(new PdfPCell(new Phrase(new Chunk(className, headerHFont)))
                        {
                            HorizontalAlignment = Element.ALIGN_LEFT,
                            BackgroundColor = altRow,
                            NoWrap = false
                        });

                        var classTotal = Fpp.Core.Utils.CalcDogsInCalc(classRow);
                        ringTotal += classTotal;
                        cell = new PdfPCell(new Phrase(new Chunk(string.Format("{0, 5}", classTotal), headerHFont)));
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cell.BackgroundColor = altRow;
                        ptable.AddCell(cell);
                    }

                    ptable.AddCell(new PdfPCell(lhoTableInd) { BackgroundColor = altRow });
                    ptable.AddCell(new PdfPCell(lhoTableInd) { BackgroundColor = altRow });
                    ptable.AddCell(new PdfPCell(lhoTableInd) { BackgroundColor = altRow });
                    ptable.AddCell(new PdfPCell(lhoTableInd) { BackgroundColor = altRow });
                    ptable.AddCell(new PdfPCell(lhoTableInd) { BackgroundColor = altRow });
                    ptable.AddCell(new PdfPCell(lhoTableInd) { BackgroundColor = altRow });
                }
                cell = new PdfPCell(new Phrase(new Chunk("", headerHFont)));
                cell.FixedHeight = cellHeight;
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase(new Chunk(string.Format("{0}",ringTotal), headerHFont)));
                cell.FixedHeight = cellHeight;
                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase(new Chunk("", headerHFont)));
                cell.FixedHeight = cellHeight;
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase(new Chunk("", headerHFont)));
                cell.FixedHeight = cellHeight;
                cell.BorderWidth = 0;
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);
                ptable.AddCell(cell);

                doc.Add(ptable);

            }
        }
        public void TrailerSheets(Document doc, int ShowId)
        {
            Font smallFont = new Font(Font.COURIER, 8, Font.NORMAL, Color.BLACK);
            Font normalFont = new Font(Font.COURIER, 10, Font.NORMAL, Color.BLACK);
            Font mediumFont = new Font(Font.HELVETICA, 20, Font.NORMAL, Color.BLACK);
            ShowClasses sc = new ShowClasses();

            List<Rings> AllRings = new List<Rings>();
            var showDetailsList = ShowDetails.GetShowDetails(ShowId);
            Shows show = new Shows(ShowId);
            var pageBreaks = 0;
            foreach (var showDetails in showDetailsList)
            {
                Rings rings = new Rings();
                var ringsForDays = Rings.GetRingsForShowDayList(showDetails.ID);
                //            var groupByRing = ringsForDays.GroupBy(x => x.RingNo);
                int lastRingNo = 0;
                foreach (Rings ring in ringsForDays)
                {
                    if (ring.ID > -1 && lastRingNo != ring.RingNo)
                    {
                        lastRingNo = ring.RingNo;
                        if (pageBreaks % 3 == 0 || ring.RingNo == 1)
                        {
                            doc.NewPage();
                            pageBreaks = 0;
                        }

                        DataSet judgesDS = Rings.GetJudgesForRing(ring.ID);
                        if (judgesDS.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow judgeRow in judgesDS.Tables[0].Rows)
                            {
                                Judge judge = new Judge(judgeRow);
                                TrailerSheetRing(doc, show, showDetails, ring, judge, "", lastRingNo);
                            }
                        }
                    }
                    pageBreaks++;
                }
            }
            doc.NewPage();
        }
        public void ScribeSheets(Document doc, int showId, int ringId, PdfWriter writer )
        {
            var font = new Font(Font.HELVETICA, 10, Font.NORMAL, Color.BLACK);
            var smallFont = new Font(Font.HELVETICA, 8, Font.NORMAL, Color.BLACK);
            var totalsFont = new Font(Font.HELVETICA, 14, Font.BOLD, Color.BLACK);
            var bigBoyFont = new Font(Font.HELVETICA, 20, Font.BOLD, Color.BLACK);
            var bigBoyFont2 = new Font(Font.HELVETICA, 25, Font.BOLD, Color.BLACK);
            var blankCell = new PdfPCell(new Phrase(new Chunk("", font)));
            var sc = new ShowClasses();
            var currentRing = new Rings(ringId);
            var multiClasses = TeamPairsManager.GetTeamPairClasses(showId);
            var multiTeams = TeamPairsManager.GetTeamPairsForShow(showId, multiClasses);
            var showClasses = ShowClasses.GetAllClassesForShowRing(showId, ringId);
            foreach (var showClass in showClasses)
            {
                var callingList = sc.GetCallingList(showId, showClass.ID);

                var grades = showClass.Grades;
                if (grades.Length == 1)
                {
                    grades = "Grade " + grades;
                }
                else
                {
                    grades = "Grades " + grades[0] + "-" + grades[grades.Length - 1];
                }
                var ptable = new PdfPTable(1);
                var tmp = $"Class {showClass.ClassNo}";
                var cell = new PdfPCell(new Phrase(new Chunk(tmp, bigBoyFont2)))
                {
                    BorderWidth = 0,
                    Padding = 5,
                    HorizontalAlignment = Element.ALIGN_MIDDLE,
                    VerticalAlignment = Element.ALIGN_CENTER
                };
                ptable.AddCell(cell);

                if (showClass.EntryType == 10)
                {
                    tmp = $"{showClass.longHeight} {showClass.LongClassName} {showClass.ClassName}";
                }
                else
                {
                    tmp =
                        $"{showClass.NormalName(withClassNo: false)} {(showClass.Part > 0 ? "Part " + showClass.Part : "")} ";
                }
                cell = new PdfPCell(new Phrase(new Chunk(tmp, totalsFont)))
                {
                    BorderWidth = 0,
                    Padding = 5,
                    HorizontalAlignment = Element.ALIGN_MIDDLE,
                    VerticalAlignment = Element.ALIGN_CENTER
                };
                ptable.AddCell(cell);

                if (showClass.EntryType != 10)
                {
                    tmp = $"{grades}";
                    cell = new PdfPCell(new Phrase(new Chunk(tmp, totalsFont)))
                    {
                        BorderWidth = 0,
                        Padding = 5,
                        FixedHeight = 100f,
                        HorizontalAlignment = Element.ALIGN_MIDDLE,
                        VerticalAlignment = Element.ALIGN_CENTER
                    };
                    ptable.AddCell(cell);
                }

                tmp = $"Ring {currentRing.RingNo}";
                cell = new PdfPCell(new Phrase(new Chunk(tmp, totalsFont)))
                {
                    BorderWidth = 0,
                    Padding = 5,
                    FixedHeight = 30f,
                    HorizontalAlignment = Element.ALIGN_MIDDLE
                };
                ptable.AddCell(cell);

                tmp = $"Ring Order = {showClass.Position}";
                cell = new PdfPCell(new Phrase(new Chunk(tmp, totalsFont)))
                {
                    BorderWidth = 0,
                    Padding = 5,
                    FixedHeight = 30f,
                    HorizontalAlignment = Element.ALIGN_MIDDLE
                };
                ptable.AddCell(cell);

                doc.Add(ptable);
                doc.NewPage();

                if (TeamPairsManager.isMultiDog(showClass.EntryType))
                {
                    float[] colWidths = { 300, 150 };
                    var callingListTbl = new PdfPTable(colWidths);

                    var teamsForClass = multiTeams.Where(t => t.ClassId == showClass.ID).OrderBy(t => t.RO);
                    foreach (var team in teamsForClass)
                    {

                        tmp = $"Class {showClass.NormalName()}: {(showClass.Part > 0 ? "Part " + showClass.Part : "")}";
                        cell = new PdfPCell(new Phrase(new Chunk(tmp, notSoBigFont)))
                        {
                            BorderWidth = 2,
                            BorderColorRight = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            Padding = 5,
                            PaddingTop = 1,
                            PaddingLeft = 2,
                            FixedHeight = 50f
                        };
                        callingListTbl.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk(team.RO.ToString(), bigBoyFont)))
                        {
                            BorderWidth = 2,
                            BorderColorLeft = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            HorizontalAlignment = Element.ALIGN_CENTER,
                            Padding = 5
                        };
                        callingListTbl.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk("Course Time", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            Padding = 5,
                            BorderColorRight = Color.BLACK,
                            HorizontalAlignment = Element.ALIGN_RIGHT
                        };
                        callingListTbl.AddCell(cell);
                        cell = new PdfPCell(new Phrase(new Chunk(" ", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            Padding = 5,
                            BorderColorRight = Color.BLACK,
                            HorizontalAlignment = Element.ALIGN_RIGHT
                        };
                        callingListTbl.AddCell(cell);

                        if (TeamPairsManager.isTeam(showClass.EntryType))
                        {
                            cell =
                                new PdfPCell(
                                    new Phrase(new Chunk(team.TeamDetails.TeamName.Replace("&#39;", "'"), bold12)))
                                {
                                    PaddingBottom = 5,
                                    BorderWidth = 0,
                                    BorderWidthBottom = 1,
                                    HorizontalAlignment = Element.ALIGN_CENTER,
                                    BorderColor = Color.LIGHT_GRAY,
                                    Colspan = 2
                                };
                            callingListTbl.AddCell(cell);
                            var dogCnt = 0;
                            var reserves = "";
                            foreach (var md in team.Members)
                            {
                                if (dogCnt < team.DogCount)
                                {
                                    cell = new PdfPCell(new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(md.DogName), normal8)));
                                    cell.BorderWidth = 0;
                                    callingListTbl.AddCell(cell);

                                    cell = new PdfPCell(new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(md.HandlerName), normal8)));
                                    cell.BorderWidth = 0;
                                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                                    callingListTbl.AddCell(cell);
                                }
                                else
                                {
                                    if (md.HandlerName.Length > 0  )
                                    {
                                        if (reserves.Length > 0) reserves += ",";
                                        reserves +=
                                            $"{Utils.TitleCaseString(md.HandlerName)} & {Utils.TitleCaseString(md.DogName)}";
                                    }
                                }
                                dogCnt++;
                            }
                            if (reserves.Length > 0)
                            {
                                cell = new PdfPCell(new Phrase(new Chunk("Reserves:" + reserves, italic8)))
                                {
                                    BorderWidth = 0,
                                    Colspan = 2
                                };
                                callingListTbl.AddCell(cell);
                            }
                            doc.Add(callingListTbl);

                            callingListTbl = new PdfPTable(colWidths);
                            var linecnt = writer.GetVerticalPosition(false) - doc.BottomMargin;
                            cell = new PdfPCell
                            {
                                BorderWidth = 0,
                                Colspan = 2,
                                FixedHeight = writer.PageSize.Height - linecnt - 60
                            };
                            callingListTbl.AddCell(cell);
                            doc.Add(callingListTbl);

                        }
                        else
                        {
                            var memberTable = new PdfPTable(new float[] { 300, 300 });
                            var memberCell = new PdfPCell(memberTable)
                            {
                                BorderWidth = 0,
                                Colspan = 2,
                                PaddingBottom = 10
                            };
                            var dogCnt = 0;
                            foreach (var md in team.Members)
                            {
                                if (dogCnt < team.DogCount)
                                {
                                    cell =
                                        new PdfPCell(
                                            new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(md.HandlerName), font)))
                                        {
                                            BorderWidth = 0
                                        };
                                    memberTable.AddCell(cell);

                                    cell =
                                        new PdfPCell(
                                            new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(md.DogName), font)))
                                        {
                                            BorderWidth = 0
                                        };
                                    memberTable.AddCell(cell);
                                }
                                dogCnt++;
                            }
                            memberCell.FixedHeight = 180f;
                            callingListTbl.AddCell(memberCell);
                            doc.Add(callingListTbl);
                        }

                        callingListTbl = new PdfPTable(colWidths);
                        cell = new PdfPCell(new Phrase(new Chunk("Time", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            BorderColorRight = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            Padding = 5,
                            HorizontalAlignment = Element.ALIGN_CENTER
                        };
                        callingListTbl.AddCell(cell);
                        callingListTbl.AddCell(blankCell);

                        cell = new PdfPCell(new Phrase(new Chunk("Course Faults", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            BorderColorRight = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            Padding = 5,
                            HorizontalAlignment = Element.ALIGN_CENTER
                        };
                        callingListTbl.AddCell(cell);
                        callingListTbl.AddCell(blankCell);

                        cell = new PdfPCell(new Phrase(new Chunk("Time Faults", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            BorderColorRight = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            Padding = 5,
                            HorizontalAlignment = Element.ALIGN_CENTER
                        };
                        callingListTbl.AddCell(cell);
                        callingListTbl.AddCell(blankCell);

                        cell = new PdfPCell(new Phrase(new Chunk("Totals Faults", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            BorderColorRight = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            Padding = 5,
                            HorizontalAlignment = Element.ALIGN_CENTER
                        };
                        callingListTbl.AddCell(cell);
                        callingListTbl.AddCell(blankCell);
                        doc.Add(callingListTbl);
                        doc.NewPage();

                        doc.NewPage();
                        callingListTbl = new PdfPTable(colWidths);

                    }
                    doc.Add(callingListTbl);

                }
                else {
                    foreach (var item in callingList)
                    {
                        if (item.Category == 0 && showClass.EntryType != 10)
                        {
                            var tbl = new PdfPTable(1);
                            tmp = item.Grade == 99 ? "Veteran" : $"Grade {item.Grade}";
                            cell = new PdfPCell(new Phrase(new Chunk(tmp, bigBoyFont2)))
                            {
                                BackgroundColor = Color.LIGHT_GRAY,
                                BorderWidth = 2,
                                Padding = 9,
                                PaddingTop = 4,
                                HorizontalAlignment = Element.ALIGN_RIGHT
                            };
                            tbl.AddCell(cell);
                            doc.Add(tbl);
                        }

                        float[] colWidths = { 300, 150 };
                        var callingListTbl = new PdfPTable(colWidths);
                        tmp = showClass.EntryType == 10 ?
                            $"Class {showClass.ClassNo}: {showClass.longHeight} {showClass.LongClassName} {showClass.ClassName}"
                            : $"Class {showClass.ClassNo}: {showClass.NormalName(withClassNo: false)} {(showClass.Part > 0 ? "Part " + showClass.Part : "")}";
                        cell = new PdfPCell(new Phrase(new Chunk(tmp, notSoBigFont)))
                        {
                            BorderWidth = 2,
                            BorderColorRight = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            Padding = 5,
                            PaddingTop = 1,
                            PaddingLeft = 2,
                            FixedHeight = 50f
                        };
                        callingListTbl.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk($"{item.Ro}", bigBoyFont)))
                        {
                            BorderWidth = 2,
                            BorderColorLeft = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            HorizontalAlignment = Element.ALIGN_CENTER,
                            Padding = 5
                        };
                        callingListTbl.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk("Course Time", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            Padding = 5,
                            BorderColorRight = Color.BLACK,
                            HorizontalAlignment = Element.ALIGN_RIGHT
                        };
                        callingListTbl.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk("", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            Padding = 5,
                            BorderColorBottom = Color.BLACK
                        };
                        callingListTbl.AddCell(cell);

                        var handlerName = item.Name;
                        User user;
                        if (item.DefaultHandlerId > 0)
                        {
                            user = new User(item.DefaultHandlerId);
                            handlerName = user.Name;
                        }
                        if (item.AltHandlerId> 0)
                        {
                            user = new User(item.AltHandlerId);
                            handlerName = user.Name;
                        }

                        if (showClass.EntryType == 5 || showClass.EntryType == 9)
                        {
                            cell =
                                new PdfPCell(new Phrase(new Chunk($"{Utils.TitleCaseString(handlerName)}", smallFont)))
                                {
                                    BorderWidth = 0,
                                    Colspan = 1,
                                    HorizontalAlignment = Element.ALIGN_LEFT
                                };
                            callingListTbl.AddCell(cell);

                            cell = new PdfPCell(new Phrase(new Chunk(
                                $"{Utils.TitleCaseString(item.KcName),-10}", smallFont)))
                            {
                                Colspan = 1,
                                HorizontalAlignment = Element.ALIGN_RIGHT,
                                BorderWidth = 0
                            };
                        }
                        else
                        {
                            cell =
                                new PdfPCell(new Phrase(new Chunk($"{Utils.TitleCaseString(handlerName)}", notSoBigFont)))
                                {
                                    BorderWidth = 0,
                                    Colspan = 2
                                };
                            callingListTbl.AddCell(cell);
                            callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk(
                                $"{item.RingNumber,-10} {Utils.TitleCaseString(item.KcName)}",
                                notSoBigFont)))
                            {
                                BorderWidth = 0,
                                Colspan = 2
                            });

                            callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk($"{item.Breed}", notSoBigFontItalic))) { BorderWidth = 0, Colspan = 2});

                            cell = new PdfPCell(new Phrase(new Chunk($"{(item.Lho == 0 ? "" : "Lower Height")}", Bold18Black)))
                            {
                                BorderWidth = 0,
                                Colspan = 2,
                                PaddingTop = 10
                            };
                        }

                        int[] extendHeight = { 1, 2, 3, 7, 10, 11 };
                        if (extendHeight.Any(h => h == showClass.EntryType))
                        {
                            cell.FixedHeight = 160f;
                        }
                        cell.Colspan = 2;
                        callingListTbl.AddCell(cell);

                        doc.Add(callingListTbl);
                        callingListTbl = new PdfPTable(colWidths);
                        cell = new PdfPCell(new Phrase(new Chunk("Time", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            BorderColorRight = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            Padding = 5,
                            HorizontalAlignment = Element.ALIGN_CENTER
                        };
                        callingListTbl.AddCell(cell);
                        callingListTbl.AddCell(blankCell);

                        cell = new PdfPCell(new Phrase(new Chunk("Course Faults", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            BorderColorRight = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            Padding = 5,
                            HorizontalAlignment = Element.ALIGN_CENTER
                        };
                        callingListTbl.AddCell(cell);
                        callingListTbl.AddCell(blankCell);

                        cell = new PdfPCell(new Phrase(new Chunk("Time Faults", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            BorderColorRight = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            Padding = 5,
                            HorizontalAlignment = Element.ALIGN_CENTER
                        };
                        callingListTbl.AddCell(cell);
                        callingListTbl.AddCell(blankCell);

                        cell = new PdfPCell(new Phrase(new Chunk("Totals Faults", notSoBigFont)))
                        {
                            BorderWidth = 2,
                            BorderColorRight = Color.BLACK,
                            BorderColorBottom = Color.BLACK,
                            Padding = 5,
                            HorizontalAlignment = Element.ALIGN_CENTER
                        };
                        callingListTbl.AddCell(cell);
                        callingListTbl.AddCell(blankCell);
                        doc.Add(callingListTbl);
                        doc.NewPage();

                    }
                }
            }
        }
 public JsonResult DeleteRing(int RingId)
 {
     Rings ring = new Rings(RingId);
     ring.Delete();
     return Json(
         new
         {
             Status = 0,
         });
 }
 public JsonResult AddRing(int ShowDetailsId, int RingNo)
 {
     Rings ring = new Rings();
     return Json(
         new
         {
             Status = 0,
             RingId = ring.Add(ShowDetailsId, RingNo)
         });
 }
 public RingManager()
 {
     _ring = new Rings();
 }