using System.Collections;
using Microsoft.AspNetCore.Mvc;
using Estsh.Core.Services.IServices;
using Estsh.Core.Models;
using Estsh.Core.Util;
using Estsh.Core.Controllers;
using Estsh.Core.Model.Result;
using Estsh.Core.Model.ExcelModel;
namespace Estsh.Core.Web.Controllers
{
///
/// 支给件客户
///
public class SupportingCustomerController : BaseController
{
private ISupportingCustomerService service;
public SupportingCustomerController(ISupportingCustomerService _service)
{
service = _service;
}
//
// GET: /Menu/
public ActionResult Index()
{
return View();
}
///
/// 获取支给件客户信息
///
///
///
///
///
///
public ActionResult GetListByPage(String customerNo, String hzCustomerNo, String partSpec, Pager pager, String direction, String sort, String enabled = "Y")
{
Hashtable result = new Hashtable();
result.Add("pager.pageNo", pager.pageNo);
Hashtable dataHt = this.service.GetListByPage(customerNo, hzCustomerNo, partSpec, pager, direction, sort, enabled);
result.Add("rows", dataHt["dataList"]);
result.Add("pager.totalRows", dataHt["totalCount"]);
result.Add("sort", sort);
result.Add("direction", direction);
return Json(result);
}
///
/// 获取父节点支给件维护下拉列表数据
///
///
public ActionResult GetSelect()
{
Hashtable result = new Hashtable();
List list = this.service.GetSelect();
result.Add("list", list);
return Json(result);
}
///
/// 保存支给件客户数据
///
///
public ActionResult Save()
{
String editType = Request.Form["editType"].ToString();
String ruid = Request.Form["ruid"].ToString();
String customerNo = Request.Form["customerNo"].ToString();
String partSpec = Request.Form["partSpec"].ToString();
String hzCustomerNo = Request.Form["hzCustomerNo"].ToString();
String partSpec2 = Request.Form["partSpec2"].ToString();
WmsCustomerToSupplier sysExemptionList = new WmsCustomerToSupplier();
Hashtable result = new Hashtable();
String message = "";
if (editType != null && editType.Trim().Equals("edit"))
{
try
{
List ht1 = this.service.ifExemptionList(customerNo, hzCustomerNo);
if (ht1.Count != 0)
{
message = "该客户编号已存在于支给件客户中!";
}
else
{
sysExemptionList.ruid = Convert.ToInt32(ruid);
sysExemptionList.CustomerNo = customerNo;
sysExemptionList.HzCustomerId = 0;
sysExemptionList.HzCustomerNo = hzCustomerNo;
sysExemptionList.PartSpec = partSpec;
sysExemptionList.PartSpec2 = partSpec2;
sysExemptionList.FactoryId = CurrentEmp.FactoryId;
sysExemptionList.FactoryCode = CurrentEmp.FactoryCode;
sysExemptionList.UpdateUserId = CurrentEmp.EmpId;
this.service.Update(sysExemptionList);
message = "修改成功";
}
}
catch (Exception e)
{
message = "修改失败!";
}
}
else
{
try
{
List ht1 = this.service.ifExemptionList(customerNo, hzCustomerNo);
if (ht1.Count != 0)
{
message = "该零件号已存在于支给件维护中!";
}
else
{
sysExemptionList.CustomerNo = customerNo;
sysExemptionList.HzCustomerId =0;
sysExemptionList.HzCustomerNo = hzCustomerNo;
sysExemptionList.PartSpec = partSpec;
sysExemptionList.PartSpec2 = partSpec2;
sysExemptionList.FactoryId = CurrentEmp.FactoryId;
sysExemptionList.FactoryCode = CurrentEmp.FactoryCode;
this.service.Insert(sysExemptionList);
message = "添加成功";
}
}
catch (Exception e)
{
message = "添加失败!";
}
}
result.Add("message", message);
return Json(result);
}
///
/// 导入支给件维护
///
///
public ActionResult partImport()
{
int factoryId = CurrentEmp.FactoryId;
string factoryCode = CurrentEmp.FactoryCode;
Hashtable result = new Hashtable();
IFormFile file = Request.Form.Files[0];
List data = ExcelHelper.GetList(file, 0);
result = service.ImportExcel(data, factoryId, factoryCode, CurrentEmp.EmpId);
return Json(result);
}
public ActionResult uploadFile()
{
return View("uploadFile");
}
///
/// 导出数据到Excel
/// BY NOAH
///
///
public ActionResult exportData(String partNo, string enabled = "Y")
{
List listHt = this.service.getExportList(partNo, enabled);
var memoryStream = ExcelHelper.ToExcel(listHt);
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
return File(memoryStream.ToArray(), "application/ms-excel", "支给件维护" + dateTime + ".xls");
}
///
/// 下载模板
///
///
public ActionResult downLoadExcel()
{
List listHt = new List();//导出空数据模板
var memoryStream = ExcelHelper.ToExcel(listHt);
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
return File(memoryStream.ToArray(), "application/ms-excel", "支给件客户" + dateTime + ".xls");
}
///
/// 编辑支给件维护
///
///
///
public ActionResult Edit(String ruid)
{
if (!string.IsNullOrEmpty(ruid))
{
List Info = this.service.ifExemptionList(ruid);
ViewData.Add("editType", "edit");
ViewData.Add("ruid", Info[0].ruid);
ViewData.Add("CustomerNo", Info[0].CustomerNo);
ViewData.Add("partSpec", Info[0].PartSpec);
ViewData.Add("hz_customer_id", Info[0].HzCustomerId);
ViewData.Add("HzCustomerNo", Info[0].HzCustomerNo);
ViewData.Add("partSpec2", Info[0].PartSpec2);
}
else
{
ViewData.Add("editType", "new");
}
return View("editSupportingCustomer");
}
///
/// 启用
///
///
///
public ActionResult onEnable(String ids)
{
int delCount = 0;
try
{
delCount = this.service.EnableData(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.DisableData(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
}
}