ScoreFormulaController.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using System.Dynamic;
  7. using EMIS.ViewModel;
  8. using EMIS.Utility;
  9. using EMIS.CommonLogic.ScoreManage;
  10. using EMIS.Entities;
  11. using Bowin.Common.Mvc;
  12. using Bowin.Common.Linq.Entity;
  13. using Bowin.Web.Controls.Mvc;
  14. using EMIS.ViewModel.ScoreManage;
  15. using Bowin.Common.Exceptions;
  16. using EMIS.ViewModel.CacheManage;
  17. using Bowin.Common.JSON;
  18. namespace EMIS.Web.Controllers.ScoreManage
  19. {
  20. [Authorization]
  21. public class ScoreFormulaController : JsonNetController
  22. {
  23. public IScoreFormulaServices scoreFormulaServices { get; set; }
  24. /// <summary>
  25. /// 总分公式页面
  26. /// </summary>
  27. /// <returns></returns>
  28. public ActionResult List()
  29. {
  30. var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
  31. ViewBag.ScoreDynamicTypes = scoreDynamicTypes;
  32. return View();
  33. }
  34. /// <summary>
  35. /// 总分公式列表查询
  36. /// </summary>
  37. /// <param name="pararms"></param>
  38. /// <returns></returns>
  39. [HttpPost]
  40. public ActionResult List(QueryParamsModel pararms)
  41. {
  42. var name = pararms.getExtraString("textName");
  43. var query = scoreFormulaServices.GetScoreFormulaGrid(name, (int)pararms.page, (int)pararms.rows);
  44. var differentDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
  45. var list = WrapResult(query.rows, differentDynamicTypes);
  46. return Json(new { total = list.Count, rows = list });
  47. }
  48. /// <summary>
  49. /// 编辑
  50. /// </summary>
  51. /// <param name="scoreFormulaID"></param>
  52. /// <returns></returns>
  53. public ActionResult Edit(Guid? scoreFormulaID)
  54. {
  55. ScoreFormulaView scoreFormulaView = new ScoreFormulaView();
  56. if (scoreFormulaID != null && scoreFormulaID != Guid.Empty)
  57. {
  58. ER_ScoreFormula scoreFormula = scoreFormulaServices.GetScoreFormula(scoreFormulaID);
  59. scoreFormulaView.ScoreFormulaID = scoreFormula.ScoreFormulaID;
  60. scoreFormulaView.Name = scoreFormula.Name;
  61. }
  62. return View(scoreFormulaView);
  63. }
  64. /// <summary>
  65. /// 编辑
  66. /// </summary>
  67. /// <param name="scoreFormula"></param>
  68. /// <returns></returns>
  69. [HttpPost]
  70. public ActionResult Edit(ScoreFormulaView scoreFormulaView)
  71. {
  72. try
  73. {
  74. var scoreFormulaDetailList = DataGrid.GetTableData<ScoreFormulaDropdownDetailView>("dgScoreFormulaDetailList");
  75. scoreFormulaServices.ScoreFormulaAdd(scoreFormulaView, scoreFormulaDetailList);
  76. return Json(new ReturnMessage()
  77. {
  78. IsSuccess = true,
  79. Message = "保存成功。"
  80. });
  81. }
  82. catch (Exception ex)
  83. {
  84. return Json(new ReturnMessage()
  85. {
  86. IsSuccess = false,
  87. Message = "保存失败,原因:" + ex.Message
  88. });
  89. }
  90. }
  91. /// <summary>
  92. /// 删除
  93. /// </summary>
  94. /// <param name="scoreFormulaIDs"></param>
  95. /// <returns></returns>
  96. [HttpPost]
  97. public ActionResult Delete(string scoreFormulaIDs)
  98. {
  99. try
  100. {
  101. List<Guid> list = new List<Guid>();
  102. for (int i = 0; i < scoreFormulaIDs.Split(',').Length; i++)
  103. {
  104. string id = scoreFormulaIDs.Split(',')[i];
  105. if (!string.IsNullOrEmpty(id))
  106. {
  107. Guid scoreFormulaID = new Guid(id);
  108. list.Add(scoreFormulaID);
  109. }
  110. }
  111. scoreFormulaServices.ScoreFormulaDelete(list);
  112. return Json("删除成功");
  113. }
  114. catch (Exception ex)
  115. {
  116. string mge = ex.Message;
  117. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  118. if (num != null)
  119. {
  120. if (num.Number == 547)
  121. mge = "请先删除所有关联的数据,如参数设置!";
  122. }
  123. return base.Json("删除失败,原因:" + mge);
  124. }
  125. }
  126. /// <summary>
  127. /// 总分公式明细页面
  128. /// </summary>
  129. /// <param name="scoreFormulaID"></param>
  130. /// <returns></returns>
  131. [HttpPost]
  132. public ActionResult ScoreFormulaDetailList(Guid? scoreFormulaID)
  133. {
  134. var listScoreFormulaDetail = scoreFormulaServices.GetScoreFormulaDetailListByScoreFormulaID(scoreFormulaID);
  135. return Json(new GridResultSet<ScoreFormulaDropdownDetailView>() { rows = listScoreFormulaDetail, total = listScoreFormulaDetail.Count });
  136. }
  137. /// <summary>
  138. ///
  139. /// </summary>
  140. /// <param name="result"></param>
  141. /// <param name="differentDynamicTypes"></param>
  142. /// <returns></returns>
  143. private List<ExpandoObject> WrapResult(List<ER_ScoreFormula> result, IEnumerable<Sys_DictionaryItem> differentDynamicTypes)
  144. {
  145. var list = new List<ExpandoObject>();
  146. if (result == null || result.Count == 0)
  147. {
  148. return list;
  149. }
  150. var scoreFormulas = result.Select(s => new { s.ScoreFormulaID, s.Name }).Distinct();
  151. foreach (var scoreFormula in scoreFormulas)
  152. {
  153. dynamic item = new ExpandoObject();
  154. item.ScoreFormulaID = scoreFormula.ScoreFormulaID;
  155. item.Name = scoreFormula.Name;
  156. ER_ScoreFormulaDetail scoreFormulaDetail = null;
  157. foreach (var differentDynamicType in differentDynamicTypes)
  158. {
  159. scoreFormulaDetail = scoreFormulaServices.GetScoreFormulaDetailList(scoreFormula.ScoreFormulaID).Where(x => x.ScoreType == differentDynamicType.Value).FirstOrDefault();
  160. var percentage = scoreFormulaDetail == null ? 0 : scoreFormulaDetail.Percentage;
  161. ((IDictionary<string, object>)item).Add("ScoreType" + differentDynamicType.Value.ToString(), percentage.ToString());
  162. }
  163. list.Add(item);
  164. }
  165. return list;
  166. }
  167. /// <summary>
  168. /// 绑定下拉列表
  169. /// </summary>
  170. /// <param name="bindType"></param>
  171. /// <returns></returns>
  172. [HttpPost]
  173. public ActionResult ScoreFormulaDataBind(DropdownListBindType? bindType)
  174. {
  175. List<DropdownListItem> list = scoreFormulaServices.GetScoreFormulaList("").Select(x => new DropdownListItem { Text = x.Name, Value = x.ScoreFormulaID.ToString() }).ToList();
  176. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  177. DropdownList.FormatDropdownItemList(dbt, list);
  178. return base.Json(list);
  179. }
  180. /// <summary>
  181. /// 绑定下拉列表
  182. /// </summary>
  183. /// <param name="bindType"></param>
  184. /// <returns></returns>
  185. [HttpPost]
  186. public ActionResult ScoreFormulaDataJosnBind(DropdownListBindType? bindType)
  187. {
  188. List<DropdownListItem> list = new List<DropdownListItem>();
  189. var scoreType = IdNameExt.GetDictionaryItem(DictionaryItem.CF_ScoreType.ToString());
  190. List<ER_ScoreFormula> listScoreFormula = scoreFormulaServices.GetScoreFormulaList("");
  191. foreach (var scoreFormula in listScoreFormula)
  192. {
  193. string reulst = "{\"ScoreFormulaID\":\"" + scoreFormula.ScoreFormulaID + "\",";
  194. foreach (var st in scoreType)
  195. {
  196. ER_ScoreFormulaDetail scoreFormulaDetail = scoreFormula.ER_ScoreFormulaDetail.ToList().Where(x => x.ScoreType == st.Value).FirstOrDefault();
  197. if (scoreFormulaDetail != null)
  198. reulst += "\"Formula_" + st.Value + "\":\"" + scoreFormulaDetail.Percentage + "\",";
  199. else
  200. reulst += "\"Formula_" + st.Value + "\":\"0\",";
  201. }
  202. reulst = reulst.Substring(0, reulst.Length - 1) + "}";
  203. DropdownListItem dlt = new DropdownListItem { Text = scoreFormula.Name, Value = reulst };
  204. list.Add(dlt);
  205. }
  206. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  207. DropdownList.FormatDropdownItemList(dbt, list);
  208. return base.Json(list);
  209. }
  210. }
  211. }