private void ParseEventSetting()
        {
            string           eventName;
            int              rank;
            DateTime         beginningTime      = DateTime.MinValue;
            Queue <DateTime> beginningTimeQueue = new Queue <DateTime>();
            TimeSpan         duration           = TimeSpan.Zero;
            bool             autoDelete         = (chkAutoDelete.IsChecked == true) ? true : false;
            bool             thisDayForwardOnly = (chkThisDayForwardOnly.IsChecked == true) ? true : false;

            // EventName
            if (reEscChars.IsMatch(txtEventName.Text))
            {
                throw new Exception("Event name shoud not contain the following charaters: \\/:*?\"<>|");
            }
            eventName = txtEventName.Text.TrimEnd(' ');
            if (eventName.Length == 0)
            {
                throw new Exception("Event name should not be space.");
            }

            // Rank
            if (!reDigitOnly.IsMatch(txtRank.Text))
            {
                throw new Exception("Given value of \"Rank\" is invalid, it should contains digits only.");
            }
            rank = int.Parse(txtRank.Text);

            // Beginning time
            List <DateTime> dtList = new List <DateTime>();

            dtList.Add(dateTimePicker.Value.Value);
            foreach (Grid gd in spTimePickerList.Children)
            {
                TimePicker tp = gd.FindChild <TimePicker>();
                if (tp == null)
                {
                    continue;
                }

                // Get time component only (although formate of timePicker has been set as `DateTimeFormat.LongTime`,
                // we still have to prevent illegal input)
                DateTime dt = dateTimePicker.Value.Value.Date;  // get date only
                dtList.Add(dt.Add(tp.Value.Value.TimeOfDay));
            }

            dtList.Sort();
            foreach (DateTime dt in dtList)
            {
                beginningTimeQueue.Enqueue(dt);
            }

            // Duration
            if (chkSetDuration.IsChecked == true)
            {
                duration = timeSpanUpDown.Value.Value;
            }

            // Set recurring frequency
            RecurringFrequencies recurringFreq = 0;

            if (cmbRecurringFreq.SelectedItem.ToString() == RecurringFrequencies.Custom.ToString())
            {
                recurringFreq = ConvertBlocksToRecurringFreq();
            }
            else
            {
                recurringFreq = (RecurringFrequencies)cmbRecurringFreq.SelectedItem;
            }

            if (cmbTrackIndex.SelectedIndex == -1)
            {
                throw new Exception("No track is avalible in this playlist");
            }

            MultiTriggerEvent evnt = new MultiTriggerEvent(beginningTimeQueue)
            {
                EventText           = eventName,
                Rank                = rank,
                Duration            = duration,
                AutoDelete          = autoDelete,
                ThisDayForwardOnly  = thisDayForwardOnly,
                Enabled             = true, // let user set this while creating event?
                RecurringFrequency  = recurringFreq,
                IgnoreTimeComponent = true,
                ReadOnlyEvent       = false
            };

            evnt.ActionStartsEventArgs = new SchedulerEventArgs
            {
                PlaylistGUID = (cmbPlaylist.SelectedItem as Playlist).GUID,
                Command      = PlaybackCommands.Play,
                Mode         = (PlaybackMode)cmbPlaybackMode.SelectedItem,
                TrackIndex   = (int)cmbTrackIndex.SelectedItem
            };

            evnt.ActionEndsEventArgs = new SchedulerEventArgs
            {
                Command = PlaybackCommands.Stop
            };

            if (WindowMode == DisplayMode.Create)
            {
                NewEventIsCreatedEvent(evnt);
            }
            else if (WindowMode == DisplayMode.Edit)
            {
                evnt.CloneTo(evntToBeUpdated);
                UpdateEvent(evntToBeUpdated);
            }
        }
        public void ShowEventSetting <T>(T evnt, DisplayMode mode) where T : class, IEvent
        {
            WindowMode        = mode;
            IsReadOnly        = (mode == DisplayMode.ShowInfo) ? true : false;
            evntToBeUpdated   = (mode == DisplayMode.Edit) ? evnt as T : null;
            txtEventName.Text = evnt.EventText;
            txtRank.Text      = evnt.Rank.ToString();

            // beginning time
            if (evnt.GetType().Equals(typeof(CustomEvent)))
            {
                dateTimePicker.Value = evnt.BeginningTime;
            }
            else if (evnt.GetType().Equals(typeof(MultiTriggerEvent)))
            {
                MultiTriggerEvent mte = evnt as MultiTriggerEvent;
                dateTimePicker.Value = mte.BeginningTimeQueue.Peek();
                for (int i = 1; i < mte.BeginningTimeQueue.Count; i++)
                {
                    Button     btn;
                    TimePicker tp;
                    ChangeMarginOfTimePickerContainer(true);
                    CreateTimePickerGroup(mte.BeginningTimeQueue.ElementAt(i), out btn, out tp);
                    btn.IsEnabled = !IsReadOnly;
                    tp.IsEnabled  = !IsReadOnly;
                }
            }

            timeSpanUpDown.Value     = evnt.Duration;
            chkSetDuration.IsChecked = (evnt.Duration == TimeSpan.Zero) ? false : true;

            // Recurring frequency
            if (Enum.GetValues(typeof(RecurringFrequencies)).Contains <RecurringFrequencies>(evnt.RecurringFrequency))
            {
                cmbRecurringFreq.SelectedItem = evnt.RecurringFrequency;
            }
            else
            {
                cmbRecurringFreq.SelectedItem = RecurringFrequencies.Custom;
                ConvertRecurringFreqToBlocks(evnt.RecurringFrequency);
            }

            gridRecurringDate.IsEnabled     = IsReadOnly ? false : true;
            chkAutoDelete.IsChecked         = evnt.AutoDelete;
            chkThisDayForwardOnly.IsChecked = evnt.ThisDayForwardOnly;

            // Settings of playback
            SchedulerEventArgs actionArgs = evnt.ActionStartsEventArgs as SchedulerEventArgs;

            cmbPlaylist.SelectedItem = cmbPlaylist.Items.OfType <Playlist>().ToList().Find(x => x.GUID == actionArgs.PlaylistGUID);
            // NOTICE: mode should be set first, because it affects the item source of `cmbTrackIndex`
            cmbPlaybackMode.SelectedItem = actionArgs.Mode;
            cmbTrackIndex.SelectedItem   = actionArgs.TrackIndex;

            if (IsReadOnly)
            {
                foreach (Control ctrl in controlList)
                {
                    ctrl.IsEnabled = false;
                }
            }
        }