private static ArrayList GetApplicationsRecursiveSummary(int parentTaskId, DateTime ini, DateTime end) { ArrayList arrayHT = DbHelper.ExecuteGetRows( "SELECT TasksLog.TaskId, Sum(ApplicationsLog.ActiveTime) AS TotalActiveTime, ApplicationsLog.Name, ApplicationsLog.ApplicationFullPath " + "FROM TasksLog INNER JOIN ApplicationsLog ON TasksLog.Id = ApplicationsLog.TaskLogId " + "WHERE TasksLog.Id IN (select TasksLog.Id from TasksLog where TasksLog.TaskId=? and TasksLog.InsertTime>=? and TasksLog.InsertTime<=?) " + "GROUP BY TasksLog.TaskId, ApplicationsLog.Name, ApplicationsLog.ApplicationFullPath", new string[] { "TaskId", "InsertTime1", "InsertTime2" }, new object[] { parentTaskId, ini, end }); ArrayList tempDataset = new ArrayList(); foreach (IDictionary dictionary in arrayHT) { ApplicationSummary appSum = new ApplicationSummary(); appSum.TaskId = (int)dictionary["TaskId"]; appSum.TotalActiveTime = (double)dictionary["TotalActiveTime"]; appSum.Name = (string)dictionary["Name"]; appSum.ApplicationFullPath = (string)dictionary["ApplicationFullPath"]; tempDataset.Add(appSum); } //foreach ArrayList appSumaryList = MergeApplicationSummaryLists(new ArrayList(), tempDataset); Task[] childRows; childRows = Tasks.GetChildTasks(parentTaskId); foreach (Task childRow in childRows) { appSumaryList = MergeApplicationSummaryLists(appSumaryList, GetApplicationsRecursiveSummary(childRow.Id, ini, end)); } //foreach return(appSumaryList); } //GetApplicationsRecursiveSummary
public static DateRange GetTaskLogDateRange(int taskId) { Queue queue = new Queue(); queue.Enqueue(taskId); DateRange range; range.StartDate = DateTime.MaxValue; range.EndDate = DateTime.MinValue; while (queue.Count > 0) { int curTaskId = (int)queue.Dequeue(); Task[] childs; childs = Tasks.GetChildTasks(curTaskId); foreach (Task child in childs) { if (child.Id != Tasks.IdleTask.Id) { queue.Enqueue(child.Id); } } object retValue = DbHelper.ExecuteScalar("Select Min(InsertTime) From TasksLog Where TaskId = ?", new string[] { "TaskId" }, new object[] { curTaskId }); if (retValue == null || retValue == DBNull.Value) { continue; } DateTime curStartTime = (DateTime)retValue; DateTime curEndTime = (DateTime)DbHelper.ExecuteScalar("Select Max(InsertTime) From TasksLog Where TaskId = ?", new string[] { "TaskId" }, new object[] { curTaskId }); if (curStartTime < range.StartDate) { range.StartDate = curStartTime; } if (curEndTime > range.EndDate) { range.EndDate = curEndTime; } } return(range); }