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 ZonePartController : BaseController
{
private IZonePartService service;
public ZonePartController(IZonePartService _service)
{
service = _service;
}
//
// GET: /Menu/
public ActionResult Index()
{
return View();
}
///
/// 获取库位零件管理列表数据
///
///
///
///
///
///
public ActionResult getZoneListByPage(String zoneName, String zoneDesc, string partNo, string partSpec, 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.getZoneListByPage(zoneName, zoneDesc, partNo, partSpec, enabled, 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);
}
#region 过滤供应商
public ActionResult GetVendorCode(string q)
{
List list = fileVendorCode(q);
return writeResult(list);
}
///
/// 过滤供应商
///
///
///
public List fileVendorCode(string key)
{
Hashtable autoComplateList = GetItemVendorName(key);
List result = new List();
foreach (System.Collections.DictionaryEntry item in autoComplateList)
{
if (item.Value.ToString().ToUpper().StartsWith(key.ToUpper()))
{
result.Add(item.Value.ToString());
}
}
return result;
}
///
/// 查询供应商
///
///
///
public Hashtable GetItemVendorName(string key)
{
List autoComplateList = new List();
Hashtable result = new Hashtable();
try
{
List dt = service.GetVendorInfo(key);
for (int i = 0; i < dt.Count; i++)
{
result.Add(dt[i].VendorId.ToString(), dt[i].VendorCode.ToString());
}
}
catch (Exception e)
{
result = new Hashtable();
}
return result;
}
#endregion
#region 过滤库区
public ActionResult GetZoneName(string q)
{
List list = fileZoneName(q);
return writeResult(list);
}
///
/// 过滤库区
///
///
///
public List fileZoneName(string key)
{
Hashtable autoComplateList = GetItemZoneName(key);
List result = new List();
foreach (System.Collections.DictionaryEntry item in autoComplateList)
{
if (item.Value.ToString().ToUpper().StartsWith(key.ToUpper()))
{
result.Add(item.Value.ToString());
}
}
return result;
}
///
/// 查询库区
///
///
///
public Hashtable GetItemZoneName(string key)
{
List autoComplateList = new List();
Hashtable result = new Hashtable();
try
{
List dt = service.GetZoneInfo(key);
for (int i = 0; i < dt.Count; i++)
{
result.Add(dt[i].ZoneId.ToString(), dt[i].ZoneName.ToString());
}
}
catch (Exception e)
{
result = new Hashtable();
}
return result;
}
#endregion
#region 过滤零件号
public ActionResult GetPart_no(string q)
{
List list = filePart(q);
return writeResult(list);
}
///
/// 过滤零件号
///
///
///
public List filePart(string key)
{
Hashtable autoComplateList = GetItemPart(key);
List result = new List();
foreach (System.Collections.DictionaryEntry item in autoComplateList)
{
if (item.Value.ToString().ToUpper().StartsWith(key.ToUpper()))
{
result.Add(item.Value.ToString());
}
}
return result;
}
///
/// 查询零件号
///
///
///
public Hashtable GetItemPart(string key)
{
List autoComplateList = new List();
Hashtable result = new Hashtable();
try
{
List dt = service.GetPartInfo(key);
for (int i = 0; i < dt.Count; i++)
{
result.Add(dt[i].PartId.ToString(), dt[i].PartNo.ToString());
}
}
catch (Exception e)
{
result = new Hashtable();
}
return result;
}
#endregion
private ActionResult writeResult(List list)
{
Hashtable result = new Hashtable();
result.Add("list", list);
return Json(result);
}
///
/// 获取父节点菜单下拉列表数据
///
///
public ActionResult getSelectZone(string WarehouseId)
{
Hashtable result = new Hashtable();
List menuList = this.service.getSelectZone(WarehouseId);
result.Add("list", menuList);
return Json(result);
}
public ActionResult GetpartInfo()
{
Hashtable result = new Hashtable();
List menuList = this.service.GetpartInfo();
result.Add("list", menuList);
return Json(result);
}
///
/// 保存菜单数据
///
///
public ActionResult saveZonePart()
{
String message = ""; String flag = "";
String editType = Request.Form["editType"].ToString();
String ruid = Request.Form["ruid"].ToString();
String zoneName = Request.Form["zoneName"].ToString();
String vendorCode = Request.Form["vendorCode"].ToString();
String partNo = Request.Form["partNo"].ToString();
int priority = string.IsNullOrEmpty(Request.Form["priority"]) ? 0 : Convert.ToInt32(Request.Form["priority"].ToString());
String enabled = Request.Form["enabled"].ToString();
List sysZones = service.getSelectZoneInfo(zoneName);
if (sysZones.Count == 0)
{
Hashtable resultMsg = new Hashtable();
resultMsg.Add("flag", "false");
resultMsg.Add("message", "库位代码不存在,请重新输入");
return Json(resultMsg);
}
int zoneId = sysZones[0].ZoneId;
List sysVendors = service.getSelectVendorInfo(vendorCode);
int vendorId = 0;
if (sysVendors.Count > 0)
{
vendorId = sysVendors[0].VendorId;
}
List partInfo = service.GetPartInfo(partNo);
if (partInfo.Count == 0)
{
Hashtable resultMsg = new Hashtable();
resultMsg.Add("flag", "false");
resultMsg.Add("message", "零件号不存在,请重新输入");
return Json(resultMsg);
}
int partId = partInfo[0].PartId;
string partSpec = partInfo[0].PartSpec;
SysZonePart sysZonePart = new SysZonePart();
sysZonePart.ZoneId = zoneId;
sysZonePart.ZoneName = zoneName;
sysZonePart.VendorId = vendorId;
sysZonePart.VendorCode = vendorCode;
sysZonePart.PartId = partId;
sysZonePart.PartNo = partNo;
sysZonePart.PartSpec = partSpec;
sysZonePart.Priority = priority;
sysZonePart.Enabled = enabled;
sysZonePart.FactoryId = CurrentEmp.FactoryId;
sysZonePart.FactoryCode = CurrentEmp.FactoryCode;
try
{
if (editType != null && editType.Trim().Equals("edit"))
{
sysZonePart.Ruid = Convert.ToInt32(ruid == null ? 0 : ruid);
sysZonePart.UpdateUserId = CurrentEmp.EmpId;
int num = this.service.updateZonePart(sysZonePart);
if (num > 0)
{
flag = "true";
message = "修改成功";
}
else
{
flag = "false";
message = "修改失败!";
}
}
else
{
List sysZoneParts = service.getSelectZonePartInfo(zoneName, partNo);
if (sysZoneParts.Count > 0)
{
Hashtable resultMsg = new Hashtable();
resultMsg.Add("flag", "false");
resultMsg.Add("message", "库位和零件号关系已维护");
return Json(resultMsg);
}
sysZonePart.CreateUserId = CurrentEmp.EmpId;
sysZonePart.Guid = Guid.NewGuid().ToString();
int num = this.service.saveZonePart(sysZonePart);
if (num > 0)
{
flag = "true";
message = "添加成功";
}
else
{
flag = "false";
message = "添加失败!";
}
}
}
catch (Exception e)
{
flag = "false";
message = "添加失败!" + e.Message;
}
Hashtable result = new Hashtable();
result.Add("flag", flag);
result.Add("message", message);
return Json(result);
}
///
/// 编辑菜单
///
///
///
public ActionResult editZonePart(String ruid)
{
if (!string.IsNullOrEmpty(ruid))
{
Hashtable ht = this.service.getZoneDetail(ruid);
ViewData.Add("editType", "edit");
ViewData.Add("zoneId", ht["zoneId"]);
ViewData.Add("zoneName", ht["zoneName"]);
ViewData.Add("partId", ht["partId"]);
ViewData.Add("partNo", ht["partNo"]);
ViewData.Add("partSpec", ht["partSpec"]);
ViewData.Add("priority", ht["priority"]);
ViewData.Add("factoryId", ht["factoryId"]);
ViewData.Add("factoryCode", ht["factoryCode"]);
ViewData.Add("enabled", ht["enabled"]);
ViewData.Add("ruid", ht["ruid"]);
}
else
{
ViewData.Add("editType", "new");
}
return View("EditZonePart");
}
///
/// 删除菜单
///
///
///
public ActionResult deleteZonePart(String ruid)
{
int delCount = 0;
try
{
delCount = this.service.deleteZonePart(ruid);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 启用
///
///
///
public ActionResult onEnable(String ruid)
{
int delCount = 0;
try
{
delCount = this.service.EnableLocatePart(ruid);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 禁用
///
///
///
public ActionResult onDisable(String ruid)
{
int delCount = 0;
try
{
delCount = this.service.DisableLocatePart(ruid);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 导入
///
///
public ActionResult importFile()
{
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 zoneName, String zoneDesc, string partNo, string partSpec, string enabled = "Y")
{
List listHt = this.service.getExportList(zoneName, zoneDesc, partNo, partSpec, enabled, CurrentEmp.FactoryId);
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");
}
}
}