using Estsh.Core.Controllers; using Estsh.Core.Model.ExcelModel; using Estsh.Core.Model.Result; using Estsh.Core.Models; using Estsh.Core.Services.IServices; using Estsh.Core.Util; using Microsoft.AspNetCore.Mvc; using System.Collections; /*************************************************************************************************** * * 更新人:sitong.dong * 描述:客户管理 * 修改时间:2022.06.22 * 修改日志:系统迭代升级 * **************************************************************************************************/ namespace Estsh.Core.Web.Controllers { /// /// 客户订单维护 /// public class CustomerController : BaseController { private ICustomerService service; public CustomerController(ICustomerService _service) { service = _service; } // // GET: /Customer/ public ActionResult Index() { return View(); } /// /// 获取客户管理列表数据 /// /// 菜单名称 /// 分页 /// 排序方式 /// 排序列 /// public ActionResult getCustomerListByPage(String customerCode,String customerName, Pager pager, String direction, String sort, String enabled="Y") { int factoryId = CurrentEmp.FactoryId; Hashtable result = new Hashtable(); result.Add("pager.pageNo", pager.pageNo); Hashtable dataHt = this.service.getCustomerListByPage(enabled,customerCode,customerName, factoryId, pager, direction, sort); result.Add("rows", dataHt["dataList"]); result.Add("pager.totalRows", dataHt["totalCount"]); result.Add("sort", sort); result.Add("direction", direction); return Json(result); } /// /// 获取下拉列表数据 /// /// public ActionResult getSelectCustomer() { Hashtable result = new Hashtable(); List CustomerList = this.service.getSelectCustomer(); result.Add("list", CustomerList); return Json(result); } /// /// 保存数据 /// /// public ActionResult saveCustomer() { String editType = Request.Form["editType"].ToString(); String customerCode = Request.Form["customerCode"].ToString(); String customerName = Request.Form["customerName"].ToString(); String customerTel = Request.Form["customerTel"].ToString(); String customerAddr = Request.Form["customerAddr"].ToString(); String customerId = Request.Form["customerId"].ToString(); String enabled = Request.Form["enabled"].ToString(); SysCustomer sysCustomer = new SysCustomer(); sysCustomer.CustomerCode = customerCode; sysCustomer.CustomerName = customerName; sysCustomer.CustomerTel = customerTel; sysCustomer.CustomerAddr = customerAddr; sysCustomer.Enabled = enabled; sysCustomer.FactoryId =CurrentEmp.FactoryId; sysCustomer.FactoryCode = CurrentEmp.FactoryCode; String message = ""; if (editType != null && editType.Trim().Equals("edit")) { try { sysCustomer.CustomerId = Convert.ToInt32(customerId); sysCustomer.UpdateUserId = CurrentEmp.EmpId; this.service.updateCustomer(sysCustomer); message = "修改成功"; } catch (Exception e) { message = "修改失败!"; } } else { try { if (this.service.getCustomerByExistName(customerCode)!=null) { message = "客户代码已存在,请检查!"; } else { sysCustomer.CreateUserId = CurrentEmp.EmpId; if (this.service.saveCustomer(sysCustomer)>0) { message = "添加成功"; } else { message = "添加失败"; } } } catch (Exception e) { message = "添加失败!"; } } Hashtable result = new Hashtable(); result.Add("message", message); return Json(result); } /// /// 查看详情 /// /// /// public ActionResult getCustomer(String customerId) { //List CustomerInfo = this.service.getCustomer(customerId); //Hashtable htCustomerInfo = (Hashtable)CustomerInfo[0]; //ViewData.Add("partId", CustomerInfo[0]["partId"]); //ViewData.Add("custOrder", htCustomerInfo["custOrder"]); //ViewData.Add("shipUnit", htCustomerInfo["shipUnit"]); return View("viewCustomer"); } /// /// 编辑 /// /// /// public ActionResult editCustomer(String customerId) { if (!string.IsNullOrEmpty(customerId)) { List CustomerInfo = this.service.getCustomer(customerId); ViewData.Add("editType", "edit"); ViewData.Add("customerId", customerId); ViewData.Add("customerCode", CustomerInfo[0].CustomerCode); ViewData.Add("customerName", CustomerInfo[0].CustomerName); ViewData.Add("customerTel", CustomerInfo[0].CustomerTel); ViewData.Add("customerAddr", CustomerInfo[0].CustomerAddr); ViewData.Add("enabled", CustomerInfo[0].Enabled); } else { ViewData.Add("editType", "new"); } return View("EditCustomer"); } /// /// 删除 /// /// /// public ActionResult deleteCustomer(String ids) { int delCount = 0; try { delCount = this.service.deleteCustomer(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 启用 /// /// /// public ActionResult onEnable(String ids) { int delCount = 0; try { delCount = this.service.EnableCustomer(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 禁用 /// /// /// public ActionResult onDisable(String ids) { int delCount = 0; try { delCount = this.service.DisableCustomer(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 导出数据到Excel /// BY NOAH /// public ActionResult exportData(String customerCode, String customerName, string enabled = "Y") { List listHt = this.service.getExportList(customerCode, customerName, enabled, CurrentEmp.FactoryId); var memoryStream = ExcelHelper.ToExcel(listHt); string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss"); return File(memoryStream.ToArray(), "application/ms-excel", "客户管理"+ dateTime + ".xls"); } } }