private void download(HttpContext context, List<int> ids)
        {
            Document doc = new Document(PageSize.A4, -50, -50, 2, 2);
            Stream output;
            output = new MemoryStream();
            var writer = PdfWriter.GetInstance(doc, output);
            StyleSheet sheet = new StyleSheet();

            doc.Open();
            Font font = new Font(Font.COURIER, 10, Font.NORMAL, Color.BLACK);
            Font resFont = new Font(Font.COURIER, 9, Font.ITALIC, Color.BLACK);
            Font headerFont = new Font(Font.COURIER, 10, Font.BOLD, Color.BLACK);
            Font headerFont2 = new Font(Font.HELVETICA, 12, Font.NORMAL, Color.BLACK);
            Font headerFont3 = new Font(Font.HELVETICA, 16, Font.NORMAL, Color.BLACK);
            Font ClassTitleFont = new Font(Font.HELVETICA, 24, Font.NORMAL, Color.BLACK);
            PdfPTable ptable = new PdfPTable(new float[]  { 20, 200, 50});
            PdfPCell cell;
            foreach (int id in ids)
            {
                ptable = new PdfPTable(3);
                var judge = new Judge(id);
                var showDetails = new ShowDetails(judge.ShowDetailsID);
                var user = new User(judge.UserID);

                cell = new PdfPCell(new Phrase(new Chunk("First Place Processing", ClassTitleFont)));
                cell.Border = 0;
                cell.Colspan = 3;
                ptable.AddCell(cell);

                cell = new PdfPCell();
                cell.Border = 0;
                cell.Colspan = 3;
                cell.FixedHeight = 18f;
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase(new Chunk(
                    String.Format("{0}\n{1}\n{2}\n\n{3}",
                        user.Name,
                        user.Address,
                        user.Postcode,
                        user.EmailAddress), headerFont2)));
                cell.Border = 0;
                cell.Colspan = 3;
                ptable.AddCell(cell);

                cell = new PdfPCell(
                    new Phrase(
                            new Chunk(
            string.Format(@"

            Hi,

            This is to confirm the classes you will be judging at our show {0} on the {1:dddd, dd MMMM yyyy}.", show.ShowName, showDetails.ShowDate)
                                    , headerFont2)));
                cell.Border = 0;
                cell.Colspan = 3;
                ptable.AddCell(cell);

                cell = new PdfPCell();
                cell.Border = 0;
                cell.Colspan = 3;
                cell.FixedHeight = 18f;
                ptable.AddCell(cell);

                var classesDS = judge.getClassesForJudge();
                if (classesDS.Tables.Count > 0)
                {
                    var total = 0;
                    foreach (DataRow classRow in classesDS.Tables[0].Rows)
                    {
                        var dic = Utils.CalcDogsInCalc(classRow);
                        cell = new PdfPCell(new Phrase(new Chunk(string.Format("{0,5})",classRow["ClsNo"]) , headerFont2)));
                        cell.Border = 0;
                        cell.Colspan = 1;
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        ptable.AddCell(cell);

                        var classes = String.Format("{3} {4} {7} {5} {6}  -  {1}\n",
                                        classRow["ClassID"], dic, classRow["ClsNo"], ShowClasses.expandHeight(classRow), ShowClasses.expandCatagory(classRow), classRow["LongName"], classRow["Name"], ShowClasses.shortenGrades(classRow)
                                    );
                        cell = new PdfPCell(new Phrase(new Chunk(classes, headerFont2)));
                        cell.Border = 0;
                        cell.Colspan = 2;
                        ptable.AddCell(cell);

                        total += dic;
                    }
                    cell = new PdfPCell(new Phrase(""));
                    cell.Border = 0;
                    cell.Colspan = 3;
                    cell.FixedHeight = 18f;
                    ptable.AddCell(cell);

                    var totals = String.Format("Totals number of dogs {0}\n", total );

                    cell = new PdfPCell(new Phrase(""));
                    cell.Border = 0;
                    cell.Colspan = 1;
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase(new Chunk(totals, headerFont3)));
                    cell.Border = 0;
                    cell.Colspan = 2;
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase(new Chunk(
            @"
            Can I request that if you would like us to set up your course at the show, could you send me your course plan 7 days before the show at the latest? If you do not forward to me I will assume that you wish to set your course yourself or with friends, which is fine.

            If you wish to set your course up yourself then I will just need to know if you require any special or extra equipment at least 10 days before the show. Attached is a full list of equipment supplied in a standard set from First Contact.

            A continental breakfast & lunch will be available for you, your scribe and ring manager.

            If you can supply enough people to man the ring all day we will pay £100, also can you confirm any ring party / full ring party 10 days before the show.

            Many thanks

            Jackie Kenny

            Dog Vegas show secretary", headerFont2)));
                    cell.Border = 0;
                    cell.Colspan = 3;
                    ptable.AddCell(cell);
                }

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

            }
            doc.Close();
            context.Response.ClearContent();
            context.Response.ContentType = "application/pdf";
            context.Response.AddHeader("content-disposition", "inline;filename=JudgesClassConfirmation.pdf");
            context.Response.BinaryWrite((output as MemoryStream).ToArray());
        }
        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 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);

            }
        }
        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;
        }
        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);
            }
        }