protected void btNew_Click(object sender, EventArgs e)
 {
     StyleGuide.API api = new StyleGuide.API();
     try
     {
         btSave_Click(this.btSave, null);
         StyleGuide.SgCategories.CategoryType type = new StyleGuide.SgCategories.CategoryType();
         type.ID   = -1;
         type.Type = "New ";
         StyleGuide.SgCategories.CategoryTypes types = api.getAllCategoryTypes();
         if (types == null)
         {
             types = new StyleGuide.SgCategories.CategoryTypes();
         }
         types.Add(type);
         this.gvCatTypeList.DataSource = types;
         this.gvCatTypeList.DataBind();
     }
     catch (Exception ex)
     {
         ShowErrorMessage("Error on CreateNew(). " + ex.Message);
     }
     finally
     {
         api.Dispose();
     }
 }
 protected void btSave_Click(object sender, EventArgs e)
 {
     StyleGuide.API api = new StyleGuide.API();
     try
     {
         foreach (GridViewRow r in this.gvCatTypeList.Rows)
         {
             string Changed = getPostedValue(r, "hfChanged");
             string tbId    = getPostedValue(r, "tbID");
             if (Changed == "1" || tbId == "-1")
             {
                 string tbType = getPostedValue(r, "tbType");
                 StyleGuide.SgCategories.CategoryType type;
                 if (tbId == "-1")
                 {
                     type = new StyleGuide.SgCategories.CategoryType();
                 }
                 else
                 {
                     type = api.getCategoryTypeByID(Convert.ToInt64(tbId));
                 }
                 if (type != null)
                 {
                     type.ID   = Convert.ToInt64(tbId);
                     type.Type = tbType;
                     api.SaveCategoryType(type);
                     ShowMessage("Category Type saved");
                 }
                 else
                 {
                     throw new Exception("Category Type ID not found.");
                 }
             }
         }
         Refresh(api);
     }
     catch (Exception ex)
     {
         ShowErrorMessage("Error on Save(). " + ex.Message);
     }
     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.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 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) { }
                }
            }
        }