using System; using System.Collections.Generic; using System.Web.Mvc; using WX.CRM.Common; using WX.CRM.IBLL.Wx; using WX.CRM.Model.Entity; using WX.CRM.Model.MAP; using WX.CRM.WebHelper; namespace WX.CRM.WEB.Controllers.WeiXin { public class InneruserJobnumController : BaseController { private IWX_INNERUSERJOBNUM jobnumBL; ValidationErrors errors = new ValidationErrors(); public InneruserJobnumController(IWX_INNERUSERJOBNUM _jobnumBL) { this.jobnumBL = _jobnumBL; } #region 首页 [AuthorizeRedirect(Roles = InitRights.CONST_工作微信员工关系)] public ActionResult Index() { ToolBar tool = new ToolBar(); string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.工作微信员工关系, userRightId); tool.AllowButton(toolbtn); ViewBag.ToolBar = tool; Pager pager = new Pager() { page = 1, rows = 10 }; string tableId = "tablist"; Table tab = new Table(tableId); tab.AddHeadCol("PKID", "10%", "编号"); tab.AddHeadCol("groupName", "", "组别"); tab.AddHeadCol("inneruserEid", "", "员工工号"); tab.AddHeadCol("WXUSERNAME", "15%", "微信用户名"); tab.AddHeadCol("WXNUMBER", "", "微信号"); tab.AddHeadCol("CTIME", "15%", "创建时间"); tab.AddHeadRow(); ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "5,8,10,15"); ViewBag.inneruserid = UserId; ViewBag.userGroupId = userGroupId; ViewBag.saleDeptId = saleDeptId; ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId); return View(); } #endregion #region 列表 [HttpPost] /// /// 按照条件获取数据 /// /// /// /// [AuthorizeRedirect(Roles = InitRights.CONST_工作微信员工关系)] public JsonResult GetHtmlList(Pager pager, string Username, string Num, string userId, string groupId, string columns) { string Eid = Request.Form["Eid"]; decimal saleid = 0; try { if (!string.IsNullOrWhiteSpace(Eid)) saleid = InnerUserHelper.Instance.GetUserIdByEid(Convert.ToDecimal(Eid.Trim())); List list = jobnumBL.GetList(ref pager, Username, Num, userId, groupId, saleid); Table table = new Table(columns, true); table.gridPager = pager; foreach (WX_INNERUSERJOBNUM_Extend model in list) { table.AddCol(model.wx_inneruserJobNum.PKID); table.AddCol(model.groupName); table.AddCol(model.inneruserEid.ToString() + " - " + model.inneruserName); table.AddCol(model.wx_inneruserJobNum.WXUSERNAME); table.AddCol(model.wx_inneruserJobNum.WXNUMBER); table.AddCol(model.wx_inneruserJobNum.CTIME); table.AddRow(); } var json = new { totalPages = pager.totalPages, totalRows = pager.totalRows, rowsList = table.GetRows() }; return Json(json, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.Error("InneruserJobnumController:" + ex.Message + ex.StackTrace); return JsonHandler.ManageMessage(ex.Message, false); } } #endregion #region 编辑 [HttpGet] [AuthorizeToolBar(InitRights.CONST_工作微信员工关系, InitToolBar.CONST_Edit)] public ActionResult Edit(string id) { WX_INNERUSERJOBNUM model = null; if (id == null) { model = new WX_INNERUSERJOBNUM(); // 数据初始化 } else { model = jobnumBL.GetModel(Convert.ToDecimal(id)); model.INNERUSERID = Convert.ToInt32(InnerUserHelper.Instance.GetEid(model.INNERUSERID)); } return View(model); } [HttpPost] [AuthorizeToolBar(InitRights.CONST_工作微信员工关系, InitToolBar.CONST_Edit)] public JsonResult Edit(WX_INNERUSERJOBNUM model) { if (!ModelState.IsValid) { return JsonHandler.ValidateFailMessage(); } if (model.PKID == 0) { bool result = jobnumBL.Create(ref errors, model.INNERUSERID.Value, model.WXUSERNAME, model.WXNUMBER); return JsonHandler.InsertMessage(errors, result); } else { bool result = jobnumBL.Update(ref errors, model.PKID, model.INNERUSERID.Value, model.WXUSERNAME, model.WXNUMBER); return JsonHandler.UpdateMessage(errors, result); } } #endregion #region 删除 /// /// 删除数据 /// /// /// [AuthorizeToolBar(InitRights.CONST_工作微信员工关系, InitToolBar.CONST_Delete)] public JsonResult Delete(string id) { if (string.IsNullOrWhiteSpace(id)) { return JsonHandler.ManageMessage("删除失败", false); } bool result = jobnumBL.Delete(ref errors, Convert.ToDecimal(id)); return JsonHandler.DeleteMessage(errors, result); } #endregion } }