自动生成报告(每周和每月)

本文关键字:每周 报告 自动生成 | 更新日期: 2023-09-27 18:16:42

有人知道如何安排自动生成每周和每月的报告吗?我尝试使用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();
    }

自动生成报告(每周和每月)

为什么不使用windows任务调度程序与控制台应用程序接收每周或每月作为参数?

可以使用 SQL-JOB 在周期Date-Time启动, run the exe

  1. 在这种情况下,您可以将 Query parameter 发送为 Run-time Parameter
  2. 还必须 write an App 获取参数和 Run report based on input parameter and then Save it