using System; using System.Collections.Generic; using System.Web.Mvc; using WX.CRM.Common; using WX.CRM.IBLL.Base; using WX.CRM.WebHelper; namespace WX.CRM.WEB.Controllers.Base { public class SalesDepartmentController : BaseController { private IBAS_SALESDEPARTMENT deptBiz; private IBAS_SALESDEPARTMENT_Q deptBiz_Q; ValidationErrors errors = new ValidationErrors(); public SalesDepartmentController(IBAS_SALESDEPARTMENT _deptBiz, IBAS_SALESDEPARTMENT_Q _deptBiz_Q) { this.deptBiz = _deptBiz; this.deptBiz_Q = _deptBiz_Q; } #region 首页 [AuthorizeRedirect(Roles = InitRights.CONST_营业部管理)] public ActionResult Index() { //ToolBar ToolBar tool = new ToolBar(); string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.营业部管理, userRightId); //= InitRights.营业部管理.ToolBars.Where(p => userRightId.Contains(p.RightId)&&p.ToolBarId) //.Select(p => p.ToolBarCode).ToArray(); tool.AllowButton(toolbtn); // tool.AllowButton("Create", "Edit", "Details", "Delete"); ViewBag.ToolBar = tool; //table Pager page = new Pager() { page = 1, rows = 10 }; string tableId = "tablist"; Table table = new Table(tableId); table.AddHeadCol("saleDeptId", "10%", "部门ID"); table.AddHeadCol("saleDeptCode", "10%", "部门编码"); table.AddHeadCol("deptName", "10%", "部门名称"); table.AddHeadCol("LinkName", "10%", "联系人"); table.AddHeadCol("AreaCode", "10%", "邮编"); table.AddHeadCol("Phone", "10%", "联系电话"); table.AddHeadCol("Address", "", "营业部地址"); table.AddHeadRow(); ViewBag.gridTable = table.GetTable() + Pagination.GetPage(page, tableId, "15,30,50,100"); return View(); } #endregion #region 列表 /// /// 按照条件获取数据 /// /// /// /// [AuthorizeRedirect(Roles = InitRights.CONST_营业部管理)] public JsonResult GetHtmlList(Pager pager, string columns) { string companyId = Request.Form["companyId"]; string deptName = Request.Form["deptName"]; string saleDeptCode = Request.Form["saleDeptCode"]; string creationDate1 = Request.Form["creationDate1"]; string creationDate2 = Request.Form["creationDate2"]; List list = deptBiz_Q.GetList(ref pager, companyId, deptName, saleDeptCode, creationDate1, creationDate2); Table table = new Table(columns, true); table.gridPager = pager; foreach (WX.CRM.Model.Entity.BAS_SALESDEPARTMENT model in list) { table.AddCol(model.map_SALEDEPTID.ToString()); table.AddCol(model.map_SALEDEPTCODE); table.AddCol(model.map_DEPTNAME); //table.AddCol(model.businessLicense); //table.AddCol(model.legal); table.AddCol(model.map_LINKNAME); table.AddCol(model.map_AREACODE); table.AddCol(model.map_PHONE); table.AddCol("text-align:left", "", "  " + model.map_ADDRESS); table.AddRow(); } var json = new { totalPages = pager.totalPages, totalRows = pager.totalRows, rowsList = table.GetRows() }; return Json(json, JsonRequestBehavior.AllowGet); } #endregion #region 详细 [AuthorizeToolBar(InitRights.CONST_营业部管理, InitToolBar.CONST_Details)] public ActionResult Details(string id) { WX.CRM.Model.Entity.BAS_SALESDEPARTMENT model = null; if (id != null) model = deptBiz_Q.GetModel(Convert.ToDecimal(id)); else model = new WX.CRM.Model.Entity.BAS_SALESDEPARTMENT(); return View(model); } #endregion #region 编辑 [HttpGet] [AuthorizeToolBar(InitRights.CONST_营业部管理, InitToolBar.CONST_Edit)] public ActionResult Edit(string id) { WX.CRM.Model.Entity.BAS_SALESDEPARTMENT model = null; if (id == null) { model = new WX.CRM.Model.Entity.BAS_SALESDEPARTMENT(); } else model = deptBiz_Q.GetModel(Convert.ToDecimal(id)); return View(model); } [HttpPost] [AuthorizeToolBar(InitRights.CONST_营业部管理, InitToolBar.CONST_Edit)] public JsonResult Edit(WX.CRM.Model.Entity.BAS_SALESDEPARTMENT model) { if (!ModelState.IsValid) return JsonHandler.ValidateFailMessage(); if (model.map_SALEDEPTID == 0) { model.CREATIONBY = UserId; bool result = deptBiz.Create(ref errors, model); return JsonHandler.InsertMessage(errors, result); } else { model.UPDATEBY = UserId; model.UPDATEDATE = DateTime.Now; bool result = deptBiz.Update(ref errors, model); 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 = deptBiz.Delete(ref errors, Convert.ToDecimal(id)); return JsonHandler.DeleteMessage(errors, result); } #endregion #region 获取销售组树形 public JsonResult GetTreeList() { List obj = new List(); obj.Add(new { id = 0, text = "集团公司", iconCls = "icon-transf", children = DataCacheHelper.GetCache().GetTreeList_saleDepartMent() }); return Json(obj, JsonRequestBehavior.AllowGet); } #endregion } }