简体   繁体   English

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

[英]auto generate report(weekly and monthly)

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. 我尝试使用Windows Service,但问题是我不知道如何设置我的报告以自动生成每周和每月报告。 At this moment, I just put the date at the setparametervalue only. 目前,我只将日期设置为setparametervalue。 would appreciate if someone can guide me about this and do refer below for my coding. 如果有人可以为我提供指导并在下面为我的编码提供帮助,我将不胜感激。 Thanks. 谢谢。

    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任务计划程序与控制台应用程序一起使用,该控制台应用程序每周或每月接收一个参数?

You can use SQL-JOB to start at periodic Date-Time and run the exe . 您可以使用SQL-JOB在定期的Date-Time上启动并run the exe

  1. In this case you can send your Query parameter as Run-time Parameter . 在这种情况下,您可以将Query parameter作为Run-time Parameter
  2. Also your must write an App to get parameter and Run report based on input parameter and then Save it . 另外,您还必须write an App以获取参数并Run report based on input parameter and then Save it

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM