Exemplo n.º 1
0
		public WeekControl(DayControl[] days)
		{
			InitializeComponent();
			Dock = DockStyle.Top;
			Resize += OnResize;

			if (days.Length > 0)
			{
				_dayControls.AddRange(days);
				Controls.AddRange(days);
				_maxWeekDayIndex = _dayControls.Max(x => x.Day.WeekDayIndex);
				if (_maxWeekDayIndex < 7)
				{
					_footer = new WeekEmptySpaceControl();
					Controls.Add(_footer);
				}

				_minWeekDayIndex = _dayControls.Min(x => x.Day.WeekDayIndex);
				if (_maxWeekDayIndex > 1)
				{
					_header = new WeekEmptySpaceControl();
					Controls.Add(_header);
				}
				FitControls();
			}
		}
Exemplo n.º 2
0
		public void AddDays(DayControl[][] weeks)
		{
			_weekControls.Clear();
			foreach (var days in weeks)
			{
				var week = new WeekControl(days);
				_weekControls.Add(week);
				pnData.Controls.Add(week);
				week.BringToFront();
			}
			HasData = true;
		}
        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();
        }
Exemplo n.º 4
0
		public SelectDayEventArgs(DayControl selectedDay, Keys modifierKeys)
		{
			SelectedDay = selectedDay;
			ModifierKeys = modifierKeys;
		}
 public SelectDayEventArgs(DayControl selectedDay, Keys modifierKeys)
 {
     SelectedDay  = selectedDay;
     ModifierKeys = modifierKeys;
 }
Exemplo n.º 6
0
		public void ChangeMonth(DateTime date)
		{
			MonthControl month = null;

			SelectionManager.ClearSelection();
			pnMain.Controls.Clear();
			CopyPasteManager.ResetCopy();
			foreach (var existedMonth in Months.Values)
				existedMonth.RaiseEvents(false);

			var calendarMonth = Calendar.CalendarContent.Months.FirstOrDefault(x => x.Date.Equals(date));
			if (calendarMonth == null) return;
			if (Months.ContainsKey(date))
			{
				month = Months[date];
				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.CalendarContent.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.GetImageFormClipboard();
									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));
			}
			if (month == null) return;
			if (!pnMain.Controls.Contains(month))
			{
				pnMain.Controls.Add(month);
			}
			month.BringToFront();
			month.RaiseEvents(true);
		}