コード例 #1
0
        protected void AddComponentSaveButton_Click(object sender, EventArgs e)
        {
            if (_Kit == null)
            {
                // WE MUST HAVE KIT TO HAVE KIT COMPONENTS
                _Kit = new Kit(_Product, false);
                _Kit.Save();
            }

            // CREATE THE KIT COMPONENT
            KitComponent component = new KitComponent();

            component.Name        = AddComponentName.Text;
            component.InputTypeId = (short)(AddComponentInputTypeId.SelectedIndex);
            //component.HeaderOption = HeaderOption.Text;
            component.Save();

            // ASSOCIATE KIT COMPONENT TO THE PRODUCT
            _Product.ProductKitComponents.Add(new ProductKitComponent(_Product, component));
            _Product.Save();

            // RESET THE ADD COMPONENT DIALOG
            AddComponentName.Text = string.Empty;
            AddComponentInputTypeId.SelectedIndex = 1;
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
 protected void SaveButton_Click(object sender, EventArgs e)
 {
     //CREATE THE KIT COMPONENT
     KitComponent.Name         = Name.Text;
     KitComponent.InputTypeId  = (short)(InputTypeId.SelectedIndex);
     KitComponent.HeaderOption = HeaderOption.Text;
     KitComponent.Save();
     Response.Redirect(string.Format("EditKit.aspx?CategoryId={0}&ProductId={1}", this.CategoryId, this.ProductId));
 }
コード例 #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;
                }
            }
        }