/// <summary>
        /// throws ApplicationException if config file corrupt
        /// </summary>
        public bool UpdateHoliday( string oldName, Holiday toAdd )
        {
            if( toAdd.Name != oldName &&
                HolidayElementFromName( toAdd.Name ).Count() > 0 )
                return false;

            IEnumerable<XElement> elementsToEdit = HolidayElementFromName( oldName );
            if( elementsToEdit.Count() != 1 )
                throw new ApplicationException( "Config file corrupted" );

            elementsToEdit.First().ReplaceWith( toAdd.ToXml() );
            this.Save();
            return true;
        }
示例#2
0
        private void SaveHoliday( object sender, EventArgs e )
        {
            if (HolidayName.Text == "")
            {
                MessageBox.Show("The holiday must have a name");
                return;
            }

            DateTime LastDay = JustDate( HolidayLastDay.Value );
            DateTime FirstDay = JustDate( HolidayFirstDay.Value );
            if( LastDay < FirstDay ) {
                MessageBox.Show( @"The first day of the holiday must be before or on the same day
                    as the last day of the holiday." );
                return;
            }

            Holiday toAdd = new Holiday( HolidayName.Text, FirstDay, LastDay );

            Holiday old = null;
            if( isEdit ) old = ( Holiday )HolidayList.SelectedItem;
            if( isEdit ? !config.UpdateHoliday( old.Name, toAdd )
                       : !config.AddHoliday( toAdd ) ) {
                MessageBox.Show( @"That name is already in use. Either select that holiday in the list
                    above and edit it or choose a name for this holiday." );
                HolidayName.Focus();
                return;
            }

            AddEditHoliday.Enabled = false;
            LoadHolidayList();
            if( isEdit ) CurrentHolidayList.Items.Clear();
        }
        /// <summary>
        /// Returns whether the name conflicts
        /// </summary>
        public bool AddHoliday( Holiday h )
        {
            if( HolidayElementFromName( h.Name ).Count() > 0 )
                return false;

            theDoc.Root.Element( "holidays" ).Add( h.ToXml() );
            this.Save();

            return true;
        }