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;
namespace Estsh.Core.Web.Controllers
{
public class PullGroupMESController : BaseController
{
private IPullGroupMESService service;
public PullGroupMESController(IPullGroupMESService _service)
{
service = _service;
}
//
// GET: /Menu/
public ActionResult Index()
{
return View();
}
///
/// 获取采购单管理列表数据
///
///
///
///
///
///
public ActionResult getPullGroupListByPage(string pdlineCode, 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(pdlineCode, 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);
}
///
/// 获取采购单管理明细列表数据
///
///
///
///
///
///
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);
}
///
/// 获取父节点菜单下拉列表数据
///
///
public ActionResult getSelectFactory()
{
Hashtable result = new Hashtable();
List menuList = this.service.getSelectFactory();
result.Add("list", menuList);
return Json(result);
}
public ActionResult getSelectWarehouse()
{
Hashtable result = new Hashtable();
List menuList = this.service.getSelectWarehouse();
result.Add("list", menuList);
return Json(result);
}
public ActionResult getSelectZone()
{
Hashtable result = new Hashtable();
List menuList = this.service.getSelectZone();
result.Add("list", menuList);
return Json(result);
}
public ActionResult getSelectVendor()
{
Hashtable result = new Hashtable();
List menuList = this.service.getSelectVendor();
result.Add("list", menuList);
return Json(result);
}
public ActionResult GetPart()
{
Hashtable result = new Hashtable();
List menuList = this.service.GetPart();
result.Add("list", menuList);
return Json(result);
}
//public ActionResult GetPdlineByPdlineCode(string pdlineCode)
//{
// Hashtable result = new Hashtable();
// List menuList = this.service.getSelectZone();
// result.Add("list", menuList);
// return Json(result);
//}
public ActionResult GetPdlineByKey()
{
Hashtable result = new Hashtable();
List menuList = this.service.GetPdlineByKey();
result.Add("list", menuList);
return Json(result);
}
public ActionResult getPartNoInfo(string partNo)
{
Hashtable resault = new Hashtable();
List list = service.GetPartNoInfo(partNo);
return Json(list);
}
public ActionResult getPartSpecInfo(string partSpec)
{
Hashtable resault = new Hashtable();
List list = service.GetPartSpecInfo(partSpec);
return Json(list);
}
public ActionResult EditHandPullGroup(string pdlineCode, string maxPullValue)
{
ViewData.Add("editType", "edit");
ViewData.Add("pdlineCode", pdlineCode);
ViewData.Add("maxPullValue", maxPullValue);
return View("EditHandPullGroup");
}
public ActionResult saveHandPullGroup()
{
String pdlineCode = Request.Form["pdlineCode"].ToString();
String PullValue = Request.Form["PullValue"].ToString();
String message = "";
String status = "0";
try
{
bool ret = this.service.saveHandPullGroup(pdlineCode, PullValue);
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);
}
///
/// 保存菜单数据
///
///
public ActionResult savePullGroup()
{
string ruid = Request.Form["ruid"].ToString();
String triggerValue = Request.Form["triggerValue"].ToString();
String pullValue = Request.Form["pullValue"].ToString();
String maxPullValue = Request.Form["maxPullValue"].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());
WmsPullingGroupMes wmsPulling = new WmsPullingGroupMes();
wmsPulling.TriggerValue = Convert.ToInt32(triggerValue);
wmsPulling.PullValue = Convert.ToInt32(pullValue);
wmsPulling.PdlineName = pdlineName;
wmsPulling.PdlineCode = pdlineCode;
wmsPulling.CumulativeValue = Convert.ToInt32(kittingQty);
wmsPulling.Enabled = "Y";
wmsPulling.FactoryId = CurrentEmp.FactoryId;
wmsPulling.FactoryCode = CurrentEmp.FactoryCode;
wmsPulling.CreateUserId = CurrentEmp.EmpId;
String message = "";
String status = "0";
try
{
if (string.IsNullOrEmpty(ruid))
{
wmsPulling.CreateUserId = CurrentEmp.EmpId;
int ret = this.service.savePullGroup(wmsPulling);
if (ret > 0)
{
status = "1";
message = "添加成功";
}
else
{
status = "0";
message = "添加失败!";
}
}
else
{
wmsPulling.UpdateUserId = CurrentEmp.EmpId;
int ret = this.service.updatePullGroup(wmsPulling);
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 pdlineList = service.GetErpwarehouse();
resault.Add("list", pdlineList);
return Json(resault);
}
///
/// 编辑菜单
///
///
///
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 list)
{
Hashtable result = new Hashtable();
result.Add("list", list);
return Json(result);
}
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
///
/// 启用
///
///
///
public ActionResult onEnable(String pdlineCode)
{
int delCount = 0;
try
{
delCount = this.service.EnableData(pdlineCode);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 禁用
///
///
///
public ActionResult onDisable(String pdlineCode)
{
int delCount = 0;
try
{
delCount = this.service.DisableData(pdlineCode);
}
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
/// carImport
///
public ActionResult exportData(string groupCode, string groupName, string enabled = "Y")
{
List 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");
}
///
/// 下载模板
///
///
public ActionResult downLoadExcel(string rackPart, string partPackage, string enabled = "Y")
{
List listHt = new List();//导出空数据模板
var memoryStream = ExcelHelper.ToExcel(listHt);
string dateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
return File(memoryStream.ToArray(), "application/ms-excel", "拉动组管理" + dateTime + ".xls");
}
}
}