private void PopulateRankFields()
        {
            int rankCount;
            int enhancementIndex;

            enhancementIndex = EnhancementIconListControl.SelectedIndex;
            rankCount        = RankModels[enhancementIndex].Count;

            //lets reset what tabs are shown based on number of ranks
            tabControl1.TabPages.Remove(tpRank2);
            tabControl1.TabPages.Remove(tpRank3);
            tabControl1.TabPages.Remove(tpNewRank);


            //Rank 1 data
            RankDescriptionHE1.Text = RankModels[enhancementIndex][0].Description;
            RankRequirementsRP1.Clear();
            RankRequirementsRP1.RecordId = RankModels[enhancementIndex][0].Id;
            RankRequirementsRP1.Initialize();
            RankModifiersMP1.Clear();
            RankModifiersMP1.RecordId = RankModels[enhancementIndex][0].Id;
            RankModifiersMP1.Initialize();

            //Rank 2 data
            if (rankCount > 1)
            {
                tabControl1.TabPages.Add(tpRank2);
                RankDescriptionHE2.Text = RankModels[enhancementIndex][1].Description;
                RankRequirementsRP2.Clear();
                RankRequirementsRP2.RecordId = RankModels[enhancementIndex][1].Id;
                RankRequirementsRP2.Initialize();
                RankModifiersMP2.Clear();
                RankModifiersMP2.RecordId = RankModels[enhancementIndex][1].Id;
                RankModifiersMP2.Initialize();
            }

            //Rank 3 data
            if (rankCount == 3)
            {
                tabControl1.TabPages.Add(tpRank3);
                RankDescriptionHE3.Text = RankModels[enhancementIndex][2].Description;
                RankRequirementsRP3.Clear();
                RankRequirementsRP3.RecordId = RankModels[enhancementIndex][2].Id;
                RankRequirementsRP3.Initialize();
                RankModifiersMP3.Clear();
                RankModifiersMP3.RecordId = RankModels[enhancementIndex][2].Id;
                RankModifiersMP3.Initialize();
            }
            if (rankCount < 3)
            {
                tabControl1.TabPages.Add(tpNewRank);
            }
        }
 private void tabControl1_MouseClick(object sender, MouseEventArgs e)
 {
     for (int i = 0; i < tabControl1.TabCount; i++)
     {
         if (tabControl1.GetTabRect(i).Contains(e.Location))
         {
             if (tabControl1.TabPages[i] == tpNewRank)
             {
                 //we need to add a new rank model for this tab
                 AddRankModel(EnhancementIconListControl.SelectedIndex);
                 if (i == 1)
                 {
                     //tabControl1.TabPages.Insert(i, tpRank2);
                     //tabControl1.TabPages.Add(tpRank2);
                     tabControl1.TabPages.Insert(i, tpRank2);
                     tabControl1.SelectedTab = tpRank2;
                     RankDescriptionHE2.Text = "test2";
                     RankRequirementsRP2.Clear();
                     RankRequirementsRP2.RecordId = RankModels[EnhancementIconListControl.SelectedIndex][1].Id;
                     RankRequirementsRP2.Initialize();
                     RankModifiersMP2.Clear();
                     RankModifiersMP2.RecordId = RankModels[EnhancementIconListControl.SelectedIndex][1].Id;
                     RankModifiersMP2.Initialize();
                 }
                 if (i == 2)
                 {
                     tabControl1.TabPages.Insert(i, tpRank3);
                     tabControl1.TabPages.Remove(tpNewRank);
                     tabControl1.SelectedTab = tpRank3;
                     RankDescriptionHE3.Text = "Test3";
                     RankRequirementsRP3.Clear();
                     RankRequirementsRP3.RecordId = RankModels[EnhancementIconListControl.SelectedIndex][2].Id;
                     RankRequirementsRP3.Initialize();
                     RankModifiersMP3.Clear();
                     RankModifiersMP3.RecordId = RankModels[EnhancementIconListControl.SelectedIndex][2].Id;
                     RankModifiersMP3.Initialize();
                 }
             }
         }
     }
 }
        private void CopyPreviousRank(int previousRank)
        {
            List <EnhancementRankRequirementModel> newRankRequirements;
            List <EnhancementRankModifierModel>    newRankModifiers;
            List <EnhancementRankRequirementModel> deleteRankRequirements;
            List <EnhancementRankModifierModel>    deleteRankModifiers;

            newRankRequirements    = new List <EnhancementRankRequirementModel>();
            newRankModifiers       = new List <EnhancementRankModifierModel>();
            deleteRankRequirements = new List <EnhancementRankRequirementModel>();
            deleteRankModifiers    = new List <EnhancementRankModifierModel>();

            //We need to save any changes to the enhancement record before doing any copying.
            if (HasDataChanged() == true)
            {
                SaveSlotRecord();
                SaveRecord();
            }

            //Lets delete the records for the current rank requirements and modifiers.
            deleteRankRequirements = EnhancementRankRequirementModel.GetAll(RankModels[EnhancementIndexLoaded][previousRank].Id);
            foreach (EnhancementRankRequirementModel deleteRequirement in deleteRankRequirements)
            {
                deleteRequirement.Delete();
            }
            deleteRankModifiers = EnhancementRankModifierModel.GetAll(RankModels[EnhancementIndexLoaded][previousRank].Id);
            foreach (EnhancementRankModifierModel deleteModifier in deleteRankModifiers)
            {
                deleteModifier.Delete();
            }

            //Lets make a copy of the previous rank requirements and modifiers now and save them to the database.
            newRankRequirements = EnhancementRankRequirementModel.GetAll(RankModels[EnhancementIndexLoaded][previousRank - 1].Id);
            foreach (EnhancementRankRequirementModel rankRequirement in newRankRequirements)
            {
                rankRequirement.ConvertToNewRecord();
                rankRequirement.EnhancementRankId = RankModels[EnhancementIndexLoaded][previousRank].Id;
                rankRequirement.Save();
            }
            newRankModifiers = EnhancementRankModifierModel.GetAll(RankModels[EnhancementIndexLoaded][previousRank - 1].Id);
            foreach (EnhancementRankModifierModel rankModifier in newRankModifiers)
            {
                rankModifier.ConvertToNewRecord();
                rankModifier.EnhancementRankId = RankModels[EnhancementIndexLoaded][previousRank].Id;
                rankModifier.Save();
            }

            //Ok, now that new records are saved, lets Update the screen with the changes and also update the Description boxes.
            switch (previousRank)
            {
            case 1:
            {
                RankRequirementsRP2.Clear();
                RankRequirementsRP2.RecordId = RankModels[EnhancementIndexLoaded][previousRank].Id;
                RankRequirementsRP2.Initialize();
                RankModifiersMP2.Clear();
                RankModifiersMP2.RecordId = RankModels[EnhancementIndexLoaded][previousRank].Id;
                RankModifiersMP2.Initialize();

                RankModels[EnhancementIconListControl.SelectedIndex][1].Description = RankDescriptionHE1.Text;
                RankDescriptionHE2.Text  = RankDescriptionHE1.Text;
                EnhancementRecordChanged = true;
                break;
            }

            case 2:
            {
                RankRequirementsRP3.Clear();
                RankRequirementsRP3.RecordId = RankModels[EnhancementIndexLoaded][previousRank].Id;
                RankRequirementsRP3.Initialize();
                RankModifiersMP3.Clear();
                RankModifiersMP3.RecordId = RankModels[EnhancementIndexLoaded][previousRank].Id;
                RankModifiersMP3.Initialize();

                RankModels[EnhancementIconListControl.SelectedIndex][2].Description = RankDescriptionHE2.Text;
                RankDescriptionHE3.Text  = RankDescriptionHE2.Text;
                EnhancementRecordChanged = true;
                break;
            }
            }

            //lets save the enhancement record again to make sure changes hold. this may be redundant but it doesn't hurt :)
            SaveRecord();
        }