目录

  1. ASP.NET MVC搭建项目后台UI框架—1、后台主框架
  2. ASP.NET MVC搭建项目后台UI框架—2、菜单特效
  3. ASP.NET MVC搭建项目后台UI框架—3、面板折叠和展开
  4. ASP.NET MVC搭建项目后台UI框架—4、tab多页签支持
  5. ASP.NET MVC搭建项目后台UI框架—5、Demo演示Controller和View的交互
  6. ASP.NET MVC搭建项目后台UI框架—6、客户管理(添加、修改、查询、分页)
  7. ASP.NET MVC搭建项目后台UI框架—7、统计报表
  8. ASP.NET MVC搭建项目后台UI框架—8、将View中选择的数据行中的部分数据传入到Controller中
  9. ASP.NET MVC搭建项目后台UI框架—9、服务器端排序

接着之前未写完的继续,本篇,我将讲解在此UI框架中和ASP.NET MVC4进行结合开发。效果如下:

这里,我将添加和修改用了两个不同的视图,当然也可以把添加和修改放到同一个视图中,但是要写一些业务逻辑代码来区分当前调用的是修改还是添加,根据添加和修改的不同,而对界面进行不同的操作。

添加控制器Customer,关于更新操作,我就不得不想吐槽一下NHibernate,他妹的,每次都要先load一次,然后再Update()一次,如果你直接save,它就把你表中有,但是界面上没有传过来的值全部更新为null了,相比之下EF就好多了。

  1. public class CustomerController : Controller
  2. {
  3. private string message = "<script>frameElement.api.opener.hidePublishWin('{0}', '{1}','{2}'); </script>"; //消息,是否关闭弹出窗,是否停留在当前分页(0,1)
  4.  
  5. #region 客户管理主页
  6. public ActionResult Index()
  7. {
  8. return View();
  9. }
  10.  
  11. /// <summary>
  12. /// 客户列表
  13. /// </summary>
  14. /// <param name="filter"></param>
  15. /// <returns></returns>
  16. [HttpPost]
  17. public JsonResult List(CustomerFilter filter)
  18. {
  19. filter.PageSize = int.MaxValue;
  20. var dataSource = CustomerInfo.GetByFilter(filter);
  21.  
  22. List<CustomerInfo> queryData = dataSource.ToList();
  23.  
  24. var data = queryData.Select(u => new
  25. {
  26. ID = u.ID,
  27. CusCode = u.CusCode,
  28. CusName = u.CusName,
  29. BusssinessType = u.BusssinessType.GetDescription(false),
  30. Balance = u.Balance,
  31. CreditAmount = u.CreditAmount,
  32. Status = u.Status.GetDescription(false),
  33. Country = u.Country,
  34. CompanyName = u.CompanyName,
  35. Delivery = GetDeliveryList(u.ExpressCurInfoBy)
  36.  
  37. });
  38.  
  39. //构造成Json的格式传递
  40. var result = new { iTotalRecords = queryData.Count, iTotalDisplayRecords = , data = data };
  41. return Json(result, JsonRequestBehavior.AllowGet);
  42. }
  43. #region 添加客户
  44. /// <summary>
  45. /// 添加客户
  46. /// </summary>
  47. /// <param name="id"></param>
  48. /// <returns></returns>
  49. public ActionResult AddCustomer()
  50. {
  51. ViewBag.Title = "添加客户";
  52. return View();
  53. }
  54.  
  55. /// <summary>
  56. /// 添加客户
  57. /// </summary>
  58. /// <param name="info"></param>
  59. /// <returns></returns>
  60. [HttpPost]
  61. public ActionResult AddCustomer(CustomerInfo info)
  62. {
  63. string msg = string.Empty;
  64. if (ModelState.IsValid)
  65. {
  66. try
  67. {
  68. info.Save();
  69. msg = "添加客户成功。";
  70. }
  71. catch (Exception ex)
  72. {
  73. msg = "添加客户失败!" + ex.Message;
  74. ViewBag.Msg = string.Format(message, msg, false,"");
  75. }
  76. ViewBag.Msg = string.Format(message, msg, true,"");
  77. }
  78. return View();
  79. }
  80. #endregion
  81.  
  82. #region 修改客户
  83. /// <summary>
  84. /// 修改客户
  85. /// </summary>
  86. /// <param name="id"></param>
  87. /// <returns></returns>
  88. public ActionResult UpdateCustomer(int id)
  89. {
  90. ViewBag.Title = "修改客户";
  91. var result = CustomerInfo.Load(id);
  92.  
  93. return View(result);
  94. }
  95.  
  96. /// <summary>
  97. /// 修改客户
  98. /// </summary>
  99. /// <param name="info"></param>
  100. /// <returns></returns>
  101. [HttpPost]
  102. public ActionResult UpdateCustomer(CustomerInfo info)
  103. {
  104. string msg = string.Empty;
  105. if (ModelState.IsValid)
  106. {
  107. try
  108. {
  109. info.Update();
  110. msg = "修改客户成功。";
  111. }
  112. catch (Exception ex)
  113. {
  114. msg = "修改客户失败!" + ex.Message;
  115. ViewBag.Msg = string.Format(message, msg, false,"");
  116. }
  117. ViewBag.Msg = string.Format(message, msg, true,"");
  118. }
  119. return View();
  120. }
  121. #endregion
  122. }

添加视图Index

  1. @{
  2. ViewBag.Title = "客户信息";
  3. }
  4. <link href="~/libs/DataTables-1.10.6/media/css/jquery.dataTablesNew.css" rel="stylesheet" />
  5. <script src="~/libs/DataTables-1.10.6/media/js/jquery.dataTables.min.js"></script>
  6. <script src="~/Scripts/DataTablesExt.js"></script>
  7. <script type="text/javascript">
  8. //弹出框
  9. var addDG, updateDG, matchDG;
  10. var w = 424, h = 520; //宽,高
  11. //添加记录
  12. function showPublishWin() {
  13. addDG = new $.dialog({
  14. id: "AddChannel",
  15. title: "添加客户",
  16. content: "url:/Customer/AddCustomer",
  17. width: w,
  18. height: h,
  19. max: false,
  20. min: false,
  21. lock: true,
  22. close: true,
  23. btnBar: false
  24. });
  25. addDG.show();
  26. }
  27. //修改记录
  28. function modifyRecord(id) {
  29. updateDG = new $.dialog({
  30. id: "UpdateCustomer",
  31. title: "修改客户",
  32. content: "url:/Customer/UpdateCustomer/" + id,
  33. width: w,
  34. height: h,
  35. max: false,
  36. min: false,
  37. lock: true,
  38. close: true,
  39. btnBar: false
  40. });
  41. updateDG.show();
  42. }
  43. //隐藏弹出框
  44. function hidePublishWin(msg, result, isStay) {
  45. var icon = "success.gif";
  46. if (result == "False") {
  47. icon = "error.gif";
  48. }
  49. $.dialog({
  50. title: "提示",
  51. icon: icon,
  52. titleIcon: 'lhgcore.gif',
  53. content: msg,
  54. lock: true,
  55. ok: true
  56. });
  57. if (result != "False") {
  58. if (addDG) {
  59. addDG.close();
  60. }
  61. if (updateDG) {
  62. updateDG.close();
  63. }
  64. if (matchDG) {
  65. matchDG.close();
  66. }
  67. if (isStay == 0) {
  68. reloadList();
  69. }
  70. else {
  71. reloadListNew();
  72. }
  73. }
  74. }
  75. function matchDelivery(id) {
  76. matchDG = new $.dialog({
  77. id: "UpdateCustomer",
  78. title: "客户匹配",
  79. content: "url:/Customer/DeliveryMatching/" + id,
  80. width: 800,
  81. height: h,
  82. max: false,
  83. min: false,
  84. lock: true,
  85. close: true,
  86. btnBar: false
  87. });
  88. matchDG.show();
  89. }
  90. //刷新,但是停留在当前分页
  91. function reloadListNew() {
  92. var tables = $('#table_local').dataTable().api();//获取DataTables的Api,详见 http://www.datatables.net/reference/api/
  93. tables.ajax.reload(null,false);
  94. }
  95. </script>
  96. <script type="text/javascript">
  97. $(function () {
  98. var h = $(document).height() - 258;
  99. var table = $("#table_local").dataTable({
  100. bProcessing: true,
  101. "scrollY": h,
  102. "scrollCollapse": "true",
  103. "dom": 'ftr<"bottom"lip><"clear">',
  104. "bServerSide": false, //指定从服务器端获取数据
  105. sServerMethod: "POST",
  106. sAjaxSource: "@Url.Action("List", "Customer")",
  107. "fnServerParams": function (aoData) { //查询条件
  108. aoData.push(
  109. { "name": "CusCode", "value": $("#CusCode").val() },
  110. { "name": "CusName", "value": $("#CusName").val() }
  111. );
  112. },
  113. columns: [{ title: "1", "visible": false, "data": "ID" },
  114. { "data": "CusCode", title: "客户代码" },
  115. { "data": "CusName", title: "客户名称" },
  116. { "data": "BusssinessType", title: "业务类型", width: "100" },
  117. { "data": "Country", title: "国家", width: "200" },
  118. { "data": "CompanyName", title: "公司名称", width: "200" },
  119. { "data": "Delivery", title: "收货商", width: "150" },
  120. { "data": "Balance", title: "账户余额", width: "150" },
  121. { "data": "CreditAmount", title: "信用额度", width: "150" },
  122. { "data": "Status", title: "是否启用", width: "100" },
  123. {
  124. "data": "ID", orderable: false, title: "操作", width: "140", "render": function (data, type, row, meta) { //自定义列
  125. var re = "<div style='text-align:center'><a style='visibility:visible' onclick='modifyRecord(" + data + ")'>修改</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  126. re = re + "<a style='visibility:visible' onclick='matchDelivery(" + data + ")'>匹配</a></div>";
  127. return re;
  128. }
  129. }
  130. ],
  131. paging: true,//分页
  132. ordering: true,//是否启用排序
  133. searching: true,//搜索
  134. language: {
  135. "sProcessing": "处理中...",
  136. lengthMenu: '每页显示:<select class="form-control input-xsmall">' + '<option value="5">5</option>' + '<option value="10">10</option>' + '<option value="15">15</option>'
  137. + '<option value="20">20</option>' + '<option value="25">25</option>' + '<option value="30">30</option>' + '<option value="35">35</option>' + '<option value="40">40</option>',//左上角的分页大小显示。
  138. search: '<span class="label label-success">搜索:</span>',//右上角的搜索文本,可以写html标签
  139.  
  140. paginate: {//分页的样式内容。
  141. previous: "上一页",
  142. next: "下一页",
  143. first: "",
  144. last: ""
  145. },
  146.  
  147. zeroRecords: "暂无记录",//table tbody内容为空时,tbody的内容。
  148. //下面三者构成了总体的左下角的内容。
  149. info: "总共 <span class='pagesStyle'>(_PAGES_) </span>页,显示 _START_ -- _END_ ,共<span class='recordsStyle'> (_TOTAL_)</span> 条",//左下角的信息显示,大写的词为关键字。初始_MAX_ 条
  150. infoEmpty: "0条记录",//筛选为空时左下角的显示。
  151. infoFiltered: ""//筛选之后的左下角筛选提示,
  152. },
  153. pagingType: "full_numbers"//分页样式的类型
  154.  
  155. });
  156. //设置选中行样式
  157. $('#table_local tbody').on('click', 'tr', function () {
  158. if ($(this).hasClass('selected')) {
  159. $(this).removeClass('selected');
  160. }
  161. else {
  162. table.$('tr.selected').removeClass('selected');
  163. $(this).addClass('selected');
  164. }
  165. });
  166. });
  167. //查询 刷新
  168. function reloadList() {
  169. var tables = $('#table_local').dataTable().api();//获取DataTables的Api,详见 http://www.datatables.net/reference/api/
  170. tables.ajax.reload();
  171. }
  172. </script>
  173. <div class="areabx clear">
  174. @using (Html.BeginForm("List", null, FormMethod.Get, new { @clase = "form-inline", @role = "form" }))
  175. {
  176. <div class="areabx_header">客户信息</div>
  177. <ul class="formod mgt10">
  178. <li><span>客户代码:</span>@Html.TextBox("CusCode", "", new { @class = "trade-time wid153" })</li>
  179. <li><span>客户名称:</span>@Html.TextBox("CusName", "", new { @class = "trade-time" })</li>
  180. <li></li>
  181. </ul>
  182. <div class="botbtbx pdb0" style="margin-bottom: -30px;">
  183. <input type="button" value="添加客户" class="btn btn-primary" onclick="showPublishWin()" />
  184. <input type="button" value="查询" onclick="reloadList();" class="btn btn-primary">
  185. </div>
  186. }
  187. <div class="tob_box mgt15">
  188. <table id="table_local" class="display" cellspacing="0" cellpadding="0" border="0" style="width: 100%">
  189. </table>
  190. </div>
  191. </div>

添加AddCustomer视图,之前公司ASP.NET MVC的项目没有启用模型验证,界面验证代码都是自己js写的,我晕,那用ASP.NET MVC干嘛呢?使用框架就是要充分发挥框架优良的功能,尽可能高效快速的开发,并减少开发人员的代码量。

  1. @model Core.Customer.CustomerInfo
  2. @using ProjectBase.Utils
  3. @Html.Raw(ViewBag.Msg)
  4. <div class="areabx clear">
  5. @* <div class="areabx_header">@ViewBag.Title</div>*@
  6. <div class="tian_xi">
  7. @using (Html.BeginForm("AddCustomer", "Customer", FormMethod.Post, new { @clase = "form-inline", @role = "form", name = "from1" }))
  8. {
  9. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  10. <tbody>
  11. <tr style="height: 40px;">
  12. <td style="width: 120px; text-align: right;">客户代码:</td>
  13. <td>
  14. @Html.TextBoxFor(x => x.CusCode, new { @class = "trade-timen", @id = "cusCode" })<span class="wtps">* @Html.ValidationMessageFor(m => m.CusCode)</span></td>
  15. </tr>
  16. <tr style="height: 40px;">
  17. <td align="right">客户名称:</td>
  18. <td>
  19. @Html.TextBoxFor(x => x.CusName, new { @class = "trade-timen", @id = "cusName" })<span class="wtps">* @Html.ValidationMessageFor(m => m.CusName)</span></td>
  20. </tr>
  21. <tr style="height: 40px;">
  22. <td align="right">手机:</td>
  23. <td>
  24. @Html.TextBoxFor(x => x.Phone, new { @class = "trade-timen" })</td>
  25. </tr>
  26. <tr style="height: 40px;">
  27. <td align="right">电话:</td>
  28. <td>
  29. @Html.TextBoxFor(x => x.Tel, new { @class = "trade-timen" })</td>
  30. </tr>
  31. <tr style="height: 40px;">
  32. <td align="right">邮箱:</td>
  33. <td>
  34. @Html.TextBoxFor(x => x.Email, new { @class = "trade-timen", @id = "email" })<span class="wtps">@Html.ValidationMessageFor(m => m.Email)</span></td>
  35. </tr>
  36. <tr style="height: 40px;">
  37. <td align="right">传真:</td>
  38. <td>
  39. @Html.TextBoxFor(x => x.Fax, new { @class = "trade-timen" })</td>
  40. </tr>
  41. <tr style="height: 40px;">
  42. <td align="right">国家:</td>
  43. <td>
  44. @Html.TextBoxFor(x => x.Country, new { @class = "trade-timen" })</td>
  45. </tr>
  46. <tr style="height: 40px;">
  47. <td align="right">地址:</td>
  48. <td>
  49. @Html.TextBoxFor(x => x.Address, new { @class = "trade-timen" })</td>
  50. </tr>
  51. <tr style="height: 40px;">
  52. <td align="right">公司名称:</td>
  53. <td>
  54. @Html.TextBoxFor(x => x.CompanyName, new { @class = "trade-timen" })</td>
  55. </tr>
  56. <tr style="height: 40px;">
  57. <td align="right">业务类型:</td>
  58. <td>
  59. @Html.DropDownListFor(x => x.BusssinessType, @Html.EnumToList(typeof(Core.Customer.Busssiness), false), new { @class = "trade-timen", style = "width:180px" })
  60. </tr>
  61. <tr style="height: 40px;">
  62. <td align="right">是否启用:</td>
  63. <td> @Html.RadioButtonFor(x => x.Status, "0", new { Checked = "checked", @name = "status" }) &nbsp;&nbsp;&nbsp;&nbsp;
  64. <span class="radioMagin">否 @Html.RadioButtonFor(x => x.Status, "1", new { @name = "status" })</span></td>
  65. </tr>
  66. </tbody>
  67. </table>
  68. <input type="submit" value="确定" class="popbtn1 mg">
  69. <input type="button" value="关闭" class="popbtn3 mg2" onclick="frameElement.api.opener.addDG.close();" />
  70. }
  71. </div>
  72. </div>

添加UpdateCustomer视图

  1. @model Core.Customer.CustomerInfo
  2. @using ProjectBase.Utils
  3. @Html.Raw(ViewBag.Msg)
  4. <div class="areabx clear">
  5. @* <div class="areabx_header">@ViewBag.Title</div>*@
  6. <div class="tian_xi">
  7. @using (Html.BeginForm("UpdateCustomer", "Customer", FormMethod.Post, new { @clase = "form-inline", @role = "form", name = "from1" }))
  8. {
  9. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  10. <tbody>
  11. <tr style="height: 40px;">
  12. <td style="width: 120px; text-align: right;">客户代码:</td>
  13. <td>
  14. @Html.TextBoxFor(x => x.CusCode, new { @class = "trade-timen", @id = "cusCode", @readOnly = "readOnly" })<span class="wtps">* @Html.ValidationMessageFor(m => m.CusCode)</span></td>
  15. @Html.HiddenFor(x => x.ID)
  16. </tr>
  17. <tr style="height: 40px;">
  18. <td align="right">客户名称:</td>
  19. <td>
  20. @Html.TextBoxFor(x => x.CusName, new { @class = "trade-timen", @id = "cusName" })<span class="wtps">* @Html.ValidationMessageFor(m => m.CusName)</span></td>
  21. </tr>
  22. <tr style="height: 40px;">
  23. <td align="right">手机:</td>
  24. <td>
  25. @Html.TextBoxFor(x => x.Phone, new { @class = "trade-timen" })</td>
  26. </tr>
  27. <tr style="height: 40px;">
  28. <td align="right">电话:</td>
  29. <td>
  30. @Html.TextBoxFor(x => x.Tel, new { @class = "trade-timen" })</td>
  31. </tr>
  32. <tr style="height: 40px;">
  33. <td align="right">邮箱:</td>
  34. <td>
  35. @Html.TextBoxFor(x => x.Email, new { @class = "trade-timen", @id = "email" }) <span class="wtps">@Html.ValidationMessageFor(m => m.Email)</span></td>
  36. </tr>
  37. <tr style="height: 40px;">
  38. <td align="right">传真:</td>
  39. <td>
  40. @Html.TextBoxFor(x => x.Fax, new { @class = "trade-timen" })</td>
  41. </tr>
  42. <tr style="height: 40px;">
  43. <td align="right">国家:</td>
  44. <td>
  45. @Html.TextBoxFor(x => x.Country, new { @class = "trade-timen" })</td>
  46. </tr>
  47. <tr style="height: 40px;">
  48. <td align="right">地址:</td>
  49. <td>
  50. @Html.TextBoxFor(x => x.Address, new { @class = "trade-timen" })</td>
  51. </tr>
  52. <tr style="height: 40px;">
  53. <td align="right">公司名称:</td>
  54. <td>
  55. @Html.TextBoxFor(x => x.CompanyName, new { @class = "trade-timen" })</td>
  56. </tr>
  57. <tr style="height: 40px;">
  58. <td align="right">业务类型:</td>
  59. <td>
  60. @Html.DropDownListFor(x => x.BusssinessType, @Html.EnumToList(typeof(Core.Customer.Busssiness), false), new { @class = "trade-timen", style = "width:180px" })
  61. </tr>
  62. <tr style="height: 40px;">
  63. <td align="right">是否启用:</td>
  64. <td> @Html.RadioButtonFor(x => x.Status, "0", new { Checked = "checked", @name = "status" }) &nbsp;&nbsp;&nbsp;&nbsp;
  65. <span class="radioMagin">否 @Html.RadioButtonFor(x => x.Status, "1", new { @name = "status" })</span></td>
  66. </tr>
  67. </tbody>
  68. </table>
  69. <input type="submit" value="确定" class="popbtn1 mg">
  70. <input type="button" value="关闭" class="popbtn3 mg2" onclick="frameElement.api.opener.updateDG.close();" />
  71. }
  72. </div>
  73. </div>

客户实体CustomerInfo

  1. /// <summary>
  2. /// 客户信息
  3. /// </summary>
  4. public class CustomerInfo //: DomainObject<CustomerInfo, int, ICustomerInfoRepository>
  5. {
  6. #region property
  7. /// <summary>
  8. /// 客户代码
  9. /// </summary>
  10. [Required(ErrorMessage = "客户代码不能为空!")]
  11. [StringLength(, MinimumLength = , ErrorMessage = "客户代码最大长度为30个字符")]
  12. public virtual string CusCode { get; set; }
  13. /// <summary>
  14. /// 客户名称
  15. /// </summary>
  16. [Required(ErrorMessage = "客户名称不能为空!")]
  17. [StringLength(, MinimumLength = , ErrorMessage = "客户名称最大长度为30个字符")]
  18. public virtual string CusName { get; set; }
  19. /// <summary>
  20. /// 客户业务类型
  21. /// </summary>
  22. public virtual Busssiness BusssinessType { get; set; }
  23. /// <summary>
  24. /// 手机
  25. /// </summary>
  26. public virtual string Phone { get; set; }
  27. /// <summary>
  28. /// 电话
  29. /// </summary>
  30. public virtual string Tel { get; set; }
  31. /// <summary>
  32. /// 邮箱
  33. /// </summary>
  34. [RegularExpression(@"^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$", ErrorMessage="邮箱格式不正确!")]
  35. public virtual string Email { get; set; }
  36. /// <summary>
  37. /// 传真
  38. /// </summary>
  39. public virtual string Fax { get; set; }
  40. /// <summary>
  41. /// 国家
  42. /// </summary>
  43. public virtual string Country { get; set; }
  44. /// <summary>
  45. /// 地址
  46. /// </summary>
  47. public virtual string Address { get; set; }
  48. /// <summary>
  49. /// 公司名称
  50. /// </summary>
  51. public virtual string CompanyName { get; set; }
  52. /// <summary>
  53. /// 金额
  54. /// </summary>
  55. public virtual decimal Balance { get; set; }
  56. /// <summary>
  57. /// 信用额度
  58. /// </summary>
  59. public virtual decimal CreditAmount { get; set; }
  60. /// <summary>
  61. /// 状态
  62. /// </summary>
  63. public virtual CustomerStatus Status { get; set; }
  64. /// <summary>
  65. /// 快件收货商信息
  66. /// </summary>
  67. public virtual IList<ExpressCurInfo> ExpressCurInfoBy { get; set; }
  68. #endregion
  69.  
  70. #region common method
  71. /// <summary>
  72. /// 分页获取数据
  73. /// </summary>
  74. /// <param name="filter"></param>
  75. /// <returns></returns>
  76. public static IPageOfList<CustomerInfo> GetByFilter(CustomerFilter filter)
  77. {
  78. return Dao.GetByFilter(filter);
  79. }
  80. #endregion
  81. }

查询类CustomerFilter

  1. public class CustomerFilter : ParameterFilter
  2. {
  3. /// <summary>
  4. /// 客户代码
  5. /// </summary>
  6. public virtual string CusCode { get; set; }
  7. /// <summary>
  8. /// 客户名称
  9. /// </summary>
  10. public virtual string CusName { get; set; }
  11.  
  12. /// <summary>
  13. /// 生产NHQL查询语句
  14. /// </summary>
  15. /// <returns></returns>
  16. public override string ToHql()
  17. {
  18. string hql = "";
  19. if (!string.IsNullOrEmpty(CusCode))
  20. {
  21. hql += " and Cus_Code =:CusCode ";
  22. }
  23. if (!string.IsNullOrEmpty(CusName))
  24. {
  25. hql += " and Cus_Name =:CusName ";
  26. }
  27.  
  28. return hql;
  29. }
  30.  
  31. /// <summary>
  32. /// 构造查询参数
  33. /// </summary>
  34. /// <returns></returns>
  35. public override Dictionary<string, object> GetParameters()
  36. {
  37. var result = new Dictionary<string, object>();
  38. if (!string.IsNullOrEmpty(CusCode))
  39. {
  40. result["CusCode"] = CusCode.Trim();
  41. }
  42. if (!string.IsNullOrEmpty(CusName))
  43. {
  44. result["CusName"] = CusName.Trim();
  45. }
  46. return result;
  47. }
  48. }
  49. using System;
  50. using System.Collections.Generic;
  51. using System.Linq;
  52. using System.Text;
  53. using ProjectBase.Utils.Entities;
  54.  
  55. namespace ProjectBase.Data
  56. {
  57. public abstract class ParameterFilter
  58. {
  59. public ParameterFilter()
  60. {
  61. HasQueryString = false;
  62. PageSize = ;
  63. }
  64.  
  65. public string OrderBy { get;set; }
  66.  
  67. public abstract string ToHql();
  68.  
  69. public override string ToString()
  70. {
  71. return ToHql();
  72. }
  73.  
  74. public abstract Dictionary<string, object> GetParameters();
  75.  
  76. public string GetOrderString()
  77. {
  78. if (OrderBy.HasValue())
  79. return " Order By " + OrderBy;
  80. return String.Empty;
  81. }
  82.  
  83. protected string GetLike(string value)
  84. {
  85. return "%" + value + "%";
  86. }
  87.  
  88. public int PageIndex { get; set; }
  89.  
  90. public int PageSize { get; set; }
  91.  
  92. /// <summary>
  93. /// 标识此构造器是包含全部查询语句。
  94. /// 若为 False,则ToHql() 只需要构造条件查询,系统会自动在前面加上<code>" from " + typeof(T).Name + " a where 1=1 "</code>
  95. /// 若为 True, ToHql() 需要返回 连form在类的完整Hql语句
  96. /// </summary>
  97. public bool HasQueryString { get; set; }
  98.  
  99. protected static bool HasValue(string str)
  100. {
  101. return str.HasValue();
  102. }
  103.  
  104. public static bool HasValue<T>(System.Nullable<T> value) where T:struct
  105. {
  106. return value.HasValue;
  107. }
  108.  
  109. }
  110. }

在这里,我只演示了控制器和视图的交互,至于Hhibernate和Unity等数据的操作,这里暂时不讲,因为你也可以使用其它的ORM框架和IOC框架,诸如EF、AutoFac等等。这里主要讲解jquery datatables和ASP.NET MVC的结合使用,但是这里只演示了客户端分页排序,后面我会讲服务器分页排序。我发现,网上都没有ASP.NET MVC和Datatables结合的完整的服务器分页、排序的Demo,只看到PHP的。于是我不断的尝试,皇天不负有心人,终于试验成功了,后面我会为大家讲述实现方式。

ASP.NET MVC搭建项目后台UI框架—6、客户管理(添加、修改、查询、分页)的更多相关文章

  1. ASP.NET MVC搭建项目后台UI框架—1、后台主框架

    目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...

  2. ASP.NET MVC搭建项目后台UI框架—11、自动加载下拉框查询

    ASP.NET MVC搭建项目后台UI框架—1.后台主框架 需求:在查询记录的时候,输入第一个字,就自动把以这个字开头的相关记录查找出来,输入2个字就过滤以这两个子开头的记录,依次类推. 突然要用到这 ...

  3. ASP.NET MVC搭建项目后台UI框架—2、菜单特效

    目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...

  4. ASP.NET MVC搭建项目后台UI框架—3、面板折叠和展开

    目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...

  5. ASP.NET MVC搭建项目后台UI框架—4、tab多页签支持

    目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...

  6. ASP.NET MVC搭建项目后台UI框架—5、Demo演示Controller和View的交互

    目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...

  7. ASP.NET MVC搭建项目后台UI框架—7、统计报表

    ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NET M ...

  8. ASP.NET MVC搭建项目后台UI框架—8、将View中选择的数据行中的部分数据传入到Controller中

    目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...

  9. ASP.NET MVC搭建项目后台UI框架—9、服务器端排序

    ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NET M ...

随机推荐

  1. 《Entity Framework 6 Recipes》中文翻译系列 (21) -----第四章 ASP.NET MVC中使用实体框架之在页面中创建查询和使用ASP.NET URL路由过虑

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 4.2. 构建一个搜索查询 搜索数据是几乎所有应用的一个基本功能.它一般是动态的,因 ...

  2. lintcode循环数组之连续子数组求和

    v 题目:连续子数组求和 II 给定一个整数循环数组(头尾相接),请找出一个连续的子数组,使得该子数组的和最大.输出答案时,请分别返回第一个数字和最后一个数字的值.如果多个答案,请返回其中任意一个. ...

  3. Objective-C中的类目,延展,协议

    Objective-C中的类目(Category),延展(Extension),协议(Protocol)这些名词看起来挺牛的,瞬间感觉OC好高大上.在其他OOP语言中就没见过这些名词,刚看到这三个名词 ...

  4. 连连看游戏(dfs)【华为上机题目】

    1 连连看游戏 今天同学给我做了道编程题目,貌似是华为的,题目描述大概是这样的: 给定一个连连看棋盘,棋盘上每个点都有各种图案(用非0数字表示),输入棋盘上的任意两个左标,判断这两个坐标对应的图案是否 ...

  5. beego上传文件

    html代码: <form id="fform" method="POST" enctype="multipart/form-data" ...

  6. Electron Angular 开发小记

    一介绍 electron分为主进程和渲染进程,主进程负责和原生交互,控制窗口等. 渲染进程就是普通网页.主进程和渲染进程可以通过ipcMain(主进程使用)及ipcRenderer(渲染进程用)通信 ...

  7. 微信小程序开发初体验

    微信小程序上线几天了,趁着周末补了一下JS,然后今天参照文档和教程写了个小demo 文档地址       教程地址 看文档就看了一点时间,因为以前没接触过JS框架,但是接触过PHP框架= = ,所以理 ...

  8. Sql Server之使用T_SQL创建,修改,查看数据库信息

    一.使用Transact_SQL创建数据库 Transact_SQL语法如下:  create database database_name   [ on     [primary]  [<fi ...

  9. 在ASP.NET Core中怎么使用HttpContext.Current

    一.前言 我们都知道,ASP.NET Core作为最新的框架,在MVC5和ASP.NET WebForm的基础上做了大量的重构.如果我们想使用以前版本中的HttpContext.Current的话,目 ...

  10. LINQ(集成化查询)

    LINQ可以对数组.集合等数据结构进行查询.筛选.排序等操作:也可以用于与数据库交互:也支持对XML的操作,使用LINQ技术可以动态创建.筛选和修改XML数据和直接操作XML文件. 一). LINQ基 ...