Exemple #1
0
        public static ProductTemplateField Load(Int32 productTemplateFieldId, bool useCache)
        {
            if (productTemplateFieldId == 0)
            {
                return(null);
            }
            ProductTemplateField productTemplateField = null;
            string key = "ProductTemplateField_" + productTemplateFieldId.ToString();

            if (useCache)
            {
                productTemplateField = ContextCache.GetObject(key) as ProductTemplateField;
                if (productTemplateField != null)
                {
                    return(productTemplateField);
                }
            }
            productTemplateField = new ProductTemplateField();
            if (productTemplateField.Load(productTemplateFieldId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, productTemplateField);
                }
                return(productTemplateField);
            }
            return(null);
        }
        public static void CollectProductTemplateInput(Product product, Control container)
        {
            foreach (ProductTemplate template in product.ProductTemplates)
            {
                // COLLECT ANY ADDITIONAL INPUTS
                foreach (InputField input in template.InputFields)
                {
                    //LOOK FOR MERCHANT INPUT FIELDS
                    if (input.IsMerchantField)
                    {
                        //SEE IF WE CAN LOCATE THE CONTROL
                        WebControl inputControl = (WebControl)AbleCommerce.Code.PageHelper.RecursiveFindControl(container, input.UniqueId);
                        if (inputControl != null)
                        {
                            ProductTemplateField itemInput = (from tf in product.TemplateFields where tf.InputField.Id == input.Id select tf).SingleOrDefault <ProductTemplateField>();
                            if (itemInput == null)
                            {
                                itemInput = new ProductTemplateField();
                            }
                            itemInput.Product    = product;
                            itemInput.InputField = input;
                            itemInput.InputValue = input.GetControlValue(inputControl);

                            if (itemInput.IsTransient())
                            {
                                product.TemplateFields.Add(itemInput);
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        public static bool Delete(Int32 productTemplateFieldId)
        {
            ProductTemplateField productTemplateField = new ProductTemplateField();

            if (productTemplateField.Load(productTemplateFieldId))
            {
                return(productTemplateField.Delete());
            }
            return(false);
        }
Exemple #4
0
        public static ProductTemplateFieldCollection LoadForProduct(Int32 productId, int maximumRows, int startRowIndex, string sortExpression)
        {
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + ProductTemplateField.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_ProductTemplateFields");
            selectQuery.Append(" WHERE ProductId = @productId");
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@productId", System.Data.DbType.Int32, productId);
            //EXECUTE THE COMMAND
            ProductTemplateFieldCollection results = new ProductTemplateFieldCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        ProductTemplateField productTemplateField = new ProductTemplateField();
                        ProductTemplateField.LoadDataReader(productTemplateField, dr);
                        results.Add(productTemplateField);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
Exemple #5
0
        protected void BuildProductChoices()
        {
            if (_Product.ProductTemplates.Count > 0)
            {
                foreach (ProductTemplate template in _Product.ProductTemplates)
                {
                    StringBuilder customerFields = new StringBuilder();
                    // SHOW THE SECTION HEADER
                    phCustomFields.Controls.Add(new LiteralControl("<div class=\"sectionHeader\">" + template.Name + "</div>"));
                    phCustomFields.Controls.Add(new LiteralControl("<table cellspacing=\"0\" class=\"inputForm\">"));
                    foreach (InputField input in template.InputFields)
                    {
                        if (input.IsMerchantField)
                        {
                            // CHECK IF IT IS A TEXT AREA FIELD
                            ImageButton          htmlButton = null;
                            string               tempValue  = string.Empty;
                            ProductTemplateField cf         = FindTemplateField(input.Id);
                            if (cf != null)
                            {
                                tempValue = cf.InputValue;
                            }
                            WebControl o = input.GetControl(tempValue);
                            if (o != null)
                            {
                                // SHOW HTML EDITOR FOR TEXT AREA
                                TextBox textBox = o as TextBox;
                                if (textBox != null && textBox.TextMode == TextBoxMode.MultiLine)
                                {
                                    htmlButton        = new ImageButton();
                                    htmlButton.SkinID = "HtmlIcon";
                                }
                            }

                            // OPEN THE ROW
                            phCustomFields.Controls.Add(new LiteralControl("<tr>"));
                            // CREATE A LABEL FOR THE CHOICE
                            phCustomFields.Controls.Add(new LiteralControl("<th class=\"rowHeader\" valign=\"top\">" + input.UserPrompt));
                            if (htmlButton != null)
                            {
                                phCustomFields.Controls.Add(new LiteralControl("<br/>"));
                                phCustomFields.Controls.Add(htmlButton);
                            }
                            phCustomFields.Controls.Add(new LiteralControl("</th>"));
                            // ADD THE CONTROL TO THE PLACEHOLDER
                            phCustomFields.Controls.Add(new LiteralControl("<td valign=\"top\">"));

                            if (o != null)
                            {
                                phCustomFields.Controls.Add(o);
                            }
                            phCustomFields.Controls.Add(new LiteralControl("</td></tr>"));

                            // BIND THE HTML EDITOR
                            if (htmlButton != null)
                            {
                                AbleCommerce.Code.PageHelper.SetHtmlEditor(o as TextBox, htmlButton);
                            }
                        }
                        else
                        {
                            // DISPLAY INFO ABOUT THE CUSTOMER FIELD
                            customerFields.Append("<tr>");
                            customerFields.Append("<th class=\"rowHeader\">" + input.UserPrompt + "</th>");
                            customerFields.Append("<td>");
                            customerFields.Append("<i>Customer Field, " + StringHelper.SpaceName(input.InputType.ToString()) + "</i>");
                            customerFields.Append("</td></tr>");
                        }
                    }
                    if (customerFields.Length > 0)
                    {
                        phCustomFields.Controls.Add(new LiteralControl(customerFields.ToString()));
                    }
                    phCustomFields.Controls.Add(new LiteralControl("</table><br />"));
                }
            }
            else
            {
                phCustomFields.Controls.Clear();
            }
        }
Exemple #6
0
 public static SaveResult Insert(ProductTemplateField productTemplateField)
 {
     return(productTemplateField.Save());
 }
Exemple #7
0
 public static bool Delete(ProductTemplateField productTemplateField)
 {
     return(productTemplateField.Delete());
 }