|
|
|
|
|
using System.Collections;
|
|
|
using Aspose.Cells;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Estsh.Core.Services.IServices;
|
|
|
using Estsh.Core.Model.Result;
|
|
|
using Estsh.Core.Models;
|
|
|
using System.Text.Json;
|
|
|
using Estsh.Core.Controllers;
|
|
|
using Estsh.Core.Model.ExcelModel;
|
|
|
using Estsh.Core.Util;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:BOM管理
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Web.Controllers
|
|
|
{
|
|
|
public class BOMDefineController : BaseController
|
|
|
{
|
|
|
|
|
|
private IBOMDefineService service;
|
|
|
private ICommonService commonService;
|
|
|
private IWebHostEnvironment hostingEnvironment;
|
|
|
public BOMDefineController(IBOMDefineService _service, ICommonService _commonService, IWebHostEnvironment _hostingEnvironment)
|
|
|
{
|
|
|
service = _service;
|
|
|
commonService = _commonService;
|
|
|
hostingEnvironment = _hostingEnvironment;
|
|
|
}
|
|
|
|
|
|
//
|
|
|
// GET: /BOMDefineController/
|
|
|
public ActionResult Index()
|
|
|
{
|
|
|
return View();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取车型列表
|
|
|
/// </summary>
|
|
|
/// <rehuoturns></returns>
|
|
|
public ActionResult getSelectModelType()
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
List<KeyValueResult> modelTypeList = commonService.getModelTypeInfo();
|
|
|
result.Add("list", modelTypeList);
|
|
|
return Json(result);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取配置列表
|
|
|
/// </summary>
|
|
|
/// <rehuoturns></returns>
|
|
|
public ActionResult getSelectModel(String modelType)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
List<KeyValueResult> modelList = service.getSelectModel(modelType);
|
|
|
result.Add("list", modelList);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取BOM类型列表
|
|
|
/// </summary>
|
|
|
/// <rehuoturns></returns>
|
|
|
public ActionResult getSelectBOMType()
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
List<KeyValueResult> bomTypeList = commonService.GetSysEnum("sys_bom_type");
|
|
|
result.Add("list", bomTypeList);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取零件名称列表
|
|
|
/// </summary>
|
|
|
/// <rehuoturns></returns>
|
|
|
public ActionResult getSelectPartNo(String bomType, String model)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
List<KeyValueResult> partList = this.service.getSelectPartNo(bomType, model);
|
|
|
result.Add("list", partList);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取获取工站数据列表
|
|
|
/// </summary>
|
|
|
/// <rehuoturns></returns>
|
|
|
public ActionResult getProcessData()
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
List<KeyValueResult> partList = this.service.getProcessData(CurrentEmp.FactoryId);
|
|
|
result.Add("list", partList);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取BOM数据列表
|
|
|
/// </summary>
|
|
|
/// <param name="bomType"></param>
|
|
|
/// <param name="partNo"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult getBOMList(String bomType, String partId,string pdline, String sort, String direction, string enabled = "Y")
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
if (string.IsNullOrEmpty(partId) || partId=="null")
|
|
|
{
|
|
|
return Json("");
|
|
|
}
|
|
|
List<SysBom> bomDataList = this.service.getBOMList(bomType, partId, sort, direction, pdline, enabled);
|
|
|
result.Add("rows", bomDataList);
|
|
|
result.Add("sort", sort);
|
|
|
result.Add("direction", direction);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 校验零件号是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="validateValue"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult validatePart(String validateValue)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
ValidateResult vResult = new ValidateResult();
|
|
|
int _id = service.GetPartID(validateValue);
|
|
|
if (_id == 0)
|
|
|
{
|
|
|
vResult.valid = false;
|
|
|
vResult.message = "零件号不存在!";
|
|
|
result.Add("validateResult", vResult);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
vResult.valid = true;
|
|
|
vResult.message = "OK";
|
|
|
result.Add("validateResult", vResult);
|
|
|
}
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 编辑BOM明细的子零件信息
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult editBOMD(String editType, String partNo, String bomType)
|
|
|
{
|
|
|
return View("AddBOM");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 编辑BOM明细的子零件信息
|
|
|
/// </summary>
|
|
|
/// <param name="ruid"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult editBOMDetail(String editType, SysBom bom)
|
|
|
{
|
|
|
String partNo= bom.PartNo;
|
|
|
|
|
|
ViewData.Add("editType", editType);
|
|
|
if (editType != null)
|
|
|
{
|
|
|
int BomID = service.GetBOMID(partNo, bom.BomType);
|
|
|
if (BomID == 0)
|
|
|
{
|
|
|
return Json("零件号不存在!");
|
|
|
}
|
|
|
if (editType.Equals("new"))
|
|
|
{
|
|
|
ViewData.Add("partNo", partNo);
|
|
|
ViewData.Add("itemCount", 0);
|
|
|
ViewData.Add("bomId", BomID);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ViewData.Add("bomId", BomID);
|
|
|
ViewData.Add("partNo", bom.PartNo);
|
|
|
ViewData.Add("stepType", bom.PartNo);
|
|
|
ViewData.Add("itemPartNo", bom.ItemPartNo);
|
|
|
ViewData.Add("itemCount", bom.ItemCount);
|
|
|
ViewData.Add("itemGroup", bom.ItemGroup);
|
|
|
ViewData.Add("location", bom.Location);
|
|
|
ViewData.Add("processId", bom.ProcessId);
|
|
|
ViewData.Add("version", bom.Version);
|
|
|
ViewData.Add("vitualPart", bom.VitualPart);
|
|
|
ViewData.Add("guid", bom.Guid);
|
|
|
}
|
|
|
return View("EditBOMDefine");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return Json("编辑类型为空!");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存BOM明细的子零件信息
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult saveBOMDetail()
|
|
|
{
|
|
|
String editType = Request.Form["editType"].ToString();
|
|
|
String bomId = Request.Form["bomId"].ToString();
|
|
|
String partNo = Request.Form["partNo"].ToString();
|
|
|
|
|
|
int partId = 0;
|
|
|
if (!string.IsNullOrEmpty(partNo))
|
|
|
{
|
|
|
partId = Convert.ToInt32(service.GetBOMPartId(partNo));
|
|
|
}
|
|
|
|
|
|
String stepType = Request.Form["stepType"].ToString();
|
|
|
String itemPartNo = Request.Form["itemPartNo"].ToString();
|
|
|
String itemCount = Request.Form["itemCount"].ToString() == null ? "" : Request.Form["itemCount"].ToString();
|
|
|
String itemGroup = Request.Form["itemGroup"].ToString() == "" ? "" : Request.Form["itemGroup"].ToString();
|
|
|
String location = Request.Form["location"].ToString() == "" ? "" : Request.Form["location"].ToString();
|
|
|
String processId = Request.Form["processName"].ToString() == "" ? "" : Request.Form["processName"].ToString();
|
|
|
String item_version = Request.Form["itemVersion"].ToString() == "" ? "" : Request.Form["itemVersion"].ToString();
|
|
|
string vitualPart = Request.Form["vitualPart"].ToString() == "" ? "" : Request.Form["vitualPart"].ToString();
|
|
|
|
|
|
String message = "";
|
|
|
String flag = "OK";
|
|
|
Hashtable result = new Hashtable();
|
|
|
|
|
|
string BOMType = service.GetBOMType(Convert.ToInt32(bomId));
|
|
|
int _id = service.GetPartID(itemPartNo);
|
|
|
if (BOMType == "绑定" || BOMType == "特征")
|
|
|
{
|
|
|
if (!service.ExistsPartSNRule(_id))
|
|
|
{
|
|
|
message = "请先定义条码特征!";
|
|
|
flag = "fail";
|
|
|
result.Add("message", message);
|
|
|
result.Add("flag", flag);
|
|
|
return Json(result);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
SysBomDetail model = new SysBomDetail();
|
|
|
model.BomId =Convert.ToInt32(bomId);
|
|
|
model.PartId = partId;
|
|
|
model.PartNo = partNo;
|
|
|
model.StepType = Convert.ToInt32(stepType);
|
|
|
model.ItemPartId = _id;
|
|
|
model.ItemGroup = itemGroup;
|
|
|
model.ItemQty = Convert.ToDecimal(itemCount);
|
|
|
model.ProcessId = Convert.ToInt32(processId);
|
|
|
model.Version = item_version;
|
|
|
model.Location = location;
|
|
|
model.VitualPart = vitualPart;
|
|
|
|
|
|
|
|
|
SysBomDetail detail = new SysBomDetail();
|
|
|
detail.BomId = Convert.ToInt32(bomId);
|
|
|
bool resultFlag = false;
|
|
|
if (editType != null && editType.Trim().Equals("new"))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
model.CreateUserId = CurrentEmp.EmpId;
|
|
|
|
|
|
resultFlag = this.service.addBomItemPart("sys_bom_detail", model);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
message = "添加失败!";
|
|
|
flag = "fail";
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
model.UpdateUserId = CurrentEmp.EmpId;
|
|
|
String guid = Request.Form["guid"].ToString() == "" ? "" : Request.Form["guid"].ToString();
|
|
|
resultFlag = this.service.UpdateBOMDetail(model, guid);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
message = "修改失败!";
|
|
|
flag = "fail";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (resultFlag)
|
|
|
{
|
|
|
if (BOMType.Equals("物料"))
|
|
|
{
|
|
|
this.service.BuildBOMMatch(Convert.ToInt32(bomId));
|
|
|
}
|
|
|
else if (BOMType.Equals("特征"))
|
|
|
{
|
|
|
this.service.BuildBOMMatchForTransBind(Convert.ToInt32(bomId));
|
|
|
}
|
|
|
message = "保存成功!";
|
|
|
flag = "OK";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
message = "保存失败!";
|
|
|
flag = "fail";
|
|
|
}
|
|
|
result.Add("message", message);
|
|
|
result.Add("flag", flag);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除BOMdetail数据
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult deleteBOMDetail(String guid)
|
|
|
{
|
|
|
int delCount = 0;
|
|
|
try
|
|
|
{
|
|
|
delCount = this.service.deleteBOMDetail(guid);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
delCount = -1;
|
|
|
}
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("status", delCount);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存BOM
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult saveBOM()
|
|
|
{
|
|
|
String modelType = Request.Form["modelType"].ToString();
|
|
|
String model = Request.Form["model"].ToString();
|
|
|
int bom_Type = int.Parse(Request.Form["bomType"].ToString());
|
|
|
String partNo = Request.Form["part"].ToString();
|
|
|
|
|
|
String message = "";
|
|
|
String flag = "OK";
|
|
|
Hashtable result = new Hashtable();
|
|
|
int bomID = service.GetBOMID(partNo, bom_Type);
|
|
|
if (bomID != 0)
|
|
|
{
|
|
|
message = "BOM 已经存在!";
|
|
|
flag = "fail";
|
|
|
result.Add("message", message);
|
|
|
result.Add("flag", flag);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
int partId = service.GetPartID(partNo);
|
|
|
|
|
|
Hashtable values = new Hashtable();
|
|
|
|
|
|
values.Add("partId", partId);
|
|
|
values.Add("bom_type", bom_Type);
|
|
|
|
|
|
values.Add("createUserid", CurrentEmp.EmpId);
|
|
|
values.Add("enabled", "Y");
|
|
|
|
|
|
SysBom bom = new SysBom();
|
|
|
bom.PartId = partId;
|
|
|
bom.BomType = bom_Type;
|
|
|
bom.CreateUserId = CurrentEmp.EmpId;
|
|
|
bom.Enabled = "Y";
|
|
|
|
|
|
if (service.InsertBOM(bom))
|
|
|
{
|
|
|
message = "新增成功";
|
|
|
flag = "OK";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
message = "新增失败!";
|
|
|
flag = "fail";
|
|
|
}
|
|
|
result.Add("message", message);
|
|
|
result.Add("flag", flag);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除BOM
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult deleteBOM(String partNo, int bomType)
|
|
|
{
|
|
|
String message = "";
|
|
|
int flag = 0;
|
|
|
try
|
|
|
{
|
|
|
int bomId = service.GetBOMID(partNo, bomType);
|
|
|
if (bomId == 0)
|
|
|
{
|
|
|
message = "请选择 BOM 和 BOM 类型";
|
|
|
flag = 0;
|
|
|
}
|
|
|
if (service.DeleteBOM(bomId))
|
|
|
{
|
|
|
message = "BOM 删除成功!";
|
|
|
flag = 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
message = "BOM 删除失败!";
|
|
|
flag = 0;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
message = "删除BOM出错!";
|
|
|
flag = 0;
|
|
|
}
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("message", message);
|
|
|
result.Add("flag", flag);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 启用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult onEnable(String ids)
|
|
|
{
|
|
|
String message = "";
|
|
|
int flag = 0;
|
|
|
int delCount = 0;
|
|
|
try
|
|
|
{
|
|
|
delCount = this.service.EnableData(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.DisableData(ids);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
delCount = -1;
|
|
|
}
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("status", delCount);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导入Bom Excel文件
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult importBOMInfo()
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
IFormFile file = Request.Form.Files[0];
|
|
|
List<BOMDefine> data = ExcelHelper.GetList<BOMDefine>(file, 0);
|
|
|
result = service.ImportExcel(data, CurrentEmp.EmpId);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导出Bom 数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult exportBOMInfo(String bomType, String partId)
|
|
|
{
|
|
|
List<BOMDefine> dataHt = this.service.exportBOMInfo(bomType, partId);
|
|
|
var memoryStream = ExcelHelper.ToExcel(dataHt);
|
|
|
return File(memoryStream.ToArray(), "application/ms-excel", "BOM管理.xls");
|
|
|
}
|
|
|
public ActionResult exportALL(String bomType)
|
|
|
{
|
|
|
List<BOMDefine> dataHt = this.service.exportALL(bomType);
|
|
|
var memoryStream = ExcelHelper.ToExcel(dataHt);
|
|
|
return File(memoryStream.ToArray(), "application/ms-excel", "BOM管理.xls");
|
|
|
}
|
|
|
}
|
|
|
}
|