ConditionExtensions.cs 24 KB

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