Как автоматически обновить startDate и EndDate для следующего выполнения? - PullRequest
0 голосов
/ 09 февраля 2012

Мне нужна помощь относительно того, как автоматически обновить StartDate и EndDate для следующего выполнения. В этот момент я вручную добавляю StartDate и EndDate в базу данных sql, и если я не изменил 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);
    }
}    

1 Ответ

1 голос
/ 20 марта 2012

Мне удается сделать это, вызвав другой метод для автоматического обновления моего 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();
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...