Example #1
0
        /// <summary>
        /// Remove the menstruation by any of it egestion day.
        /// </summary>
        /// <param name="date">Day of egestion.</param>
        /// <returns>True if successfully removed the menstruation cycle.</returns>
        public bool RemoveMenstruationDay(DateTime date)
        {
            if (!this.Menstruations.IsMenstruationDay(date))
            {
                return(false);
            }

            MenstruationPeriod removedPeriod = this.Menstruations.GetPeriodByDate(date);

            if (this.Menstruations.Remove(date))
            {
                if (removedPeriod.HasPregnancy)
                {
                    MenstruationPeriod period = this.Menstruations.GetClosestPeriodBeforeDay(date);
                    if (period != null)
                    {
                        period.HasPregnancy = true;
                    }
                }

                this.AveragePeriodLength = this.Menstruations.CalculateAveragePeriodLength();
                return(true);
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Remove a pregnancy by its any date.
        /// </summary>
        /// <param name="date">Date of pregnancy period.</param>
        /// <returns>True if remover; otherwise false.</returns>
        public bool RemovePregnancy(DateTime date)
        {
            MenstruationPeriod period = this.Menstruations.GetClosestPeriodBeforeDay(date);

            if (period != null)
            {
                period.HasPregnancy = false;
            }

            return(this.Conceptions.RemoveByDate(date));
        }
Example #3
0
        /// <summary>
        /// Create copy of itself.
        /// </summary>
        /// <returns>The object copy.</returns>
        public object Clone()
        {
            var copy = new MenstruationPeriod()
            {
                Egestas       = this.Egestas.Clone() as EgestasCollection,
                HasPregnancy  = this.HasPregnancy,
                ovulationDate = this.ovulationDate,
                StartDay      = this.StartDay
            };

            return(copy);
        }
Example #4
0
        private void LoadForm()
        {
            Text = date.ToLongDateString();

            Woman w = Program.CurrentWoman;

            MenstruationPeriod period = w.Menstruations.GetPeriodByDate(date);

            if (period != null)
            {
                mensesEditControl.Length = period.Length;
                int egesta = period.Egestas[date];
                mensesEditControl.EgestaSliderValue = egesta;
                chkMentrustions.Checked             = true;
                chkMentrustions.Enabled             = period.StartDay == date;
            }
            else
            {
                chkMentrustions.Checked = false;
                chkMentrustions.Enabled = true;
            }

            var schedules = w.Schedules.GetFiredSchedulesForDay(date);

            if (schedules.Count > 0)
            {
                chkSchedules.Checked = true;
                editScheduleControl.SetSchedules(schedules);
            }
            else
            {
                chkSchedules.Checked = false;
            }

            dayEditControl.BBT = w.BBT.GetBBTString(date);

            string note = w.Notes[date];

            dayEditControl.Note = (!note.Contains("\r\n")) ? note.Replace("\n", "\r\n") : note;

            dayEditControl.HadSex = w.HadSexList[date];

            dayEditControl.Health = w.Health[date];

            dayEditControl.CurrentCF = w.CFs[date];

            editScheduleControl.InitialDate = date;

            initialData = CollectDayData();
        }
Example #5
0
        private bool SaveData()
        {
            Woman w = Program.CurrentWoman;

            if (chkMentrustions.Checked)
            {
                MenstruationPeriod period = w.Menstruations.GetPeriodByDate(date);
                if (period == null)
                {     // this is new period user want to add
                    if (!Program.CurrentWoman.Menstruations.Add(date, mensesEditControl.Length))
                    { // nothing was saved for now, let's quit.
                        return(false);
                    }
                    Program.CurrentWoman.Menstruations.SetEgesta(date, mensesEditControl.EgestaSliderValue);
                }
                else
                {
                    w.Menstruations.SetPeriodLength(period, mensesEditControl.Length);
                    period.Egestas[date] = mensesEditControl.EgestaSliderValue;
                }
            }
            else
            {
                w.Menstruations.Remove(date);
            }

            w.BBT.SetBBT(date, dayEditControl.BBT);

            w.Notes[date] = dayEditControl.Note;

            w.HadSexList[date] = dayEditControl.HadSex;

            w.Health[date] = dayEditControl.Health;

            w.CFs[date] = dayEditControl.CurrentCF;

            w.Menstruations.ResetOvulyationsDates();

            w.Schedules.UpdateData(editScheduleControl.GetAllSchedules());

            Program.ApplicationForm.UpdateDayInformationIfFocused(date);
            Program.ApplicationForm.RedrawCalendar(); // redraw whole calendar

            return(true);
        }
Example #6
0
        /// <summary>
        /// Check if the day is predicted as no-conceive day.
        /// </summary>
        /// <param name="date">Day to check.</param>
        /// <returns>True if it is safe to have sex that day.</returns>
        public bool IsPredictedAsSafeSexDay(DateTime date)
        {
            if (this.Menstruations.Count == 0)
            {
                return(false);
            }

            MenstruationPeriod lastPeriod = this.Menstruations.Last;

            if (date <= lastPeriod.StartDay.AddDays(this.DefaultMenstruationLength))
            {
                return(false);
            }

            int daysBetween = (date - lastPeriod.StartDay).Days % this.ManualPeriodLength;

            return((daysBetween >= (this.ManualPeriodLength - 5) && daysBetween <= (this.ManualPeriodLength + 4)) || (daysBetween <= 4));
        }
Example #7
0
        protected void InitializePeriodList()
        {
            MenstruationPeriod selectMe = null;
            var current = Program.CurrentWoman.Menstruations.GetPeriodByDate(initialMonth);

            if (current != null)
            {
                selectMe = current;
            }
            else
            {
                var before     = Program.CurrentWoman.Menstruations.GetClosestPeriodBeforeDay(initialMonth);
                var after      = Program.CurrentWoman.Menstruations.GetClosestPeriodAfterDay(initialMonth);
                int beforeDays = before == null ? int.MaxValue : (initialMonth - before.StartDay).Days;
                int afterDays  = after == null ? int.MaxValue : (after.StartDay - initialMonth).Days;
                selectMe = (afterDays <= beforeDays) ? after : before;
            }

            int selectIndex = 0;

            for (int i = 0; i < Program.CurrentWoman.Menstruations.Count; i++)
            {
                var p1    = Program.CurrentWoman.Menstruations[i];
                var p2    = i == Program.CurrentWoman.Menstruations.Count - 1 ? null : Program.CurrentWoman.Menstruations[i + 1];
                int days  = p2 == null ? Program.CurrentWoman.ManualPeriodLength : ((p2.StartDay - p1.StartDay).Days);
                var start = p1.StartDay;
                var stop  = p2 == null?p1.StartDay.AddDays(Program.CurrentWoman.ManualPeriodLength) : p2.StartDay.AddDays(-1);

                int index = cmbPeriods.Items.Add(new PeriodDisplayItem(i + 1, start, stop, days));
                if (p1 == selectMe)
                {
                    selectIndex = index;
                }
                else if (p2 == selectMe)
                {
                    selectIndex = index;
                }
            }
            if (cmbPeriods.Items.Count > 0)
            {
                cmbPeriods.SelectedIndex = selectIndex;
            }
        }
Example #8
0
        /// <summary>
        /// Finds the nearest (before or after) ovulation date. This function is necessary to find boy/girl
        /// conception days.
        /// </summary>
        /// <param name="date">Day to search near.</param>
        /// <returns>The ovulation date vlosest to the givem date.</returns>
        public DateTime GetClosestOvulationDay(DateTime date)
        {
            if (this.Menstruations.Count == 0)
            {
                throw new InvalidOperationException("No menstruations. The method call prohibited.");
            }

            MenstruationPeriod lastPeriod  = this.Menstruations.Last;
            MenstruationPeriod firstPeriod = this.Menstruations.First;

            if (this.Menstruations.Count != 1 && date < lastPeriod.StartDay && date > firstPeriod.StartDay)
            { // the ov. date is already calculated. Let's return it.
                MenstruationPeriod resultPeriodBefore = null;
                MenstruationPeriod resultPeriodAfter  = null;
                foreach (MenstruationPeriod period in this.Menstruations)
                {
                    if (period.StartDay < date && (resultPeriodBefore == null || period.StartDay > resultPeriodBefore.StartDay))
                    {
                        resultPeriodBefore = period;
                    }

                    if (period.StartDay >= date && (resultPeriodAfter == null || period.StartDay < resultPeriodAfter.StartDay))
                    {
                        resultPeriodAfter = period;
                    }
                }

                return(resultPeriodBefore.GetOvulationDate(this));
            }

            // We are trying to get ovulation of the day without any menstruation near.
            int      cycles            = (date - lastPeriod.StartDay).Days / this.ManualPeriodLength;
            DateTime lastCycleFirstDay = lastPeriod.StartDay.AddDays((cycles + 1) * this.ManualPeriodLength);

            return(this.OvDetector.EstimateOvulationDate(lastCycleFirstDay));
        }
Example #9
0
        /// <summary>
        /// Create the string which is shown to user as the full day description. May have lots of text.
        /// </summary>
        /// <param name="date">The day to describe.</param>
        /// <returns>The day descruption.</returns>
        public string GenerateDayInfo(DateTime date)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(TEXT.Get["Date_double_colon"]);
            sb.Append(date.ToShortDateString());
            if (date == DateTime.Today)
            {
                sb.Append(TEXT.Get["Today_parentheses"]);
            }

            MenstruationPeriod period = this.Menstruations.GetPeriodByDate(date);

            if (period != null)
            {
                sb.AppendLine();
                sb.AppendLine(TEXT.Get.Format("This_is_N_menstr_day", (date - period.StartDay).Days + 1));
                sb.Append(EgestasCollection.EgestasNames[period.Egestas[date]]);
            }

            if (this.IsPregnancyDay(date))
            {
                sb.AppendLine();

                int week = this.Conceptions.GetPregnancyWeekNumber(date);
                if (week > 0)
                {
                    sb.AppendLine(TEXT.Get.Format("Preg_week_number_N", week));
                }

                if (this.IsConceptionDay(date))
                {
                    sb.AppendLine(TEXT.Get["Conception_day"]);
                }

                var      concPeriod     = this.Conceptions.GetConceptionByDate(date);
                DateTime conceptionDate = concPeriod.StartDay;
                DateTime dateOfBirth    = conceptionDate.AddDays(ConceptionPeriod.StandardLength);
                sb.AppendLine(TEXT.Get.Format("Probable_birth_date", dateOfBirth.ToLongDateString()));
                sb.Append(TEXT.Get.Format("Zodiac_will_be", HoroscopDatePair.GetZodiacSignName(dateOfBirth)));

                string gender = string.Empty;
                if (this.IsPredictedAsBoyDay(concPeriod.StartDay))
                {
                    gender = TEXT.Get["Boy"];
                }
                else if (this.IsPredictedAsGirlDay(concPeriod.StartDay))
                {
                    gender = TEXT.Get["Girl"];
                }

                if (!string.IsNullOrEmpty(gender))
                {
                    sb.AppendLine();
                    sb.Append(TEXT.Get.Format("Child_gender_will_be", gender));
                }
            }
            else
            {
                var closestBefore = this.Menstruations.GetClosestPeriodBeforeDay(date);
                if (closestBefore != null && period == null)
                {
                    sb.AppendLine();
                    sb.Append(TEXT.Get.Format("Cycle_day_number_N", ((date - closestBefore.StartDay).Days + 1).ToString()));
                }

                var closestAfter = this.Menstruations.GetClosestPeriodAfterDay(date);
                closestBefore = this.Menstruations.GetClosestPeriodBeforeDay(date.AddDays(1));
                if (closestBefore != null && closestAfter != null)
                {
                    int days = (closestAfter.StartDay - closestBefore.StartDay).Days;
                    sb.AppendLine();
                    sb.Append(TEXT.Get.Format("Cycle_length_days", days.ToString(), TEXT.GetDaysString(days)));
                }

                if (this.IsPredictedAsMenstruationDay(date))
                {
                    sb.AppendLine();
                    sb.Append(TEXT.Get["Possible_menst"]);
                }

                if (this.IsPredictedAsOvulationDay(date))
                {
                    sb.AppendLine();
                    sb.Append(TEXT.Get["Estimated_ovulation_day"]);
                }

                string gender = string.Empty;
                if (this.IsPredictedAsBoyDay(date))
                {
                    sb.AppendLine();
                    sb.Append(TEXT.Get["Boy_conception_day"]);
                }
                else if (this.IsPredictedAsGirlDay(date))
                {
                    sb.AppendLine();
                    sb.Append(TEXT.Get["Girl_conception_day"]);
                }

                if (this.HadSexList.ContainsKey(date))
                {
                    DateTime dateOfBirth = date.AddDays(ConceptionPeriod.StandardLength);
                    sb.AppendLine();
                    sb.Append(TEXT.Get.Format(
                                  "If_conceive_info",
                                  dateOfBirth.ToLongDateString(),
                                  HoroscopDatePair.GetZodiacSignName(dateOfBirth)));
                }
            }

            // got to be last
            string text;

            if (this.Notes.TryGetValue(date, out text))
            {
                sb.AppendLine();
                sb.Append(TEXT.Get["Note_semicolon"]);
                sb.Append(text);
            }

            return(sb.ToString());
        }
Example #10
0
        /// <summary>
        /// Try to add pregnancy. Asks user any questions he has to be asked.
        /// </summary>
        /// <param name="date">The clicked day.</param>
        /// <returns>True if added. Otherwise false.</returns>
        public bool AddConceptionDay(DateTime date)
        {
            if (!this.Conceptions.IsPregnancyDay(date))
            {
                if (date > DateTime.Today)
                {
                    if (!MsgBox.YesNo(
                            TEXT.Get["Future_pregnancy_day"] + TEXT.Get["Are_you_sure_capital"],
                            TEXT.Get["What_a_situation"]))
                    {
                        return(false);
                    }
                }

                ConceptionPeriod concPeriod = this.Conceptions.GetConceptionAfterDate(date);
                if (concPeriod != null && (concPeriod.StartDay - date).Days <= ConceptionPeriod.StandardLength)
                {
                    MsgBox.YesNo(
                        TEXT.Get.Format("Already_pregnant_after", (concPeriod.StartDay - date).Days.ToString()),
                        TEXT.Get["No_no_no"]);
                    return(false);
                }

                MenstruationPeriod nextMenses = this.Menstruations.GetClosestPeriodAfterDay(date);
                if (nextMenses != null)
                {
                    if (!MsgBox.YesNo(
                            TEXT.Get["Have_menses_after_pregn"] + TEXT.Get["Are_you_sure_capital"],
                            TEXT.Get["What_a_situation"]))
                    {
                        return(false);
                    }
                }

                MenstruationPeriod prevMenses = this.Menstruations.GetPeriodByDate(date);
                if (prevMenses != null)
                {
                    if (!MsgBox.YesNo(
                            TEXT.Get["Pregn_on_menses"] + TEXT.Get["Are_you_sure_capital"],
                            TEXT.Get["What_a_situation"]))
                    {
                        return(false);
                    }
                }
                else
                {
                    prevMenses = this.Menstruations.GetClosestPeriodBeforeDay(date);
                }

                if (prevMenses != null && Math.Abs((date - prevMenses.LastDay).Days) <= this.ManualPeriodLength)
                { // The pregnancy must start from last cycle start.
                  // Also we must be sure is was not so long time ago since last cycle.
                    prevMenses.HasPregnancy = true;
                    return(this.Conceptions.Add(prevMenses.StartDay));
                }
                else
                {
                    return(this.Conceptions.Add(date));
                }
            }

            return(false);
        }