protected void btnClear_Click(object sender, EventArgs e)
 {
     CategoryId.ClearSelection();
     AgeGroupId.ClearSelection();
     BranchId.ClearSelection();
     LocationID.ClearSelection();
     odsBadges.DataBind();
     rptr.DataBind();
     var wt = new WebTools();
     CategoryId.CssClass = wt.CssRemoveClass(CategoryId.CssClass, "gra-search-active");
     AgeGroupId.CssClass = wt.CssRemoveClass(AgeGroupId.CssClass, "gra-search-active");
     BranchId.CssClass = wt.CssRemoveClass(BranchId.CssClass, "gra-search-active");
     LocationID.CssClass = wt.CssRemoveClass(LocationID.CssClass, "gra-search-active");
 }
        protected void Page_Load(object sender, EventArgs e) {
            var wt = new WebTools();
            codeEntryField.CssClass = wt.CssRemoveClass(codeEntryField.CssClass, "code-glow");

            if (!IsPostBack) {
                if(Session["Patron"] == null) {
                    Response.Redirect("~");
                }
                var patron = (Patron)Session[SessionKey.Patron];
                var program = Programs.FetchObject(patron.ProgID);

                if(program == null || !program.IsOpen) {
                    codeControlPanel.Visible = false;
                    return;
                }
                ViewState["PatronId"] = patron.PID.ToString();

                var storedCode = Session[SessionKey.SecretCode];
                if(storedCode != null && !string.IsNullOrWhiteSpace(storedCode.ToString()))
                {
                    codeEntryField.Text = storedCode.ToString();
                    codeEntryField.CssClass = wt.CssEnsureClass(codeEntryField.CssClass, "code-glow");
                
                    Session.Remove(SessionKey.SecretCode);
                    new SessionTools(Session).AlertPatron(
                        StringResources.getString("secret-code-link"),
                        PatronMessageLevels.Info,
                        "barcode");
                }
            }
        }
        protected void btnFilter_Click(object sender, EventArgs e)
        {
            odsBadges.DataBind();
            rptr.DataBind();
            var wt = new WebTools();
            if (CategoryId.SelectedIndex > 0
                || AgeGroupId.SelectedIndex > 0
                || BranchId.SelectedIndex > 0
                || LocationID.SelectedIndex > 0)
            {
                CategoryId.CssClass = wt.CssEnsureClass(CategoryId.CssClass, "gra-search-active");
                AgeGroupId.CssClass = wt.CssEnsureClass(AgeGroupId.CssClass, "gra-search-active");
                BranchId.CssClass = wt.CssEnsureClass(BranchId.CssClass, "gra-search-active");
                LocationID.CssClass = wt.CssEnsureClass(LocationID.CssClass, "gra-search-active");
            }
            else
            {
                CategoryId.CssClass = wt.CssRemoveClass(CategoryId.CssClass, "gra-search-active");
                AgeGroupId.CssClass = wt.CssRemoveClass(AgeGroupId.CssClass, "gra-search-active");
                BranchId.CssClass = wt.CssRemoveClass(BranchId.CssClass, "gra-search-active");
                LocationID.CssClass = wt.CssRemoveClass(LocationID.CssClass, "gra-search-active");

            }
        }
        protected void ClearSearch(object sender, EventArgs e)
        {
            SearchText.Text = string.Empty;
            BranchId.SelectedIndex = 0;
            var wt = new WebTools();

            BranchId.CssClass = wt.CssRemoveClass(BranchId.CssClass, "gra-search-active");
            SearchText.CssClass = wt.CssRemoveClass(SearchText.CssClass, "gra-search-active");
            LoadData();
        }
        protected void Search(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(SearchText.Text))
            {
                SearchText.Text = string.Empty;
            }

            var wt = new WebTools();
            if (!string.IsNullOrEmpty(SearchText.Text) || BranchId.SelectedIndex > 0)
            {
                BranchId.CssClass = wt.CssEnsureClass(BranchId.CssClass, "gra-search-active");
                SearchText.CssClass = wt.CssEnsureClass(SearchText.CssClass, "gra-search-active");
            }
            else
            {
                BranchId.CssClass = wt.CssRemoveClass(BranchId.CssClass, "gra-search-active");
                SearchText.CssClass = wt.CssRemoveClass(SearchText.CssClass, "gra-search-active");
            }
            LoadData();
        }
 protected void PopulateChallengeList()
 {
     int patronId = -1;
     if (this.CurrentPatron != null)
     {
         patronId = this.CurrentPatron.PID;
     }
     Filtered = !string.IsNullOrWhiteSpace(SearchText.Text);
     var ds = DAL.BookList.GetForDisplay(patronId, SearchText.Text);
     rptr.DataSource = ds;
     rptr.DataBind();
     var wt = new WebTools();
     if (ds.Tables[0].Rows.Count == 0)
     {
         ChallengesContainer.Visible = false;
         if (Filtered)
         {
             WhatsShowing.Text
                 = WhatsShowingPrint.Text
                 = StringResources.getString("challenges-no-match");
             WhatsShowingPanel.Visible = true;
             WhatsShowingPanel.CssClass = wt.CssRemoveClass(WhatsShowingPanel.CssClass,
                 "alert-success");
             WhatsShowingPanel.CssClass = wt.CssEnsureClass(WhatsShowingPanel.CssClass,
                 "alert-warning");
         }
         else
         {
             WhatsShowing.Text
                 = WhatsShowingPrint.Text
                 = StringResources.getString("challenges-no-challenges");
             WhatsShowingPanel.Visible = true;
             WhatsShowingPanel.CssClass = wt.CssRemoveClass(WhatsShowingPanel.CssClass,
                 "alert-success");
             WhatsShowingPanel.CssClass = wt.CssEnsureClass(WhatsShowingPanel.CssClass,
                 "alert-warning");
         }
     }
     else
     {
         ChallengesContainer.Visible = true;
         if (Filtered)
         {
             WhatsShowing.Text
                 = WhatsShowingPrint.Text
                 = string.Format("You searched for: <strong>{0}</strong>", SearchText.Text);
             WhatsShowingPanel.Visible = true;
             WhatsShowingPanel.CssClass
                 = wt.CssRemoveClass(WhatsShowingPanel.CssClass, "alert-warning");
             WhatsShowingPanel.CssClass
                 = wt.CssEnsureClass(WhatsShowingPanel.CssClass, "alert-success");
         }
         else
         {
             WhatsShowing.Text
                 = WhatsShowingPrint.Text
                 = string.Empty;
             WhatsShowingPanel.Visible = false;
         }
     }
     if (Filtered)
     {
         SearchText.CssClass
             = wt.CssEnsureClass(SearchText.CssClass, "gra-search-active");
     }
     else
     {
         SearchText.CssClass
             = wt.CssRemoveClass(SearchText.CssClass, "gra-search-active");
     }
 }
        protected void DoFilter(EventSearchCriteria criteria)
        {
            StringBuilder sb = new StringBuilder();
            if (!string.IsNullOrEmpty(criteria.StartDate))
            {
                sb.Append("Start Date: ");
                sb.Append("<strong>");
                sb.Append(criteria.StartDate);
                sb.Append("</strong>");
            }
            if (!string.IsNullOrEmpty(criteria.EndDate))
            {
                if (sb.Length > 0)
                {
                    sb.Append(" / ");
                }
                sb.Append("End date: ");
                sb.Append("<strong>");
                sb.Append(criteria.EndDate);
                sb.Append("</strong>");
            }
            if (criteria.SystemId > 0)
            {
                if (sb.Length > 0)
                {
                    sb.Append(" / ");
                }
                sb.Append("System: ");
                sb.Append("<strong>");
                sb.Append(SystemId.Items.FindByValue(criteria.SystemId.ToString()).Text);
                sb.Append("</strong>");
            }
            if (criteria.BranchId > 0)
            {
                if (sb.Length > 0)
                {
                    sb.Append(" / ");
                }
                sb.Append("Branch/library: ");
                sb.Append("<strong>");
                sb.Append(criteria.BranchName);
                sb.Append("</strong>");
            }
            if (!string.IsNullOrWhiteSpace(criteria.SearchText))
            {
                if (sb.Length > 0)
                {
                    sb.Append(" / ");
                }
                sb.Append("Search text: ");
                sb.Append("<strong>");
                sb.Append(criteria.SearchText);
                sb.Append("</strong>");
            }

            WhatsShowing.Text = WhatsShowingPrint.Text = sb.ToString();
            WhatsShowingPanel.Visible = Filtered = !string.IsNullOrEmpty(WhatsShowing.Text);

            if (string.IsNullOrEmpty(WhatsShowing.Text))
            {
                // no filter criteria, use cache if possible
                var st = new SessionTools(Session);
                var cachedEvents = st.GetCache(Cache, CacheKey.AllEvents) as System.Data.DataSet;
                if (cachedEvents != null)
                {
                    rptr.DataSource = cachedEvents;
                }
                else
                {
                    var allEvents = Event.GetUpcomingDisplay(
                        criteria.StartDate,
                        criteria.EndDate,
                        criteria.SystemId,
                        criteria.BranchId,
                        criteria.SearchText);
                    rptr.DataSource = allEvents;

                    string tenantCacheKey = st.GetTenantCacheKey(CacheKey.AllEvents);
                    Cache.Insert(tenantCacheKey,
                        allEvents,
                        null,
                        DateTime.UtcNow.AddHours(2),
                        System.Web.Caching.Cache.NoSlidingExpiration,
                        System.Web.Caching.CacheItemPriority.Default,
                        null);
                }
            }
            else
            {
                rptr.DataSource = Event.GetUpcomingDisplay(
                    criteria.StartDate,
                    criteria.EndDate,
                    criteria.SystemId,
                    criteria.BranchId,
                    criteria.SearchText);
            }
            rptr.DataBind();

            var wt = new WebTools();
            if (Filtered)
            {
                StartDate.CssClass = wt.CssEnsureClass(StartDate.CssClass, "gra-search-active");
                EndDate.CssClass = wt.CssEnsureClass(EndDate.CssClass, "gra-search-active");
                BranchId.CssClass = wt.CssEnsureClass(BranchId.CssClass, "gra-search-active");
                SystemId.CssClass = wt.CssEnsureClass(SystemId.CssClass, "gra-search-active");
                SearchText.CssClass = wt.CssEnsureClass(SearchText.CssClass, "gra-search-active");
            }
            else
            {
                StartDate.CssClass = wt.CssRemoveClass(StartDate.CssClass, "gra-search-active");
                EndDate.CssClass = wt.CssRemoveClass(EndDate.CssClass, "gra-search-active");
                BranchId.CssClass = wt.CssRemoveClass(BranchId.CssClass, "gra-search-active");
                SystemId.CssClass = wt.CssRemoveClass(SystemId.CssClass, "gra-search-active");
                SearchText.CssClass = wt.CssRemoveClass(SearchText.CssClass, "gra-search-active");
            }
        }