Пример #1
0
        /// <summary>
        ///     no caching
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="type"></param>
        /// <param name="columns"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataTable GetTable(string tableName, AppVar.ConnectionStringType type, string[] columns = null,
                                         string sql = null)
        {
            var connectionString = AppVar.GetConnectionString(type);

            return(GetTable(tableName, connectionString, columns, sql));
        }
        public static HtmlString DropDowns(this HtmlHelper helper, string valueField, string textField,
                                           string htmlName = null, string displayName  = null, string modelValue      = null, string isRequried = "*",
                                           string classes  = null, string toolTipValue = null, string otherAttributes = "", string tableName    = null,
                                           AppVar.ConnectionStringType connectionType = AppVar.ConnectionStringType.DefaultConnection)
        {
            var divElement = @"<div class='form-group {0}-main'>
                             <div class='controls'>
                                <label class='col-md-2 control-label' for='{0}'>{1}<span class='red '>{2}</span></label>
                                <div class='col-md-10 {0}-combo-div'>
                                    {3}
                                    <a href='#' data-toggle='tooltip' data-original-title='{4}' title='{4}' class='tooltip-show'><span class='glyphicon glyphicon-question-sign font-size-22 glyphicon-top-fix almost-white'></span></a>
                                </div>
                            </div>
                        </div>";

            // 0- name
            // 1- displayName
            // 2 - isRequried
            // 3 - select element
            // 4 - tooltipValue
            if (tableName == null)
            {
                tableName = valueField.Replace("ID", "");
            }
            if (modelValue == null)
            {
                modelValue = "";
            }
            if (classes == null)
            {
                classes = "btn btn-success";
            }
            if (displayName == null)
            {
                displayName = textField;
            }
            if (toolTipValue == null)
            {
                toolTipValue = "Please select " + displayName;
            }
            if (htmlName == null)
            {
                htmlName = valueField;
            }
            var selected = "";
            var countryOptionsGenerate = "<select class='form-control selectpicker " + classes +
                                         "' data-live-search='true' name='" + htmlName + "' " + otherAttributes +
                                         " title='Choose...' data-style='" + classes + "'>";
            var dt = CachedQueriedData.GetTable(tableName, connectionType, new[] { valueField, textField });

            if (dt != null && dt.Rows.Count > 0)
            {
                var     sb = new StringBuilder(countryOptionsGenerate, dt.Rows.Count + 10);
                DataRow row;
                for (var i = 0; i < dt.Rows.Count; i++)
                {
                    row = dt.Rows[i];
                    if (row[valueField].Equals(modelValue))
                    {
                        selected = Selected;
                    }
                    sb.Append(string.Format("<option value='{0}' {1} {2}>{2}</option>", row[valueField], selected,
                                            row[textField]));
                }
                sb.AppendLine("</select>");
                var complete = string.Format(divElement, htmlName, displayName, isRequried, sb, toolTipValue);

                return(new HtmlString(complete));
            }
            return(new HtmlString(""));
        }