예제 #1
0
    private List<ItemAttributeValue> form2obj(ProductItem obj)
    {
        obj.Id = CurrentId;
        obj.Enabled = ChkEnabled.Checked;
        obj.TitleTranslations.Clear();
        obj.DescriptionTranslations.Clear();
        obj.CategoryId = int.Parse(DropCategories.SelectedValue);
        obj.Alias = TxtAlias.Text;
        obj.CssClass = TxtCssClass.Text;
        obj.ItemDate = this.ItemDate;
        obj.ValidFrom = this.ValidFrom;
        obj.ValidTo = this.ValidTo;

        // product fields

        // Product Type
        int type = 0;
        int.TryParse(DropNew.SelectedValue, out type);
        if (type > 0)
        {
            obj.ProductType = (ProductItem.ProductTypeEnum)type;
        }
        // Attribute Set
        int attributeSetId = 0;
        int.TryParse(DropSets.SelectedValue, out attributeSetId);

        obj.AttributeSet = attributeSetId;

        // Draft
        obj.IsDraft = false;
        // SKU
        obj.SKU = TxtSKU.Text;
        // Regular Price
        decimal regPrice = 0m;
        decimal.TryParse(TxtRegularPrice.Text, out regPrice);
        if (regPrice > 0)
            obj.RegularPrice = regPrice;
        // Sale Price
        decimal salePrice = 0m;
        decimal.TryParse(TxtSalePrice.Text, out salePrice);
        if(salePrice > 0)
            obj.SalePrice = salePrice;
        // Weight
        decimal weight = 0m;
        decimal.TryParse(TxtWeight.Text, out weight);
        if(weight > 0)
            obj.Weight = weight;
        // Qty
        int qty = 0;
        int.TryParse(TxtQty.Text, out qty);
        if (weight > 0)
            obj.Availability = qty;
        // Stock
        int inStock = 0;
        int.TryParse(DropStock.SelectedValue, out inStock);
        if (inStock > 0)
            obj.InStock = (inStock == 1) ? true : false;

        if (CurrentId == 0)
            obj.ItemTypeName = LitItemType.Text;

        foreach (KeyValuePair<string, string> item in Config.CultureList)
        {
            TextBox t1 = new TextBox();
            t1 = (TextBox)PanelTitle.FindControl("TxtTitle" + item.Value);
            obj.TitleTranslations.Add(item.Key, t1.Text);

            var txt2 = new Controls_ContentEditorControl();
            txt2 = Utility.FindControlRecursive<Controls_ContentEditorControl>(this, "TxtDescription" + item.Value);
            obj.DescriptionTranslations.Add(item.Key, txt2.Text);
        }

        foreach(GridViewRow r in GridViewSimple.Rows)
        {
            CheckBox cb = (CheckBox)r.FindControl("chkRow");
            string IdString = r.Cells[5].Text;

            int Id = 0;
            int.TryParse(IdString, out Id);
            var p = new ProductItemsManager().GetByKey(Id);

            if (cb.Checked)
            {
                p.ThreadId = CurrentId;
            }
            else
            {
                if (p.ThreadId == CurrentId )
                    p.ThreadId = p.Id;
            }

            try
            {
                new ProductItemsManager().Update(p);
            }
            catch (Exception e1)
            {
                LblErr.Text = RenderError(Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString());
            }

        }

        foreach (GridViewRow r in GridRelated.Rows)
        {
            CheckBox cb = (CheckBox)r.FindControl("chkRow");
            string IdString = r.Cells[5].Text;
            int Id = 0;
            int.TryParse(IdString, out Id);
            var p = new ProductItemsManager().GetByKey(Id);

            if (cb.Checked)
            {
                try
                {
                    new ProductItemsManager().SetRelated(CurrentId, p.Id);
                }
                catch (Exception e1)
                {
                    LblErr.Text = RenderError(Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString());
                }
            }
            else
            {
                try
                {
                    new ProductItemsManager().DeleteRelated(CurrentId, p.Id);
                }
                catch (Exception e1)
                {
                    LblErr.Text = RenderError(Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString());
                }
            }

        }

        var atts = new List<ItemAttributeValue>();

        // Store ItemAttributeValues

        var set = sman.GetByKey(attributeSetId);

        attributes.Clear();

        foreach (var attributeId in set.AttributesList)
        {
            var attribute = aman.GetByKey(attributeId);
            attributes.Add(attribute);
        }

        foreach (var attribute in attributes)
        {
            if (!attribute.AllowCustomValue)
            {
                DropDownList d1 = new DropDownList();
                d1 = (DropDownList)PanelAttributes.FindControl("DropAttributeValues" + attribute.Name);
                int attributeValueId = 0;
                int.TryParse(d1.SelectedValue, out attributeValueId);
                var record = new ItemAttributeValue();
                record.AttributeId = attribute.Id;
                record.AttributeValueId = attributeValueId;
                record.ItemId = CurrentId;
                atts.Add(record);
            }
            else
            {
                TextBox t1 = new TextBox();
                t1 = (TextBox)QuickAttributes.FindControl("TxtCustomField" + attribute.Name);

                var record = new ItemAttributeValue();
                record.AttributeId = attribute.Id;
                record.AttributeValueId = 0;
                record.CustomValueString = t1.Text;
                record.ItemId = CurrentId;
                atts.Add(record);

            }
        }

        obj.ItemParams = FormBuilder.GetParamsString(obj.ItemType.Params, ItemParams1);
        string fieldsString = FormBuilder.GetParamsString(obj.ItemType.Fields, ItemFields1);
        obj.LoadCustomFieldsFromString(fieldsString);
        PermissionsControl1.Form2obj(obj);

        return atts;
    }
예제 #2
0
    private List<ItemAttributeValue> quickform2obj(ProductItem obj)
    {
        int enabled = 0;
        int.TryParse(DropEnabled.SelectedValue, out enabled);
        obj.Enabled = (enabled == 1) ? true : false;
        obj.TitleTranslations.Clear();
        obj.DescriptionTranslations.Clear();
        obj.CategoryId = int.Parse(DropCategories.SelectedValue);
        obj.ThreadId = CurrentId;
        obj.ItemDate = this.ItemDate;
        obj.ValidFrom = this.ValidFrom;
        obj.ValidTo = this.ValidTo;

        // product fields
        obj.ProductType = ProductItem.ProductTypeEnum.Simple;
        int set = 0;
        int.TryParse(DropSets.SelectedValue, out set);
        obj.AttributeSet = set;
        obj.IsDraft = false;
        obj.SKU = QuickTxtSKU.Text;
        decimal regPrice = 0m;
        decimal.TryParse(QuickTxtRegularPrice.Text, out regPrice);
        obj.RegularPrice = regPrice;
        decimal salePrice = 0m;
        decimal.TryParse(QuickTxtSalePrice.Text, out salePrice);
        obj.SalePrice = salePrice;
        decimal weight = 0m;
        decimal.TryParse(QuickTxtWeight.Text, out weight);
        obj.Weight = weight;
        int qty = 0;
        int.TryParse(QuickTxtQty.Text, out qty);
        obj.Availability = qty;
        int inStock = 0;
        int.TryParse(QuickDropStock.SelectedValue, out inStock);
        obj.InStock = (inStock == 1) ? true : false;

        var atts = new List<ItemAttributeValue>();

        // QUI raccolo i quick attributevalue da salvare

        string endofname = "";
        foreach (var attribute in attributes)
        {
            if (!attribute.AllowCustomValue)
            {
                DropDownList d1 = new DropDownList();
                d1 = (DropDownList)QuickAttributes.FindControl("DropAttributeValuesQuick" + attribute.Name);
                int attributeValueId = 0;
                int.TryParse(d1.SelectedValue, out attributeValueId);
                if (attributeValueId > 0)
                {
                    endofname += "-" + d1.SelectedItem.Text;
                    var record = new ItemAttributeValue();
                    record.AttributeId = attribute.Id;
                    record.AttributeValueId = attributeValueId;
                    atts.Add(record);
                }
            }
            else
            {
                TextBox t1 = new TextBox();
                t1 = (TextBox)QuickAttributes.FindControl("TxtCustomFieldQuick" + attribute.Name);
                var record = new ItemAttributeValue();
                record.AttributeId = attribute.Id;
                record.AttributeValueId = 0;
                record.CustomValueString = t1.Text;
                atts.Add(record);
            }
        }

        foreach (KeyValuePair<string, string> item in Config.CultureList)
        {
            TextBox t1 = new TextBox();
            t1 = (TextBox)PanelTitle.FindControl("TxtTitle" + item.Value);
            obj.TitleTranslations.Add(item.Key, t1.Text + endofname);
        }
        obj.Alias = TxtAlias.Text + endofname.ToLower();

        obj.ItemParams = FormBuilder.GetParamsString(obj.ItemType.Params, ItemParams1);
        string fieldsString = FormBuilder.GetParamsString(obj.ItemType.Fields, ItemFields1);
        obj.LoadCustomFieldsFromString(fieldsString);
        PermissionsControl1.Form2obj(obj);

        return atts;
    }