2025-03-27 15:05:14 +08:00

93 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using Business = SuperMap.RealEstate.HighWay.Running.Business;
using HZQR.Common;
namespace SuperMap.RealEstate.Finance.Handler
{
/// <summary>
/// Filehelper 的摘要说明
/// </summary>
public class Filehelper : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string action_type = Pub.Request("action_type");
string action_data = Pub.Request("action_data");
//文件操作
//action_data = "24".ToEncrypt();
string RetString = string.Empty;
ServiceModel.Transaction _Transaction = new ServiceModel.Transaction();
Business.ATTACHMENT _ATTACHMENT = new Business.ATTACHMENT(_Transaction);
switch (action_type)
{
#region
case "downloadfile":
_ATTACHMENT.ResetProperty();
_ATTACHMENT.AddSearchParameter("ATTACHMENT_ID", action_data.ToDecrypt());
if (_ATTACHMENT.Search())
{
string uploadPath = HttpContext.Current.Server.MapPath("~/UploadImageDir/FINANCEPROINST/") + _ATTACHMENT.ATTACHMENT_NAME;
if (!System.IO.File.Exists(uploadPath))
{
context.Response.Write("error:服务器上该文件已被删除或不存在!");
return;
}
context.Response.Clear();
context.Response.Buffer = true;
context.Response.Charset = "utf-8";
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");//设置输出流为简体中文
context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=" +
_ATTACHMENT.ATTACHMENT_NAME, DateTime.Now.ToString("yyyyMMddHHmmssfff")));
context.Response.AddHeader("Content-length", System.IO.File.ReadAllBytes(uploadPath).Length.ToString());
//context.Response.BinaryWrite(System.IO.File.ReadAllBytes(uploadPath));
System.IO.FileInfo lFileInfo = new System.IO.FileInfo(uploadPath);
context.Response.WriteFile(lFileInfo.FullName);
context.Response.ContentType = "application/octet-stream";//设置输出文件类型为excel文件。
context.Response.Flush();
context.Response.End();
}
break;
#endregion
case "DeleteFile":
RetString = CommonInterface.BusinessHelper.DeleteFile(_Transaction);
break;
case "deletefilebycode":
_ATTACHMENT.ResetProperty();
_ATTACHMENT.AddSearchParameter("ATTACHMENT_ID", action_data.ToDecrypt());
if (_ATTACHMENT.Search())
{
_ATTACHMENT.Delete();
RetString = "1";
}
break;
}
_Transaction.AutoCommit();
context.Response.ContentType = "text/plain";
context.Response.Write(RetString);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}