Exemple #1
0
        public override string RenderHtml()
        {
            StringBuilder html      = new StringBuilder();
            string        inputName = _fieldPrefix + _key;
            List <KeyValuePair <string, bool> > choiceList = ChoiceKeyValuePairs.ToList();
            var selectedValue  = string.Empty;
            var IsAfterControl = false;

            if (!IsValid)
            {
                var error = new TagBuilder("label");
                error.Attributes.Add("class", _errorClass);
                error.SetInnerText(Error);
                html.Append(error.ToString());
            }

            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
            }

            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background:yellow";
            }

            if (choiceList.Count == Locations.Count + 1)
            {
                string strindex = choiceList[Locations.Count].Key;
                bool   bodex    = choiceList[Locations.Count].Value;
                int    index;

                if (int.TryParse(strindex, out index))
                {
                    KeyValuePair <string, bool> newKvp = new KeyValuePair <string, bool>(choiceList[index].Key, bodex);
                    choiceList[index] = newKvp;
                }
            }

            for (int i = 0; i < Locations.Count; i++)
            {
                double innerTop  = 0.0;
                double innerLeft = 0.0;
                string radId     = inputName + i;

                List <string> TopLeft = Locations[i].ToString().Split(':').ToList();

                if (TopLeft.Count > 0)
                {
                    innerTop = Math.Truncate(ParseDouble(TopLeft[0].ToString()) * Height);
                }

                if (TopLeft.Count > 1)
                {
                    innerLeft = Math.Truncate(ParseDouble(TopLeft[1].ToString()) * Width);
                }

                TagBuilder divTag = new TagBuilder("div");
                divTag.Attributes.Add("class", _orientation == Orientation.Vertical ? _verticalClass : _horizontalClass);
                divTag.Attributes["class"] += " " + _listClass;
                divTag.Attributes.Add("style", "position:absolute; left:" + (_left + innerLeft) + "px;top:" + (_top + innerTop) + "px" + ";width:" + _ControlWidth.ToString() + "px" + ";height:" + _ControlHeight.ToString() + "px");
                html.Append(divTag.ToString(TagRenderMode.StartTag));

                if (!_showTextOnRight)
                {
                    var Leftlbl = new TagBuilder("label");

                    Leftlbl.Attributes.Add("for", inputName);
                    Leftlbl.Attributes.Add("class", "label" + inputName);
                    Leftlbl.Attributes.Add("Id", "label" + inputName + "_" + i);
                    StringBuilder StyleValues1 = new StringBuilder();
                    StyleValues1.Append(GetRadioListStyle(_fontstyle.ToString(), null, null, null, null, IsHidden));
                    string InputFieldStyle_L = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());
                    Leftlbl.Attributes.Add("style", StyleValues1.ToString() + ";" + IsHighlightedStyle + ";" + IsHiddenStyle + ";" + InputFieldStyle_L);
                    Leftlbl.SetInnerText(choiceList[i].Key);
                    html.Append(Leftlbl.ToString());
                }

                TagBuilder radioTag = new TagBuilder("input");
                radioTag.Attributes.Add("type", "radio");
                radioTag.Attributes.Add("name", inputName);
                radioTag.Attributes.Add("class", inputName);

                if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
                {
                    //radioTag.Attributes.Add("onchange", "$('#" + inputName + "').parent().next().find('input[type=hidden]')[0].value='" + i.ToString() + "'; return " + _key + "_after();"); //After
                    radioTag.Attributes.Add("onchange", "$('#" + inputName + "').val('" + i.ToString() + "');return " + _key + "_after();");
                    IsAfterControl = true;
                }
                if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
                {
                    radioTag.Attributes.Add("onclick", "return " + _key + "_click();"); //click
                    IsAfterControl = true;
                }
                if (!IsAfterControl)
                {
                    radioTag.Attributes.Add("onchange", "$('#" + inputName + "').val('" + i.ToString() + "');"); //click
                }
                radioTag.SetInnerText(choiceList[i].Key);
                radioTag.Attributes.Add("value", i.ToString());
                radioTag.Attributes.Add("style", IsHiddenStyle);

                if (_IsDisabled)
                {
                    radioTag.Attributes.Add("disabled", "disabled");
                }

                if (choiceList[i].Value == true)
                {
                    radioTag.Attributes.Add("checked", "checked");
                    selectedValue = i.ToString();
                }

                radioTag.MergeAttributes(_inputHtmlAttributes);
                html.Append(radioTag.ToString(TagRenderMode.SelfClosing));

                if (_showTextOnRight)
                {
                    var rightlbl = new TagBuilder("label");
                    rightlbl.Attributes.Add("for", inputName);
                    rightlbl.Attributes.Add("class", "label" + inputName);
                    rightlbl.Attributes.Add("Id", "label" + inputName + "_" + i);
                    StringBuilder StyleValues2 = new StringBuilder();
                    StyleValues2.Append(GetRadioListStyle(_fontstyle.ToString(), null, null, null, null, IsHidden));
                    string InputFieldStyle_R = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());
                    rightlbl.Attributes.Add("style", StyleValues2.ToString() + ";" + IsHighlightedStyle + ";" + IsHiddenStyle + ";" + InputFieldStyle_R);
                    rightlbl.SetInnerText(choiceList[i].Key);
                    html.Append(rightlbl.ToString());
                }

                html.Append(divTag.ToString(TagRenderMode.EndTag));
            }

            var hidden = new TagBuilder("input");

            hidden.Attributes.Add("type", "hidden");
            hidden.Attributes.Add("id", inputName);
            hidden.Attributes.Add("name", inputName);
            hidden.Attributes.Add("value", selectedValue);
            html.Append(hidden.ToString(TagRenderMode.SelfClosing));

            var wrapper = new TagBuilder(_fieldWrapper);

            wrapper.Attributes["class"] = _fieldWrapperClass;

            if (_IsHidden)
            {
                wrapper.Attributes["style"] = "display:none";
            }

            wrapper.Attributes["id"] = inputName + "_fieldWrapper";
            wrapper.InnerHtml        = html.ToString();
            return(wrapper.ToString());
        }
Exemple #2
0
        public override string RenderHtml()
        {
            string name       = _fieldPrefix + _key;
            var    html       = new StringBuilder();
            string ErrorStyle = string.Empty;

            var commandButtonTag = new TagBuilder("input");

            commandButtonTag.Attributes.Add("value", Prompt);
            commandButtonTag.Attributes.Add("id", name);
            commandButtonTag.Attributes.Add("name", name);
            commandButtonTag.Attributes.Add("type", "button");

            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }

            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }

            if (_IsDisabled)
            {
                commandButtonTag.Attributes.Add("disabled", "disabled");
            }

            commandButtonTag.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _Width.ToString() + "px" + ";height:" + _Height.ToString() + "px" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle);

            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                commandButtonTag.Attributes.Add("onblur", "return " + _key + "_after();"); //After
            }

            if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            {
                commandButtonTag.Attributes.Add("onfocus", "return " + _key + "_before();"); //Before
            }

            if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
            {
                commandButtonTag.Attributes.Add("onclick", "return " + _key + "_click();");
            }

            html.Append(commandButtonTag.ToString(TagRenderMode.SelfClosing));

            var scriptBuilder = new TagBuilder("script");

            scriptBuilder.InnerHtml = "$('#" + name + "').BlockEnter('" + name + "');";
            scriptBuilder.ToString(TagRenderMode.Normal);
            html.Append(scriptBuilder.ToString(TagRenderMode.Normal));

            var wrapper = new TagBuilder(_fieldWrapper);

            wrapper.Attributes["class"] = _fieldWrapperClass;
            if (_IsHidden)
            {
                wrapper.Attributes["style"] = "display:none";
            }
            wrapper.Attributes["id"] = name + "_fieldWrapper";
            wrapper.InnerHtml        = html.ToString();
            return(wrapper.ToString());
        }
Exemple #3
0
        public override string RenderHtml()
        {
            var    html       = new StringBuilder();
            var    inputName  = _fieldPrefix + _key;
            string ErrorStyle = string.Empty;
            var    prompt     = new TagBuilder("label");

            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"(\r\n|\r|\n)+");
            string newText  = regex.Replace(Prompt.Replace("  ", "&nbsp;"), "<br />");
            string NewPromp = System.Web.Mvc.MvcHtmlString.Create(newText).ToString();

            prompt.InnerHtml = NewPromp;
            prompt.Attributes.Add("for", inputName);
            prompt.Attributes.Add("class", "select");
            prompt.Attributes.Add("Id", "label" + inputName);

            prompt.Attributes.Add("style", "display:block !important; ");
            html.Append(prompt.ToString());
            var OuterDiv = new TagBuilder("div");

            //if (this.IsAndroidfield)
            //{

            OuterDiv.Attributes.Add("class", "mainselection");
            OuterDiv.Attributes.Add("id", inputName + "_mainselection");
            OuterDiv.SetInnerText("");
            html.Append(OuterDiv.ToString(TagRenderMode.StartTag));
            //}
            // if (this.IsAndroidfield)
            // {
            var Div = new TagBuilder("div");

            Div.Attributes.Add("class", "arrow_icon");
            Div.Attributes.Add("id", inputName + "_arrow_icon");
            Div.SetInnerText("");
            if (ReadOnly || _IsDisabled)
            {
                Div.Attributes.Add("style", "background-color:lightgray !important");
            }
            html.Append(Div.ToString());
            //}
            if (!IsValid)
            {
                ErrorStyle = ";border-color: red";
            }

            var select = new TagBuilder("select");

            select.Attributes.Add("id", inputName);
            select.Attributes.Add("name", inputName);

            //if (this.IsAndroidfield)
            //{
            select.Attributes.Add("data-role", "none");
            select.Attributes.Add("data-native-menu", "false");
            // }
            //select.Attributes.Add("data-corners",  "true");
            //select.Attributes.Add("data-icon", "arrow-d");
            //select.Attributes.Add("data-shadow", "true");
            //select.Attributes.Add("data-iconshadow", "true");
            //select.Attributes.Add("data-theme", "c");
            if (_form != null)
            {
                FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);
                if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
                {
                    select.Attributes.Add("onchange", "return " + _key + "_after(this.id);"); //After
                }
                FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);
                if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
                {
                    select.Attributes.Add("onfocus", "return " + _key + "_before(this.id);"); //Before
                }
                FunctionObjectClick = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + _key);
                if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
                {
                    select.Attributes.Add("onclick", "return " + _key + "_click(this.id);"); //click
                }
                if (this.RelateCondition)
                {
                    select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + SourceTable + "'," + "''" + ",'" + TextColumnName + "','" + FieldRelateCondition + "');"); //click
                }
            }
            int    LargestChoiseLength = 0;
            string measureString       = "";

            foreach (var choice in _choices)
            {
                if (choice.Key.ToString().Length > LargestChoiseLength)
                {
                    LargestChoiseLength = choice.Key.ToString().Length;
                    measureString       = choice.Key.ToString();
                }
            }

            Font stringFont = new Font(ControlFontStyle, _ControlFontSize);

            SizeF size = new SizeF();

            using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
            {
                size = g.MeasureString(measureString.ToString(), stringFont);
            }

            if (Required == true)
            {
                if ((size.Width) > _ControlWidth)
                {
                    select.Attributes.Add("class", "validate[required] text-input fix-me   ");
                }
                else
                {
                    select.Attributes.Add("class", "validate[required] text-input   ");
                }
                select.Attributes.Add("data-prompt-position", "topLeft:10");
            }
            else
            {
                if ((size.Width) > _ControlWidth)
                {
                    select.Attributes.Add("class", "fix-me   ");
                }
            }
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }

            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }
            //if (_IsDisabled)
            //{
            //    select.Attributes.Add("disabled", "disabled");
            //}
            select.Attributes.Add("style", "" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle);
            select.MergeAttributes(_inputHtmlAttributes);
            html.Append(select.ToString(TagRenderMode.StartTag));

            if (ReadOnly || _IsDisabled)
            {
                var scriptReadOnlyText = new TagBuilder("script");
                //scriptReadOnlyText.InnerHtml = "$(function(){$('#" + inputName + "').attr('disabled','disabled')});";
                scriptReadOnlyText.InnerHtml = "$(function(){  var List = new Array();List.push('" + _key + "');CCE_Disable(List, false);});";
                html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));
            }
            //var optgroup = new TagBuilder("optgroup ");
            //if (this.IsAndroidfield)
            //{


            //    optgroup.Attributes.Add("label", null);
            //    optgroup.SetInnerText("");
            //   // html.Append(optgroup.ToString());
            //    html.Append(optgroup.ToString(TagRenderMode.StartTag));
            //}

            if (ShowEmptyOption)
            {
                var opt = new TagBuilder("option");
                opt.Attributes.Add("value", null);
                opt.SetInnerText(EmptyOption);
                opt.Attributes.Add("style", "");
                html.Append(opt.ToString());
            }

            switch (FieldTypeId.ToString())
            {
            case "11":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("style", "");
                    var optSelectedVale = "";
                    if (!string.IsNullOrEmpty(SelectedValue.ToString()))
                    {
                        optSelectedVale = SelectedValue.ToString();    //=="1"? "Yes" : "No";
                    }
                    opt.Attributes.Add("value", (choice.Key == "Yes" ? "1" : "0"));
                    if (choice.Key == optSelectedVale.ToString())
                    {
                        opt.Attributes.Add("selected", "selected");
                    }
                    if (choice.Key == "Yes" || choice.Key == "No")
                    {
                        opt.SetInnerText(choice.Key);
                        html.Append(opt.ToString());
                    }
                }
                break;

            case "17":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("style", "");
                    opt.Attributes.Add("value", choice.Key);
                    if (choice.Key == SelectedValue.ToString())
                    {
                        opt.Attributes.Add("selected", "selected");
                    }
                    opt.SetInnerText(choice.Key);
                    html.Append(opt.ToString());
                }
                break;

            case "18":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("style", "");
                    opt.Attributes.Add("value", choice.Key);
                    if (choice.Key == SelectedValue.ToString())
                    {
                        opt.Attributes.Add("selected", "selected");
                    }
                    opt.SetInnerText(choice.Key);
                    html.Append(opt.ToString());
                }
                break;

            case "19":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("style", "");
                    if (choice.Key.Contains("-"))
                    {
                        string[] keyValue    = choice.Key.Split(new char[] { '-' }, 2);
                        string   comment     = keyValue[0].Trim();
                        string   description = keyValue[1].Trim();

                        opt.Attributes.Add("value", comment);

                        if (choice.Value || comment == SelectedValue.ToString())
                        {
                            opt.Attributes.Add("selected", "selected");
                        }

                        opt.SetInnerText(description);
                    }

                    html.Append(opt.ToString());
                }
                break;
            }
            //if (this.IsAndroidfield)
            //{

            //    html.Append(optgroup.ToString(TagRenderMode.EndTag));
            //}
            html.Append(select.ToString(TagRenderMode.EndTag));
            //  if (this.IsAndroidfield)
            // {

            html.Append(OuterDiv.ToString(TagRenderMode.EndTag));
            // }
            var hidden = new TagBuilder("input");

            hidden.Attributes.Add("type", "hidden");
            hidden.Attributes.Add("id", inputName + "_hidden");
            hidden.Attributes.Add("name", inputName);
            hidden.Attributes.Add("value", string.Empty);
            html.Append(hidden.ToString(TagRenderMode.SelfClosing));

            var    wrapper        = new TagBuilder(_fieldWrapper);
            string AndroidClasses = "";

            // if (this.IsAndroidfield)
            // {
            AndroidClasses = " ui-field-contain   ";
            // }
            if (!IsValid)
            {
                wrapper.Attributes["class"] = _fieldWrapperClass + " SelectNotValid" + AndroidClasses + "   ";
            }
            else
            {
                wrapper.Attributes["class"] = _fieldWrapperClass + AndroidClasses + "   ";
            }

            if (_IsHidden)
            {
                wrapper.Attributes["style"] = "display:none";
            }

            wrapper.Attributes["id"] = inputName + "_fieldWrapper";
            wrapper.InnerHtml        = html.ToString();
            return(wrapper.ToString());
        }
Exemple #4
0
        public override string RenderHtml()
        {
            var    inputName  = _fieldPrefix + _key;
            var    html       = new StringBuilder();
            string ErrorStyle = string.Empty;

            if (!IsValid)
            {
                ErrorStyle = ";border-color: red";
            }

            var checkboxTag = new TagBuilder("input");

            checkboxTag.Attributes.Add("id", inputName);
            checkboxTag.Attributes.Add("name", inputName);
            checkboxTag.Attributes.Add("type", "checkbox");

            if (Checked)
            {
                checkboxTag.Attributes.Add("checked", "checked");
            }

            checkboxTag.Attributes.Add("value", bool.TrueString);

            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }

            //if (_IsDisabled)
            //{
            //    checkboxTag.Attributes.Add("disabled", "disabled");
            //}

            checkboxTag.Attributes.Add("style", "" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle);
            checkboxTag.MergeAttributes(_inputHtmlAttributes);

            var FunctionCalls = "";

            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                //checkboxTag.Attributes.Add("onblur", "return " + _key + "_after(this.id);"); //After
                // checkboxTag.Attributes.Add("onclick", "return " + _key + "_after(this.id);");
                FunctionCalls += _key + "_after(this.id); ";
            }

            if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            {
                //checkboxTag.Attributes.Add("onfocus", "return " + _key + "_before(this.id);"); //Before
                /// checkboxTag.Attributes.Add("onclick", "return " + _key + "_before(this.id);");
                FunctionCalls += _key + "_before(this.id); ";
            }

            if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
            {
                // checkboxTag.Attributes.Add("onclick", "return " + _key + "_click(this.id);");
                FunctionCalls += _key + "_click(this.id); ";
            }

            if (!string.IsNullOrEmpty(FunctionCalls))
            {
                checkboxTag.Attributes.Add("onclick", "return " + FunctionCalls);
            }

            html.Append(checkboxTag.ToString(TagRenderMode.SelfClosing));

            var prompt = new TagBuilder("label");

            prompt.SetInnerText(Prompt);
            prompt.Attributes.Add("for", inputName);
            prompt.Attributes.Add("class", "EpiLabel");
            prompt.Attributes.Add("Id", "label" + inputName);
            html.Append(prompt.ToString());

            //if (ReadOnly)
            //{
            //    var scriptReadOnlyText = new TagBuilder("script");
            //    scriptReadOnlyText.InnerHtml = "$(function(){$('#" + inputName + "').attr('disabled','disabled')});";
            //    html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));
            //}
            if (ReadOnly || _IsDisabled)
            {
                var scriptReadOnlyText = new TagBuilder("script");
                //scriptReadOnlyText.InnerHtml = "$(function(){$('#" + inputName + "').attr('disabled','disabled')});";
                scriptReadOnlyText.InnerHtml = "$(function(){  var List = new Array();List.push('" + _key + "');CCE_Disable(List, false);});";
                html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));
            }
            var hdn = new TagBuilder("input");

            hdn.Attributes.Add("type", "hidden");
            hdn.Attributes.Add("id", inputName + "_hidden");
            hdn.Attributes.Add("name", inputName);
            hdn.Attributes.Add("value", bool.FalseString);
            html.Append(hdn.ToString(TagRenderMode.SelfClosing));

            //prevent check box control to submit on enter click
            var scriptBuilder = new TagBuilder("script");

            scriptBuilder.InnerHtml = "$('#" + inputName + "').BlockEnter('" + inputName + "');";
            scriptBuilder.ToString(TagRenderMode.Normal);
            html.Append(scriptBuilder.ToString(TagRenderMode.Normal));

            var wrapper = new TagBuilder(_fieldWrapper);

            wrapper.Attributes["class"] = _fieldWrapperClass;

            if (_IsHidden)
            {
                wrapper.Attributes["style"] = "display:none";
            }

            wrapper.Attributes["id"] = inputName + "_fieldWrapper";
            wrapper.InnerHtml        = html.ToString();
            return(wrapper.ToString());
        }