|
|
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
|
|
|
* 描述:委外BOM
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Web.Controllers
|
|
|
{
|
|
|
public class OutsourceBomController : BaseController
|
|
|
{
|
|
|
private IOutsourceBomService service;
|
|
|
public OutsourceBomController(IOutsourceBomService _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 getBomListByPage(string partNo, string itemPartNo, 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.getBomListByPage(partNo, itemPartNo, 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 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);
|
|
|
}
|
|
|
|
|
|
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 saveOutsourceBom()
|
|
|
{
|
|
|
String message = ""; String flag = "";
|
|
|
String editType = Request.Form["editType"].ToString();
|
|
|
String ruid = Request.Form["ruid"].ToString();
|
|
|
String partNo = Request.Form["partNo"].ToString();
|
|
|
String itemPartNo = Request.Form["itemPartNo"].ToString();
|
|
|
String enabled = Request.Form["enabled"].ToString();
|
|
|
|
|
|
List<SysPart> partInfo = service.GetPartInfo(partNo);
|
|
|
if (partInfo.Count == 0)
|
|
|
{
|
|
|
Hashtable resultMsg = new Hashtable();
|
|
|
resultMsg.Add("flag", "false");
|
|
|
resultMsg.Add("message", "源零件号不存在,请重新输入");
|
|
|
return Json(resultMsg);
|
|
|
}
|
|
|
|
|
|
List<SysPart> itemPartNoInfo = service.GetPartInfo(itemPartNo);
|
|
|
if (itemPartNoInfo.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;
|
|
|
WmsOutsourceBom wmsOutsourceBom = new WmsOutsourceBom();
|
|
|
wmsOutsourceBom.PartNo = partNo;
|
|
|
wmsOutsourceBom.ItemPartNo = itemPartNo;
|
|
|
wmsOutsourceBom.Enabled = enabled;
|
|
|
wmsOutsourceBom.FactoryId = CurrentEmp.FactoryId;
|
|
|
wmsOutsourceBom.FactoryCode = CurrentEmp.FactoryCode;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
if (editType != null && editType.Trim().Equals("edit"))
|
|
|
{
|
|
|
wmsOutsourceBom.Ruid = Convert.ToInt32(ruid == null ? 0 : ruid);
|
|
|
wmsOutsourceBom.UpdateUserId = CurrentEmp.EmpId;
|
|
|
int num = this.service.updateOutsourceBom(wmsOutsourceBom);
|
|
|
if (num > 0)
|
|
|
{
|
|
|
flag = "true";
|
|
|
message = "修改成功";
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
flag = "false";
|
|
|
message = "修改失败!";
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
wmsOutsourceBom.CreateUserId = CurrentEmp.EmpId;
|
|
|
wmsOutsourceBom.Guid = Guid.NewGuid().ToString();
|
|
|
int num = this.service.saveOutsourceBom(wmsOutsourceBom);
|
|
|
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 editOutsourceBom(String ruid)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(ruid))
|
|
|
{
|
|
|
Hashtable ht = this.service.getOutsourceBomDetail(ruid);
|
|
|
ViewData.Add("editType", "edit");
|
|
|
|
|
|
ViewData.Add("partNo", ht["partNo"]);
|
|
|
ViewData.Add("itemPartNo", ht["itemPartNo"]);
|
|
|
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("EditOutsourceBom");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult deleteOutsourceBom(String ruid)
|
|
|
{
|
|
|
int delCount = 0;
|
|
|
try
|
|
|
{
|
|
|
delCount = this.service.deleteOutsourceBom(ruid);
|
|
|
}
|
|
|
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 ruid)
|
|
|
{
|
|
|
int delCount = 0;
|
|
|
try
|
|
|
{
|
|
|
delCount = this.service.EnableOutsourceBom(ruid);
|
|
|
}
|
|
|
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 ruid)
|
|
|
{
|
|
|
int delCount = 0;
|
|
|
try
|
|
|
{
|
|
|
delCount = this.service.DisableOutsourceBom(ruid);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
delCount = -1;
|
|
|
}
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("status", delCount);
|
|
|
return Json(result);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 导入
|
|
|
/// </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<ZonePart> data = ExcelHelper.GetList<ZonePart>(file, 0);
|
|
|
result = service.ImportExcel(data, factoryId, factoryCode, CurrentEmp.EmpId);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
public ActionResult uploadFile()
|
|
|
{
|
|
|
return View("uploadFile");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导出数据到Excel
|
|
|
/// BY NOAH
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult exportData( string partNo, string itemPartNo, string enabled = "Y")
|
|
|
{
|
|
|
List<WmsOutsourceBom> listHt = this.service.getExportList(partNo, itemPartNo, enabled, CurrentEmp.FactoryId);
|
|
|
var memoryStream = ExcelHelper.ToExcel(listHt);
|
|
|
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
return File(memoryStream.ToArray(), "application/ms-excel", "委外Bom" + dateTime + ".xls");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 下载模板
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult downLoadExcel()
|
|
|
{
|
|
|
List<WmsOutsourceBom> listHt = new List<WmsOutsourceBom>();//导出空数据模板
|
|
|
var memoryStream = ExcelHelper.ToExcel(listHt);
|
|
|
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
return File(memoryStream.ToArray(), "application/ms-excel", "委外Bom" + dateTime + ".xls");
|
|
|
}
|
|
|
}
|
|
|
}
|