public void Refresh(StyleGuide.API api, Int32 pPageNo)
 {
     StyleGuide.PagingInfo pgInf = null;
     if (pPageNo > 0)
     {
         pgInf = new StyleGuide.PagingInfo();
         pgInf.RecordsPerPage = REC_PER_PAGE;
         pgInf.CurrentPage    = pPageNo;
     }
     StyleGuide.SgCategories.Categories cats = null;
     if (!string.IsNullOrWhiteSpace(tbSearch.Text))
     {
         if (this.rbSearchOpt.SelectedItem.Value == "C")
         {
             cats = api.getAllCategoriesNameContains(tbSearch.Text, pgInf);
         }
         else
         {
             cats = api.getAllCategoriesNameStartsWith(tbSearch.Text, pgInf);
         }
     }
     else
     {
         cats = api.getAllCategories(pgInf);
     }
     this.gvCatList.DataSource = cats;
     this.gvCatList.DataBind();
     SetPaging(cats, (pPageNo == -1 ? true : false));
 }
        public void Refresh(StyleGuide.API api)
        {
            StyleGuide.SgCategories.Categories cats = null;
            if (!string.IsNullOrWhiteSpace(tbSearch.Text))
            {
                cats = api.getAllCategoriesContainsEntitiesOrderByType(tbSearch.Text, true);
            }
            else
            {
                cats = api.getAllCategoriesOrderByType(null, true);
            }
            if (cats != null)
            {
                this.lbError.Text = "";

                this.trvCat.Nodes.Clear();
                bool selected = false;
                foreach (StyleGuide.SgCategories.Category cat in cats)
                {
                    TreeNode node  = new TreeNode();
                    int      xDays = App_Code.webConfig.ShowEntityCountModifiedInLastXdays();
                    int      count = api.getEntityCountModifiedLaterthan(cat.ID, DateTime.Now.AddDays(xDays * -1));
                    if (count >= 1)
                    {
                        node.Text = cat.Name + string.Format("<span style='color:red;padding-left:5px;'>{0}*</span>", count);
                    }
                    else
                    {
                        node.Text = cat.Name;
                    }
                    node.Value   = cat.ID.ToString();
                    node.ToolTip = cat.Name;
                    if (!selected)
                    {
                        node.Select();
                        selected = true;
                    }
                    this.trvCat.Nodes.Add(node);
                    node = null;
                }
                trvCat_SelectedNodeChanged(this.trvCat, null);
            }
            else
            {
                this.trvCat.Nodes.Clear();
                this.rptType.DataSource = null;
                this.rptType.DataBind();
                this.divShowAllEntityType.Visible = false;
                this.lbError.Text = "No Entity found.";
            }
        }
        protected void btNew_Click(object sender, EventArgs e)
        {
            StyleGuide.API api = new StyleGuide.API();
            try
            {
                this.tbSearch.Text = "";
                btSave_Click(this.btSave, null);
                Refresh(api, UcPaging1.TotalPages);

                StyleGuide.PagingInfo pgInf = null;
                if (this.UcPaging1.CurrentPage > 0)
                {
                    pgInf = new StyleGuide.PagingInfo();
                    pgInf.RecordsPerPage = REC_PER_PAGE;
                    pgInf.CurrentPage    = this.UcPaging1.TotalPages;
                }

                StyleGuide.SgCategories.Categories cats = api.getAllCategories(pgInf);
                if (cats == null)
                {
                    cats = new StyleGuide.SgCategories.Categories();
                }

                StyleGuide.SgCategories.Category cat = new StyleGuide.SgCategories.Category();
                cat.ID   = -1;
                cat.Name = "New ";
                cats.Add(cat);

                this.gvCatList.DataSource = cats;
                this.gvCatList.DataBind();
                SetPaging(cats, true);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("Error on CreateNew(). " + ex.Message);
            }
            finally
            {
                api.Dispose();
            }
        }
 private void SetPaging(StyleGuide.SgCategories.Categories cats, bool Move2LastPage)
 {
     if (cats != null)
     {
         this.UcPaging1.TotalPages = cats.PageInfo.TotalPages;
         if (Move2LastPage)
         {
             this.UcPaging1.CurrentPage = this.UcPaging1.TotalPages;
         }
         else
         {
             this.UcPaging1.CurrentPage = Convert.ToInt32(cats.PageInfo.CurrentPage);
         }
         this.UcPaging1.Refresh();
     }
     else
     {
         this.UcPaging1.TotalPages = 0;
         this.UcPaging1.Enabled    = false;
     }
 }