private void NewEventButton_Click(object sender, RoutedEventArgs e)
        {
            Event       EventToAdd     = new Event();
            EventWindow NewEventWindow = new EventWindow(EventToAdd);

            NewEventWindow.Owner = this;
            NewEventWindow.ShowDialog();

            if (EventToAdd.IsActive == true)
            {
                CopyBuffer.Clear();
                CopyBuffer.Add(new Event()
                {
                    Hours = EventToAdd.Hours, Minutes = EventToAdd.Minutes, RelayState = EventToAdd.RelayState, IsActive = true
                });
                PasteEvent();
                CopyBuffer.Clear();
            }
        }
        private void EditEventButton_Click(object sender, RoutedEventArgs e)
        {
            if (Events.SelectedItems.Count == 1)
            {
                Event EventToEdit  = new Event();
                Event EventLastSet = new Event();
                EventToEdit.Hours       = Days[CurrentDay][Events.SelectedIndex].Hours;
                EventToEdit.Minutes     = Days[CurrentDay][Events.SelectedIndex].Minutes;
                EventToEdit.RelayState  = Days[CurrentDay][Events.SelectedIndex].RelayState;
                EventToEdit.IsActive    = true;
                EventLastSet.Hours      = Days[CurrentDay][Events.SelectedIndex].Hours;
                EventLastSet.Minutes    = Days[CurrentDay][Events.SelectedIndex].Minutes;
                EventLastSet.RelayState = Days[CurrentDay][Events.SelectedIndex].RelayState;
                EventLastSet.IsActive   = true;
                EventWindow NewEventWindow = new EventWindow(EventToEdit);
                NewEventWindow.Owner = this;
                NewEventWindow.ShowDialog();

                if (EventToEdit.IsActive == true)
                {
                    if ((Days[CurrentDay][Events.SelectedIndex].Hours == EventToEdit.Hours) &&
                        (Days[CurrentDay][Events.SelectedIndex].Minutes == EventToEdit.Minutes))
                    {
                        Days[CurrentDay][Events.SelectedIndex].RelayState = EventToEdit.RelayState;
                    }

                    else
                    {
                        int NewItemIndex = -1;
                        int ItemIndex    = Events.SelectedIndex;

                        Days[CurrentDay].RemoveAt(Events.SelectedIndex);

                        foreach (Event EventToComp in Days[CurrentDay])
                        {
                            if ((EventToEdit.Hours < EventToComp.Hours) ||
                                ((EventToEdit.Hours == EventToComp.Hours) && (EventToEdit.Minutes < EventToComp.Minutes)))
                            {
                                NewItemIndex = Days[CurrentDay].IndexOf(EventToComp);
                                break;
                            }

                            else if ((EventToEdit.Hours == EventToComp.Hours) && (EventToEdit.Minutes == EventToComp.Minutes))
                            {
                                NewItemIndex = EVENTS_MAX;
                                break;
                            }
                        }

                        if ((NewItemIndex >= 0) && (NewItemIndex < EVENTS_MAX))
                        {
                            Days[CurrentDay].Insert(NewItemIndex, new Event()
                            {
                                Hours = EventToEdit.Hours, Minutes = EventToEdit.Minutes, RelayState = EventToEdit.RelayState, IsActive = true
                            });
                        }

                        else if (NewItemIndex == EVENTS_MAX)
                        {
                            CopyBuffer.Clear();
                            CopyBuffer.Add(new Event()
                            {
                                Hours = EventToEdit.Hours, Minutes = EventToEdit.Minutes, RelayState = EventToEdit.RelayState, IsActive = true
                            });
                            if (PasteEvent() == -1)
                            {
                                Days[CurrentDay].Insert(ItemIndex, new Event()
                                {
                                    Hours = EventLastSet.Hours, Minutes = EventLastSet.Minutes, RelayState = EventLastSet.RelayState, IsActive = true
                                });
                            }
                            CopyBuffer.Clear();
                        }

                        else
                        {
                            Days[CurrentDay].Add(new Event()
                            {
                                Hours = EventToEdit.Hours, Minutes = EventToEdit.Minutes, RelayState = EventToEdit.RelayState, IsActive = true
                            });
                        }
                    }
                }
            }
        }