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));
 }
        protected void gvEntCats_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string cmd   = e.CommandName.ToLower();
            string entID = e.CommandArgument.ToString().Split(',')[0];
            string catID = e.CommandArgument.ToString().Split(',')[1];

            StyleGuide.API api = new StyleGuide.API();
            try
            {
                if (cmd == "DeleteCatRow".ToLower())
                {
                    if (entID != "-1")
                    {
                        api.RemoveCategoryFromEntity(Convert.ToInt64(catID), Convert.ToInt64(entID));

                        StyleGuide.SgEntities.Entity ent = api.getEntityByID(Convert.ToInt64(entID));
                        if (ent != null)
                        {
                            ent.LMBY = StyleGuideUI.App_Code.SgCommon.getLoggedUser();
                            api.SaveEntity(ent);
                        }
                    }
                }
                Refresh(api, UcPaging1.CurrentPage);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("Error on DeleteCatRow(). " + ex.Message);
            }
            finally
            {
                api.Dispose();
            }
        }
Beispiel #3
0
 protected void btNew_Click(object sender, EventArgs e)
 {
     StyleGuide.API api = new StyleGuide.API();
     try
     {
         btSave_Click(this.btSave, null);
         StyleGuide.SgEntities.EntityType type = new StyleGuide.SgEntities.EntityType();
         type.ID   = -1;
         type.Type = "New ";
         StyleGuide.SgEntities.EntityTypes types = api.getAllEntityTypes();
         if (types == null)
         {
             types = new StyleGuide.SgEntities.EntityTypes();
         }
         types.Add(type);
         this.gvEntTypeList.DataSource = types;
         this.gvEntTypeList.DataBind();
     }
     catch (Exception ex)
     {
         ShowErrorMessage("Error on CreateNew(). " + ex.Message);
     }
     finally
     {
         api.Dispose();
     }
 }
        protected void trvCat_SelectedNodeChanged(object sender, EventArgs e)
        {
            StyleGuide.API api = new StyleGuide.API();
            try
            {
                StyleGuide.SgEntities.EntitiesSearchResultsByCategory entitiesSearchResultsByCategory = null;

                if (!string.IsNullOrWhiteSpace(tbSearch.Text))
                {
                    entitiesSearchResultsByCategory = api.getEntitiesForSearchModule(Convert.ToInt64(trvCat.SelectedNode.Value), tbSearch.Text);
                    if (entitiesSearchResultsByCategory != null)
                    {
                        this.divShowAllEntityType.Visible = true;
                    }
                }
                else
                {
                    entitiesSearchResultsByCategory   = api.getEntitiesForSearchModule(Convert.ToInt64(trvCat.SelectedNode.Value), null);
                    this.divShowAllEntityType.Visible = false;
                }

                this.rptType.DataSource = entitiesSearchResultsByCategory;
                this.rptType.DataBind();
            }
            finally
            {
                api.Dispose();
            }
        }
        protected void gvCatList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string cmd = e.CommandName.ToLower();
            string id  = e.CommandArgument.ToString();

            StyleGuide.API api = new StyleGuide.API();
            try
            {
                if (cmd == "DeleteRow".ToLower())
                {
                    if (id != "-1")
                    {
                        api.DropCategory(Convert.ToInt64(id));
                    }
                }
                Refresh(api, UcPaging1.CurrentPage);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains(" REFERENCE "))
                {
                    ShowErrorMessage("Category already in use, and cannot be deleted.<br /><br />" + ex.Message);
                }
                else
                {
                    ShowErrorMessage("Error on DeleteRow(). " + ex.Message);
                }
            }
            finally
            {
                api.Dispose();
            }
        }
 protected void on_PageChange(object sender, int Page)
 {
     StyleGuide.API api = new StyleGuide.API();
     try
     {
         Refresh(api, Page);
     }
     finally
     {
         api.Dispose();
     }
 }
 protected void btSearch_Click(object sender, EventArgs e)
 {
     StyleGuide.API api = new StyleGuide.API();
     try
     {
         Refresh(api);
     }
     finally
     {
         api.Dispose();
     }
 }
 public void Refresh(StyleGuide.API api, Int32 pPageNo, string searchText = null)
 {
     StyleGuide.PagingInfo pgInf = null;
     if (pPageNo > 0)
     {
         pgInf = new StyleGuide.PagingInfo();
         pgInf.RecordsPerPage = REC_PER_PAGE;
         pgInf.CurrentPage    = pPageNo;
     }
     if (searchText != null)
     {
         tbSearch.Text = searchText;
     }
     StyleGuide.SgEntities.Entities ents = null;
     if (!string.IsNullOrWhiteSpace(tbSearch.Text))
     {
         if (tbSearch.Text.StartsWith("{ID}"))
         {
             string temp = tbSearch.Text.Replace("{ID}", "");
             if (StyleGuideUI.App_Code.SgCommon.IsNumeric(temp))
             {
                 long entID = Convert.ToInt64(temp);
                 StyleGuide.SgEntities.Entity ent = null;
                 ent  = api.getEntityByID(entID);
                 ents = new StyleGuide.SgEntities.Entities();
                 ents.Add(ent);
             }
             else
             {
                 ents = api.getAllEntities(pgInf);
             }
         }
         else
         {
             if (this.rbSearchOpt.SelectedItem.Value == "C")
             {
                 ents = api.getAllEntitiesNameContains(tbSearch.Text, pgInf);
             }
             else
             {
                 ents = api.getAllEntitiesNameStartsWith(tbSearch.Text, pgInf);
             }
         }
     }
     else
     {
         ents = api.getAllEntities(pgInf);
     }
     this.gvEntList.DataSource = ents;
     this.gvEntList.DataBind();
     SetPaging(ents, (pPageNo == -1 ? true : false));
 }
 protected void btClear_Click(object sender, EventArgs e)
 {
     StyleGuide.API api = new StyleGuide.API();
     try
     {
         this.tbSearch.Text = "";
         Refresh(api, 1);
     }
     finally
     {
         api.Dispose();
     }
 }
        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.";
            }
        }
Beispiel #11
0
        public bool InitEntities()
        {
            bool ret = false;

            StyleGuide.API api = new StyleGuide.API();
            try
            {
                ArticleFr.entities = api.getAllEntities(null, true);
            }
            finally
            {
                api.Dispose();
            }
            return(ret);
        }
Beispiel #12
0
        private void ShowModule(string module, string searchText)
        {
            StyleGuide.API api = new StyleGuide.API();
            try
            {
                switch (module)
                {
                case "E":
                {
                    this.MultiView1.SetActiveView(this.E);
                    this.UcEntityList1.Refresh(api, 1, searchText);
                    break;
                }

                case "C":
                {
                    this.MultiView1.SetActiveView(this.C);
                    this.UcCategoryList1.Refresh(api, 1);
                    break;
                }

                case "ET":
                {
                    this.MultiView1.SetActiveView(this.ET);
                    this.UcEntityTypeList1.Refresh(api);
                    break;
                }

                case "CT":
                {
                    this.MultiView1.SetActiveView(this.CT);
                    this.UcCategoryTypeList1.Refresh(api);
                    break;
                }

                default:
                {
                    this.MultiView1.SetActiveView(this.E);
                    this.UcEntityList1.Refresh(api, 1);
                    break;
                }
                }
            }
            finally
            {
                api.Dispose();
            }
        }
        public void RefreshEntCatGrid(StyleGuide.API api, GridView gvEntCats, long entID)
        {
            IList <EntCat> entCats = new List <EntCat>();
            IList <StyleGuide.SgCategories.Category> cats = api.getEntityByID(entID).categories;

            foreach (StyleGuide.SgCategories.Category cat in cats)
            {
                EntCat entCat = new EntCat();
                entCat.EntID   = entID;
                entCat.CatID   = cat.ID;
                entCat.CatName = cat.Name;
                entCats.Add(entCat);
            }
            gvEntCats.DataSource = entCats;// api.getEntityByID(entID).categories;
            gvEntCats.DataBind();
        }
Beispiel #14
0
 protected void btSave_Click(object sender, EventArgs e)
 {
     StyleGuide.API api = new StyleGuide.API();
     try
     {
         foreach (GridViewRow r in this.gvEntTypeList.Rows)
         {
             string Changed = getPostedValue(r, "hfChanged");
             string tbId    = getPostedValue(r, "tbID");
             if (Changed == "1" || tbId == "-1")
             {
                 string tbType = getPostedValue(r, "tbType");
                 StyleGuide.SgEntities.EntityType type;
                 if (tbId == "-1")
                 {
                     type = new StyleGuide.SgEntities.EntityType();
                 }
                 else
                 {
                     type = api.getEntityTypeByID(Convert.ToInt64(tbId));
                 }
                 if (type != null)
                 {
                     type.ID   = Convert.ToInt64(tbId);
                     type.Type = tbType;
                     api.SaveEntityType(type);
                     ShowMessage("Entity Type saved");
                 }
                 else
                 {
                     throw new Exception("Entity Type ID not found.");
                 }
             }
         }
         Refresh(api);
     }
     catch (Exception ex)
     {
         ShowErrorMessage("Error on Save(). " + ex.Message);
     }
     finally
     {
         api.Dispose();
     }
 }
        protected void lbShowAllEntityType_Click(object sender, EventArgs e)
        {
            StyleGuide.API api = new StyleGuide.API();
            try
            {
                StyleGuide.SgEntities.EntitiesSearchResultsByCategory entitiesSearchResultsByCategory = null;

                entitiesSearchResultsByCategory = api.getEntitiesForSearchModule(Convert.ToInt64(trvCat.SelectedNode.Value), null);

                this.rptType.DataSource = entitiesSearchResultsByCategory;
                this.rptType.DataBind();
            }
            finally
            {
                api.Dispose();
            }
            this.divShowAllEntityType.Visible = false;
        }
        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();
            }
        }
Beispiel #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            mPermission = new StyleGuide.Permission(this.Page);
            if (!mPermission.AccessStyleGuide())
            {
                Server.Transfer(StyleGuideUI.App_Code.SgCommon.AccessDeniedPage());
            }

            this.Page.MaintainScrollPositionOnPostBack = true;

            if (!IsPostBack)
            {
                StyleGuide.API api = new StyleGuide.API();
                try
                {
                    UcSearch1.Refresh(api);
                }
                finally
                {
                    api.Dispose();
                }
            }
        }
        protected void btSave_Click(object sender, EventArgs e)
        {
            StyleGuide.API api = new StyleGuide.API();
            try
            {
                Int32 PgIdx = UcPaging1.CurrentPage;
                foreach (GridViewRow r in this.gvEntList.Rows)
                {
                    string Changed = getPostedValue(r, "hfChanged");
                    string tbId    = getPostedValue(r, "tbID");
                    if (Changed == "1" || tbId == "-1")
                    {
                        string tbName        = getPostedValue(r, "tbName");
                        string tbSuspects    = getPostedValue(r, "tbSuspects");
                        string tbSuggestions = getPostedValue(r, "tbSuggestions");
                        string ddlEntType    = getPostedValue(r, "ddlEntTypes");
                        string tbNotes       = getPostedValue(r, "tbNotes");

                        StyleGuide.SgEntities.Entity     ent;
                        StyleGuide.SgEntities.EntityType entType = api.getEntityTypeByID(Convert.ToInt64(ddlEntType));

                        if (tbId == "-1")
                        {
                            ent = new StyleGuide.SgEntities.Entity();
                        }
                        else
                        {
                            ent = api.getEntityByID(Convert.ToInt64(tbId));
                        }
                        if (ent != null)
                        {
                            ent.Name        = tbName;
                            ent.Type.ID     = entType.ID;
                            ent.Type.Type   = entType.Type;
                            ent.Notes       = tbNotes;
                            ent.Suspects    = tbSuspects;
                            ent.Suggestions = tbSuggestions;
                            ent.LMBY        = StyleGuideUI.App_Code.SgCommon.getLoggedUser();
                            api.SaveEntity(ent);
                            initHandler();
                            ShowMessage("Entity saved");
                            if (tbId == "-1")
                            {
                                Refresh(api, UcPaging1.TotalPages);
                                PgIdx = UcPaging1.TotalPages;
                            }
                            else
                            {
                                PgIdx = UcPaging1.CurrentPage;
                            }
                        }
                        else
                        {
                            throw new Exception("Entity ID not found.");
                        }
                    }
                }
                Refresh(api, PgIdx);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("Error on Save(). " + ex.Message);
            }
            finally
            {
                api.Dispose();
            }
        }
        protected void gvEntList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string cmd = e.CommandName.ToLower();

            StyleGuide.API api = new StyleGuide.API();
            try
            {
                switch (cmd)
                {
                case "deleterow":
                {
                    string entID = e.CommandArgument.ToString();
                    if (entID != "-1")
                    {
                        try
                        {
                            api.DropEntity(Convert.ToInt64(entID));
                            initHandler();
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message.Contains(" REFERENCE "))
                            {
                                throw new Exception("Entity already in use, and cannot be deleted.<br /><br />" + ex.Message);
                            }
                            else
                            {
                                throw new Exception("Error on DeleteRow(). " + ex.Message);
                            }
                        }
                    }
                    Refresh(api, UcPaging1.CurrentPage);
                    break;
                }

                case "catnew":     //Image Button
                {
                    GridViewRow gvRow = ((e.CommandSource as Control).NamingContainer as GridViewRow);
                    if (gvRow != null)
                    {
                        ImageButton btCatNew = (ImageButton)(e.CommandSource as Control);
                        System.Web.UI.HtmlControls.HtmlGenericControl divAddNewCat = (System.Web.UI.HtmlControls.HtmlGenericControl)gvRow.FindControl("divAddNewCat");
                        DropDownList ddlEntCatList = (DropDownList)gvRow.FindControl("ddlEntCatList");
                        ddlEntCatList.DataSource = api.getAllCategories(null, true);
                        ddlEntCatList.DataBind();
                        divAddNewCat.Visible = true;
                        btCatNew.Visible     = false;
                    }

                    break;
                }

                case "catadd":     // Buton
                {
                    string entID = e.CommandArgument.ToString();
                    if (entID != "-1")
                    {
                        try
                        {
                            GridViewRow gvRow = ((e.CommandSource as Control).NamingContainer as GridViewRow);
                            if (gvRow != null)
                            {
                                ImageButton btCatNew = (ImageButton)gvRow.FindControl("btCatNew");
                                System.Web.UI.HtmlControls.HtmlGenericControl divAddNewCat = (System.Web.UI.HtmlControls.HtmlGenericControl)gvRow.FindControl("divAddNewCat");
                                DropDownList ddlEntCatList = (DropDownList)gvRow.FindControl("ddlEntCatList");
                                string       catID         = ddlEntCatList.SelectedItem.Value;

                                api.AddCategoryToEntity(Convert.ToInt64(catID), Convert.ToInt64(entID));
                                StyleGuide.SgEntities.Entity ent = api.getEntityByID(Convert.ToInt64(entID));
                                if (ent != null)
                                {
                                    ent.LMBY = StyleGuideUI.App_Code.SgCommon.getLoggedUser();
                                    api.SaveEntity(ent);
                                }


                                divAddNewCat.Visible = false;
                                btCatNew.Visible     = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Error on AddCategoryToEntity(). " + ex.Message);
                        }
                    }
                    Refresh(api, UcPaging1.CurrentPage);
                    break;
                }

                case "cataddcancel":     //Button
                {
                    string entID = e.CommandArgument.ToString();
                    if (entID != "-1")
                    {
                        try
                        {
                            GridViewRow gvRow = ((e.CommandSource as Control).NamingContainer as GridViewRow);
                            if (gvRow != null)
                            {
                                ImageButton btCatNew = (ImageButton)gvRow.FindControl("btCatNew");
                                System.Web.UI.HtmlControls.HtmlGenericControl divAddNewCat = (System.Web.UI.HtmlControls.HtmlGenericControl)gvRow.FindControl("divAddNewCat");
                                btCatNew.Visible     = true;
                                divAddNewCat.Visible = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Error on AddCategoryToEntity(). " + ex.Message);
                        }
                    }
                    Refresh(api, UcPaging1.CurrentPage);
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex.Message);
            }
            finally
            {
                api.Dispose();
            }
        }
 public void Refresh(StyleGuide.API api)
 {
     this.gvCatTypeList.DataSource = api.getAllCategoryTypes();
     this.gvCatTypeList.DataBind();
 }
Beispiel #21
0
 public void Refresh(StyleGuide.API api)
 {
     this.gvEntTypeList.DataSource = api.getAllEntityTypes();
     this.gvEntTypeList.DataBind();
 }
        protected void gvCatList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            bool borderleft = false;

            foreach (TableCell tc in e.Row.Cells)
            {
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    if (!borderleft)
                    {
                        tc.Attributes["style"] = "border-left:1px solid #c3cecc;border-right:1px solid #c3cecc;border-bottom:1px solid #c3cecc;";
                        borderleft             = true;
                    }
                    else
                    {
                        tc.Attributes["style"] = "border-right:1px solid #c3cecc;border-bottom:1px solid #c3cecc;";
                    }
                }
                else
                {
                    if (!borderleft)
                    {
                        tc.Attributes["style"] = "border-left:1px solid #c3cecc;border-right:1px solid #c3cecc;";
                        borderleft             = true;
                    }
                    else
                    {
                        tc.Attributes["style"] = "border-right:1px solid #c3cecc;";
                    }
                }
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DropDownList ddlCatTypes = (e.Row.FindControl("ddlCatTypes") as DropDownList);
                if (ddlCatTypes != null)
                {
                    try
                    {
                        StyleGuide.API api = new StyleGuide.API();
                        try
                        {
                            ddlCatTypes.DataSource     = api.getAllCategoryTypes(null, true);
                            ddlCatTypes.DataTextField  = "Type";
                            ddlCatTypes.DataValueField = "ID";
                            ddlCatTypes.DataBind();
                            ddlCatTypes.Style.Add("-webkit-appearance", "none");
                            StyleGuide.SgCategories.CategoryType catType = (StyleGuide.SgCategories.CategoryType)DataBinder.Eval(e.Row.DataItem, "Type");
                            if (catType != null)
                            {
                                int idx = _Library._Web._Common.FindDdlItemIndex(ddlCatTypes, catType.ID.ToString(), true);
                                ddlCatTypes.SelectedIndex = idx;
                            }
                            else
                            {
                                ddlCatTypes.Items.Insert(0, new ListItem("Please select", ""));
                            }

                            long catID = Convert.ToInt64(DataBinder.Eval(e.Row.DataItem, "ID"));
                            if (catID == -1)
                            {
                                (e.Row.FindControl("tbID") as TextBox).ForeColor             = System.Drawing.Color.Red;
                                (e.Row.FindControl("tbName") as TextBox).ForeColor           = System.Drawing.Color.Red;
                                (e.Row.FindControl("ddlCatTypes") as DropDownList).ForeColor = System.Drawing.Color.Red;
                                (e.Row.FindControl("tbNotes") as TextBox).ForeColor          = System.Drawing.Color.Red;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            api.Dispose();
                        }
                    }
                    catch (Exception) { }
                }
            }
        }
        protected void btSave_Click(object sender, EventArgs e)
        {
            StyleGuide.API api = new StyleGuide.API();
            try
            {
                Int32 PgIdx = UcPaging1.CurrentPage;
                foreach (GridViewRow r in this.gvCatList.Rows)
                {
                    string Changed = getPostedValue(r, "hfChanged");
                    string tbId    = getPostedValue(r, "tbID");
                    if (Changed == "1" || tbId == "-1")
                    {
                        string tbName     = getPostedValue(r, "tbName");
                        string ddlCatType = getPostedValue(r, "ddlCatTypes");
                        string tbNotes    = getPostedValue(r, "tbNotes");

                        StyleGuide.SgCategories.Category     cat;// = api.getCategoryByID(Convert.ToInt64(tbId));
                        StyleGuide.SgCategories.CategoryType catType = api.getCategoryTypeByID(Convert.ToInt64(ddlCatType));

                        if (tbId == "-1")
                        {
                            cat = new StyleGuide.SgCategories.Category();
                        }
                        else
                        {
                            cat = api.getCategoryByID(Convert.ToInt64(tbId));
                        }
                        if (cat != null)
                        {
                            cat.Name      = tbName;
                            cat.Type.ID   = catType.ID;
                            cat.Type.Type = catType.Type;
                            cat.Notes     = tbNotes;
                            cat.LMBY      = StyleGuideUI.App_Code.SgCommon.getLoggedUser();
                            api.SaveCategory(cat);
                            ShowMessage("Category saved");
                            if (tbId == "-1")
                            {
                                Refresh(api, UcPaging1.TotalPages);
                                PgIdx = UcPaging1.TotalPages;
                            }
                            else
                            {
                                PgIdx = UcPaging1.CurrentPage;
                            }
                        }
                        else
                        {
                            throw new Exception("Category ID not found.");
                        }
                    }
                }
                Refresh(api, PgIdx);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("Error on Save(). " + ex.Message);
            }
            finally
            {
                api.Dispose();
            }
        }
        protected void gvEntList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            bool borderleft = false;
            int  cellIdx    = 0;

            foreach (TableCell tc in e.Row.Cells)
            {
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    if (!borderleft)
                    {
                        if (cellIdx == 1)
                        {
                            tc.Attributes["style"] = "border-left:1px solid #c3cecc;border-right:1px solid #c3cecc;border-bottom:1px solid #c3cecc;display:none;";
                        }
                        else
                        {
                            tc.Attributes["style"] = "border-left:1px solid #c3cecc;border-right:1px solid #c3cecc;border-bottom:1px solid #c3cecc;";
                        }
                        borderleft = true;
                    }
                    else
                    {
                        if (cellIdx == 1)
                        {
                            tc.Attributes["style"] = "border-right:1px solid #c3cecc;border-bottom:1px solid #c3cecc;display:none;";
                        }
                        else
                        {
                            tc.Attributes["style"] = "border-right:1px solid #c3cecc;border-bottom:1px solid #c3cecc;";
                        }
                    }
                }
                else
                {
                    if (!borderleft)
                    {
                        if (cellIdx == 1)
                        {
                            tc.Attributes["style"] = "border-left:1px solid #c3cecc;border-right:1px solid #c3cecc;display:none;";
                        }
                        else
                        {
                            tc.Attributes["style"] = "border-left:1px solid #c3cecc;border-right:1px solid #c3cecc;";
                        }
                        borderleft = true;
                    }
                    else
                    {
                        if (cellIdx == 1)
                        {
                            tc.Attributes["style"] = "border-right:1px solid #c3cecc;display:none;";
                        }
                        else
                        {
                            tc.Attributes["style"] = "border-right:1px solid #c3cecc;";
                        }
                    }
                }
                cellIdx++;
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DropDownList ddlEntTypes = (e.Row.FindControl("ddlEntTypes") as DropDownList);
                if (ddlEntTypes != null)
                {
                    try
                    {
                        StyleGuide.API api = new StyleGuide.API();
                        try
                        {
                            ddlEntTypes.DataSource     = api.getAllEntityTypes(null, true);
                            ddlEntTypes.DataTextField  = "Type";
                            ddlEntTypes.DataValueField = "ID";
                            ddlEntTypes.DataBind();
                            ddlEntTypes.Style.Add("-webkit-appearance", "none");
                            StyleGuide.SgEntities.EntityType entType = (StyleGuide.SgEntities.EntityType)DataBinder.Eval(e.Row.DataItem, "Type");
                            if (entType != null)
                            {
                                int idx = _Library._Web._Common.FindDdlItemIndex(ddlEntTypes, entType.ID.ToString(), true);
                                ddlEntTypes.SelectedIndex = idx;
                            }
                            else
                            {
                                ddlEntTypes.Items.Insert(0, new ListItem("Please select", ""));
                            }

                            long entID = Convert.ToInt64(DataBinder.Eval(e.Row.DataItem, "ID"));
                            if (entID == -1)
                            {
                                ImageButton btCatNew = (e.Row.FindControl("btCatNew") as ImageButton);
                                if (btCatNew != null)
                                {
                                    btCatNew.Visible = false;
                                }
                                (e.Row.FindControl("tbID") as TextBox).ForeColor             = System.Drawing.Color.Red;
                                (e.Row.FindControl("tbName") as TextBox).ForeColor           = System.Drawing.Color.Red;
                                (e.Row.FindControl("ddlEntTypes") as DropDownList).ForeColor = System.Drawing.Color.Red;
                                (e.Row.FindControl("tbNotes") as TextBox).ForeColor          = System.Drawing.Color.Red;
                            }
                            GridView gvEntCats = (e.Row.FindControl("gvEntCats") as GridView);
                            RefreshEntCatGrid(api, gvEntCats, entID);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            api.Dispose();
                        }
                    }
                    catch (Exception) { }
                }
            }
        }