private List <Task> QueryTasks(List <Task> allData, string FromDate, string ToDate, List <string> Organizations, DateTime fromElapsedTime, DateTime toElapsedTime, List <string> usedTimes, bool APSHours) { List <Task> queriedData = allData; List <bool> toRemove = new List <bool>(); foreach (Task t in allData) { toRemove.Add(false); } //Filter by APS Hours #region APS Hours Utilized if (APSHours) { for (int i = 0; i < queriedData.Count; i++) { if (!toRemove[i]) { if (!queriedData[i].APS) { toRemove[i] = true; } } } } #endregion //Filter by Date #region Date Filter if (FromDate != "" && ToDate != "") { for (int i = 0; i < queriedData.Count; i++) { if (queriedData[i].Date == null || queriedData[i].Date.Trim() == "") { toRemove[i] = true; } } } if (FromDate == "") { FromDate = TaskTracker.GetFirstDay(days).Date; } if (ToDate == "") { ToDate = TaskTracker.GetLastDay(days).Date; } bool sameDate = (FromDate == ToDate ? true : false); if (sameDate) { for (int i = 0; i < queriedData.Count; i++) { if (!toRemove[i] && queriedData[i].Date != null && queriedData[i].Date != "") { if (DateTime.Parse(FromDate).CompareTo(DateTime.Parse(DateTime.Parse(queriedData[i].Date).ToShortDateString())) != 0) { toRemove[i] = true; } } } } else { for (int i = 0; i < queriedData.Count; i++) { if (!toRemove[i] && queriedData[i].Date != null && queriedData[i].Date != "") { DateTime taskDate = DateTime.Parse(DateTime.Parse(queriedData[i].Date).ToShortDateString()); if (DateTime.Parse(FromDate).CompareTo(taskDate) > 0 || DateTime.Parse(ToDate).CompareTo(taskDate) < 0) { toRemove[i] = true; } } } } #endregion //Filter by Organization #region Org Filter if (Organizations.Count > 0) { for (int i = 0; i < queriedData.Count; i++) { if (!toRemove[i]) { bool remove = true; foreach (string s in Organizations) { if (!queriedData[i].IssueNumber.ToLower().Replace(s.ToLower(), "").Equals(queriedData[i].IssueNumber.ToLower())) { remove = false; } } if (remove) { toRemove[i] = true; } } } } #endregion //Filter by Elapsed Time #region Elapsed Filter if (fromElapsedTime != DateTime.MinValue && toElapsedTime != DateTime.MinValue) { for (int i = 0; i < queriedData.Count; i++) { if (queriedData[i].ElapsedTime == null || queriedData[i].ElapsedTime == "") { toRemove[i] = true; } if (!toRemove[i] && queriedData[i].ElapsedTime != null && queriedData[i].ElapsedTime != "") { int[] elapsed = TaskTracker.ParseTime(queriedData[i].ElapsedTime); int[] from = TaskTracker.ParseTime(fromElapsedTime.ToLongTimeString().Replace(" AM", "").Replace(" PM", "")); if (!fromElapsedTime.ToLongTimeString().Replace(" AM", "").Equals(fromElapsedTime.ToLongDateString()) && from[0] == 12) { from[0] = 0; } if (elapsed[0] < from[0]) { toRemove[i] = true; } else if (elapsed[0] == from[0]) { if (elapsed[1] < from[1]) { toRemove[i] = true; } else if (elapsed[1] == from[1]) { if (elapsed[2] < from[2]) { toRemove[i] = true; } } } if (!toRemove[i]) { int[] to = TaskTracker.ParseTime(toElapsedTime.ToLongTimeString().Replace(" AM", "").Replace(" PM", "")); if (!toElapsedTime.ToLongTimeString().Replace(" AM", "").Equals(toElapsedTime.ToLongDateString()) && to[0] == 12) { to[0] = 0; } if (elapsed[0] > to[0]) { toRemove[i] = true; } else if (elapsed[0] == to[0]) { if (elapsed[1] > to[1]) { toRemove[i] = true; } else if (elapsed[1] == to[1]) { if (elapsed[2] > to[2]) { toRemove[i] = true; } else if (elapsed[2] == to[2] && elapsed[3] > 0) { toRemove[i] = true; } } } } } } } #endregion //Filter by Used Time #region Used Time Filter if (usedTimes.Count > 0) { for (int i = 0; i < queriedData.Count; i++) { if (!toRemove[i]) { bool remove = true; foreach (string s in usedTimes) { if (queriedData[i].TimeUsed.Trim().Equals(s.Trim())) { remove = false; } } if (remove) { toRemove[i] = true; } } } } #endregion for (int i = queriedData.Count - 1; i >= 0; i--) { if (toRemove[i]) { queriedData.RemoveAt(i); } } return(queriedData); }