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.

517 lines
18 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
{
public class LocatePartDefineController : BaseController
{
private ILocatePartDefineService service;
public LocatePartDefineController(ILocatePartDefineService _service)
{
service = _service;
}
//
// GET: /Menu/
public ActionResult Index()
{
return View();
}
/// <summary>
/// 获取库位零件管理列表数据
/// </summary>
/// <param name="menuName"></param>
/// <param name="pager"></param>
/// <param name="direction"></param>
/// <param name="sort"></param>
/// <returns></returns>
public ActionResult getLocateListByPage(string locateName, string locateDesc, string partNo, string partSpec,string partSpec2, Pager pager, String direction, String sort,string safetyPullOrder,string isSafetyPull, string enabled = "Y")
{
int factoryId = CurrentEmp.FactoryId;
Hashtable result = new Hashtable();
result.Add("pager.pageNo", pager.pageNo);
Hashtable dataHt = this.service.getLocateListByPage(locateName, locateDesc, partNo, partSpec, partSpec2, enabled, factoryId, pager, direction, safetyPullOrder, isSafetyPull, 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 GetLocateName(string q)
{
List<string> list = fileLocateName(q);
return writeResult(list);
}
/// <summary>
/// 过滤库位
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public List<string> fileLocateName(string key)
{
Hashtable autoComplateList = GetItemLocateName(key);
List<String> result = new List<string>();
foreach (System.Collections.DictionaryEntry item in autoComplateList)
{
if (item.Value.ToString().ToUpper().StartsWith(key.ToUpper()))
{
result.Add(item.Value.ToString());
}
}
return result;
}
/// <summary>
/// 查询库位
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public Hashtable GetItemLocateName(string key)
{
List<String> autoComplateList = new List<string>();
Hashtable result = new Hashtable();
try
{
List<SysLocate> dt = service.GetLocateInfo(key);
for (int i = 0; i < dt.Count; i++)
{
result.Add(dt[i].LocateId.ToString(), dt[i].LocateName.ToString());
}
}
catch (Exception e)
{
result = new Hashtable();
}
return result;
}
#endregion
#region 过滤零件号
public ActionResult GetPart_no(string q)
{
List<string> list = filePart(q);
return writeResult(list);
}
/// <summary>
/// 过滤零件号
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public List<string> filePart(string key)
{
Hashtable autoComplateList = GetItemPart(key);
List<String> result = new List<string>();
foreach (System.Collections.DictionaryEntry item in autoComplateList)
{
if (item.Value.ToString().ToUpper().StartsWith(key.ToUpper()))
{
result.Add(item.Value.ToString());
}
}
return result;
}
/// <summary>
/// 查询零件号
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public Hashtable GetItemPart(string key)
{
List<String> autoComplateList = new List<string>();
Hashtable result = new Hashtable();
try
{
List<SysPart> 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<string> list)
{
Hashtable result = new Hashtable();
result.Add("list", list);
return Json(result);
}
///// <summary>
///// 获取零件信息
///// </summary>
///// <returns></returns>
//public ActionResult getPart()
//{
// Hashtable result = new Hashtable();
// string partNo = Request.Form["partNo"].ToString();
// string message = "";
// List<SysPart> dt = service.GetPartInfo(0, partNo);
// if (dt.Count > 0)
// {
// partId = dt[0].PartId.ToString();
// biaoNumber = dt[0].DefaultBoxQty.ToString();
// partSpec = dt[0].PartSpec.ToString();
// if (!service.IsPoPartNo(txtBuyNo, partNo))
// {
// message = " [" + partNo + "]所选择零件与采购单数据不匹配! ";
// result.Add("message", message);
// result.Add("status", -1);
// return Json(result);
// }
// if (!service.IsExistLineLocate(partId))
// {
// message = " [" + partNo + "]:不存在此零件对应的线边库位配置信息! ";
// result.Add("message", message);
// result.Add("status", -1);
// return Json(result);
// }
// result.Add("partId", partId);
// result.Add("biaoNumber", biaoNumber);
// result.Add("partSpec", partSpec);
// result.Add("status", 1);
// }
// return Json(result);
//}
/// <summary>
/// 获取父节点菜单下拉列表数据
/// </summary>
/// <rehuoturns></returns>
public ActionResult getSelectWarehouse()
{
string factoryId = CurrentEmp.FactoryId.ToString();
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.getSelectWarehouse(factoryId);
result.Add("list", menuList);
return Json(result);
}
/// <summary>
/// 获取父节点菜单下拉列表数据
/// </summary>
/// <rehuoturns></returns>
public ActionResult getSelectZone(string WarehouseId)
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.getSelectZone(WarehouseId);
result.Add("list", menuList);
return Json(result);
}
/// <summary>
/// 获取库位类型列表
/// </summary>
/// <returns></returns>
public ActionResult GetLocateType()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.GetLocateType();
result.Add("list", menuList);
return Json(result);
}
public ActionResult GetpartInfo()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.GetpartInfo();
result.Add("list", menuList);
return Json(result);
}
/// <summary>
/// 保存菜单数据
/// </summary>
/// <returns></returns>
public ActionResult saveLocatePart()
{
String message = ""; String flag = "";
String editType = Request.Form["editType"].ToString();
String locateName = Request.Form["locateName"].ToString();
String partNo = Request.Form["partNo"].ToString();
String maxQty = Request.Form["maxQty"].ToString();
String minQty = Request.Form["minQty"].ToString();
String safetyQty = Request.Form["safetyQty"].ToString();
String wipMinQty = Request.Form["wipMinQty"].ToString();
String enabled = Request.Form["enabled"].ToString();
String guid = Request.Form["guid"].ToString();
List<SysLocate> locateInfo = service.getSelectLocateInfo(locateName);
if (locateInfo.Count == 0)
{
Hashtable resultMsg = new Hashtable();
resultMsg.Add("flag", "false");
resultMsg.Add("message", "库位代码不存在,请重新输入");
return Json(resultMsg);
}
int locateId = locateInfo[0].LocateId;
string locateDesc = locateInfo[0].LocateDesc;
List<SysPart> 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;
SysLocatePart sysLocatePart = new SysLocatePart();
sysLocatePart.LocateId = Convert.ToInt32(locateId);
sysLocatePart.LocateName = locateName;
sysLocatePart.LocateDesc = locateDesc;
sysLocatePart.PartId = partId;
sysLocatePart.PartNo = partNo;
sysLocatePart.MaxQty = string.IsNullOrEmpty(maxQty) ? 0 : Convert.ToDecimal(maxQty);
sysLocatePart.MinQty = string.IsNullOrEmpty(minQty) ? 0 : Convert.ToDecimal(minQty);
sysLocatePart.SafetyQty = string.IsNullOrEmpty(safetyQty) ? 0 : Convert.ToDecimal(safetyQty);
sysLocatePart.WipMinQty = string.IsNullOrEmpty(wipMinQty) ? 0 : Convert.ToDecimal(wipMinQty);
sysLocatePart.Enabled = enabled;
sysLocatePart.FactoryId = CurrentEmp.FactoryId;
sysLocatePart.FactoryCode = CurrentEmp.FactoryCode;
try
{
if (editType != null && editType.Trim().Equals("edit"))
{
sysLocatePart.Guid = guid;
sysLocatePart.UpdateUserId = CurrentEmp.EmpId;
int num = this.service.updateLocatePart(sysLocatePart);
if (num > 0)
{
flag = "true";
message = "修改成功";
}
else
{
flag = "false";
message = "修改失败!";
}
}
else
{
List<SysLocatePart> locatePartInfo = service.getSelectLocatePartInfo(locateName, partNo);
if (locatePartInfo.Count > 0)
{
Hashtable resultMsg = new Hashtable();
resultMsg.Add("flag", "false");
resultMsg.Add("message", "库位和零件号关系已维护");
return Json(resultMsg);
}
sysLocatePart.CreateUserId = CurrentEmp.EmpId;
int num = this.service.saveLocatePart(sysLocatePart);
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);
}
/// <summary>
/// 编辑菜单
/// </summary>
/// <param name="ruid"></param>
/// <returns></returns>
public ActionResult editLocatePart(String guid)
{
if (!string.IsNullOrEmpty(guid))
{
Hashtable ht = this.service.getLocateDetail(guid);
ViewData.Add("editType", "edit");
ViewData.Add("locateId", ht["locateId"]);
ViewData.Add("locateName", ht["locateName"]);
ViewData.Add("locateDesc", ht["locateDesc"]);
ViewData.Add("partId", ht["partId"]);
ViewData.Add("partNo", ht["partNo"]);
ViewData.Add("partSpec", ht["partSpec"]);
ViewData.Add("maxQty", ht["maxQty"]);
ViewData.Add("minQty", ht["minQty"]);
ViewData.Add("safetyQty", ht["safetyQty"]);
ViewData.Add("wipMinQty", ht["wipMinQty"]);
ViewData.Add("factoryId", ht["factoryId"]);
ViewData.Add("factoryCode", ht["factoryCode"]);
ViewData.Add("enabled", ht["enabled"]);
ViewData.Add("guid", ht["guid"]);
}
else
{
ViewData.Add("editType", "new");
}
return View("EditLocatePartDefine");
}
/// <summary>
/// 删除菜单
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public ActionResult deleteLocatePart(String ids)
{
int delCount = 0;
try
{
delCount = this.service.deleteLocatePart(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.EnableLocatePart(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.DisableLocatePart(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
/// 导入
/// </summary>
/// <returns></returns>
public ActionResult importFile()
{
int factoryId = CurrentEmp.FactoryId;
string factoryCode = CurrentEmp.FactoryCode;
Hashtable result = new Hashtable();
IFormFile file = Request.Form.Files[0];
List<LocatePart> data = ExcelHelper.GetList<LocatePart>(file, 0);
result = service.ImportExcel(data, factoryId, factoryCode, CurrentEmp.EmpId);
return Json(result);
}
public ActionResult uploadFile()
{
return View("uploadFile");
}
/// <summary>
/// 导出数据到Excel
/// BY NOAH
/// </summary>carImport
/// <returns></returns>
public ActionResult exportData(string locateName, string locateDesc, string partNo, string partSpec, string partSpec2, string enabled = "Y")
{
List<LocatePart> listHt = this.service.getExportList(locateName, locateDesc, partNo, partSpec, partSpec2, enabled, CurrentEmp.FactoryId);
var memoryStream = ExcelHelper.ToExcel(listHt);
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
return File(memoryStream.ToArray(), "application/ms-excel", "库位零件管理"+ dateTime + ".xls");
}
/// <summary>
/// 下载模板
/// </summary>
/// <returns></returns>
public ActionResult downLoadExcel(string rackPart, string partPackage, string enabled = "Y")
{
List<LocatePart> listHt = new List<LocatePart>();//导出空数据模板
var memoryStream = ExcelHelper.ToExcel(listHt);
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
return File(memoryStream.ToArray(), "application/ms-excel", "库位零件管理"+ dateTime + ".xls");
}
}
}