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
{
///
/// 自定义通讯录
/// add 作者: 季健国 QQ:181589805 by 2016-11-06
///
public class CusContactController : BaseController
{
#region 声明容器
///
/// 外部通讯录
///
ICusContactManage CusContactManage { get; set; }
///
/// 字典编码
///
ICodeManage CodeManage { get; set; }
#endregion
#region 公共变量
public string code = string.Empty;
public string sex = string.Empty;
#endregion
#region 基本视图
///
/// 列表
///
///
[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());
}
///
/// 编辑
///
///
[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 帮助方法
///
/// 加载列表
///
private PageInfo 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);
}
///
/// 保存通讯录
///
///
[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);
}
///
/// 删除通讯录
///
[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
}
}