Exemplo n.º 1
0
        /// <summary>
        /// When the user flips the month on the calendar to move to the next or previous months
        /// we'll need to add in the views for the previous and next months of the new month navigated
        /// to
        /// </summary>
        /// <param name="sender">The Selector in the flipview</param>
        /// <param name="e">Args passed in</param>
        private void CalendarFlip_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // to stop from recursing
            if (_changingSelection)
            {
                return;
            }

            CalendarMonth selectedMonth = (sender as Selector).SelectedItem as CalendarMonth;

            // if we just set the itemsSource there was nothing selected
            if (selectedMonth == null)
            {
                return;
            }

            // get the current datetime object
            DateTime dt = new DateTime(selectedMonth.Year, selectedMonth.Month, 1);

            // add next month and last month
            AddMonthToCal(dt.AddMonths(1).Year, dt.AddMonths(1).Month);
            AddMonthToCal(dt.AddMonths(-1).Year, dt.AddMonths(-1).Month);

            CalendarFlip.SelectedItem = selectedMonth;
            CalendarFlip.UpdateLayout();

            // change the month
            MonthName.Text = dt.ToString("MMM") + " " + dt.Year.ToString();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add the period data to a specific calendar month
        /// </summary>
        /// <param name="p">The most recent period information present</param>
        /// <param name="cm">The calendar month to add to</param>
        private void Add_Period_To_Calendar(Period p, CalendarMonth cm)
        {
            // for fertility dates
            foreach (DateTime fDate in p.AllFertilityDates)
            {
                if (cm.ContainsDay(fDate.Year, fDate.Month, fDate.Day))
                {
                    cm.SetDayColor(fDate.Year, fDate.Month, fDate.Day, Utilities.Helpers.Colors.Green);
                    cm.SetDayText(fDate.Year, fDate.Month, fDate.Day, "Fertility");
                }
            }

            // for the Periods
            foreach (DateTime pDate in p.AllPeriodDates.Keys)
            {
                if (cm.ContainsDay(pDate.Year, pDate.Month, pDate.Day))
                {
                    cm.SetDayColor(pDate.Year, pDate.Month, pDate.Day, Utilities.Helpers.Colors.Red);
                    cm.SetDayText(pDate.Year, pDate.Month, pDate.Day, "Period");
                }
            }

            // for ovulation dates
            foreach (DateTime oDate in p.AllOvulationDates)
            {
                if (cm.ContainsDay(oDate.Year, oDate.Month, oDate.Day))
                {
                    cm.SetDayColor(oDate.Year, oDate.Month, oDate.Day, Utilities.Helpers.Colors.Blue);
                    cm.SetDayText(oDate.Year, oDate.Month, oDate.Day, "Ovulation");
                }
            }
        }
Exemplo n.º 3
0
        private void PeriodListSnapped_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                DateTime nav = ((DateTime)((e.ClickedItem as Viewbox).DataContext));
                CalculateDateDifference dateDiff;

                // if the month has NOT already been loaded, load into memory
                if (!isMonthLoaded(nav.Year, nav.Month))
                {
                    // since this is specific to months in the future we only need to see
                    // where it is relative to our last month
                    DateTime last = new DateTime(_allMonths.Last().Year, _allMonths.Last().Month, 1);

                    // get the difference
                    dateDiff = new CalculateDateDifference(last, nav);

                    // now add all the months to the flipview
                    for (int i = 0; i < dateDiff.Months; i++)
                    {
                        last = last.AddMonths(1);
                        AddMonthToCal(last.Year, last.Month);
                    }
                }

                // now that it's loaded, navigate to it

                // first determine which month we're at
                CalendarMonth curMonth = (CalendarFlip.SelectedItem as CalendarMonth);
                DateTime      curDate  = new DateTime(curMonth.Year, curMonth.Month, 1);

                // then determine how many months we need to move (not specific to forward or back)
                dateDiff = new CalculateDateDifference(curDate, nav);

                // then determine if the current month is ahead or behind where we need to go
                int compare = curMonth.Compare(nav.Year, nav.Month);

                // if we're trying to navigate to the current month we're at... gtfo
                if (compare == 0)
                {
                    return;
                }
                else if (compare > 0) // the current month is further than where we want to nav... go back
                {
                    CalendarFlip.SelectedIndex -= dateDiff.Months;
                }
                else // the navigation point is further than where we're at... go forward
                {
                    CalendarFlip.SelectedIndex += dateDiff.Months;
                }
            }
            catch { }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _allMonths  = new ObservableCollection <CalendarMonth>();
            _allPeriods = new Dictionary <DateTime, Period>();


            // add this month
            _thisMonth = AddMonthToCal(DateTime.Today.Year, DateTime.Today.Month);
            CalendarFlip.ItemsSource   = _allMonths.ToArray();
            CalendarFlip.SelectedIndex = 1;

            // Load sate
            LoadState();

            // Populate the snapped list
            Add_FuturePeriodsToList(PeriodListSnapped);

            // set viewstate handler
            //Window.Current.SizeChanged += Current_SizeChanged;
            this.SizeChanged += Current_SizeChangedUAP;

            // init calc view
            MainPage_ViewStateChanged();

            // set colors for the snapped view text
            PeriodSnappedText.Foreground    = Utilities.Helpers.GetBrush(Utilities.Helpers.Colors.Red);
            OvulationSnappedText.Foreground = Utilities.Helpers.GetBrush(Utilities.Helpers.Colors.Blue);
            FertileSnappedText.Foreground   = Utilities.Helpers.GetBrush(Utilities.Helpers.Colors.Green);

            //TBD:SettingsPane.GetForCurrentView().CommandsRequested += Settings_CommandsRequested;

            // show help
            Utilities.Common.ShowHelp.ShowHelpMessage(App.Apps.PCalendar);

            // show up comming period information
            ShowNextPeriod();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Add a single month to the UI and underlying calendar
        /// </summary>
        /// <param name="Year">The current Year as int</param>
        /// <param name="Month">The current Month as int</param>
        /// <returns>True if the add was successfull, false if the month already existed in the list</returns>
        private CalendarMonth AddMonthToCal(int Year, int Month)
        {
            bool          toFront     = false;
            CalendarMonth returnMonth = null;

            // determine if this month should go in the front or back
            // we always assume the caller has given us either the next
            // or previous month... we do no validation
            if (_allMonths == null || _allMonths.Count == 0)
            {
                toFront = false;
            }
            else
            {
                CalendarMonth first = _allMonths[0];

                if (first.Compare(Year, Month) > 0)
                {
                    toFront = true;
                }
                else
                {
                    toFront = false;
                }
            }

            if (toFront)
            {
                // figure out how much time from today to this value "in the past"
                TimeSpan ts = DateTime.Today - new DateTime(Year, Month, 1);

                // if it's too far back don't add it
                if (Math.Abs(ts.Days) > Period.DAYS_IN_YEAR * Period.YEARS_BACK)
                {
                    return(returnMonth);
                }
            }
            else
            {
                // figure out how much time from today to this value "in the past"
                TimeSpan ts = DateTime.Today - new DateTime(Year, Month, 1);

                // if it's too far back don't add it
                if (Math.Abs(ts.Days) > Period.DAYS_IN_YEAR * Period.YEARS_FORWARD)
                {
                    return(returnMonth);
                }
            }


            // if this month isn't already loaded, add it
            if (!isMonthLoaded(Year, Month))
            {
                CalendarMonth cm = new CalendarMonth(Year, Month);

                // ensure the proper colors are added to it with the
                // most recent period
                if (mostRecentPeriod != null)
                {
                    Add_Period_To_Calendar(mostRecentPeriod, cm);
                }

                // ensure the calendar is appropriate to the current
                // view mode (snapped vs normal)
                if (App.isSnapped())
                {
                    cm.SnapView();
                }

                if (toFront)
                {
                    _allMonths.Insert(0, cm);
                }
                else
                {
                    _allMonths.Add(cm);
                }

                _changingSelection       = true;
                CalendarFlip.ItemsSource = _allMonths;
                _changingSelection       = false;

                returnMonth = cm;
            }

            return(returnMonth);
        }