Ejemplo n.º 1
0
        public void SetValue(HtmlControl ctrl, string v)
        {
            switch (ctrl.GetType().Name)
            {
            case "HtmlInputHidden":
            case "HtmlInputText":
            case "HtmlInputPassword":
            case "BoundedHiddenElement":
            case "BoundedTextField":
            case "HtmlInputGenericControl":
                HtmlInputControl _input = ctrl as HtmlInputControl;
                _input.Value = v;
                break;

            case "HtmlTextArea":
            case "BoundedRichTextEditor":
            case "BoundedTextArea":
                HtmlTextArea textArea = ctrl as HtmlTextArea;
                textArea.Value = v;
                break;

            case "HtmlSelect":
            case "BoundedSelectList":
                HtmlSelect select = ctrl as HtmlSelect;
                select.Value = v;
                break;

            case "HtmlInputCheckBox":
            case "BoundedCheckbox":
                HtmlInputCheckBox checkbox = ctrl as HtmlInputCheckBox;
                checkbox.Checked = !string.IsNullOrWhiteSpace(v) && (checkbox.Value == v || v == "on");
                break;

            case "HtmlInputRadioButton":
                HtmlInputRadioButton radio = ctrl as HtmlInputRadioButton;
                Regex r = new Regex(":[a-z_0-9]*$", RegexOptions.IgnoreCase);
                v             = Request.Get(radio.Name);
                radio.Checked = radio.Value == v;
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Will get the value of any HtmlControl within the form
        /// </summary>
        /// <param name="ctrl">Any HtmlControl <seealso cref="HtmlControl"/></param>
        /// <returns></returns>
        public string GetValue(HtmlControl ctrl)
        {
            switch (ctrl.GetType().Name)
            {
            case "HtmlInputHidden":
            case "HtmlInputText":
            case "HtmlInputPassword":
            case "BoundedHiddenElement":
            case "BoundedTextField":
            case "HtmlInputGenericControl":
                HtmlInputControl _input = ctrl as HtmlInputControl;
                return(Request.Get(_input.ID));

            case "HtmlTextArea":
            case "BoundedRichTextEditor":
            case "BoundedTextArea":
                HtmlTextArea textArea = ctrl as HtmlTextArea;
                return(Request.Get(textArea.ID));

            case "HtmlSelect":
            case "BoundedSelectList":
                HtmlSelect select = ctrl as HtmlSelect;
                return(Request.Get(select.ID));

            case "HtmlInputCheckBox":
            case "BoundedCheckbox":
                HtmlInputCheckBox checkbox = ctrl as HtmlInputCheckBox;
                return(!String.IsNullOrEmpty(Request.Get(checkbox.ID)) ?
                       Request.Get(checkbox.ID) :
                       "");

            case "HtmlInputRadioButton":
                HtmlInputRadioButton radio = ctrl as HtmlInputRadioButton;
                return(Request.Get(radio.Attributes["name"]));

            default:
                return("");
            }
        }
        private static IEnhancedHtmlControl WrapUtil(HtmlControl control)
        {
            IEnhancedHtmlControl con = null;

            if (control.GetType() == typeof(HtmlButton))
            {
                con = new EnhancedHtmlButton();
            }
            else if (control.GetType() == typeof(HtmlCheckBox))
            {
                con = new EnhancedHtmlCheckBox();
            }
            else if (control.GetType() == typeof(HtmlComboBox))
            {
                con = new EnhancedHtmlComboBox();
            }
            else if (control.GetType() == typeof(HtmlDiv))
            {
                con = new EnhancedHtmlDiv();
            }
            else if (control.GetType() == typeof(HtmlEdit) && (string.Compare(control.Type, "password", true) == 0))
            {
                con = new EnhancedHtmlPassword();
            }
            else if (control.GetType() == typeof(HtmlEdit))
            {
                con = new EnhancedHtmlEdit();
            }
            else if (control.GetType() == typeof(HtmlEditableDiv))
            {
                con = new EnhancedHtmlEditableDiv();
            }
            else if (control.GetType() == typeof(HtmlFileInput))
            {
                con = new EnhancedHtmlFileInput();
            }
            else if (control.GetType() == typeof(HtmlHyperlink))
            {
                con = new EnhancedHtmlHyperlink();
            }
            else if (control.GetType() == typeof(HtmlImage))
            {
                con = new EnhancedHtmlImage();
            }
            else if (control.GetType() == typeof(HtmlInputButton))
            {
                con = new EnhancedHtmlInputButton();
            }
            else if (control.GetType() == typeof(HtmlLabel))
            {
                con = new EnhancedHtmlLabel();
            }
            else if (control.GetType() == typeof(HtmlList))
            {
                con = new EnhancedHtmlList();
            }
            else if (control.GetType() == typeof(HtmlListItem))
            {
                con = new EnhancedHtmlListItem();
            }
            else if (control.GetType() == typeof(HtmlRadioButton))
            {
                con = new EnhancedHtmlRadioButton();
            }
            else if (control.GetType() == typeof(HtmlSpan))
            {
                con = new EnhancedHtmlSpan();
            }
            else if (control.GetType() == typeof(HtmlEditableSpan))
            {
                con = new EnhancedHtmlEditableSpan();
            }
            else if (control.GetType() == typeof(HtmlTable))
            {
                con = new EnhancedHtmlTable();
            }
            else if (control.GetType() == typeof(HtmlCell))
            {
                con = new EnhancedHtmlCell();
            }
            else if (control.GetType() == typeof(HtmlTextArea))
            {
                con = new EnhancedHtmlTextArea();
            }
            else if (control.GetType() == typeof(HtmlScrollBar))
            {
                con = new EnhancedHtmlScrollBar();
            }
            else if (control.GetType() == typeof(HtmlTextArea))
            {
                con = new EnhancedHtmlTextArea();
            }
            else if (control.GetType() == typeof(HtmlCustom))
            {
                switch (control.TagName.ToLower())
                {
                case "p":
                    con = new EnhancedHtmlParagraph();
                    break;

                case "h1":
                    con = new EnhancedHtmlHeading1();
                    break;

                case "h2":
                    con = new EnhancedHtmlHeading2();
                    break;

                case "h3":
                    con = new EnhancedHtmlHeading3();
                    break;

                case "h4":
                    con = new EnhancedHtmlHeading4();
                    break;

                case "h5":
                    con = new EnhancedHtmlHeading5();
                    break;

                case "h6":
                    con = new EnhancedHtmlHeading6();
                    break;

                case "ul":
                    con = new EnhancedHtmlUnorderedList();
                    break;

                case "ol":
                    con = new EnhancedHtmlOrderedList();
                    break;

                case "ins":
                    con = new EnhancedHtmlIns();
                    break;

                default:
                    con = new EnhancedHtmlCustom(control.TagName);
                    break;
                }
            }
            else
            {
                throw new Exception(string.Format("WrapUtil: '{0}' not supported", control.GetType().Name));
            }
            con.WrapReady(control);
            return(con);
        }
        public static HtmlControl CloneElement(this HtmlControl element, int count)
        {
            if (element == null)
            {
                return(null);
            }

            using (HtmlControl control = HtmlElementFactory.Create(element.TagName.Increment(count), element.GetType(), true))
            {
                foreach (var attribute in element.Attributes.Keys)
                {
                    string attr = (string)attribute;

                    control.Attributes[attr] = element.Attributes[attr].Increment(count);

                    if (attr == "class")
                    {
                        control.Attributes[attr] = control.Attributes[attr].Increment(count);
                    }
                }

                if (!string.IsNullOrEmpty(element.ID))
                {
                    control.ID = element.ID.Increment(count);
                }

                if (element.Controls.Count == 1)
                {
                    LiteralControl literal = element.Controls[0] as LiteralControl;
                    if (literal != null)
                    {
                        control.Controls.Add(new LiteralControl(literal.Text.Increment(count)));
                    }
                }

                var lorem = element as LoremControl;
                if (lorem != null)
                {
                    lorem.InnerText = lorem.Generate(count);
                }

                return(control);
            }
        }
        private bool SetHtmlControlValueInEmail(HtmlControl htmlControl)
        {
            bool validation = true;

            if (htmlControl.GetType() == typeof(HtmlInputText))
            {
                HtmlInputControl inputControl    = (HtmlInputControl)htmlControl;
                string           validationRules = htmlControl.Attributes["data-validation"];
                if (validationRules == null || Validate(inputControl.Value, validationRules.Split(',')))
                {
                    emailValues += "<tr><td>" + IdToLabelName(htmlControl.ID) + "</td><td>" + inputControl.Value + "</td></tr>";
                }
                else
                {
                    validation = false;
                    if (this.Messagelabel != null)
                    {
                        this.Messagelabel.Text += IdToLabelName(htmlControl.ID) + "<br />";
                    }
                    if (this.showFieldErrorClass)
                    {
                        inputControl.Attributes.Add("class", this.Settings["showFieldErrorClassName"].ToString());
                    }
                }
            }

            if (htmlControl.GetType() == typeof(HtmlInputCheckBox))
            {
                HtmlInputCheckBox inputCheckboxControl = (HtmlInputCheckBox)htmlControl;
                string            validationRules      = htmlControl.Attributes["data-validation"];
                if (validationRules == null || Validate(inputCheckboxControl.Value, validationRules.Split(',')))
                {
                    emailValues += "<tr><td>" + IdToLabelName(htmlControl.ID) + "</td><td>" + inputCheckboxControl.Checked.ToString() + "</td></tr>";
                }
                else
                {
                    validation = false;
                    if (this.Messagelabel != null)
                    {
                        this.Messagelabel.Text += IdToLabelName(htmlControl.ID) + "<br />";
                    }
                    if (this.showFieldErrorClass)
                    {
                        inputCheckboxControl.Attributes.Add("class", this.Settings["showFieldErrorClassName"].ToString());
                    }
                }
            }

            if (htmlControl.GetType() == typeof(HtmlInputRadioButton))
            {
                HtmlInputRadioButton inputRadioControl = (HtmlInputRadioButton)htmlControl;
                string validationRules = htmlControl.Attributes["data-validation"];
                if (validationRules == null || Validate(inputRadioControl.Value, validationRules.Split(',')))
                {
                    emailValues += "<tr><td>" + IdToLabelName(htmlControl.ID) + "</td><td>" + inputRadioControl.Value + "</td></tr>";
                }
                else
                {
                    validation = false;
                    if (this.Messagelabel != null)
                    {
                        this.Messagelabel.Text += IdToLabelName(htmlControl.ID) + "<br />";
                    }
                    if (this.showFieldErrorClass && this.Settings["showFieldErrorClassName"].ToString() != "")
                    {
                        inputRadioControl.Attributes.Add("class", this.Settings["showFieldErrorClassName"].ToString());
                    }
                }
            }

            if (htmlControl.GetType() == typeof(HtmlSelect))
            {
                HtmlSelect selectControl = (HtmlSelect)htmlControl;
                emailValues += "<tr><td>" + IdToLabelName(htmlControl.ID) + "</td><td>" + selectControl.Value + "</td></tr>";
            }

            if (htmlControl.GetType() == typeof(HtmlInputFile))
            {
            }

            if (htmlControl.GetType() == typeof(HtmlTextArea))
            {
                HtmlTextArea inputControl    = (HtmlTextArea)htmlControl;
                string       validationRules = htmlControl.Attributes["data-validation"];
                if (validationRules == null || Validate(inputControl.Value, validationRules.Split(',')))
                {
                    emailValues += "<tr><td>" + IdToLabelName(htmlControl.ID) + "</td><td><pre>" + inputControl.Value + "</pre></td></tr>";
                }
                else
                {
                    validation = false;
                    if (this.Messagelabel != null)
                    {
                        this.Messagelabel.Text += IdToLabelName(htmlControl.ID) + "<br />";
                    }
                    if (this.showFieldErrorClass)
                    {
                        inputControl.Attributes.Add("class", this.Settings["showFieldErrorClassName"].ToString());
                    }
                }
            }

            return(validation);
        }
Ejemplo n.º 6
0
        public void GenerateClick(object sender, EventArgs e)
        {
            int scale;

            if (general_res3.Checked)
            {
                scale = 3;
            }
            else if (general_res2.Checked)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }
            string text = HttpUtility.UrlEncode(Request.Form[general_Text.UniqueID]);

            code.Barcode temporaryBarcode = FindSelectedBarcode();
            HtmlControl  control          = temporaryBarcode.SpecificValue;

            data2.Controls.Clear();
            data2.Controls.Add(control);

            string a1   = string.Empty;
            string a2   = string.Empty;
            string a3   = string.Empty;
            Type   type = control.GetType();

            if (type == typeof(HtmlInputCheckBox))
            {
                a1 = Request.Form[control.UniqueID];
                if (!string.IsNullOrEmpty(a1) && a1.Equals("1"))
                {
                    ((HtmlInputCheckBox)control).Checked = true;
                }
            }
            else if (type == typeof(HtmlSelect))
            {
                a2 = Request.Form[control.UniqueID];
                if (!string.IsNullOrEmpty(a2))
                {
                    foreach (ListItem item in ((HtmlSelect)control).Items)
                    {
                        item.Selected = item.Value.Equals(a2);
                    }
                }
            }
            else if (type == typeof(HtmlInputText))
            {
                a3 = Request.Form[control.UniqueID];
                if (!string.IsNullOrEmpty(a3))
                {
                    ((HtmlInputText)control).Value = a3;
                }
            }

            if (!string.IsNullOrEmpty(text))
            {
                imagerow.Visible      = true;
                barcodeimage.ImageUrl = string.Format("image.aspx?code={0}&o={1}&t={2}&r={3}&text={4}&f1={5}&f2={6}&a1={7}&a2={8}&a3={9}",
                                                      HttpUtility.UrlEncode(Request.Form[general_type.UniqueID]),
                                                      Request.Form[general_output.UniqueID],
                                                      Request.Form[general_thickness.UniqueID],
                                                      scale,
                                                      text,
                                                      HttpUtility.UrlEncode(Request.Form[general_font.UniqueID]),
                                                      Request.Form[general_fontsize.UniqueID],
                                                      a1,
                                                      a2,
                                                      a3);
            }
            else
            {
                imagerow.Visible = false;
            }
        }