旧版报表、仓库
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.
 
 
 
 
 

79 lines
2.3 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Warehouse.DAL.Sitecapacity;
using OfficeOpenXml;
using System.Data;
using Dapper;
using System.Net.Http.Headers;
//using System.Web.Mvc;
using System.Data.SqlClient;
using System.IO;
namespace Warehouse.WebApi
{
[RoutePrefix("api/Sitecapacity")]
public class SitecapacityController : ApiController
{
static DbUtility dbhelp = new DbUtility(System.Configuration.ConfigurationManager.ConnectionStrings["mesConn"].ToString(), DbProviderType.MySql);
Sitecapacity scp = new Sitecapacity();
[Route("QueryQCInfo")]
[HttpPost]
public IHttpActionResult QueryQCInfo(dynamic para)
{
var res = scp.QueryQCInfo(para);
return Json(res);
//return Json<dynamic>(new { AA = "aa", BB = "cc" });
}
[Route("QueryStatus")]
[HttpPost]
public IHttpActionResult QueryStatus()
{
var res = scp.QueryStatus();
return Json<dynamic>(res);
}
[Route("ExportExcel")]
[HttpPost]
public HttpResponseMessage ExportExcel()
{
var stream = new MemoryStream();
// processing the stream.
string sql = @"SELECT TOP 1000 *
FROM[mes_main].[dbo].[assembly_basis]";
DataTable dt = dbhelp.ExecuteDataTable(sql, null);
using (ExcelPackage pck = new ExcelPackage())
{
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Accounts");
ws.Cells["A1"].LoadFromDataTable(dt, true);
pck.SaveAs(stream);
}
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
//Content = new ByteArrayContent(stream.ToArray())
Content = new StreamContent(stream)
};
result.Content.Headers.ContentDisposition =
new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
{
FileName = "exceltst.xlsx"
};
result.Content.Headers.ContentType =
new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
return result;
}
}
}