public static StatusCls UpgradeDog(UpgradeDogView upgradeDogView)
        {
            var status = new StatusCls();
            AppException.LogEvent($"Upgrade Dog (UserID={upgradeDogView.UserId}, DogId={upgradeDogView.DogId})");
            try
            {
                DateTime activeDate;
                var currentUser = new User(upgradeDogView.UserId);
                var dog = new Dogs(upgradeDogView.DogId);
                DogHistory.Add(upgradeDogView);
                var mm = new MailMessage();
                var oldgrade = dog.Grade;
                if (upgradeDogView.UpgradeType == 0)
                {

                    mm.Subject = "First Place Processing - Confirmation of grade change";
                    var body = "This is a confirmation of grade change of your dog: " + dog.KCName + " from grade " + oldgrade + " to grade " + upgradeDogView.NewGrade +
                                  Environment.NewLine + Environment.NewLine +
                                  "Your dog will be grade " + upgradeDogView.NewGrade + " from the " + upgradeDogView.WinDate.AddDays(25).ToString("dd MMM yyyy") +
                                  Environment.NewLine + Environment.NewLine;
                    mm.Body = body;
                    activeDate = upgradeDogView.WinDate.Add(new TimeSpan(25, 0, 0, 0));
                }
                else
                {
                    mm.Subject = "First Place Processing - Confirmation of grade change";
                    var body = "This is a confirmation of grade change of your dog: " + dog.KCName + " from grade " + oldgrade + " to grade " + upgradeDogView.NewGrade + Environment.NewLine + Environment.NewLine;
                    mm.Body = body;
                    activeDate = DateTime.Now;
                }
                EmailManager.Send(currentUser, mm);
                if (activeDate > DateTime.Now)
                {
                    status.Extra = activeDate.ToString("dd MMM yyyy");
                }
            }
            catch (Exception e)
            {
                AppException.LogEvent($"Error:UpgradeDog:{e.Message} {e.StackTrace}");
            }
            return status;
        }
Esempio n. 2
0
        public static List<Dogs> GetAllDogsForHandler(int HandlerID, DateTime ShowStartDate)
        {
            String moduleSettings = ModuleConfig.GetSettings();
            Fpp.Data.Dogs dogData = new Fpp.Data.Dogs(moduleSettings);
            List<Dogs> dogList = new List<Dogs>();
            DataSet ds = dogData.GetAllDogsForHandler(HandlerID, ShowStartDate);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                var d = new Dogs(row);
                d.Wins = DogHistory.GetRecordedWins(d.ID);
                dogList.Add(d);
            }
            return dogList;
        }
        public JsonResult UpgradeDog(UpgradeDogView upgradeDog)
        {
            try { TrackUser("UpgradeDog", Newtonsoft.Json.JsonConvert.SerializeObject(upgradeDog)); } catch (Exception e )  { AppException.LogError(
                $"Error:UpgradeDog {upgradeDog.DogId} {e.Message} {CurrentUser?.UserID ?? -1}"); }

            if (upgradeDog.FromUser)
            {
                upgradeDog.UserId = CurrentUser.ID;
            }
            var dog = new Dogs(upgradeDog.DogId);
            var status = ProcessDog.ProcessDog.UpgradeDog(upgradeDog);
            var effectiveDate = DateTime.Now;
            var showsForUser = Shows.GetShowsForUser(upgradeDog.UserId);

            // get all shows entered but not closed
            var enteredShow = showsForUser
                                .Where(x => x.ClosingDate > DateTime.Now).ToList();

            // get all shows closed and entered and upgrade by win.
            var closedShows = new List<Shows>();
            var missedShows = new List<Shows>();
            if (upgradeDog.UpgradeType == 0)
            {
                var today = DateTime.Now;
                effectiveDate = upgradeDog.WinDate.AddDays(+25);
                closedShows = showsForUser
                            .Where(x => x.ClosingDate <= today && today < x.ShowDate.AddDays(-14) && effectiveDate <= x.ShowDate).ToList();

                var showIds = (from show in enteredShow let dogClasses = DogClasses.Retrieve(upgradeDog.DogId, show.ShowID) where !dogClasses.Any() select show).ToList();
                if (showIds.Any())
                {
                    foreach (var show in showIds)
                        enteredShow.Remove(show);
                }

                showIds = (from show in closedShows let dogClasses = DogClasses.Retrieve(upgradeDog.DogId, show.ShowID) where !dogClasses.Any() select show).ToList();
                if (showIds.Any())
                {
                    foreach (var show in showIds)
                        closedShows.Remove(show);
                }

                missedShows = showsForUser
                            .Where(x => x.ClosingDate <= today && today >= x.ShowDate.AddDays(-14) && effectiveDate < x.ShowDate).ToList();
                var tmp = closedShows.Aggregate("closedShows:", (current, item) => current + $"[{item.ShowName},{item.ShowDate.ToShortDateString()}],");

                tmp += "    missedShows:";
                tmp = missedShows.Aggregate(tmp, (current, item) => current + $"[{item.ShowName},{item.ShowDate.ToShortDateString()}],");
                AppException.LogEvent($"Upgrade Dog (effectiveDate={effectiveDate},{tmp})");
            }

            AppException.LogEvent(string.Format("Upgrade Dog UserId:{3}, DogId:{4} (enteredShow={0}, closedShows={1}, missedshows={2})",
                    enteredShow?.Count ?? -1,
                    (closedShows.Count),
                    (missedShows.Count),
                    upgradeDog.UserId,
                    upgradeDog.DogId));

            return Json(new
            {
                Status = 0,
                upgradeDog.DogId,
                upgradeDog.NewGrade,
                OldGrade = dog.Grade,
                upgradeDog.UpgradeType,
                EffectiveDate = effectiveDate.ToString("dd MMM yyyy"),
                DateActive = effectiveDate.ToString("yyyy-MM-dd hh:mm:ss"),
                enteredShow,
                closedShows,
                missedShows
            });
        }
 public JsonResult GetOwner(int DogId)
 {
     Dogs d = new Dogs(DogId);
     return Json(new
     {
         Status = 0,
         User = new User(d.OwnerID)
     });
 }
        public JsonResult SaveDog(DogDetailsDto dogDetails)
        {
            try
            {
                TrackUser("SaveDog", Newtonsoft.Json.JsonConvert.SerializeObject(dogDetails));
            }
            catch
            {
            }
            int dogid = dogDetails.DogId;
            Dogs dogs = new Dogs(dogid);
            dogs.HandlerID = (dogDetails.UserId > 0 ? dogDetails.UserId : CurrentUser.ID);
            dogs.KCName = dogDetails.KCName;
            dogs.KCNumber = dogDetails.KCNumber;
            dogs.PetName = dogDetails.PetName;
            dogs.Grade = dogDetails.Grade;
            dogs.Height = dogDetails.Height;
            dogs.DoB = dogDetails.DoB;
            dogs.Sex = dogDetails.sex;
            dogs.DogIcon = dogDetails.DogIcon;
            dogs.DogColour = dogDetails.DogColour;
            dogs.Breed = dogDetails.Breed;
            dogs.BreedType = dogDetails.BreedType + dogDetails.CrossBreed + dogDetails.GunDog;
            dogs.Rescue = dogDetails.Rescue;
            dogs.AltHandlerID = dogDetails.AltHandlerId;
            dogs.Save();
            AppException.LogEvent(String.Format("SaveDog: UserID={0}, DogId={1}", dogDetails.UserId, dogid));

            return Json(new
            {
                Status = 0,
                DogID = dogs.ID
            });
        }
        private ShowEntry GetCurrentEntry(int ShowId, int UserId, int handlerType)
        {
            var currentEntry = new ShowEntry();
            var us = new UserShows(UserId, ShowId);
            currentEntry.HandlerType = us.HandlerType;
            currentEntry.OptOut = us.Optout;
            currentEntry.EnterData = "";

            Shows thisShow = new Shows(ShowId);
            Dogs dog = new Dogs();
            var DogDetails = Dogs.GetAllDogsForHandler(UserId, thisShow.ShowDate);
            var UserDetails = new User(UserId);

            var classList = ShowClasses.GetAllClassesForShow(ShowId);
            List<validClassesForDog> validDogClasses = new List<validClassesForDog>();
            foreach (Dogs d in DogDetails)
            {
                if (currentEntry.EnterData.Length > 0) currentEntry.EnterData += ",";

                validClassesForDog vc4d = new validClassesForDog(d.ID);
                validDogClasses.Add(vc4d);
                DogClasses dc = new DogClasses(d.ID, ShowId);
                dc.getDogsClasses(ShowId);
                currentEntry.EnterData += String.Format("{0}:", d.ID);
                foreach (ShowClasses cls in classList)
                {
                    if (dc.Classlist.IndexOf(cls.ID) > -1)
                    {
                        currentEntry.EnterData += cls.ID + ".";
                    }
                }
            }
            var userCamping = UserCamping.GetUserShow(us.ID);
            if (userCamping.ID > -1)
            {
                currentEntry.CampingDays = userCamping.PitchDetails[0].CampingDays;
                currentEntry.CampingParty = userCamping.PitchDetails[0].PartyName;
                currentEntry.CampComments = userCamping.PitchDetails[0].Comments;
                currentEntry.Plots = userCamping.PitchDetails.Count();
            }

            return currentEntry;
        }
        public JsonResult GetDetails(int? id)
        {
            int userId = (id.HasValue ? id.Value : CurrentUser.ID);

            try
            {
                TrackUser("GetDetails", "");
            }
            catch
            {
            }

            UserDogDetails userDetails = new UserDogDetails();
            Dogs dog = new Dogs();

            userDetails.DogDetails = Dogs.GetAllDogsForHandler(userId, DateTime.Now);
            userDetails.UserDetails = new User(userId);
            userDetails.ShowTransList = ShowTransaction.getTransactionForUser(userId);
            userDetails.AltHandlers = AltHandler.GetAllAltHandlers(userId);

            return Json(new
            {
                Status = 0,
                UserDetails = userDetails
            });
        }
 public JsonResult DeleteDog(int DogId, int? UserId, bool Admin = false)
 {
     try
     {
         TrackUser("DeleteDog", string.Format("DogId={0}, by {1} ", DogId, (Admin ? "Admin" : "User")));
     }
     catch
     {
     }
     Dogs dogs = new Dogs();
     var userId = CurrentUser.ID;
     if (UserId.HasValue) userId = UserId.Value;
     AppException.LogEvent(string.Format("Delete Dog: UserId={0}, DogId={1}, By={2}", userId, DogId,
         (Admin ? "Admin" : "User")));
     if (dogs.Delete(DogId, Admin) > 0)
     {
         return Json(new
         {
             Status = Admin ? 0 : 1,
             DogID = DogId
         });
     }
     return Json(new
     {
         Status = 0,
         DogID = DogId
     });
 }
 public JsonResult DeleteOwner(int Id, int DogId)
 {
     Business.User.Delete(Id);
     Dogs d = new Dogs(DogId);
     d.OwnerID = -1;
     d.Save();
     return Json(new
     {
         Status = 0
     });
 }
        public StatusCls GetEntryForm(int ShowId, int UserId, int handlerType)
        {
            StatusCls status = new StatusCls {
                MultiDogClasses = new List<MultiDogClasses>()
            };
            Shows thisShow = new Shows(ShowId);
            User currentUser = new User(UserId);
            List<ShowClasses> classList = ShowClasses.GetAllClassesForShow(ShowId).Where(sc => sc.Part == 0).ToList();
            var lhoLabel = false;
            var fouthHeightLabel = false;
            if (classList.Any(x => x.Lho > 0))
            {
                lhoLabel = true;
                if (classList.Any(x => x.Lho == 3))
                {
                    lhoLabel = false;
                    fouthHeightLabel = true;
                }
            }

            status.MultiDogClasses = TeamPairsManager.GetTeamPairClasses(ShowId);

            UserShows us = new UserShows(UserId, ShowId);
            //
            // if user entering a new show then set up the handler type, cos that is pasted in
            if (us.ID == -1)
            {
                us.HandlerType = handlerType;
            }
            //
            // add check to see if this person is on the judging list.
            // and there are not a member as members override the judging discounts.
            if (Judge.isJudgeAtShow(UserId, ShowId) && handlerType == 0)
            {
                handlerType = 2;
                us.HandlerType = 2;
            }
            else
            {
                //
                // check if alt handlers are judging
                //
                List<AltHandler> altHList = AltHandler.GetAllAltHandlersList(us.Userid);
                foreach (AltHandler alt in altHList)
                {
                    if (Judge.isJudgeAtShow(alt.AltHandlerID, ShowId))
                    {
                        handlerType = 2;
                        us.HandlerType = 2;
                    }
                }
            }

            Dogs dog = new Dogs();
            List<Dogs> dogs = Dogs.GetAllDogsForHandler(UserId, thisShow.ShowDate);

            String html = $"<input type='hidden' name='handlertype' id='handlertype' value='{us.HandlerType}' />";
            String header = "<div class='dogRow group header'><div class='petName header'>&nbsp;</div>";
            Boolean headerCompleted = false;
            String rowClass = "dogRowAlt";
            foreach (Dogs d in dogs.Where(d => d.Grade > 0 ) )
            {
                String buttons = "";
                DogClasses dc = new DogClasses(d.ID);
                dc.getDogsClasses(ShowId);
                if (d.Grade != 0)
                {
                    buttons = "<div class='buttons'><a href='#tick'><img title='Select All Single Classes' class='tickcross tickimg' src='/Content/Assets/tickv2.png' /></a><a href='#cross'><img title='Clear All Classes' class='tickcross crossimg' src='/Content/Assets/crossv1.png' /></a>";
                    buttons += "</div>";
                    if (lhoLabel)
                    {
                        buttons += @"<div class='lho'><label for='cklho_" + d.ID + "'>Lower height<input type='checkbox' value='1' id='cklho_" + d.ID + "' " + (dc.Lho == 1 ? "checked='checked'" : "") + "   /></label></div>";
                    }
                    if (fouthHeightLabel)
                    {
                        buttons += @"<div class='ext'><label for='cklho_" + d.ID + "'>4th height<input type='checkbox' value='1' id='cklho_" + d.ID + "' " + (dc.Lho == 1 ? "checked='checked'" : "") + "   /></label></div>";
                    }
                    buttons += "<div class='infoText'>Handler:</div>";
                    if (d.AltHandlerID == -1)
                    {
                        buttons += currentUser.Name;
                    }
                    else
                    {
                        User altHandler = new User(d.AltHandlerID);
                        buttons += altHandler.Name;
                    }
                }
                html += String.Format("<div class='{2} group themeBorder-t' dogid='{0}' grade='{4}'><div class='petName'><div class='lbl'>{1}<p class='grade'>{4}</p></div>{3}</div>", d.ID, d.PetName, rowClass, buttons, d.DisplayGrade);
                rowClass = (rowClass == "dogRowAlt" ? "dogRow" : "dogRowAlt");

                String classTable = "";
                String dayName = "";
                String lastDay = "";
                Boolean classesForDog = true;
                foreach (ShowClasses cls in classList)
                {
                    if (dayName != cls.Showdate.ToString("dddd, dd MMM"))
                    {

                        if (dayName != "")
                        {
                            if (!classesForDog)
                            {
                                classTable += String.Format("<div class='clsNo' ><span class='naCls'>n/a</span></div>");
                            }
                            classTable += "</div>";
                        }
                        classesForDog = false;
                        lastDay = dayName;
                        dayName = cls.Showdate.ToString("dddd, dd MMM");

                        ShowDetails showDetails = new ShowDetails(cls.ShowDetailsID);
                        classTable += String.Format("<div class='day' classlimit='{0}'>", showDetails.ClassLimit);

                        if (!headerCompleted)
                        {
                            header += String.Format("<div class='day header' >{0}</div>", dayName);
                        }
                    }

                    //
                    //  cls.EntryType == (int)EntryType.EntryTypes.ABC &&
                    //

                    if (isDogInClass(cls, d))
                    {
                        int otherDogs = 0;
                        int reserves = 0;
                        bool teamName = false;
                        String ticked = "";
                        String altHandlerInfo = "<img class='handler' src='/Content/Assets/AddHandler.png'  width='16' height='14' />";
                        int clsIndex = dc.Classlist.IndexOf(cls.ID);
                        if (clsIndex > -1)
                        {
                            ticked = "tick";
                            if (dc.AltHandlerList[clsIndex] > 0)
                            {
                                User u = new User(dc.AltHandlerList[clsIndex]);
                                altHandlerInfo = "<img class='handler changed' width='16' height='14' src='/Content/Assets/AddHandler.png' data-althandlerid='" + dc.AltHandlerList[clsIndex].ToString() + "' title='Handler:" + u.Name + "' />";
                            }
                        }
                        classesForDog = true;

                        if (otherDogs > 0)
                        {
                            String iconType = "mdSet.png";
                            var multiDogs = "";
                            classTable += String.Format("<div {12} {13} {14} {15} class='clsNo " + ticked + "' classno='{15}' classcount='{11}' clsid='{0}' chargeType='{2}' classType='{3}' entryType='{4}' otherdogs='{5}' reserves='{9}' team='{10}' ><span class='chghandlemenu'>[+]</span>{6}<a class='otherdogs' title='Enter other dogs'><img src='/Content/Assets/{8}' >{7}</img></a><span class='clickable'><img class='tickHolder ' src='/Content/Assets/tickv2.png' /><span class='ah'>*</span><span class='clsname'>{1}</span></span></div>",
                                cls.ID, ShortenName(cls), cls.ChargeType, cls.ClassType, cls.EntryType,
                                otherDogs, altHandlerInfo, multiDogs, iconType, reserves, teamName, cls.ClassCount,
                                cls.Anysize == 1 ? "anysize" : "", cls.Veteran == 1 ? "veteran" : "",  ShowLhoModifier( cls.Lho ), cls.ClassNo, cls.AwardByHeight > 0 ? "AH" : "");

                        }
                        else
                        {
                            if (cls.EntryType == 10)
                            {
                                var hasChampDogsIcon = "mdNotSet.png";
                                var allDetailsCheck = 0;

                                var wins = DogHistory.GetRecordedWins(d.ID);
                                var h = "<span class='wins'>";
                                foreach (var dogH in wins) {
                                    h += string.Format("<span class='champ-wins' data-upgradetype='{4}'  data-winid='{3}'  data-showname='{0}' data-showdate='{1:dd-MM-yy}' data-showclass='{2}'></span>",
                                        dogH.ShowName, dogH.DateOfWin, dogH.ClassWon, dogH.Id, dogH.UpgradeType);
                                    allDetailsCheck += (dogH.ShowName.Length > 0 && dogH.ClassWon.Length > 0) ? 1 : 0;
                                }
                                if (allDetailsCheck == 4)
                                {
                                    hasChampDogsIcon = "mdSet.png";
                                }
                                h += "</span>";
                                classTable += String.Format("<div class='clsNo " + ticked + "' clsid='{0}' chargeType='{2}' classType='{3}' entryType='{4}' classCount='{8}'><span class='chghandlemenu'>[+]</span>{5}<a class='champ-dogs " + (allDetailsCheck == 4 ? " all-wins-entered " : "") + "' href='' title='Enter Your Wins' ><img src='/Content/Assets/{6}' /></a><span class='clickable'><img class='tickHolder ' src='/Content/Assets/tickv2.png' /><span class='clsname'>{1}</span></span>{7}</div>",
                                    cls.ID, ShortenName(cls), cls.ChargeType, cls.ClassType, cls.EntryType, altHandlerInfo, hasChampDogsIcon, h, cls.ClassCount);
                            }
                            else if (cls.EntryType == 11)
                            {
                                var hasJuniorDetails = "mdNotSet.png";
                                var allDetailsCheck = false;

                                var jnr= new Juniors(cls.ID, d.ID);
                                var h = "";
                                if (jnr != null && jnr.ID > 0)
                                {
                                    h += string.Format("<span class='junior-details' data-id='{2}' data-dob='{0:dd-MM-yyyy}' data-ykcnumber='{1}'></span>",
                                                jnr.DoB, jnr.YKCNumber, jnr.ID);
                                    hasJuniorDetails = "mdSet.png";
                                    allDetailsCheck = true;
                                }
                                h += "";
                                classTable += String.Format("<div {9} {10} {11} {12} class='clsNo " + ticked + "' clsid='{0}' chargeType='{2}' classType='{3}' entryType='{4}' classCount='{8}'  ><span class='chghandlemenu'>[+]</span>{5}<a class='ykc " + (allDetailsCheck  ? " all-entered " : "") + "' href='' title='Enter YKC Details' ><img src='/Content/Assets/{6}' /></a><span class='clickable'><img class='tickHolder ' src='/Content/Assets/tickv2.png' /><span class='ah'>*</span><span class='clsname'>{1}</span></span>{7}</div>",
                                    cls.ID, ShortenName(cls), cls.ChargeType, cls.ClassType, cls.EntryType, altHandlerInfo,
                                    hasJuniorDetails, h, cls.ClassCount, cls.Anysize == 1 ? "anysize" : "", cls.Veteran == 1 ? "veteran" : "", ShowLhoModifier(cls.Lho), cls.AwardByHeight > 0 ? "AH" : "");
                            }
                            else
                            {
                                //                                lhoclass = (cls.Lho == 0 && dc.Lho == 1 ? " hidecls ": "");

                                var lhoclass = "";
                                if (cls.Lho == 0 )
                                {
                                    lhoclass = (dc.Lho == 1 ? " hidecls " : "");
                                }
                                else
                                {
                                    if (cls.Lho < 3)
                                    {
                                        lhoclass = ""; // (dc.Lho == 1 ? "" : " hidecls ");
                                    }
                                    else
                                    {
                                        lhoclass = (dc.Lho == 0 ? " hidecls " : "");
                                    }

                                }

                                classTable += String.Format("<div {7} {8} {9} {10}  class='clsNo " + ticked + " " + lhoclass + "' clsid='{0}' chargeType='{2}' classType='{3}' entryType='{4}' classCount='{6}'><span class='chghandlemenu'>[+]</span>{5}<a class='nootherdogs'><img class='nootherdogs' src='/Content/Assets/infov1.png' /></a><span class='clickable'><img class='tickHolder ' src='/Content/Assets/tickv2.png' /><span class='ah'>*</span><span class='clsname'>{1}</span></span></div>",
                                    cls.ID, ShortenName(cls), cls.ChargeType, cls.ClassType, cls.EntryType, altHandlerInfo, cls.ClassCount, cls.Anysize == 1 ? "anysize" : "", cls.Veteran == 1 ? "veteran" : "", ShowLhoModifier(cls.Lho), cls.AwardByHeight > 0 ? "AH" : "");
                            }
                        }
                    }
                }

                headerCompleted = true;
                if (!classesForDog)
                {
                    classTable += String.Format("<div class='clsNo nohover'><span class='naCls'>n/a</span></div>");
                }
                html += classTable + "</div>";
                html += "</div>";
            }

            header += "</div>";

            String showDetailsBox = "";
            showDetailsBox += "<div class='showDetails themeText'>";
            showDetailsBox += "<div class='title'  style=' width: 375px;white-space: nowrap;overflow: hidden;text-overflow: clip;'>" + thisShow.ShowName + "</div>";
            showDetailsBox += "<div class='showdate'>" + thisShow.ShowDate.ToString("dd MMM yyyy") + "</div>";
            showDetailsBox += "</div >";

            showDetailsBox += "<div class='helpBox themeNoticeText themeBorder'>";
            showDetailsBox += "<div><span class='legend themeBackgroundColor'>Help Information</span></div>";
            showDetailsBox += "<div><img src='/Content/Assets/tickv2.png' /><span class='afterImgAdj'> To select all classes</span></div>";
            showDetailsBox += "<div><img src='/Content/Assets/crossv1.png' /><span class='afterImgAdj'>  To unselect all classes</span></div>";
            showDetailsBox += "<div><img src='/Content/Assets/mdNotSet.png' /><span class='afterImgAdj'>  Missing details</span></div>";
            showDetailsBox += "<div><img src='/Content/Assets/mdSet.png' /><span class='afterImgAdj'> All detail entered</span></div>";
            showDetailsBox += "<div><span style='color:#fff;'>[+]</span><span ><span> To Add Handler</span></div>";
            showDetailsBox += "<div><span class='ah' style='color:#fff;display:inline;margin: 0px 7px;top:4px'>*</span><span ><span>Awards By Height</span></div>";
            showDetailsBox += "</div>";

            String totalsBox = "";
            totalsBox += "<div class='totals themeBorder' ><div class='showTotals short themeBackgroundColor themeBorder'>";
            totalsBox += "<div class='clsTypeRow group fulltotal'>";
            totalsBox += "<div class='clsTypePaymentInfo themeBorder-t'></div>";
            totalsBox += "<div class='clsTypeTotal themeBorder-t themeBorder-l'>0.00</div>";
            totalsBox += "</div >";
            totalsBox += "</div>";
            totalsBox += "<div class='ctrlButtons'>";

            if (thisShow.Status == (int)Shows.SHOW_STATUS.PUBLISHED)
            {
                if (us.Status != (int)UserShows.UserStatus.STATUS_ENTERED_NOT_PAID
                    && us.Status != (int)UserShows.UserStatus.STATUS_ENTERED_AND_PAID)
                {
                    totalsBox += "<input type='button' id='btnSaveEntry' value='Save Details' />";
                }
            }

            HttpCookie cookie = HttpContext.Current.Request.Cookies[".FPPAUTH"];
            if (cookie != null)
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);

                String[] lists = ticket.UserData.Split(':');
                int userid = Convert.ToInt32(lists[1]);
                if ((lists[0].Contains("showadmin") && thisShow.Status == (int)Shows.SHOW_STATUS.NOT_PUBLISHED)
                    || thisShow.Status == (int)Shows.SHOW_STATUS.PUBLISHED)
                {
                    totalsBox += "<input type='button' id='btnDoEntry' value='Enter Show' />";
                }
            }

            totalsBox += "<input type='button' id='btnCancel' value='Close' /></div>";
            totalsBox += "</div >";
            status.Status = 0;
            status.UserID = currentUser.ID;
            status.Data = "<input id='ShowID' type='hidden' value='" + ShowId.ToString() + "' /><div class='enterform themeBorder' showid='" + ShowId.ToString() + "'><div class='vscroll'>" + header + "<div class='hscroll'>" + html + "</div></div></div>" + showDetailsBox + totalsBox;
            status.Extra = AltHandler.GetAllAltHandlers(UserId);

            status.TransactionSummaryData = TransactionSummary.getTransactionSummary(ShowId, currentUser.ID);

            status.Camping = new Camping(ShowId);
            status.CampingSummary = UserCamping.GetCampingSummary(ShowId, 0);
            if (!status.CampingSummary.Any())
            {
                for (DateTime dt = status.Camping.Startdate; dt <= status.Camping.Enddate; dt = dt.AddDays(1))
                {
                    status.CampingSummary.Add(new Core.Dto.CampingSummary
                    {
                        CampingDay = dt,
                        Count = 0
                    });
                }
            }
            else
            {
                status.CampingFull = status.CampingSummary.Where(x => x.Count >= status.Camping.Limit).Count() == status.CampingSummary.Count();
            }
            status.PaymentSummary = CreatePaymentSummary(us, false, status.CampingFull);
            if (status.Camping.ID > -1 && !status.CampingFull)
            {
                status.UserCamping = new UserCamping(us.ID);
            }
            status.UserShow = us;

            status.MultiDogEntries = TeamPairsManager.GetTeamPairs(ShowId, UserId, status.MultiDogClasses);

            status.Lho = lhoLabel;
            status.fouthHeight = fouthHeightLabel;

            return status;
        }
        public JsonResult AddOwner(OwnerModel owner)
        {
            User u = new User(owner.Id);
            u.Name = owner.Name;
            u.FirstName = "";
            u.LastName = "";
            u.EmailAddress = "";
            u.Password = "";
            u.Address = owner.Address;
            u.Postcode = owner.Postcode;
            u.HomePhone = owner.HomePhone;
            u.Update();

            if (u.UserID > 0)
            {
                Dogs d = new Dogs(owner.DogId);
                d.OwnerID = u.UserID;
                d.Save();
            }

            return Json(new
            {
                Status = 0,
                UserId = u.UserID
            });
        }
        // From Admin Site
        public UserDogDetails GetDetails(int ShowId, int UserId, int handlerType)
        {
            var userDetails = new UserDogDetails();
            userDetails.MultiDogClasses = new List<MultiDogClasses>();
            List<ShowClasses> classList = ShowClasses.GetAllClassesForShow(ShowId).Where(sc => sc.Part == 0).ToList();
            userDetails.MultiDogClasses = TeamPairsManager.GetTeamPairClasses(ShowId);
            userDetails.Juniors = new List<Juniors>();
            var us = new UserShows(UserId, ShowId);
            //
            // if user entering a new show then set up the handler type, cos that is pasted in
            if (us.ID == -1)
            {
                us.HandlerType = handlerType;
                if (handlerType == 0)
                {
                    if (Judge.isJudgeAtShow(UserId, ShowId))
                    {
                        handlerType = 2;
                        us.HandlerType = 2;
                    }
                    else
                    {
                        //
                        // check if alt handlers are judging
                        //
                        List<AltHandler> altHList = AltHandler.GetAllAltHandlersList(us.Userid);
                        foreach (AltHandler alt in altHList)
                        {
                            if (Judge.isJudgeAtShow(alt.AltHandlerID, ShowId))
                            {
                                handlerType = 2;
                                us.HandlerType = 2;
                            }
                        }
                    }
                }
            }
            var discountTotal = 0M;
            var addNewTransation = 0;
            var singleEntryId = getSingleEntry(ShowId);
            userDetails.Camping = new Camping(ShowId);
            userDetails.CampingSummary = UserCamping.GetCampingSummary(us.ShowID, us.Userid);
            var totals = calcNewTotalForEntry(us, userDetails.Camping, singleEntryId, ref discountTotal, ref addNewTransation);
            if (!userDetails.CampingSummary.Any())
            {
                for (DateTime dt = userDetails.Camping.Startdate; dt <= userDetails.Camping.Enddate; dt = dt.AddDays(1))
                {
                    userDetails.CampingSummary.Add(new Core.Dto.CampingSummary
                    {
                        CampingDay = dt,
                        Count = 0
                    });
                }
            }
            else
            {
                userDetails.CampingFull = userDetails.CampingSummary.Where(x => x.Count >= userDetails.Camping.Limit).Count() == userDetails.CampingSummary.Count();
            }

            userDetails.PaymentSummary = CreatePaymentSummary(us, true, userDetails.CampingFull);
            userDetails.AltHandlers = AltHandler.GetAllAltHandlers(UserId);
            if (us.ID > 0)
            {
                userDetails.ShowTransactions = Transaction.getTransactionForShowUser(us.ID.ToString("000000"));
            }
            else
            {
                userDetails.ShowTransactions = new List<Transaction>();
            }
            userDetails.helperDetails = Business.Helpers.HelperForShow(ShowId, UserId);

            Shows thisShow = new Shows(ShowId);
            Dogs dog = new Dogs();
            userDetails.DogDetails = Dogs.GetAllDogsForHandler(UserId, thisShow.ShowDate);
            userDetails.UserDetails = new User(UserId);

            userDetails.HandlerType = us.HandlerType;
            userDetails.UserShowID = us.ID.ToString("000000");
            userDetails.Optout = us.Optout;
            userDetails.SaveStatus = us.Status;

            userDetails.MultiDogEntries = TeamPairsManager.GetTeamPairs(ShowId, UserId, userDetails.MultiDogClasses);

            String html = "";
            List<validClassesForDog> validDogClasses = new List<validClassesForDog>();
            if (true)
            {

                html = "<input type='hidden' name='ShowId' value='" + ShowId.ToString() + "' /><input type='hidden' name='userid' value='" + UserId.ToString() + "' /><div class='entryAdminLeft'><table class='dogsToEnter'>";
                html += @"<tr>
                        <th class='dogName'>Dog Name</th>
                        <th class='lho-handler'>LHO</th>
                        <th class='classNos'>Classes</th>";
                foreach (Dogs d in userDetails.DogDetails)
                {
                    validClassesForDog vc4d = new validClassesForDog(d.ID);
                    validDogClasses.Add(vc4d);
                    DogClasses dc = new DogClasses(d.ID, ShowId);
                    dc.getDogsClasses(ShowId);
                    String tmpNFC = d.Grade.ToString();
                    if (d.Grade == 0)
                    {
                        tmpNFC = "NFC";
                    }
                    else if (d.Grade == 99)
                    {
                        tmpNFC = "Vet";
                    }
                    html += String.Format("<tr class='dogClass' lho='{6}' dogid='{0}' height='{3}' grade='{2}'><td class='dogName'><div ><b>[{4}] </b>{1}</div><div class='altHandler'>{5}</div></td>", d.ID, d.KCName, d.Grade, d.Height, tmpNFC, d.AltHandlerName, dc.Lho);
                    html += "<td class='lho'><input type='checkbox' class='lho' value='1' " + (dc.Lho == 1 ? "checked" : "") + "    /></td>";
                    //html += "<td class='vet'><input type='checkbox' class='vet' value='1' " + (dc.Veteran == 1 ? "checked" : "") + "    /></td>";
                    //html += "<td class='any'><input type='checkbox' class='any' value='1' " + (dc.Anysize == 1 ? "checked" : "") + "    /></td>";
                    String classesEntered = "";
                    foreach (ShowClasses cls in classList)
                    {
                        int otherDogs = 0;
                        int reserves = 0;
                        bool teamName = false;
                        if (cls.EntryType == 4 || cls.EntryType == 8) { otherDogs = 1; }
                        else if (cls.EntryType == 5) { otherDogs = 3; reserves = 2; teamName = true; }
                        else if (cls.EntryType == 9) { otherDogs = 2; reserves = 2; teamName = true; }

                        int clsIndex = dc.Classlist.IndexOf(cls.ID);
                        if (clsIndex > -1)
                        {
                            classesEntered += String.Format("<span entrytype='{1}' chargetype='{2}' classtype='{3}' classno='{0}' clsid='{4}' class='classNumber  ", cls.ClassNo, cls.EntryType, cls.ChargeType, cls.ClassType, cls.ID);
                            if (dc.AltHandlerList[clsIndex] > 0)
                            {
                                var jnrHtml = "";
                                if (cls.EntryType == 11)
                                {
                                    var jnr = new Juniors(cls.ID, d.ID);
                                    if (jnr != null && jnr.ID > 0)
                                    {
                                        jnrHtml += string.Format("<span class='junior-details' data-id='{2}' data-dob='{0:dd-MM-yyyy}' data-ykcnumber='{1}'></span>",
                                                    jnr.DoB, jnr.YKCNumber, jnr.ID);
                                    }
                                }
                                classesEntered += String.Format("althandler ykc' data-althandlerid='{1}'>{0}{2}</span>", cls.ClassNo, dc.AltHandlerList[clsIndex], jnrHtml);
                            }
                            else
                            {
                                if (otherDogs > 0)
                                {
                                    classesEntered += String.Format("'  data-otherdogs='{1}' data-reserves='{2}' data-team='{3}' >{0}", cls.ClassNo, otherDogs, reserves, teamName);
                                    classesEntered += "<img class='otherdogs' src='/Content/Assets/mdSet.png' />";
                                    classesEntered += "</span>";
                                }
                                else
                                {
                                    var extrahtml = "";
                                    if (cls.EntryType == 10)
                                    {
                                        var wins = DogHistory.GetRecordedWins(d.ID);
                                        foreach (var dogH in wins)
                                        {
                                            extrahtml += string.Format("<span class='champ-details' data-upgradetype='{4}' data-winid='{3}' data-showname='{0}' data-showdate='{1:dd-MM-yy}' data-showclass='{2}'></span>",
                                                dogH.ShowName, dogH.DateOfWin, dogH.ClassWon, dogH.Id, dogH.UpgradeType);
                                        }
                                        classesEntered += String.Format("' >{0}{1}</span>", cls.ClassNo, extrahtml);
                                    }
                                    else if (cls.EntryType == 11 || cls.EntryType == 3)
                                    {
                                        var jnr = new Juniors(cls.ID, d.ID);
                                        if (jnr != null && jnr.ID > 0)
                                        {
                                            extrahtml += string.Format("<span class='junior-details' data-id='{2}' data-dob='{0:dd-MM-yyyy}' data-ykcnumber='{1}'></span>",
                                                        jnr.DoB, jnr.YKCNumber, jnr.ID);
                                        }
                                        classesEntered += String.Format("ykc' >{0}{1}</span>", cls.ClassNo, extrahtml);
                                    }
                                    else
                                    {
                                        classesEntered += String.Format("' >{0}</span>", cls.ClassNo);

                                    }
                                }
                            }
                        }

                        if (isDogInClass(cls, d))
                        {
                            vc4d.addClassDetails(cls);
                        }
                    }
                    html += "<td class='classNos'><div >" + classesEntered + "</div></td></tr>";
                }
                html += "</table></div><div class='entryAdminRight'></div>";
            }
            userDetails.Data = html;
            userDetails.ValidClassesForDogs = validDogClasses;
            userDetails.TransactionSummaryData = TransactionSummary.getTransactionSummary(ShowId, UserId);
            userDetails.UserCamping = new UserCamping(us.ID);
            if (us.ID > 0)
            {
                userDetails.ShowTransList = ShowTransaction.getTransactionForShowRef(us.ID);
            }
            else
            {
                userDetails.ShowTransList = new List<ShowTransaction>();
            }

            return userDetails;
        }
        private Boolean isDogInClass(ShowClasses cls, Dogs d)
        {
            Boolean isABClass = (cls.EntryType == (int)EntryTypes.ABC);
            Boolean isABCDog = (d.BreedType & (int)Dogs.BreedTypes.ABC) == (int)Dogs.BreedTypes.ABC;
            Boolean isHeightValid = (cls.Height == d.Height || cls.Height == 0 || (cls.Height == 5 && (d.Height == 1 || d.Height == 2))  );
            Boolean isGradeValid = cls.Grades.Contains(d.Grade.ToString());
            Boolean isAnySize = ((cls.EntryType == (int)EntryTypes.Veterans || cls.EntryType == (int)EntryTypes.VeteranPairs) &&
                                 d.Grade != 0 );

            if (isHeightValid && (cls.Anysize == 1 || cls.Veteran == 1)) return true;

            if (isABClass && isHeightValid && isGradeValid && !isABCDog)
            {
                return false;
            }
            else if (isABClass && isHeightValid && isGradeValid && isABCDog)
            {
                return true;
            }
            else if (isHeightValid && isGradeValid)
            {
                return true;
            }
            else if (isAnySize)
            {
                return true;
            }

            return false;
        }
        private String getEntrySummary(UserShows us)
        {
            Shows thisShow = new Shows(us.ShowID);
            UserDogDetails userDetails = new UserDogDetails();
            Dogs dog = new Dogs();
            userDetails.DogDetails = Dogs.GetAllDogsForHandler(us.Userid, thisShow.ShowDate);
            userDetails.UserDetails = new User(us.Userid);

            UserCamping userCamping = new UserCamping(us.ID);
            List<Business.Helpers> helpersList = Business.Helpers.HelperForShow(us.ShowID, us.Userid);

            List<ShowClasses> classList = ShowClasses.GetAllClassesForShow(us.ShowID);

            String html = "<input type='hidden' name='showid' value='" + us.ShowID.ToString() + "' /><input type='hidden' name='userid' value='" + us.Userid.ToString() + "' /><div class='entryAdminLeft'>";

            html += "<div id='showEntryDetails'><ul>";
            html += "<li><a href='#showdetails'>Show Details</a></li>";
            html += "<li><a href='#entrydetails'>Entry Details</a></li>";
            if (userCamping.ID > -1)
            {
                html += "<li><a href='#campingdetails'>Camping Details</a></li>";
            }
            if (helpersList.Count > 0)
            {
                html += "<li><a href='#helperdetails'>Helper Details</a></li>";
            }

            html += "</ul>";

            String schedule = "../Schedules/" + thisShow.ShowDate.ToString("yyyy") + "/";
            String entryForm = schedule;
            String filename = thisShow.ShowName.Replace(' ', '_');
            String fthing = thisShow.ShowDate.ToString("dd_yyyy");
            schedule += filename + fthing + "Schedule.pdf";
            entryForm += filename + fthing + "EntryForm.pdf";

            html += "<div id='showdetails'>";
            html += "<h2>" + thisShow.ShowName + "</h2>" +
                    "<p>Start Date:" + thisShow.ShowDate.ToString("dd MMM yyyy") + "</p>" +
                    "<p>Closing Date:" + thisShow.ClosingDate.ToString("dd MMM yyyy") + "</p>";
            html += "<p>Venue:" + thisShow.Venue + "</p>" +
                    "<p>" + thisShow.VenuePostcode + "(<a target='_blank' href='https://maps.google.co.uk/maps?q=" + thisShow.VenuePostcode + "'>map</a>)</p>";

            var showDocs = ShowDocuments.getShowDocumentsFor(us.ShowID);
            foreach (var doc in showDocs)
            {
                html += string.Format("<div><a class='scheduleLocation' target='_blank' href='../Schedules/{2}/{1}'>{0}</a></div>", doc.Name, doc.Url, thisShow.ShowDate.ToString("yyyy"));
            }
            html += "</div>";

            html += "<div id='entrydetails'>";
            html += "<table class='dogsToEnter themeBorder'>";
            html += "<tr><th class='dogName'>Dog Name</th><th class='classNos'>Classes</th>";
            List<validClassesForDog> validDogClasses = new List<validClassesForDog>();
            int dogCnt = 0;
            foreach (Dogs d in userDetails.DogDetails.Where(d => d.Grade > 0))
            {
                validClassesForDog vc4d = new validClassesForDog(d.ID);
                validDogClasses.Add(vc4d);
                DogClasses dc = new DogClasses(d.ID, us.ShowID);
                dc.getDogsClasses(us.ShowID);
                String altBackground = "infoTextBackground";
                if (dogCnt % 2 == 0) altBackground = "infoTextBackgroundAlt";
                html += String.Format("<tr class='dogClass {4}' dogid='{0}' height='{3}' grade='{2}'><td valign='top'><div >{1}</div>{5}</td>", d.ID, d.KCName, d.Grade, d.Height, altBackground, (dc.Lho == 0 ? "": "**** Entered lower height option"));
                String classesEntered = "";
                foreach (ShowClasses cls in classList)
                {
                    int clsIndex = dc.Classlist.IndexOf(cls.ID);
                    if (clsIndex > -1)
                    {
                        if (classesEntered.Length > 0) { classesEntered += "<br>"; }
                        if (dc.AltHandlerList[clsIndex] > 0)
                        {
                            classesEntered += String.Format("<span class='classNumber althandler' data-althandlerid='{1}'>{0}</span>", cls.ClassNo, dc.AltHandlerList[clsIndex]);
                        }
                        else
                        {
                            //classesEntered += String.Format("<span class='classNumber' style='padding:5px'>{0}</span>", cls.ClassNo);
                            classesEntered += String.Format("<span class='classNumber' style='padding:5px'>{0}</span> {1} {2} {3} {4}", cls.ClassNo, cls.longHeight, cls.LongClassName, cls.longCatagory, cls.getGrades);

                        }

                    }
                    //
                    // if veterans/anysize or anything that is valid for that dog, add to list;
                    if (d.Grade == 99)
                    {
                        if (cls.EntryType == 2)
                        {
                            vc4d.addClassDetails(cls);
                        }
                    }
                    else
                    {
                        if (cls.EntryType == 2 || (d.Height == cls.Height && cls.Grades.Contains(d.Grade.ToString())))
                        {
                            vc4d.addClassDetails(cls);
                        }
                    }
                }
                dogCnt++;
                html += "<td class=''><div class='classNos'><div class='classContainer'>" + classesEntered + "</div></div></td></tr>";
            }
            html += "</table>";
            html += "</div>";
            if (userCamping.ID > -1)
            {
                String[] campDays = userCamping.PitchDetails[0].CampingDays.Split(',');

                html += "<div id='campingdetails' class='infoText'>";
                html += "<h2>Camping Days Booked</h2><ul>";
                foreach (String cdays in campDays.Where(x => x.Length > 0))
                {
                    html += "<li>" + CampDateFormat(cdays) + "</li>";
                }
                html += "</ul>";
                html += "<p>No of pitches:<span style='color:#fff'>" + userCamping.PitchDetails.Count + "</span></p>";
                html += "<p>Camping With:<span style='color:#fff'>" + userCamping.PitchDetails[0].PartyName + "</span></p>";
                html += "<p>Special Requests:<span style='color:#fff'>" + userCamping.PitchDetails[0].Comments + "</span></p>";
                html += "</div>";
            }

            if (helpersList.Count > 0)
            {
                html += "<div id='helperdetails' class='infoText'>";
                html += "<h2>Helping Details</h2>";
                var helperComment = "";
                foreach (Business.Helpers helper in helpersList)
                {
                    String judge = "";
                    if (helper.JudgeID > -1)
                    {
                        Judge j = new Judge(helper.JudgeID);
                        judge = "Judge: " + j.Name;
                    }
                    String ring = "";
                    if (helper.RingNo > 0)
                    {
                        ring = "Ring No:" + helper.RingNo.ToString();
                    }
                    html += String.Format("<div >{0:ddd dd MMM} - {1} {2} {3}</div>", helper.HelpDate, helper.expandJob(), judge, ring);
                    helperComment = helper.Comments;
                }
                if (helperComment.Length > 0)
                {
                    html += string.Format("<p>{0}</p>", helperComment);
                }
                html += "</div>";
            }
            html += "</div>";
            return html;
        }
        private PdfPCell AddDogDetails(Dogs d, List<DogClasses> dcList, Color altColor, bool topBorder )
        {
            Paragraph p = new Paragraph();
            Phrase ph = new Phrase();
            ph.Add(new Chunk(d.KCName, normalFont));
            ph.Add(Chunk.NEWLINE);
            var doginfo = d.KCNumber;
            if (!string.IsNullOrEmpty(d.DoB))
            {
                doginfo += ",";
                doginfo += d.DoB;
            }
            ph.Add(new Chunk(doginfo, normalFont));
            ph.Add(Chunk.NEWLINE);
            doginfo = d.Breed;
            if (doginfo.Length > 0) doginfo += ",";
            doginfo += "Grade " + Dogs.GetDogGrade(d.Grade);
            ph.Add(new Chunk(doginfo, normalFont));
            ph.Add(Chunk.NEWLINE);
            doginfo = "";
            doginfo += Dogs.GetDogHeight(d.Height);
            doginfo += ",";
            doginfo += Dogs.GetDogSexType(d.Sex);
            if (dcList.Any() && dcList.First().Lho == 1)
            {
                doginfo += ",LHO";
            }

            ph.Add(new Chunk(doginfo, normalFont));
            ph.Add(Chunk.NEWLINE);
            var cell = new PdfPCell(ph);
            cell.BorderWidth = 0;
            cell.BackgroundColor = altColor;
            if (topBorder)
            {
                cell.BorderColorTop = Color.BLACK;
                cell.BorderWidthTop = 1;
            }

            return cell;
        }
        public JsonResult DogSearch(int handlerId, string dogName)
        {
            if (dogName == "*") dogName = "%";
            var d = new Dogs();

            return Json(new
            {
                Dogs= d.SearchFor(handlerId, dogName)
            });
        }
        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}");
            }
        }
        public static List<ShowClasses> getDogClasses(int ShowId, int DogId, int Grade, bool includeVeteran = true)
        {
            var classList = ShowClasses.GetAllClassesForShow(ShowId);
            var dogClasses = new List<ShowClasses>();
            var d = new Dogs(DogId);
            d.Grade = Grade;

            foreach (ShowClasses cls in classList)
            {
                if (d.Grade == 99)
                {
                    if (cls.EntryType == 2 && includeVeteran)
                    {
                        dogClasses.Add(cls);
                    }
                }
                else
                {
                    if ((cls.EntryType == 2 && includeVeteran))
                    {
                        dogClasses.Add(cls);
                    }
                    else if (cls.Grades.Contains(d.Grade.ToString())
                        && ( d.Height == cls.Height ||
                        (cls.Height == 0 && (cls.EntryType == 1 || cls.EntryType == 4 || cls.EntryType == 5 || cls.EntryType == 9)) ||
                        cls.Height == 5 && d.Height == 1  )  )
                    {
                        dogClasses.Add(cls);
                    }
                }
            }
            return dogClasses;
        }