예제 #1
0
        private void UpdateCalendar(DateTime dateTime)
        {
            if (dateTime.Day != 1)
            {
                throw new ArgumentException($"{nameof(dateTime)}.Day is {dateTime.Day} but should be 1!");
            }

            // Remove days
            CalendarGrid.Children.Clear();

            // Update month and year label
            MonthLabel.Text = dateTime.ToString("MMMM");
            YearLabel.Text  = dateTime.Year.ToString();

            // Add days
            var dayOfWeek = (int)dateTime.DayOfWeek - 1; // -1 to let the week start on Monday instead of Sunday

            if (dayOfWeek < 0)
            {
                dayOfWeek = 6;
            }

            var daysInMonth = DateTime.DaysInMonth(dateTime.Year, dateTime.Month) + 1;
            var row         = 0;

            for (var day = 1; day < daysInMonth; day++)
            {
                var currentDay = dateTime.AddDays(day - 1);
                var isInRange  = currentDay >= RangeFrom.Date && currentDay <= RangeUntil.Date;

                var dayButton = new Button
                {
                    Text = day.ToString(),
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    BackgroundColor   = Color.White,
                };

                //오늘 버튼 표시
                if (DateTime.Now.Year == currentDay.Year && DateTime.Now.Month == currentDay.Month && DateTime.Now.Day == currentDay.Day)
                {
                    FocusButton = dayButton;
                    FocusButton.BackgroundColor = Color.Red;
                }

                dayButton.Clicked += delegate {
                    if (FocusButton != null)
                    {
                        FocusButton.BackgroundColor = Color.White;
                    }

                    FocusButton = dayButton;
                    FocusButton.BackgroundColor = Color.Red;

                    ScheduleGrid.IsVisible = true;

                    ScheduleView.Clear();
                    SchedueListView.ItemsSource = scheduleView;

                    foreach (var data in SQLLiteDB.ReadUserScheduleData())
                    {
                        if (dateTime.Year == data.Time.Year && dateTime.Month == data.Time.Month && Convert.ToInt16(dayButton.Text) == data.Time.Day)
                        {
                            scheduleView.Add(new ScheduleViewItem {
                                Display = Helper.DateTimeToShortTime(data.Time) + " " + data.Message, Id = data.Id
                            });
                        }
                    }
                };

                if (_shouldShowRange && isInRange)
                {
                    dayButton.BackgroundColor = Color.Red;
                }

                CalendarGrid.Children.Add(dayButton, dayOfWeek, row);

                dayOfWeek += 1;

                // Begin new row
                if (dayOfWeek > 6)
                {
                    dayOfWeek = 0;
                    row++;
                }
            }
        }