CusContactController.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Ant.Service.Common;
  7. using Central.Control.Domain;
  8. using MES.Production.Service.IService;
  9. using ChangFa.Machinery.WebPage.Controllers;
  10. namespace ChangFa.Machinery.WebPage.Areas.ComManage.Controllers
  11. {
  12. /// <summary>
  13. /// 自定义通讯录
  14. /// add 作者: 季健国 QQ:181589805 by 2016-11-06
  15. /// </summary>
  16. public class CusContactController : BaseController
  17. {
  18. #region 声明容器
  19. /// <summary>
  20. /// 外部通讯录
  21. /// </summary>
  22. ICusContactManage CusContactManage { get; set; }
  23. /// <summary>
  24. /// 字典编码
  25. /// </summary>
  26. ICodeManage CodeManage { get; set; }
  27. #endregion
  28. #region 公共变量
  29. public string code = string.Empty;
  30. public string sex = string.Empty;
  31. #endregion
  32. #region 基本视图
  33. /// <summary>
  34. /// 列表
  35. /// </summary>
  36. /// <returns></returns>
  37. [UserAuthorizeAttribute(ModuleAlias = "Contact", OperaAction = "View")]
  38. public ActionResult Index()
  39. {
  40. //获取客户类型
  41. var codelist = this.CodeManage.GetCode("LXRLX");
  42. ViewData["codelist"] = codelist;
  43. code = Request["code"] ?? "";
  44. ViewData["code"] = code;
  45. sex = Request["sex"] ?? "";
  46. ViewData["sex"] = sex;
  47. //职业资格
  48. var zwlist = this.CodeManage.GetCode("ZW");
  49. ViewData["zwlist"] = zwlist;
  50. ViewBag.Search = base.keywords;
  51. return View(BindList());
  52. }
  53. /// <summary>
  54. /// 编辑
  55. /// </summary>
  56. /// <returns></returns>
  57. [UserAuthorizeAttribute(ModuleAlias = "Contact", OperaAction = "Detail")]
  58. public ActionResult Detail(int? id)
  59. {
  60. //获取客户类型
  61. var codelist = this.CodeManage.GetCode("LXRLX");
  62. ViewData["codelist"] = codelist;
  63. //职业资格
  64. var zwlist = this.CodeManage.GetCode("ZW");
  65. ViewData["zwlist"] = zwlist;
  66. var _entity = this.CusContactManage.Get(p => p.ID == id) ?? new COM_CUSCONTACT();
  67. return View(_entity);
  68. }
  69. #endregion
  70. #region 帮助方法
  71. /// <summary>
  72. /// 加载列表
  73. /// </summary>
  74. private PageInfo<COM_CUSCONTACT> BindList()
  75. {
  76. //预加载
  77. var query = this.CusContactManage.LoadAll(p => p.FK_USERID == CurrentUser.Id);
  78. //where
  79. if (!string.IsNullOrEmpty(base.keywords))
  80. {
  81. query = query.Where(p => p.NAME.Contains(keywords) || p.PHOME.Contains(keywords));
  82. }
  83. // 性别
  84. if (!string.IsNullOrEmpty(sex))
  85. {
  86. var sexs = Convert.ToInt32(sex);
  87. query = query.Where(p => p.SEX == sexs);
  88. }
  89. //客户类型
  90. if (!string.IsNullOrEmpty(code))
  91. {
  92. query = query.Where(p => p.FK_TYPE == code);
  93. }
  94. //手机号
  95. if (!string.IsNullOrEmpty(base.keywords))
  96. {
  97. query = query.Where(p => p.PHOME.Contains(keywords) || p.TELNO.Contains(keywords));
  98. }
  99. query = query.OrderByDescending(p => p.CREATETIME);
  100. //Executed
  101. return this.CusContactManage.Query(query, base.page, base.pagesize);
  102. }
  103. /// <summary>
  104. /// 保存通讯录
  105. /// </summary>
  106. /// <returns></returns>
  107. [UserAuthorizeAttribute(ModuleAlias = "wbtxl", OperaAction = "Add,Edit")]
  108. public ActionResult Save(COM_CUSCONTACT entity)
  109. {
  110. bool isEdit = false;
  111. var json = new JsonHelper() { Msg = "保存成功", Status = "n" };
  112. if (entity != null)
  113. {
  114. var _entity = new COM_CUSCONTACT();
  115. //Add
  116. if (entity.ID>0)
  117. {
  118. isEdit = true;
  119. }
  120. entity.FK_USERID = CurrentUser.Id;
  121. entity.PROV = Request.Form["hkprov"];
  122. entity.CITY = Request.Form["hkcity"];
  123. _entity = entity;
  124. if (!this.CusContactManage.IsExist(p => p.PHOME == _entity.PHOME && p.FK_USERID == _entity.FK_USERID && p.ID != _entity.ID))
  125. {
  126. if (this.CusContactManage.SaveOrUpdate(_entity, isEdit))
  127. {
  128. json.Status = "y";
  129. }
  130. else
  131. {
  132. json.Msg = "保存失败";
  133. }
  134. }
  135. else
  136. {
  137. json.Msg = "该用户已存在!";
  138. }
  139. }
  140. return Json(json);
  141. }
  142. /// <summary>
  143. /// 删除通讯录
  144. /// </summary>
  145. [UserAuthorizeAttribute(ModuleAlias = "wbtxl", OperaAction = "Remove")]
  146. public ActionResult Delete(string idList)
  147. {
  148. JsonHelper json = new JsonHelper() { Msg = "删除完毕", Status = "n" };
  149. if (!string.IsNullOrEmpty(idList))
  150. {
  151. var idList1 = idList.Trim(',').Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToList();
  152. this.CusContactManage.Delete(p => idList1.Contains(p.ID));
  153. json.Status = "y";
  154. }
  155. else
  156. {
  157. json.Msg = "未找到要删除的通讯录";
  158. }
  159. return Json(json);
  160. }
  161. #endregion
  162. #region 其他调用
  163. #endregion
  164. }
  165. }