2011-02-07 5 views
0

데이터베이스에서 SQL 쿼리를 실행하는 콘솔 응용 프로그램을 작성해야합니다. 그런 다음 응용 프로그램은이 정보를 취하여 보고서로 컴파일하고이 보고서를 pdf로 내 보낸 다음 pdf 보고서를 전자 메일로 보내야합니다. (이 모든 것은 자동으로 수행한다 - 나는 특정 날짜와 시간에이 응용 프로그램을 실행하는 윈도우 스케줄러를 사용하기 위하여려고하고있다.)콘솔 응용 프로그램에서 SQL 보고서 컴파일

여기

내가 지금까지 무엇을 가지고 :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Data.Sql; 
using System.Data.SqlClient; 
using System.IO; 
using System.Net.Mail; 

namespace SqlQueryReports 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     SqlConnection dataConnection = new SqlConnection(); 
     try 
     { 
      dataConnection.ConnectionString ="Data Source=MY-PC\\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=True;Pooling=False"; 
      dataConnection.Open(); 

      SqlCommand dataCommand = new SqlCommand(); 
      dataCommand.Connection = dataConnection; 

      dataCommand.CommandText = "SELECT Product_id,Product_name,Product_price FROM Product"; 
      Console.WriteLine("About to execute: {0}\n\n", dataCommand.CommandText); 

      SqlDataReader dataReader = dataCommand.ExecuteReader(); 

      // Compile data into Report 
      // Export Report to .pdf 
      // Email .pdf report 

      dataReader.Close(); 

      Console.WriteLine("DONE"); 
     } 
     catch(SqlException e) 
     { 
      Console.WriteLine(e.Message); 
     } 

     finally 
     { 
      dataConnection.Close(); 
     } 

    }  
} 
} 

난 그냥 방법을 알 필요가 받는 사람 :

  1. 이 정보를 사용하여 보고서를 컴파일하십시오.
  2. 이 보고서를 PDF로 내보내기
  3. pdf 리포트를 전자 메일로 보내십시오.

미리 감사드립니다.

답변

0

DevExpress 또는 다른 타사 보고서 엔진에서 XtraReports를 사용할 수있는 사용자 친화적 인 디자이너에서 보고서를 멋지게 디자인하려는 경우 대개 데이터 소스를 바인딩하고 pdf (또는 Excel , png 등등 ...).

모든 것을 직접하고 싶다면 dataReader 필드 및 열에서 표 루프를 문자 그대로 작성하는 테이블 (예 :)을 사용하여 일종의 HTML 문서 형식을 지정할 수 있습니다. pdf 문서를 만들고 마지막으로 .NET Framework의 Smtp Mailing을 사용하여 전자 메일을 통해 pdf를 보낼 수 있습니다.

0

기본적으로 똑같은 작업이 기본적으로 주어 졌으므로이 입력에 대한 더 많은 정보를 얻으시기 바랍니다. 지금까지 제가 도움이 될만한 것을 찾았습니다. 샘플 PDF 내보내기 (출처 : ASP 스 니펫) ...

protected void ExportToPDF(object sender, EventArgs e) 
{ 
    //Get the data from database into datatable 
    string strQuery = "select CustomerID, ContactName, City, PostalCode"  + 
     " from customers"; 
    SqlCommand cmd = new SqlCommand(strQuery); 
DataTable dt = GetData(cmd); 

//Create a dummy GridView 
GridView GridView1 = new GridView(); 
GridView1.AllowPaging = false; 
GridView1.DataSource = dt; 
GridView1.DataBind(); 

Response.ContentType = "application/pdf"; 
Response.AddHeader("content-disposition", 
    "attachment;filename=DataTable.pdf"); 
Response.Cache.SetCacheability(HttpCacheability.NoCache); 
StringWriter sw = new StringWriter(); 
HtmlTextWriter hw = new HtmlTextWriter(sw); 
GridView1.RenderControl(hw); 
StringReader sr = new StringReader(sw.ToString()); 
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); 
HTMLWorker htmlparser = new HTMLWorker(pdfDoc); 
PdfWriter.GetInstance(pdfDoc, Response.OutputStream); 
pdfDoc.Open(); 
htmlparser.Parse(sr); 
pdfDoc.Close(); 
Response.Write(pdfDoc); 
Response.End(); 
관련 문제