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 { /// /// 数据获取对象 /// public static IDataGeter MyDataGeter { get; set; } #region 多条件查询 //public static MvcHtmlString QPerceptTextboxForD(this HtmlHelper htmlHelper, Expression> 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(this HtmlHelper htmlHelper, Expression> expression, // Expression> 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(this HtmlHelper htmlHelper, Expression> expression, Expression> expressionName, string kind, string callBackFunc, IDictionary 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(""); var inputName = ExpressionHelper.GetExpressionText(expression); var hiddenString = ""; TagBuilder tagSpen = QMHTMLInput.easyUIInput(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("
" + tagSpen.ToString() + "
" + sbScript.ToString()); return MvcHtmlString.Create(tagSpen.ToString() + "" + 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; } } }