Files
2-BeiqiFutian-MES_Manage/submit/MESCommonBase07.ashx
2026-05-29 13:44:19 +08:00

254 lines
11 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<%@ WebHandler Language="C#" Class="MESCommonBase07" %>
using System;
using System.Web;
using System.IO;
using System.Web.Script.Serialization;
using BasicData;
using DataLinkMesWork;
public class MESCommonBase07 : IHttpHandler
{
public bool IsReusable
{
get
{
return false;
}
}
public void ProcessRequest(HttpContext context)
{
string connType = "07";
context.Response.ContentType = "application/json";
var data = context.Request;
var stream = new StreamReader(data.InputStream).ReadToEnd();
string InvoiceNum;
//JsonData jsonData;
string responseText = "NULL";
byte[] bytes = null;
string fileName = "test.xsl";
try
{
JsonData jsonData=null;
try
{
jsonData = JsonMapper.ToObject(stream);
}
catch(Exception err)
{ }
int type=0;
try
{
if(jsonData!=null)
{
if(jsonData.ContainsKey("Type"))
{
type = Int32.Parse( jsonData["Type"].ToString());
}else if(jsonData.ContainsKey("type"))
{
type = Int32.Parse( jsonData["type"].ToString());
}
}
}
catch
{
}
jsonobj dataobj=null;
try
{
dataobj = new JavaScriptSerializer().Deserialize<jsonobj>(stream);
if(dataobj!=null)
{
type = Int32.Parse(dataobj.Type);
}
}
catch(Exception err)
{
dataobj = null;
}
if(dataobj==null)
{
try
{
InvoiceNum = HttpContext.Current.Request["param"];
if(InvoiceNum!=null)
{
jsonData = JsonMapper.ToObject(InvoiceNum);
if(jsonData.ContainsKey("Type"))
{
type = Int32.Parse( jsonData["Type"].ToString());
}else if(jsonData.ContainsKey("type"))
{
type = Int32.Parse( jsonData["type"].ToString());
}
}
}
catch
{
jsonData = null;
}
}
string fileExtension="";
HttpFileCollection files;
string suffix;
string name;
switch(type)
{
case 2001:
//DataLink.LogJsonData(jsonData);
MESDownloadExcel.ExcelWebCall.ExcelFile(jsonData,out bytes,out fileName,ref fileExtension);
fileName = fileName + "."+fileExtension;
HttpContext.Current.Response.ContentType = "application/octet-stream";
//HttpContext.Current.Response.ContentType = getContentType(extension);
//通知浏览器下载文件而不是打开
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Access-Control-Expose-Headers", "Content-Disposition");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
break;
case 2002:
//DataLink.LogJsonData(jsonData);
MESDownloadExcel.ExcelWebCall.ExcelFilePdf(jsonData,out bytes,out fileName,out fileExtension);
fileName = fileName + "."+fileExtension;
HttpContext.Current.Response.ContentType = "application/octet-stream";
//HttpContext.Current.Response.ContentType = getContentType(extension);
//通知浏览器下载文件而不是打开
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Access-Control-Expose-Headers", "Content-Disposition");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
break;
case 2003:// 合成excel图片下载
string[] dataimg;
if(context.Request.Form.Keys.Count>0)
{
dataimg = data.Form.GetValues(0);
MESDownloadExcel.ExcelWebCall.ExcelFile(jsonData,out bytes,out fileName,ref dataimg[0]);
if (bytes == null) return;
fileName = fileName + "."+dataimg[0];
HttpContext.Current.Response.ContentType = "application/octet-stream";
//HttpContext.Current.Response.ContentType = getContentType(extension);
//通知浏览器下载文件而不是打开
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Access-Control-Expose-Headers", "Content-Disposition");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
//if(DataLinkMesWork.DataLink.isBakup=="1")
//{
// DataLinkMesWork.DataLink.ExePROCEDURE_Type16_Bakup(jsonData, out bytes, out fileName, out suffix);
//}
}
break;
case 2004:
//DataLink.LogJsonData(jsonData);
DataLinkMesWork.DataLink.ExePROCEDURE_Type2004(connType,jsonData, out bytes, out fileName, out fileExtension);
//MESDownloadExcel.ExcelWebCall.ExcelFile(jsonData,out bytes,out fileName,ref fileExtension);
fileName = fileName + "."+fileExtension;
HttpContext.Current.Response.ContentType = "application/octet-stream";
//HttpContext.Current.Response.ContentType = getContentType(extension);
//通知浏览器下载文件而不是打开
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Access-Control-Expose-Headers", "Content-Disposition");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
break;
case 15://上传文件
files = context.Request.Files;
if (files.Count > 0)
{
fileName = files[0].FileName;
bytes = new byte[files[0].InputStream.Length];
files[0].InputStream.Read(bytes, 0, bytes.Length);
suffix = fileName.Substring(fileName.LastIndexOf(".")+1);
name = fileName.Substring(0,fileName.LastIndexOf("."));
responseText = DataLinkMesWork.DataLink.ExePROCEDURE_Type15(connType,jsonData, name, suffix, bytes);
context.Response.Write(responseText);
//if(DataLinkMesWork.DataLink.isBakup=="1")
//{
// DataLinkMesWork.DataLink.ExePROCEDURE_Type15_Bakup(jsonData, name, suffix, bytes);
//}
}
else
{
fileName = "";
bytes = new byte[1];
suffix = "";
name = "";
responseText = DataLinkMesWork.DataLink.ExePROCEDURE_Type15(connType,jsonData, name, suffix, bytes);
context.Response.Write(responseText);
//if(DataLinkMesWork.DataLink.isBakup=="1")
//{
// DataLinkMesWork.DataLink.ExePROCEDURE_Type15_Bakup(jsonData, name, suffix, bytes);
//}
}
break;
case 16://上传文件
DataLink.LogJsonData(jsonData);
DataLinkMesWork.DataLink.ExePROCEDURE_Type16(connType,jsonData, out bytes, out fileName, out suffix);
if (bytes == null) return;
fileName = fileName + "."+suffix;
HttpContext.Current.Response.ContentType = "application/octet-stream";
//HttpContext.Current.Response.ContentType = getContentType(extension);
//通知浏览器下载文件而不是打开
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Access-Control-Expose-Headers", "Content-Disposition");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
//if(DataLinkMesWork.DataLink.isBakup=="1")
//{
// DataLinkMesWork.DataLink.ExePROCEDURE_Type16_Bakup(jsonData, out bytes, out fileName, out suffix);
//}
break;
default:
//DataLink.LogJsonData(jsonData);
responseText = DataLinkMesWork.DataLink.SqlWebCall(connType,type,jsonData,dataobj);//.SqlWebCall(stream);
context.Response.Write(responseText);
//if(DataLinkMesWork.DataLink.isBakup=="1")
//{
// DataLinkMesWork.DataLink.SqlWebCall_Bakup(type,jsonData,dataobj);
//}
break;
}
}
catch(Exception err)
{
context.Response.Write(responseText);
} }
}