///-------------------------------------------------------------------------------- /// <summary>This method is used to copy/paste a new item.</summary> /// /// <param name="copyItem">The item to copy/paste.</param> /// <param name="savePaste">Flag to determine whether to save the results of the paste.</param> ///-------------------------------------------------------------------------------- public StateModelViewModel PasteStateModel(StateModelViewModel copyItem, bool savePaste = true) { StateModel newItem = new StateModel(); newItem.ReverseInstance = new StateModel(); newItem.TransformDataFromObject(copyItem.StateModel, null, false); newItem.StateModelID = Guid.NewGuid(); newItem.IsAutoUpdated = false; newItem.Entity = Entity; newItem.Solution = Solution; StateModelViewModel newView = new StateModelViewModel(newItem, Solution); newView.ResetModified(true); AddStateModel(newView); // paste children foreach (StateViewModel childView in copyItem.States) { newView.PasteState(childView, savePaste); } if (savePaste == true) { Solution.StateModelList.Add(newItem); Entity.StateModelList.Add(newItem); newView.OnUpdated(this, null); Solution.ResetModified(true); } return(newView); }
///-------------------------------------------------------------------------------- /// <summary>This method loads StateModels into the view model.</summary> /// /// <param name="entity">The entity to load.</param> /// <param name="solution">The associated solution.</param> /// <param name="loadChildren">Flag indicating whether to perform a deeper load.</param> ///-------------------------------------------------------------------------------- public void LoadStateModels(Entity entity, Solution solution, bool loadChildren = true) { // attach the items Items.Clear(); if (StateModels == null) { StateModels = new EnterpriseDataObjectList <StateModelViewModel>(); } if (loadChildren == true) { foreach (StateModel item in entity.StateModelList) { StateModelViewModel itemView = new StateModelViewModel(item, solution); itemView.Updated += new EventHandler(Children_Updated); StateModels.Add(itemView); Items.Add(itemView); } } }
///-------------------------------------------------------------------------------- /// <summary>This method applies statemodel updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditStateModelPerformed(StateModelEventArgs data) { try { bool isItemMatch = false; if (data != null && data.StateModel != null) { foreach (StateModelViewModel item in StateModels) { if (item.StateModel.StateModelID == data.StateModel.StateModelID) { isItemMatch = true; item.StateModel.TransformDataFromObject(data.StateModel, null, false); item.OnUpdated(item, null); item.ShowInTreeView(); break; } } if (isItemMatch == false) { // add new StateModel data.StateModel.Entity = Entity; StateModelViewModel newItem = new StateModelViewModel(data.StateModel, Solution); newItem.Updated += new EventHandler(Children_Updated); StateModels.Add(newItem); Entity.StateModelList.Add(newItem.StateModel); Solution.StateModelList.Add(newItem.StateModel); Items.Add(newItem); OnUpdated(this, null); newItem.ShowInTreeView(); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method deletes an instance of StateModel from the view model.</summary> /// /// <param name="itemView">The StateModel to delete.</param> ///-------------------------------------------------------------------------------- public void DeleteStateModel(StateModelViewModel itemView) { itemView.Updated -= Children_Updated; StateModels.Remove(itemView); Delete(itemView); }
///-------------------------------------------------------------------------------- /// <summary>This method adds an instance of StateModel to the view model.</summary> /// /// <param name="itemView">The StateModel to add.</param> ///-------------------------------------------------------------------------------- public void AddStateModel(StateModelViewModel itemView) { itemView.Updated += new EventHandler(Children_Updated); StateModels.Add(itemView); Add(itemView); }