CreditFormulaController.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.ViewModel;
  7. using EMIS.CommonLogic.ScoreManage;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel.ScoreManage;
  10. using Bowin.Web.Controls.Mvc;
  11. using Bowin.Common.JSON;
  12. using Bowin.Common.Exceptions;
  13. namespace EMIS.Web.Controllers.ScoreManage
  14. {
  15. [Authorization]
  16. public class CreditFormulaController : Controller
  17. {
  18. public ICreditFormulaServices creditFormulaServices { get; set; }
  19. //
  20. // GET: /CreditFormula/
  21. public ActionResult List()
  22. {
  23. return View();
  24. }
  25. /// <summary>
  26. /// 查询列表
  27. /// </summary>
  28. /// <param name="pararms"></param>
  29. /// <returns></returns>
  30. [HttpPost]
  31. public ActionResult List(QueryParamsModel pararms)
  32. {
  33. string name = pararms.getExtraString("textName");
  34. return Json(creditFormulaServices.GetCreditFormulaGrid(name, (int)pararms.page, (int)pararms.rows));
  35. }
  36. /// <summary>
  37. /// 编辑
  38. /// </summary>
  39. /// <param name="creditFormulaID"></param>
  40. /// <returns></returns>
  41. public ActionResult Edit(Guid? creditFormulaID)
  42. {
  43. CreditFormulaView creditFormulaView = new CreditFormulaView();
  44. if (creditFormulaID != null && creditFormulaID.Value != Guid.Empty)
  45. {
  46. ER_CreditFormula creditFormula = creditFormulaServices.GetCreditFormula(creditFormulaID);
  47. creditFormulaView.CreditFormulaID = creditFormula.CreditFormulaID;
  48. creditFormulaView.Name = creditFormula.Name;
  49. creditFormulaView.Scores = creditFormula.Scores;
  50. }
  51. return View(creditFormulaView);
  52. }
  53. /// <summary>
  54. /// 编辑
  55. /// </summary>
  56. /// <param name="creditFormula"></param>
  57. /// <returns></returns>
  58. [HttpPost]
  59. public ActionResult Edit(CreditFormulaView creditFormulaView)
  60. {
  61. try
  62. {
  63. creditFormulaServices.CreditFormulaAdd(creditFormulaView);
  64. return Json(new ReturnMessage()
  65. {
  66. IsSuccess = true,
  67. Message = "保存成功!"
  68. });
  69. }
  70. catch (Exception ex)
  71. {
  72. return Json(new ReturnMessage()
  73. {
  74. IsSuccess = true,
  75. Message = "保存失败,原因:" + ex.Message + "!"
  76. });
  77. }
  78. }
  79. /// <summary>
  80. /// 删除
  81. /// </summary>
  82. /// <param name="creditFormulas"></param>
  83. /// <returns></returns>
  84. [HttpPost]
  85. public ActionResult Delete(string creditFormulaIDs)
  86. {
  87. try
  88. {
  89. List<Guid> list = new List<Guid>();
  90. for (int i = 0; i < creditFormulaIDs.Split(',').Length; i++)
  91. {
  92. string id = creditFormulaIDs.Split(',')[i];
  93. if (!string.IsNullOrEmpty(id))
  94. {
  95. Guid creditFormulaID = new Guid(id);
  96. list.Add(creditFormulaID);
  97. }
  98. }
  99. creditFormulaServices.CreditFormulaDelete(list);
  100. return Json("删除成功");
  101. }
  102. catch (Exception ex)
  103. {
  104. string mge = ex.Message;
  105. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  106. if (num != null)
  107. {
  108. if (num.Number == 547)
  109. mge = "请先删除所有关联的数据,如参数设置!";
  110. }
  111. return this.Json("删除失败,原因:" + mge);
  112. }
  113. }
  114. /// <summary>
  115. /// 绑定学分下拉列表
  116. /// </summary>
  117. /// <param name="bindType"></param>
  118. /// <returns></returns>
  119. [HttpPost]
  120. public ActionResult CreditFormulaDataBind(DropdownListBindType? bindType)
  121. {
  122. List<DropdownListItem> list = creditFormulaServices.GetCreditFormulaList("").Select(x => new DropdownListItem { Text = x.Name, Value = x.CreditFormulaID.ToString() }).ToList();
  123. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  124. DropdownList.FormatDropdownItemList(dbt, list);
  125. return base.Json(list);
  126. }
  127. /// <summary>
  128. /// 绑定学分下拉列表
  129. /// </summary>
  130. /// <param name="bindType"></param>
  131. /// <returns></returns>
  132. [HttpPost]
  133. public ActionResult CreditFormulaDataJsonBind(DropdownListBindType? bindType)
  134. {
  135. List<DropdownListItem> list = creditFormulaServices.GetCreditFormulaList("").Select(x => new DropdownListItem { Text = x.Name, Value = new ER_CreditFormula { CreditFormulaID = x.CreditFormulaID, Name = x.Name, Scores = x.Scores }.ToJson() }).ToList();
  136. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  137. DropdownList.FormatDropdownItemList(dbt, list);
  138. return base.Json(list);
  139. }
  140. }
  141. }