コード例 #1
0
        private void LoadMonth(MonthControl month)
        {
            SelectionManager.ClearSelection();
            CopyPasteManager.ResetCopy();
            foreach (var existedMonth in xtraTabControl.TabPages.OfType <MonthControl>().ToList())
            {
                existedMonth.RaiseEvents(false);
            }

            var calendarMonth = (CalendarMonth)month.Tag;

            if (!month.HasData)
            {
                var weeks        = new List <DayControl[]>();
                var datesByWeeks = Calendar.CalendarContent.GetDaysByWeek(calendarMonth.DaysRangeBegin, calendarMonth.DaysRangeEnd);
                foreach (var weekDays in datesByWeeks)
                {
                    var week = new List <DayControl>();
                    foreach (var calendarDay in weekDays.Select(weekDay =>
                                                                Calendar.ActiveCalendarSection.Days.FirstOrDefault(x => x.Date.Equals(weekDay))))
                    {
                        if (calendarDay != null)
                        {
                            var dayControl = new DayControl(calendarDay);
                            dayControl.AllowToPasteNote = CopyPasteManager.SourceNote != null;
                            dayControl.DaySelected     += (sender, e) =>
                            {
                                SelectionManager.SelectDay(e.SelectedDay.Day, e.ModifierKeys);
                                CopyPasteManager.SetCopyDay();
                            };
                            dayControl.DayCopied      += (sender, e) => CopyDay();
                            dayControl.DayPasted      += (sender, e) => PasteDay();
                            dayControl.DayCloned      += (sender, e) => CloneDay();
                            dayControl.DayDataDeleted += (sender, e) =>
                            {
                                foreach (var day in SelectionManager.SelectedDays)
                                {
                                    day.ClearData();
                                    RefreshData();
                                }
                                Calendar.SettingsNotSaved = true;
                                Calendar.CalendarView.RefreshData();
                                Calendar.SlideInfo.LoadData();
                                Calendar.UpdateDataManagementAndOutputFunctions();
                            };
                            dayControl.DataChanged += (sender, e) =>
                            {
                                var day = sender as DayControl;
                                if (day == null)
                                {
                                    return;
                                }
                                Calendar.UpdateDataManagementAndOutputFunctions();
                                Calendar.SettingsNotSaved = true;
                            };

                            dayControl.SelectionStateRequested += (sender, e) => SelectionManager.ProcessSelectionStateRequest();
                            dayControl.DayMouseMove            += (sender, e) =>
                            {
                                foreach (var day in _days)
                                {
                                    if (day.Day.BelongsToSchedules && day.ClientRectangle.Contains(day.PointToClient(Cursor.Position)) &&
                                        day.RaiseEvents)
                                    {
                                        SelectionManager.SelectDay(day.Day, Keys.Control);
                                    }
                                }
                            };
                            dayControl.NoteAdded += (sender, e) =>
                            {
                                var noteDateRange = Calendar.CalendarContent
                                                    .CalculateDateRange(SelectionManager.SelectedDays.Select(x => x.Date).ToArray()).LastOrDefault();
                                AddNote(noteDateRange);
                                RefreshData();
                                Calendar.UpdateDataManagementAndOutputFunctions();
                            };
                            dayControl.NotePasted += (sender, e) =>
                            {
                                PasteNote();
                                RefreshData();
                            };
                            dayControl.ImageCopied += (sender, e) => CopyImage();
                            dayControl.ImagePasted += (sender, e) =>
                            {
                                ImageSource imageSource    = null;
                                var         clipboardImage = ClipboardHelper.GetPngFormClipboard();
                                if (clipboardImage != null)
                                {
                                    imageSource = ImageSource.FromImage(clipboardImage);
                                }
                                else if (Clipboard.ContainsText(TextDataFormat.Html))
                                {
                                    var textContent = Clipboard.GetText(TextDataFormat.Html);
                                    try
                                    {
                                        imageSource = ImageSource.FromString(textContent);
                                    }
                                    catch
                                    {
                                    }
                                }
                                PasteImage(imageSource);
                            };
                            dayControl.ImageDeleted += (sender, e) =>
                            {
                                foreach (var day in SelectionManager.SelectedDays)
                                {
                                    day.Logo = new ImageSource();
                                    RefreshData();
                                }
                                Calendar.SettingsNotSaved = true;
                                Calendar.CalendarView.RefreshData();
                                Calendar.UpdateDataManagementAndOutputFunctions();
                            };

                            SelectionManager.SelectionStateResponse += (sender, e) =>
                                                                       dayControl.UpdateNoteMenuAccordingSelection(SelectionManager.SelectedDays.OrderBy(x => x.Date).ToList());

                            CopyPasteManager.CopyDaySet += (sender, e) =>
                            {
                                dayControl.toolStripMenuItemCopy.Enabled  = true;
                                dayControl.toolStripMenuItemClone.Enabled = true;
                            };
                            CopyPasteManager.CopyReset += (sender, e) =>
                            {
                                dayControl.toolStripMenuItemCopy.Enabled  = false;
                                dayControl.toolStripMenuItemClone.Enabled = false;
                                dayControl.ChangeCopySource(false);
                            };
                            CopyPasteManager.PasteReset += (sender, e) =>
                            {
                                dayControl.toolStripMenuItemPaste.Enabled = false;
                                dayControl.AllowToPasteNote = false;
                            };
                            CopyPasteManager.DayCopied += (sender, e) =>
                            {
                                dayControl.toolStripMenuItemPaste.Enabled = true;
                                dayControl.ChangeCopySource(dayControl.Day.Date.Equals(CopyPasteManager.SourceDay.Date));
                            };
                            CopyPasteManager.NoteCopied += (sender, e) => { dayControl.AllowToPasteNote = true; };
                            Calendar.AssignCloseActiveEditorsonOutSideClick(dayControl);
                            week.Add(dayControl);
                            _days.Add(dayControl);
                        }
                        Application.DoEvents();
                    }
                    weeks.Add(week.ToArray());
                    Application.DoEvents();
                }
                month.AddDays(weeks.ToArray());
                month.AddNotes(GetNotesByWeeeks(calendarMonth));
            }
            month.RefreshData(Calendar.GetColorSchema(calendarMonth.OutputData.SlideColor));
            month.RaiseEvents(true);
            month.ResizeControls();
        }