public static bool UnAssignAllProducts(ProductFilter filter, int groupId)
        {
            int totalCount   = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly);
            int currentIndex = 0;
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            while (currentIndex < totalCount)
            {
                IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex);
                foreach (Product p in currentBatch)
                {
                    ProductGroup pg = ProductGroupDataSource.Load(p.Id, groupId);
                    if (pg != null)
                    {
                        p.ProductGroups.Remove(pg);
                        p.Save();
                        pg.Delete();
                    }
                }
                currentIndex += 100;
            }

            database.CommitTransaction();
            return(true);
        }
예제 #2
0
        protected void GoButton_Click(object sender, EventArgs e)
        {
            bool selectAll = AlwaysConvert.ToBool(SelectAll.Value, false);
            bool link      = AlwaysConvert.ToBool(GridActions.SelectedValue, false);

            if (selectAll)
            {
                BitFieldState   featured = (BitFieldState)Enum.Parse(typeof(BitFieldState), FeaturedFilter.SelectedValue);
                IList <Product> products = ProductDataSource.FindProducts(Name.Text.Trim(), SearchDescriptions.Checked, Sku.Text.Trim(), AlwaysConvert.ToInt(CategoriesList.SelectedValue), AlwaysConvert.ToInt(ManufacturerList.SelectedValue), AlwaysConvert.ToInt(VendorList.SelectedValue), featured, AlwaysConvert.ToInt(TaxCodeList.SelectedValue), AlwaysConvert.ToDecimal(FromPrice.Text), AlwaysConvert.ToDecimal(ToPrice.Text), OnlyDigitalGoods.Checked, OnlyGiftCertificates.Checked, OnlyKits.Checked, OnlySubscriptions.Checked, AlwaysConvert.ToInt(ProductGroups.SelectedValue));
                foreach (var product in products)
                {
                    SetFeatured(product.Id, link);
                }
            }
            else
            {
                int indexPeg = PG.PageSize * PG.PageIndex;

                foreach (GridViewRow row in PG.Rows)
                {
                    CheckBox selected = (CheckBox)PageHelper.RecursiveFindControl(row, "PID");
                    if ((selected != null) && selected.Checked)
                    {
                        int productId = (int)PG.DataKeys[row.DataItemIndex - indexPeg].Values[0];
                        SetFeatured(productId, link);
                    }
                }
            }

            PG.DataBind();
        }
        public static bool AssignAllProducts(ProductFilter filter, int[] groupIds, string groupRestrictions)
        {
            int totalCount   = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly);
            int currentIndex = 0;
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            List <Group> groups = new List <Group>();

            foreach (int gid in groupIds)
            {
                Group group = GroupDataSource.Load(gid);
                if (group != null)
                {
                    groups.Add(group);
                }
            }
            while (currentIndex < totalCount)
            {
                IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex);
                foreach (Product p in currentBatch)
                {
                    foreach (Group group in groups)
                    {
                        ProductGroup pg = ProductGroupDataSource.Load(p.Id, group.Id);
                        if (pg == null)
                        {
                            pg = new ProductGroup(p, group);
                            p.ProductGroups.Add(pg);
                        }
                    }

                    switch (groupRestrictions)
                    {
                    case "YES":
                        p.EnableGroups = true;
                        break;

                    case "NO":
                        p.EnableGroups = false;
                        break;

                    default:
                        break;
                    }

                    p.Save();
                }
                currentIndex += 100;
            }

            database.CommitTransaction();
            return(true);
        }
        protected void GoButton_Click(object sender, EventArgs e)
        {
            bool selectAll = AlwaysConvert.ToBool(SelectAll.Value, false);
            bool link      = AlwaysConvert.ToBool(GridActions.SelectedValue, false);

            if (selectAll)
            {
                BitFieldState featured = OnlyFeatured.Checked ? BitFieldState.True : BitFieldState.Any;
                BitFieldState status   = (BitFieldState)Enum.Parse(typeof(BitFieldState), ProductAssignment.SelectedValue);

                int categoryId = 0;
                if (!_DisplayCategorySearch)
                {
                    categoryId = AlwaysConvert.ToInt(CategoriesList.SelectedValue);
                }
                else
                {
                    categoryId = AlwaysConvert.ToInt(HiddenSelectedCategoryId.Value);
                }

                IList <Product> products = ProductDataSource.FindProducts(Name.Text.Trim(), SearchDescriptions.Checked, Sku.Text.Trim(), categoryId, AlwaysConvert.ToInt(ManufacturerList.SelectedValue), AlwaysConvert.ToInt(VendorList.SelectedValue), featured, AlwaysConvert.ToInt(TaxCodeList.SelectedValue), AlwaysConvert.ToDecimal(FromPrice.Text), AlwaysConvert.ToDecimal(ToPrice.Text), OnlyDigitalGoods.Checked, OnlyGiftCertificates.Checked, OnlyKits.Checked, OnlySubscriptions.Checked, AlwaysConvert.ToInt(ProductGroups.SelectedValue), AssignmentTable, AssignmentValue, status);
                foreach (var product in products)
                {
                    if (OnAssignProduct != null)
                    {
                        OnAssignProduct(this, new FindAssignProductEventArgs(product.Id, link));
                    }
                }
            }
            else
            {
                int indexPeg = PG.PageSize * PG.PageIndex;

                foreach (GridViewRow row in PG.Rows)
                {
                    CheckBox selected = (CheckBox)PageHelper.RecursiveFindControl(row, "PID");
                    if ((selected != null) && selected.Checked)
                    {
                        int productId = (int)PG.DataKeys[row.DataItemIndex - indexPeg].Values[0];
                        if (OnAssignProduct != null)
                        {
                            OnAssignProduct(this, new FindAssignProductEventArgs(productId, link));
                        }
                    }
                }
            }

            PG.DataBind();
        }
        public static bool DeleteAllProducts(ProductFilter filter)
        {
            int totalCount   = ProductDataSource.FindProductsCount(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly);
            int currentIndex = 0;

            while (currentIndex < totalCount)
            {
                IList <Product> currentBatch = ProductDataSource.FindProducts(filter.Name, filter.SearchDescriptions, filter.Sku, filter.CategoryId, filter.ManufacturerId, filter.VendorId, filter.Featured, 0, filter.FromPrice, filter.ToPrice, filter.DigitalGoodsOnly, filter.GiftCertificatesOnly, filter.KitsOnly, filter.SubscriptionsOnly, 100, currentIndex);
                foreach (Product p in currentBatch)
                {
                    p.Delete();
                }
                currentIndex += 100;
            }
            return(true);
        }
        public IList <Product> GetSelectedProducts()
        {
            bool            selectAll = AlwaysConvert.ToBool(SelectAll.Value, false);
            bool            link      = AlwaysConvert.ToBool(GridActions.SelectedValue, false);
            IList <Product> products  = new List <Product>();

            if (selectAll)
            {
                BitFieldState featured   = OnlyFeatured.Checked ? BitFieldState.True : BitFieldState.Any;
                BitFieldState status     = (BitFieldState)Enum.Parse(typeof(BitFieldState), ProductAssignment.SelectedValue);
                int           categoryId = 0;
                if (!_DisplayCategorySearch)
                {
                    categoryId = AlwaysConvert.ToInt(CategoriesList.SelectedValue);
                }
                else
                {
                    categoryId = AlwaysConvert.ToInt(HiddenSelectedCategoryId.Value);
                }
                products = ProductDataSource.FindProducts(Name.Text.Trim(), SearchDescriptions.Checked, Sku.Text.Trim(), categoryId, AlwaysConvert.ToInt(ManufacturerList.SelectedValue), AlwaysConvert.ToInt(VendorList.SelectedValue), featured, AlwaysConvert.ToInt(TaxCodeList.SelectedValue), AlwaysConvert.ToDecimal(FromPrice.Text), AlwaysConvert.ToDecimal(ToPrice.Text), OnlyDigitalGoods.Checked, OnlyGiftCertificates.Checked, OnlyKits.Checked, OnlySubscriptions.Checked, AlwaysConvert.ToInt(ProductGroups.SelectedValue), AssignmentTable, AssignmentValue, status);
            }
            else
            {
                int indexPeg = PG.PageSize * PG.PageIndex;

                foreach (GridViewRow row in PG.Rows)
                {
                    CheckBox selected = (CheckBox)PageHelper.RecursiveFindControl(row, "PID");
                    if ((selected != null) && selected.Checked)
                    {
                        int dataItemIndex = row.DataItemIndex;
                        dataItemIndex = (dataItemIndex - (PG.PageSize * PG.PageIndex));
                        int productId = (int)PG.DataKeys[dataItemIndex].Value;
                        products.Add(ProductDataSource.Load(productId));
                    }
                }
            }

            return(products);
        }