2011-12-01 2 views
0

주간 및 월간 보고서에 대해 자동 생성을 예약하는 방법을 아는 사람이 있습니까? Windows 서비스를 사용하려고했지만 문제는 매주 및 월간 보고서를 자동으로 생성하도록 보고서를 설정하는 방법을 모르겠다는 것입니다. 이 시점에서, 나는 단지 날짜를 setparametervalue에 놓는다. 누군가가 이것에 관해 나를 안내 할 수 있고 내 코딩을 위해 아래에서 참조 할 수 있다면 고맙겠습니다. 감사.자동 생성 보고서 (주별 및 월별)

private Timer scheduleTimer = null; 
    private DateTime lastRun; 
    private bool flag; 

    static TableLogOnInfo crTableLogonInfo; 
    static ConnectionInfo crConnectionInfo; 
    static Tables crTables; 
    static Database crDatabase; 

    static string Server = ConfigurationManager.AppSettings["serverName"]; 
    static string Database = ConfigurationManager.AppSettings["databaseName"]; 
    static string UserID = ConfigurationManager.AppSettings["userID"]; 
    static string Password = ConfigurationManager.AppSettings["password"]; 

    public ReportWindowsService() 
    { 
     InitializeComponent(); 

     scheduleTimer = new Timer(); 
     scheduleTimer.Interval = 1 * 5 * 60 * 1000; 
     scheduleTimer.Elapsed += new ElapsedEventHandler(scheduleTimer_Elapsed); 

    } 

    protected override void OnStart(string[] args) 
    { 
     // TODO: Add code here to start your service. 
     flag = true; 
     lastRun = DateTime.Now; 
     scheduleTimer.Start(); 
    } 

    protected void scheduleTimer_Elapsed(object sender, ElapsedEventArgs e) 
    { 
     if (flag == true) 
     { 
      BillingReport(); 
      ReleaseImageReport(); 
      lastRun = DateTime.Now; 
      flag = false; 
     } 
     else if (flag == false) 
     { 
      if (lastRun.Date < DateTime.Now.Date) 
      { 
       BillingReport(); 
       ReleaseImageReport(); 
      } 
     } 
    } 

    public static ConnectionInfo ReportLogin(ReportDocument crRpt) 
    { 
     crConnectionInfo = new ConnectionInfo(); 
     crConnectionInfo.ServerName = Server; 
     crConnectionInfo.DatabaseName = Database; 
     crConnectionInfo.UserID = UserID; 
     crConnectionInfo.Password = Password; 

     crDatabase = crRpt.Database; 
     crTables = crDatabase.Tables; 
     foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables) 
     { 
      crTableLogonInfo = crTable.LogOnInfo; 
      crTableLogonInfo.ConnectionInfo = crConnectionInfo; 
      crTable.ApplyLogOnInfo(crTableLogonInfo); 
     } 

     return crConnectionInfo; 
    } 

    public static void BillingReport()//monthly report 
    { 
     ReportDocument crRpt = new ReportDocument(); 
     TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); 
     TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); 
     ConnectionInfo crConnectionInfo = new ConnectionInfo(); 
     crRpt.Load("C:\\rptBilling.rpt"); 

     ReportLogin(crRpt); 

     crRpt.SetParameterValue("@CollectionStartDate", "2011/09/14"); 
     crRpt.SetParameterValue("@CollectionEndDate", "2011/09/29"); 
     crRpt.SetParameterValue("@SpokeCode", "14"); 
     crRpt.SetParameterValue("@UseCollectionDate", "1");//value can be set 0 or 1 
     crRpt.SetParameterValue("@UseUploadDate", "0");//value can be set 0 or 1 
     crRpt.SetParameterValue("@UploadStartDate", "2011/09/23"); 
     crRpt.SetParameterValue("@UploadEndDate", "2011/09/23"); 

     crRpt.ExportToDisk(ExportFormatType.PortableDocFormat, "e:\\BillingReport.pdf"); 
    } 

    public static void ReleaseImageReport()//weekly report 
    { 
     ReportDocument crRpt = new ReportDocument(); 
     TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); 
     TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); 
     ConnectionInfo crConnectionInfo = new ConnectionInfo(); 
     crRpt.Load("C:\\rptReleaseImage.rpt"); 

     ReportLogin(crRpt); 

     crRpt.SetParameterValue("@CollectionStartDate", "2011/09/14"); 
     crRpt.SetParameterValue("@CollectionEndDate", "2011/09/29"); 
     crRpt.SetParameterValue("@SpokeCode", "14"); 
     crRpt.SetParameterValue("@UseCollectionDate", "1");//value can be set 0 or 1 
     crRpt.SetParameterValue("@UseUploadDate", "0");//value can be set 0 or 1 
     crRpt.SetParameterValue("@UploadStartDate", "2011/09/23"); 
     crRpt.SetParameterValue("@UploadEndDate", "2011/09/23"); 

     crRpt.ExportToDisk(ExportFormatType.PortableDocFormat, "e:\\ReleaseImageReport.pdf"); 
    } 

    protected override void OnStop() 
    { 
     // TODO: Add code here to perform any tear-down necessary to stop your service. 
     scheduleTimer.Stop(); 
    } 

답변

0

당신은 정기적으로 날짜 - 시간 및 run the exe에서 시작 SQL-JOB를 사용할 수 있습니다.

  1. 이 경우 당신은 당신의 Query parameterRun-time Parameter을 보낼 수 있습니다.
  2. 또한 당신의 필수 write an App 매개 변수와 Run report based on input parameter and then Save it를 얻을 수 있습니다.
+0

안녕하세요. 제안 ... 제안 해 주셔서 감사합니다. 첫 번째 coz을 시도해 봅니다. C#에서 스케줄러 코드를 직접 넣어 주시면 감사하겠습니다. – srahifah

+0

Sql-job은 C# 코드 (이 경우 Windows 서비스)보다 낫습니다. cuz 작업은 서버와 SQL 서버가 실행될 때까지 활성화됩니다. (정기적 인 시간에 호출하는) jop의 스케줄링은 윈도우의 서비스보다 훨씬 쉽습니다. – Rev

1

매주 또는 매월 인수로 콘솔 응용 프로그램에서 Windows 작업 스케줄러를 사용하지 않는 이유는 무엇입니까?

관련 문제