You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
6.0 KiB
144 lines
6.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMFrameWork.WebUI.DataSource;
|
|
using System.Web.Mvc;
|
|
using System.Web.Mvc.Html;
|
|
using System.Linq.Expressions;
|
|
using System.Web.Routing;
|
|
|
|
namespace QMAPP.Common.Web
|
|
{
|
|
public static class QPerceptTextboxD
|
|
{
|
|
/// <summary>
|
|
/// 数据获取对象
|
|
/// </summary>
|
|
public static IDataGeter MyDataGeter { get; set; }
|
|
|
|
#region 多条件查询
|
|
//public static MvcHtmlString QPerceptTextboxForD<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression,
|
|
// string kind, string callBackFunc, object htmlAttributes, string idName, string contentName, string text, params string[] ps)
|
|
//{
|
|
// return QPerceptTextboxForD(htmlHelper, expression, null, kind, callBackFunc, htmlAttributes, idName, contentName, text, ps);
|
|
//}
|
|
|
|
//public static MvcHtmlString QPerceptTextboxForD<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression,
|
|
// Expression<Func<TModel, TProperty>> expressionName, string kind, string callBackFunc, object htmlAttributes, string idName, string contentName, string text, params string[] ps)
|
|
//{
|
|
// return QPerceptTextboxForD(htmlHelper, expression, expressionName, kind, callBackFunc, new RouteValueDictionary(htmlAttributes), idName, contentName, text, ps);
|
|
//}
|
|
|
|
public static MvcHtmlString QPerceptTextboxForD<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression,
|
|
Expression<Func<TModel, TProperty>> expressionName, string kind, string callBackFunc, IDictionary<string, object> htmlAttributes, string idName, string contentName, string text, params string[] ps)
|
|
{
|
|
string url = "";
|
|
string urlD = "";
|
|
string showUrl = "";
|
|
string showUrlD = "";
|
|
if (expression == null)
|
|
{
|
|
throw new ArgumentNullException("expression");
|
|
}
|
|
string strValueName = ExpressionHelper.GetExpressionText(expression);
|
|
|
|
|
|
//获取数据源
|
|
if (MyDataGeter == null)
|
|
{
|
|
throw new Exception("为设置智能提示框数据源!");
|
|
}
|
|
|
|
urlD = GetDataUrlD(kind, idName, contentName);
|
|
url = MyDataGeter.GetDataUrl(kind);
|
|
|
|
|
|
//参数
|
|
string paramList = "";
|
|
|
|
if (ps != null)
|
|
{
|
|
for (int i = 0; i < ps.Length; i++)
|
|
{
|
|
if (ps[i] == "")
|
|
ps[i] = "none";
|
|
paramList += "|" + ps[i];
|
|
}
|
|
}
|
|
|
|
if (paramList != "")
|
|
{
|
|
if (url.IndexOf("?") > 0)
|
|
{
|
|
url += "¶mList=" + paramList.Substring(1);
|
|
}
|
|
else
|
|
{
|
|
|
|
url += "?paramList=" + paramList.Substring(1);
|
|
}
|
|
}
|
|
|
|
showUrl = url.Replace("GetPerceptData", "ShowPerceptData");
|
|
showUrlD = urlD.Replace("GetPerceptData", "ShowQueryMore");
|
|
|
|
StringBuilder sbScript = new StringBuilder();
|
|
sbScript.AppendLine("<script language=\"javascript\" type=\"text/javascript\">");
|
|
sbScript.AppendLine(" $(function () {");
|
|
string strLabelName = "";
|
|
|
|
//名称显示控件
|
|
if (expressionName != null)
|
|
{
|
|
strLabelName = ExpressionHelper.GetExpressionText(expressionName);
|
|
}
|
|
|
|
//回调函数
|
|
string backFunctionDefine = "function (data) {}";
|
|
|
|
if (string.IsNullOrEmpty(callBackFunc) == false)
|
|
{
|
|
backFunctionDefine = "function (data) {" + callBackFunc + "(data);}";
|
|
}
|
|
|
|
sbScript.AppendFormat(" _setAutoComplete('{0}','{1}','{2}',{3});", url, strValueName, strLabelName, backFunctionDefine);
|
|
|
|
sbScript.AppendLine(" }); ");
|
|
sbScript.AppendLine("</script>");
|
|
|
|
var inputName = ExpressionHelper.GetExpressionText(expression);
|
|
var hiddenString = "";
|
|
TagBuilder tagSpen = QMHTMLInput.easyUIInput<TModel, TProperty>(htmlHelper, expression, QMHTMLInput.easyuiClass.validatebox, out hiddenString);
|
|
|
|
//输入后校验
|
|
if (string.IsNullOrEmpty(text))
|
|
{
|
|
htmlAttributes.Add("onChange", string.Format("_isAutoComplete(\'{0}\',\'{1}\',\'{2}\',{3});", url, strValueName, strLabelName, backFunctionDefine));
|
|
}
|
|
//双击显示选择窗口
|
|
//htmlAttributes.Add("ondblclick", string.Format("_showAutoComplete(\'{0}\',\'{1}\',\'{2}\',{3});", showUrl, strValueName, strLabelName, backFunctionDefine));
|
|
|
|
string onclick = string.Format("_showAutoComplete1(\'{0}\',\'{1}\',\'{2}\',{3});", showUrlD, strValueName, strLabelName, backFunctionDefine);
|
|
|
|
tagSpen.MergeAttributes(htmlAttributes);
|
|
|
|
//return MvcHtmlString.Create("<table cellpadding=\"0\" cellspacing=\"0\"><tr><td>" + tagSpen.ToString() + "</td><td><a href=\"#\" class=\"easyui-linkbutton\" onclick=\"" + onclick + "\" plain=\"true\" iconCls=\"icon-search\"></a></td></tr></table>" + sbScript.ToString());
|
|
return MvcHtmlString.Create(tagSpen.ToString() + "<a href=\"#\" class=\"easyui-linkbutton\" onclick=\"" + onclick + "\" plain=\"true\" iconCls=\"icon-search\" style=\" margin-bottom:5px\"></a>" + sbScript.ToString());
|
|
}
|
|
#endregion
|
|
|
|
public static string GetDataUrlD(string dataKind, string idName, string contentName)
|
|
{
|
|
string strUrl = "";
|
|
switch (dataKind.ToLower())
|
|
{
|
|
default:
|
|
strUrl = "/PerceptText/ShowQueryMore?kind=" + dataKind + "&idName=" + idName + "&contentName=" + contentName;
|
|
break;
|
|
|
|
}
|
|
return strUrl;
|
|
}
|
|
}
|
|
}
|
|
|