7d289a3b64
pulizia codice...
91 lines
2.8 KiB
C#
91 lines
2.8 KiB
C#
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
|
|
namespace GIM_site
|
|
{
|
|
public partial class ExcelExportAllData : System.Web.UI.Page
|
|
{
|
|
/// <summary>
|
|
/// wrapper traduzione
|
|
/// </summary>
|
|
/// <param name="lemma"></param>
|
|
/// <returns></returns>
|
|
public string traduci(object lemma)
|
|
{
|
|
return user_std.UtSn.Traduci(lemma.ToString());
|
|
}
|
|
/// <summary>
|
|
/// fix rendering tabelle standard in webform
|
|
/// </summary>
|
|
/// <param name="control"></param>
|
|
public override void VerifyRenderingInServerForm(Control control)
|
|
{
|
|
// Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.
|
|
}
|
|
/// <summary>
|
|
/// Si occupa di rendere l'out HTML come excel file (mimetype)
|
|
/// </summary>
|
|
private void doExportCsv()
|
|
{
|
|
var dataTable = TA_app.obj.taAllData.GetData();
|
|
StringBuilder builder = new StringBuilder();
|
|
List<string> columnNames = new List<string>();
|
|
List<string> rows = new List<string>();
|
|
|
|
foreach (DataColumn column in dataTable.Columns)
|
|
{
|
|
columnNames.Add(column.ColumnName);
|
|
}
|
|
|
|
builder.Append(string.Join(memLayer.ML.confReadString("separatoreCsv"), columnNames.ToArray())).Append("\n");
|
|
|
|
foreach (DataRow row in dataTable.Rows)
|
|
{
|
|
List<string> currentRow = new List<string>();
|
|
|
|
foreach (DataColumn column in dataTable.Columns)
|
|
{
|
|
object item = row[column];
|
|
|
|
currentRow.Add(item.ToString().Replace("\n", " ").Replace("\r", ""));
|
|
}
|
|
|
|
rows.Add(string.Join(memLayer.ML.confReadString("separatoreCsv"), currentRow.ToArray()));
|
|
}
|
|
|
|
builder.Append(string.Join("\n", rows.ToArray()));
|
|
|
|
Response.Clear();
|
|
Response.AddHeader("content-disposition", "attachment; filename=WebGIM_AllData.csv");
|
|
Response.ContentType = "text/csv";
|
|
Response.Charset = "";
|
|
Response.Cache.SetCacheability(HttpCacheability.NoCache);
|
|
Response.Write(builder.ToString());
|
|
Response.End();
|
|
}
|
|
|
|
#region area protected
|
|
|
|
/// <summary>
|
|
/// caricamento pagina
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!Page.IsPostBack)
|
|
{
|
|
doExportCsv();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
} |