示例#1
0
        public static MvcHtmlString HoneyPotTextArea(this HtmlHelper helper, string name, object value, int cols, int rows, dynamic htmlAttributes, string honeypotCss = null)
        {
            StringBuilder sbControlHtml = new StringBuilder();

            using (StringWriter stringWriter = new StringWriter())
            {
                using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter))
                {
                    HtmlTextArea hashedField = new HtmlTextArea();
                    string       hashedName  = GetHashedPropertyName(name);
                    hashedField.Value = value != null?value.ToString() : string.Empty;

                    hashedField.ID   = hashedName;
                    hashedField.Name = hashedName;
                    hashedField.Cols = cols;
                    hashedField.Rows = rows;
                    if (htmlAttributes != null)
                    {
                        foreach (var property in htmlAttributes.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                        {
                            var attributeName  = property.Name.Replace('_', '-');
                            var attributeValue = property.GetValue(htmlAttributes, null);
                            hashedField.Attributes[attributeName] = attributeValue;
                        }
                    }
                    hashedField.RenderControl(htmlWriter);


                    HtmlTextArea hiddenField = new HtmlTextArea();
                    hiddenField.Value = string.Empty;
                    hiddenField.ID    = name;
                    hiddenField.Name  = name;
                    hiddenField.Rows  = rows;
                    hiddenField.Cols  = cols;
                    if (!string.IsNullOrWhiteSpace(honeypotCss))
                    {
                        hiddenField.Attributes["class"] = honeypotCss;
                    }
                    hiddenField.RenderControl(htmlWriter);
                    sbControlHtml.Append(stringWriter.ToString());
                }
            }
            return(new MvcHtmlString(sbControlHtml.ToString()));
        }
示例#2
0
        public static MvcHtmlString HoneyPotTextArea(this HtmlHelper helper, string name, object value, int cols, int rows, string inputCss = null, string honeypotCss = null)
        {
            StringBuilder sbControlHtml = new StringBuilder();

            using (StringWriter stringWriter = new StringWriter())
            {
                using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter))
                {
                    HtmlTextArea hashedField = new HtmlTextArea();
                    string       hashedName  = GetHashedPropertyName(name);
                    hashedField.Value = value != null?value.ToString() : string.Empty;

                    hashedField.ID   = hashedName;
                    hashedField.Name = hashedName;
                    hashedField.Cols = cols;
                    hashedField.Rows = rows;
                    if (!string.IsNullOrWhiteSpace(inputCss))
                    {
                        hashedField.Attributes["class"] = inputCss;
                    }
                    hashedField.RenderControl(htmlWriter);


                    HtmlTextArea hiddenField = new HtmlTextArea();
                    hiddenField.Value = string.Empty;
                    hiddenField.ID    = name;
                    hiddenField.Name  = name;
                    hiddenField.Rows  = rows;
                    hiddenField.Cols  = cols;
                    if (!string.IsNullOrWhiteSpace(honeypotCss))
                    {
                        hiddenField.Attributes["class"] = honeypotCss;
                    }
                    hiddenField.RenderControl(htmlWriter);
                    sbControlHtml.Append(stringWriter.ToString());
                }
            }
            return(new MvcHtmlString(sbControlHtml.ToString()));
        }
示例#3
0
        private string GeneratePropertyControl(ProductProperty item, string propertyValue)
        {
            using (var sw = new StringWriter())
            {
                using (var writer = new HtmlTextWriter(sw))
                {
                    if (item.TypeCode == ProductPropertyType.CurrencyField)
                    {
                        var input = new HtmlInputText();
                        input.ID = "ProductTypeProperty" + item.Id;
                        if (propertyValue != null)
                        {
                            input.Value = propertyValue;
                        }
                        else
                        {
                            input.Value = item.DefaultValue;
                        }
                        input.RenderControl(writer);
                    }
                    else if (item.TypeCode == ProductPropertyType.DateField)
                    {
                        var input = new HtmlInputText();
                        input.ID = "ProductTypeProperty" + item.Id;
                        if (propertyValue != null)
                        {
                            input.Value = propertyValue;
                        }
                        else
                        {
                            input.Value = item.DefaultValue;
                        }
                        input.RenderControl(writer);
                    }
                    else if (item.TypeCode == ProductPropertyType.HyperLink)
                    {
                        var input = new HtmlInputText();
                        input.ID = "ProductTypeProperty" + item.Id;
                        if (propertyValue != null)
                        {
                            input.Value = propertyValue;
                        }
                        else
                        {
                            input.Value = item.DefaultValue;
                        }
                        input.RenderControl(writer);
                    }
                    else if (item.TypeCode == ProductPropertyType.MultipleChoiceField)
                    {
                        var input = new HtmlSelect();
                        input.ID = "ProductTypeProperty" + item.Id;
                        foreach (var choice in item.Choices)
                        {
                            var li = new ListItem(choice.DisplayName, choice.Id.ToString());
                            input.Items.Add(li);
                        }

                        if (propertyValue != null)
                        {
                            input.Value = propertyValue;
                        }
                        else
                        {
                            input.Value = item.DefaultValue;
                        }
                        input.RenderControl(writer);
                    }
                    else if (item.TypeCode == ProductPropertyType.TextField)
                    {
                        var input = new HtmlTextArea();
                        input.ID = "ProductTypeProperty" + item.Id;
                        var defaultValue = item.IsLocalizable ? item.DefaultLocalizableValue : item.DefaultValue;
                        if (propertyValue != null)
                        {
                            input.Value = propertyValue;
                        }
                        else
                        {
                            input.Value = defaultValue;
                        }
                        input.Rows = 5;
                        input.Cols = 40;
                        input.RenderControl(writer);
                    }
                    else if (item.TypeCode == ProductPropertyType.FileUpload)
                    {
                        //TODO:
                    }

                    writer.Flush();
                    return(sw.ToString());
                }
            }
        }
        protected void GenerateProductTypePropertyFields()
        {
            ProductTypePropertiesLiteral.Text = "";
            if (lstProductType.SelectedValue.Trim() != string.Empty)
            {
                string productTypeBvin       = lstProductType.SelectedValue;
                List <ProductProperty> props = MTApp.CatalogServices.ProductPropertiesFindForType(productTypeBvin);
                StringBuilder          sb    = new StringBuilder();
                int count = 0;
                foreach (ProductProperty item in props)
                {
                    count += 1;
                    StringWriter   sw     = new StringWriter();
                    HtmlTextWriter writer = new HtmlTextWriter(sw);
                    sb.Append("<tr><td class=\"formlabel\">");
                    sb.Append(item.DisplayName);
                    sb.Append("</td><td class=\"formfield\">");
                    if (item.TypeCode == ProductPropertyType.CurrencyField)
                    {
                        HtmlInputText input = new HtmlInputText();
                        input.ID = "ProductTypeProperty" + count.ToString();
                        if (ProductTypeProperties.Count > (count - 1))
                        {
                            if (ProductTypeProperties[count - 1] != null)
                            {
                                input.Value = ProductTypeProperties[count - 1];
                            }
                            else
                            {
                                input.Value = item.DefaultValue;
                            }
                        }
                        else
                        {
                            input.Value = item.DefaultValue;
                        }
                        input.RenderControl(writer);
                        writer.Flush();
                        sb.Append(sw.ToString());
                    }
                    else if (item.TypeCode == ProductPropertyType.DateField)
                    {
                        HtmlInputText input = new HtmlInputText();
                        input.ID = "ProductTypeProperty" + count.ToString();
                        if (ProductTypeProperties.Count > (count - 1))
                        {
                            if (ProductTypeProperties[count - 1] != null)
                            {
                                input.Value = ProductTypeProperties[count - 1];
                            }
                            else
                            {
                                input.Value = item.DefaultValue;
                            }
                        }
                        else
                        {
                            input.Value = item.DefaultValue;
                        }
                        input.RenderControl(writer);
                        writer.Flush();
                        sb.Append(sw.ToString());
                    }
                    else if (item.TypeCode == ProductPropertyType.HyperLink)
                    {
                        HtmlInputText input = new HtmlInputText();
                        input.ID = "ProductTypeProperty" + count.ToString();
                        if (ProductTypeProperties.Count > (count - 1))
                        {
                            if (ProductTypeProperties[count - 1] != null)
                            {
                                input.Value = ProductTypeProperties[count - 1];
                            }
                            else
                            {
                                input.Value = item.DefaultValue;
                            }
                        }
                        else
                        {
                            input.Value = item.DefaultValue;
                        }
                        input.RenderControl(writer);
                        writer.Flush();
                        sb.Append(sw.ToString());
                    }
                    else if (item.TypeCode == ProductPropertyType.MultipleChoiceField)
                    {
                        HtmlSelect input = new HtmlSelect();
                        input.ID = "ProductTypeProperty" + count.ToString();
                        bool setWidth = false;
                        foreach (ProductPropertyChoice choice in item.Choices)
                        {
                            if (choice.ChoiceName.Length > 25)
                            {
                                setWidth = true;
                            }
                            System.Web.UI.WebControls.ListItem li = new System.Web.UI.WebControls.ListItem(choice.ChoiceName, choice.Id.ToString());
                            input.Items.Add(li);
                        }
                        if (setWidth)
                        {
                            input.Style.Add("width", "305px");
                        }

                        if (ProductTypeProperties.Count > (count - 1))
                        {
                            if (ProductTypeProperties[count - 1] != null)
                            {
                                input.Value = ProductTypeProperties[count - 1];
                            }
                            else
                            {
                                input.Value = item.DefaultValue;
                            }
                        }
                        else
                        {
                            input.Value = item.DefaultValue;
                        }
                        input.RenderControl(writer);
                        writer.Flush();
                        sb.Append(sw.ToString());
                    }
                    else if (item.TypeCode == ProductPropertyType.TextField)
                    {
                        HtmlTextArea input = new HtmlTextArea();
                        input.ID = "ProductTypeProperty" + count.ToString();
                        if (ProductTypeProperties.Count > (count - 1))
                        {
                            if (ProductTypeProperties[count - 1] != null)
                            {
                                input.Value = ProductTypeProperties[count - 1];
                            }
                            else
                            {
                                input.Value = item.DefaultValue;
                            }
                        }
                        else
                        {
                            input.Value = item.DefaultValue;
                        }
                        input.Rows = 5;
                        input.Cols = 40;
                        input.RenderControl(writer);
                        writer.Flush();
                        sb.Append(sw.ToString());
                    }
                    sb.Append("</td></tr>");
                    ProductTypePropertiesLiteral.Text = sb.ToString();
                }
            }
        }