コード例 #1
0
        protected void lbSave_Click(object sender, EventArgs e)
        {
            SaveLastViewedProduct();

            if (GetStringState(MODE) == EDIT)
            {
                if (NotChosenProducts.Count > 0)
                {
                    BrandService.UpdateProductWithBrandCategory(AppConstant.DEFAULT_BRAND_CATEGORY, NotChosenProducts);
                }

                if (ChosenProducts.Count > 0)
                {
                    BrandService.UpdateProductWithBrandCategory(GetIntState(LAST_CHOSEN_BRAND_CATEGORY), ChosenProducts);
                }

                var treeList = BrandService.GetBrandCategoryTreeList(GetIntState(LAST_CHOSEN_BRAND_CATEGORY));

                ectBrandCategory.FindSelectedNode(AppConstant.DEFAULT_BRAND_CATEGORY, treeList);

                DisposeState(PRODUCT_ID_FILTER);
                DisposeState(NAME_FILTER);
                SetState(CHOSEN_FILTER, (GetIntState(BRAND_CATEGORY_ID) == -1 ? ANY : YES));

                // Reset page number to 1
                gvProducts.CustomPageIndex = 0;
                UtilityService.RefreshCache(CacheEntityKey.Brand | CacheEntityKey.Product);

                LoadProducts();

                enbNotice.Message = "Product(s) was saved successfully.";
            }
            else
            {
                enbNotice.Message = "Please save new brand category first.";
            }

            hfCurrentPanel.Value = "products";
        }
コード例 #2
0
        protected void lbSaveBrandCategory_Click(object sender, EventArgs e)
        {
            string urlKey = txtUrlKey.Text.Trim();

            txtUrlKey.BackColor = Color.Empty;

            // If url key is empty, regenerate with given category name
            if (urlKey == string.Empty)
            {
                urlKey         = AdminStoreUtility.GetFriendlyUrlKey(txtName.Text.Trim());
                txtUrlKey.Text = urlKey;
            }

            // Make sure url key is unique
            if (((GetStringState(MODE) == NEW) && (BrandService.GetBrandCategoryByUrlKey(urlKey) != null)) ||
                ((GetStringState(MODE) == EDIT) && (BrandService.GetBrandCategoryByUrlKey(urlKey) != null) && (BrandService.GetBrandCategoryByUrlKey(urlKey).Id != GetIntState(BRAND_CATEGORY_ID))))
            {
                enbNotice.Message = "Url key is not unique.";
            }
            else
            {
                string thumbnailFilename = string.Empty;

                if (fuThumbnail.HasFile)
                {
                    thumbnailFilename = txtUrlKey.Text.Trim() + Path.GetExtension(fuThumbnail.FileName).ToLower();
                    fuThumbnail.SaveAs(MediaSettings.BrandMediaLocalPath + thumbnailFilename);
                }
                else
                {
                    if (!cbRemoveThumb.Checked)
                    {
                        BrandCategory category = BrandService.GetBrandCategoryByUrlKey(urlKey);

                        if (category != null)
                        {
                            thumbnailFilename = category.ImageUrl;
                        }
                    }
                }

                BrandCategory brandCategory = new BrandCategory();
                brandCategory.Name        = Server.HtmlEncode(txtName.Text.Trim());
                brandCategory.BrandId     = QueryBrandId;
                brandCategory.Description = Server.HtmlEncode(txtDesc.Text.Trim());
                brandCategory.ImageUrl    = thumbnailFilename;
                brandCategory.UrlRewrite  = txtUrlKey.Text.Trim();
                brandCategory.Visible     = cbVisible.Checked;

                if (!string.IsNullOrEmpty(hfParent.Value))
                {
                    brandCategory.ParentId = Convert.ToInt32(hfParent.Value);
                }

                if (GetStringState(MODE) == NEW)
                {
                    if (string.IsNullOrEmpty(hfParent.Value))
                    {
                        brandCategory.ParentId = AppConstant.DEFAULT_BRAND_CATEGORY;
                    }

                    brandCategory.Id = BrandService.InsertBrandCategory(brandCategory);
                }
                else // Edit mode
                {
                    brandCategory.Id = GetIntState(LAST_CHOSEN_BRAND_CATEGORY);
                    BrandService.UpdateBrandCategory(brandCategory);
                }

                ectBrandCategory.Repopulate();

                var treeList = BrandService.GetBrandCategoryTreeList(brandCategory.Id);
                ectBrandCategory.FindSelectedNode(AppConstant.DEFAULT_BRAND_CATEGORY, treeList);

                PopulateBrandCategoryInfo(brandCategory.Id);

                enbNotice.Message = "Brand category was saved successfully.";
            }

            cbRemoveThumb.Checked = false;

            ChosenProducts.Clear();
            NotChosenProducts.Clear();
            LoadProducts();
        }