示例#1
0
        private void BuildCalendarUI()
        {
            int iDaysInMonth = sysCal.GetDaysInMonth(_DisplayStartDate.Year, _DisplayStartDate.Month);
            int iOffsetDays  = Convert.ToInt32(System.Enum.ToObject(typeof(System.DayOfWeek), _DisplayStartDate.DayOfWeek));
            int iWeekCount   = 0;
            WeekOfDaysControl weekRowCtrl = new WeekOfDaysControl();

            MonthViewGrid.Children.Clear();
            AddRowsToMonthGrid(iDaysInMonth, iOffsetDays);
            MonthYearLabel.Content = (new DateTimeFormatInfo()).GetMonthName(_DisplayMonth) + " " + _DisplayYear;
            //CultureInfo.CurrentUICulture.DateTimeFormat.MonthNames[i]

            for (int i = 1; i <= iDaysInMonth; i++)
            {
                if ((i != 1) && System.Math.IEEERemainder((i + iOffsetDays - 1), 7) == 0)
                {
                    //-- add existing weekrowcontrol to the monthgrid
                    Grid.SetRow(weekRowCtrl, iWeekCount);
                    MonthViewGrid.Children.Add(weekRowCtrl);
                    //-- make a new weekrowcontrol
                    weekRowCtrl = new WeekOfDaysControl();
                    iWeekCount += 1;
                }

                //-- load each weekrow with a DayBoxControl whose label is set to day number
                DayBoxControl dayBox = new DayBoxControl();
                dayBox.DayNumberLabel.Content = i.ToString();
                dayBox.Tag = i;
                dayBox.MouseDoubleClick += DayBox_DoubleClick;

                //-- customize daybox for today:
                if ((new System.DateTime(_DisplayYear, _DisplayMonth, i)) == System.DateTime.Today)
                {
                    dayBox.DayLabelRowBorder.Background    = (Brush)dayBox.TryFindResource("OrangeGradientBrush");
                    dayBox.DayAppointmentsStack.Background = Brushes.Wheat;
                }

                //-- for design mode, add appointments to random days for show...
                if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
                {
                    if (Math.Round(1d) < 0.25)
                    {
                        DayBoxAppointmentControl apt = new DayBoxAppointmentControl();
                        apt.DisplayText.Text = "Apt on " + i + "th";
                        dayBox.DayAppointmentsStack.Children.Add(apt);
                    }
                }
                else if (_monthAppointments != null)
                {
                    //-- Compiler warning about unpredictable results if using i (the iterator) in lambda, the
                    //   "hint" suggests declaring another var and set equal to iterator var
                    int iday = i;
                    List <Appointment> aptInDay = _monthAppointments.FindAll(new System.Predicate <Appointment>((Appointment apt) => Convert.ToDateTime(apt.StartTime).Day == iday));
                    foreach (Appointment a in aptInDay)
                    {
                        DayBoxAppointmentControl apt = new DayBoxAppointmentControl();
                        apt.DisplayText.Text = a.Subject;
                        apt.Tag = a.AppointmentID;
                        apt.MouseDoubleClick += Appointment_DoubleClick;
                        dayBox.DayAppointmentsStack.Children.Add(apt);
                    }
                }

                Grid.SetColumn(dayBox, (i - (iWeekCount * 7)) + iOffsetDays);
                weekRowCtrl.WeekRowGrid.Children.Add(dayBox);
            }
            Grid.SetRow(weekRowCtrl, iWeekCount);
            MonthViewGrid.Children.Add(weekRowCtrl);
        }
        private void BuildCalendarUi()
        {
            int iDaysInMonth = sysCal.GetDaysInMonth(_DisplayStartDate.Year, _DisplayStartDate.Month);
            int iOffsetDays = Convert.ToInt32(Enum.ToObject(typeof(DayOfWeek), _DisplayStartDate.DayOfWeek)) - 1 /* without -1 for US calendar */;
            if (iOffsetDays < 0) iOffsetDays = 6;
            int iWeekCount = 0;
            var weekRowCtrl = new WeekOfDaysControl();

            MonthViewGrid.Children.Clear();
            AddRowsToMonthGrid(iDaysInMonth, iOffsetDays);
            MonthYearLabel.Content = Thread.CurrentThread.CurrentUICulture.DateTimeFormat.GetMonthName(_displayMonth) + " " + _displayYear;

            for (int i = 1; i <= iDaysInMonth; i++) {
                if ((i != 1) && Math.IEEERemainder((i + iOffsetDays - 1), 7) == 0) {
                    //-- add existing weekrowcontrol to the monthgrid
                    Grid.SetRow(weekRowCtrl, iWeekCount);
                    MonthViewGrid.Children.Add(weekRowCtrl);
                    //-- make a new weekrowcontrol
                    weekRowCtrl = new WeekOfDaysControl();
                    iWeekCount++;
                }

                //-- load each weekrow with a DayBoxControl whose label is set to day number
                var dayBox = new DayBoxControl {DayNumberLabel = {Content = i.ToString(CultureInfo.InvariantCulture)}, Tag = i};
                dayBox.MouseDoubleClick += DayBox_DoubleClick;

                //-- customize daybox for today:
                if ((new DateTime(_displayYear, _displayMonth, i)) == DateTime.Today)
                {
                    dayBox.DayLabelRowBorder.Background = (Brush) dayBox.TryFindResource("TodayGradient");
                    dayBox.DayReservationsStack.Background = new SolidColorBrush(Color.FromArgb(87, 188, 206, 125));
                }
                else
                {
                    dayBox.DayReservationsStack.Background = new SolidColorBrush(Color.FromArgb(87, 255, 255, 255));
                }

                //-- for design mode, add reservations to random days for show...
                if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) {
                    if (Math.Round(1d) < 0.25) {
                        var apt = new DayBoxReservationControl {DisplayText = {Text = "Apt on " + i + "th"}};
                        dayBox.DayReservationsStack.Children.Add(apt);
                    }

                }
                else if (MonthReservations != null)
                {
                    //-- Compiler warning about unpredictable results if using i (the iterator) in lambda, the
                    //   "hint" suggests declaring another var and set equal to iterator var
                    int iday = i;
                    var aptInDay = MonthReservations.Where(apt => Convert.ToDateTime(apt.StartTime).Day == iday);
                    foreach (var a in aptInDay) {
                        var apt = new DayBoxReservationControl {DisplayText = {Text = a.Subject}, Tag = a.Ptr};
                        apt.Click += Reservation_Click;
                        dayBox.DayReservationsStack.Children.Add(apt);
                    }
                }

                Grid.SetColumn(dayBox, (i - (iWeekCount * 7)) + iOffsetDays);
                weekRowCtrl.WeekRowGrid.Children.Add(dayBox);
            }
            Grid.SetRow(weekRowCtrl, iWeekCount);
            MonthViewGrid.Children.Add(weekRowCtrl);
        }
        private void BuildCalendarUI()
        {
            int iDaysInMonth = sysCal.GetDaysInMonth(_DisplayStartDate.Year, _DisplayStartDate.Month);
            int iOffsetDays = Convert.ToInt32(System.Enum.ToObject(typeof(System.DayOfWeek), _DisplayStartDate.DayOfWeek));
            int iWeekCount = 0;
            WeekOfDaysControl weekRowCtrl = new WeekOfDaysControl();

            MonthViewGrid.Children.Clear();
            AddRowsToMonthGrid(iDaysInMonth, iOffsetDays);
            MonthYearLabel.Content = (new DateTimeFormatInfo()).GetMonthName(_DisplayMonth) + " " + _DisplayYear;
            //CultureInfo.CurrentUICulture.DateTimeFormat.MonthNames[i]

            for (int i = 1; i <= iDaysInMonth; i++) {
            if ((i != 1) && System.Math.IEEERemainder((i + iOffsetDays - 1), 7) == 0) {
                //-- add existing weekrowcontrol to the monthgrid
                Grid.SetRow(weekRowCtrl, iWeekCount);
                MonthViewGrid.Children.Add(weekRowCtrl);
                //-- make a new weekrowcontrol
                weekRowCtrl = new WeekOfDaysControl();
                iWeekCount += 1;
            }

            //-- load each weekrow with a DayBoxControl whose label is set to day number
            DayBoxControl dayBox = new DayBoxControl();
            dayBox.DayNumberLabel.Content = i.ToString();
            dayBox.Tag = i;
            dayBox.MouseDoubleClick += DayBox_DoubleClick;

            //-- customize daybox for today:
            if ((new System.DateTime(_DisplayYear, _DisplayMonth, i)) == System.DateTime.Today) {
                dayBox.DayLabelRowBorder.Background = (Brush)dayBox.TryFindResource("OrangeGradientBrush");
                dayBox.DayAppointmentsStack.Background = Brushes.Wheat;
            }

            //-- for design mode, add appointments to random days for show...
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) {
                if (Math.Round(1d) < 0.25) {
                    DayBoxAppointmentControl apt = new DayBoxAppointmentControl();
                    apt.DisplayText.Text = "Apt on " + i + "th";
                    dayBox.DayAppointmentsStack.Children.Add(apt);
                }

            } else if (_monthAppointments != null) {
                //-- Compiler warning about unpredictable results if using i (the iterator) in lambda, the
                //   "hint" suggests declaring another var and set equal to iterator var
                int iday = i;
                List<Appointment> aptInDay = _monthAppointments.FindAll(new System.Predicate<Appointment>((Appointment apt) => Convert.ToDateTime(apt.StartTime).Day == iday));
                foreach (Appointment a in aptInDay) {
                    DayBoxAppointmentControl apt = new DayBoxAppointmentControl();
                    apt.DisplayText.Text = a.Subject;
                    apt.Tag = a.AppointmentID;
                    apt.MouseDoubleClick += Appointment_DoubleClick;
                    dayBox.DayAppointmentsStack.Children.Add(apt);
                }

            }

            Grid.SetColumn(dayBox, (i - (iWeekCount * 7)) + iOffsetDays);
            weekRowCtrl.WeekRowGrid.Children.Add(dayBox);
            }
            Grid.SetRow(weekRowCtrl, iWeekCount);
            MonthViewGrid.Children.Add(weekRowCtrl);
        }