private void LoadChecks(DateTime currentDate) { AppointmentGenerator generator = new AppointmentGenerator(); DateTime lastMonth = currentDate.AddMonths(-1); DateTime nextMonth = currentDate.AddMonths(1); YearMonthInfo forLastMonth = CreateSearchParameter(lastMonth); YearMonthInfo forCurrentMonth = CreateSearchParameter(currentDate); YearMonthInfo forNextMonth = CreateSearchParameter(nextMonth); _checksInLastMonth = _checkRepository.GetChecksByMonth(forLastMonth); _checksInThisMonth = _checkRepository.GetChecksByMonth(forCurrentMonth); _checksInNextMonth = _checkRepository.GetChecksByMonth(forNextMonth); _allChecks = new List <Check>(); _allChecks.AddRange(_checksInLastMonth); _allChecks.AddRange(_checksInThisMonth); _allChecks.AddRange(_checksInNextMonth); List <Check> checksWithFlag = ApplyCheckFlagQuery(); List <AppointmentCheck> allAppointments = generator.CreateAppointmentObjects(checksWithFlag); ScheduleView.AppointmentsSource = allAppointments; ScheduleView.Commit(); ScheduleView.SelectedAppointment = null; }
private YearMonthInfo CreateSearchParameter(DateTime currentDate) { YearMonthInfo i = new YearMonthInfo(); i.Year = currentDate.Year; i.Month = currentDate.Month; i.ShouldFilterByStatus = false; Bank selectedBank = BankComboBox.SelectedValue as Bank; Department selectedDept = DepartmentComboBox.SelectedValue as Department; if (selectedDept.Name == "All") { i.ShouldFilterByDepartment = false; } else { i.ShouldFilterByDepartment = true; i.DepartmentId = selectedDept.Id; } if (selectedBank == null || selectedBank.BankName == "All") { i.ShouldFilterByBank = false; } else { i.ShouldFilterByBank = true; i.BankId = selectedBank.Id; } return(i); }
public List <Check> GetChecksByMonth(YearMonthInfo paramInfo) { IQueryable <Check> query = _context.Checks; if (paramInfo.ShouldFilterByDepartment) { query = query.Where(c => c.Bank.Department.Id == paramInfo.DepartmentId); } if (paramInfo.ShouldFilterByBank) { query = query.Where(c => c.Bank.Id == paramInfo.BankId); } query = query.Where( c => (c.DateIssued.HasValue && c.HoldDate.HasValue == false && c.DateIssued.Value.Year == paramInfo.Year && c.DateIssued.Value.Month == paramInfo.Month) || (c.HoldDate.HasValue && c.HoldDate.Value.Year == paramInfo.Year && c.HoldDate.Value.Month == paramInfo.Month)); //query = ApplyCheckFlagQuery(query, paramInfo); return(query.ToList()); }
public static int HowManyDaysFromNow(string fileName, out YearMonthInfo logDate) { int howManyDaysFromNow = 0; fileName = Path.GetFileName(fileName.Replace('/', '\\')); logDate = null; if (String.IsNullOrEmpty(fileName)) { throw new Exception(String.Format("wrong file name: '{0}'", fileName)); } string[] parts = fileName.Split('-'); if (3 == parts.Length) { if (parts[0].StartsWith("updater")) { parts[0] = parts[0].Replace("updater", String.Empty); } if (!int.TryParse(parts[0], out int year)) { throw new Exception(String.Format("wrong year in name : '{0}'", fileName)); } if (!int.TryParse(parts[1], out int month)) { throw new Exception(String.Format("wrong month in name : '{0}'", fileName)); } var index = parts[2].IndexOf('.'); var tmp = parts[2].Substring(0, index); if (!int.TryParse(tmp, out int day)) { throw new Exception(String.Format("wrong month in name : '{0}'", fileName)); } logDate = new YearMonthInfo(year, month); var parsedDate = new DateTime(year, month, day); var dateDiff = DateTime.Now - parsedDate.Date; howManyDaysFromNow = dateDiff.Days; } else { throw new Exception(String.Format("wrong file name format : '{0}'", fileName)); } return(howManyDaysFromNow); }
public void YearMonthInfo_Test() { YearMonthInfo ymi = new YearMonthInfo(2011, 3); Assert.AreEqual("2011-03", ymi.ToString()); }