protected void SearchResultsGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Attach"))
            {
                EnsureKit();
                int          index          = AlwaysConvert.ToInt(e.CommandArgument);
                int          kitComponentId = (int)SearchResultsGrid.DataKeys[index].Value;
                KitComponent kitComponent   = KitComponentDataSource.Load(kitComponentId);
                if (kitComponent != null)
                {
                    _Product.ProductKitComponents.Add(new ProductKitComponent(_Product, kitComponent));
                    _Product.Save();
                    CancelButton_Click(sender, e);
                }
            }
            else if (e.CommandName.Equals("Copy"))
            {
                EnsureKit();
                int          index          = AlwaysConvert.ToInt(e.CommandArgument);
                int          kitComponentId = (int)SearchResultsGrid.DataKeys[index].Value;
                KitComponent kitComponent   = KitComponentDataSource.Load(kitComponentId);
                if (kitComponent != null)
                {
                    // copy the component
                    KitComponent branchedComponent = kitComponent.Copy(true);
                    branchedComponent.Name = "Copy of " + kitComponent.Name;
                    branchedComponent.Save();

                    // attach to the product
                    _Product.ProductKitComponents.Add(new ProductKitComponent(_Product, branchedComponent));
                    _Product.Save();
                    CancelButton_Click(sender, e);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int     productId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
            Product product   = ProductDataSource.Load(productId);

            if (product == null)
            {
                Response.Redirect("../../Catalog/Browse.aspx?CategoryId=" + AbleCommerce.Code.PageHelper.GetCategoryId());
            }
            Caption.Text = string.Format(Caption.Text, product.Name);

            // build list of kits
            List <KitMemberInfo> kitMemberships = new List <KitMemberInfo>();
            IList <KitComponent> components     = KitComponentDataSource.LoadForMemberProduct(productId);

            foreach (KitComponent component in components)
            {
                foreach (ProductKitComponent pkc in component.ProductKitComponents)
                {
                    kitMemberships.Add(new KitMemberInfo(pkc.ProductId, pkc.Product.Name, component.Name));
                }
            }
            kitMemberships.Sort(new KitMemberInfoComparer());
            KitMembershipList.DataSource = kitMemberships;
            KitMembershipList.DataBind();
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            //INITIALIZE VARIABLES
            _CategoryId = AbleCommerce.Code.PageHelper.GetCategoryId();
            _Category   = CategoryDataSource.Load(_CategoryId);
            _ProductId  = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
            _Product    = ProductDataSource.Load(_ProductId);
            if (_Product == null)
            {
                Response.Redirect(AbleCommerce.Code.NavigationHelper.GetAdminUrl("Catalog/Browse.aspx?CategoryId=" + _CategoryId.ToString()));
            }
            _KitComponentId = AlwaysConvert.ToInt(Request.QueryString["KitComponentId"]);
            _KitComponent   = KitComponentDataSource.Load(_KitComponentId);
            if (_KitComponent == null)
            {
                Response.Redirect("EditKit.aspx?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString());
            }
            CancelLink.NavigateUrl += "?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString();
            Caption.Text            = string.Format(Caption.Text, _KitComponent.Name);
            InstructionText.Text    = string.Format(InstructionText.Text, _KitComponent.Name, _Product.Name);

            int categoryCount             = CategoryDataSource.CountAll();
            StoreSettingsManager settings = AbleContext.Current.Store.Settings;

            _DisplayCategorySearch = settings.CategorySearchDisplayLimit > 0 && categoryCount >= settings.CategorySearchDisplayLimit;

            // INITIALIZE DROP DOWN LISTS
            if (!_DisplayCategorySearch)
            {
                InitializeCategoryTree();
            }
            else
            {
                // DISPLAY AUTO COMPLETE FOR CATEGORY SEARCH OPTION
                string js = PageHelper.GetAutoCompleteScript(Page.ResolveClientUrl("~/CategorySuggest.ashx"), CategoryAutoComplete, HiddenSelectedCategoryId, "Key", "Value");

                ScriptManager.RegisterStartupScript(PageAjax, this.GetType(), "CATEGORY_SUGGEST", js, true);
                CategoryAutoComplete.Visible = true;
                CategoryFilter.Visible       = false;
            }
            ManufacturerFilter.DataSource = ManufacturerDataSource.LoadAll("Name");
            ManufacturerFilter.DataBind();
            VendorFilter.DataSource = VendorDataSource.LoadAll("Name");
            VendorFilter.DataBind();

            // LOAD CUSTOM VIEWSTATE VARIABLES
            LoadCustomViewState();
            if (_SelectedProducts.Count > 0)
            {
                // REBIND THE REPEATER
                BindSelectedProducts(_SelectedProducts);
            }

            AbleCommerce.Code.PageHelper.SetDefaultButton(NameFilter, SearchButton.ClientID);
            AbleCommerce.Code.PageHelper.SetDefaultButton(SkuFilter, SearchButton.ClientID);
        }
Esempio n. 4
0
        protected void ComponentList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int          kitComponentId = AlwaysConvert.ToInt(e.CommandArgument);
            KitComponent kitComponent   = KitComponentDataSource.Load(kitComponentId);

            if (kitComponent != null)
            {
                switch (e.CommandName)
                {
                case "Branch":
                    // locate the product relationship
                    ProductKitComponent pkc = _Product.ProductKitComponents.FirstOrDefault(x => x.KitComponentId == kitComponent.Id);
                    if (pkc != null)
                    {
                        // create a copy of the component
                        KitComponent branchedComponent = kitComponent.Copy(true);
                        branchedComponent.Save();

                        // update the product relationship
                        _Product.ProductKitComponents.Add(new ProductKitComponent(_Product, branchedComponent, pkc.OrderBy));
                        _Product.ProductKitComponents.DeleteAt(_Product.ProductKitComponents.IndexOf(pkc));
                        _Product.Save();
                    }
                    break;

                case "Delete":
                    AbleContext.Current.Database.BeginTransaction();
                    ProductKitComponent matchingComponent = _Product.ProductKitComponents.FirstOrDefault(x => x.KitComponentId == kitComponentId);
                    if (matchingComponent != null)
                    {
                        int index = _Product.ProductKitComponents.IndexOf(matchingComponent);
                        if (index > -1)
                        {
                            _Product.ProductKitComponents.RemoveAt(index);
                            _Product.Save();
                        }
                    }
                    kitComponent.Delete();

                    // DELETE THE KIT RECORD IF NO COMPONENTS REMAINING
                    if (_Product.ProductKitComponents.Count == 0)
                    {
                        Kit kit = _Product.Kit;
                        _Product.Kit = null;
                        _Product.Save();
                        kit.Delete();
                    }
                    AbleContext.Current.Database.CommitTransaction();
                    ComponentList.DataBind();
                    break;
                }
            }
        }
 protected void Page_Init(object sender, EventArgs e)
 {
     //INITIALIZE VARIABLES
     _CategoryId = AbleCommerce.Code.PageHelper.GetCategoryId();
     _Category = CategoryDataSource.Load(_CategoryId);
     _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
     _Product = ProductDataSource.Load(_ProductId);
     if (_Product == null) Response.Redirect(AbleCommerce.Code.NavigationHelper.GetAdminUrl("Catalog/Browse.aspx"));
     _KitComponentId = AlwaysConvert.ToInt(Request.QueryString["KitComponentId"]);
     _KitComponent = KitComponentDataSource.Load(_KitComponentId);
     if (_KitComponent == null) Response.Redirect("EditKit.aspx?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString());
     //INITIALIZE PAGE ELEMENTS
     Caption.Text = string.Format(Caption.Text, _KitComponent.Name);
     BindKitList();
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     _CategoryId = AbleCommerce.Code.PageHelper.GetCategoryId();
     _Category   = CategoryDataSource.Load(_CategoryId);
     _ProductId  = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
     _Product    = ProductDataSource.Load(_ProductId);
     if (_Product == null)
     {
         Response.Redirect(AbleCommerce.Code.NavigationHelper.GetAdminUrl("Catalog/Browse.aspx"));
     }
     _KitComponentId = AlwaysConvert.ToInt(Request.QueryString["KitComponentId"]);
     _KitComponent   = KitComponentDataSource.Load(_KitComponentId);
     if (_KitComponent == null)
     {
         Response.Redirect("Default.aspx?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString());
     }
     Caption.Text = string.Format(Caption.Text, _KitComponent.Name);
     if (!Page.IsPostBack)
     {
         KitParts.DataSource = _KitComponent.KitProducts;
         KitParts.DataBind();
     }
 }