コード例 #1
0
    private void GetResultByFilters()
    {
        String crit = string.Empty;

        if (cbCR.Checked)
        {
            crit = crit + cbCR.Text + ",";
        }
        if (cbPR.Checked)
        {
            crit = crit + cbPR.Text + ",";
        }
        if (cbTDR.Checked)
        {
            crit = crit + cbTDR.Text;
        }

        crit = crit.TrimEnd(',');

        ErrorMessage = crit;
        //return;
        if (!crit.Equals(""))
        {
            gvItems.DataSource = CCBDAL.GetCCBItems(crit);
        }

        gvItems.DataBind();
    }
コード例 #2
0
    public void ExportToSpreadsheet()
    {
        string delimiter = ",";

        string    name  = "";
        DataTable table = new DataTable();

        if (cbCR.Checked)
        {
            table = CCBDAL.GetCCBItems("CR").Tables[0];
            name  = "Formatted_Dump_CR_" + DateTime.Now.ToString("yyyyMMdd");
        }
        if (cbPR.Checked)
        {
            table = CCBDAL.GetCCBItems("PR").Tables[0];
            name  = "Formatted_Dump_PR_" + DateTime.Now.ToString("yyyyMMdd");
        }
        if (cbTDR.Checked)
        {
            table = CCBDAL.GetCCBItems("TDR").Tables[0];
            name  = "Formatted_Dump_TDR_" + DateTime.Now.ToString("yyyyMMdd");
        }



        HttpContext context = HttpContext.Current;

        context.Response.Clear();
        foreach (DataColumn column in table.Columns)
        {
            context.Response.Write(column.ColumnName + delimiter);
        }
        context.Response.Write(Environment.NewLine);
        foreach (DataRow row in table.Rows)
        {
            for (int i = 0; i < table.Columns.Count; i++)
            {
                context.Response.Write(row[i].ToString().Replace(delimiter, string.Empty) + delimiter);
            }
            context.Response.Write(Environment.NewLine);
        }
        context.Response.ContentType = "text/csv";
        context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + name + ".csv");
        context.Response.End();
    }