using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Collections.Generic;

public partial class Admin_PledgeList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Utility.IsNull(Session["Admin"]))
        {
            Response.Redirect("~/Home.aspx");
        }


        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["SabrinContent"].ToString());
        cn.Open();
        SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Pledges", cn);
        DataTable dt = new DataTable();
        da.Fill(dt);
        cn.Close();

        Response.Clear();
        Response.ContentType = "text/csv";
//        Response.Headers.Add("content-disposition", "attachment; filename=Pledges.csv");
        Response.AppendHeader("content-disposition", "inline; filename = pledges.csv");
        string sep = "";
        foreach (DataColumn dc in dt.Columns)
        {
            Response.Write(sep + dc.ColumnName);
            sep = ",";
        }
        Response.Write("\n");

        int i;
        foreach (DataRow dr in dt.Rows)
        {
            sep = "";
            for (i = 0; i < dt.Columns.Count; i++)
            {
                Response.Write(sep + dr[i].ToString());
                sep = ",";
            }
            Response.Write("\n");
        }
        Response.End(); 
    }
}
