示例#1
0
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write("<div class='propertyItem'><div class='propertyItemheader'>" + ui.Text("dataBaseDatatype") + "</div>");
            _dropdownlist.RenderControl(writer);
            writer.Write("<br style='clear: both'/></div>");

            List <KeyValuePair <int, String> > _prevalues = PrevaluesAsKeyValuePairList;

            if (_prevalues.Count > 0)
            {
                writer.Write("<div class='propertyItem'><table style='width: 100%' id=\"prevalues\">");
                writer.Write("<tr class='header'><th style='width: 15%'>Text</th><td colspan='2'>Value</td></tr>");

                foreach (KeyValuePair <int, String> item in _prevalues)
                {
                    writer.Write("<tr class=\"row\"><td class=\"text\">" + item.Value + "</td><td class=\"value\"> " + item.Key.ToString() + "</td><td><a onclick='javascript:return ConfirmPrevalueDelete();' href='?id=" + _datatype.DataTypeDefinitionId + "&delete=" + item.Key.ToString() + "'>" + ui.Text("delete") + "</a> <span class=\"handle\" style=\"cursor:move\">sort<span></td></tr>");
                }
                writer.Write("</table><br style='clear: both'/></div>");
            }

            writer.Write("<div class='propertyItem'><div class='propertyItemheader'>" + ui.Text("addPrevalue") + "</div>");
            _textbox.RenderControl(writer);
            writer.Write("<br style='clear: both'/></div>");

            _tbhidden.RenderControl(writer);
        }
示例#2
0
        protected override void Render(HtmlTextWriter writer)
        {
            writer.WriteLine("<table>");
            writer.WriteLine("<tr><td colspan='2'>Database datatype</td><td>");
            _dropdownlist.RenderControl(writer);
            writer.Write("</td></tr>");
            writer.Write("<tr><th>Value</th><th colspan='2'>Text</th></tr>");
            SortedList _prevalues = Prevalues;

            foreach (string key in _prevalues.Keys)
            {
                writer.Write("<tr><td> " + key + "</td><td>" + _prevalues[key].ToString() + "</td><td><a href='?id=" + _datatype.DataTypeDefinitionId + "&delete=" + key.ToString() + "'>" + UI.Text("delete") + "</a></td></tr>");
            }
            writer.Write("<tr><th>Add prevalue</th><td colspan='2'>");
            _textbox.RenderControl(writer);
            writer.WriteLine("</td></tr>");
            writer.Write("</table>");
        }
示例#3
0
文件: ValueList.cs 项目: Ganon11/Rock
        /// <summary>
        /// Renders the base control.
        /// </summary>
        /// <param name="writer">The writer.</param>
        public virtual void RenderBaseControl( HtmlTextWriter writer )
        {
            Dictionary<string, string> definedValues = null;
            if ( DefinedTypeId.HasValue )
            {
                definedValues = new Dictionary<string, string>();
                new DefinedValueService( new RockContext() )
                    .GetByDefinedTypeId( DefinedTypeId.Value )
                    .ToList()
                    .ForEach( v => definedValues.Add( v.Id.ToString(), v.Value ) );
            }
            else if ( CustomValues != null )
            {
                definedValues = CustomValues;
            }

            writer.AddAttribute( HtmlTextWriterAttribute.Class, "value-list" );
            writer.RenderBeginTag( HtmlTextWriterTag.Span );
            writer.WriteLine();

            _hfValue.RenderControl( writer );
            writer.WriteLine();

            StringBuilder valueHtml = new StringBuilder();
            valueHtml.Append( @"<div class=""controls controls-row form-control-group"">");
            if ( definedValues != null )
            {
                valueHtml.Append( @"<select class=""form-control input-width-lg js-value-list-input""><option value=""""></option>" );
                foreach ( var definedValue in definedValues )
                {
                    valueHtml.AppendFormat( @"<option value=""{0}"">{1}</option>", definedValue.Key, definedValue.Value );
                }
                valueHtml.Append( @"</select>" );
            }
            else
            {
                valueHtml.AppendFormat( @"<input class=""form-control input-width-lg js-value-list-input"" type=""text"" placeholder=""{0}""></input>", ValuePrompt );
            }
            valueHtml.Append( @"<a href=""#"" class=""btn btn-sm btn-danger value-list-remove""><i class=""fa fa-minus-circle""></i></a></div>" );

            var hfValueHtml = new HtmlInputHidden();
            hfValueHtml.AddCssClass( "js-value-list-html" );
            hfValueHtml.Value = valueHtml.ToString();
            hfValueHtml.RenderControl( writer );

            writer.AddAttribute( HtmlTextWriterAttribute.Class, "value-list-rows" );
            writer.RenderBeginTag( HtmlTextWriterTag.Span );
            writer.WriteLine();

            string[] values = this.Value.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
            foreach ( string value in values )
            {
                writer.AddAttribute( HtmlTextWriterAttribute.Class, "controls controls-row form-control-group" );
                writer.RenderBeginTag( HtmlTextWriterTag.Div );
                writer.WriteLine();

                if ( definedValues != null )
                {
                    DropDownList ddl = new DropDownList();
                    ddl.AddCssClass( "form-control input-width-lg js-value-list-input" );
                    ddl.DataTextField = "Value";
                    ddl.DataValueField = "Key";
                    ddl.DataSource = definedValues;
                    ddl.DataBind();
                    ddl.Items.Insert( 0, new ListItem( string.Empty, string.Empty ) );
                    ddl.SelectedValue = value;
                    ddl.RenderControl( writer );
                }
                else
                {
                    writer.AddAttribute( HtmlTextWriterAttribute.Class, "form-control input-width-lg js-value-list-input" );
                    writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
                    writer.AddAttribute( "placeholder", ValuePrompt );
                    writer.AddAttribute( HtmlTextWriterAttribute.Value, value );
                    writer.RenderBeginTag( HtmlTextWriterTag.Input );
                    writer.RenderEndTag();
                }

                writer.Write( " " );
                writer.WriteLine();

                // Write Remove Button
                writer.AddAttribute( HtmlTextWriterAttribute.Href, "#" );
                writer.AddAttribute( HtmlTextWriterAttribute.Class, "btn btn-sm btn-danger value-list-remove" );
                writer.RenderBeginTag( HtmlTextWriterTag.A );
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-minus-circle");
                writer.RenderBeginTag( HtmlTextWriterTag.I );
                writer.RenderEndTag();
                writer.RenderEndTag();
                writer.WriteLine();

                writer.RenderEndTag();
                writer.WriteLine();

            }

            writer.RenderEndTag();
            writer.WriteLine();

            writer.AddAttribute( HtmlTextWriterAttribute.Class, "actions" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );

            writer.AddAttribute( HtmlTextWriterAttribute.Class, "btn btn-action btn-xs value-list-add" );
            writer.AddAttribute( HtmlTextWriterAttribute.Href, "#" );
            writer.RenderBeginTag( HtmlTextWriterTag.A );
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-plus-circle");
            writer.RenderBeginTag( HtmlTextWriterTag.I );

            writer.RenderEndTag();
            writer.RenderEndTag();
            writer.RenderEndTag();
            writer.WriteLine();

            writer.RenderEndTag();
            writer.WriteLine();

            RegisterClientScript();
        }
示例#4
0
        protected override void RenderFooter(HtmlTextWriter writer) {
            writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "4px");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            DropDownList zonesDropDownList = new DropDownList();
            zonesDropDownList.ClientIDMode = ClientIDMode.AutoID;
            zonesDropDownList.ID = ZonesID;

            // Populate the DropDownList
            if (DesignMode) {
                // Add sample zone to dropdown
                zonesDropDownList.Items.Add(SR.GetString(SR.Zone_SampleHeaderText));
            }
            else {
                if (WebPartManager != null && WebPartManager.Zones != null) {
                    foreach (WebPartZoneBase zone in WebPartManager.Zones) {
                        if (zone.AllowLayoutChange) {
                            Debug.Assert(!String.IsNullOrEmpty(zone.ID));
                            ListItem item = new ListItem(zone.DisplayTitle, zone.ID);
                            if (String.Equals(zone.ID, _selectedZoneID, StringComparison.OrdinalIgnoreCase)) {
                                item.Selected = true;
                            }
                            zonesDropDownList.Items.Add(item);
                        }
                    }
                }
            }

            LabelStyle.AddAttributesToRender(writer, this);
            // Only render the "for" attribute if we are going to render the associated DropDownList (VSWhidbey 541458)
            if (zonesDropDownList.Items.Count > 0) {
                writer.AddAttribute(HtmlTextWriterAttribute.For, zonesDropDownList.ClientID);
            }
            writer.RenderBeginTag(HtmlTextWriterTag.Label);
            writer.Write(SelectTargetZoneText);
            writer.RenderEndTag();

            // Render &nbsp; before the DropDownList (VSWhidbey 77709)
            writer.Write("&nbsp;");

            zonesDropDownList.ApplyStyle(EditUIStyle);
            // Do not render empty DropDownList (VSWhidbey 534498)
            if (zonesDropDownList.Items.Count > 0) {
                zonesDropDownList.RenderControl(writer);
            }

            writer.Write("&nbsp;");

            RenderVerbs(writer);

            writer.RenderEndTag();  // Div
        }
示例#5
0
        /// <summary>
        /// Renders the entity fields controls.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="filterControl">The filter control.</param>
        /// <param name="writer">The writer.</param>
        /// <param name="entityFields">The entity fields.</param>
        /// <param name="ddlEntityField">The DDL entity field.</param>
        /// <param name="propertyControls">The property controls.</param>
        /// <param name="propertyControlsPrefix">The property controls prefix.</param>
        /// <param name="filterMode">The filter mode.</param>
        public void RenderEntityFieldsControls( Type entityType, FilterField filterControl, HtmlTextWriter writer, List<EntityField> entityFields,
            DropDownList ddlEntityField, List<Control> propertyControls, string propertyControlsPrefix, FilterMode filterMode )
        {
            string selectedEntityField = ddlEntityField.SelectedValue;

            writer.AddAttribute( "class", "row" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );

            bool entityFieldPickerIsHidden = filterMode == FilterMode.SimpleFilter;

            if ( entityFieldPickerIsHidden )
            {
                ddlEntityField.Style[HtmlTextWriterStyle.Display] = "none";
            }

            if ( !entityFieldPickerIsHidden )
            {
                writer.AddAttribute( "class", "col-md-3" );
                writer.RenderBeginTag( HtmlTextWriterTag.Div );
                ddlEntityField.AddCssClass( "entity-property-selection" );
                ddlEntityField.RenderControl( writer );
                writer.RenderEndTag();
            }
            else
            {
                // render it as hidden (we'll need the postback value)
                ddlEntityField.RenderControl( writer );
            }

            writer.AddAttribute( "class", entityFieldPickerIsHidden ? "col-md-12" : "col-md-9" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );

            if ( entityFieldPickerIsHidden && ddlEntityField.SelectedItem != null )
            {
                if ( filterControl.ShowCheckbox )
                {
                    // special case when a filter is a entity field filter: render the checkbox here instead of in FilterField.cs
                    filterControl.cbIncludeFilter.Text = ddlEntityField.SelectedItem.Text;
                    filterControl.cbIncludeFilter.RenderControl( writer );
                }
                else
                {
                    writer.AddAttribute( "class", "filterfield-label" );
                    writer.RenderBeginTag( HtmlTextWriterTag.Span );
                    writer.Write( ddlEntityField.SelectedItem.Text );
                    writer.RenderEndTag();
                }
            }

            // generate result for "none"
            StringBuilder sb = new StringBuilder();
            string lineFormat = @"
            case '{0}': {1}; break;";

            int fieldIndex = 0;
            sb.AppendFormat( lineFormat, fieldIndex, "result = ''" );
            fieldIndex++;

            // render empty row for "none"
            writer.AddAttribute( "class", "row field-criteria" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );
            writer.RenderEndTag();  // "row field-criteria"

            // render the controls for the selectedEntityField
            string controlId = string.Format( "{0}_{1}", propertyControlsPrefix, selectedEntityField );
            var control = propertyControls.FirstOrDefault( c => c.ID == controlId );
            if ( control != null )
            {
                if ( control is IAttributeAccessor )
                {
                    ( control as IAttributeAccessor ).SetAttribute( "data-entity-field-name", selectedEntityField );
                }

                control.RenderControl( writer );
            }

            // create a javascript block for all the possible entityFields which will get rendered once per entityType
            foreach ( var entityField in entityFields )
            {
                string clientFormatSelection = entityField.FieldType.Field.GetFilterFormatScript( entityField.FieldConfig, entityField.Title );

                if ( clientFormatSelection != string.Empty )
                {
                    sb.AppendFormat( lineFormat, entityField.Name, clientFormatSelection );
                }

                fieldIndex++;
            }

            writer.RenderEndTag();  // col-md-9 or col-md-12

            writer.RenderEndTag();  // "row"

            string scriptFormat = @"
            function {0}PropertySelection($content){{
            var selectedFieldName = $('select.entity-property-selection', $content).find(':selected').val();
            var $selectedContent = $('[data-entity-field-name=' + selectedFieldName + ']', $content)
            var result = '';
            switch(selectedFieldName) {{
            {1}
            }}
            return result;
            }}
            ";

            string script = string.Format( scriptFormat, entityType.Name, sb.ToString() );
            ScriptManager.RegisterStartupScript( filterControl, typeof( FilterField ), entityType.Name + "-property-selection", script, true );

            RegisterFilterCompareChangeScript( filterControl );
        }
示例#6
0
        /// <summary>
        /// Renders the entity fields controls.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="filterControl">The filter control.</param>
        /// <param name="writer">The writer.</param>
        /// <param name="entityFields">The entity fields.</param>
        /// <param name="groupedControls">The grouped controls.</param>
        /// <param name="ddlEntityField">The DDL entity field.</param>
        public void RenderEntityFieldsControls( Type entityType, FilterField filterControl, HtmlTextWriter writer, List<EntityField> entityFields, Dictionary<string, List<Control>> groupedControls, DropDownList ddlEntityField )
        {
            string selectedEntityField = ddlEntityField.SelectedValue;

            writer.AddAttribute( "class", "row js-filter-row" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );

            writer.AddAttribute( "class", "col-md-3" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );
            ddlEntityField.AddCssClass( "entity-property-selection" );
            ddlEntityField.RenderControl( writer );
            writer.RenderEndTag();

            StringBuilder sb = new StringBuilder();
            int i = 0;

            writer.AddAttribute( "class", "col-md-9" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );

            foreach ( var entityField in entityFields )
            {
                if ( entityField.Name != selectedEntityField )
                {
                    writer.AddStyleAttribute( HtmlTextWriterStyle.Display, "none" );
                }

                writer.AddAttribute( "class", "row field-criteria" );
                writer.RenderBeginTag( HtmlTextWriterTag.Div );

                var propertyControls = groupedControls[entityField.Name];
                if ( propertyControls.Count == 1 )
                {
                    writer.AddAttribute( "class", "col-md-1" );
                    writer.RenderBeginTag( HtmlTextWriterTag.Div );
                    writer.Write( "<span class='data-view-filter-label'>is</span>" );
                    writer.RenderEndTag();

                    writer.AddAttribute( "class", "col-md-11" );
                    writer.RenderBeginTag( HtmlTextWriterTag.Div );
                    propertyControls[0].RenderControl( writer );
                    writer.RenderEndTag();
                }
                else if ( propertyControls.Count == 2 )
                {
                    writer.AddAttribute( "class", "col-md-4" );
                    writer.RenderBeginTag( HtmlTextWriterTag.Div );
                    propertyControls[0].RenderControl( writer );
                    writer.RenderEndTag();

                    writer.AddAttribute( "class", "col-md-8" );
                    writer.RenderBeginTag( HtmlTextWriterTag.Div );
                    propertyControls[1].RenderControl( writer );
                    writer.RenderEndTag();
                }

                writer.RenderEndTag();  // row

                string clientFormatSelection = string.Empty;
                switch ( entityField.FilterFieldType )
                {
                    case SystemGuid.FieldType.TIME:
                    case SystemGuid.FieldType.DATE:
                        clientFormatSelection = string.Format( "result = '{0} ' + $('select', $selectedContent).find(':selected').text() + ( $('input', $selectedContent).filter(':visible').length ?  (' \\'' +  $('input', $selectedContent).filter(':visible').val()  + '\\'') : '' )", entityField.Title );
                        break;

                    case SystemGuid.FieldType.DECIMAL:
                    case SystemGuid.FieldType.INTEGER:
                    case SystemGuid.FieldType.TEXT:
                        clientFormatSelection = string.Format( "result = '{0} ' + $('select', $selectedContent).find(':selected').text() + ( $('input', $selectedContent).filter(':visible').length ?  (' \\'' +  $('input', $selectedContent).filter(':visible').val()  + '\\'') : '' )", entityField.Title );
                        break;

                    case SystemGuid.FieldType.MULTI_SELECT:
                        clientFormatSelection = string.Format( "var selectedItems = ''; $('input:checked', $selectedContent).each(function() {{ selectedItems += selectedItems == '' ? '' : ' or '; selectedItems += '\\'' + $(this).parent().text() + '\\'' }}); result = '{0} is ' + selectedItems ", entityField.Title );
                        break;

                    case SystemGuid.FieldType.DAY_OF_WEEK:
                    case SystemGuid.FieldType.SINGLE_SELECT:
                        clientFormatSelection = string.Format( "result = '{0} is ' + '\\'' + $('select', $selectedContent).find(':selected').text() + '\\''", entityField.Title );
                        break;
                }

                if ( clientFormatSelection != string.Empty )
                {
                    string lineFormat = @"
            case {0}: {1}; break;";

                    sb.AppendFormat( lineFormat, i, clientFormatSelection );
                }

                i++;
            }

            writer.RenderEndTag();  // col-md-9

            writer.RenderEndTag();  // row

            string scriptFormat = @"
    function {0}PropertySelection($content){{
        var sIndex = $('select.entity-property-selection', $content).find(':selected').index();
        var $selectedContent = $('div.field-criteria', $content).eq(sIndex);
        var result = '';
        switch(sIndex) {{
            {1}
        }}
        return result;
    }}
";

            string script = string.Format( scriptFormat, entityType.Name, sb.ToString() );
            ScriptManager.RegisterStartupScript( filterControl, typeof( FilterField ), entityType.Name + "-property-selection", script, true );

            script = @"
    $('select.entity-property-selection').change(function(){
        var $parentRow = $(this).closest('.js-filter-row');
        $parentRow.find('div.field-criteria').hide();
        $parentRow.find('div.field-criteria').eq($(this).find(':selected').index()).show();
    });";

            // only need this script once per page
            ScriptManager.RegisterStartupScript( filterControl.Page, filterControl.Page.GetType(), "entity-property-selection-change-script", script, true );

            RegisterFilterCompareChangeScript( filterControl );
        }
示例#7
0
        /// <summary>
        /// Writes the value controls.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="nameAndValue">The name and value.</param>
        /// <param name="values">The values.</param>
        private void WriteValueControls( HtmlTextWriter writer, string[] nameAndValue, Dictionary<string, string> values )
        {
            if ( values != null )
            {
                DropDownList ddl = new DropDownList();
                ddl.AddCssClass( "key-value-value form-control input-width-md js-key-value-input" );
                ddl.DataTextField = "Value";
                ddl.DataValueField = "Key";
                ddl.DataSource = values;
                ddl.DataBind();
                if ( nameAndValue.Length >= 2 )
                {
                    ddl.SelectedValue = nameAndValue[1];
                }
                ddl.RenderControl( writer );
            }
            else
            {
                writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-value form-control input-width-md js-key-value-input" );
                writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
                writer.AddAttribute( HtmlTextWriterAttribute.Value, nameAndValue.Length >= 2 ? nameAndValue[1] : string.Empty );
                writer.AddAttribute( "placeholder", ValuePrompt );
                writer.RenderBeginTag( HtmlTextWriterTag.Input );
                writer.RenderEndTag();
            }

            writer.Write( " " );
            writer.WriteLine();
        }
        private string DropDownPopulate(HttpContext context)
        {
            DropDownList list = new DropDownList();
            list.ID = "FoodUnitList";

            using (var conn = new SqlConnection("Server=(local);DataBase=Nutrition;Integrated Security=SSPI"))
            {
                using (var command = new SqlCommand("dbo.Food_Units_Get", conn)
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    command.Parameters.Add("@Food_Key", SqlDbType.Int);
                    command.Parameters["@Food_Key"].Value = context.Request.Params["FoodKey"];
                    conn.Open();
                    var reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                    list.DataSource = reader;
                    list.DataTextField = "Unit_Name";
                    list.DataValueField = "Unit_Key";
                    list.DataBind();
                    conn.Close();
                    using (var command2 = new SqlCommand("dbo.Food_Unit_Get", conn)
                    {
                        CommandType = CommandType.StoredProcedure
                    })
                    {
                        conn.Open();
                        command2.Parameters.Add("@Food_Key", SqlDbType.Int);
                        command2.Parameters["@Food_Key"].Value = context.Request.Params["FoodKey"];
                        // Create parameter with Direction as Output (and correct name and type)
                        SqlParameter outputIdParam = new SqlParameter("@Unit_Key", SqlDbType.Int)
                        {
                            Direction = ParameterDirection.Output
                        };

                        command2.CommandType = CommandType.StoredProcedure;
                        command2.Parameters.Add(outputIdParam);
                        command2.ExecuteNonQuery();
                        list.SelectedValue = outputIdParam.Value.ToString();
                        conn.Close();
                    }
                }
            }

            StringWriter theStringWriter = new StringWriter();
            HtmlTextWriter theHtmlTextWriter = new HtmlTextWriter(theStringWriter);

            // Render the table row control into the writer
            list.RenderControl(theHtmlTextWriter);

            // Return the string via the StringWriter
            return theStringWriter.ToString();
        }
示例#9
0
        /// <summary>
        /// Writes the key controls.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="nameAndValue">The name and value.</param>
        private void WriteKeyControls( HtmlTextWriter writer, string[] nameAndValue )
        {
            if ( CustomKeys != null && CustomKeys.Any() )
            {
                DropDownList ddl = new DropDownList();
                ddl.AddCssClass( "key-value-key form-control input-width-md js-key-value-input" );
                ddl.DataTextField = "Value";
                ddl.DataValueField = "Key";
                ddl.DataSource = CustomKeys;
                ddl.DataBind();
                if ( nameAndValue.Length >= 1 )
                {
                    ddl.SelectedValue = nameAndValue[0];
                }
                ddl.RenderControl( writer );
            }
            else
            {
                // Write Name
                writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-key form-control input-width-md js-key-value-input" );
                writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
                writer.AddAttribute( HtmlTextWriterAttribute.Value, nameAndValue.Length >= 1 ? nameAndValue[0] : string.Empty );
                writer.AddAttribute( "placeholder", KeyPrompt );
                writer.RenderBeginTag( HtmlTextWriterTag.Input );
                writer.RenderEndTag();
            }

            writer.Write( " " );
            writer.WriteLine();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int? foodKey = null;
            int? unitKey = null;
            this.tableHeader.Attributes.Add("nutritionhistorykey", Request.QueryString["Nutrition_History_Key"]);
            this.tableHeader.Attributes.Add("adddatefrom", Request.QueryString["Add_Date_From"]);
            this.tableHeader.Attributes.Add("adddateto", Request.QueryString["Add_Date_To"]);
            using (var conn = new SqlConnection("Server=(local);DataBase=Nutrition;Integrated Security=SSPI"))
            {
                using (var command = new SqlCommand("dbo.Nutrition_Profile_Entry_Get", conn)
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    conn.Open();
                    command.Parameters.Add("@User_Key", SqlDbType.Int);
                    command.Parameters["@User_Key"].Value = 1; //Hard-coded to my User_Key for now
                    command.Parameters.Add("@Nutrition_History_Key", SqlDbType.Int);
                    command.Parameters["@Nutrition_History_Key"].Value = Request.QueryString["Nutrition_History_Key"];
                    var reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                    if (reader.HasRows)
                    {
                        reader.Read();
                        foodKey = int.Parse(reader["Food_Key"].ToString());
                        unitKey = int.Parse(reader["Unit_Key"].ToString());
                        var cell = new TableHeaderCell { Text = reader["Name"].ToString(), ColumnSpan = 2 };
                        cell.Style.Add("border-bottom-width", "2px");
                        cell.Style.Add("border-bottom-style", "solid");
                        cell.Style.Add("border-bottom-color", "#8dbdd8");
                        tableHeader.Cells.Add(cell);

                        this.FoodQuantityDisplay.Value = reader["Quantity"].ToString();
                        DateTime datetime = DateTime.Parse(reader["Add_Date"].ToString());
                        string date = datetime.ToString("yyyy-MM-dd");
                        this.AddDateDisplay.Value = date;
                        this.CaloriesDisplay.InnerHtml = reader["Calories"].ToString();
                        this.WaterDisplay.InnerHtml = reader["Water"].ToString();
                        this.ProteinDisplay.InnerHtml = reader["Protein"].ToString();
                        this.LipidDisplay.InnerHtml = reader["Lipid"].ToString();
                        this.CarbohydrateDisplay.InnerHtml = reader["Carbohydrate"].ToString();
                        this.FiberDisplay.InnerHtml = reader["Fiber"].ToString();
                        this.SugarDisplay.InnerHtml = reader["Sugar"].ToString();
                        this.CalciumDisplay.InnerHtml = reader["Calcium"].ToString();
                        this.IronDisplay.InnerHtml = reader["Iron"].ToString();
                    }

                    conn.Close();
                }
            }

            if (foodKey.HasValue)
            {
                DropDownList list = new DropDownList();
                list.ID = "UnitDisplay";
                using (var conn = new SqlConnection("Server=(local);DataBase=Nutrition;Integrated Security=SSPI"))
                {
                    using (var command = new SqlCommand("dbo.Food_Units_Get", conn)
                    {
                        CommandType = CommandType.StoredProcedure
                    })
                    {
                        command.Parameters.Add("@Food_Key", SqlDbType.Int);
                        command.Parameters["@Food_Key"].Value = foodKey.Value;
                        conn.Open();
                        var reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        list.DataSource = reader;
                        list.DataTextField = "Unit_Name";
                        list.DataValueField = "Unit_Key";
                        list.DataBind();
                        list.SelectedValue = unitKey.Value.ToString();
                        conn.Close();
                    }
                }

                StringWriter theStringWriter = new StringWriter();
                HtmlTextWriter theHtmlTextWriter = new HtmlTextWriter(theStringWriter);

                // Render the table row control into the writer
                list.RenderControl(theHtmlTextWriter);

                // Return the string via the StringWriter
                this.UnitDisplayHolder.InnerHtml = theStringWriter.ToString();
            }
        }
示例#11
0
        /// <summary>
        /// Renders the base control.
        /// </summary>
        /// <param name="writer">The writer.</param>
        public override void RenderBaseControl( HtmlTextWriter writer )
        {
            Dictionary<string, string> values = null;
            if ( DefinedTypeId.HasValue )
            {
                values = new Dictionary<string, string>();
                new DefinedValueService( new RockContext() )
                    .GetByDefinedTypeId( DefinedTypeId.Value )
                    .ToList()
                    .ForEach( v => values.Add( v.Id.ToString(), v.Value ) );
            }
            else if ( CustomValues != null )
            {
                values = CustomValues;
            }

            writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-list " + this.CssClass );
            writer.AddAttribute( HtmlTextWriterAttribute.Id, this.ClientID );
            writer.RenderBeginTag( HtmlTextWriterTag.Span );
            writer.WriteLine();

            _hfValue.RenderControl( writer );
            writer.WriteLine();

            StringBuilder html = new StringBuilder();
            html.Append( @"<div class=""controls controls-row form-control-group"">");
            if ( CustomKeys != null && CustomKeys.Any() )
            {
                html.Append( @"<select class=""key-value-key form-control input-width-md js-key-value-input"">" );
                foreach ( var key in CustomKeys )
                {
                    html.AppendFormat( @"<option value=""{0}"">{1}</option>", key.Key, key.Value );
                }
                html.Append( @"</select>" );
            }
            else
            {
                html.AppendFormat( @"<input class=""key-value-key form-control input-width-md js-key-value-input"" type=""text"" placeholder=""{0}""></input> ", KeyPrompt );
            }

            if ( values != null )
            {
                html.Append( @"<select class=""key-value-value form-control input-width-md js-key-value-input"">" );
                foreach ( var value in values )
                {
                    html.AppendFormat( @"<option value=""{0}"">{1}</option>", value.Key, value.Value );
                }
                html.Append( @"</select>" );
            }
            else
            {
                html.AppendFormat( @"<input class=""key-value-value input-width-md form-control js-key-value-input"" type=""text"" placeholder=""{0}""></input>", ValuePrompt );
            }
            html.Append( @"<a href=""#"" class=""btn btn-sm btn-danger key-value-remove""><i class=""fa fa-minus-circle""></i></a></div>" );

            var hfValueHtml = new HtmlInputHidden();
            hfValueHtml.AddCssClass( "js-value-html" );
            hfValueHtml.Value = html.ToString();
            hfValueHtml.RenderControl( writer );

            writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-rows" );
            writer.RenderBeginTag( HtmlTextWriterTag.Span );
            writer.WriteLine();

            string[] nameValues = this.Value.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
            foreach ( string nameValue in nameValues )
            {
                string[] nameAndValue = nameValue.Split( new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries );

                writer.AddAttribute( HtmlTextWriterAttribute.Class, "controls controls-row form-control-group" );
                writer.RenderBeginTag( HtmlTextWriterTag.Div );
                writer.WriteLine();

                // Write Key
                if ( CustomKeys != null && CustomKeys.Any() )
                {
                    DropDownList ddl = new DropDownList();
                    ddl.AddCssClass( "key-value-key form-control input-width-md js-key-value-input" );
                    ddl.DataTextField = "Value";
                    ddl.DataValueField = "Key";
                    ddl.DataSource = CustomKeys;
                    ddl.DataBind();
                    if ( nameAndValue.Length >= 1 )
                    {
                        ddl.SelectedValue = nameAndValue[0];
                    }
                    ddl.RenderControl( writer );
                }
                else
                {
                    // Write Name
                    writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-key form-control input-width-md js-key-value-input" );
                    writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
                    writer.AddAttribute( HtmlTextWriterAttribute.Value, nameAndValue.Length >= 1 ? nameAndValue[0] : string.Empty );
                    writer.AddAttribute( "placeholder", KeyPrompt );
                    writer.RenderBeginTag( HtmlTextWriterTag.Input );
                    writer.RenderEndTag();
                }

                writer.Write( " " );
                writer.WriteLine();

                // Write Value
                if ( values != null )
                {
                    DropDownList ddl = new DropDownList();
                    ddl.AddCssClass( "key-value-value form-control input-width-md js-key-value-input" );
                    ddl.DataTextField = "Value";
                    ddl.DataValueField = "Key";
                    ddl.DataSource = values;
                    ddl.DataBind();
                    if ( nameAndValue.Length >= 2 )
                    {
                        ddl.SelectedValue = nameAndValue[1];
                    }
                    ddl.RenderControl( writer );
                }
                else
                {
                    writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-value form-control input-width-md js-key-value-input" );
                    writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
                    writer.AddAttribute( HtmlTextWriterAttribute.Value, nameAndValue.Length >= 2 ? nameAndValue[1] : string.Empty );
                    writer.AddAttribute( "placeholder", ValuePrompt );
                    writer.RenderBeginTag( HtmlTextWriterTag.Input );
                    writer.RenderEndTag();
                }

                writer.Write( " " );
                writer.WriteLine();

                // Write Remove Button
                writer.AddAttribute( HtmlTextWriterAttribute.Href, "#" );
                writer.AddAttribute( HtmlTextWriterAttribute.Class, "btn btn-sm btn-danger key-value-remove" );
                writer.RenderBeginTag( HtmlTextWriterTag.A );
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-minus-circle");
                writer.RenderBeginTag( HtmlTextWriterTag.I );
                writer.RenderEndTag();
                writer.RenderEndTag();
                writer.WriteLine();

                writer.RenderEndTag();
                writer.WriteLine();

            }

            writer.RenderEndTag();
            writer.WriteLine();

            writer.AddAttribute( HtmlTextWriterAttribute.Class, "actions" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );

            writer.AddAttribute( HtmlTextWriterAttribute.Class, "btn btn-action btn-xs key-value-add" );
            writer.AddAttribute( HtmlTextWriterAttribute.Href, "#" );
            writer.RenderBeginTag( HtmlTextWriterTag.A );
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-plus-circle");
            writer.RenderBeginTag( HtmlTextWriterTag.I );

            writer.RenderEndTag();
            writer.RenderEndTag();
            writer.RenderEndTag();
            writer.WriteLine();

            writer.RenderEndTag();
            writer.WriteLine();

            RegisterClientScript();
        }
示例#12
0
        /// <summary>
        /// Outputs server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter" /> object and stores tracing information about the control if tracing is enabled.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter" /> object that receives the control content.</param>
        public override void RenderControl( HtmlTextWriter writer )
        {
            writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-list" );
            writer.RenderBeginTag( HtmlTextWriterTag.Span );
            writer.WriteLine();

            base.RenderControl( writer );
            writer.WriteBreak();
            writer.WriteLine();

            writer.AddAttribute( HtmlTextWriterAttribute.Class, "key-value-rows" );
            writer.RenderBeginTag( HtmlTextWriterTag.Span );
            writer.WriteLine();

            List<DefinedValue> values = null;
            if ( DefinedTypeId.HasValue )
            {
                values = new DefinedValueService().GetByDefinedTypeId( DefinedTypeId.Value ).ToList();
            }

            string[] nameValues = this.Value.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries );
            foreach ( string nameValue in nameValues )
            {
                string[] nameAndValue = nameValue.Split( new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries );

                writer.AddAttribute( HtmlTextWriterAttribute.Class, "controls controls-row" );
                writer.RenderBeginTag( HtmlTextWriterTag.Div );
                writer.WriteLine();

                // Write Name
                writer.AddAttribute( HtmlTextWriterAttribute.Class, "span3 key-value-key" );
                writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
                writer.AddAttribute( HtmlTextWriterAttribute.Value, nameAndValue.Length >= 1 ? nameAndValue[0] : string.Empty );
                writer.AddAttribute( "placeholder", "Key" );
                writer.RenderBeginTag( HtmlTextWriterTag.Input );
                writer.RenderEndTag();
                writer.Write( " " );
                writer.WriteLine();

                // Write Value
                if ( values == null )
                {
                    writer.AddAttribute( HtmlTextWriterAttribute.Class, "span4 key-value-value" );
                    writer.AddAttribute( HtmlTextWriterAttribute.Type, "text" );
                    writer.AddAttribute( "placeholder", "Value" );
                    writer.AddAttribute( HtmlTextWriterAttribute.Value, nameAndValue.Length >= 2 ? nameAndValue[1] : string.Empty );
                    writer.RenderBeginTag( HtmlTextWriterTag.Input );
                    writer.RenderEndTag();
                }
                else
                {
                    DropDownList ddl = new DropDownList();
                    ddl.AddCssClass( "key-value-value" );
                    ddl.DataTextField = "Name";
                    ddl.DataValueField = "Id";
                    ddl.DataSource = values;
                    ddl.DataBind();
                    ddl.Items.Insert(0, new ListItem( string.Empty, string.Empty ) );
                    if ( nameAndValue.Length >= 2 )
                    {
                        ddl.SelectedValue = nameAndValue[1];
                    }
                    ddl.RenderControl( writer );
                }

                writer.Write( " " );
                writer.WriteLine();

                // Write Remove Button
                writer.AddAttribute( HtmlTextWriterAttribute.Class, "btn key-value-remove" );
                writer.AddAttribute( HtmlTextWriterAttribute.Href, "#" );
                writer.RenderBeginTag( HtmlTextWriterTag.A );
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-minus-circle");
                writer.RenderBeginTag( HtmlTextWriterTag.I );
                writer.RenderEndTag();
                writer.RenderEndTag();
                writer.WriteLine();

                writer.RenderEndTag();
                writer.WriteLine();

            }

            writer.RenderEndTag();
            writer.WriteLine();

            writer.AddAttribute( HtmlTextWriterAttribute.Class, "btn key-value-add" );
            writer.AddAttribute( HtmlTextWriterAttribute.Href, "#" );
            writer.RenderBeginTag( HtmlTextWriterTag.A );
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-plus-circle");
            writer.RenderBeginTag( HtmlTextWriterTag.I );
            writer.RenderEndTag();
            writer.RenderEndTag();
            writer.WriteLine();

            writer.RenderEndTag();
            writer.WriteLine();

            RegisterClientScript( values );
        }
 protected override void RenderFooter(HtmlTextWriter writer)
 {
     writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "4px");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     DropDownList list = new DropDownList {
         ClientIDMode = ClientIDMode.AutoID,
         ID = this.ZonesID
     };
     if (base.DesignMode)
     {
         list.Items.Add(System.Web.SR.GetString("Zone_SampleHeaderText"));
     }
     else if ((base.WebPartManager != null) && (base.WebPartManager.Zones != null))
     {
         foreach (WebPartZoneBase base2 in base.WebPartManager.Zones)
         {
             if (base2.AllowLayoutChange)
             {
                 ListItem item = new ListItem(base2.DisplayTitle, base2.ID);
                 if (string.Equals(base2.ID, this._selectedZoneID, StringComparison.OrdinalIgnoreCase))
                 {
                     item.Selected = true;
                 }
                 list.Items.Add(item);
             }
         }
     }
     base.LabelStyle.AddAttributesToRender(writer, this);
     if (list.Items.Count > 0)
     {
         writer.AddAttribute(HtmlTextWriterAttribute.For, list.ClientID);
     }
     writer.RenderBeginTag(HtmlTextWriterTag.Label);
     writer.Write(this.SelectTargetZoneText);
     writer.RenderEndTag();
     writer.Write("&nbsp;");
     list.ApplyStyle(base.EditUIStyle);
     if (list.Items.Count > 0)
     {
         list.RenderControl(writer);
     }
     writer.Write("&nbsp;");
     this.RenderVerbs(writer);
     writer.RenderEndTag();
 }
        /// <summary>
        /// Renders the entity fields controls.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="filterControl">The filter control.</param>
        /// <param name="writer">The writer.</param>
        /// <param name="entityFields">The entity fields.</param>
        /// <param name="ddlEntityField">The DDL entity field.</param>
        /// <param name="propertyControls">The property controls.</param>
        /// <param name="propertyControlsPrefix">The property controls prefix.</param>
        public void RenderEntityFieldsControls( Type entityType, FilterField filterControl, HtmlTextWriter writer, List<EntityField> entityFields, 
            DropDownList ddlEntityField, List<Control> propertyControls, string propertyControlsPrefix )
        {
            string selectedEntityField = ddlEntityField.SelectedValue;

            writer.AddAttribute( "class", "row js-filter-row" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );

            writer.AddAttribute( "class", "col-md-3" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );
            ddlEntityField.AddCssClass( "entity-property-selection" );
            ddlEntityField.RenderControl( writer );
            writer.RenderEndTag();
            writer.AddAttribute( "class", "col-md-9" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );

            // generate result for "none"
            StringBuilder sb = new StringBuilder();
            string lineFormat = @"
            case {0}: {1}; break;";

            int fieldIndex = 0;
            sb.AppendFormat( lineFormat, fieldIndex, "result = ''" );
            fieldIndex++;

            // render empty row for "none"
            writer.AddAttribute( "class", "row field-criteria" );
            writer.RenderBeginTag( HtmlTextWriterTag.Div );
            writer.RenderEndTag();  // row

            foreach ( var entityField in entityFields )
            {
                string controlId = string.Format("{0}_{1}", propertyControlsPrefix, entityField.Name );
                var control = propertyControls.FirstOrDefault( c => c.ID == controlId );
                if ( control != null )
                {
                    if ( entityField.Name != selectedEntityField )
                    {
                        if ( control is HtmlControl )
                        {
                            ( (HtmlControl)control ).Style["display"] = "none";
                        }
                        else if ( control is WebControl )
                        {
                            ( (WebControl)control ).Style["display"] = "none";
                        }
                    }
                    control.RenderControl( writer );

                    string clientFormatSelection = entityField.FieldType.Field.GetFilterFormatScript( entityField.FieldConfig, entityField.Title );

                    if ( clientFormatSelection != string.Empty )
                    {
                        sb.AppendFormat( lineFormat, fieldIndex, clientFormatSelection );
                    }

                    fieldIndex++;
                }
            }

            writer.RenderEndTag();  // col-md-9

            writer.RenderEndTag();  // row

            string scriptFormat = @"
            function {0}PropertySelection($content){{

            var sIndex = $('select.entity-property-selection', $content).find(':selected').index();
            var $selectedContent = $('div.field-criteria', $content).eq(sIndex);
            var result = '';
            switch(sIndex) {{
            {1}
            }}
            return result;
            }}
            ";

            string script = string.Format( scriptFormat, entityType.Name, sb.ToString() );
            ScriptManager.RegisterStartupScript( filterControl, typeof( FilterField ), entityType.Name + "-property-selection", script, true );

            script = @"
            $('select.entity-property-selection').change(function(){
            var $parentRow = $(this).closest('.js-filter-row');
            $parentRow.find('div.field-criteria').hide();
            $parentRow.find('div.field-criteria').eq($(this).find(':selected').index()).show();
            });";

            // only need this script once per page
            ScriptManager.RegisterStartupScript( filterControl.Page, filterControl.Page.GetType(), "entity-property-selection-change-script", script, true );

            RegisterFilterCompareChangeScript( filterControl );
        }