public static PeriodCalendar GenerateCalendarData(string cycleDurationSetting, string periodDurationSetting, DateTime lastPeriodDateSetting) { PeriodCalendar generatedCalendar = new PeriodCalendar(); int cycleDuration = Int32.Parse(cycleDurationSetting); int periodDuration = Int32.Parse(periodDurationSetting); DateTime lastCycleDateStart = lastPeriodDateSetting; DateTime startPeriod = lastCycleDateStart; DateTime endPeriod = startPeriod.AddDays(cycleDuration - 1); List<PeriodMonth> pastPeriods = new List<PeriodMonth>(); while (DateTime.Today > startPeriod && DateTime.Today > endPeriod) { PeriodMonth lastMonth = new PeriodMonth(startPeriod, cycleDuration, periodDuration); pastPeriods.Add(lastMonth); startPeriod = startPeriod.AddDays(cycleDuration).AddDays(1); endPeriod = startPeriod.AddDays(cycleDuration - 1); } var currentPeriod = new PeriodMonth(startPeriod, cycleDuration, periodDuration); generatedCalendar.PastPeriods = pastPeriods; generatedCalendar.CurrentPeriod = currentPeriod; return generatedCalendar; }
public static IPeriodsStrategy Create(string description) { IPeriodsStrategy instance = null; instance = PeriodDay.GetInstance(description, instance); instance = PeriodWeek.GetInstance(description, instance); instance = PeriodMonth.GetInstance(description, instance); instance = PeriodYear.GetInstance(description, instance); return(instance); }
protected PeriodBimonthlyIMSS getPeriodBimonthlyIMSS(int month, PeriodMonth periodMonth) { if ((periodMonth == PeriodMonth.Initial || periodMonth == PeriodMonth.Both) && (month % 2 == ODD_NUMBER)) { return(PeriodBimonthlyIMSS.Initial); } else if ((periodMonth == PeriodMonth.Final || periodMonth == PeriodMonth.Both) && (month % 2 == EVEN_NUMBER)) { return(PeriodBimonthlyIMSS.Final); } else { return(PeriodBimonthlyIMSS.None); } }
public static PeriodCalendar MockCalendar() { PeriodCalendar calendar = new PeriodCalendar(); PeriodMonth september = new PeriodMonth(new DateTime(2014, 9, 1), 6, 28); PeriodMonth october = new PeriodMonth(new DateTime(2014, 9, 29), 6, 28); PeriodMonth november = new PeriodMonth(new DateTime(2014, 10, 27), 6, 28); PeriodMonth december = new PeriodMonth(new DateTime(2014, 11, 24), 6, 28); PeriodMonth january = new PeriodMonth(new DateTime(2015, 1, 19), 6, 28); PeriodMonth february = new PeriodMonth(new DateTime(2015, 2, 17), 6, 28); calendar.PastPeriods.Add(september); calendar.PastPeriods.Add(october); calendar.PastPeriods.Add(november); calendar.PastPeriods.Add(december); calendar.PastPeriods.Add(january); // calendar.PastPeriods.Add(february); calendar.CurrentPeriod = february; // calendar.Year = 2014; return calendar; }
public static void AddPillAlarm(PeriodMonth period) { AddOrReplaceAlarm( AppResources.PillAlarmName, AppResources.PillAlarmContent, period.PeriodEndDay.AddDays(1), period.CycleEndDay, RecurrenceInterval.Daily, new Uri("/Reminder/Reminder01.wav", UriKind.Relative)); }
private void SetupCalendarData(PeriodMonth modifiedCurrentPeriod) { var currentStoredPeriod = NextPeriod; var pastPeriods = Calendar.PastPeriods; if (pastPeriods.Contains(currentStoredPeriod)) { PeriodMonth month = pastPeriods.FirstOrDefault(item => item.PeriodStartDay == currentStoredPeriod.PeriodStartDay && item.PeriodEndDay == currentStoredPeriod.PeriodEndDay); month = modifiedCurrentPeriod; } else { if (StartCycleConfirmed && EndCycleConfirmed) { //update existing past period pastPeriods.Add(modifiedCurrentPeriod); Calendar.PastPeriods = pastPeriods; //update current period var currentPeriod = Calendar.FuturePeriods.FirstOrDefault(); //update current period's period&cycle duration currentPeriod.CycleDuration = Calendar.AverageCycleDuration; currentPeriod.PeriodDuration = Calendar.AveragePeriodDuration; Calendar.CurrentPeriod = currentPeriod; ClearCache(); } else { if (StartCycleConfirmed && pastPeriods.Count > 0) { PeriodMonth previousPeriod = pastPeriods[pastPeriods.Count - 1]; //this period started early/ later -> this means the previous period ended early/later if (previousPeriod.CycleEndDay.AddDays(1) != modifiedCurrentPeriod.PeriodStartDay) { previousPeriod.CycleEndDay = modifiedCurrentPeriod.PeriodStartDay.AddDays(-1); previousPeriod.CycleDuration = (previousPeriod.CycleEndDay - previousPeriod.PeriodStartDay).Days + 1; } pastPeriods[pastPeriods.Count - 1] = previousPeriod; } else if (EndCycleConfirmed) { int computedCycleDuration = (modifiedCurrentPeriod.PeriodEndDay - modifiedCurrentPeriod.PeriodStartDay).Days + 1; //this period ended later/earlier -> this means the duration was longer/shorter if (computedCycleDuration != modifiedCurrentPeriod.PeriodDuration) modifiedCurrentPeriod.PeriodDuration = computedCycleDuration; } Calendar.CurrentPeriod = modifiedCurrentPeriod; Calendar.PastPeriods = pastPeriods; } } PersistanceStorage.WriteDataToPersistanceStorage(calendar); }
public void SetupDialog(ValidationEnum validationType, PeriodMonth period) { switch (validationType) { case ValidationEnum.NoNeedForValidation: { if (!StartCycleConfirmed && !EndCycleConfirmed && DateTime.Now >= SelectedStartCycle.AddDays(period.PeriodDuration)) { FirstRowText = AppResources.PeriodStartedQuestion; SecondRowText = string.Empty; ThirdRowText = AppResources.PeriodEndedQuestion; ForthRowText = string.Empty; ShowSelectStartDay = true; ShowSelectEndDay = true; } else if (!StartCycleConfirmed) { FirstRowText = AppResources.PeriodStartedQuestion; ThirdRowText = string.Empty; ForthRowText = string.Empty; ShowSelectStartDay = true; } else { FirstRowText = string.Empty; SecondRowText = string.Empty; if (!EndCycleConfirmed && DateTime.Now >= SelectedStartCycle.AddDays(2)) { if (SelectedEndCycle > DateTime.Today) SelectedEndCycle = DateTime.Today; ThirdRowText = AppResources.PeriodEndedQuestion; ShowSelectEndDay = true; } else { OkButtonContent = string.Empty; CancelButtonContent = string.Empty; ShowDialog = false; break; } } if (ShowSelectStartDay || ShowSelectEndDay) { OkButtonContent = AppResources.OkButton; CancelButtonContent = AppResources.CancelButton; SetDelayedAdvancedCounter(period); } break; } case ValidationEnum.StartDateInFuture: { FirstRowText = AppResources.PeriodStartedQuestion; SecondRowText = AppResources.StartDateInFutureValidation; ShowSelectEndDay = false; ThirdRowText = string.Empty; break; } case ValidationEnum.DateOverlappsExistingPeriod: { FirstRowText = AppResources.PeriodStartedQuestion; SecondRowText = AppResources.OverlapExistingPeriodValidation; OkButtonContent = AppResources.ReplaceButton; CancelButtonContent = AppResources.CancelButton; //enable modify //recall this page break; } case ValidationEnum.EndDateBeforeStart: { OkButtonContent = AppResources.OkButton; CancelButtonContent = AppResources.CancelButton; ForthRowText = AppResources.EndDateBeforeStartValidation; break; } case ValidationEnum.EndDateTooCloseToStart: { OkButtonContent = AppResources.OkButton; CancelButtonContent = AppResources.CancelButton; ForthRowText = AppResources.EndDateTooCloseToStartValidation; break; } case ValidationEnum.EndDateFarInTheFuture: { OkButtonContent = AppResources.OkButton; CancelButtonContent = AppResources.CancelButton; ForthRowText = AppResources.EndDateFarInFutureValidation; break; } } }
public void SetDelayedAdvancedCounter(PeriodMonth currentPeriod) { int counter; DelayedAdvancedStart = 0; DelayedAdvancedEnd = 0; DateTime expectedEndDate = SelectedStartCycle.AddDays(currentPeriod.PeriodDuration - 1); if (ShowSelectStartDay && (SelectedStartCycle < currentPeriod.PeriodStartDay || SelectedStartCycle > currentPeriod.PeriodStartDay)) { counter = (SelectedStartCycle - currentPeriod.PeriodStartDay).Days; DelayedAdvancedStart = Math.Abs(counter); if (counter < 0) SecondRowText = string.Format(AppResources.PeriodEarlierMessage, DelayedAdvancedStart); else if (counter > 0) SecondRowText = string.Format(AppResources.PeriodLaterMessage, DelayedAdvancedStart); } if (ShowSelectEndDay && (SelectedEndCycle < expectedEndDate || SelectedEndCycle > expectedEndDate)) { counter = (SelectedEndCycle - expectedEndDate).Days; DelayedAdvancedEnd = Math.Abs(counter); if (counter < 0) ForthRowText = string.Format(AppResources.PeriodEarlierMessage, DelayedAdvancedEnd); else if (counter > 0) ForthRowText = string.Format(AppResources.PeriodLaterMessage, DelayedAdvancedEnd); } }
public void ReplaceCommand() { PeriodMonth period = new PeriodMonth(SelectedStartCycle, Calendar.AverageCycleDuration, Calendar.AveragePeriodDuration); SelectedEndCycle = SelectedStartCycle.AddDays(Calendar.AveragePeriodDuration - 1); SetupDialog(ValidationEnum.NoNeedForValidation, period); }
private void SetWaveHeigth(PeriodMonth currentPeriod) { double top = 0; //from begining to half of cycle you have 100% if (DateTime.Today >= currentPeriod.PeriodStartDay && DateTime.Today <= currentPeriod.PeriodStartDay.AddDays(currentPeriod.PeriodDuration/2)) top = 0; else //from half cycle to end, decreasing if (DateTime.Today > currentPeriod.PeriodStartDay.AddDays(currentPeriod.PeriodDuration / 2) && DateTime.Today <= currentPeriod.PeriodEndDay) { double totalDaysSpan = (currentPeriod.PeriodEndDay - currentPeriod.PeriodStartDay.AddDays(currentPeriod.PeriodDuration / 2)).Days; double percentage = Math.Round(MAX_HEIGHT / totalDaysSpan); double remaining = (currentPeriod.PeriodEndDay - DateTime.Today).Days +1; top = - percentage * remaining; } else //half duration to start cycle, increasing { double totalDaysSpan = currentPeriod.PeriodDuration / 2; if (DaysToPeriod < totalDaysSpan && DateTime.Today < currentPeriod.PeriodStartDay) { double percentage = Math.Round(MAX_HEIGHT / totalDaysSpan); double remaining = (DateTime.Today- currentPeriod.PeriodStartDay).Days + 1; top = -percentage * (totalDaysSpan - remaining); } } double bottom = -303 - top; TopMarginValue = top; BottomMarginValue = bottom; WavingGridMargins = new Thickness(-40, top, 40, bottom); }
public void SetDropValues(PeriodMonth currentPeriod) { // the current cycle's mestruation hasn't started yet if (DateTime.Today < currentPeriod.PeriodStartDay) { int remainingDays = ((TimeSpan)(currentPeriod.PeriodStartDay - DateTime.Today)).Days; DaysToPeriodText = AppResources.DaysToPeriodText; DaysToPeriod = Math.Abs(remainingDays); } else { // the current cycle's menstruation has ended if (DateTime.Today > currentPeriod.PeriodEndDay) { PeriodMonth nextPeriod = App.MainViewModel.Calendar.FuturePeriods.FirstOrDefault(); int remainingDays = ((TimeSpan)(nextPeriod.PeriodStartDay - DateTime.Today)).Days; DaysToPeriodText = AppResources.DaysToPeriodText; DaysToPeriod = Math.Abs(remainingDays); } else // you are during your current cycle's menstruation if (DateTime.Today >= currentPeriod.PeriodStartDay && DateTime.Today <= currentPeriod.PeriodEndDay) { int daysUntilEndCycle = ((TimeSpan)(currentPeriod.PeriodEndDay - DateTime.Today)).Days + 1; DaysToPeriodText = AppResources.DayOfPeriodText; DaysToPeriod = Math.Abs(daysUntilEndCycle); } } SetWaveHeigth(currentPeriod); }