protected void Page_Init(object sender, EventArgs e)
        {
            HasEditPermission = Permissions.PermissionsForUser(SessionHelper.UserId()).Contains(Permissions.PermissionKeys.sys_perm);

            Master.AddButtonNew(CategoriesStrings.GetText(@"NewSubCategoryButton"), @"EditSubCategory.aspx?New=yes", new string[] { Permissions.PermissionKeys.sys_perm });
            dgSubCategories.PageIndexChanged += dgSubCategories_PageIndexChanged;
        }
        protected void LoadItems(string sortField = "CategoryId", dg.Sql.SortDirection sortDirection = dg.Sql.SortDirection.ASC)
        {
            if (!HasEditPermission)
            {
                dgCategories.Columns[dgCategories.Columns.Count - 1].Visible = false;
            }

            dgCategories.VirtualItemCount = ProductController.GetAllCategory().Count;
            if (dgCategories.VirtualItemCount == 0)
            {
                phHasItems.Visible   = false;
                phHasNoItems.Visible = true;
                lblNoItems.Text      = CategoriesStrings.GetText(@"MessageNoCategoriesFound");
            }
            else
            {
                phHasItems.Visible   = true;
                phHasNoItems.Visible = false;

                if (dgCategories.PageSize * dgCategories.CurrentPageIndex > dgCategories.VirtualItemCount)
                {
                    dgCategories.CurrentPageIndex         = 0;
                    hfCurrentPageIndex_dgCategories.Value = dgCategories.CurrentPageIndex.ToString();
                }
                List <CategoryUI> categories = ProductController.GetAllCategory(0, dgCategories.PageSize, dgCategories.CurrentPageIndex);
                BindList(categories);
            }
        }
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         SubCategory.Delete(SubCategoryId);
         string url = "SubCategories.aspx?message-success=" + CategoriesStrings.GetText(@"MessageSubCategoryDeleted");
         Response.Redirect(url, true);
     }
 }
Beispiel #4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Category category;

            if (!Page.IsValid)
            {
                return;
            }
            if (IsNewMode)
            {
                category = Category.FetchByName(txtCategoryName.Text);
                if (category != null)
                {
                    Master.MessageCenter.DisplayErrorMessage(CategoriesStrings.GetText(@"MessageCategoryAlreadyExists"));
                    return;
                }
                category = new Category();
                category.CategoryName = txtCategoryName.Text;
            }
            else
            {
                category = Category.FetchByID(CategoryId);
            }
            if (category == null)
            {
                Master.MessageCenter.DisplayErrorMessage(CategoriesStrings.GetText(@"MessageUnknownError"));
                return;
            }


            //if (fuImage.HasFile)
            //{
            //    if (!IsNewMode) MediaUtility.DeleteImageFilePath("Category", category.CategoryImage, 64, 64, 0);
            //    string fn = MediaUtility.SaveFile(fuImage.PostedFile, "Category", 0);
            //    category.CategoryImage = fn;
            //    imgImage.ImageUrl = Snoopi.core.MediaUtility.GetImagePath("Category", category.CategoryImage, 0, 64, 64);
            //    ImageFileHandler(fuImage, imgImage, btnDeleteImage, imgImage.ImageUrl);
            //}
            //else if (category.CategoryImage != "" && fuImage.Visible)
            //{
            //    MediaUtility.DeleteImageFilePath("Category", category.CategoryImage, 64, 64, 0);
            //    category.CategoryImage = "";
            //}
            category.Save();

            CategoryId = category.CategoryId;
            string successMessage = IsNewMode ? CategoriesStrings.GetText(@"MessageCategoryCreated") : CategoriesStrings.GetText(@"MessageCategorySaved");
            string url            = @"EditCategory.aspx?New=yes";

            url += @"&message-success=" + Server.UrlEncode(successMessage);
            Response.Redirect(url, true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Int64.TryParse(Request.QueryString[@"SubCategoryId"], out SubCategoryId))
            {
                if (ProductController.IsSubCategoryInUse(SubCategoryId))
                {
                    Master.MessageCenter.DisplayErrorMessage(CategoriesStrings.GetText(@"MessageDeleteFailedCategoryInUse"));
                    pnlDelete.Visible = false;
                }
            }
            SubCategoryName = new Query(SubCategory.TableSchema).Select(SubCategory.Columns.SubCategoryName).Where(SubCategory.Columns.SubCategoryId, SubCategoryId).ExecuteScalar();

            if (SubCategoryName == null)
            {
                Http.Respond404(true);
            }
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                SubCategoryCollection coll = ProductController.GetAllSubCategory(CategoryId);
                if (coll.Count > 0)
                {
                    foreach (SubCategory subCategory in coll)
                    {
                        SubCategory.Delete(subCategory.SubCategoryId);
                    }
                }

                Category.Delete(CategoryId);
                string url = "Categories.aspx?message-success=" + CategoriesStrings.GetText(@"MessageCategoryDeleted");
                Response.Redirect(url, true);
            }
        }
        protected void LoadItems(string sortField = "CategoryId", dg.Sql.SortDirection sortDirection = dg.Sql.SortDirection.ASC)
        {
            if (!HasEditPermission)
            {
                dgSubCategories.Columns[dgSubCategories.Columns.Count - 1].Visible = false;
            }
            if (Int64.Parse(ddlCategory.SelectedValue) != 0)
            {
                dgSubCategories.VirtualItemCount = ProductController.GetSubCategories(Int64.Parse(ddlCategory.SelectedValue)).Count;
            }
            else
            {
                dgSubCategories.VirtualItemCount = ProductController.GetSubCategories().Count;
            }

            if (dgSubCategories.VirtualItemCount == 0)
            {
                phHasItems.Visible   = false;
                phHasNoItems.Visible = true;
                lblNoItems.Text      = CategoriesStrings.GetText(@"MessageNoSubCategoriesFound");
            }
            else
            {
                phHasItems.Visible   = true;
                phHasNoItems.Visible = false;

                if (dgSubCategories.PageSize * dgSubCategories.CurrentPageIndex > dgSubCategories.VirtualItemCount)
                {
                    dgSubCategories.CurrentPageIndex         = 0;
                    hfCurrentPageIndex_dgSubCategories.Value = dgSubCategories.CurrentPageIndex.ToString();
                }
                List <CategoryUI> categories = ProductController.GetSubCategories(Int64.Parse(ddlCategory.SelectedValue), dgSubCategories.PageSize, dgSubCategories.CurrentPageIndex);
                //foreach (CategoryUI item in categories)
                //{
                //    item.Filters = ProductController.GetAllFilter();
                //}

                BindList(categories);
            }
        }
        protected void btnExport_Click(object sender, EventArgs e)
        {
            System.Data.DataTable dt = new System.Data.DataTable();

            dt.Columns.Add(new System.Data.DataColumn(CategoriesStrings.GetText(@"CategoryId"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(CategoriesStrings.GetText(@"CategoryName"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(CategoriesStrings.GetText(@"CategoryRate"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(CategoriesStrings.GetText(@"SubCategoryId"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(CategoriesStrings.GetText(@"SubCategoryName"), typeof(string)));
            List <CategoryUI> categories = ProductController.GetAllCategoriesAndSubCategories();

            foreach (CategoryUI category in categories)
            {
                int i = 0;
                System.Data.DataRow row = dt.NewRow();
                row[i++] = category.CategoryId;
                row[i++] = category.CategoryName;
                row[i++] = category.CategoryRate;
                row[i++] = category.SubCategoryId;
                row[i++] = category.SubCategoryName;
                dt.Rows.Add(row);
            }

            SpreadsheetWriter ex     = SpreadsheetWriter.FromDataTable(dt, true, true);
            ExcelSheetStyle   _style = new ExcelSheetStyle();

            _style.Alignment.Horizontal = HorizontalAlignment.Center;
            ex.AddStyle(_style);

            Response.Clear();
            Response.AddHeader(@"content-disposition", @"attachment;filename=CategoriesExport_" + DateTime.Now.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension);
            Response.Charset         = @"UTF-8";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = ex.FileContentType;
            Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
            Response.Write(ex.ToString());
            Response.End();
        }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     Master.PageTitleHtml = string.Format(CategoriesStrings.GetText(@"DeleteCategoryPageTitle"), SubCategoryName);
     Master.ActiveMenu    = "SubCategories";
 }
Beispiel #10
0
 protected void Page_PreRender(object sender, EventArgs e)
 {
     Master.PageTitle        = CategoriesStrings.GetText(IsNewMode ? @"NewSubCategoryPageTitle" : @"EditSubCategoryPageTitle");
     Master.ActiveMenu       = "NewSubCategory";
     rfvCategoryName.Visible = rfvCategoryName.Enabled;
 }
Beispiel #11
0
 protected void Page_Init(object sender, EventArgs e)
 {
     Master.AddButtonNew(CategoriesStrings.GetText(@"NewSubCategoryButton"), @"EditSubCategory.aspx?New=yes", new string[] { Permissions.PermissionKeys.sys_perm });
 }
Beispiel #12
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            SubCategory subCategory;

            if (!Page.IsValid)
            {
                return;
            }
            if (IsNewMode)
            {
                Int64 CategoryId = ddlCategory.SelectedValue != null?Convert.ToInt64(ddlCategory.SelectedValue) : 0;

                subCategory = SubCategory.FetchByName(txtCategoryName.Text, CategoryId);
                if (subCategory != null)
                {
                    Master.MessageCenter.DisplayErrorMessage(CategoriesStrings.GetText(@"MessageSubCategoryAlreadyExists"));
                    return;
                }
                subCategory = new SubCategory();
                subCategory.SubCategoryName = txtCategoryName.Text;
                subCategory.CategoryId      = Convert.ToInt64(ddlCategory.SelectedValue);
            }
            else
            {
                subCategory = SubCategory.FetchByID(SubCategoryId);
                subCategory.SubCategoryName = txtCategoryName.Text;
                //if(txtCategoryName.Text != subCategory.SubCategoryName)
            }
            if (subCategory == null)
            {
                Master.MessageCenter.DisplayErrorMessage(CategoriesStrings.GetText(@"MessageUnknownError"));
                return;
            }
            subCategory.Save();

            List <Int64> FiltersToSave = FillFiltersrList();

            if (FiltersToSave.Count > 0)
            {
                foreach (Int64 item in FiltersToSave)
                {
                    SubCategoryFilter subCategoryFilter = SubCategoryFilter.FetchByID(subCategory.SubCategoryId, item, subCategory.CategoryId);
                    if (subCategoryFilter == null)
                    {
                        subCategoryFilter = new SubCategoryFilter();
                        subCategoryFilter.SubCategoryId = subCategory.SubCategoryId;
                        subCategoryFilter.FilterId      = item;
                        subCategoryFilter.CategoryId    = subCategory.CategoryId;
                        subCategoryFilter.Save();
                    }
                }
            }

            //if (fuImage.HasFile)
            //{
            //    if (!IsNewMode) MediaUtility.DeleteImageFilePath("SubCategory", subCategory.SubCategoryImage, 64, 64, 0);
            //    string fn = MediaUtility.SaveFile(fuImage.PostedFile, "SubCategory", 0);
            //    subCategory.SubCategoryImage = fn;
            //    imgImage.ImageUrl = Snoopi.core.MediaUtility.GetImagePath("SubCategory", subCategory.SubCategoryImage, 0, 64, 64);
            //    ImageFileHandler(fuImage, imgImage, btnDeleteImage, imgImage.ImageUrl);
            //}
            //else if (subCategory.SubCategoryImage != "" && fuImage.Visible)
            //{
            //    MediaUtility.DeleteImageFilePath("SubCategory", subCategory.SubCategoryImage, 64, 64, 0);
            //    subCategory.SubCategoryImage = "";
            //}


            SubCategoryId = subCategory.SubCategoryId;
            string successMessage = IsNewMode ? CategoriesStrings.GetText(@"MessageSubCategoryCreated") : CategoriesStrings.GetText(@"MessageSubCategorySaved");
            string url            = @"EditSubCategory.aspx?New=yes";

            url += @"&message-success=" + Server.UrlEncode(successMessage);
            Response.Redirect(url, true);
        }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     Master.PageTitle  = CategoriesStrings.GetText(@"SubCategoriesPageTitle");
     Master.ActiveMenu = "SubCategories";
     Master.AddClientScriptInclude(@"dgDateManager.js");
 }