Ejemplo n.º 1
0
        /// <summary>
        /// Ask the woman for her password.
        /// </summary>
        /// <param name="woman">The woman to ask. Also stores credentials.</param>
        /// <returns>True if authetification succeded.</returns>
        public static bool AskPassword(Woman woman)
        {
            LoginForm form = new LoginForm();

            form.Text = woman.Name + ", " + form.Text;
            while (true)
            {
                if (form.ShowDialog() != DialogResult.OK)
                {
                    break;
                }

                if (form.Password != woman.Password)
                {
                    if (!MsgBox.YesNo(TEXT.Get["Wrong_password_question"], TEXT.Get["Error"]))
                    {
                        break;
                    }
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draw the control.
        /// </summary>
        /// <param name="pe">Draing event arguments.</param>
        protected override void OnPaint(PaintEventArgs pe)
        {
            this.Font = this.Enabled ? fontBold : fontNormal;

            if (!this.Enabled)
            {
                this.DrawDisabled(pe);
            }
            else
            {
                if (!this.ManualDrawOptions)
                {
                    Woman w = Program.CurrentWoman;
                    this.Egesta                       = w.Menstruations.GetEgestaAmount(this.Date);
                    this.IsFocusDay                   = this.OwnerOneMonthControl != null && this == this.OwnerOneMonthControl.FocusDay;
                    this.IsTodayDay                   = this.Date == DateTime.Today;
                    this.IsPregnancyDay               = w.IsPregnancyDay(this.Date);
                    this.PregnancyWeek                = w.Conceptions.GetPregnancyWeekNumberWhenFirstWeekDay(this.Date);
                    this.IsMenstruationDay            = !this.IsPregnancyDay && w.Menstruations.IsMenstruationDay(this.Date);
                    this.IsPredictedAsOvulationDay    = !this.IsPregnancyDay && w.IsPredictedAsOvulationDay(this.Date);
                    this.IsPredictedAsSafeSexDay      = !this.IsPregnancyDay && w.IsPredictedAsSafeSexDay(this.Date);
                    this.IsHaveNote                   = w.Notes.ContainsKey(this.Date);
                    this.IsPredictedAsBoyDay          = !this.IsPregnancyDay && w.IsPredictedAsBoyDay(this.Date);
                    this.IsPredictedAsGirlDay         = !this.IsPregnancyDay && w.IsPredictedAsGirlDay(this.Date);
                    this.IsPredictedAsMenstruationDay = !this.IsPregnancyDay && w.IsPredictedAsMenstruationDay(this.Date);
                    this.IsConceptionDay              = w.IsConceptionDay(this.Date);
                    this.IsHadSex                     = w.HadSexList.ContainsKey(this.Date);
                    this.IsAScheduleFired             = w.Schedules.HasAFiredSchedule(this.Date);
                }

                this.DrawEnabled(pe);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Check if two women data is the same. Used to determine if any changes were done to woman data.
        /// </summary>
        /// <param name="obj">Object to compare with.</param>
        /// <returns>True if women data are same.</returns>
        public override bool Equals(object obj)
        {
            if (!(obj is Woman))
            {
                return(false);
            }

            Woman w = obj as Woman;

            bool equal = true;

            equal &= w.AllwaysAskPassword.Equals(this.AllwaysAskPassword);
            equal &= w.AveragePeriodLength.Equals(this.AveragePeriodLength);
            equal &= w.BBT.Equals(this.BBT);
            equal &= w.CFs.Equals(this.CFs);
            equal &= w.Conceptions.Equals(this.Conceptions);
            equal &= w.DefaultMenstruationLength.Equals(this.DefaultMenstruationLength);
            equal &= w.HadSexList.Equals(this.HadSexList);
            equal &= w.Health.Equals(this.Health);
            equal &= w.ManualPeriodLength.Equals(this.ManualPeriodLength);
            equal &= w.Menstruations.Equals(this.Menstruations);
            equal &= w.Name.Equals(this.Name);
            equal &= w.Notes.Equals(this.Notes);
            equal &= w.Password.Equals(this.Password);
            equal &= w.UseManualPeriodLength.Equals(this.UseManualPeriodLength);

            return(equal);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Read the woman from a file and creates the woman object.
        /// </summary>
        /// <param name="path">Path to the woman file.</param>
        /// <returns>Newly loaded woman object.</returns>
        public static Woman ReadFrom(string path)
        {
            Woman w  = null;
            var   fs = new FileStream(path, FileMode.Open);

            try
            {
                var s = new BZip2InputStream(fs);
                w = (Woman) new XmlSerializer(typeof(Woman)).Deserialize(s);
                s.Close();
            }
            catch (BZip2Exception)
            { // old file type support
                fs.Seek(0, SeekOrigin.Begin);
                w = (Woman) new XmlSerializer(typeof(Woman)).Deserialize(fs);
            }
            finally
            {
                fs.Close();
            }

            if (w == null)
            {
                return(null);
            }

            w.AssociatedFile = path;
            return(w);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create the object.
        /// </summary>
        /// <param name="w">The data to use.</param>
        public OvulationDetector(Woman w)
        {
            if (w == null)
            {
                throw new ArgumentNullException("Woman must be specified.", "w");
            }

            this.woman = w;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Saves current woman to the given file path. Synch all necessary 'current' static variables.
        /// </summary>
        /// <param name="path">Path to the new/overwritten file.</param>
        /// <returns>True if file successfully saved.</returns>
        public static bool SaveCurrentWomanTo(string path)
        {
            if (SaveWomanTo(currentWoman, path))
            {
                currentWoman.AssociatedFile = path;
                currentWomanClone           = currentWoman.Clone() as Woman;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Detect and return the ovulation day.
        /// </summary>
        /// <param name="w">The current woman we are working with.</param>
        /// <returns>Predicted ovulation day.</returns>
        public DateTime GetOvulationDate(Woman w)
        {
            if (this.ovulationDate == default(DateTime))
            {
                var      period2            = w.Menstruations.GetClosestPeriodAfterDay(this.StartDay.AddDays(1));
                DateTime nextPeriodFirstDat = period2 == null?this.StartDay.AddDays(w.ManualPeriodLength) : period2.StartDay;

                this.ovulationDate = w.OvDetector.EstimateOvulationDate(nextPeriodFirstDat);
            }

            return(this.ovulationDate);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads woman from the given file. Interfacts with user if needed. Set the current woman to the data just read.
        /// </summary>
        /// <param name="path">The path to the owman file.</param>
        /// <returns>False if the file was not loaded.</returns>
        public static bool LoadWoman(string path)
        {
            Woman w = Woman.ReadFrom(path);

            if (w == null || (w.AllwaysAskPassword && !AskPassword(w)))
            {
                return(false);
            }

            CurrentWoman = w;
            return(true);
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Generate the object from the given woman and the date.
 /// </summary>
 /// <param name="w">Woman to use.</param>
 /// <param name="day">The date of the future data.</param>
 /// <returns>Day info data.</returns>
 public static OneDayInfo GetByDate(Woman w, DateTime day)
 {
     return(new OneDayInfo()
     {
         Date = day,
         IsMentruation = w.Menstruations.IsMenstruationDay(day),
         Egesta = w.Menstruations.GetEgestaAmount(day),
         IsOvulation = w.IsPredictedAsOvulationDay(day),
         HadSex = w.HadSexList[day],
         BBT = w.BBT.GetBBT(day),
         Health = w.Health[day],
         CF = w.CFs[day],
         Note = w.Notes[day],
     });
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Saves a woman to the given path.
        /// </summary>
        /// <param name="w">Woman to save.</param>
        /// <param name="path"><Path to the new/overwritten file./param>
        /// <returns>True if file successfully saved.</returns>
        public static bool SaveWomanTo(Woman w, string path)
        {
            try
            {
                // Serialize to memory stream to make sure data is serializable.
                var saveMemoryStream   = new MemoryStream();
                var testSaveDataStream = new BZip2OutputStream(saveMemoryStream, 9);

                // Make sure serialization goes well.
                new XmlSerializer(w.GetType()).Serialize(testSaveDataStream, w);
                testSaveDataStream.Close();
                var data = saveMemoryStream.ToArray();

                testSaveDataStream.Close();

                // Dispose resources.
                saveMemoryStream.Dispose();
                testSaveDataStream.Dispose();

                // Prepare to read the saved data.
                var loadMemoryStream   = new MemoryStream(data);
                var testLoadDataStream = new BZip2InputStream(loadMemoryStream);

                // Make sure we can read it back.
                new XmlSerializer(typeof(Woman)).Deserialize(testLoadDataStream);
                testLoadDataStream.Close();

                // Dispose resources.
                loadMemoryStream.Dispose();
                testLoadDataStream.Dispose();

                // Make sure we have access to the file system.
                var filestream = new FileStream(path, FileMode.Create);

                // Save to file.
                filestream.Write(data, 0, data.Length);
                filestream.Close();
            }
            catch (Exception ex)
            {
                MsgBox.Error(TEXT.Get["Unable_to_save_file"] + ex.Message, TEXT.Get["Error"]);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Create the full copy of the woman object.
        /// </summary>
        /// <returns>Fully copied woman.</returns>
        public object Clone()
        {
            var w = new Woman();

            w.AllwaysAskPassword  = this.AllwaysAskPassword;
            w.AssociatedFile      = this.AssociatedFile;
            w.averagePeriodLength = this.averagePeriodLength;
            w.BBT         = this.BBT.Clone() as BBTCollection;
            w.CFs         = this.CFs.Clone() as CFCollection;
            w.Conceptions = this.Conceptions.Clone() as ConceptionsCollection;
            w.DefaultMenstruationLength = this.DefaultMenstruationLength;
            w.HadSexList         = this.HadSexList.Clone() as HadSexCollection;
            w.Health             = this.Health.Clone() as HealthCollection;
            w.ManualPeriodLength = this.ManualPeriodLength;
            w.Menstruations      = this.Menstruations.Clone() as MenstruationsCollection;
            w.Name     = this.Name;
            w.Notes    = this.Notes.Clone() as NotesCollection;
            w.Password = this.Password;
            w.UseManualPeriodLength = this.UseManualPeriodLength;
            return(w);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Make an attempt to leave current woman and create a new one.
        /// </summary>
        /// <returns>Truye if new woman was created and applied.</returns>
        public static bool NewWoman()
        {
            if (AskAndSaveCurrentWoman())
            {
                NewEditWomanForm form = new NewEditWomanForm();
                if (form.ShowDialog() == DialogResult.OK)
                {
                    Woman w = new Woman();
                    w.Name     = form.WomanName;
                    w.Password = form.WomanPassword;
                    if (!string.IsNullOrEmpty(w.Password))
                    {
                        w.AllwaysAskPassword = true;
                    }

                    CurrentWoman = w;
                    return(true);
                }
            }

            return(false);
        }