85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
using FI.FIC;
|
|
using FI.FIC.Contracts.DataObjects.BLObject;
|
|
using FI.FIC.DataProviders.ChartItems;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
public partial class ExportToFile : System.Web.UI.Page
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
string method = Request.Form["method"];
|
|
if (method == "targetExport")
|
|
{
|
|
ExportTargetData();
|
|
return;
|
|
}
|
|
|
|
string tid = HttpUtility.UrlDecode(Request.Params["dataid"]);
|
|
|
|
string title = HttpUtility.UrlDecode(Request.Params["Title"]);
|
|
string fileTyp = "";
|
|
try
|
|
{
|
|
fileTyp = Request.Params["FileTyp"].ToString();
|
|
}
|
|
catch { }
|
|
|
|
|
|
byte[] bts = null;
|
|
if (string.Equals(fileTyp, "xlsx", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
title = title + ".xlsx";
|
|
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
}
|
|
|
|
|
|
bts = (byte[])SubscribeCacheManager.GetExcelData<CacheExportData>(tid).Data;
|
|
SubscribeCacheManager.RemoveData(tid);
|
|
|
|
Response.BufferOutput = false;
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(title, System.Text.Encoding.UTF8));
|
|
Response.AddHeader("Content-Length", bts.Length.ToString());
|
|
|
|
Response.BinaryWrite(bts);
|
|
Response.Flush();
|
|
Response.End();
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
private void ExportTargetData()
|
|
{
|
|
string dtstring = HttpUtility.UrlDecode(Request.Form["dt"]);
|
|
bool exportColumnName = Request.Form["columnName"] == "1";
|
|
|
|
var dtobj = (JObject)JsonConvert.DeserializeObject(dtstring);
|
|
var dt = FICUtility.ConvertToDataTable(dtobj);
|
|
|
|
var xml = ExportHandler.Export(dt, false);
|
|
var data = Encoding.UTF8.GetBytes(xml);
|
|
|
|
Response.BufferOutput = false;
|
|
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
Response.AddHeader("Content-Disposition", "attachment; filename=TargetData.xml");
|
|
Response.AddHeader("Content-Length", data.Length.ToString());
|
|
|
|
Response.BinaryWrite(data);
|
|
Response.Flush();
|
|
Response.End();
|
|
}
|
|
} |