using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Web.Mvc;
using System.Web.UI.WebControls;
namespace Core.Web.WebHelper
{
public static class ExtendMvcHtml
{
///
/// 普通按钮
///
/// htmlhelper
/// 控件Id
/// 控件icon图标class
/// 控件的名称
/// 分割线
/// html
public static MvcHtmlString ToolButton(this HtmlHelper helper, string id, string icon, string text, bool hr)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("", id);
sb.AppendLine("");
sb.AppendFormat("", icon);
sb.AppendLine("");
sb.AppendFormat("{0}", text);
sb.AppendLine("");
if (hr)
{
sb.Append("
");
sb.AppendLine("");
}
return new MvcHtmlString(sb.ToString());
}
///
/// 普通按钮
///
/// htmlhelper
/// 控件Id
/// 控件icon图标class
/// 控件的名称
/// click事件名称
/// 分割线
/// html
public static MvcHtmlString ToolButton(this HtmlHelper helper, string id, string icon, string text, string click, bool hr)
{
StringBuilder sb = new StringBuilder();
if (!string.IsNullOrEmpty(click))
sb.AppendFormat("", id, click);
else
sb.AppendFormat("", id);
sb.AppendLine("");
sb.AppendFormat("", icon);
sb.AppendLine("");
sb.AppendFormat("{0}", text);
sb.AppendLine("");
if (hr)
{
sb.Append("");
sb.AppendLine("");
}
return new MvcHtmlString(sb.ToString());
}
///
/// 不浮动
///
///
///
///
///
///
///
///
public static MvcHtmlString ToolButtonPlain(this HtmlHelper helper, string id, string icon, string text, bool hr, string attribute)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("", id);
sb.AppendLine("");
sb.AppendFormat("", icon, icon == "" ? "" : " style=\"padding-left: 20px;\"");
sb.AppendLine("");
sb.AppendFormat("{0}", text);
sb.AppendLine("");
if (hr)
{
sb.Append("");
sb.AppendLine("");
}
return new MvcHtmlString(sb.ToString());
}
///
/// 分割按钮
///
///
public static MvcHtmlString SplitButton(this HtmlHelper helper, string id, string icon, string text, ChildButton[] buttonList, bool hr)
{
Random rd = new Random();
string childId = id + rd.Next(100, 1000);
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{2}", id, icon, text, childId);
sb.AppendLine("");
sb.AppendFormat(" ", childId);
sb.AppendLine("");
foreach (ChildButton button in buttonList)
{
sb.AppendFormat("
{1}
", button.icon, button.text, button.id, button.click);
sb.AppendLine("");
}
sb.AppendLine("
");
sb.AppendLine("");
if (hr)
{
sb.Append("");
sb.AppendLine("");
}
return new MvcHtmlString(sb.ToString());
}
/////
///// 获取未知ToolBar按钮
/////
/////
/////
/////
//public static MvcHtmlString ToolBarOtherButton(this HtmlHelper helper, ToolBarButton button)
//{
// if (button.child == null)
// {
// return ToolButton(helper, button.id, button.icon, button.text, button.click, button.hr);
// }
// else
// {
// ChildButton[] childs = new ChildButton[button.child.Count];
// for (int i = 0; i < button.child.Count; i++)
// {
// childs[i] = new ChildButton() { click = button.child[i].click, icon = button.child[i].icon, id = button.child[i].id, text = button.child[i].text };
// }
// return SplitButton(helper, button.id, button.icon, button.text, childs, true);
// }
//}
///
///
///
///
/// 名称和ID
/// 默认值
/// 数据源
///
public static MvcHtmlString OptGroupSelect(this HtmlHelper helper, string name, string selectValue, ListOptGroup obj, string attribute = "", bool canChooseParent = false)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(string.Format("");
return new MvcHtmlString(sb.ToString());
}
///
/// 时间控件
///
///
///
///
///
public static MvcHtmlString WdatePickerText(this HtmlHelper helper, string id, string text, bool hasHour = false, string attribute = "")
{
StringBuilder sb = new StringBuilder();
if (hasHour)
{
sb.Append("");
}
else
sb.Append("");
return new MvcHtmlString(sb.ToString());
}
///
/// 时间控件(限定范围)
///
///
///
///
///
///
///
///
///
public static MvcHtmlString WdatePickerText(this HtmlHelper helper, string id, string text, string minDate, string maxDate, bool hasHour = false, string attribute = "")
{
StringBuilder sb = new StringBuilder();
string option = "";
if (!string.IsNullOrEmpty(minDate))
{
option += ",minDate:" + minDate;
}
if (!string.IsNullOrEmpty(maxDate))
{
option += ",maxDate:" + maxDate;
}
if (hasHour)
{
sb.Append("");
}
else
{
if (option.Length > 0)
option = "{" + option.Substring(1, option.Length - 1) + "}";
sb.Append("");
}
return new MvcHtmlString(sb.ToString());
}
public static MvcHtmlString CheckBoxList(this HtmlHelper htmlHelper, string name, IEnumerable items, RepeatDirection repeatDirection = RepeatDirection.Horizontal, int RepeatColumns = 3, bool isRadio = false, string radioSelect = null)
{
StringBuilder str = new StringBuilder();
string type = isRadio ? "Radio" : "checkbox";
str.Append(@"");
return new MvcHtmlString(str.ToString());
}
#region 单选框和复选框的扩展
///
/// 复选框,selValue为选中项
///
///
///
///
///
///
public static MvcHtmlString CheckBoxList(this HtmlHelper htmlHelper, string name, IEnumerable selectList, IEnumerable selValue)
{
return CheckBoxAndRadioFor