You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
8.8 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
{
/// <summary>
/// 客户订单维护
/// </summary>
public class CustomerController : BaseController
{
private ICustomerService service;
public CustomerController(ICustomerService _service)
{
service = _service;
}
//
// GET: /Customer/
public ActionResult Index()
{
return View();
}
/// <summary>
/// 获取客户管理列表数据
/// </summary>
/// <param name="CustomerName">菜单名称</param>
/// <param name="pager">分页</param>
/// <param name="direction">排序方式</param>
/// <param name="sort">排序列</param>
/// <returns></returns>
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);
}
/// <summary>
/// 获取下拉列表数据
/// </summary>
/// <rehuoturns></returns>
public ActionResult getSelectCustomer()
{
Hashtable result = new Hashtable();
List<KeyValueResult> CustomerList = this.service.getSelectCustomer();
result.Add("list", CustomerList);
return Json(result);
}
/// <summary>
/// 保存数据
/// </summary>
/// <returns></returns>
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);
}
/// <summary>
/// 查看详情
/// </summary>
/// <param name="ruid"></param>
/// <returns></returns>
public ActionResult getCustomer(String customerId)
{
//List<SysCustomer> 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");
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="ruid"></param>
/// <returns></returns>
public ActionResult editCustomer(String customerId)
{
if (!string.IsNullOrEmpty(customerId))
{
List<SysCustomer> 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");
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
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);
}
/// <summary>
/// 启用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
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);
}
/// <summary>
/// 禁用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
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);
}
/// <summary>
/// 导出数据到Excel
/// BY NOAH
/// <returns></returns>
public ActionResult exportData(String customerCode, String customerName, string enabled = "Y")
{
List<Customer> 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");
}
}
}