123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using Ant.Service.Common;
- using Central.Control.Domain;
- using MES.Production.Service.IService;
- using ChangFa.Machinery.WebPage.Controllers;
- namespace ChangFa.Machinery.WebPage.Areas.ComManage.Controllers
- {
- /// <summary>
- /// 自定义通讯录
- /// add 作者: 季健国 QQ:181589805 by 2016-11-06
- /// </summary>
- public class CusContactController : BaseController
- {
- #region 声明容器
- /// <summary>
- /// 外部通讯录
- /// </summary>
- ICusContactManage CusContactManage { get; set; }
- /// <summary>
- /// 字典编码
- /// </summary>
- ICodeManage CodeManage { get; set; }
- #endregion
- #region 公共变量
- public string code = string.Empty;
- public string sex = string.Empty;
- #endregion
- #region 基本视图
- /// <summary>
- /// 列表
- /// </summary>
- /// <returns></returns>
- [UserAuthorizeAttribute(ModuleAlias = "Contact", OperaAction = "View")]
- public ActionResult Index()
- {
- //获取客户类型
- var codelist = this.CodeManage.GetCode("LXRLX");
- ViewData["codelist"] = codelist;
- code = Request["code"] ?? "";
- ViewData["code"] = code;
- sex = Request["sex"] ?? "";
- ViewData["sex"] = sex;
- //职业资格
- var zwlist = this.CodeManage.GetCode("ZW");
- ViewData["zwlist"] = zwlist;
- ViewBag.Search = base.keywords;
- return View(BindList());
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <returns></returns>
- [UserAuthorizeAttribute(ModuleAlias = "Contact", OperaAction = "Detail")]
- public ActionResult Detail(int? id)
- {
- //获取客户类型
- var codelist = this.CodeManage.GetCode("LXRLX");
- ViewData["codelist"] = codelist;
- //职业资格
- var zwlist = this.CodeManage.GetCode("ZW");
- ViewData["zwlist"] = zwlist;
- var _entity = this.CusContactManage.Get(p => p.ID == id) ?? new COM_CUSCONTACT();
- return View(_entity);
- }
- #endregion
- #region 帮助方法
- /// <summary>
- /// 加载列表
- /// </summary>
- private PageInfo<COM_CUSCONTACT> BindList()
- {
- //预加载
- var query = this.CusContactManage.LoadAll(p => p.FK_USERID == CurrentUser.Id);
- //where
- if (!string.IsNullOrEmpty(base.keywords))
- {
- query = query.Where(p => p.NAME.Contains(keywords) || p.PHOME.Contains(keywords));
- }
- // 性别
- if (!string.IsNullOrEmpty(sex))
- {
- var sexs = Convert.ToInt32(sex);
- query = query.Where(p => p.SEX == sexs);
- }
- //客户类型
- if (!string.IsNullOrEmpty(code))
- {
- query = query.Where(p => p.FK_TYPE == code);
- }
- //手机号
- if (!string.IsNullOrEmpty(base.keywords))
- {
- query = query.Where(p => p.PHOME.Contains(keywords) || p.TELNO.Contains(keywords));
- }
- query = query.OrderByDescending(p => p.CREATETIME);
- //Executed
- return this.CusContactManage.Query(query, base.page, base.pagesize);
- }
- /// <summary>
- /// 保存通讯录
- /// </summary>
- /// <returns></returns>
- [UserAuthorizeAttribute(ModuleAlias = "wbtxl", OperaAction = "Add,Edit")]
- public ActionResult Save(COM_CUSCONTACT entity)
- {
- bool isEdit = false;
- var json = new JsonHelper() { Msg = "保存成功", Status = "n" };
- if (entity != null)
- {
- var _entity = new COM_CUSCONTACT();
- //Add
- if (entity.ID>0)
- {
- isEdit = true;
- }
- entity.FK_USERID = CurrentUser.Id;
- entity.PROV = Request.Form["hkprov"];
- entity.CITY = Request.Form["hkcity"];
- _entity = entity;
- if (!this.CusContactManage.IsExist(p => p.PHOME == _entity.PHOME && p.FK_USERID == _entity.FK_USERID && p.ID != _entity.ID))
- {
- if (this.CusContactManage.SaveOrUpdate(_entity, isEdit))
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存失败";
- }
- }
- else
- {
- json.Msg = "该用户已存在!";
- }
- }
- return Json(json);
- }
- /// <summary>
- /// 删除通讯录
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "wbtxl", OperaAction = "Remove")]
- public ActionResult Delete(string idList)
- {
- JsonHelper json = new JsonHelper() { Msg = "删除完毕", Status = "n" };
- if (!string.IsNullOrEmpty(idList))
- {
- var idList1 = idList.Trim(',').Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(p => int.Parse(p)).ToList();
- this.CusContactManage.Delete(p => idList1.Contains(p.ID));
- json.Status = "y";
- }
- else
- {
- json.Msg = "未找到要删除的通讯录";
- }
- return Json(json);
- }
- #endregion
- #region 其他调用
- #endregion
- }
- }
|