Ejemplo n.º 1
0
        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();
            }
        }