/// <summary>
        /// undo whatever changes we have made
        /// </summary>
        private void OnDescriptionEditCancelButtonClick(object sender, EventArgs e)
        {
            DescriptionPreview.Navigate("about:blank");
            DescriptionPreview.Document.OpenNew(false);
            DescriptionPreview.Document.Write(OldDescription);
            DescriptionPreview.Refresh();

            DescriptionEditWindow.Close();
        }
        private void PopulateFields(string recordName)
        {
            bool bitFlag;

            Model       = new SpellModel();
            DetailModel = new List <SpellDetailsModel>();
            if (recordName != string.Empty)
            {
                Model.Initialize(recordName);
                DetailModel = SpellDetailsModel.GetAll(Model.Id);
            }

            //basic fields
            SpellNameInputBox.Text           = Model.SpellName;
            SpellSchoolComboBox.SelectedItem = SpellSchoolModel.GetNameFromId(Model.SpellSchoolId);
            SpellIconInputBox.Text           = Model.IconFilename;
            DescriptionPreview.Navigate("about:blank");
            DescriptionPreview.Document.OpenNew(false);
            DescriptionPreview.Document.Write(Model.Description);
            DescriptionPreview.Refresh();
            RangeInputComboBox.SelectedItem = Model.SpellRange;
            for (int i = 0; i < ComponentCheckListBox.Items.Count; i++)
            {
                bitFlag = ((Model.SpellComponents & (1 << i)) > 0);
                ComponentCheckListBox.SetItemChecked(i, bitFlag);
            }
            for (int i = 0; i < MetamagicFeatCheckListBox.Items.Count; i++)
            {
                bitFlag = ((Model.MetamagicFeats & (1 << i)) > 0);
                MetamagicFeatCheckListBox.SetItemChecked(i, bitFlag);
            }
            for (int i = 0; i < TargetCheckListBox.Items.Count; i++)
            {
                bitFlag = ((Model.Targets & (1 << i)) > 0);
                TargetCheckListBox.SetItemChecked(i, bitFlag);
            }
            DurationInputTextBox.Text        = Model.Duration;
            SavingThrowComboBox.SelectedItem = Model.SavingThrow;
            if (Model.SpellResistance == true)
            {
                SpellResistanceComboBox.SelectedItem = "Yes";
            }
            else
            {
                SpellResistanceComboBox.SelectedItem = "No";
            }
            ModDateLabel.Text    = Model.LastUpdatedDate.ToString();
            ModVersionLabel.Text = Model.LastUpdatedVersion;
            RecordGUIDLabel.Text = Model.Id.ToString();

            //the icon
            SpellIcon = new IconClass("Spells\\" + Model.IconFilename);
            SpellIcon.SetLocation(this.Width, this.Height, IconLocation);

            //the spell detail panel
            //Delete/Remove Current Controls
            for (int i = 0; i < SpellDetailSubPanel.Controls.Count; i++)
            {
                SpellDetailSubPanel.Controls[i].Dispose();
            }
            SpellDetailSubPanel.Controls.Clear();
            SpellDetailClassComboBox.Clear();
            SpellDetailLevelComboBox.Clear();
            SpellDetailCoolDownTextBox.Clear();
            SpellDetailSPCostUpDownBox.Clear();
            SpellDetailDeleteButton.Clear();
            //reload the panel
            SpellDetailRecordCount = 0;
            foreach (SpellDetailsModel detail in DetailModel)
            {
                AddSpellDetailRecordUI(detail);
            }

            DatabaseName = Model.SpellName;
            //invalidate the screen to make sure everything gets updated (icon, etc).
            Invalidate();
        }
        /// <summary>
        /// for a given selected record, show its data in the appropriate fields
        /// </summary>
        /// <param name="recordName">The name of the record to show</param>
        private void PopulateFields(string recordName)
        {
            string             controlName;
            ComboBox           bonusFeatComboBox;
            FeatTypeModel      featType;
            List <string>      destinyName;
            DestinySphereModel currentDestiny;

            Model.Initialize(recordName);
            //cache the name and abbreviation strings for later comparisons
            DatabaseName           = Model.Name;
            DatabaseAbbreviation   = Model.Abbreviation;
            ClassNameInputBox.Text = Model.Name;
            DescriptionPreview.Navigate("about:blank");
            DescriptionPreview.Document.OpenNew(false);
            DescriptionPreview.Document.Write(Model.Description);
            DescriptionPreview.Refresh();
            HitDieInputBox.Text = Model.HitDie.ToString();
            ClassNameAbbreviationInputBox.Text = Model.Abbreviation;
            SkillPointsInputBox.Text           = Model.SkillPoints.ToString();
            IconNameInputBox.Text = Model.ImageFilename;
            ClassIcon             = new IconClass(Model.ImageFilename);
            ClassIcon.SetLocation(this.Width, this.Height, IconLocation);
            for (int i = 1; i <= Constant.NumHeroicLevels; i++)
            {
                controlName = "FortSaveInputBox" + i;
                Controls[controlName].Text = Model.LevelDetails[i - 1].FortitudeSave.ToString();
                controlName = "ReflexSaveInputBox" + i;
                Controls[controlName].Text = Model.LevelDetails[i - 1].ReflexSave.ToString();
                controlName = "WillSaveInputBox" + i;
                Controls[controlName].Text = Model.LevelDetails[i - 1].WillSave.ToString();
                controlName = "BABInputBox" + i;
                Controls[controlName].Text = Model.LevelDetails[i - 1].BaseAttackBonus.ToString();
                controlName       = "BonusFeatComboBox" + i;
                bonusFeatComboBox = Controls[controlName] as ComboBox;
                if (Model.LevelDetails[i - 1].FeatTypeId == Guid.Empty)
                {
                    bonusFeatComboBox.SelectedIndex = 0;
                }
                else
                {
                    featType = new FeatTypeModel();
                    featType.Initialize(Model.LevelDetails[i - 1].FeatTypeId);
                    bonusFeatComboBox.SelectedIndex = bonusFeatComboBox.FindStringExact(featType.Name);
                }
            }
            AlignmentsAllowedListBox.Items.Clear();
            if (Model.AllowedAlignments != null)
            {
                foreach (AlignmentModel alignment in Model.AllowedAlignments)
                {
                    AlignmentsAllowedListBox.Items.Add(alignment.Name);
                }
            }

            ClassSkillsListBox.Items.Clear();
            if (Model.ClassSkills != null)
            {
                foreach (SkillModel skill in Model.ClassSkills)
                {
                    ClassSkillsListBox.Items.Add(skill.Name);
                }
            }

            RecordGUIDLabel.Text = Model.Id.ToString();
            ModDateLabel.Text    = Model.LastUpdatedDate.ToString();
            ModVersionLabel.Text = Model.LastUpdatedVersion;

            destinyName = DestinySphereModel.GetNames();
            StartingDestinySphereComboBox.Items.Clear();
            foreach (string name in destinyName)
            {
                StartingDestinySphereComboBox.Items.Add(name);
            }

            MaxSpellLevelComboBox.Items.Clear();
            for (int i = 0; i <= 9; i++)
            {
                MaxSpellLevelComboBox.Items.Add(i.ToString());
            }
            MaxSpellLevelComboBox.SelectedIndex = Model.MaxSpellLevel;

            currentDestiny = new DestinySphereModel();
            currentDestiny.Initialize(Model.StartingDestinySphereId);
            StartingDestinySphereComboBox.SelectedIndex = StartingDestinySphereComboBox.FindStringExact(currentDestiny.Name);


            //make sure we haven't changed the data (Populating data from the database doesn't count as a change!)
            DataHasChanged = false;
        }