private void SaveTree() { if (NewRecord == true || RecordChanged == true) { TreeModel.Save(); //Lets update the Sub Tables next (EnhancementSlot Records) for (int i = 0; i < SlotChanged.Count; i++) { if (SlotDeleted[i] == true) { if (SlotModels[i].Id != Guid.Empty) { SlotModels[i].Delete(); SlotChanged[i] = false; } } if (SlotChanged[i] == true) { SlotModels[i].EnhancementTreeId = TreeModel.Id; SlotModels[i].SlotIndex = i; SlotModels[i].Save(); } } } //Lets see if we need to update EnhancementTreeRequirement records if (TreeRP2.HaveRecordsChanged() == true) { TreeRP2.RecordId = TreeModel.Id; TreeRP2.SaveRecords(); } //cache the TreeName String for later comparison since we have updated the database DatabaseName = TreeModel.Name; }
private void buttonDuplicateRecord_Click(object sender, EventArgs e) { string selection; EnhancementTreeModel newTreeModel = new EnhancementTreeModel(); List <EnhancementTreeRequirementModel> newTreeRequirementModels = new List <EnhancementTreeRequirementModel>(); List <EnhancementSlotModel> newSlotModels = new List <EnhancementSlotModel>(); List <EnhancementModel> newEnhancementModels = new List <EnhancementModel>(); List <EnhancementRankModel> newEnhancementRankModels = new List <EnhancementRankModel>(); List <EnhancementRankModifierModel> newEnhancementRankModifierModels = new List <EnhancementRankModifierModel>(); List <EnhancementRankRequirementModel> newEnhancementRankRequirementModels = new List <EnhancementRankRequirementModel>(); Guid oldSlotId; Guid oldEnhancementId; Guid oldRankId; Guid oldModifierId; Guid oldRequirementId; //Copy the Tree Model First newTreeModel.Initialize(TreeModel.Id); newTreeModel.ConvertToNewRecord(); newTreeModel.Name = TreeModel.Name + "Duplicate"; newTreeModel.Save(); //Copy the Tree Requirement Models newTreeRequirementModels = EnhancementTreeRequirementModel.GetAll(TreeModel.Id); foreach (EnhancementTreeRequirementModel etrm in newTreeRequirementModels) { etrm.ConvertToNewRecord(); etrm.EnhancementTreeId = newTreeModel.Id; etrm.Save(); } //Copy the Slot Models newSlotModels = EnhancementSlotModel.GetAll(TreeModel.Id); foreach (EnhancementSlotModel slot in newSlotModels) { oldSlotId = slot.Id; slot.ConvertToNewRecord(); slot.EnhancementTreeId = newTreeModel.Id; slot.Save(); //Copy the Enhancements for this Slot Model. newEnhancementModels = EnhancementModel.GetAll(oldSlotId); foreach (EnhancementModel em in newEnhancementModels) { oldEnhancementId = em.Id; em.ConvertToNewRecord(); em.EnhancementSlotId = slot.Id; em.Save(); //Copy the Enhancement Ranks for this Enhancement. newEnhancementRankModels = EnhancementRankModel.GetAll(oldEnhancementId); foreach (EnhancementRankModel erm in newEnhancementRankModels) { oldRankId = erm.Id; erm.ConvertToNewRecord(); erm.EnhancementId = em.Id; erm.Save(); //Copy the Enhancement Rank Modifier Models newEnhancementRankModifierModels = EnhancementRankModifierModel.GetAll(oldRankId); foreach (EnhancementRankModifierModel ermm in newEnhancementRankModifierModels) { oldModifierId = ermm.Id; ermm.ConvertToNewRecord(); ermm.EnhancementRankId = erm.Id; ermm.Save(); } //Copy the Enhancement Rank Requirement Models newEnhancementRankRequirementModels = EnhancementRankRequirementModel.GetAll(oldRankId); foreach (EnhancementRankRequirementModel errm in newEnhancementRankRequirementModels) { oldRequirementId = errm.Id; errm.ConvertToNewRecord(); errm.EnhancementRankId = erm.Id; errm.Save(); } } } } //Now lets update our screen with the new record selection = newTreeModel.Name; EnhancementTreeListBox.Items.Clear(); PopulateEnhancementTreeListBox(); //AllowChangeEvents = false; EnhancementTreeListBox.SelectedItem = selection; //AllowChangeEvents = true; //Now we can reset our flags RecordChanged = false; NewRecord = false; }