示例#1
0
        private void ToolboxCustomTrackBar_Paint(object sender, PaintEventArgs e)
        {
            //when i allow for scrolling into the TrackBar / Timeline, i'll want to repaint all the time
            backdropPanel.Location = new Point(Min, LabelHeight);
            backdropPanel.Width    = Width;
            backdropPanel.Height   = Height - LabelHeight;

            foreach (var panel in panels)
            {
                if (panel != backdropPanel)
                {
                    panel.Height = Height - LabelHeight;
                    panel.Width  = PanelWidth;
                }
            }

            minPanel.Location = new Point(SelectedMin - (PanelWidth / 2), backdropPanel.Location.Y);

            maxPanel.Location   = new Point((SelectedMax * Width / (Max - Min)) - 1, backdropPanel.Location.Y);
            valuePanel.Location = new Point((SelectedValue) * Width / (Max - Min), backdropPanel.Location.Y);

            minLabel.Location = new Point(minPanel.Location.X - (minLabel.Width / 2) + (minPanel.Width / 2), minPanel.Location.Y - LabelHeight);
            minLabel.Text     = SelectedMin.ToString();

            maxLabel.Location = new Point(SelectedMax - (maxLabel.Width / 2) + (maxPanel.Width / 2), backdropPanel.Location.Y - LabelHeight);
            maxLabel.Text     = SelectedMax.ToString();

            valueLabel.Location = new Point(SelectedValue - (valueLabel.Width / 2) + (valuePanel.Width / 2), backdropPanel.Location.Y - LabelHeight);
            valueLabel.Text     = SelectedValue.ToString();
        }
        /// <summary>
        /// IntData[0] - Power of rotor
        /// StringData[0]-Type of regulation
        /// !!!!!StringData[1] - Power of engine in STRING type
        /// </summary>
        /// <returns></returns>
        public override DataClass GetPowerData()
        {
            var result = new DataClass();

            result.IntData.Add(SelectedRotorPower);
            result.StringData.Add(SelectedValue.ToString()); //3
            result.StringData.Add(SelectedSpeedRegulator);   //4
            result.StringData.Add(SelectedSignal);           //5
            return(result);
        }
示例#3
0
        private void EnumComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var convertedValue = SelectedValue as EnumData;

            if (convertedValue != null)
            {
                return;
            }
            if (EnumType != null && !string.IsNullOrEmpty(SelectedValue.ToString()))
            {
                SelectedEnumValue = Convert.ToInt32(Enum.Parse(EnumType, SelectedValue.ToString()));
            }
        }
示例#4
0
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            if (e.Property == SelectedValueDP)
            {
                if (Editable == true)
                {
                    xValeur.Visibility       = System.Windows.Visibility.Visible;
                    xValeur.IsHitTestVisible = true;
                    xValeur.Background       = Brushes.White;
                }
                else
                {
                    xValeur.Visibility       = System.Windows.Visibility.Visible;
                    xValeur.IsHitTestVisible = false;
                    xValeur.ToolTip          = null;
                }

                if (Intitule == true)
                {
                    xIntitule.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    xIntitule.Visibility = System.Windows.Visibility.Collapsed;
                }

                String Objet         = "";
                String Propriete     = "";
                String TypePropriete = "";

                if (InfosBinding(e.Property, ref Objet, ref Propriete, ref TypePropriete))
                {
                    String pIntitule = DicIntitules.Intitule(Objet, Propriete);
                    xIntitule.Text = pIntitule + " :";

                    if (String.IsNullOrWhiteSpace(SelectedValue.ToString()) && (Editable == false))
                    {
                        xBase.Visibility = System.Windows.Visibility.Collapsed;
                    }

                    String ToolTip = DicIntitules.Info(Objet, Propriete);
                    if (!String.IsNullOrWhiteSpace(ToolTip))
                    {
                        xBase.ToolTip = ToolTip;
                    }
                }
            }

            base.OnPropertyChanged(e);
        }
示例#5
0
        private void UIXCombobox_SelectedValueChanged(object sender, EventArgs e)
        {
            String selectedValue = this.SelectedValue.ToString();

            Form frm = FindForm();


            foreach (Control ctr in frm.Controls)
            {
                if (ctr.Name == ControlId)
                {
                    ctr.Text = SelectedValue.ToString();
                }
            }
        }
 public IList <AutoCompleteDataItem <TOption> > GetOptionItems()
 {
     if (_optionDataItems != null)
     {
         if (FilterExpression != null && AllowFilter == true && SelectedValue != null)
         {
             return(_optionDataItems.Where(x => FilterExpression(x, SelectedValue?.ToString())).ToList());
         }
         else
         {
             return(_optionDataItems);
         }
     }
     else
     {
         return(new List <AutoCompleteDataItem <TOption> >());
     }
 }
示例#7
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();
        }
示例#8
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());
        }
示例#9
0
        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());
        }
示例#10
0
 public bool IsInitalized(bool isLoading)
 {
     return(isLoading || string.IsNullOrEmpty(SelectedValue?.ToString()));
 }
示例#11
0
 public Int32 GetLanguageLCID()
 {
     return(Localization.CultureByLCID.FirstOr(
                x => String.Equals(x.Value.CustomName, SelectedValue.ToString(), StringComparison.CurrentCultureIgnoreCase),
                new KeyValuePair <Int32, Culture>(Localization.DefaultCulture.LCID, Localization.DefaultCulture)).Key);
 }
示例#12
0
        public IEnumerable GetData()
        {
            var data = DataSource as IEnumerable;

            if (data != null)
            {
                return(data);
            }

            if (GetCache != null)
            {
                var cache = GetCache();
                if (cache != null)
                {
                    return(cache);
                }
            }

            var            idataSource = DataSource as IDataSource;
            DataSourceView view        = null;

            if (idataSource != null)
            {
                view = idataSource.GetView("Default");
            }
            else if (!string.IsNullOrEmpty(ProjectName) && !string.IsNullOrEmpty(TableName))
            {
                var type = BuildManager.GetType(ProjectName + "." + TableName + "JournalDataSourceView", false, true);
                if (type != null)
                {
                    view = (DataSourceView)Activator.CreateInstance(type);
                }
            }

            if (view != null)
            {
                var baseView = view as IDataSourceView;
                if (baseView != null && SelectedValue != null)
                {
                    baseView.SelectedRowKey = SelectedValue.ToString();
                }

                if (baseView != null && !string.IsNullOrEmpty(SelectMode))
                {
                    data = baseView.GetSelectIRow("mode=" + SelectMode);
                }
                else
                {
                    view.Select(
                        new DataSourceSelectArguments(),
                        delegate(IEnumerable dataSource) { data = dataSource; });
                }

                if (SetCache != null)
                {
                    var result = data.Cast <object>().ToList();
                    SetCache(result);
                    return(result);
                }

                return(data);
            }

            return(null);
        }
示例#13
0
        public override string RenderHtml()
        {
            var    html       = new StringBuilder();
            var    inputName  = _fieldPrefix + _key;
            string ErrorStyle = string.Empty;
            var    prompt     = new TagBuilder("label");

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

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

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

            //if (this.IsAndroidfield)
            //{

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

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

            var select = new TagBuilder("select");

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

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

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

            Font stringFont = new Font(ControlFontStyle, _ControlFontSize);

            SizeF size = new SizeF();

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

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

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

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

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


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

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

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

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

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

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

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

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

                        opt.SetInnerText(description);
                    }

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

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

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

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

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

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

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

            wrapper.Attributes["id"] = inputName + "_fieldWrapper";
            wrapper.InnerHtml        = html.ToString();
            return(wrapper.ToString());
        }
示例#14
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());
        }
示例#15
0
        private async Task PostArticle()
        {
            if (postType == 0)
            {
                ArticleStatusId = 0;
            }
            else if (postType == 1)
            {
                if (user.IsInRole("Quản trị hệ thống"))
                {
                    ArticleStatusId = 2;
                }
                if (!user.IsInRole("Quản trị hệ thống"))
                {
                    ArticleStatusId = 1;
                }
            }
            else if (postType == -999)
            {
                NavigationManager.NavigateTo("/Admin/Article");
            }
            //Create new
            if (article.Id == null || article.Id == 0)
            {
                article.ArticleCategoryIds = SelectedValue.ToString();
                article.Id = await Repository.Article.ArticleInsert(Mapper.Map <CMS.Data.ModelEntity.Article>(article), UserManager.GetUserId(user), ArticleStatusId);
            }
            //Update
            if (article.Id != null && article.Id > 0)
            {
                try
                {   //Save Main Image
                    if (MainImages != null)
                    {
                        article.Image = await SaveMainImage((int)article.Id, MainImages);
                    }
                    //Save Upload File
                    if (lstAttachFile.Count > 0)
                    {
                        lstAttachFile.ForEach(x =>
                        {
                            x.ArticleId    = article.Id;
                            x.CreateDate   = DateTime.Now;
                            x.LastEditDate = DateTime.Now;
                            x.CreateBy     = UserManager.GetUserId(user);
                            x.LastEditBy   = UserManager.GetUserId(user);
                        });
                        var uploadResult = await Repository.Article.ArticleAttachInsert(lstAttachFile);

                        if (!uploadResult)
                        {
                            Logger.LogError("Upload File Error");
                        }
                    }

                    await Repository.Article.ArticleUpdate(Mapper.Map <CMS.Data.ModelEntity.Article>(article), UserManager.GetUserId(user), ArticleStatusId);

                    if (chkTopArticleCategory == true)
                    {
                        Repository.Article.ArticleTopCategorySave(article.Id.Value);
                    }
                    if (chkTopArticleCategoryParent == true)
                    {
                        Repository.Article.ArticleTopParentCategorySave(article.Id.Value);
                    }
                    //ToastMessage
                    toastService.ShowToast(ToastLevel.Success, "Cập nhật bài viết thành công", "Thành công");
                    //Noti for user

                    hubConnection.SendAsync("SendNotification", UserManager.GetUserId(user), "Gửi bài viết thành công", $"Bạn đã gửi bài viết <b>{article.Name}</b> tới tòa soạn thành công", "/Admin/Article", article.Image);
                    //Noti for sectary
                    var modelfilter = new AccountSearchFilter();
                    modelfilter.RoleId      = Guid.Parse("EF289F43-08FD-4C16-9F82-498BC8D1CD85"); // Thư kí
                    modelfilter.PageSize    = 100;
                    modelfilter.CurrentPage = 1;
                    modelfilter.Active      = true;
                    var lstProfielSec = await Repository.AspNetUsers.GetLstUsersPaging(modelfilter);

                    if (lstProfielSec != null && lstProfielSec.Items.Count > 0)
                    {
                        foreach (var p in lstProfielSec.Items)
                        {
                            hubConnection.SendAsync("SendNotification", p.Id, "Bài viết mới gửi", $"Bài viết {article.Name} đã được {user.Identity.Name} gửi tới tòa soạn chờ sơ duyệt", "/Admin/Article", article.Image);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //ToastMessage
                    toastService.ShowToast(ToastLevel.Error, $"Có lỗi trong quá trình cập nhật {ex.ToString()}", "Lỗi");
                }
            }
            //NavigationManager.NavigateTo("/Admin/Article");
        }