136 lines
3.8 KiB
C#
136 lines
3.8 KiB
C#
using AppData;
|
|
using System;
|
|
using System.Data;
|
|
using System.Text;
|
|
|
|
namespace C_TRACK
|
|
{
|
|
public partial class doExport : BasePage
|
|
{
|
|
#region Protected Properties
|
|
|
|
protected DateTime dateFrom
|
|
{
|
|
get
|
|
{
|
|
DateTime answ = DateTime.Today.AddYears(-1);
|
|
// se è diverso da vuoto faccio parse...
|
|
if (!string.IsNullOrEmpty(from))
|
|
{
|
|
DateTime.TryParse(from, out answ);
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
protected DateTime dateTo
|
|
{
|
|
get
|
|
{
|
|
DateTime answ = DateTime.Today.AddDays(1);
|
|
// se è diverso da vuoto faccio parse...
|
|
if (!string.IsNullOrEmpty(to))
|
|
{
|
|
DateTime.TryParse(to, out answ);
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
protected string from
|
|
{
|
|
get
|
|
{
|
|
return Request.QueryString["from"];
|
|
}
|
|
}
|
|
|
|
protected string mode
|
|
{
|
|
get
|
|
{
|
|
return Request.QueryString["mode"];
|
|
}
|
|
}
|
|
|
|
protected string to
|
|
{
|
|
get
|
|
{
|
|
return Request.QueryString["to"];
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
string delimiter = ",";
|
|
|
|
//prepare the output stream
|
|
Response.Clear();
|
|
Response.ContentType = "text/csv";
|
|
Response.AppendHeader("Content-Disposition", "attachment; filename=ctrack_report.csv");
|
|
|
|
string value = "";
|
|
StringBuilder builder = new StringBuilder();
|
|
DataTable dt = new DataTable();
|
|
|
|
// leggo tabella secondo il MODO
|
|
if (mode == "aggr")
|
|
{
|
|
dt = (DataTable)DLMan.taTRA.getByFilt("", dateFrom, dateTo);
|
|
}
|
|
else
|
|
{
|
|
dt = (DataTable)DLMan.taTR.getByFilt("", dateFrom, dateTo);
|
|
}
|
|
|
|
// write the csv column headers
|
|
for (int i = 0; i < dt.Columns.Count; i++)
|
|
{
|
|
value = dt.Columns[i].ColumnName;
|
|
// Implement special handling for values that contain comma or quote
|
|
// Enclose in quotes and double up any double quotes
|
|
if (value.IndexOfAny(new char[] { '"', ',' }) != -1)
|
|
builder.AppendFormat("\"{0}\"", value.Replace("\"", "\"\""));
|
|
else
|
|
{
|
|
builder.Append(value);
|
|
}
|
|
|
|
Response.Write(value);
|
|
Response.Write((i < dt.Columns.Count - 1) ? delimiter : Environment.NewLine);
|
|
builder.Clear();
|
|
}
|
|
|
|
//write the data
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
for (int i = 0; i < dt.Columns.Count; i++)
|
|
{
|
|
value = row[i].ToString();
|
|
// Implement special handling for values that contain comma or quote
|
|
// Enclose in quotes and double up any double quotes
|
|
|
|
if (value.IndexOfAny(new char[] { '"', ',' }) != -1)
|
|
builder.AppendFormat("\"{0}\"", value.Replace("\"", "\"\""));
|
|
else
|
|
{
|
|
builder.Append(value);
|
|
}
|
|
|
|
Response.Write(builder.ToString());
|
|
Response.Write((i < dt.Columns.Count - 1) ? delimiter : Environment.NewLine);
|
|
builder.Clear();
|
|
}
|
|
}
|
|
|
|
Response.End();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |