一厂MES,含注塑,喷涂,冲孔
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.9 KiB

3 months ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using MESClassLibrary.BLL.BasicInfo;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
namespace MESWebSite.HttpHandlers
{
/// <summary>
/// ZpBadInjectionSearchHandler 的摘要说明
/// </summary>
public class ZpBadInjectionSearchHandler : IHttpHandler
{
HttpRequest _request = null;
HttpResponse _response = null;
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
_request = context.Request;
_response = context.Response;
string method = _request.Params["method"];
switch (method)
{
case "QueryList":
QueryList();
break;
case "QueryExcel":
QueryExcel();
break;
}
}
void QueryList()
{
string page = _request.Params["page"];
string pageSize = _request.Params["rows"];
string barCode = _request.Params["barcode"];
string startTime = _request.Params["StartTime"];
string endTime = _request.Params["EndTime"];
if (string.IsNullOrEmpty(page))
{
page = "0";
}
if (string.IsNullOrEmpty(pageSize))
{
pageSize = "15";
}
BadInjectionBLL bll = new BadInjectionBLL();
_response.Write(bll.SearchZpInfoAll(page, pageSize, barCode, startTime, endTime));
_response.End();
}
void QueryExcel()
{
string barCode = _request.Params["barcode"];
string startTime = _request.Params["StartTime"];
string endTime = _request.Params["EndTime"];
BadInjectionBLL bll = new BadInjectionBLL();
List<List<string>> list = bll.SearchZpForExcel(barCode, startTime, endTime);
XSSFWorkbook book = new XSSFWorkbook();
ISheet sheet = book.CreateSheet("Sheet1");
for (int i = 0; i < list.Count; i++)
{
IRow row = sheet.CreateRow(i);
for (int k = 0; k < list[i].Count; k++)
{
row.CreateCell(k).SetCellValue(list[i][k].ToString());
}
}
// 写入到客户端
MemoryStream ms = new MemoryStream();
book.Write(ms);
_response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmssfff")));
_response.BinaryWrite(ms.ToArray());
book = null;
ms.Close();
ms.Dispose();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}