2012-02-09 11 views
0

次の実行のためにStartDateとEndDateを自動更新する方法については、私は助けが必要です。現時点では、SQLデータベースにStartDateとEndDateを手動で追加していますが、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); 
    } 
}  

答えて

1

私は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(); 
    } 
関連する問題