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.

681 lines
24 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 MovementInstockManageController : BaseController
{
private IMovementInstockManageService service;
public MovementInstockManageController(IMovementInstockManageService _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 getMoveHeaderListByPage(string orderNo, string orderType, string orderStatus, string startTime, string endTime, 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.getMoveHeaderListByPage(orderNo, orderType, orderStatus, startTime, endTime, 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 getMoveDetailListByPage(string orderNo, string enabled = "Y")
{
int factoryId = CurrentEmp.FactoryId;
Hashtable result = new Hashtable();
Hashtable dataHt = this.service.getMoveDetailListByPage(orderNo, enabled, factoryId);
result.Add("rows", dataHt["dataList"]);
result.Add("pager.totalRows", dataHt["totalCount"]);
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 getMoveSnListByPage(string orderNo, string partNo, string enabled = "Y")
{
int factoryId = CurrentEmp.FactoryId;
Hashtable result = new Hashtable();
Hashtable dataHt = this.service.getMoveSnListByPage(orderNo, partNo, enabled, factoryId);
result.Add("rows", dataHt["dataList"]);
result.Add("pager.totalRows", dataHt["totalCount"]);
return Json(result);
}
//打印查询
public ActionResult getInstockListByPrintCount(string orderNo, string enabled = "Y")
{
Hashtable result = new Hashtable();
int factoryId = CurrentEmp.FactoryId;
List<WmsInstock> listData = this.service.getInstockListByPrintCount(orderNo, enabled, factoryId);
result.Add("rows", listData);
result.Add("pager.totalRows", listData.Count);
return Json(result);
}
//打印查询
public ActionResult getInstockListByPrintRange(string orderNo,string rowRange, string enabled = "Y")
{
Hashtable result = new Hashtable();
string factoryId = CurrentEmp.FactoryId.ToString();
List<WmsInstockSn> listData = this.service.getInstockListByPrintRange(orderNo, rowRange,enabled, factoryId);
return Json(listData);
}
//处理分组打印
public ActionResult EditBlockPrint(String orderNo,string orderType)
{
ViewData.Add("orderNo", orderNo);
ViewData.Add("orderType", orderType);
return View("EditBlockPrint");
}
//打印查询
public ActionResult getMoveSnListByPrint(string orderNo, string groupCount, string enabled = "Y")
{
int factoryId = CurrentEmp.FactoryId;
List<WmsInstockSn> listData = this.service.getMoveSnListByPrint(orderNo, enabled, factoryId);
return Json(listData);
}
/// <summary>
/// 生成条码
/// </summary>
/// <param name="ruid"></param>
/// <returns></returns>
public ActionResult onBarcodeGenerator(String orderNos)
{
Hashtable result = new Hashtable();
try
{
string userId = CurrentEmp.EmpId.ToString();
string factoryId = CurrentEmp.FactoryId.ToString();
string factoryCode = CurrentEmp.FactoryCode;
result = this.service.onBarcodeGenerator(orderNos, userId, factoryId, factoryCode);
}
catch (Exception e)
{
result.Add("message", "生成条码失败,请重查看!");
result.Add("flag", "error");
}
return Json(result);
}
public ActionResult getSelectMoveOrderType()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.GetMoveOrderType();
result.Add("list", menuList);
return Json(result);
}
public ActionResult getSelectMoveOrderStatus()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.GetMoveOrderStatus();
result.Add("list", menuList);
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 getSelectZoneByZoneId(string zoneId)
{
Hashtable result = new Hashtable();
List<SysZone> Zones = service.getSelectZone(zoneId);
return Json(Zones);
}
public ActionResult getSelectVendor()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.getSelectVendor();
result.Add("list", menuList);
return Json(result);
}
#region 过滤供应商
public ActionResult GetfileVendor(string q)
{
List<string> list = fileVendor(q);
return writeResult(list);
}
/// <summary>
/// 过滤供应商
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public List<string> fileVendor(string key)
{
Hashtable autoComplateList = GetItemVendor(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 GetItemVendor(string key)
{
List<String> autoComplateList = new List<string>();
Hashtable result = new Hashtable();
try
{
List<SysVendor> dt = service.GetfileVendor(key, CurrentEmp.FactoryId);
for (int i = 0; i < dt.Count; i++)
{
result.Add(dt[i].VendorId.ToString(), dt[i].VendorName.ToString());
}
}
catch (Exception e)
{
result = new Hashtable();
}
return result;
}
#endregion
public ActionResult getSelectCustomer()
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.getSelectCustomer();
result.Add("list", menuList);
return Json(result);
}
public ActionResult getSelectLocateDown(string zoneId)
{
Hashtable result = new Hashtable();
List<KeyValueResult> menuList = this.service.getSelectLocateDown(zoneId);
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);
}
/// <summary>
/// 保存数据
/// </summary>
/// <returns></returns>
public ActionResult saveMovementInstockManage()
{
int orderType = int.Parse(Request.Form["orderType"]);
int factoryId = CurrentEmp.FactoryId;
String factoryCode = CurrentEmp.FactoryCode;
String enabled = Request.Form["enabled"].ToString();
string vendorName = Request.Form["vendorName"];
string customerId = Request.Form["customerId"];
String planDate = Request.Form["planDate"].ToString();
String planTime = Request.Form["planTime"].ToString();
String destWarehouseId = Request.Form["destWarehouseId"].ToString();
String destZoneId = Request.Form["destZoneId"].ToString();
String destLocateId = Request.Form["destLocateId"].ToString();
String destErpWarehouse = Request.Form["destErpWarehouse"].ToString();
String reforderno = Request.Form["reforderno"].ToString();
String destWarehouseName = "";
List<SysWarehouse> destWare = service.getSelectWarehouse(destWarehouseId);
if (destWare.Count > 0)
{
destWarehouseName = destWare[0].WarehouseName;
}
String destZoneName = "";
List<SysZone> destZones = service.getSelectZone(destZoneId);
if (destZones.Count > 0)
{
destZoneName = destZones[0].ZoneName;
}
else
{
destZoneName = "";
}
String destLocateName = "";
List<SysLocate> locates = service.getSelectLocate(destLocateId);
if (locates.Count > 0)
{
destLocateName = locates[0].LocateName;
}
else
{
destLocateName = "";
}
int VendorId = 0;
SysVendor sysVendors = service.GetVendorInfoByName(vendorName, CurrentEmp.FactoryId);
string vendorCode = "";
if (sysVendors != null)
{
VendorId = sysVendors.VendorId;
vendorCode = sysVendors.VendorCode;
}
customerId = string.IsNullOrEmpty(customerId) ? "0" : customerId;
List<SysCustomer> sysCustomers = service.getSelectCustomer(customerId.ToString());
string customerCode = "";
if (sysCustomers.Count > 0)
{
customerCode = sysCustomers[0].CustomerCode;
}
WmsInstock moveHeader = new WmsInstock();
moveHeader.OrderType = orderType;
moveHeader.VendorId = VendorId;
moveHeader.VendorCode = vendorCode;
moveHeader.CustomerId = Convert.ToInt32(customerId);
moveHeader.CustomerCode = customerCode;
moveHeader.FactoryId = factoryId;
moveHeader.FactoryCode = factoryCode;
moveHeader.Enabled = enabled;
moveHeader.RefOrderNo = reforderno;
string detailRow = Request.Form["detailRow"].ToString();
IList<WmsInstockDetail> moveDetailsList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<WmsInstockDetail>>(detailRow);
for (int i = 0; i < moveDetailsList.Count; i++)
{
moveDetailsList[i].ItemNo = (i + 1).ToString();
//purchaseDetailList[i].PartId = Convert.ToInt32(PartId);
string PartNo = string.IsNullOrEmpty(moveDetailsList[i].PartNo.ToString()) ? "0" : moveDetailsList[i].PartNo.ToString();
List<SysPart> parts = service.GetPart(PartNo);
if (parts.Count > 0)
{
moveDetailsList[i].PartId = parts[0].PartId;
moveDetailsList[i].PartSpec = parts[0].PartSpec;
moveDetailsList[i].Unit = parts[0].Unit;
}
else
{
moveDetailsList[i].PartId = 0;
moveDetailsList[i].PartSpec = "";
moveDetailsList[i].Unit = "";
}
//moveDetailsList[i].Qty = string.IsNullOrEmpty(Qty) ? 0 : Convert.ToDecimal(Qty);
moveDetailsList[i].RecQty = 0;
moveDetailsList[i].PlanDate = planDate;
moveDetailsList[i].PlanTime = planTime;
moveDetailsList[i].DestWarehouseId = string.IsNullOrEmpty(destWarehouseId) ? 0 : Convert.ToInt32(destWarehouseId);
moveDetailsList[i].DestWarehouseName = destWarehouseName;
moveDetailsList[i].DestZoneId = string.IsNullOrEmpty(destZoneId) ? 0 : Convert.ToInt32(destZoneId);
moveDetailsList[i].DestZoneName = destZoneName;
moveDetailsList[i].DestLocateId = string.IsNullOrEmpty(destLocateId) ? 0 : Convert.ToInt32(destLocateId);
moveDetailsList[i].DestLocateName = destLocateName;
moveDetailsList[i].DestErpWarehouse = destErpWarehouse;
moveDetailsList[i].Enabled = enabled;
moveDetailsList[i].FactoryId = CurrentEmp.FactoryId;
moveDetailsList[i].FactoryCode = CurrentEmp.FactoryCode;
moveDetailsList[i].CreateUserId = CurrentEmp.EmpId;
}
String message = "";
try
{
moveHeader.CreateUserId = CurrentEmp.EmpId;
bool flag = this.service.saveMovementManage(moveHeader, moveDetailsList);
if (flag == true)
{
message = "添加成功";
}
else
{
message = "添加失败!";
}
}
catch (Exception e)
{
message = "添加失败!";
}
Hashtable result = new Hashtable();
result.Add("message", message);
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.GetPartNoInfo(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
#region 过滤零件号简码
public ActionResult GetPart_Spec(string q)
{
List<string> list = filePartSpec(q);
return writeResult(list);
}
/// <summary>
/// 过滤零件号
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public List<string> filePartSpec(string key)
{
Hashtable autoComplateList = GetItemPartSpec(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 GetItemPartSpec(string key)
{
List<String> autoComplateList = new List<string>();
Hashtable result = new Hashtable();
try
{
List<SysPart> dt = service.GetPartSpecInfo(key);
for (int i = 0; i < dt.Count; i++)
{
result.Add(dt[i].PartId.ToString(), dt[i].PartSpec.ToString());
}
}
catch (Exception e)
{
result = new Hashtable();
}
return result;
}
#endregion
public ActionResult getPartNoInfo(string partNo)
{
Hashtable resault = new Hashtable();
List<SysPart> list = service.GetPartNoInfo(partNo);
return Json(list);
}
public ActionResult getPartNoInfoByPartNo(string partNo)
{
Hashtable resault = new Hashtable();
List<SysPart> list = service.GetPartNoInfoByPartNo(partNo);
return Json(list);
}
public ActionResult getPartSpecInfo(string partSpec)
{
Hashtable resault = new Hashtable();
List<SysPart> list = service.GetPartSpecInfo(partSpec);
return Json(list);
}
public ActionResult getPartSpecInfoByPartSpec(string partSpec)
{
Hashtable resault = new Hashtable();
List<SysPart> list = service.GetPartSpecInfoByPartSpec(partSpec);
return Json(list);
}
private ActionResult writeResult(List<string> list)
{
Hashtable result = new Hashtable();
result.Add("list", list);
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 EditMoveInstockManage(String warehouseId)
{
ViewData.Add("editType", "new");
List<KeyValueResult> menuList = this.service.getSelectWarehouse();
if (menuList.Count > 0)
{ //目标仓库绑定默认值
ViewData.Add("destWarehouseId", menuList[0].value);
}
return View("EditMoveInstockManage");
}
/// <summary>
/// 关闭
/// </summary>
/// <param name="ruid"></param>
/// <returns></returns>
public ActionResult onClose(String orderNos)
{
bool flag = true;
try
{
string empId = CurrentEmp.EmpId.ToString();
flag = this.service.onClose(orderNos, empId);
}
catch (Exception e)
{
flag = false;
}
Hashtable result = new Hashtable();
result.Add("status", flag);
return Json(result);
}
/// <summary>
/// 启用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public ActionResult onEnable(String orderNos)
{
bool flag = true;
try
{
flag = this.service.EnableData(orderNos);
}
catch (Exception e)
{
flag = false;
}
Hashtable result = new Hashtable();
result.Add("status", flag);
return Json(result);
}
/// <summary>
/// 禁用
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public ActionResult onDisable(String orderNos)
{
bool flag = true;
try
{
flag = this.service.DisableData(orderNos);
}
catch (Exception e)
{
flag = false;
}
Hashtable result = new Hashtable();
result.Add("status", flag);
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<MovementInstockManage> data = ExcelHelper.GetList<MovementInstockManage>(file, 0);
result = service.ImportExcel(data, factoryId, factoryCode, CurrentEmp.EmpId);
return Json(result);
}
public ActionResult uploadFile()
{
return View("uploadFile");
}
/// <summary>
/// 下载模板
/// </summary>
/// <returns></returns>
public ActionResult downLoadExcel()
{
List<MovementInstockManage> listHt = new List<MovementInstockManage>();//导出空数据模板
var memoryStream = ExcelHelper.ToExcel(listHt);
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
return File(memoryStream.ToArray(), "application/ms-excel", "入库单管理" + dateTime + ".xls");
}
}
}