using Estsh.Core.Controllers;
using Estsh.Core.Model.ExcelModel;
using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Services;
using Estsh.Core.Services.IServices;
using Estsh.Core.Util;
using Microsoft.AspNetCore.Mvc;
using NPOI.HSSF.UserModel;
using System.Collections;
/***************************************************************************************************
*
* 更新人:sitong.dong
* 描述:批次追溯查询
* 修改时间:2022.06.22
* 修改日志:系统迭代升级
*
**************************************************************************************************/
namespace Estsh.Core.Web.Controllers
{
public class LotDefineController : BaseController
{
private ILotDefineService service;
private IGridColumnService colService;
public LotDefineController(ILotDefineService _service, IGridColumnService colService)
{
service = _service;
this.colService = colService;
}
public ActionResult Index()
{
return View();
}
public string GetWhereStr()
{
string _whereStr = string.Empty;
//零件号
if (!string.IsNullOrEmpty(Request.Form["txtPart_No"]))
{
if (Request.Form["txtPart_No"].ToString().Trim() == "")
{
_whereStr += "";
}
else
{
_whereStr += " and a.item_part_no = '" + Request.Form["txtPart_No"].ToString().Trim() + "'";
}
}
//批次
if (!string.IsNullOrEmpty(Request.Form["txtLotNo"]))
{
if (Request.Form["txtLotNo"].ToString().Trim() == "")
{
_whereStr += "";
}
else
{
_whereStr += " and lot_no = '" + Request.Form["txtLotNo"].ToString().Trim() + "'";
}
}
return _whereStr;
}
///
/// 获取批次追溯查询列表数据
///
///
public ActionResult GetQuery(Pager pager)
{
if (string.IsNullOrEmpty(Request.Form["txtPart_No"]) && string.IsNullOrEmpty(Request.Form["txtLotNo"]))
{
return Json("");
}
string wheres = GetWhereStr();
int totalCount = 0;
List dataHt = service.GetQuery(wheres, pager, ref totalCount);
Hashtable result = new Hashtable();
result.Add("rows", dataHt);
result.Add("pager.totalRows", totalCount);
return Json(result);
}
public ActionResult exportData(Pager pager)
{
// 如果没有数据就直接返回
Hashtable resault = new Hashtable();
string wheres = GetWhereStr();
int totalCount = 0;
Hashtable dataHt = service.getTableListByPage(wheres, pager);
List listHt = (List)dataHt["dataList"];
var memoryStream = ExcelHelper.ToExcel(listHt);
return File(memoryStream.ToArray(), "application/ms-excel", "批次追溯查询.xls");
}
}
}