list, bool appendEmptyAll = true, bool enabled = true, object htmlAttributes = null, bool multiple = true, bool searchBox = false, int dataWidth = 152)
{
var temp = "{1}";
if (appendEmptyAll)
{
if (list != null && list.Count > 0 && list[0].Text != "全部")
{
list.Insert(0, new SelectListItem() { Text = "全部", Value = "" });
}
}
object option;
if (multiple)
{
option = new { @class = "selectpicker", multiple = "", data_live_search = "true", data_actions_box = "true", data_selected_text_format = "count > 1", data_width = $"{dataWidth}px" };
}
else
{
option = new { @class = "selectpicker", data_live_search = "true", data_actions_box = "true", data_width = $"{dataWidth}px" };
list.Insert(0, new SelectListItem() { Text = "---", Value = "" });
}
var m2 = HtmlHelperSelectExtensions.DropDownList(helper, name, list, option);
if (!enabled)
{
var inOption = multiple
? (new { @class = "selectpicker", @disabled = "disabled", multiple = "", data_live_search = "true", data_actions_box = "true", data_selected_text_format = "count > 1", data_width = $"{dataWidth}px" })
: (object)(new { @class = "selectpicker", @disabled = "disabled", data_live_search = "true", data_actions_box = "true", data_selected_text_format = "count > 1", data_width = $"{dataWidth}px" });
m2 = HtmlHelperSelectExtensions.DropDownList(helper, name, list, inOption);
}
if (htmlAttributes != null)
{
m2 = HtmlHelperSelectExtensions.DropDownList(helper, name, list, htmlAttributes);
}
var m3 = new HtmlString(" " + string.Format(temp, name, label) + ToHtmlString(m2) + "
");
return m3;
}
public static IHtmlContent YcShortInput(this IHtmlHelper helper, string name, string label)
{
var temp =
" {1}
";
return new HtmlString(string.Format(temp, name, label, helper.ViewData[name] ?? ""));
}
public static IHtmlContent YcAceDropdownInput2(this IHtmlHelper helper, string name, string label, IList list, bool appendEmptyAll = true, string defaultvalue = "", bool enabled = true, object htmlAttributes = null, int dataWidth = 152)
{
var temp = "{1}";
if (appendEmptyAll)
{
if (list != null && list.Count > 0 && list[0].Text != "全部")
{
list.Insert(0, new SelectListItem() { Text = "全部", Value = "" });
}
}
if (!string.IsNullOrEmpty(defaultvalue))
{
var dataSel = list.Where(l => l.Value == defaultvalue).FirstOrDefault();
if (dataSel != null)
{
dataSel.Selected = true;
}
}
var m2 = HtmlHelperSelectExtensions.DropDownList(helper, name, list, htmlAttributes);
if (htmlAttributes == null)
{
m2 = HtmlHelperSelectExtensions.DropDownList(helper, name, list, new { @class = "selectpicker form-control form-control-sm", data_width = $"{dataWidth}px" });
}
if (!enabled)
{
m2 = HtmlHelperSelectExtensions.DropDownList(helper, name, list, new { @class = "selectpicker form-control form-control-sm", data_width = $"{dataWidth}px", @disabled = "disabled" });
}
var m3 = new HtmlString(" " + string.Format(temp, name, label) + ToHtmlString(m2) + "
");
return m3;
}
public static IHtmlContent YcSearchDateRange(this IHtmlHelper helper, string name, string label)
{
var temp =
" {1}-
";
return new HtmlString(string.Format(temp, name, label
, helper.ViewData["DateFrom" + name] == null ? "" : string.Format("value='{0}'", helper.ViewData["DateFrom" + name])
, helper.ViewData["DateTo" + name] == null ? "" : string.Format("value='{0}'", helper.ViewData["DateTo" + name])));
}
}
///
///
///
static class UnderlyingHelper
{
///
/// 从标的代码中提取品种代码
/// ^[a-z|A-Z]+(?=\d+)
///
public static string GetVarietyCode(string underlyingCode)
{
if (string.IsNullOrWhiteSpace(underlyingCode)) { return ""; }
return Regex.Match(underlyingCode, @"^[a-z|A-Z]+(?=\d+)").Value;
}
}
public static class MyControls
{
public static IHtmlContent Btn(string text, string onClick, string icon = "", string id = "", string addclass = "")
{
var tagBuilder = new TagBuilder("button");
tagBuilder.Attributes["type"] = "button";
if (!string.IsNullOrWhiteSpace(id))
{
tagBuilder.Attributes["id"] = id.Trim();
}
tagBuilder.Attributes["class"] = "btn btn-primary " + addclass?.Trim();
tagBuilder.Attributes["onclick"] = onClick + ";return false;";
if (!string.IsNullOrEmpty(icon))
{
tagBuilder.InnerHtml.AppendFormat("", icon);
}
tagBuilder.InnerHtml.Append(text);
return tagBuilder;
}
public static IHtmlContent SearchBtn()
{
return new HtmlString("");
}
}
}