protected void btnAddAttribute_Click(object sender, EventArgs e)
    {
        Commerce.Common.Attribute att = new Commerce.Common.Attribute();
        att.Name          = txtAttributeNew.Text.Trim();
        att.Description   = txtAttNewDesc.Text.Trim();
        att.SelectionType = (AttributeType)int.Parse(ddlAttNewSelectionType.SelectedValue);

        //get the selections from the viewstate
        ArrayList aList = GetSelections();

        att.Selections = new System.Collections.Generic.List <AttributeSelection>();

        if (att.SelectionType != AttributeType.UserInput)
        {
            for (int i = 0; i < aList.Count; i++)
            {
                att.Selections.Add((AttributeSelection)aList[i]);
            }
        }
        else
        {
            AttributeSelection sel = new AttributeSelection();
            sel.Value           = "";
            sel.PriceAdjustment = 0;
            att.Selections.Add(sel);
        }


        //a product can have one or more attribute selections
        //like "size" and "color"
        //store these into the viewstate as they are saved
        //and synch them with the product bits as well
        Commerce.Common.Attributes atts = null;
        if (ViewState["atts"] == null)
        {
            atts = new Attributes();
        }
        else
        {
            atts = (Attributes)ViewState["atts"];
        }
        atts.Add(att);


        //put it back the ViewState
        ViewState["atts"] = atts;

        //and set it to the product, which will serialize it down
        //to XML
        ProductController.UpdateProductAttributes(int.Parse(lblID.Text), atts);
        //bind up the grid
        BindAttList(atts);
    }
    protected void btnSetTemplate_Click(object sender, EventArgs e)
    {
        string            sTemplate = ddlAttTemplates.SelectedValue;
        AttributeTemplate template  = new AttributeTemplate(int.Parse(sTemplate));

        txtAttributeNew.Text = template.AttributeName;
        txtAttNewDesc.Text   = template.Description;
        ddlAttNewSelectionType.SelectedValue = template.AttributeTypeID.ToString();
        Commerce.Common.Attributes attributes =
            (Attributes)Utility.XmlToObject(typeof(Attributes), template.SelectionList);
        ArrayList aList = new ArrayList();

        foreach (AttributeSelection selection in attributes[0].Selections)
        {
            aList.Add(selection);
        }
        BindSells(aList);
        ViewState["aList"] = aList;
    }
Exemple #3
0
 /// <summary>
 /// Updates the XML attributes for a given product
 /// </summary>
 /// <param name="productID"></param>
 /// <param name="atts"></param>
 public static void UpdateProductAttributes(int productID, Commerce.Common.Attributes atts)
 {
     Commerce.Common.Product prod = new Commerce.Common.Product(productID);
     prod.Attributes = atts;
     prod.Save(Utility.GetUserName());
 }
    void LoadControls()
    {
        HtmlTable tbl = new HtmlTable();

        tbl.ID = "tblAtts";
        HtmlTableRow  tr;
        HtmlTableCell td;
        int           indexer = 0;

        if (product.Attributes != null)
        {
            selectedAttributes = new Attributes();
            foreach (Commerce.Common.Attribute att in product.Attributes)
            {
                tr = new HtmlTableRow();
                td = new HtmlTableCell();

                Label lblSingle = new Label();
                lblSingle.Text = "<br><b>" + att.Name + ":</b>";
                if (att.Description != string.Empty)
                {
                    lblSingle.Text += "<br><span class=smalltext>" + att.Description + "</span><br>";
                }
                lblSingle.ID = "lbl" + att.Name + indexer.ToString();
                td.Controls.Add(lblSingle);
                indexer++;
                switch (att.SelectionType)
                {
                case AttributeType.SingleSelection:
                    lblSingle.Text += "&nbsp;";
                    DropDownList ddl = new DropDownList();
                    ddl.ID             = att.Name;
                    ddl.DataSource     = att.Selections;
                    ddl.DataTextField  = "FormattedValue";
                    ddl.DataValueField = "Value";
                    ddl.DataBind();
                    ddl.SelectedIndex = 0;
                    td.Controls.Add(ddl);

                    break;

                case AttributeType.MultipleSelection:
                    lblSingle.Text += "<br>";
                    CheckBoxList chkList = new CheckBoxList();
                    chkList.ID             = att.Name;
                    chkList.DataSource     = att.Selections;
                    chkList.DataTextField  = "Value";
                    chkList.DataValueField = "Value";
                    chkList.DataBind();
                    td.Controls.Add(chkList);
                    break;

                case AttributeType.UserInput:
                    lblSingle.Text += "<br>";
                    TextBox t = new TextBox();
                    t.ID       = att.Name;
                    t.TextMode = TextBoxMode.MultiLine;
                    t.Height   = Unit.Pixel(80);
                    t.Width    = Unit.Pixel(120);
                    td.Controls.Add(t);

                    break;
                }
                tr.Cells.Add(td);
                tbl.Rows.Add(tr);
            }
            pnlAttControls.Controls.Add(tbl);
        }
    }