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.

498 lines
17 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.EnumUtil;
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 PullGroupController : BaseController
{
private IPullGroupService service;
public PullGroupController(IPullGroupService _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 getPullGroupListByPage(string groupCode, string groupName, 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.getPullGroupListByPage(groupCode, groupName, 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);
}
/// <summary>
/// 获取采购单管理明细列表数据
/// </summary>
/// <param name="menuName"></param>
/// <param name="pager"></param>
/// <param name="direction"></param>
/// <param name="sort"></param>
/// <returns></returns>
public ActionResult getPullGroupDetailListByPage(string groupCode, string enabled = "Y")
{
int factoryId = CurrentEmp.FactoryId;
Hashtable result = new Hashtable();
Hashtable dataHt = this.service.getPullGroupDetailListByPage(groupCode, enabled, factoryId);
result.Add("rows", dataHt["dataList"]);
result.Add("pager.totalRows", dataHt["totalCount"]);
return Json(result);
}
/// <summary>
/// 获取父节点菜单下拉列表数据
/// </summary>
/// <rehuoturns></returns>
public ActionResult getSelectFactory()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.getSelectFactory();
result.Add("list", menuList);
return Json(result);
}
public ActionResult getSelectWarehouse()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.getSelectWarehouse();
result.Add("list", menuList);
return Json(result);
}
public ActionResult getSelectZone()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.getSelectZone();
result.Add("list", menuList);
return Json(result);
}
public ActionResult getSelectVendor()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.getSelectVendor();
result.Add("list", menuList);
return Json(result);
}
public ActionResult GetPart()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.GetPart();
result.Add("list", menuList);
return Json(result);
}
//public ActionResult GetPdlineByPdlineCode(string pdlineCode)
//{
// Hashtable result = new Hashtable();
// List<KeyValueResult> menuList = this.service.getSelectZone();
// result.Add("list", menuList);
// return Json(result);
//}
public ActionResult GetPdlineByKey()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.GetPdlineByKey();
result.Add("list", menuList);
return Json(result);
}
public ActionResult getPartNoInfo(string partNo)
{
Hashtable resault = new Hashtable();
List<SysPart> list = service.GetPartNoInfo(partNo);
return Json(list);
}
public ActionResult getPartSpecInfo(string partSpec)
{
Hashtable resault = new Hashtable();
List<SysPart> list = service.GetPartSpecInfo(partSpec);
return Json(list);
}
public ActionResult EditHandPullGroup(string groupCode)
{
ViewData.Add("editType", "edit");
ViewData.Add("groupCode", groupCode);
return View("EditHandPullGroup");
}
public ActionResult saveHandPullGroup()
{
String groupCode = Request.Form["groupCode"].ToString();
String handPullQty = Request.Form["handPullQty"].ToString();
String message = "";
String status = "0";
try
{
bool ret = this.service.saveHandPullGroup(groupCode, handPullQty);
if (ret)
{
status = "1";
message = "手工拉动成功";
}
else
{
status = "0";
message = "手工拉动失败!";
}
}
catch (Exception e)
{
status = "0";
message = "手工拉动失败!";
}
Hashtable result = new Hashtable();
result.Add("status", status);
result.Add("message", message);
return Json(result);
}
/// <summary>
/// 保存菜单数据
/// </summary>
/// <returns></returns>
public ActionResult savePullGroup()
{
string ruid = Request.Form["ruid"].ToString();
String groupCode = Request.Form["groupCode"].ToString();
String groupName = Request.Form["groupName"].ToString();
String triggerValue = Request.Form["triggerValue"].ToString();
String pullValue = Request.Form["pullValue"].ToString();
int pullingType = Convert.ToInt32(String.IsNullOrEmpty(Request.Form["pullingType"]) ? 0 : Request.Form["pullingType"].ToString());
string pdlineCode = String.IsNullOrEmpty(Request.Form["pdlineCode"]) ? "" : Request.Form["pdlineCode"].ToString();
SysPdline sysPdlines = service.GetPdlineByPdlineCode(pdlineCode);
string pdlineName = "";
if (sysPdlines != null)
{
pdlineName = sysPdlines.PdlineName;
}
decimal kittingQty = Convert.ToDecimal(Request.Form["kittingQty"].ToString());
int isAutoPrint = Convert.ToInt32(Request.Form["isAutoPrint"].ToString());
WmsPullingGroup wmsPulling = new WmsPullingGroup();
wmsPulling.GroupCode = groupCode;
wmsPulling.GroupName = groupName;
wmsPulling.TriggerValue = triggerValue;
wmsPulling.PullValue = pullValue;
wmsPulling.PullingType = pullingType;
wmsPulling.PdlineName = pdlineName;
wmsPulling.PdlineCode = pdlineCode;
wmsPulling.KittingQty = kittingQty;
wmsPulling.IsAutoPrint = isAutoPrint;
wmsPulling.Enabled = "Y";
wmsPulling.FactoryId = CurrentEmp.FactoryId;
wmsPulling.FactoryCode = CurrentEmp.FactoryCode;
wmsPulling.CreateUserId = CurrentEmp.EmpId;
string detailRow = Request.Form["detailRow"].ToString();
IList<WmsPullingGroupPart> wmsPullingDetailList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<WmsPullingGroupPart>>(detailRow);
for (int i = 0; i < wmsPullingDetailList.Count; i++)
{
//wmsPullingDetailList[i].PartId = Convert.ToInt32(PartId);
string PartNo = string.IsNullOrEmpty(wmsPullingDetailList[i].PartNo.ToString()) ? "0" : wmsPullingDetailList[i].PartNo.ToString();
List<SysPart> parts = service.GetPart(PartNo);
if (parts.Count > 0)
{
wmsPullingDetailList[i].PartId = parts[0].PartId;
wmsPullingDetailList[i].PartSpec = parts[0].PartSpec;
}
else
{
wmsPullingDetailList[i].PartId = 0;
wmsPullingDetailList[i].PartSpec = "";
}
wmsPullingDetailList[i].Enabled = "Y";
wmsPullingDetailList[i].FactoryId = CurrentEmp.FactoryId;
wmsPullingDetailList[i].FactoryCode = CurrentEmp.FactoryCode;
wmsPullingDetailList[i].CreateUserId = CurrentEmp.EmpId;
}
String message = "";
String status = "0";
try
{
if (string.IsNullOrEmpty(ruid))
{
List<WmsPullingGroupPart> wmsPullings = service.getPullGroupDetailList(groupCode);
if (wmsPullings.Count > 0)
{
status = "0";
message = "拉动组代码已存在,请检查";
}
else
{
wmsPulling.CreateUserId = CurrentEmp.EmpId;
int ret = this.service.savePullGroup(wmsPulling, wmsPullingDetailList);
if (ret > 0)
{
status = "1";
message = "添加成功";
}
else
{
status = "0";
message = "添加失败!";
}
}
}
else
{
wmsPulling.UpdateUserId = CurrentEmp.EmpId;
int ret = this.service.updatePullGroup(wmsPulling, wmsPullingDetailList);
if (ret > 0)
{
status = "1";
message = "修改成功";
}
else
{
status = "0";
message = "修改失败!";
}
}
}
catch (Exception e)
{
status = "0";
message = "操作失败!";
}
Hashtable result = new Hashtable();
result.Add("status", status);
result.Add("message", message);
return Json(result);
}
public ActionResult GetErpwarehouse()
{
Hashtable resault = new Hashtable();
List<KeyValueResult> pdlineList = service.GetErpwarehouse();
resault.Add("list", pdlineList);
return Json(resault);
}
/// <summary>
/// 编辑菜单
/// </summary>
/// <param name="ruid"></param>
/// <returns></returns>
public ActionResult EditPullGroup(String ruid)
{
if (!string.IsNullOrEmpty(ruid))
{
Hashtable ht = this.service.getPullGroup(ruid);
ViewData.Add("editType", "edit");
ViewData.Add("ruid", ht["ruid"]);
ViewData.Add("groupCode", ht["groupCode"]);
ViewData.Add("groupName", ht["groupName"]);
ViewData.Add("pullingType", ht["pullingType"]);
ViewData.Add("pdlineId", ht["pdlineId"]);
ViewData.Add("pdlineCode", ht["pdlineCode"]);
ViewData.Add("kittingQty", ht["kittingQty"]);
ViewData.Add("isAutoPrint", ht["isAutoPrint"]);
ViewData.Add("printCopies", ht["printCopies"]);
ViewData.Add("triggerValue", ht["triggerValue"]);
ViewData.Add("pullValue", ht["pullValue"]);
}
else
{
ViewData.Add("editType", "new");
}
return View("EditPullGroup");
}
#region 过滤零件号
private ActionResult writeResult(List<string> list)
{
Hashtable result = new Hashtable();
result.Add("list", list);
return Json(result);
}
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
/// <summary>
/// 启用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public ActionResult onEnable(String groupCode)
{
int delCount = 0;
try
{
delCount = this.service.EnableData(groupCode);
}
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 groupCode)
{
int delCount = 0;
try
{
delCount = this.service.DisableData(groupCode);
}
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<PullGroup> data = ExcelHelper.GetList<PullGroup>(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 groupCode, string groupName, string enabled = "Y")
{
List<PullGroup> listHt = this.service.getExportList(groupCode, groupName, 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<PullGroup> listHt = new List<PullGroup>();//导出空数据模板
var memoryStream = ExcelHelper.ToExcel(listHt);
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
return File(memoryStream.ToArray(), "application/ms-excel", "拉动组管理" + dateTime + ".xls");
}
}
}