繁体   English   中英

如何自动更新startDate和EndDate以便下次执行?

[英]How to auto update startDate and EndDate for next execution?

我需要一些有关如何自动更新StartDate和EndDate以便下次执行的帮助。 这时,我在SQL数据库中手动添加了StartDate和EndDate,如果没有更改StartDate和EndDate,则将使用相同的StartDate和EndDate生成报告。 谢谢大家都可以对此提出任何想法或建议。 谢谢。

static void Main(string[] args)
{
    DateTime start = System.DateTime.Now.AddMinutes(1);
    Schedule.PeriodicSchedules schedule = 
        new Schedule.PeriodicSchedules(start,
            Schedule.PeriodicSchedules.Frequency.Minutely);
    schedule.Elapsed += new System.Timers.ElapsedEventHandler(GenerateReport);
    schedule.Enabled = true;

    Console.ReadLine();
}

static void GenerateReport(object sender, EventArgs e)
{
    if (TypeOfReport == "BillingReport")
    {
        DateOfExecution = DateTime.Parse(strDOE);
        Schedule.PeriodicSchedules s = 
            new Schedule.PeriodicSchedules(DateOfExecution,
                Schedule.PeriodicSchedules.Frequency.Weekly);

        crRpt.Load(BillingReport);
        ReportLogin(crRpt);

        while (ThisReader.Read())
        {
            //StartDate and EndDate >>next execution?
            crRpt.SetParameterValue("@CollectionStartDate", StartDate);
            crRpt.SetParameterValue("@CollectionEndDate", EndDate);
            crRpt.SetParameterValue("@SpokeCode", SpokeCode);
        }
    }
    if (TypeOfReport == "ImageReport")
    {
        DateOfExecution = DateTime.Parse(strDOE);
        Schedule.PeriodicSchedules s = 
            new Schedule.PeriodicSchedules(DateOfExecution,         
                Schedule.PeriodicSchedules.Frequency.Monthly);

        crRpt.Load(ImageReport);
        ReportLogin(crRpt);

        crRpt.SetParameterValue("@CollectionStartDate", StartDate);
        crRpt.SetParameterValue("@CollectionEndDate", EndDate);
        crRpt.SetParameterValue("@SpokeCode", SpokeCode);
    }
}    

我设法通过调用另一种方法来自动更新我的DateOfExecution。 让我知道是否有人有其他选择。 :)

static void GenerateReport(object sender, EventArgs e)
    {
        if (TypeOfReport == "BillingReport")
        {
           ......
           DateOfExecution = DateTime.Parse(strDOE);
           Schedule.PeriodicSchedules s = new Schedule.PeriodicSchedules(DateOfExecution, Schedule.PeriodicSchedules.Frequency.Minutely);
           //weekly
           DateTime StartDate = DateOfExecution.AddDays(-7);
           DateTime EndDate = DateOfExecution.AddDays(-1);
           ..........
           UpdateWeekly(DateOfExecution, strReportType);             
        }        
    }

static void UpdateWeekly(DateTime DateOfExecution, String strReportType)
    {
        DateOfExecution = DateOfExecution.AddMinutes(2);
        SqlConnection thisConnection = new SqlConnection(SQLConnection);
        thisConnection.Open();
        SqlCommand thisCommand = thisConnection.CreateCommand();
        //thisCommand.CommandText = "INSERT INTO dbo.Schedules (DateOfExecution)" + "Values('"+DateOfExecution+"')";
        thisCommand.CommandText = "UPDATE dbo.Schedule set DateOfExecution = '" + DateOfExecution + "' WHERE TypeOfReport = '" + strReportType + "'";
        thisCommand.ExecuteNonQuery();
    }

暂无
暂无

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

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