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 VendorController : BaseController
{
private IVendorService service;
public VendorController(IVendorService _service)
{
service = _service;
}
//
// GET: /Vendor/
public ActionResult Index()
{
return View();
}
///
/// 获取列表数据
///
/// 菜单名称
/// 分页
/// 排序方式
/// 排序列
///
public ActionResult getVendorListByPage(String vendorCode, String vendorName, 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.getVendorListByPage(enabled, vendorCode, vendorName, 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 getSelectVendor()
{
Hashtable result = new Hashtable();
List VendorList = this.service.getSelectVendor();
result.Add("list", VendorList);
return Json(result);
}
///
/// 保存数据
///
///
public ActionResult saveVendor()
{
String editType = Request.Form["editType"].ToString();
String vendorCode = Request.Form["vendorCode"].ToString();
String vendorFax = Request.Form["vendorFax"].ToString();
String vendorName = Request.Form["vendorName"].ToString();
String vendorMtel = Request.Form["vendorMtel"].ToString();
String vendorTel = Request.Form["vendorTel"].ToString();
String vendorMail = Request.Form["vendorMail"].ToString();
String vendorSale = Request.Form["vendorSale"].ToString();
String vendorPwd = Request.Form["vendorPwd"].ToString();
String vendorAddr = Request.Form["vendorAddr"].ToString();
String vendorId = Request.Form["vendorId"].ToString();
String dock = Request.Form["dock"].ToString();
SysVendor sysVendor = new SysVendor();
sysVendor.VendorCode = vendorCode;
sysVendor.VendorFax = vendorFax;
sysVendor.VendorName = vendorName;
sysVendor.VendorMtel = vendorMtel;
sysVendor.VendorTel = vendorTel;
sysVendor.VendorMail = vendorMail;
sysVendor.VendorSale = vendorSale;
sysVendor.VendorPwd = vendorPwd;
sysVendor.VendorAddr = vendorAddr;
sysVendor.Dock = dock;
sysVendor.FactoryId = CurrentEmp.FactoryId;
sysVendor.FactoryCode = CurrentEmp.FactoryCode;
String message = "";
if (editType != null && editType.Trim().Equals("edit"))
{
try
{
sysVendor.VendorId = Convert.ToInt32(vendorId);
sysVendor.UpdateUserId = CurrentEmp.EmpId;
this.service.updateVendor(sysVendor);
message = "修改成功";
}
catch (Exception e)
{
message = "修改失败!";
}
}
else
{
try
{
if (this.service.getVendorByExistName(vendorCode) != null)
{
message = "供应商代码已存在,请检查!";
}
else
{
sysVendor.CreateUserId = CurrentEmp.EmpId;
if (this.service.saveVendor(sysVendor) > 0)
{
message = "添加成功";
}
else
{
message = "添加失败";
}
}
}
catch (Exception e)
{
message = "添加失败!";
}
}
Hashtable result = new Hashtable();
result.Add("message", message);
return Json(result);
}
///
/// 编辑
///
///
///
public ActionResult editVendor(String vendorId)
{
if (!string.IsNullOrEmpty(vendorId))
{
List VendorInfo = this.service.getVendor(vendorId);
ViewData.Add("editType", "edit");
ViewData.Add("vendorId", vendorId);
ViewData.Add("vendorCode", VendorInfo[0].VendorCode);
ViewData.Add("vendorName", VendorInfo[0].VendorName);
ViewData.Add("vendorTel", VendorInfo[0].VendorTel);
ViewData.Add("vendorAddr", VendorInfo[0].VendorAddr);
ViewData.Add("vendorFax", VendorInfo[0].VendorFax);
ViewData.Add("vendorMtel", VendorInfo[0].VendorMtel);
ViewData.Add("vendorMail", VendorInfo[0].VendorMail);
ViewData.Add("vendorSale", VendorInfo[0].VendorSale);
ViewData.Add("vendorPwd", VendorInfo[0].VendorPwd);
ViewData.Add("dock", VendorInfo[0].Dock);
}
else
{
ViewData.Add("editType", "new");
}
return View("EditVendor");
}
///
/// 删除
///
///
///
public ActionResult deleteVendor(String ids)
{
int delCount = 0;
try
{
delCount = this.service.deleteVendor(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.EnableVendor(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.DisableVendor(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 导入dock
///
///
public ActionResult dockImport()
{
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 vendorCode, String vendorName, string enabled = "Y")
{
List listHt = this.service.getExportList(vendorCode, vendorName, enabled, CurrentEmp.FactoryId);
var memoryStream = ExcelHelper.ToExcel(listHt);
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
return File(memoryStream.ToArray(), "application/ms-excel", "供应商管理" + dateTime + ".xls");
}
/// k
/// 下载模板
///
///
public ActionResult downLoadExcel(string rackPart, string partPackage, string enabled = "Y")
{
List listHt = new List();//导出空数据模板
var memoryStream = ExcelHelper.ToExcel(listHt);
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
return File(memoryStream.ToArray(), "application/ms-excel", "供应商道口" + dateTime + ".xls");
}
}
}