protected void Page_Load(object sender, EventArgs e)
        {
            FormsIdentity identity = (FormsIdentity)HttpContext.Current.User.Identity;
            FormsAuthenticationTicket ticket = identity.Ticket;
            // get the roles stored as UserData into the ticket
            String[] userData = ticket.UserData.Split(':');
            String[] roles = userData[0].Split(',');
            int id = Convert.ToInt32(userData[1]);
            String html = "";

            Fpp.WebModules.Business.User currentUser = new User(id);
            int ShowID = Convert.ToInt32(Request["showid"]);
            Shows show = new Shows(ShowID);

            List<ShowDetails> showDetailsList = ShowDetails.GetShowDaysList(ShowID);
            html += "<h2>" + show.ShowName + "</h2>";

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

            Dogs d = new Dogs();

            DogClasses dc = new DogClasses();
            DateTime dt = DateTime.Now;
            Boolean newday = false;
            int currentRingID = 0;
            foreach (DataRow ringRow in ringList.Tables[0].Rows)
            {
                int RingID = Convert.ToInt32(ringRow["RingID"]);
                if (ringRow.IsNull("ClassID") )
                {
                    continue;
                }
                int ClassID = Convert.ToInt32(ringRow["ClassID"]);
                DateTime rowDT = Convert.ToDateTime(ringRow["ShowDate"]);
                if (rowDT != dt)
                {
                    newday = true;
                    if (currentRingID != 0)
                    {
                        html += "</table></div>";
                        html += "<div class='pagebreak'></div>";
                    }
                    html += "<div class='clsDate'>" + rowDT.ToString("dddd d MMM") + "</div>";
                    dt = rowDT;
                }

                if (currentRingID != RingID)
                {
                    List<Judge> judgeList = Judge.getJudgesForRingList(RingID);

                    if (currentRingID != 0 && !newday)
                    {
                        html += "</table></div>";
                    }
                    html += "<div class='Ring'>";
                    html += "<table class='roClassesTbl'>";
                    html += "<tr class='ringInfo'>";
                    html += "<td colspan='3'>" +
                                "<div class='roTitle centered'>Ring No " + ringRow["RingNo"].ToString() + "</div>";
                    foreach (Judge judge in judgeList)
                    {
                        html += "<div class='roTitle centered'>" + judge.Name + "</div>";
                    }
                    html += "</td></tr>";
                    currentRingID = RingID;
                }

                html += "<tr>";
                DataSet dogsList = d.GetDogsInClass(currentUser.UserID, ClassID);
                int DogsInClass = d.dogsInClassCount(ClassID);

                String clsName = ShowClasses.expandCatagory(ringRow) + " " + ShowClasses.expandHeight(ringRow) + ringRow["name"].ToString();
                String grades = ShowClasses.shortenGrades(ringRow);
                int ix = clsName.IndexOf("Grd");
                if (ix == -1) ix = clsName.IndexOf("Cmb");
                if (ix > -1)
                {
                    clsName = clsName.Substring(0, ix + 3) + " (" + grades + ") " + clsName.Substring(ix + 4);
                }
                else
                {
                    ix = clsName.IndexOf(" ");
                    clsName = clsName.Substring(0, ix) + " (" + grades + ") " + clsName.Substring(ix + 1);
                }

                if (dogsList.Tables[0].Rows.Count > 0)
                {
                    html += "<td valign='top' class='clsRing InClass'>" + ringRow["ClsNo"] + "</td>";
                    html += "<td  valign='top' class='clsDetails InClass'><div>" + clsName  + "</div>";
                    foreach (DataRow dogRow in dogsList.Tables[0].Rows)
                    {
                        String img = "<img src='data:image/gif;base64," + CreateImage(dogRow["DogColour"].ToString()) + "' />";

                        html += String.Format("<div class='dogInClass'><div style='background:{2};' class='dogIcon'>{3}</div>[{1}] {0}</div>", dogRow["DogName"], dogRow["RO"], dogRow["DogColour"], img);
                    }
                    html += "</td>";
                    html += "<td valign='top' class='clsEntry'><div>(" + DogsInClass+ ")</div></td>";
                }
                else
                {
                    html += "<td valign='top' class='clsRing notInClass'>" + ringRow["ClsNo"] + "</td>";
                    html += "<td valign='top' class='clsDetails notInClass'>" + clsName + "</td>";
                    html += "<td valign='top' class='clsEntry notInClass'><div>(" + DogsInClass + ")</div></td>";
                }

                html += "</tr>";
                newday = false;

            }
            html += "</table>";
            html += "</div>";
            ringPlanContainer.InnerHtml = html;
        }
        private void printRingForUser(UserShows userShow, int UserID, Document doc, ref List<int> defaultUsers, ref int pageCount)
        {
            String html = "";
            float[] ringColumns = new float[] { 300, 300, 300, 300};

            Font pageFont = FontFactory.GetFont("Arial", 22, Font.NORMAL);
            Font headerFont = new Font(Font.HELVETICA, 16, Font.BOLD, Color.BLACK);
            Font judgeFont = FontFactory.GetFont("Arial", 9, Font.BOLD);
            Font notInClassFont = new Font(Font.HELVETICA, 6, Font.NORMAL, Color.BLACK);
            Font inClassFont = new Font(Font.HELVETICA, 9, Font.NORMAL, Color.BLACK);
            Font font = new Font(Font.HELVETICA, 10, Font.NORMAL, Color.BLACK);
            Font font1 = FontFactory.GetFont("Arial", 18, Font.BOLD);
            Font dogNotInClass = new Font(Font.HELVETICA, 6, Font.NORMAL, Color.BLACK);
            Font dogInClass = new Font(Font.HELVETICA, 9, Font.NORMAL, Color.BLACK);
            Font dogDetailsInClass = new Font(Font.HELVETICA, 9, Font.BOLD, Color.BLACK);
            Fpp.WebModules.Business.User currentUser = new User(userShow.Userid);
            Shows show = new Shows(userShow.ShowID);

            List<ShowDetails> showDetailsList = ShowDetails.GetShowDaysList(userShow.ShowID);
            doc.Add(new Paragraph(show.ShowName, pageFont));

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

            Dogs d = new Dogs();

            DogClasses dc = new DogClasses();
            DateTime dt = DateTime.Now;
            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>();
            foreach (DataRow ringRow in ringList.Tables[0].Rows)
            {
                int RingID = Convert.ToInt32(ringRow["RingID"]);
                ShowDetailsID = Convert.ToInt32(ringRow["ShowDetailsID"]);

                if (ringRow.IsNull("ClassID"))
                {
                    continue;
                }
                int ClassID = Convert.ToInt32(ringRow["ClassID"]);
                DateTime rowDT = Convert.ToDateTime(ringRow["ShowDate"]);
                if (rowDT != dt)
                {
                    if (currentRingID != 0)
                    {
                        if (ringCnt % 4 != 0)
                        {
                            var remind = ringCnt % 4;
                            while (remind-- > 0)
                            {
                                cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                                cell.BorderWidth = 0;
                                rings.AddCell(cell);
                            }
                        }

                        doc.Add(rings);
                        if (currentUser.UserID == UserID)
                        {
                            doc.Add(getHandlerDetails(userShow, currentUser, PrevShowDetailsID, dogsRunningToday));
                        }
                        else
                        {
                            User defaultHandler = new User(UserID);
                            doc.Add(getHandlerDetails(userShow, defaultHandler, PrevShowDetailsID, dogsRunningToday));
                        }
                        doc.NewPage();
                        if (dogsRunningToday.Count > 0)
                        {
                            pageCount++;
                        }
                    }
                    dogsRunningToday.Clear();
                    doc.Add(new Paragraph(rowDT.ToString("dddd d MMM"), headerFont));
                    doc.Add(new Paragraph("  ", judgeFont));
                    dt = rowDT;
                    rings = new PdfPTable(ringColumns);
                    rings.WidthPercentage = 100;
                    ringCnt = 0;
                }

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

                    List<Judge> judgeList = Judge.getJudgesForRingList(RingID);

                    cell = new PdfPCell(new Phrase(new Chunk("Ring No " + ringRow["RingNo"].ToString(), judgeFont)));
                    cell.BorderWidth = 0;
                    cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    ringDetails.AddCell(cell);

                    foreach (Judge judge in judgeList)
                    {
                        cell = new PdfPCell(new Phrase(new Chunk(judge.Name, judgeFont)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        ringDetails.AddCell(cell);
                    }
                    currentRingID = RingID;
                    classDetailsTable = new PdfPTable(new float[] { 50, 225, 100 });
                    classDetailsTable.DefaultCell.BorderWidth = 0;
                    ringDetails.AddCell(classDetailsTable);
                }
                html += "<tr>";
                DataSet dogsList = d.GetDogsInClass(userShow.Userid, ClassID);
                int DogsInClass = d.dogsInClassCount(ClassID);

                String clsName = String.Format("{0} {1} {2} {3}",
                                ShowClasses.expandCatagory(ringRow),
                                ShowClasses.expandHeight(ringRow),
                                ringRow["LongName"],
                                ringRow["name"]);
                String grades = ShowClasses.shortenGrades(ringRow);
                int ix = clsName.IndexOf("Grd");
                if (ix == -1) ix = clsName.IndexOf("Cmb");
                if (ix > -1)
                {
                    clsName = clsName.Substring(0, ix + 3) + " " + grades + " " + clsName.Substring(ix + 4);
                }
                else
                {
                    ix = clsName.IndexOf(" ");
                    clsName = clsName.Substring(0, ix) + " " + grades + " " + clsName.Substring(ix + 1);
                }

                if (dogsList.Tables[0].Rows.Count > 0)
                {
                    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(String.Format("({0})", DogsInClass), dogInClass));

                    int countDogs = 0;
                    int DefaultHandler;
                    Paragraph p = new Paragraph();
                    foreach (DataRow dogRow in dogsList.Tables[0].Rows)
                    {
                        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);
                                p.Add(tmpCells[1]);
                                p.Add(Chunk.NEWLINE);
                            }
                            if (!dogsRunningToday.Contains(DogID))
                            {
                                dogsRunningToday.Add(DogID);
                            }
                            String img = "<img src='data:image/gif;base64," + CreateImage(dogRow["DogColour"].ToString()) + "' />";
                            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())  ));
                            p.Add(new Phrase(chunk));
                            p.Add(new Phrase(new Chunk(String.Format(" [{1}] {0}", dogName, dogRow["RO"]), dogDetailsInClass)));
                            p.Add(Chunk.NEWLINE);

                            int AltHandler = Convert.ToInt32(dogRow["AltHandler"]);
                            String HandlerName = "";
                            if (AltHandler > 0)
                            {
                                User u = new User(AltHandler);
                                HandlerName = u.Name;

                                html += "<div class='altHandler'>Handler:" + AltHandler + "</div>";
                                p.Add(Chunk.NEWLINE);
                                p.Add(new Phrase(new Chunk(String.Format("Handler:", AltHandler),dogInClass)));
                            }
                            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);

                        cell = new PdfPCell(new Phrase(new Chunk(clsName, dogNotInClass)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        cell.NoWrap = true;
                        classDetailsTable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk(String.Format("({0})", DogsInClass), 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 = true;
                        classDetailsTable.AddCell(cell);

                        cell = new PdfPCell(tmpCells[2]);
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        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);

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

                    cell = new PdfPCell(new Phrase(new Chunk(String.Format("({0})", DogsInClass), dogNotInClass)));
                    cell.BorderWidth = 0;
                    cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                    classDetailsTable.AddCell(cell);
                }

                PrevShowDetailsID = ShowDetailsID;
            }

            if (ringCnt % 4 != 0)
            {
                var remind = ringCnt % 4;
                while (remind-- > 0)
                {
                    cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                    cell.BorderWidth = 0;
                    rings.AddCell(cell);

                }
            }

            if (currentUser.UserID == UserID)
            {
                doc.Add(getHandlerDetails(userShow, currentUser, PrevShowDetailsID, dogsRunningToday));
            }
            else
            {
                User defaultHandler = new User(UserID);
                doc.Add(getHandlerDetails(userShow, defaultHandler, PrevShowDetailsID, dogsRunningToday));
            }
            doc.NewPage();
        }
        private String printRingForUser(UserShows userShow, int UserID, ref List<int> defaultUsers)
        {
            String html = "";

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

            List<ShowDetails> showDetailsList = ShowDetails.GetShowDaysList(userShow.ShowID);
            html += "<h2>" + show.ShowName + "</h2>";

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

            Dogs d = new Dogs();

            DogClasses dc = new DogClasses();
            DateTime dt = DateTime.Now;
            Boolean newday = false;
            int currentRingID = 0;
            int ShowDetailsID = -1;
            int PrevShowDetailsID = -1;
            foreach (DataRow ringRow in ringList.Tables[0].Rows)
            {
                try
                {
                    int RingID = Convert.ToInt32(ringRow["RingID"]);
                    int EntryType = Convert.ToInt32(ringRow["EntryType"]);
                    ShowDetailsID = Convert.ToInt32(ringRow["ShowDetailsID"]);
                    if (ringRow.IsNull("ClassID"))
                    {
                        continue;
                    }
                    int ClassID = Convert.ToInt32(ringRow["ClassID"]);
                    DateTime rowDT = Convert.ToDateTime(ringRow["ShowDate"]);
                    if (rowDT != dt)
                    {
                        newday = true;
                        if (currentRingID != 0)
                        {
                            html += "</table></div></div>";
                            if (currentUser.UserID == UserID)
                            {
                                html += getHandlerDetails(userShow, currentUser, PrevShowDetailsID);
                            }
                            else
                            {
                                User defaultHandler = new User(UserID);
                                html += getHandlerDetails(userShow, defaultHandler, PrevShowDetailsID);
                            }
                            html += "<div class='pagebreak'></div>";
                        }
                        html += "<div class='day group'>";
                        html += "<div class='clsDate'>" + rowDT.ToString("dddd d MMM") + "</div>";
                        dt = rowDT;
                    }

                    if (currentRingID != RingID)
                    {
                        List<Judge> judgeList = Judge.getJudgesForRingList(RingID);

                        if (currentRingID != 0 && !newday)
                        {
                            html += "</table></div>";
                        }
                        html += "<div class='Ring'>";
                        html += "<table class='roClassesTbl'>";
                        html += "<tr class='ringInfo'>";
                        html += "<td colspan='3'>" +
                                    "<div class='roTitle centered'>Ring No " + ringRow["RingNo"].ToString() + "</div>";
                        foreach (Judge judge in judgeList)
                        {
                            html += "<div class='roTitle centered'>" + judge.Name + "</div>";
                        }
                        html += "</td></tr>";
                        currentRingID = RingID;
                    }

                    html += "<tr>";
                    DataSet dogsList = d.GetDogsInClass(userShow.Userid, ClassID);
                    int DogsInClass = d.dogsInClassCount(ClassID);

                    String clsName = String.Format("{0} {1} {2} {3}",
                                    ShowClasses.expandCatagory(ringRow),
                                    ShowClasses.expandHeight(ringRow),
                                    ringRow["LongName"],
                                    ringRow["name"]);
                    String grades = ShowClasses.shortenGrades(ringRow);
                    int ix = clsName.IndexOf("Grd");
                    if (ix == -1) ix = clsName.IndexOf("Cmb");
                    if (ix > -1)
                    {
                        clsName = clsName.Substring(0, ix + 3) + " " + grades + " " + clsName.Substring(ix + 4);
                    }
                    else
                    {
                        ix = clsName.IndexOf(" ");
                        clsName = clsName.Substring(0, ix) + " " + grades + " " + clsName.Substring(ix + 1);
                    }

                    if (dogsList.Tables[0].Rows.Count > 0)
                    {
                        String tmphtml = "<td valign='top' class='clsRing InClass'>" + ringRow["ClsNo"] + "</td>" +
                                            "<td  valign='top' class='clsDetails InClass'><div>" + clsName + "</div>";
                        int countDogs = 0;
                        int DefaultHandler;
                        foreach (DataRow dogRow in dogsList.Tables[0].Rows)
                        {
                            int DogID = Convert.ToInt32(dogRow["DogID"]);
                            DefaultHandler = Convert.ToInt32(dogRow["DefaultHandler"]);
                            if (DefaultHandler == 0) DefaultHandler = -1;
                            if ((DefaultHandler == -1 && currentUser.UserID == UserID) ||
                                (DefaultHandler == UserID)
                                )
                            {
                                html += tmphtml;
                                tmphtml = "";

                                String img = "<img src='data:image/gif;base64," + CreateImage(dogRow["DogColour"].ToString()) + "' />";
                                String dogName = dogRow["DogName"].ToString();
                                if (dogName.Length == 0)
                                {
                                    dogName = dogRow["KCName"].ToString();
                                }
                                html += String.Format("<div class='dogInClass'><div style='background:{2};' class='dogIcon'>{3}</div>[{1}] {0}</div>", dogName, dogRow["RO"], dogRow["DogColour"], img);

                                int AltHandler = Convert.ToInt32(dogRow["AltHandler"]);
                                String HandlerName = "";
                                if (AltHandler > 0)
                                {
                                    User u = new User(AltHandler);
                                    HandlerName = u.Name;

                                    html += "<div class='altHandler'>Handler:" + AltHandler + "</div>";
                                }

                                // Pairs
                                if (EntryType == 4)
                                {

                                    MultiDog md = new MultiDog(UserID, DogID, ClassID);
                                    html += String.Format("<div class='dogInClass'><div style='width:8px;height:10px;' class='dogIcon'></div>[{1}] {0}</div>", md.Dogname, dogRow["RO"]);
                                }

                                countDogs++;
                            }
                            else
                            {
                                if (defaultUsers != null && defaultUsers.IndexOf(DefaultHandler) == -1)
                                {
                                    defaultUsers.Add(DefaultHandler);
                                }
                            }
                        }
                        if (countDogs == 0)
                        {
                            html += "<td valign='top' class='clsRing notInClass'>" + ringRow["ClsNo"] + "</td>";
                            html += "<td valign='top' class='clsDetails notInClass'>" + clsName + "</td>";
                            html += "<td valign='top' class='clsEntry notInClass'><div>(" + DogsInClass + ")</div></td>";
                        }
                        else
                        {
                            html += "</td>";
                            html += "<td valign='top' class='clsEntry'><div>(" + DogsInClass + ")</div></td>";
                        }
                    }
                    else
                    {
                        html += "<td valign='top' class='clsRing notInClass'>" + ringRow["ClsNo"] + "</td>";
                        html += "<td valign='top' class='clsDetails notInClass'>" + clsName + "</td>";
                        html += "<td valign='top' class='clsEntry notInClass'><div>(" + DogsInClass + ")</div></td>";
                    }

                    html += "</tr>";
                    newday = false;
                    PrevShowDetailsID = ShowDetailsID;
                }
                catch (Exception e)
                {
                    AppException.LogEvent("Printing Ring Plan:  " + e.Message);
                }
            }
            html += "</table>";
            html += "</div>";
            html += "</div>";

            if (currentUser.UserID == UserID)
            {
                html += getHandlerDetails(userShow, currentUser, PrevShowDetailsID);
            }
            else
            {
                User defaultHandler = new User(UserID);
                html += getHandlerDetails(userShow, defaultHandler, PrevShowDetailsID);
            }
            html += "<div class='pagebreak'></div>";

            return html;
        }
        public static void Cancel(User currentUser, int showid)
        {
            DogClasses dc = new DogClasses();

            Shows show = new Shows(showid);
            UserShows us = new UserShows(currentUser.ID, showid);
            UserCamping.DeleteForUser(us.ID);

            String refcode = us.ID.ToString("000000");
            us.Delete();
            //us.Status =(int) UserShows.UserStatus.STATUS_PENDING_REFUND;
            //us.Save();

            DogClasses.deleteUserDogs(currentUser.ID, showid);
            MultiDog.DeleteUserFromShow(currentUser.ID, showid);

            if (us.Status != (int)UserShows.UserStatus.STATUS_SAVED)
            {
                String htmlContents = readTemplate("CancelledEntry", "html", show, refcode);
                String plainContents = readTemplate("CancelledEntry", "txt", show, refcode);

                List<Transaction> transList = Transaction.getTransactionForUserRefCode(showid, currentUser.ID, us.ID);
                if (us.Status == (int)UserShows.UserStatus.STATUS_ENTERED_NOT_PAID)
                {
                    htmlContents = htmlContents.Replace("[PAYMENT_NOTE]", "");
                    plainContents = plainContents.Replace("[PAYMENT_NOTE]", "");
                    Transaction.Add(refcode, 4, -transList[0].Amount, "Entry Fee Returned", showid, currentUser.ID, DateTime.Now);
                }
                else
                {
                    if (transList.Count > 0)
                    {
                        //
                        // if handler is cancelling the show and there have paid, then
                        // mark in their account history that there have a refund

                        htmlContents = htmlContents.Replace("[PAYMENT_NOTE]", "Your payment will be refunded in the next 24 - 48 hours");
                        plainContents = plainContents.Replace("[PAYMENT_NOTE]", "Your payment will be refunded in the next 24 - 48 hours");

                        int transid = Transaction.Add(refcode, 2, -transList[0].Amount, "Refund Requested", showid, currentUser.ID, DateTime.Now);
                        Transaction.SetEnteredBy(transid, Transaction.ENTERED_BY.ONLINE_ENTRY);
                    }
                    else
                    {
                        htmlContents = htmlContents.Replace("[PAYMENT_NOTE]", "");
                        plainContents = plainContents.Replace("[PAYMENT_NOTE]", "");
                    }
                }

                MailMessage mm = new MailMessage();
                AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlContents, null, MediaTypeNames.Text.Html);
                LinkedResource logoImage = new LinkedResource(HttpContext.Current.Server.MapPath("~/Assets/logo.gif"), MediaTypeNames.Image.Gif);
                logoImage.ContentId = "LogoImage";
                //htmlView.LinkedResources.Add(logoImage);
                AlternateView plainView = AlternateView.CreateAlternateViewFromString(plainContents, null, MediaTypeNames.Text.Plain);

                mm.AlternateViews.Add(plainView);
                mm.AlternateViews.Add(htmlView);

                SmtpClient client = new SmtpClient("localhost");
                mm.From = new MailAddress("*****@*****.**", "First Place Processing");
                mm.To.Add(new MailAddress(currentUser.EmailAddress, currentUser.Name));
                mm.Subject = String.Format("Entry Cancellation {0} ({1:dd MMM yyyy})", show.ShowName, show.ShowDate);
                client.Send(mm);

                if (us.Status == (int)UserShows.UserStatus.STATUS_ENTERED_AND_PAID)
                {
                    mm = new MailMessage();
                    mm.From = new MailAddress("*****@*****.**", "First Place Processing");
                    mm.To.Add(new MailAddress("*****@*****.**", "First Place Processing"));
                    mm.Subject = "Entry Cancellation Request";
                    mm.Body = String.Format("Refund Request from {0}\r\n\r\nRefcode: {1}\r\n\r\nEmail: {2}\r\n\r\nShow: {3}\r\n",
                                            currentUser.Name, refcode, currentUser.EmailAddress, show.ShowName);
                    client.SendAsync(mm, null);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            FormsIdentity identity = (FormsIdentity)HttpContext.Current.User.Identity;
            FormsAuthenticationTicket ticket = identity.Ticket;
            // get the roles stored as UserData into the ticket
            String[] userData = ticket.UserData.Split(':');
            String[] roles = userData[0].Split(',');
            int id = Convert.ToInt32(userData[1]);
            Fpp.WebModules.Business.User currentUser = new User(id);
            int ShowID = Convert.ToInt32(Request["showid"]);
            Shows show = new Shows(ShowID);

            List<ShowDetails> showDetailsList = ShowDetails.GetShowDaysList(ShowID);

            Dogs d = new Dogs();
            List<Dogs> dogsList = Dogs.GetAllDogsForHandler(currentUser.UserID, show.ShowDate);

            DogClasses dc =new DogClasses();
            String html = "";
            foreach (Dogs dog in dogsList)
            {
                html += "<div class='RunningOrder'>";
                html += "<div class='roTitle'>" + show.ShowName + " " + show.ShowDate.ToString("dd MMM yyyy") + "</div>";
                html += "<div class='bigText rightSide'>Ring No:" + dog.ID + "</div>";
                html += "<div class='bigText leftSide'>" + currentUser.Name + "</div>";
                String tmp = "Grade " + dog.Grade;
                if (dog.Grade == 99)
                {
                    tmp = "Veteran";
                }
                html += String.Format("<div class='roTitle'>({0}) {1}</div>",tmp, dog.KCName );

                DataSet runningOrders = dc.getRunningOrders(ShowID, dog.ID);
                if (runningOrders.Tables.Count > 0)
                {
                    html += "<table class='roClassesTbl'>";
                    html += "<tr class='tblHeader'>";
                    html += "<td class='clsDetails'>Class</td><td class='clsRO'>RO</td><td class='clsEntry'>Entries</td><td class='clsRing'>Ring No</td></tr>";
                    DateTime dt = DateTime.Now;
                    foreach (DataRow row in runningOrders.Tables[0].Rows)
                    {
                        html += "<tr class='tblDetails'>";
                        DateTime rowDT = Convert.ToDateTime(row["ShowDate"]);
                        if (rowDT !=  dt )
                        {
                            html += "<td colspan='4' class='clsDate'>" + rowDT.ToString("dddd") + "</td>";
                            dt = rowDT;
                            html += "</tr>";
                            html += "<tr class='tblDetails'>";
                        }
                        html += "<td class='clsDetails'>" +
                            "<span class='clsNo'>" + row["clsno"] + "</span>" +
                            row["Name"].ToString() +
                            "</td>";
                        html += "<td class='clsRO'>" + row["RO"] + "</td>";
                        html += "<td class='clsEntry'>(" + row["DogsInClass"] + ")</td>";
                        html += "<td class='clsRing'>"+  row["RingNo"] + "</td>";
                        html += "</tr>";
                    }
                    html += "</table>";
                }

                html += "</div>";
            }
            runningOrdersContainer.InnerHtml = html;
        }
        public static UserShows SaveEntry(HttpContext context, String data, Fpp.WebModules.Business.User currentUser, Shows thisShow)
        {
            DogClasses dc = new DogClasses();
            int handlertype = Convert.ToInt32(context.Request["handlertype"]);
            String[] dogs = data.Split(',');
            String[] altHandlersList = context.Request["althandlerslist"].Split(',');
            int waitingList = Convert.ToInt32(context.Request["waitinglist"]);

            //
            //  Multidog format is packed as
            //  <dogid>@<clsid>:<handlername>.<dogname>[;<handlername>.<dogname>][,<dogid>#<clsid>:<handlername>.<dogname>[;<handlername>.<dogname>]]
            //
            MultiDog.DeleteUserFromShow(currentUser.ID, thisShow.ID);
            String[] pairTeams = context.Request["pairteams"].Split(',');
            if (!String.IsNullOrEmpty(context.Request["pairteams"])) {
                foreach (String pairTeam in pairTeams)
                {
                    String[] pt = pairTeam.Split(';');
                    int DogID = -1;
                    int ClsID = -1; ;

                    foreach (String p in pt)
                    {
                        String[] dogcls;
                        String[] otherHandlerDog;
                        if (p.IndexOf(':') > 0)
                        {
                            dogcls = p.Split(':')[0].Split('@');
                            DogID = Convert.ToInt32(dogcls[0]);
                            ClsID = Convert.ToInt32(dogcls[1]);
                            otherHandlerDog = p.Split(':')[1].Split('.');

                            String []handlerDetails = otherHandlerDog[0].Split('-');
                            if (handlerDetails.Length > 1)
                            {
                                String handlerName = handlerDetails[0];
                                int handlerID = -1;
                                int.TryParse(handlerDetails[1], out handlerID);

                                String[] dogDetails = otherHandlerDog[1].Split('-');
                                String dogName = dogDetails[0];
                                int dogID = -1;
                                int.TryParse(dogDetails[1], out  dogID );

                                MultiDog.Add(currentUser.ID, DogID, ClsID, thisShow.ID, handlerName, dogName, handlerID, dogID);
                            }
                            else
                            {
                                MultiDog.Add(currentUser.ID, DogID, ClsID, thisShow.ID, otherHandlerDog[0], otherHandlerDog[1]);
                            }
                        }
                        else
                        {
                            otherHandlerDog = p.Split('.');
                            String[] handlerDetails = otherHandlerDog[0].Split('-');
                            if (handlerDetails.Length > 1)
                            {
                                String handlerName = handlerDetails[0];
                                int handlerID = -1;
                                int.TryParse(handlerDetails[1], out handlerID);

                                String[] dogDetails = otherHandlerDog[1].Split('-');
                                String dogName = dogDetails[0];
                                int dogID = -1;
                                int.TryParse(dogDetails[1], out  dogID);

                                MultiDog.Add(currentUser.ID, DogID, ClsID, thisShow.ID, handlerName, dogName, handlerID, dogID);
                            }
                        }
                    }
                }
            }

            foreach (String dog in dogs)
            {
                String[] details = dog.Split(':');
                int dogid = Convert.ToInt32(details[0]);

                String[] clslist = details[1].Split('.');
                List<int> classes = new List<int>();
                List<int> altHandlers = new List<int>();
                foreach (String clsid in clslist)
                {
                    if (clsid.Length > 0)
                    {
                        int altid = 0;
                        classes.Add(Convert.ToInt32(clsid));
                        for (int ii = 0; ii < altHandlersList.Length; ii++)
                        {
                            String[] kvPairs = altHandlersList[ii].Split(':');
                            if (kvPairs[0] == clsid && kvPairs[2] == details[0])
                            {
                                altid = Convert.ToInt32(kvPairs[1]);
                            }
                        }
                        altHandlers.Add(altid);
                    }
                }
                dc.Save(dogid, thisShow.ID, classes, altHandlers);
            }

            UserShows us = new UserShows(currentUser.ID, thisShow.ID);
            us.Status = us.Status = (int)UserShows.UserStatus.STATUS_SAVED ;

            //
            // add check to see if this person is on the judging list.
            if (Judge.isJudgeAtShow(currentUser.ID, thisShow.ID))
            {
                us.HandlerType = (int)UserShows.HandlerTypes.JUDGE;
            }
            else
            {
                us.HandlerType = handlertype;
            }
            if ( !String.IsNullOrEmpty(context.Request["optout"] )  ) {
                us.Optout = Convert.ToInt32(context.Request["optout"]);
            }
            us.Save();

            Camping camping = new Camping(thisShow.ID);
            if (camping.ID > -1)
            {
                String campParty = "";
                String campDays = "";
                String campComments = "";
                if (!String.IsNullOrEmpty(context.Request["campingdays"])) campDays = context.Request["campingdays"];
                if (!String.IsNullOrEmpty(context.Request["campingparty"])) campParty = context.Request["campingparty"];
                if (!String.IsNullOrEmpty(context.Request["campcomments"])) campComments = context.Request["campcomments"];
                if (campDays.Length > 0)
                {
                    UserCamping.Add(us.ID, campParty, campComments, campDays);
                }
            }

            if (waitingList == 1)
            {
                WaitingList.Add(us.ShowID, us.Userid);

            }

            return us;
        }