コード例 #1
0
        protected virtual string GetFormJavaScript(string CheckCode, Form form, string controlName)
        {// controlName
            StringBuilder B_JavaScript     = new StringBuilder();
            EnterRule     FunctionObject_B = (EnterRule)form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + controlName);

            if (FunctionObject_B != null && !FunctionObject_B.IsNull())
            {
                B_JavaScript.Append("function " + controlName.ToLower());
                FunctionObject_B.ToJavaScript(B_JavaScript);
            }

            StringBuilder A_JavaScript     = new StringBuilder();
            EnterRule     FunctionObject_A = (EnterRule)form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + controlName);

            if (FunctionObject_A != null && !FunctionObject_A.IsNull())
            {
                A_JavaScript.Append("function " + controlName.ToLower());
                FunctionObject_A.ToJavaScript(A_JavaScript);
            }

            EnterRule FunctionObject = (EnterRule)form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + controlName);

            if (FunctionObject != null && !FunctionObject.IsNull())
            {
                A_JavaScript.Append("function " + controlName.ToLower());
                FunctionObject.ToJavaScript(A_JavaScript);
            }

            return(B_JavaScript.ToString() + "  " + A_JavaScript.ToString());
        }
コード例 #2
0
        public override string RenderHtml()
        {
            var    html       = new StringBuilder();
            var    inputName  = _form.FieldPrefix + _key;
            string ErrorStyle = string.Empty;
            // prompt label
            var prompt = new TagBuilder("label");

            prompt.SetInnerText(Prompt);
            prompt.Attributes.Add("for", inputName);
            prompt.Attributes.Add("Id", "label" + inputName);
            //  prompt.Attributes.Add("class", _promptClass);
            prompt.Attributes.Add("class", "EpiLabel");

            StringBuilder StyleValues = new StringBuilder();

            //StyleValues.Append(GetContolStyle(_fontstyle.ToString(), _Prompttop.ToString(), _Promptleft.ToString(), _PromptWidth.ToString(), Height.ToString()));
            StyleValues.Append(GetContolStyle(_fontstyle.ToString(), _promptTop.ToString(), _promptLeft.ToString(), null, Height.ToString(), IsHidden));
            prompt.Attributes.Add("style", StyleValues.ToString());
            html.Append(prompt.ToString());

            // error label
            if (!IsValid)
            {
                //Add new Error to the error Obj
                ErrorStyle = ";border-color: red";
            }

            // input element
            var txt = new TagBuilder("input");

            txt.Attributes.Add("name", inputName);
            txt.Attributes.Add("id", inputName);
            txt.Attributes.Add("type", "text");
            if (_MaxLength > 0 && _MaxLength <= 255)
            {
                txt.Attributes.Add("MaxLength", _MaxLength.ToString());
            }
            else
            {
                txt.Attributes.Add("MaxLength", "255");
            }
            string InputFieldStyle    = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }
            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }

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

            // txt.Attributes.Add("value", Value);
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);

            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                txt.Attributes.Add("onblur", "return " + _key + "_after();"); //After
            }
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);

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

            ////////////Check code end//////////////////
            txt.Attributes.Add("value", Value);
            txt.Attributes.Add("class", GetControlClass());
            txt.Attributes.Add("data-prompt-position", "topRight:15");
            txt.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _controlWidth.ToString() + "px" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle + ";" + InputFieldStyle);
            txt.MergeAttributes(_inputHtmlAttributes);
            html.Append(txt.ToString(TagRenderMode.SelfClosing));

            //adding numeric text box validation jquery script tag
            var scriptNumeric = new TagBuilder("script");

            scriptNumeric.InnerHtml = "$(function() { $('#" + inputName + "').numeric();});";
            html.Append(scriptNumeric.ToString(TagRenderMode.Normal));

            //if masked input not empty appy the pattern jquery plugin
            if (!string.IsNullOrEmpty(_Pattern))
            {
                string maskedPatternEq   = GetMaskedPattern(_Pattern);
                var    scriptMaskedInput = new TagBuilder("script");
                scriptMaskedInput.InnerHtml = "$(function() { $('#" + inputName + "').mask('" + maskedPatternEq + "');});";
                html.Append(scriptMaskedInput.ToString(TagRenderMode.Normal));
            }
            // If readonly then add the following jquery script to make the field disabled
            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));
            }

            //prevent numeric text 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());
        }
コード例 #3
0
 public override bool IsNull()
 {
     return(CheckCodeBlock.IsNull() || (CheckCodeBlocks != null && CheckCodeBlocks.IsNull()));
 }
コード例 #4
0
        public override string RenderHtml()
        {
            int.TryParse(ConfigurationManager.AppSettings["CACHE_DURATION"].ToString(), out CacheDuration);
            CacheIsOn = ConfigurationManager.AppSettings["CACHE_IS_ON"];//false;
            IsCacheSlidingExpiration = ConfigurationManager.AppSettings["CACHE_SLIDING_EXPIRATION"].ToString();
            var html = new StringBuilder();

            var    inputName  = _form.FieldPrefix + _key;
            string ErrorStyle = string.Empty;

            // prompt
            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", "EpiLabel");
            prompt.Attributes.Add("Id", "label" + inputName);


            StringBuilder StyleValues = new StringBuilder();

            StyleValues.Append(GetContolStyle(_fontstyle.ToString(), _Prompttop.ToString(), _Promptleft.ToString(), null, Height.ToString(), _IsHidden));
            prompt.Attributes.Add("style", StyleValues.ToString());
            html.Append(prompt.ToString());

            // error label
            if (!IsValid)
            {
                //Add new Error to the error Obj

                ErrorStyle = ";border-color: red";
            }

            // open select element
            //if (this.CodesList != null)
            //{
            //    if (this.CodesList.Count() > 0)
            //    {
            //        string Html = "";
            //        var ScriptRelateCondition = new TagBuilder("script");
            //        foreach (var code in CodesList)
            //        {
            //            Html = "";

            //            var NewCode = Regex.Replace(code.Key.ToString(), @"[^0-9a-zA-Z]+", "");
            //            NewCode = Regex.Replace(NewCode, @"\s+", "");
            //            Html = "var " + NewCode + "=[";
            //            var json1 = JsonConvert.SerializeObject(code.Value);
            //            foreach (var item in code.Value)
            //            {
            //                var values = item.Split('=');
            //                Html = Html + "\"" + values[0] + "," + values[1].ToString().Replace("\"", "") + "\",";


            //            }
            //            Html = Html + "]; ";
            //            ScriptRelateCondition.InnerHtml = ScriptRelateCondition.InnerHtml + Html.ToString();

            //        }
            //        html.Append(ScriptRelateCondition.ToString(TagRenderMode.Normal));
            //        //var JasonObj =
            //        // var jsonSerialiser = new JavaScriptSerializer();
            //        // var json = JsonConvert.SerializeObject(CodesList);

            //    }
            //}
            TagBuilder select = null;

            select = new TagBuilder("select");

            select.Attributes.Add("id", inputName);
            select.Attributes.Add("name", inputName);
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);

            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                select.Attributes.Add("onblur", "return " + _key + "_after();"); //After
                // select.Attributes.Add("onchange", "return " + _key + "_after();"); //After
            }
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);

            if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            {
                select.Attributes.Add("onfocus", "return " + _key + "_before();"); //Before
            }
            EnterRule FunctionObjectClick = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + _key);

            if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
            {
                select.Attributes.Add("onclick", "return " + _key + "_click();"); //click
            }
            if (!string.IsNullOrEmpty(this.RelateCondition))
            {
                select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + _key + "');"); //click
            }
            ////////////Check code end//////////////////
            int    LargestChoiseLength = 0;
            string measureString       = "";

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

                    measureString = choise.Key.ToString();
                }
            }

            // LargestChoiseLength = LargestChoiseLength * _ControlFontSize;

            Font stringFont = new Font(ControlFontStyle, _ControlFontSize);

            SizeF size = new SizeF();

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



            // stringSize = (int) Graphics.MeasureString(measureString.ToString(), stringFont).Width;


            if (_IsRequired == true)
            {
                //awesomplete

                if ((size.Width) > _ControlWidth)
                {
                    // select.Attributes.Add("class", GetControlClass() + "text-input fix-me");
                    select.Attributes.Add("class", GetControlClass() + "fix-me");
                }
                else
                {
                    // select.Attributes.Add("class", GetControlClass() + "text-input");
                    select.Attributes.Add("class", GetControlClass());
                }
                select.Attributes.Add("data-prompt-position", "topRight:10");
            }
            else
            {
                //awesomplete

                //select.Attributes.Add("class", GetControlClass() + "text-input fix-me");
                if ((size.Width) > _ControlWidth)
                {
                    select.Attributes.Add("class", GetControlClass() + "fix-me ");
                }
                else
                {
                    select.Attributes.Add("class", GetControlClass());
                }
                select.Attributes.Add("data-prompt-position", "topRight:10");
            }
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }
            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }

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

            string InputFieldStyle = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());

            select.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _ControlWidth.ToString() + "px ; font-size:" + _ControlFontSize + "pt;" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle + ";" + InputFieldStyle);
            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));
            }


            // initial empty option
            if (this._choices.Count() < 100)
            {
                if (ShowEmptyOption)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("value", null);
                    opt.SetInnerText(EmptyOption);
                    html.Append(opt.ToString());
                }
            }
            // options

            // Build codes RelateCondition script object



            switch (this.SelectType.ToString())
            {
            case "11":
                foreach (var choice in _choices)
                {
                    var opt             = new TagBuilder("option");
                    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("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("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");

                    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;
            }



            // close select element
            html.Append(select.ToString(TagRenderMode.EndTag));

            // add hidden tag, so that a value always gets sent for select tags
            var hidden1 = new TagBuilder("input");

            hidden1.Attributes.Add("type", "hidden");
            hidden1.Attributes.Add("id", inputName + "_hidden");
            hidden1.Attributes.Add("name", inputName);
            hidden1.Attributes.Add("value", string.Empty);
            html.Append(hidden1.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());
        }
コード例 #5
0
ファイル: AutoComplete.cs プロジェクト: fgma75/epiinfo
        public override string RenderHtml()
        {
            int DropDownLimitSize = 1;

            int.TryParse(ConfigurationManager.AppSettings["CACHE_DURATION"].ToString(), out CacheDuration);
            CacheIsOn = ConfigurationManager.AppSettings["CACHE_IS_ON"];//false;
            IsCacheSlidingExpiration = ConfigurationManager.AppSettings["CACHE_SLIDING_EXPIRATION"].ToString();
            var html = new StringBuilder();

            var    inputName  = _form.FieldPrefix + _key;
            string ErrorStyle = string.Empty;

            // prompt
            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", "EpiLabel");
            prompt.Attributes.Add("Id", "label" + inputName);


            StringBuilder StyleValues = new StringBuilder();

            StyleValues.Append(GetControlStyle(_fontstyle.ToString(), _Prompttop.ToString(), _Promptleft.ToString(), null, Height.ToString(), _IsHidden));
            prompt.Attributes.Add("style", StyleValues.ToString());
            html.Append(prompt.ToString());

            // error label
            if (!IsValid)
            {
                //Add new Error to the error Obj

                ErrorStyle = ";border-color: red";
            }


            TagBuilder input = null;

            input = new TagBuilder("input");
            input.Attributes.Add("list", inputName + "_DataList");
            input.Attributes.Add("data-autofirst", "true");
            input.Attributes.Add("value", Value);
            input.Attributes.Add("id", inputName);
            input.Attributes.Add("name", inputName);
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);

            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                input.Attributes.Add("onblur", "return " + _key + "_after();"); //After
                // select.Attributes.Add("onchange", "return " + _key + "_after();"); //After
            }
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);

            if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            {
                input.Attributes.Add("onfocus", "return " + _key + "_before();"); //Before
            }
            EnterRule FunctionObjectClick = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + _key);


            if (!string.IsNullOrEmpty(this.RelateCondition))
            {
                input.Attributes.Add("onchange", "SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + SourceTable + "'," + "''" + ",'" + TextColumnName + "','" + RelateCondition + "');"); //click
            }
            ////////////Check code end//////////////////
            int    LargestChoiseLength = 0;
            string measureString       = "";

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

                    measureString = choise.Key.ToString();
                }
            }

            // LargestChoiseLength = LargestChoiseLength * _ControlFontSize;

            Font stringFont = new Font(ControlFontStyle, ControlFontSize);

            SizeF size = new SizeF();

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



            // stringSize = (int) Graphics.MeasureString(measureString.ToString(), stringFont).Width;


            if (_IsRequired == true)
            {
                //awesomplete
                if (this._choices.Count() < DropDownLimitSize)
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        // select.Attributes.Add("class", GetControlClass() + "text-input fix-me");
                        input.Attributes.Add("class", GetControlClass() + "fix-me");
                    }
                    else
                    {
                        // select.Attributes.Add("class", GetControlClass() + "text-input");
                        input.Attributes.Add("class", GetControlClass());
                    }
                    input.Attributes.Add("data-prompt-position", "topRight:10");
                }
                else
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        // select.Attributes.Add("class", GetControlClass() + "text-input fix-me");
                        input.Attributes.Add("class", GetControlClass() + "fix-me awesomplete Search");
                    }
                    else
                    {
                        // select.Attributes.Add("class", GetControlClass() + "text-input");
                        input.Attributes.Add("class", GetControlClass() + " awesomplete Search");
                    }
                    input.Attributes.Add("data-prompt-position", "topRight:10");
                }
            }
            else
            {
                //awesomplete
                if (this._choices.Count() < DropDownLimitSize)
                {
                    //select.Attributes.Add("class", GetControlClass() + "text-input fix-me");
                    if ((size.Width) > _ControlWidth)
                    {
                        input.Attributes.Add("class", GetControlClass() + "fix-me ");
                    }
                    else
                    {
                        input.Attributes.Add("class", GetControlClass());
                    }
                    input.Attributes.Add("data-prompt-position", "topRight:10");
                }
                else
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        input.Attributes.Add("class", GetControlClass() + "fix-me awesomplete Search");
                    }
                    else
                    {
                        input.Attributes.Add("class", GetControlClass() + " awesomplete Search");
                    }
                    input.Attributes.Add("data-prompt-position", "topRight:10");
                }
            }
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }
            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }

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

            string InputFieldStyle = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());

            input.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _ControlWidth.ToString() + "px ; font-size:" + ControlFontSize + "pt;" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle + ";" + InputFieldStyle);
            input.MergeAttributes(_inputHtmlAttributes);
            html.Append(input.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));
            }

            if (this._choices.Count() > DropDownLimitSize)
            {
                var           scriptReadOnlyText = new TagBuilder("script");
                StringBuilder Script             = new StringBuilder();
                Script.Append("$(window).load(function () {  ");

                Script.Append(" $( '#" + inputName + "' ).next().css( 'position', 'absolute' );  ");
                Script.Append(" $( '#" + inputName + "' ).next().css( 'left', '" + _left.ToString() + "px' );  ");
                Script.Append(" $( '#" + inputName + "' ).next().css( 'top', '" + (_top + 29).ToString() + "px' );  ");


                Script.Append("});");
                scriptReadOnlyText.InnerHtml = Script.ToString();
                html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));


                //var scriptReadOnlyText1 = new TagBuilder("script");
                //StringBuilder Script1 = new StringBuilder();
                //Script1.Append("  $(document).ready(function () {");


                //Script1.Append("$( '#" + inputName + "').blur(function() { ");
                //Script1.Append("SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + _key + "');  ");

                //Script1.Append("});");
                //Script1.Append("});");
                //scriptReadOnlyText1.InnerHtml = Script1.ToString();
                //html.Append(scriptReadOnlyText1.ToString(TagRenderMode.Normal));
            }

            var           scriptReadOnlyText2 = new TagBuilder("script");
            StringBuilder Script2             = new StringBuilder();

            if (!string.IsNullOrEmpty(this.RelateCondition))
            {
                // select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + SourceTable + "'," + "''" + ",'" + TextColumnName + "','" + FieldRelateCondition + "');"); //click
                string RelateConditionScript = "SetCodes_Val(this, '" + _form.SurveyInfo.SurveyId + "', '" + SourceTable + "', " + "''" + ", '" + TextColumnName + "', '" + this.RelateCondition + "');";
                Script2.Append("$('#" + inputName + "' ).on('awesomplete-selectcomplete',function () {  ");

                Script2.Append(RelateConditionScript);
                Script2.Append("});");
                scriptReadOnlyText2.InnerHtml = Script2.ToString();
                html.Append(scriptReadOnlyText2.ToString(TagRenderMode.Normal));
            }

            ///////////////////////////

            var datalist = new TagBuilder("datalist ");

            datalist.Attributes.Add("id", inputName + "_DataList");
            html.Append(datalist.ToString(TagRenderMode.StartTag));

            switch (FieldTypeId.ToString())

            {
            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());
                //}
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("value", choice.Key);
                    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;
            }
            // close select element
            html.Append(input.ToString(TagRenderMode.EndTag));

            // add hidden tag, so that a value always gets sent for select tags
            var hidden1 = new TagBuilder("input");

            hidden1.Attributes.Add("type", "hidden");
            hidden1.Attributes.Add("id", inputName + "_hidden");
            hidden1.Attributes.Add("name", inputName);
            hidden1.Attributes.Add("value", string.Empty);
            html.Append(hidden1.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());
        }
コード例 #6
0
        public override string RenderHtml()
        {
            var    inputName  = _form.FieldPrefix + _key;
            var    html       = new StringBuilder();
            string ErrorStyle = string.Empty;

            // error label
            if (!IsValid)
            {
                //Add new Error to the error Obj
                ErrorStyle = ";border-color: red";
            }

            // checkbox input
            var chk = new TagBuilder("input");

            chk.Attributes.Add("id", inputName);
            chk.Attributes.Add("name", inputName);
            chk.Attributes.Add("type", "checkbox");
            if (Checked)
            {
                chk.Attributes.Add("checked", "checked");
            }
            chk.Attributes.Add("value", bool.TrueString);
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }
            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }

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

            chk.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _ControlWidth.ToString() + "px" + ErrorStyle + ";" + IsHiddenStyle + ";");

            chk.MergeAttributes(_inputHtmlAttributes);
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);

            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                chk.Attributes.Add("onblur", "return " + _key + "_after();"); //After
            }
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);

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


            EnterRule FunctionObjectClick = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + _key);

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



            ////////////Check code end//////////////////
            html.Append(chk.ToString(TagRenderMode.SelfClosing));

            // prompt label
            var prompt = new TagBuilder("label");

            prompt.SetInnerText(Prompt);
            prompt.Attributes.Add("for", inputName);
            prompt.Attributes.Add("class", "EpiLabel");
            prompt.Attributes.Add("Id", "label" + inputName);
            StringBuilder StyleValues = new StringBuilder();

            StyleValues.Append(GetContolStyle(_fontstyle.ToString(), _Prompttop.ToString(), _Promptleft.ToString(), null, null, IsHidden));
            prompt.Attributes.Add("style", StyleValues.ToString() + " ; " + IsHighlightedStyle);
            html.Append(prompt.ToString());
            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));
            }

            // hidden input (so that value is posted when checkbox is unchecked)
            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);
            ////////////Check code start//////////////////
            //EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);
            //if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            //{
            //    hdn.Attributes.Add("onblur", "return " + _key + "_after();"); //After
            //}
            //EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);
            //if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            //{
            //    hdn.Attributes.Add("onfocus", "return " + _key + "_before();"); //Before
            //}

            ////////////Check code end//////////////////
            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());
        }
コード例 #7
0
        public override string RenderHtml()
        {
            string name       = "mvcdynamicfield_" + _key;
            var    html       = new StringBuilder();
            string ErrorStyle = string.Empty;

            var commandButtonTag = new TagBuilder("button");

            //commandButtonTag.Attributes.Add("text", Prompt);
            commandButtonTag.InnerHtml = Prompt;
            commandButtonTag.Attributes.Add("id", name);
            commandButtonTag.Attributes.Add("name", "Relate");
            //commandButtonTag.Attributes.Add("name", name);
            commandButtonTag.Attributes.Add("type", "button");

            commandButtonTag.Attributes.Add("onclick", "NavigateToChild(" + RelatedViewId + ");");
            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);
            commandButtonTag.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + ControlWidth.ToString() + "px" + ";height:" + ControlHeight.ToString() + "px" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle);
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);

            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                commandButtonTag.Attributes.Add("onblur", "return " + _key + "_after();"); //After
            }
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);

            if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            {
                commandButtonTag.Attributes.Add("onfocus", "return " + _key + "_before();"); //Before
            }
            EnterRule FunctionObjectClick = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + _key);

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

            //   html.Append(commandButtonTag.ToString(TagRenderMode.SelfClosing));
            html.Append(commandButtonTag.ToString());
            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());
        }
コード例 #8
0
        public override string RenderHtml()
        {
            var    html       = new StringBuilder();
            var    inputName  = _form.FieldPrefix + _key;
            string ErrorStyle = string.Empty;
            // prompt label
            var prompt = new TagBuilder("label");

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

            StringBuilder StyleValues = new StringBuilder();

            StyleValues.Append(GetContolStyle(_fontstyle.ToString(), _promptTop.ToString(), _promptLeft.ToString(), null, Height.ToString(), _IsHidden));
            //prompt.Attributes.Add("style", StyleValues.ToString());
            html.Append(prompt.ToString());

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

            // input element
            var txt = new TagBuilder("input");

            txt.Attributes.Add("name", inputName);
            txt.Attributes.Add("id", inputName);
            txt.Attributes.Add("type", "text");
            txt.Attributes.Add("Theme", "b");
            txt.Attributes.Add("data-role", "datebox");
            txt.Attributes.Add("data-options", "{\"mode\": \"datebox\", \"pickPageButtonTheme\": \"e\", \"pickPageInputTheme\":\"e\", \"pickPageFlipButtonTheme\":\"a\", \"pickPageTheme\":\"e\" ,  \"useNewStyle\":true}");
            txt.Attributes.Add("value", Value);
            //string InputFieldStyle = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);

            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                //txt.Attributes.Add("onblur", "return " + _key + "_after();"); //After
                txt.Attributes.Add("onchange", "return " + _key + "_after(this.id);"); //After
            }
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);

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

            //  txt.Attributes.Add("onchange", "return this.focus();"); //After
            ////////////Check code end//////////////////

            if (_MaxLength.ToString() != "0" && !string.IsNullOrEmpty(_MaxLength.ToString()))
            {
                txt.Attributes.Add("MaxLength", _MaxLength.ToString());
            }
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

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

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

            //if (_IsDisabled)
            //{
            //    txt.Attributes.Add("disabled", "disabled");
            //}
            txt.Attributes.Add("class", GetControlClass(Value));
            txt.Attributes.Add("data-prompt-position", "topLeft:15");
            //txt.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _ControlWidth.ToString() + "px" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle);

            txt.Attributes.Add("style", "" + _controlWidth.ToString() + "px" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle);
            //if (ReadOnly)
            //    {

            //    txt.Attributes.Add("disabled", "disabled");
            //    }
            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));
            }

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

            if (ReadOnly)
            {
                //var scriptReadOnlyText = new TagBuilder("script");
                //scriptReadOnlyText.InnerHtml = "$(function(){$('#" + inputName + "').attr('disabled','disabled')});";
                //html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));
            }
            // adding scripts for date picker
            //var scriptDatePicker = new TagBuilder("script");

            //if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            //{

            //    scriptDatePicker.InnerHtml = "$('#" + inputName + "').datepicker({onClose:function(){setTimeout(" + _key + "_after,100);},changeMonth:true,changeYear:true});";
            //}
            //else
            //{
            //    scriptDatePicker.InnerHtml = "$('#" + inputName + "').datepicker({changeMonth: true,changeYear: true});";
            //}
            //html.Append(scriptDatePicker.ToString(TagRenderMode.Normal));

            //prevent date picker 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 (!IsValid)
            {
                wrapper.Attributes["class"] = _fieldWrapperClass + " DatePickerNotValid";
            }
            else
            {
                wrapper.Attributes["class"] = _fieldWrapperClass;
            }
            if (_IsHidden)
            {
                wrapper.Attributes["style"] = "display:none";
            }
            wrapper.Attributes["id"] = inputName + "_fieldWrapper";
            wrapper.InnerHtml        = html.ToString();
            return(wrapper.ToString());
        }
コード例 #9
0
        public override string RenderHtml()
        {
            var    html       = new StringBuilder();
            var    inputName  = _form.FieldPrefix + _key;
            string ErrorStyle = string.Empty;
            // prompt label
            var prompt = new TagBuilder("label");

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

            StringBuilder StyleValues = new StringBuilder();

            StyleValues.Append(GetContolStyle(_fontstyle.ToString(), _Prompttop.ToString(), _Promptleft.ToString(), null, Height.ToString(), _IsHidden));
            prompt.Attributes.Add("style", StyleValues.ToString());
            html.Append(prompt.ToString());

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

            // input element
            var txt = new TagBuilder("input");

            txt.Attributes.Add("name", inputName);
            txt.Attributes.Add("id", inputName);
            txt.Attributes.Add("type", "text");
            txt.Attributes.Add("value", Value);
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);
            //if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            //{
            //txt.Attributes.Add("onblur", "return " + _key + "_after();"); //After
            //}
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);

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

            ////////////Check code end//////////////////

            if (_MaxLength.ToString() != "0" && !string.IsNullOrEmpty(_MaxLength.ToString()))
            {
                txt.Attributes.Add("MaxLength", _MaxLength.ToString());
            }
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }
            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }

            //if (_IsDisabled)
            //{
            //    txt.Attributes.Add("disabled", "disabled");
            //}
            txt.Attributes.Add("class", GetControlClass(Value));

            string InputFieldStyle = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());

            txt.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _ControlWidth.ToString() + "px" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle + ";" + InputFieldStyle);

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

            // If readonly then add the following jquery script to make the field disabled
            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));
            }
            // adding scripts for date picker
            var scriptDatePicker = new TagBuilder("script");
            //scriptDatePicker.InnerHtml = "$(function() { $('#" + inputName + "').datepicker({changeMonth: true,changeYear: true});});";

            /*Checkcode control after event...for datepicker, the onblur event fires on selecting a date from calender. Since the datepicker control itself is tied to after event which was firing before the datepicker
             * textbox is populated the comparison was not working. For this reason, the control after steps are interjected inside datepicker onClose event, so the after event is fired when the datepicker is populated
             */
            var MinYear = -110;
            var MaxYear = 10;

            if (!string.IsNullOrEmpty(Lower) && !string.IsNullOrEmpty(Upper))
            {
                int Year_Lower = GetYear(Lower, Pattern);
                int Year_Upper = GetYear(Upper, Pattern);

                MinYear = -(DateTime.Now.Year - Year_Lower);
                MaxYear = Year_Upper - DateTime.Now.Year;
            }
            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                //scriptDatePicker.InnerHtml = "$('#" + inputName + "').datepicker({onClose:function(){" + _key + "_after();},changeMonth:true,changeYear:true});";
                //Note: datepicker seems to have a command inst.input.focus(); (I think) called after the onClose callback which resets the focus to the original input element. I'm wondering if there is way round this with bind().
                //http://stackoverflow.com/questions/7087987/change-the-focus-on-jqueryui-datepicker-on-close
                scriptDatePicker.InnerHtml = "$('#" + inputName + "').datepicker({onClose:function(){setTimeout(" + _key + "_after,100);},changeMonth:true,changeYear:true,yearRange:'" + MinYear + ":+" + MaxYear + "'});";
            }
            else
            {
                scriptDatePicker.InnerHtml = "$('#" + inputName + "').datepicker({changeMonth: true,changeYear: true,yearRange:'" + MinYear + ":+" + MaxYear + "'});";
            }


            html.Append(scriptDatePicker.ToString(TagRenderMode.Normal));

            //prevent date picker 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());
        }
コード例 #10
0
        public override string RenderHtml()
        {
            var    html       = new StringBuilder();
            var    inputName  = _form.FieldPrefix + _key;
            string ErrorStyle = string.Empty;
            //prompt label
            var prompt = new TagBuilder("label");

            prompt.SetInnerText(Prompt);
            prompt.Attributes.Add("for", inputName);
            prompt.Attributes.Add("class", "EpiLabel");
            prompt.Attributes.Add("Id", "label" + inputName);
            StringBuilder StyleValues = new StringBuilder();

            StyleValues.Append(GetContolStyle(_fontstyle.ToString(), _promptTop.ToString(), _promptLeft.ToString(), null, Height.ToString(), IsHidden));
            prompt.Attributes.Add("style", StyleValues.ToString());
            html.Append(prompt.ToString());
            // error label
            if (!IsValid)
            {
                //Add new Error to the error Obj

                ErrorStyle = ";border-color: red";
            }

            // input element
            var txt = new TagBuilder("textarea");

            txt.Attributes.Add("name", inputName);
            txt.Attributes.Add("id", inputName);
            // txt.SetInnerText(Value);
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);

            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                txt.Attributes.Add("onblur", "return " + _key + "_after();"); //After
            }
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);

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

            ////////////Check code end//////////////////
            txt.SetInnerText(Value);
            //txt.Attributes.Add("class", GetControlClass() + "text-input");
            txt.Attributes.Add("class", GetControlClass());
            if (_isRequired == true)
            {
                // txt.Attributes.Add("class", "validate[required] text-input");
                txt.Attributes.Add("data-prompt-position", "topRight:15");
            }
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }
            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }

            //if (_IsDisabled)
            //{
            //    txt.Attributes.Add("disabled", "disabled");
            //}
            string InputFieldStyle = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());

            txt.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _controlWidth.ToString() + "px" + ";height:" + _controlHeight.ToString() + "px" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle + ";" + InputFieldStyle);
            txt.MergeAttributes(_inputHtmlAttributes);
            html.Append(txt.ToString());


            // If readonly then add the following jquery script to make the field disabled
            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 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());
        }
コード例 #11
0
        public ActionResult Index(string surveyid, string AddNewFormId, string EditForm)
        {
            int  UserId       = SurveyHelper.GetDecryptUserId(Session["UserId"].ToString());
            int  CuurentOrgId = int.Parse(Session["SelectedOrgId"].ToString());
            Guid ResponseID   = Guid.NewGuid();

            Session["FormValuesHasChanged"] = "";

            TempData[Epi.Web.MVC.Constants.Constant.RESPONSE_ID] = Session["RootResponseId"] = ResponseID.ToString();


            if (string.IsNullOrEmpty(EditForm) && Session["EditForm"] != null)
            {
                EditForm = Session["EditForm"].ToString();
            }

            if (!string.IsNullOrEmpty(EditForm) && string.IsNullOrEmpty(AddNewFormId))
            {
                Session["RootResponseId"] = EditForm.ToLower();

                Session["IsEditMode"] = true;
                Epi.Web.Enter.Common.DTO.SurveyAnswerDTO surveyAnswerDTO = GetSurveyAnswer(EditForm, Session["RootFormId"].ToString());


                Session["RequestedViewId"] = surveyAnswerDTO.ViewId;
                if (Session["RecoverLastRecordVersion"] != null)
                {
                    surveyAnswerDTO.RecoverLastRecordVersion = bool.Parse(Session["RecoverLastRecordVersion"].ToString());
                }
                string ChildRecordId = GetChildRecordId(surveyAnswerDTO);
                Session["RecoverLastRecordVersion"] = false;
                return(RedirectToAction(Epi.Web.MVC.Constants.Constant.INDEX, Epi.Web.MVC.Constants.Constant.SURVEY_CONTROLLER, new { responseid = ChildRecordId, PageNumber = 1, Edit = "Edit" }));
            }
            else
            {
                Session["IsEditMode"] = false;
            }
            bool IsMobileDevice = this.Request.Browser.IsMobileDevice;


            if (IsMobileDevice == false)
            {
                IsMobileDevice = Epi.Web.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString());
            }

            FormsAuthentication.SetAuthCookie("BeginSurvey", false);
            Session["RootFormId"] = AddNewFormId;
            //create the responseid
            Epi.Web.Enter.Common.DTO.SurveyAnswerDTO SurveyAnswer = _isurveyFacade.CreateSurveyAnswer(AddNewFormId, ResponseID.ToString(), UserId, false, "", false, CuurentOrgId);
            MvcDynamicForms.Form form = _isurveyFacade.GetSurveyFormData(SurveyAnswer.SurveyId, 1, SurveyAnswer, IsMobileDevice, null, null, false, false);
            TempData["Width"] = form.Width + 100;
            SurveyInfoModel surveyInfoModel = Mapper.ToFormInfoModel(form.SurveyInfo);

            // set the survey answer to be production or test
            SurveyAnswer.IsDraftMode = form.SurveyInfo.IsDraftMode;
            XDocument xdoc = XDocument.Parse(form.SurveyInfo.XML);

            ///////////////////////////// Execute - Record Before - start//////////////////////
            Dictionary <string, string> ContextDetailList = new Dictionary <string, string>();
            EnterRule         FunctionObject_B            = (EnterRule)form.FormCheckCodeObj.GetCommand("level=record&event=before&identifier=");
            SurveyResponseXML SurveyResponseXML           = new SurveyResponseXML(PageFields, RequiredList);

            if (FunctionObject_B != null && !FunctionObject_B.IsNull())
            {
                try
                {
                    SurveyAnswer.XML        = SurveyResponseXML.CreateResponseDocument(xdoc, SurveyAnswer.XML);
                    Session["RequiredList"] = SurveyResponseXML._RequiredList;
                    //SurveyAnswer.XML = Epi.Web.MVC.Utility.SurveyHelper.CreateResponseDocument(xdoc, SurveyAnswer.XML, RequiredList);
                    this.RequiredList       = SurveyResponseXML._RequiredList;
                    form.RequiredFieldsList = this.RequiredList;
                    FunctionObject_B.Context.HiddenFieldList      = form.HiddenFieldsList;
                    FunctionObject_B.Context.HighlightedFieldList = form.HighlightedFieldsList;
                    FunctionObject_B.Context.DisabledFieldList    = form.DisabledFieldsList;
                    FunctionObject_B.Context.RequiredFieldList    = form.RequiredFieldsList;

                    FunctionObject_B.Execute();

                    // field list
                    form.HiddenFieldsList      = FunctionObject_B.Context.HiddenFieldList;
                    form.HighlightedFieldsList = FunctionObject_B.Context.HighlightedFieldList;
                    form.DisabledFieldsList    = FunctionObject_B.Context.DisabledFieldList;
                    form.RequiredFieldsList    = FunctionObject_B.Context.RequiredFieldList;


                    ContextDetailList = Epi.Web.MVC.Utility.SurveyHelper.GetContextDetailList(FunctionObject_B);
                    form = Epi.Web.MVC.Utility.SurveyHelper.UpdateControlsValuesFromContext(form, ContextDetailList);

                    _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, ResponseID.ToString(), form, SurveyAnswer, false, false, 0, SurveyHelper.GetDecryptUserId(Session["UserId"].ToString()));
                }
                catch (Exception ex)
                {
                    // do nothing so that processing
                    // can continue
                }
            }
            else
            {
                SurveyAnswer.XML        = SurveyResponseXML.CreateResponseDocument(xdoc, SurveyAnswer.XML);//, RequiredList);
                this.RequiredList       = SurveyResponseXML._RequiredList;
                Session["RequiredList"] = SurveyResponseXML._RequiredList;
                form.RequiredFieldsList = RequiredList;
                _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, SurveyAnswer.ResponseId, form, SurveyAnswer, false, false, 0, SurveyHelper.GetDecryptUserId(Session["UserId"].ToString()));
            }


            return(RedirectToAction(Epi.Web.MVC.Constants.Constant.INDEX, Epi.Web.MVC.Constants.Constant.SURVEY_CONTROLLER, new { responseid = ResponseID, PageNumber = 1, surveyid = surveyInfoModel.SurveyId }));
        }
コード例 #12
0
ファイル: HomeController.cs プロジェクト: fgma75/epiinfo
        public ActionResult Index(Epi.Web.MVC.Models.SurveyInfoModel surveyModel)
        {
            try
            {
                bool IsMobileDevice = this.Request.Browser.IsMobileDevice;

                if (IsMobileDevice == false)
                {
                    IsMobileDevice = Epi.Web.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString());
                }

                FormsAuthentication.SetAuthCookie("BeginSurvey", false);



                Session["RootResponseId"] = surveyModel.ResponseId;
                string ResponseID = surveyModel.ResponseId; //string.Empty;
                //object tempDataValue;

                //if (TempData.TryGetValue(Epi.Web.MVC.Constants.Constant.RESPONSE_ID, out tempDataValue))
                //{
                //    ResponseID = (string)tempDataValue;
                //}
                //else
                //{

                //}

                Epi.Web.Common.DTO.SurveyAnswerDTO SurveyAnswer = _isurveyFacade.CreateSurveyAnswer(surveyModel.SurveyId, ResponseID.ToString());

                Epi.Web.Common.Message.UserAuthenticationResponse AuthenticationResponse = _isurveyFacade.GetAuthenticationResponse(ResponseID.ToString());

                string strPassCode = Epi.Web.MVC.Utility.SurveyHelper.GetPassCode();
                if (string.IsNullOrEmpty(AuthenticationResponse.PassCode))
                {
                    //_isurveyFacade.UpdatePassCode(ResponseID.ToString(),  TempData["PassCode"].ToString());
                    _isurveyFacade.UpdatePassCode(ResponseID.ToString(), surveyModel.PassCode);
                }


                Epi.Web.Common.Message.SurveyAnswerResponse SurveyAnswerResponse = _isurveyFacade.GetSurveyAnswerResponse(ResponseID);
                SurveyAnswer = SurveyAnswerResponse.SurveyResponseList[0];
                SurveyInfoModel surveyInfoModel = GetSurveyInfo(SurveyAnswer.SurveyId);

                // set the survey answer to be production or test
                SurveyAnswer.IsDraftMode = surveyInfoModel.IsDraftMode;
                XDocument xdoc = XDocument.Parse(surveyInfoModel.XML);

                // MvcDynamicForms.Form form = _isurveyFacade.GetSurveyFormData(SurveyAnswer.SurveyId, 1, SurveyAnswer, IsMobileDevice, "homeController");
                MvcDynamicForms.Form form = _isurveyFacade.GetSurveyFormData(SurveyAnswer.SurveyId, 1, SurveyAnswer, IsMobileDevice, null);

                var _FieldsTypeIDs = from _FieldTypeID in
                                     xdoc.Descendants("Field")
                                     select _FieldTypeID;

                TempData["Width"] = form.Width + 100;

                XDocument xdocResponse = XDocument.Parse(SurveyAnswer.XML);

                XElement ViewElement = xdoc.XPathSelectElement("Template/Project/View");
                string   checkcode   = ViewElement.Attribute("CheckCode").Value.ToString();

                form.FormCheckCodeObj = form.GetCheckCodeObj(xdoc, xdocResponse, checkcode);

                ///////////////////////////// Execute - Record Before - start//////////////////////
                Dictionary <string, string> ContextDetailList = new Dictionary <string, string>();
                EnterRule FunctionObject_B = (EnterRule)form.FormCheckCodeObj.GetCommand("level=record&event=before&identifier=");
                if (FunctionObject_B != null && !FunctionObject_B.IsNull())
                {
                    try
                    {
                        SurveyAnswer.XML = CreateResponseDocument(xdoc, SurveyAnswer.XML);

                        form.RequiredFieldsList = this.RequiredList;
                        FunctionObject_B.Context.HiddenFieldList      = form.HiddenFieldsList;
                        FunctionObject_B.Context.HighlightedFieldList = form.HighlightedFieldsList;
                        FunctionObject_B.Context.DisabledFieldList    = form.DisabledFieldsList;
                        FunctionObject_B.Context.RequiredFieldList    = form.RequiredFieldsList;

                        FunctionObject_B.Execute();

                        // field list
                        form.HiddenFieldsList      = FunctionObject_B.Context.HiddenFieldList;
                        form.HighlightedFieldsList = FunctionObject_B.Context.HighlightedFieldList;
                        form.DisabledFieldsList    = FunctionObject_B.Context.DisabledFieldList;
                        form.RequiredFieldsList    = FunctionObject_B.Context.RequiredFieldList;


                        ContextDetailList = Epi.Web.MVC.Utility.SurveyHelper.GetContextDetailList(FunctionObject_B);
                        form = Epi.Web.MVC.Utility.SurveyHelper.UpdateControlsValuesFromContext(form, ContextDetailList);
                        SurveyAnswer.RecordBeforeFlag = true;
                        _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, ResponseID.ToString(), form, SurveyAnswer, false, false, 0);
                    }
                    catch (Exception ex)
                    {
                        // do nothing so that processing
                        // can continue
                    }
                }
                else
                {
                    SurveyAnswer.XML        = CreateResponseDocument(xdoc, SurveyAnswer.XML);
                    form.RequiredFieldsList = RequiredList;
                    _isurveyFacade.UpdateSurveyResponse(surveyInfoModel, SurveyAnswer.ResponseId, form, SurveyAnswer, false, false, 0);
                }

                SurveyAnswer = _isurveyFacade.GetSurveyAnswerResponse(SurveyAnswer.ResponseId).SurveyResponseList[0];

                ///////////////////////////// Execute - Record Before - End//////////////////////
                //string page;
                // return RedirectToAction(Epi.Web.Models.Constants.Constant.INDEX, Epi.Web.Models.Constants.Constant.SURVEY_CONTROLLER, new {id="page" });
                return(RedirectToAction(Epi.Web.MVC.Constants.Constant.INDEX, Epi.Web.MVC.Constants.Constant.SURVEY_CONTROLLER, new { responseid = ResponseID, PageNumber = 1 }));
            }
            catch (Exception ex)
            {
                Epi.Web.Utility.ExceptionMessage.SendLogMessage(ex, this.HttpContext);
                return(View(Epi.Web.MVC.Constants.Constant.EXCEPTION_PAGE));
            }
        }
コード例 #13
0
        public override string RenderHtml()
        {
            var    html       = new StringBuilder();
            var    inputName  = _form.FieldPrefix + _key;
            string ErrorStyle = string.Empty;
            // prompt label
            var prompt = new TagBuilder("label");

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

            StringBuilder StyleValues = new StringBuilder();

            StyleValues.Append(GetContolStyle(_fontstyle.ToString(), _promptTop.ToString(), _promptLeft.ToString(), null, Height.ToString(), _IsHidden));
            prompt.Attributes.Add("style", StyleValues.ToString());
            html.Append(prompt.ToString());

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

            // input element
            var txt = new TagBuilder("input");

            txt.Attributes.Add("name", inputName);
            txt.Attributes.Add("id", inputName);
            txt.Attributes.Add("type", "text");
            txt.Attributes.Add("data-role", "datebox");
            txt.Attributes.Add("data-options", "{\"mode\": \"timebox\" , \"themeInput\":\"e\" , \"themeButton\" : \"e\", \"pickPageButtonTheme\": \"e\", \"pickPageInputTheme\":\"e\", \"pickPageFlipButtonTheme\":\"a\", \"pickPageTheme\":\"e\"}");
            //txt.Attributes.Add("data-theme", "pickPageInputTheme");



            txt.Attributes.Add("value", Value);
            string InputFieldStyle = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);

            //if Pattern is empty and the control has after event then treat it like a text box
            //if (string.IsNullOrEmpty(Pattern))
            //{
            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                // txt.Attributes.Add("onblur", "return " + _key + "_after(this.id);"); //After
                txt.Attributes.Add("onchange", "return " + _key + "_after(this.id);"); //After
            }
            //}
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);

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

            ////////////Check code end//////////////////

            if (_MaxLength.ToString() != "0" && !string.IsNullOrEmpty(_MaxLength.ToString()))
            {
                txt.Attributes.Add("MaxLength", _MaxLength.ToString());
            }
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

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

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

            //if (_IsDisabled)
            //{
            //    txt.Attributes.Add("disabled", "disabled");
            //}
            //todo: add validation
            //txt.Attributes.Add("class", GetControlClass(Value));

            if (_isRequired == true)
            {
                //txt.Attributes.Add("class", "validate[custom[time],required] text-input datepicker");
                txt.Attributes.Add("class", "validate[required,custom[time]] text-input datepicker");

                txt.Attributes.Add("data-prompt-position", "topLeft:15");
            }
            else
            {
                txt.Attributes.Add("class", "validate[custom[time]] text-input datepicker");
                txt.Attributes.Add("data-prompt-position", "topLeft:15");
            }

            //if (ReadOnly)
            //    {
            //    txt.Attributes.Add("disabled", "disabled");
            //    }
            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));
            }

            txt.Attributes.Add("style", "" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle + InputFieldStyle);

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

            //if (ReadOnly)
            //{
            //    var scriptReadOnlyText = new TagBuilder("script");
            //    scriptReadOnlyText.InnerHtml = "$(function(){$('#" + inputName + "').attr('disabled','disabled')});";
            //    html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));
            //}
            //if (!string.IsNullOrEmpty(Pattern))
            //{
            //    // adding scripts for date picker
            //    var scripttimePicker = new TagBuilder("script");
            //    //scriptDatePicker.InnerHtml = "$(function() { $('#" + inputName + "').datepicker({changeMonth: true,changeYear: true});});";
            //    /*Checkcode control after event...for datepicker, the onblur event fires on selecting a date from calender. Since the datepicker control itself is tied to after event which was firing before the datepicker
            //     textbox is populated the comparison was not working. For this reason, the control after steps are interjected inside datepicker onClose event, so the after event is fired when the datepicker is populated
            //     */
            //    if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            //    {
            //        //scriptDatePicker.InnerHtml = "$('#" + inputName + "').datepicker({onClose:function(){" + _key + "_after();},changeMonth:true,changeYear:true});";
            //        //Note: datepicker seems to have a command inst.input.focus(); (I think) called after the onClose callback which resets the focus to the original input element. I'm wondering if there is way round this with bind().
            //        //http://stackoverflow.com/questions/7087987/change-the-focus-on-jqueryui-datepicker-on-close

            //        if (Pattern == "HH:MM:SS AMPM")
            //        {
            //            scripttimePicker.InnerHtml = "$('#" + inputName + "').timepicker({onClose:function(){setTimeout(" + _key + "_after,100);},ampm : true, showSecond:true,timeFormat: 'hh:mm:ss TT'});";
            //        }
            //        else
            //        {
            //            scripttimePicker.InnerHtml = "$('#" + inputName + "').timepicker({onClose:function(){setTimeout(" + _key + "_after,100);}, showSecond:true,timeFormat: 'hh:mm:ss'});";
            //        }

            //    }
            //    else
            //    {
            //        if (Pattern == "HH:MM:SS AMPM")
            //        {
            //            scripttimePicker.InnerHtml = "$('#" + inputName + "').timepicker({ampm : true, showSecond:true,timeFormat: 'hh:mm:ss TT'});";
            //        }
            //        else
            //        {
            //            scripttimePicker.InnerHtml = "$('#" + inputName + "').timepicker({showSecond:true,timeFormat: 'hh:mm:ss'});";
            //        }
            //    }

            //    html.Append(scripttimePicker.ToString(TagRenderMode.Normal));
            //}

            ////prevent date picker 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 (!IsValid)
            {
                wrapper.Attributes["class"] = _fieldWrapperClass + " TimePickerNotValid";
            }
            else
            {
                wrapper.Attributes["class"] = _fieldWrapperClass;
            }
            if (_IsHidden)
            {
                wrapper.Attributes["style"] = "display:none";
            }
            wrapper.Attributes["id"] = inputName + "_fieldWrapper";
            wrapper.InnerHtml        = html.ToString();
            return(wrapper.ToString());
        }
コード例 #14
0
        public ActionResult Index(string surveyId, string addNewFormId, string editForm)
        {
            // Assign "editForm" parameter to a less confusing name.
            // editForm contains the responseId of the record being edited.
            string editResponseId = editForm;

            bool isNewRecord;

            int    orgId    = GetIntSessionValue(UserSession.Key.CurrentOrgId);
            int    userId   = GetIntSessionValue(UserSession.Key.UserId);
            string userName = GetStringSessionValue(UserSession.Key.UserName);

            SetSessionValue(UserSession.Key.FormValuesHasChanged, string.Empty);

            var editResponseIdFromSession = GetStringSessionValue(UserSession.Key.EditResponseId);

            if (string.IsNullOrEmpty(editResponseId) && editResponseIdFromSession != null)
            {
                editResponseId = editResponseIdFromSession;
            }

            if (!string.IsNullOrEmpty(editResponseId) && string.IsNullOrEmpty(addNewFormId))
            {
                // -------------------------------
                //      Edit Existing Record
                // -------------------------------
                isNewRecord = false;
                SetSessionValue(UserSession.Key.RootResponseId, editResponseId);

                SetSessionValue(UserSession.Key.IsEditMode, true);
                SurveyAnswerDTO surveyAnswerDTO = GetSurveyAnswer(editResponseId, GetStringSessionValue(UserSession.Key.RootFormId));

                SetSessionValue(UserSession.Key.RequestedViewId, surveyAnswerDTO.ViewId);

                surveyAnswerDTO.RecoverLastRecordVersion = GetBoolSessionValue(UserSession.Key.RecoverLastRecordVersion);

                RemoveSessionValue(UserSession.Key.RecoverLastRecordVersion);
                return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = editResponseId, PageNumber = 1, surveyid = surveyAnswerDTO.SurveyId, Edit = "Edit" }));
            }

            // -------------------------------
            //      Add New Record
            // -------------------------------
            isNewRecord = true;
            SetSessionValue(UserSession.Key.IsEditMode, false);
            bool isMobileDevice = this.Request.Browser.IsMobileDevice;


            if (isMobileDevice == false)
            {
                isMobileDevice = Epi.Cloud.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString());
            }

            FormsAuthentication.SetAuthCookie("BeginSurvey", false);

            //create the responseid
            Guid responseId = Guid.NewGuid();

            TempData[TempDataKeys.ResponseId] = responseId.ToString();

            // create the first survey response
            // Epi.Cloud.Common.DTO.SurveyAnswerDTO SurveyAnswer = _isurveyFacade.CreateSurveyAnswer(surveyModel.SurveyId, ResponseID.ToString());
            SetSessionValue(UserSession.Key.RootFormId, addNewFormId);
            var rootResponseId = responseId;

            SetSessionValue(UserSession.Key.RootResponseId, rootResponseId);

            var responseContext = InitializeResponseContext(formId: addNewFormId, responseId: responseId.ToString(), isNewRecord: true) as ResponseContext;

            SurveyAnswerDTO surveyAnswer = _surveyFacade.CreateSurveyAnswer(responseContext);

            surveyId = /*FromURL*/ surveyId ?? surveyAnswer.SurveyId;

            // Initialize the Metadata Accessor
            MetadataAccessor.CurrentFormId = surveyId;

            MvcDynamicForms.Form form            = _surveyFacade.GetSurveyFormData(surveyAnswer.SurveyId, 1, surveyAnswer, isMobileDevice);
            SurveyInfoModel      surveyInfoModel = form.SurveyInfo.ToFormInfoModel();

            MetadataAccessor metadataAccessor = form.SurveyInfo as MetadataAccessor;

            // set the survey answer to be production or test
            surveyAnswer.IsDraftMode = form.SurveyInfo.IsDraftMode;

            TempData[TempDataKeys.Width] = form.Width + 100;

            string checkcode = MetadataAccessor.GetFormDigest(surveyId).CheckCode;

            form.FormCheckCodeObj = form.GetCheckCodeObj(metadataAccessor.GetFieldDigests(surveyId), surveyAnswer.ResponseDetail, checkcode);

            ///////////////////////////// Execute - Record Before - start//////////////////////
            Dictionary <string, string> contextDetailList = new Dictionary <string, string>();
            EnterRule             functionObject_B        = (EnterRule)form.FormCheckCodeObj.GetCommand("level=record&event=before&identifier=");
            SurveyResponseBuilder surveyResponseBuilder   = new SurveyResponseBuilder(_requiredList);

            if (functionObject_B != null && !functionObject_B.IsNull())
            {
                try
                {
                    PageDigest[] pageDigests    = form.MetadataAccessor.GetCurrentFormPageDigests();
                    var          responseDetail = surveyAnswer.ResponseDetail;

                    responseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigests);
                    SetSessionValue(UserSession.Key.RequiredList, surveyResponseBuilder.RequiredList);
                    _requiredList           = surveyResponseBuilder.RequiredList;
                    form.RequiredFieldsList = _requiredList;
                    functionObject_B.Context.HiddenFieldList      = form.HiddenFieldsList;
                    functionObject_B.Context.HighlightedFieldList = form.HighlightedFieldsList;
                    functionObject_B.Context.DisabledFieldList    = form.DisabledFieldsList;
                    functionObject_B.Context.RequiredFieldList    = form.RequiredFieldsList;

                    functionObject_B.Execute();

                    // field list
                    form.HiddenFieldsList      = functionObject_B.Context.HiddenFieldList;
                    form.HighlightedFieldsList = functionObject_B.Context.HighlightedFieldList;
                    form.DisabledFieldsList    = functionObject_B.Context.DisabledFieldList;
                    form.RequiredFieldsList    = functionObject_B.Context.RequiredFieldList;


                    contextDetailList = Epi.Cloud.MVC.Utility.SurveyHelper.GetContextDetailList(functionObject_B);
                    form = Epi.Cloud.MVC.Utility.SurveyHelper.UpdateControlsValuesFromContext(form, contextDetailList);

                    _surveyFacade.UpdateSurveyResponse(surveyInfoModel,
                                                       responseId.ToString(),
                                                       form,
                                                       surveyAnswer,
                                                       false,
                                                       false,
                                                       0,
                                                       orgId,
                                                       userId,
                                                       userName);
                }
                catch (Exception ex)
                {
                    // do nothing so that processing
                    // can continue
                }
            }
            else
            {
                PageDigest[] pageDigestArray = metadataAccessor.GetPageDigests(surveyInfoModel.SurveyId);

                surveyAnswer.ResponseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigestArray);

                _requiredList = surveyResponseBuilder.RequiredList;
                SetSessionValue(UserSession.Key.RequiredList, surveyResponseBuilder.RequiredList);
                form.RequiredFieldsList = _requiredList;
            }

            ///////////////////////////// Execute - Record Before - End//////////////////////
            return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = responseId, PageNumber = 1, surveyid = surveyInfoModel.SurveyId }));
        }
コード例 #15
0
        public ActionResult Index(string surveyId, string addNewFormId, string editForm, string cancel)
        {
            // Assign "editForm" parameter to a less confusing name.
            // editForm contains the responseId of the record being edited.
            string editResponseId = editForm;

            int    userId         = GetIntSessionValue(UserSession.Key.UserId);
            string userName       = GetStringSessionValue(UserSession.Key.UserName);
            bool   isMobileDevice = this.Request.Browser.IsMobileDevice;

            FormsAuthentication.SetAuthCookie("BeginSurvey", false);
            bool isEditMode = false;

            if (isMobileDevice == true)
            {
                isMobileDevice = Epi.Cloud.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString());
            }
            bool isAndroid = this.Request.UserAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0;

            if (!string.IsNullOrEmpty(/*FromURL*/ cancel))
            {
                int pageNumber;
                int.TryParse(/*FromURL*/ cancel, out pageNumber);
                Dictionary <string, int> surveyPagesList = GetSessionValue <Dictionary <string, int> >(UserSession.Key.RelateButtonPageId);
                if (surveyPagesList != null)
                {
                    pageNumber = surveyPagesList[this.Request.Form["Parent_Response_Id"].ToString()];
                }

                return(RedirectToRoute(new { Controller = "Survey", Action = "Index", responseid = this.Request.Form["Parent_Response_Id"].ToString(), PageNumber = pageNumber }));
            }
            if (string.IsNullOrEmpty(/*FromURL*/ editResponseId) && string.IsNullOrEmpty(/*FromURL*/ addNewFormId) && !IsSessionValueNull(UserSession.Key.EditResponseId))
            {
                editResponseId = GetStringSessionValue(UserSession.Key.EditResponseId);
            }

            if (!string.IsNullOrEmpty(editResponseId))
            {
                if (IsSessionValueNull(UserSession.Key.RootResponseId))
                {
                    SetSessionValue(UserSession.Key.RootResponseId, editResponseId);
                }

                isEditMode = true;
                SetSessionValue(UserSession.Key.IsEditMode, isEditMode);

                SurveyAnswerDTO surveyAnswer = GetSurveyAnswer(editResponseId, GetStringSessionValue(UserSession.Key.RootFormId));
                if (!IsSessionValueNull(UserSession.Key.RecoverLastRecordVersion))
                {
                    surveyAnswer.RecoverLastRecordVersion = GetBoolSessionValue(UserSession.Key.RecoverLastRecordVersion);
                }
                //   string childRecordId = GetChildRecordId(surveyAnswer);
                //return RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = surveyAnswer.ParentResponseId, PageNumber = 1, Edit = "Edit" });
                return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = editResponseId, PageNumber = 1, Edit = "Edit" }));
            }

            //create the responseid
            Guid responseId = Guid.NewGuid();

            if (IsSessionValueNull(UserSession.Key.RootResponseId))
            {
                SetSessionValue(UserSession.Key.RootResponseId, responseId);
            }

            var rootResponseId = GetStringSessionValue(UserSession.Key.RootResponseId);

            TempData[TempDataKeys.ResponseId] = responseId.ToString();

            int orgId = GetIntSessionValue(UserSession.Key.CurrentOrgId);

            var responseContext = InitializeResponseContext(formId: /*FromURL*/ addNewFormId, responseId: responseId.ToString(), parentResponseId: this.Request.Form["Parent_Response_Id"].ToString(), isNewRecord: !isEditMode);

            // create the first survey response
            SurveyAnswerDTO          surveyAnswerDTO  = _surveyFacade.CreateSurveyAnswer(responseContext);
            List <FormsHierarchyDTO> formsHierarchy   = GetFormsHierarchy();
            SurveyInfoModel          surveyInfoModel  = GetSurveyInfo(surveyAnswerDTO.SurveyId, formsHierarchy);
            MetadataAccessor         metadataAccessor = surveyInfoModel as MetadataAccessor;

            // set the survey answer to be production or test
            surveyAnswerDTO.IsDraftMode = surveyInfoModel.IsDraftMode;

            MvcDynamicForms.Form form = _surveyFacade.GetSurveyFormData(surveyAnswerDTO.SurveyId, 1, surveyAnswerDTO, isMobileDevice, null, formsHierarchy, isAndroid);

            TempData[TempDataKeys.Width] = form.Width + 100;

            var    formDigest = metadataAccessor.GetFormDigest(surveyAnswerDTO.SurveyId);
            string checkcode  = formDigest.CheckCode;

            FormResponseDetail responseDetail = surveyAnswerDTO.ResponseDetail;

            form.FormCheckCodeObj = form.GetCheckCodeObj(MetadataAccessor.GetFieldDigests(surveyAnswerDTO.SurveyId), responseDetail, checkcode);

            ///////////////////////////// Execute - Record Before - start//////////////////////
            Dictionary <string, string> ContextDetailList = new Dictionary <string, string>();
            EnterRule             functionObject_B        = (EnterRule)form.FormCheckCodeObj.GetCommand("level=record&event=before&identifier=");
            SurveyResponseBuilder surveyResponseBuilder   = new SurveyResponseBuilder(_requiredList);

            if (functionObject_B != null && !functionObject_B.IsNull())
            {
                try
                {
                    PageDigest[] pageDigests = form.MetadataAccessor.GetCurrentFormPageDigests();
                    responseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigests);

                    SetSessionValue(UserSession.Key.RequiredList, surveyResponseBuilder.RequiredList);
                    _requiredList           = surveyResponseBuilder.RequiredList;
                    form.RequiredFieldsList = _requiredList;
                    functionObject_B.Context.HiddenFieldList      = form.HiddenFieldsList;
                    functionObject_B.Context.HighlightedFieldList = form.HighlightedFieldsList;
                    functionObject_B.Context.DisabledFieldList    = form.DisabledFieldsList;
                    functionObject_B.Context.RequiredFieldList    = form.RequiredFieldsList;

                    functionObject_B.Execute();

                    // field list
                    form.HiddenFieldsList      = functionObject_B.Context.HiddenFieldList;
                    form.HighlightedFieldsList = functionObject_B.Context.HighlightedFieldList;
                    form.DisabledFieldsList    = functionObject_B.Context.DisabledFieldList;
                    form.RequiredFieldsList    = functionObject_B.Context.RequiredFieldList;


                    ContextDetailList = SurveyHelper.GetContextDetailList(functionObject_B);
                    form = SurveyHelper.UpdateControlsValuesFromContext(form, ContextDetailList);

                    _surveyFacade.UpdateSurveyResponse(surveyInfoModel, responseId.ToString(), form, surveyAnswerDTO, false, false, 0, orgId, userId, userName);
                }
                catch (Exception ex)
                {
                    // do nothing so that processing
                    // can continue
                }
            }
            else
            {
                PageDigest[] pageDigestArray = form.MetadataAccessor.GetCurrentFormPageDigests();// metadataAccessor.GetPageDigests(surveyInfoModel.SurveyId);

                surveyAnswerDTO.ResponseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigestArray);

                _requiredList = surveyResponseBuilder.RequiredList;
                SetSessionValue(UserSession.Key.RequiredList, _requiredList);
                form.RequiredFieldsList = _requiredList;
                _surveyFacade.UpdateSurveyResponse(surveyInfoModel, surveyAnswerDTO.ResponseId, form, surveyAnswerDTO, false, false, 0, orgId, userId, userName);
            }

            surveyAnswerDTO = (SurveyAnswerDTO)formsHierarchy.SelectMany(x => x.ResponseIds).FirstOrDefault(z => z.ResponseId == surveyAnswerDTO.ResponseId);

            ///////////////////////////// Execute - Record Before - End//////////////////////
            return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = responseId, PageNumber = 1 }));
        }
コード例 #16
0
ファイル: Select.cs プロジェクト: fgma75/epiinfo
        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", "EpiLabel");
            prompt.Attributes.Add("Id", "label" + inputName);

            StringBuilder StyleValues = new StringBuilder();
            StyleValues.Append(GetControlStyle(_fontstyle.ToString(), _Prompttop.ToString(), _Promptleft.ToString(), null, Height.ToString(),_IsHidden));
            prompt.Attributes.Add("style", StyleValues.ToString());
            html.Append(prompt.ToString());

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

            //var select = new TagBuilder("select");
            TagBuilder select = null;
            if (this._choices.Count() < 200)
            {
                select = new TagBuilder("select");
            }
            else
            {
                var Value = _choices.FirstOrDefault(x => x.Value == true).Key;
                select = new TagBuilder("input");
                select.Attributes.Add("list", inputName + "_DataList");
                select.Attributes.Add("data-autofirst", "true");
                select.Attributes.Add("value", Value);
            }
            select.Attributes.Add("id", inputName);
            select.Attributes.Add("name", inputName);

            /*if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                select.Attributes.Add("onblur", "return " + _key + "_after();"); //After
            }
            if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
            {
                if( this.RelateCondition)
                {
                    select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + "null" + "','" + _key + "');" + _key + "_click();"); //click
                }
                else
                {
                    select.Attributes.Add("onchange", "return " + _key + "_click();"); //click
                }
            }
            else {
                if (this.RelateCondition)
                {
                    select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + "null"+ "','" + _key + "');"  ); //click
                }
            }
            if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            {
                select.Attributes.Add("onfocus", "return " + _key + "_before();"); //Before
            }*/
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);
            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {

                select.Attributes.Add("onblur", "return " + _key + "_after();"); //After
                // select.Attributes.Add("onchange", "return " + _key + "_after();"); //After
            }
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);
            if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            {

                select.Attributes.Add("onfocus", "return " + _key + "_before();"); //Before
            }
            EnterRule FunctionObjectClick = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + _key);

            if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
            {
                select.Attributes.Add("onclick", "return " + _key + "_click();"); //click
            }
            if (this.RelateCondition)
            {
                select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + SourceTable + "'," + "''" + ",'" + TextColumnName + "','" + FieldRelateCondition + "');"); //click

            }
            ////////////Check code end//////////////////
            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 (this._choices.Count() < 200)
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        select.Attributes.Add("class", GetControlClass() + "fix-me");
                    }
                    else
                    {
                        select.Attributes.Add("class", GetControlClass());
                    }

                    select.Attributes.Add("data-prompt-position", "topRight:10");
                }
                else
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        select.Attributes.Add("class", GetControlClass() + "fix-me awesomplete Search ");
                    }
                    else
                    {
                        select.Attributes.Add("class", GetControlClass() + " awesomplete Search");
                    }

                    select.Attributes.Add("data-prompt-position", "topRight:10");

                }
            }
            else
            {
                if (this._choices.Count() < 200)
                {
                    //select.Attributes.Add("class", GetControlClass() + "text-input fix-me");
                    if ((size.Width) > _ControlWidth)
                    {
                        select.Attributes.Add("class", GetControlClass() + "fix-me ");
                    }
                    else
                    {

                        select.Attributes.Add("class", GetControlClass());
                    }
                    select.Attributes.Add("data-prompt-position", "topRight:10");
                }
                else
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        select.Attributes.Add("class", GetControlClass() + "fix-me awesomplete Search");
                    }
                    else
                    {

                        select.Attributes.Add("class", GetControlClass() + " awesomplete Search");
                    }
                    select.Attributes.Add("data-prompt-position", "topRight:10");

                }

            }

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

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

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

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

            string InputFieldStyle = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());
            select.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _ControlWidth.ToString() + "px ; font-size:" + _ControlFontSize + "pt;" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle + ";" + InputFieldStyle);
            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));
                }
            if (this._choices.Count() > 200)
            {

                var scriptReadOnlyText = new TagBuilder("script");
                StringBuilder Script = new StringBuilder();
                Script.Append("$(window).load(function () {  ");
                //Script.Append(" $( '#" + inputName + "' ).next().css( 'width', '" + _ControlWidth.ToString() + "px' );  ");
                Script.Append(" $( '#" + inputName + "' ).next().css( 'left', '" + _left.ToString() + "px' );  ");
                Script.Append(" $( '#" + inputName + "' ).next().css( 'top', '" + (_top + 20).ToString() + "px' );  ");

                Script.Append("});");
                scriptReadOnlyText.InnerHtml = Script.ToString();
                html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));
            }

            // initial empty option
            if (this._choices.Count() < 200)
            {

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

            //options
            //Build codes relatecondition Script Object

            if (this._choices.Count() < 200 && this.SelectedValue.ToString() != "18")
            {
                switch (FieldTypeId.ToString())
                {
                    case "11":
                        foreach (var choice in _choices)
                        {
                            var opt = new TagBuilder("option");
                            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("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("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");

                            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;
                }
            }
            else
            {

                var datalist = new TagBuilder("datalist ");
                datalist.Attributes.Add("id", inputName + "_DataList");
                html.Append(datalist.ToString(TagRenderMode.StartTag));
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("value", choice.Key);
                    if (choice.Key == SelectedValue.ToString())
                    {
                        opt.SetInnerText(choice.Key);
                        opt.Attributes.Add("selected", "selected");
                    }
                    html.Append(opt.ToString());
                }

            }

            html.Append(select.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);
            wrapper.Attributes["class"] = _fieldWrapperClass;
            if (_IsHidden)
            {
                wrapper.Attributes["style"] = "display:none";

            }
            wrapper.Attributes["id"] = inputName + "_fieldWrapper";
            wrapper.InnerHtml = html.ToString();
            return wrapper.ToString();
        }
コード例 #17
0
        public override string RenderHtml()
        {
            var html         = new StringBuilder();
            var inputName    = _form.FieldPrefix + _key;
            var choicesList  = _choices.ToList();
            var choicesList1 = GetChoices(_ChoicesList);

            choicesList = choicesList1.ToList();
            var  selectedValue  = string.Empty;
            bool 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)
            {
                //IsHiddenStyle = "visibility:hidden";
                // IsHiddenStyle = "display:none";
            }
            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background:yellow";
            }



            for (int i = 0; i < choicesList.Count; i++)
            {
                double innerTop  = 0.0;
                double innerLeft = 0.0;
                string radId     = inputName + i;
                // if (Pattern != null && !string.IsNullOrEmpty(Pattern[0]))
                if ((Pattern.Count) == choicesList.Count)
                {
                    List <string> TopLeft = Pattern[i].ToString().Split(':').ToList();

                    if (TopLeft.Count > 0)
                    {
                        innerTop  = double.Parse(TopLeft[0]) * Height;
                        innerLeft = double.Parse(TopLeft[1]) * Width;
                    }
                }



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

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

                    Leftlbl.Attributes.Add("for", inputName);
                    //Leftlbl.Attributes.Add("class", _inputLabelClass);
                    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(choicesList[i].Key);
                    html.Append(Leftlbl.ToString());
                }

                // radio button input
                var rad = new TagBuilder("input");
                rad.Attributes.Add("type", "radio");
                rad.Attributes.Add("name", inputName);
                rad.Attributes.Add("class", inputName);
                // rad.Attributes.Add("onClick", "return document.getElementById('" + inputName + "').value = this.value;"); //After
                ////////////Check code start//////////////////
                EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);
                if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
                {
                    rad.Attributes.Add("onchange", "$('#" + inputName + "').val('" + i.ToString() + "');$('#" + inputName + "').parent().next().find('input[type=hidden]')[0].value='" + i.ToString() + "'; return " + _key + "_after();"); //After
                    //rad.Attributes.Add("onblur", "$('#" + inputName + "').val('" + i.ToString() + "');return " + _key + "_after();"); //After
                    //rad.Attributes.Add("onclick", "return " + _key + "_after();"); //After
                    IsAfterControl = true;
                }
                EnterRule FunctionObjectClick = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + _key);
                if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
                {
                    rad.Attributes.Add("onclick", "return " + _key + "_click();"); //click
                    IsAfterControl = true;
                }
                if (!IsAfterControl)
                {
                    rad.Attributes.Add("onchange", "$('#" + inputName + "').val('" + i.ToString() + "');"); //click
                }

                ////////////Check code end//////////////////
                rad.SetInnerText(choicesList[i].Key);
                rad.Attributes.Add("value", i.ToString());
                rad.Attributes.Add("style", IsHiddenStyle);
                if (_IsDisabled)
                {
                    rad.Attributes.Add("disabled", "disabled");
                }

                if (Value == i.ToString())
                {
                    selectedValue = Value;
                    rad.Attributes.Add("checked", "checked");
                }


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

                // checkbox label
                if (_showTextOnRight)
                {
                    var rightlbl = new TagBuilder("label");
                    rightlbl.Attributes.Add("for", inputName);
                    // rightlbl.Attributes.Add("class", _inputLabelClass);
                    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(choicesList[i].Key);
                    html.Append(rightlbl.ToString());
                }

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


            // add hidden tag, so that a value always gets sent for select tags
            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());
        }
コード例 #18
0
        public override string RenderHtml()
        {
            var html = new StringBuilder();

            var    inputName  = _form.FieldPrefix + _key;
            string ErrorStyle = string.Empty;



            //var Div = new TagBuilder("div");
            //Div.Attributes.Add("data-role", "fieldcontain");
            //html.Append(Div.ToString(TagRenderMode.StartTag));


            // prompt
            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);


            StringBuilder StyleValues = new StringBuilder();

            // StyleValues.Append(GetControlStyle(_fontstyle.ToString(), _Prompttop.ToString(), _Promptleft.ToString(), null, Height.ToString(), _IsHidden));
            // prompt.Attributes.Add("style", StyleValues.ToString());
            //StyleValues.Append(GetContolStyle(_fontstyle.ToString(), _Prompttop.ToString(), _Promptleft.ToString(), null, Height.ToString(), _IsHidden));
            //StyleValues.Append(GetContolStyle(_fontstyle.ToString(), null, null, null, null, _IsHidden));
            // prompt.Attributes.Add("style", StyleValues.ToString());
            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.SetInnerText("");
                html.Append(OuterDiv.ToString(TagRenderMode.StartTag));
            }
            if (this.IsAndroidfield)
            {
                var Div = new TagBuilder("div");
                Div.Attributes.Add("class", "arrow_icon");
                Div.SetInnerText("");
                html.Append(Div.ToString());
            }
            // error label
            if (!IsValid)
            {
                //Add new Error to the error Obj

                ErrorStyle = ";border-color: red";
            }

            // open select element
            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");
            }
            //string InputFieldStyle = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());
            //select.Attributes.Add("data-mini", "true");
            ////////////Check code start//////////////////
            EnterRule 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
            }
            EnterRule 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
            }
            EnterRule 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 (!string.IsNullOrEmpty(this.RelateCondition))
            {
                select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + _key + "');");  //click
            }
            ////////////Check code end//////////////////
            int    LargestChoiseLength = 0;
            string measureString       = "";

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

                    measureString = choise.Key.ToString();
                }
            }

            // LargestChoiseLength = LargestChoiseLength * _ControlFontSize;

            Font stringFont = new Font(ControlFontStyle, _ControlFontSize);

            SizeF size = new SizeF();

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



            // stringSize = (int) Graphics.MeasureString(measureString.ToString(), stringFont).Width;


            if (_IsRequired == 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", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _ControlWidth.ToString() + "px ; font-size:" + _ControlFontSize + "pt;" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle);
            select.Attributes.Add("style", "" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle);
            select.MergeAttributes(_inputHtmlAttributes);
            html.Append(select.ToString(TagRenderMode.StartTag));
            // If readonly then add the following jquery script to make the field disabled
            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));
            }

            // initial empty option
            if (ShowEmptyOption)
            {
                var opt = new TagBuilder("option");
                opt.Attributes.Add("value", null);
                opt.SetInnerText(EmptyOption);
                // opt.Attributes.Add("style", "" );
                html.Append(opt.ToString());
            }
            if (this.CodesList != null)
            {
                if (this.CodesList.Count() > 0)
                {
                    string Html = "";
                    var    ScriptRelateCondition = new TagBuilder("script");
                    foreach (var code in CodesList)
                    {
                        Html = "";
                        Html = "var " + code.Key.ToString() + "=[";
                        var json1 = JsonConvert.SerializeObject(code.Value);
                        foreach (var item in code.Value)
                        {
                            var values = item.Split('=');
                            Html = Html + "\"" + values[0] + "," + values[1].ToString().Replace("\"", "") + "\",";
                        }
                        Html = Html + "]; ";
                        ScriptRelateCondition.InnerHtml = ScriptRelateCondition.InnerHtml + Html.ToString();
                    }
                    html.Append(ScriptRelateCondition.ToString(TagRenderMode.Normal));
                    //var JasonObj =
                    // var jsonSerialiser = new JavaScriptSerializer();
                    var json = JsonConvert.SerializeObject(CodesList);
                }
            }
            // options

            switch (this.SelectType.ToString())
            {
            case "11":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    // opt.Attributes.Add("style", "" + InputFieldStyle);
                    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", "" + InputFieldStyle);
                    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", "" + InputFieldStyle);
                    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", "" + InputFieldStyle);
                    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;
            }

            // close select element
            html.Append(select.ToString(TagRenderMode.EndTag));
            //html.Append(Div.ToString(TagRenderMode.EndTag));
            // add hidden tag, so that a value always gets sent for select tags
            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["style"] = GetStyle( _IsHidden,  _IsHighlighted);

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