ConditionExtensions.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using System.Web.Mvc.Html;
  8. using Autofac;
  9. using Bowin.Web.Controls.Mvc;
  10. using Bowin.Common;
  11. using Bowin.Common.JSON;
  12. using EMIS.Utility;
  13. using EMIS.Entities;
  14. using EMIS.CommonLogic.SystemServices;
  15. namespace EMIS.Web.Controls
  16. {
  17. public static class ConditionExtensions
  18. {
  19. // public IConfiguretermsInfoServices iConfiguretermsInfoServices { get; set; }
  20. /// <summary>
  21. /// 动态查询控件,需要通过数据库配置具体的查询项
  22. /// </summary>
  23. /// <param name="htmlHelper"></param>
  24. /// <param name="menuClass">页面标识,默认为List,同一菜单内的不同页面可通过该字段区分,对应数据库中的MUNClass字段</param>
  25. /// <param name="mnuNo">菜单编号,对应数据库中的MNUID字段</param>
  26. /// <returns></returns>
  27. public static MvcHtmlString PositionCondition(this HtmlHelper htmlHelper, string menuClass = "List", string mnuNo = "")
  28. {
  29. var positionConditionId = "ul_" + Guid.NewGuid().ToString().Replace("-", "");
  30. var request = htmlHelper.ViewContext.RequestContext.HttpContext.Request;
  31. var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
  32. if (mnuNo == "")
  33. {
  34. mnuNo = request["MNU"];
  35. }
  36. StringBuilder sb = new StringBuilder();
  37. sb.Append("<div class=\"search_keyword\">");
  38. sb.Append(" <div class=\"search_input\" style=\"overflow: hidden;\">");
  39. sb.Append(" <ul id=\"" + positionConditionId + "\" dynamicWhere=\"true\">");
  40. sb.Append(" <li class=\"sn\" style=\"padding-left: 5px;\">查询:</li>");
  41. sb.Append(" <li class=\"sv\"></li>");
  42. sb.Append(" <li class=\"sv\"></li>");
  43. sb.Append(" <li class=\"sv\"></li>");
  44. sb.Append(" <li class=\"sn\" style=\"padding-right: 10px;\">");
  45. sb.Append(" <a class=\"easyui-linkbutton l-btn\" onclick=\"reload();\" href=\"javascript:void(0)\" data-options=\"iconCls:'icon-search'\">");
  46. sb.Append("查询");
  47. sb.Append(" </a>");
  48. sb.Append(" </li>");
  49. sb.Append(" </ul>");
  50. sb.Append(" </div>");
  51. sb.Append("</div>");
  52. sb.Append("<script type = \"text/javascript\" language = \"javascript\"> $(function () { EMISFunction.LoadPositionCondition('" + positionConditionId + "','" + menuClass + "'," + (mnuNo == null ? "null" : "'" + mnuNo + "'") + ",'" + urlHelper.Action("GetPositionConditionData", "Common") + "'); });</script>");
  53. return MvcHtmlString.Create(sb.ToString());
  54. }
  55. ///// <summary>
  56. /////
  57. ///// </summary>
  58. ///// <param name="htmlHelper"></param>
  59. ///// <param name="menuClass"></param>
  60. ///// <param name="htmlAttributes"></param>
  61. ///// <param name="mnuNo"></param>
  62. ///// <returns></returns>
  63. //public static MvcHtmlString PositionCondition(this HtmlHelper htmlHelper, string menuClass = "List", IDictionary<string, string> htmlAttributes = null, string mnuNo = "")
  64. //{
  65. // string menuNo = HttpContext.Current.Request["MNU"];
  66. // string html = "";
  67. // string columnName = string.Empty;
  68. // List<Sys_ConfiguretermsInfo> listAttribute = null;
  69. // if (!string.IsNullOrEmpty(mnuNo))
  70. // {
  71. // menuNo = mnuNo;
  72. // }
  73. // using (var scope = AutofacHelper.Container.BeginLifetimeScope())
  74. // {
  75. // IConfiguretermsInfoServices configuretermsInfoServices = scope.Resolve<IConfiguretermsInfoServices>();
  76. // listAttribute = configuretermsInfoServices.GetConfiguretermsInfo(menuNo, menuClass);
  77. // foreach (var item in listAttribute)
  78. // {
  79. // columnName += item.Value.Replace(".", "") + "Query" + item.ControlType + "_div" + ",";
  80. // if (htmlAttributes == null)
  81. // {
  82. // htmlAttributes = new Dictionary<string, string> { { "data-condition", item.listControl } };
  83. // }
  84. // }
  85. // }
  86. // DropdownListOptions dropdownListOptions = new DropdownListOptions();
  87. // dropdownListOptions.BindType = DropdownListBindType.None;
  88. // dropdownListOptions.ItemSourceUrl = UrlHelper.GenerateContentUrl("~/Common/DynamicConditionDropDown?menuNo="
  89. // + menuNo + "&formClass=" + menuClass, htmlHelper.ViewContext.HttpContext);
  90. // dropdownListOptions.BindType = DropdownListBindType.None;
  91. // dropdownListOptions.Name = "Attribute";
  92. // dropdownListOptions.ID = "Attribute";
  93. // dropdownListOptions.OnSelect = "SystemQueryControl.QueryControl";
  94. // DropdownListOptions dropdownListOptions1 = new DropdownListOptions();
  95. // List<DropdownListItem> listdlt = new List<DropdownListItem>{
  96. // new DropdownListItem{ Text = "=", Value = "=" },
  97. // new DropdownListItem{ Text = ">=", Value = ">=" },
  98. // new DropdownListItem{ Text = ">", Value = ">" },
  99. // new DropdownListItem{ Text = "<=", Value = "<=" },
  100. // new DropdownListItem{ Text = "<", Value = "<" },
  101. // new DropdownListItem{ Text = "<>", Value = "<>" },
  102. // new DropdownListItem{ Text = "左", Value = "左" },
  103. // new DropdownListItem{ Text = "右", Value = "右" },
  104. // new DropdownListItem{ Text = "中", Value = "中" },
  105. // };
  106. // dropdownListOptions1.BindType = DropdownListBindType.None;
  107. // dropdownListOptions1.ItemList = listdlt;
  108. // dropdownListOptions1.Name = "Condition";
  109. // dropdownListOptions1.ID = "Condition";
  110. // html = "<div class=\"search_keyword\">\n";
  111. // html += "<div class=\"search_input\">" +
  112. // "<input type=\"hidden\" id='QuerycolumnName' value='" + columnName + "'>" +
  113. // "<ul>" +
  114. // "<li class=\"sn\" style=\"padding-left: 5px;\">查询:</li>" +
  115. // "<li class=\"sv\">" +
  116. // Bowin.Web.Controls.Mvc.DropdownList.CreateControl(dropdownListOptions, htmlAttributes).Render() +
  117. // "</li>" +
  118. // "<li class=\"sv\">" +
  119. // Bowin.Web.Controls.Mvc.DropdownList.CreateControl(dropdownListOptions1, htmlAttributes).Render() +
  120. // "</li>" +
  121. // "<li class=\"sv\" id=\"liquery\">" +
  122. // GetQueryControl(htmlHelper, listAttribute) +
  123. // "</li>" +
  124. // "<li class=\"sn\" style=\"padding-left: 20px;\"><a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-search'\" onclick=\"reload();\">查询</a></li>" +
  125. // "</ul>" +
  126. // "</div>";
  127. // html += "</div>";
  128. // return MvcHtmlString.Create(html);
  129. //}
  130. /// <summary>
  131. /// 获取查询控件
  132. /// </summary>
  133. /// <param name="htmlHelper"></param>
  134. /// <param name="listAttribute"></param>
  135. /// <returns></returns>
  136. private static string GetQueryControl(HtmlHelper htmlHelper, List<Sys_ConfiguretermsInfo> listAttribute)
  137. {
  138. string control = string.Empty;
  139. int i = 0;
  140. string cl = string.Empty;
  141. foreach (var item in listAttribute)
  142. {
  143. string controlName = item.Value.Replace(".", "");
  144. cl = i == 0 ? "" : "class='divquery'";
  145. IDictionary<string, string> htmlAttributes = new Dictionary<string, string> { { "data-condition", item.listControl } };
  146. if (item.ControlType == "TextBox")
  147. {
  148. TextBoxOptions tbop = new TextBoxOptions
  149. {
  150. ID = controlName + "_QueryTextBox",
  151. Name = controlName + "_QueryTextBox"
  152. };
  153. var ss = htmlHelper.TextBox(tbop, htmlAttributes);
  154. control += "<div id='" + controlName + "QueryTextBox_div' " + cl + ">" + htmlHelper.TextBox(tbop, htmlAttributes) + "</div>";
  155. }
  156. else if (item.ControlType == "DropdownList")
  157. {
  158. DropdownListOptions dropdownListOptions = new DropdownListOptions();
  159. dropdownListOptions.BindType = DropdownListBindType.SelectAll;
  160. dropdownListOptions.ID = controlName + "_QueryDropdownList";
  161. dropdownListOptions.Name = controlName + "_QueryDropdownList";
  162. dropdownListOptions.ItemSourceUrl = item.PostUrl;
  163. dropdownListOptions.TextField = item.ControlTextFiled;
  164. dropdownListOptions.ValueField = item.ControlValueFiled;
  165. var ss = htmlHelper.DropdownList(dropdownListOptions, htmlAttributes);
  166. control += "<div id='" + controlName + "QueryDropdownList_div' " + cl + ">" + htmlHelper.DropdownList(dropdownListOptions, htmlAttributes) + "</div>";
  167. }
  168. else if (item.ControlType == "DictionaryDropDownList")
  169. {
  170. DropdownListOptions dropdownListOptions = new DropdownListOptions();
  171. dropdownListOptions.BindType = DropdownListBindType.SelectAll;
  172. dropdownListOptions.ID = controlName + "_QueryDictionaryDropDownList";
  173. dropdownListOptions.Name = controlName + "_QueryDictionaryDropDownList";
  174. dropdownListOptions.TextField = item.ControlTextFiled;
  175. dropdownListOptions.ValueField = item.ControlValueFiled;
  176. var ss = htmlHelper.DictionaryDropDownList(item.DictionaryCode, dropdownListOptions, htmlAttributes).ToHtmlString();
  177. control += "<div id='" + controlName + "QueryDictionaryDropDownList_div' " + cl + ">" + htmlHelper.DictionaryDropDownList(item.DictionaryCode, dropdownListOptions, htmlAttributes).ToHtmlString() + "</div>";
  178. }
  179. else if (item.ControlType == "CheckBox")
  180. {
  181. var ss = htmlHelper.CheckBox(controlName + "_QueryCheckBox", true, new { ID = controlName + "_QueryCheckBox" }) + "是/否";
  182. control += "<div id='" + controlName + "QueryCheckBox_div' " + cl + ">" +
  183. htmlHelper.CheckBox(controlName + "_QueryCheckBox", true, new { ID = controlName + "_QueryCheckBox" }) + "是/否" +
  184. "</div>";
  185. }
  186. else if (item.ControlType == "ComboGrid")
  187. {
  188. List<DataGridColumn> lstgridColumn = new List<DataGridColumn>();
  189. using (var scope = AutofacHelper.Container.BeginLifetimeScope())
  190. {
  191. IConfiguretermsInfoServices configuretermsServices = scope.Resolve<IConfiguretermsInfoServices>();
  192. List<Sys_ConfiguretermsExpand> listBModify = configuretermsServices.GetConfiguretermsExpand(item.ID);
  193. foreach (var bmitem in listBModify)
  194. {
  195. BoundFieldColumn bfc = new BoundFieldColumn { FieldName = bmitem.ColumnValue, HeaderText = bmitem.ColumnName, Width = 0.1, Align = AlignStyle.Center };
  196. lstgridColumn.Add(bfc);
  197. }
  198. }
  199. ComboGridOptions cgop = new ComboGridOptions
  200. {
  201. TextField = item.ControlTextFiled,
  202. ValueField = item.ControlValueFiled,
  203. ID = controlName + "_QueryComboGrid",
  204. Name = controlName + "_QueryComboGrid",
  205. GridOptions = new DataGridOptions
  206. {
  207. Columns = lstgridColumn,
  208. IsCheckOnSelect = true,
  209. DataSourceUrl = UrlHelper.GenerateContentUrl(item.PostUrl, htmlHelper.ViewContext.HttpContext),
  210. IsPagination = true,
  211. IsShowRowNumbers = true,
  212. IsSingleSelect = false
  213. }
  214. };
  215. control += "<div id='" + controlName + "QueryComboGrid_div' " + cl + ">" + htmlHelper.ComboGrid(cgop, htmlAttributes) + "</div>";
  216. }
  217. else if (item.ControlType == "TextBoxDate")
  218. {
  219. TextBoxOptions tbop = new TextBoxOptions
  220. {
  221. ID = controlName + "_QueryTextBoxDate",
  222. Name = controlName + "_QueryTextBoxDate",
  223. TextBoxType = TextBoxType.Date
  224. };
  225. var ss = htmlHelper.TextBox(tbop, htmlAttributes);
  226. control += "<div id='" + controlName + "QueryTextBoxDate_div' " + cl + ">" + htmlHelper.TextBox(tbop, htmlAttributes) + "</div>";
  227. }
  228. i++;
  229. }
  230. return control;
  231. }
  232. /// <summary>
  233. /// 批量修改控件,需要通过数据库配置具体的修改项
  234. /// </summary>
  235. /// <param name="htmlHelper"></param>
  236. /// <param name="htmlAttributes">自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary<string, string> {
  237. /// { "style", "width: 100%;" }, { "name", "ddlUsers" }
  238. /// }
  239. /// </param>
  240. /// <returns></returns>
  241. public static MvcHtmlString PositionBatchModify(this HtmlHelper htmlHelper, IDictionary<string, string> htmlAttributes = null)
  242. {
  243. var request = htmlHelper.ViewContext.RequestContext.HttpContext.Request;
  244. var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
  245. string menuNo = request["MNU"];
  246. string html = "";
  247. string listControlID = string.Empty;
  248. string columnName = string.Empty;
  249. List<Sys_BatchModify> listAttribute = null;
  250. IBatchModifyServices catchModifyServices = AutofacHelper.Container.Resolve<IBatchModifyServices>();
  251. listAttribute = catchModifyServices.GetBatchModifyList(menuNo);
  252. foreach (var item in listAttribute)
  253. {
  254. listControlID = item.listControl;
  255. columnName += item.Value + item.ControlType + "_div" + ",";
  256. }
  257. DropdownListOptions dropdownListOptions = new DropdownListOptions();
  258. dropdownListOptions.BindType = DropdownListBindType.PleaseSelect;
  259. dropdownListOptions.ItemSourceUrl = UrlHelper.GenerateContentUrl("~/Common/BatchUpdateDropDown?menuNo="
  260. + menuNo, htmlHelper.ViewContext.HttpContext);
  261. dropdownListOptions.BindType = DropdownListBindType.None;
  262. dropdownListOptions.Name = "DropdownBatchModify";
  263. dropdownListOptions.ID = "DropdownBatchModify";
  264. dropdownListOptions.OnSelect = "SystemBatchModifyControl.BatchModifyControl";
  265. //if (!string.IsNullOrEmpty(postFormUrl))
  266. // postFormUrl = "method=\"post\" action='" + postFormUrl + "'";
  267. html = "<div class=\"search_keyword\" id=\"BatchModifydiv\">\n";
  268. html += "<div class=\"search_input\">" +
  269. "<form id=\"formBatchModify\" method='post' action='" + urlHelper.Action("BatchModify", "Common").AddMenuParameter() + "' >" +
  270. "<ul>" +
  271. "<li class=\"sn\" style=\"padding-left: 5px;\">批量修改:</li>" +
  272. "<li class=\"sv\">" +
  273. Bowin.Web.Controls.Mvc.DropdownList.CreateControl(dropdownListOptions, htmlAttributes).Render() +
  274. "</li>" +
  275. "<li class=\"sv\" id=\"li_div\">" +
  276. GetBatchControl(htmlHelper, listAttribute) +
  277. "</li>" +
  278. "<li class=\"sn\" style=\"padding-left: 20px;\"><a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-confirm'\" onclick=\"SystemBatchModifyControl.BatchModifysubmit();\">确定</a>&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-cancel'\" onclick=\"SystemBatchModifyControl.closeBatchModifydiv();\">取消</a></li>" +
  279. "</ul>" +
  280. "<input type=\"hidden\" id='PL_hiddenBatchModify' name='PL_hiddenBatchModify' value='' />" +
  281. "<input type=\"hidden\" id='PL_hiddenBatchModifycolumnName' value='" + columnName + "' />" +
  282. "<input type=\"hidden\" id='PL_hiddenBatchModifylistControl' name='PL_hiddenBatchModifylistControl' value='" + listControlID + "' />" +
  283. "</form>" +
  284. "</div>";
  285. html += "</div>";
  286. return MvcHtmlString.Create(html);
  287. }
  288. /// <summary>
  289. /// 批量修改控件
  290. /// </summary>
  291. /// <param name="htmlHelper"></param>
  292. /// <param name="listAttribute"></param>
  293. /// <returns></returns>
  294. private static string GetBatchControl(HtmlHelper htmlHelper, List<Sys_BatchModify> listAttribute)
  295. {
  296. string control = string.Empty;
  297. int i = 0;
  298. foreach (var item in listAttribute)
  299. {
  300. if (item.ControlType == "TextBox")
  301. {
  302. TextBoxOptions tbop = new TextBoxOptions
  303. {
  304. ID = item.Value + "_TextBox",
  305. Name = item.Value + "_TextBox"
  306. };
  307. control += "<div id='" + item.Value + "TextBox_div' class='divbatchmodify'>" + htmlHelper.TextBox(tbop) + "</div>";
  308. }
  309. else if (item.ControlType == "DropdownList")
  310. {
  311. DropdownListOptions dropdownListOptions = new DropdownListOptions();
  312. dropdownListOptions.BindType = DropdownListBindType.PleaseSelect;
  313. dropdownListOptions.ID = item.Value + "_DropdownList";
  314. dropdownListOptions.Name = item.Value + "_DropdownList";
  315. dropdownListOptions.ItemSourceUrl = item.PostUrl;
  316. dropdownListOptions.TextField = item.ControlTextFiled;
  317. dropdownListOptions.ValueField = item.ControlValueFiled;
  318. control += "<div id='" + item.Value + "DropdownList_div' class='divbatchmodify'>" + htmlHelper.DropdownList(dropdownListOptions) + "</div>";
  319. }
  320. else if (item.ControlType == "DictionaryDropDownList")
  321. {
  322. DropdownListOptions dropdownListOptions = new DropdownListOptions();
  323. dropdownListOptions.BindType = DropdownListBindType.PleaseSelect;
  324. dropdownListOptions.ID = item.Value + "_DictionaryDropDownList";
  325. dropdownListOptions.Name = item.Value + "_DictionaryDropDownList";
  326. dropdownListOptions.TextField = item.ControlTextFiled;
  327. dropdownListOptions.ValueField = item.ControlValueFiled;
  328. control += "<div id='" + item.Value + "DictionaryDropDownList_div' class='divbatchmodify'>" + htmlHelper.DictionaryDropDownList(item.DictionaryCode, dropdownListOptions).ToHtmlString() + "</div>";
  329. }
  330. else if (item.ControlType == "CheckBox")
  331. {
  332. control += "<div id='" + item.Value + "CheckBox_div' class='divbatchmodify'>" +
  333. //"<input name='" + item.Value + "_CheckBox' type='checkbox' style='display:none' checked value='false'>" +
  334. "<input name='" + item.Value + "_CheckBox' class='batchUpdateCheckbox' id='" + item.Value + "_CheckBox' type='checkbox' value='true'>是/否" +
  335. //htmlHelper.CheckBox(item.Value + "_CheckBox") + "是/否" +
  336. "</div>";
  337. }
  338. else if (item.ControlType == "ComboGrid")
  339. {
  340. List<DataGridColumn> lstgridColumn = new List<DataGridColumn>();
  341. using (var scope = AutofacHelper.Container.BeginLifetimeScope())
  342. {
  343. IBatchModifyServices bcatchModifyServices = scope.Resolve<IBatchModifyServices>();
  344. List<Sys_BatchModifyExpand> listBModify = bcatchModifyServices.GetBatchModifyExpandList(item.BatchModifyID);
  345. foreach (var bmitem in listBModify)
  346. {
  347. BoundFieldColumn bfc = new BoundFieldColumn { FieldName = bmitem.ColumnValue, HeaderText = bmitem.ColumnName, Width = 0.1, Align = AlignStyle.Center };
  348. lstgridColumn.Add(bfc);
  349. }
  350. }
  351. ComboGridOptions cgop = new ComboGridOptions
  352. {
  353. TextField = item.ControlTextFiled,
  354. ValueField = item.ControlValueFiled,
  355. ID = item.Value + "_ComboGrid",
  356. Name = item.Value + "_ComboGrid",
  357. GridOptions = new DataGridOptions
  358. {
  359. Columns = lstgridColumn,
  360. IsCheckOnSelect = true,
  361. DataSourceUrl = UrlHelper.GenerateContentUrl(item.PostUrl, htmlHelper.ViewContext.HttpContext),
  362. IsPagination = true,
  363. IsShowRowNumbers = true,
  364. IsSingleSelect = false
  365. }
  366. };
  367. control += "<div id='" + item.Value + "ComboGrid_div' class='divbatchmodify'>" + htmlHelper.ComboGrid(cgop) + "</div>";
  368. }
  369. else if (item.ControlType == "TextBoxDate")
  370. {
  371. TextBoxOptions tbop = new TextBoxOptions
  372. {
  373. ID = item.Value + "_TextBoxDate",
  374. Name = item.Value + "_TextBoxDate",
  375. TextBoxType = TextBoxType.Date
  376. };
  377. control += "<div id='" + item.Value + "TextBoxDate_div' class='divbatchmodify'>" + htmlHelper.TextBox(tbop) + "</div>";
  378. }
  379. else if (item.ControlType == "TextBoxDateTime")
  380. {
  381. TextBoxOptions tbop = new TextBoxOptions
  382. {
  383. ID = item.Value + "_TextBoxDateTime",
  384. Name = item.Value + "_TextBoxDateTime",
  385. TextBoxType = TextBoxType.DateTime
  386. };
  387. control += "<div id='" + item.Value + "TextBoxDateTime_div' class='divbatchmodify'>" + htmlHelper.TextBox(tbop) + "</div>";
  388. }
  389. else if (item.ControlType == "NumberBox")
  390. {
  391. TextBoxOptions tbop = new TextBoxOptions
  392. {
  393. ID = item.Value + "_NumberBox",
  394. Name = item.Value + "_NumberBox",
  395. TextBoxType = TextBoxType.Normal
  396. };
  397. control += "<div id='" + item.Value + "NumberBox_div' class='divbatchmodify'>" + htmlHelper.TextBox(tbop, new Dictionary<string, string> { { "number", "true" } }) + "</div>";
  398. }
  399. i++;
  400. }
  401. return control;
  402. }
  403. }
  404. }