title: auto generate report(weekly and monthly)
body: <p>Does anyone know how to schedule auto-generate for weekly and monthly report? I tried to use Windows Service,but the problem is I don't know how to setup my report to auto generate for weekly and monthly report. At this moment, I just put the date at the setparametervalue only. would appreciate if someone can guide me about this and do refer below for my coding. Thanks.</p>
  
  <pre><code>    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 &lt; 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();
      }
  </code></pre>