Controller.cst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using Befri.Query;
  8. using Befri.Core;
  9. using Befri.Utility;
  10. using Befri.Web.Mvc;
  11. using Befri.Web.Mvc.Extensions;
  12. using Befri.Goldhoo.Models;
  13. using Befri.Goldhoo.Services;
  14. using Befri.Goldhoo.MvcUI.Controllers;
  15. namespace Befri.Goldhoo.MvcUI.Areas.Basedata.Controllers
  16. {
  17. /// <summary>
  18. /// 名 称:【<%= Request.Table.Text %>】管理控制器类
  19. /// 主要功能:
  20. /// 开发人员:
  21. /// 开发日期: <%= DateTime.Today.ToString("yyyy-MM") %>
  22. /// </summary>
  23. [HandleException("defaultPolicy")]
  24. public class <%= Table.AliasName %>Controller : BaseController
  25. {
  26. readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  27. private I<%= Table.AliasName %>Service _<%= Table.aliasName %>Service;
  28. public <%= Table.AliasName %>Controller(I<%= Table.AliasName %>Service service)
  29. {
  30. this._<%= Table.aliasName %>Service = service;
  31. }
  32. /// <summary>
  33. /// 打开【<%= Table.Text %>】列表记录页面
  34. /// </summary>
  35. /// <returns></returns>
  36. public ActionResult Index()
  37. {
  38. return View("<%= Table.AliasName %>");
  39. }
  40. /// <summary>
  41. /// 打开【<%= Table.Text %>】新增、修改页面
  42. /// </summary>
  43. /// <returns></returns>
  44. public ActionResult Edit<%= Table.AliasName %>()
  45. {
  46. return View("<%= Table.AliasName %>Edit");
  47. }
  48. /// <summary>
  49. /// 获取【<%= Table.Text %>】列表记录
  50. /// </summary>
  51. /// <returns></returns>
  52. public ActionResult List<%= Table.AliasName %>(string searchText, int page, int rows)
  53. {
  54. try
  55. {
  56. SqlPageParameter param = new SqlPageParameter("[<%= Table.SchemaName %>].[<%= Table.TableName %>]", page, rows, OrderExpression.Asc("<%= KeyParamsValueText %>"));
  57. param.AddWhereExpr(SegmentExpression.SqlSegment(" 1 = 1 "));
  58. if (!string.IsNullOrEmpty(searchText))
  59. {
  60. param.AddWhereExpr(LogicExpression.And())
  61. .AddWhereExpr(SegmentExpression.SqlSegment(" ( "))
  62. .AddWhereExpr(SimpleExpression.Like("<%= Table.AliasName %>Number", DbType.String, "%" + searchText + "%"))
  63. .AddWhereExpr(LogicExpression.Or())
  64. .AddWhereExpr(SimpleExpression.Like("<%= Table.AliasName %>Name", DbType.String, "%" + searchText + "%"))
  65. .AddWhereExpr(SegmentExpression.SqlSegment(" ) "));
  66. }
  67. DataSet dataSet = this._<%= Table.aliasName %>Service.GetPageData(param);
  68. int total = (int)dataSet.Tables[0].Rows[0][0];
  69. var result = DataTableMapper.ToList<<%= Table.AliasName %>>(dataSet.Tables[1]);
  70. return this.Ajax(total, result);
  71. }
  72. catch (Exception ex)
  73. {
  74. logger.Error("ERROR", ex);
  75. return this.AjaxException(this.ControllerContext, ex);
  76. }
  77. }
  78. /// <summary>
  79. /// 获取【<%= Table.Text %>】记录
  80. /// </summary>
  81. /// <returns></returns>
  82. public ActionResult Load<%= Table.AliasName %>(<%= KeyParamsText %>)
  83. {
  84. try
  85. {
  86. <%= Table.AliasName %> <%= Table.aliasName %> = this._<%= Table.aliasName %>Service.FindObject<<%= Table.AliasName %>>("[<%= Table.SchemaName %>].[<%= Table.TableName %>]", "<%= Table.AliasName %>Id", <%= KeyParamsValueText %>);
  87. return this.Json(<%= Table.aliasName %>, JsonRequestBehavior.AllowGet);
  88. }
  89. catch (Exception ex)
  90. {
  91. logger.Error("ERROR", ex);
  92. return this.AjaxException(this.ControllerContext, ex);
  93. }
  94. }
  95. /// <summary>
  96. /// 创建【<%= Table.Text %>】记录
  97. /// </summary>
  98. /// <returns></returns>
  99. public ActionResult Create<%= Table.AliasName %>(<%= Table.AliasName %> <%= Table.aliasName %>)
  100. {
  101. try
  102. {
  103. <%= Table.aliasName %>.CreatedBy = CurrentEmpName;
  104. this._<%= Table.aliasName %>Service.Create<%= Table.AliasName %>(<%= Table.aliasName %>);
  105. <%= Table.AliasName %> result = this._<%= Table.aliasName %>Service.FindObject<<%= Table.AliasName %>>("[<%= Table.SchemaName %>].[<%= Table.TableName %>]", "<%= Table.AliasName %>Id", <%= Table.aliasName %>.<%= KeyParamsValueText %>);
  106. return this.Ajax(result);
  107. }
  108. catch (Exception ex)
  109. {
  110. logger.Error("ERROR", ex);
  111. return this.AjaxException(this.ControllerContext, ex);
  112. }
  113. }
  114. /// <summary>
  115. /// 更新【<%= Table.Text %>】记录
  116. /// </summary>
  117. /// <returns></returns>
  118. public ActionResult Update<%= Table.AliasName %>(<%= Table.AliasName %> <%= Table.aliasName %>)
  119. {
  120. try
  121. {
  122. <%= Table.aliasName %>.ModifiedBy = CurrentEmpName;
  123. this._<%= Table.aliasName %>Service.Update<%= Table.AliasName %>(<%= Table.aliasName %>);
  124. <%= Table.AliasName %> result = this._<%= Table.aliasName %>Service.FindObject<<%= Table.AliasName %>>("[<%= Table.SchemaName %>].[<%= Table.TableName %>]", "<%= Table.AliasName %>Id", <%= Table.aliasName %>.<%= KeyParamsValueText %>);
  125. return this.Ajax(result);
  126. }
  127. catch (Exception ex)
  128. {
  129. logger.Error("ERROR", ex);
  130. return this.AjaxException(this.ControllerContext, ex);
  131. }
  132. }
  133. /// <summary>
  134. /// 删除【<%= Table.Text %>】记录
  135. /// </summary>
  136. /// <returns></returns>
  137. public ActionResult Delete<%= Table.AliasName %>(<%= KeyParamsText %>)
  138. {
  139. try
  140. {
  141. this._<%= Table.aliasName %>Service.Delete<%= Table.AliasName %>(<%= KeyParamsValueText %>);
  142. return this.Ajax();
  143. }
  144. catch (Exception ex)
  145. {
  146. logger.Error("ERROR", ex);
  147. return this.AjaxException(this.ControllerContext, ex);
  148. }
  149. }
  150. }
  151. }