/// <summary> /// /// </summary> public void Save() { EDBEntities eDB = new EDBEntities(); // To determine which items have been deleted in the collection, get all objects of the project stored in the database table first var tblTemplates = eDB.tblTemplates.Where(p => p.Project_ID == Globals.Project_ID); // Check if each template of the table exists in the templates collection // if not, delete the template in the table foreach (var templateRec in tblTemplates) { var templateItem = GetTemplate(templateRec.ID); if (templateItem == null) // template not found in collection { eDB.tblTemplates.Remove(templateRec); } } // Add and update templates recursively SaveLevel(Templates, eDB); try { eDB.SaveChanges(); } catch (Exception ex) { RadWindow.Alert(new DialogParameters() { Header = "Error", Content = "Fault while saving templates:\n" + ex.Message }); } SaveTreeState(); }
/// <summary> /// /// </summary> public void Save() { EDBEntities eDB = new EDBEntities(); // To determine which items have been deleted in the collection, get all associations of the project stored in the database table first var tblObjectAssociations = eDB.tblObjectAssociations.Where(p => p.Project_ID == Globals.Project_ID); // Check if each association of the table exists in the associations collection // if not, delete the association in the table foreach (var objectAssociationRec in tblObjectAssociations) { var objectAssociationItem = GetObjectAssociation(objectAssociationRec.Object_ID, objectAssociationRec.Association_ID); if (objectAssociationItem == null) // association not found in collection { eDB.tblObjectAssociations.Remove(objectAssociationRec); } } // Add and update associations recursively SaveLevel(ObjectAssociations, eDB); try { eDB.SaveChanges(); } catch (Exception ex) { RadWindow.Alert(new DialogParameters() { Header = "Error", Content = "Fault while saving object associations:\n" + ex.Message }); } IsChanged = false; }
private void SaveTypeItem(EDBEntities eDB, TypeModel typeItem) { if (typeItem.IsNew) { tblType NewRec = new tblType(); var Rec = eDB.tblTypes.Add(NewRec); Rec.Type = typeItem.Type; Rec.Description = typeItem.Description; Rec.Image = typeItem.Image; Rec.TypeGroup = typeItem.TypeGroup; Rec.ShowOrder = typeItem.ShowOrder; Rec.Project_ID = Globals.Project_ID; typeItem.IsNew = false; typeItem.IsChanged = false; } if (typeItem.IsChanged) { tblType Rec = eDB.tblTypes.Where(o => o.ID == typeItem.ID).FirstOrDefault(); Rec.Type = typeItem.Type; Rec.Description = typeItem.Description; Rec.Image = typeItem.Image; Rec.ShowOrder = typeItem.ShowOrder; typeItem.IsChanged = false; } if (typeItem.IsDeleted) { tblType Rec = eDB.tblTypes.Where(o => o.ID == typeItem.ID).FirstOrDefault(); if (Rec != null) { eDB.tblTypes.Remove(Rec); } } }
/// <summary> /// Loads the records from the DbSet into the ViewModel. This function designed for recursive use /// </summary> /// <returns>Observable collection of Projects</returns> private void Load() { using (EDBEntities eDB = new EDBEntities()) { try { foreach (tblProject Rec in (from o in eDB.tblProjects select o)) { ProjectModel projectItem = new ProjectModel { ID = Rec.ID, ProjectName = Rec.ProjectName, ContractNo = Rec.ContractNo, CustomerName = Rec.CustomerName, Logo = Rec.Logo, LastOpened = Rec.LastOpened, LastOpenedBy = Rec.LastOpenedBy }; Projects.Add(projectItem); } } catch (Exception ex) { RadWindow.Alert(ex.Message); } } }
/// <summary> /// Loads the records from the DbSet into the ViewModel. This function designed for recursive use /// </summary> /// <param name="Project_ID"></param> /// <param name="Parent_ID"></param> /// <returns>Observable collection of VMObjects</returns> private void Load() { using (EDBEntities eDB = new EDBEntities()) { foreach (tblType Rec in (from o in eDB.tblTypes where (o.Project_ID == Globals.Project_ID) orderby o.ShowOrder select o)) { TypeModel typeItem = new TypeModel { ID = Rec.ID, Project_ID = Rec.Project_ID, Type = Rec.Type, Description = Rec.Description, Image = Rec.Image, ShowOrder = Rec.ShowOrder.GetValueOrDefault(999), TypeGroup = Rec.TypeGroup, IsChanged = false, }; Types.Add(typeItem); } TypeGroups.Add("Object"); TypeGroups.Add("Property"); TypeGroups.Add("Template"); TypeGroups.Add("Requirement"); } IsChanged = false; }
/// <summary> /// Select Project Command through command interface /// </summary> private void SelectProject(Object p) { ProjectModel selectedProject = GetProject((int)p); Globals.Project_ID = (int)p; Globals.ProjectSelected = true; ProjectSelected = true; Globals.ProjectName = selectedProject.ProjectName; Globals.ContractNo = selectedProject.ContractNo; selectedProject.LastOpened = DateTime.Now; // Store the current DateTime in the selected project record so it can be used to sort the project list EDBEntities eDB = new EDBEntities(); tblProject Rec = eDB.tblProjects.Where(o => o.ID == selectedProject.ID).FirstOrDefault(); Rec.LastOpened = selectedProject.LastOpened; Rec.LastOpenedBy = Environment.UserName; eDB.SaveChanges(); IsBackStageOpen = false; MainTitle = Globals.ContractNo + Globals.ProjectName; TypeViewModelLocator.GetTypeVM(); ObjectViewModelLocator.GetObjectVM(); TemplateViewModelLocator.GetTemplateVM(); PropertyViewModelLocator.GetPropertyVM(); AspectViewModelLocator.GetAspectVM(); AttributeViewModelLocator.GetAttributeVM(); ObjectAssociationViewModelLocator.GetObjectAssociationVM(); ObjectRequirementViewModelLocator.GetObjectRequirementVM(); TemplateAssociationViewModelLocator.GetTemplateAssociationVM(); TemplateRequirementViewModelLocator.GetTemplateRequirementVM(); }
private void Load() { // Check if the classes and properties have ben loaded //while (!RequirementViewModelLocator.IsLoaded()); using (EDBEntities eDB = new EDBEntities()) { foreach (tblObjectRequirement Rec in (from o in eDB.tblObjectRequirements where (o.Project_ID == Globals.Project_ID) select o)) { ObjectRequirementModel objectRequirementItem = new ObjectRequirementModel { Project_ID = Rec.Project_ID, Object_ID = Rec.Object_ID, Requirement_ID = Rec.Requirement_ID, RequirementType = Rec.RequirementType, PreFATOk = Rec.PreFATOk, FATOk = Rec.FATOk, FATBy = Rec.FATBy, FATDate = Rec.FATDate, SATOk = Rec.SATOk, SATBy = Rec.SATBy, SATDate = Rec.SATDate, IsChanged = false, IsNew = false, IsDeleted = false, ChildRequirements = new TD.ObservableItemCollection <ObjectRequirementModel>() }; var requirementItem = RequirementViewModelLocator.GetRequirementVM().GetRequirement(objectRequirementItem.Requirement_ID, null); if (requirementItem != null) { objectRequirementItem.ArticleNo = requirementItem.ArticleNo; objectRequirementItem.ArticleHeader = requirementItem.ArticleHeader; objectRequirementItem.RequirementType_ID = requirementItem.RequirementType_ID; foreach (var childItem in requirementItem.ChildRequirements) { ObjectRequirementModel item = new ObjectRequirementModel { Project_ID = childItem.Project_ID, Object_ID = objectRequirementItem.Object_ID, Requirement_ID = childItem.ID, ArticleNo = childItem.ArticleNo, ArticleHeader = childItem.ArticleHeader, RequirementType = "Requirement", RequirementType_ID = childItem.RequirementType_ID, ChildRequirements = new TD.ObservableItemCollection <ObjectRequirementModel>() }; objectRequirementItem.ChildRequirements.Add(item); } ObjectRequirements.Add(objectRequirementItem); } } } }
private void SaveLevel(TD.ObservableItemCollection <AspectModel> treeLevel, EDBEntities eDB) { try { if (treeLevel != null) { foreach (var aspectItem in treeLevel) { if (aspectItem.IsNew) { tblAspect NewRec = new tblAspect(); var Rec = eDB.tblAspects.Add(NewRec); Rec.ID = aspectItem.ID; Rec.AspectName = aspectItem.AspectName; Rec.Description = aspectItem.Description; Rec.Project_ID = Globals.Project_ID; Rec.HardIO = aspectItem.HardIO; Rec.ExtIO = aspectItem.ExtIO; Rec.PLCTag = aspectItem.PLCTag; Rec.SCADATag = aspectItem.SCADATag; Rec.AlarmTag = aspectItem.AlarmTag; Rec.TrendTag = aspectItem.TrendTag; Rec.Note = aspectItem.Note; aspectItem.IsNew = false; } if (aspectItem.IsChanged) { tblAspect Rec = eDB.tblAspects.Where(o => o.ID == aspectItem.ID).FirstOrDefault(); Rec.AspectName = aspectItem.AspectName; Rec.Description = aspectItem.Description; Rec.Project_ID = Globals.Project_ID; Rec.HardIO = aspectItem.HardIO; Rec.ExtIO = aspectItem.ExtIO; Rec.PLCTag = aspectItem.PLCTag; Rec.SCADATag = aspectItem.SCADATag; Rec.AlarmTag = aspectItem.AlarmTag; Rec.TrendTag = aspectItem.TrendTag; Rec.Note = aspectItem.Note; aspectItem.IsChanged = false; } if (aspectItem.IsDeleted) { tblAspect Rec = eDB.tblAspects.Where(o => o.ID == aspectItem.ID).FirstOrDefault(); if (Rec != null) { eDB.tblAspects.Remove(Rec); } } } } } catch (Exception ex) { RadWindow.Alert("Fault while saving to database: " + ex.Message); } }
private void SaveLevel(ObservableCollection <RequirementModel> treeLevel, EDBEntities eDB) { try { if (treeLevel != null) { foreach (var requirementItem in treeLevel) { if (requirementItem.IsNew) { tblRequirement NewRec = new tblRequirement(); var Rec = eDB.tblRequirements.Add(NewRec); Rec.ID = requirementItem.ID; Rec.Parent_ID = requirementItem.Parent_ID; Rec.ArticleNo = requirementItem.ArticleNo; Rec.ArticleHeader = requirementItem.ArticleHeader; Rec.Project_ID = Globals.Project_ID; Rec.RequirementType_ID = requirementItem.RequirementType_ID; Rec.Content = requirementItem.Content; requirementItem.IsNew = false; } if (requirementItem.IsChanged) { tblRequirement Rec = eDB.tblRequirements.Where(o => o.ID == requirementItem.ID).FirstOrDefault(); Rec.Parent_ID = requirementItem.Parent_ID; Rec.ArticleNo = requirementItem.ArticleNo; Rec.ArticleHeader = requirementItem.ArticleHeader; Rec.Project_ID = requirementItem.Project_ID; Rec.RequirementType_ID = requirementItem.RequirementType_ID; Rec.Content = requirementItem.Content; requirementItem.IsChanged = false; } // Recursive call if (requirementItem.ChildRequirements != null) { SaveLevel(requirementItem.ChildRequirements, eDB); } } } } catch (Exception ex) { RadWindow.Alert(new DialogParameters() { Header = "Error", Content = "Fault while adding/updating to database:\n" + ex.Message }); } }
/// <summary> /// Saves all changes to the ViewModel /// </summary> private void SaveLevel(TD.ObservableItemCollection <ObjectModel> treeLevel, EDBEntities eDB) { try { if (treeLevel != null) { foreach (var objectItem in treeLevel) { if (objectItem.IsNew) { tblObject NewRec = new tblObject(); var Rec = eDB.tblObjects.Add(NewRec); Rec.ID = objectItem.ID; Rec.Parent_ID = objectItem.Parent_ID; Rec.ObjectName = objectItem.ObjectName; Rec.Description = objectItem.Description; Rec.Project_ID = Globals.Project_ID; Rec.ObjectType_ID = objectItem.ObjectType_ID; Rec.IsExpanded = objectItem.IsExpanded; objectItem.IsNew = false; } if (objectItem.IsChanged) { tblObject Rec = eDB.tblObjects.Where(o => o.ID == objectItem.ID).FirstOrDefault(); Rec.Parent_ID = objectItem.Parent_ID; Rec.ObjectName = objectItem.ObjectName; Rec.Description = objectItem.Description; Rec.Project_ID = objectItem.Project_ID; Rec.ObjectType_ID = objectItem.ObjectType_ID; Rec.IsExpanded = objectItem.IsExpanded; objectItem.IsChanged = false; } // Recursive call if (objectItem.ChildObjects != null) { SaveLevel(objectItem.ChildObjects, eDB); } } } } catch (Exception ex) { RadWindow.Alert(new DialogParameters() { Header = "Error", Content = "Fault while adding/updating to database:\n" + ex.Message }); } }
public void Save() { EDBEntities eDB = new EDBEntities(); SaveLevel(Aspects, eDB); try { eDB.SaveChanges(); } catch (Exception ex) { RadWindow.Alert("Fault while saving aspects: " + ex.Message); } IsChanged = false; }
/// <summary> /// Saves all changes to the ViewModel /// </summary> private void SaveLevel(ObservableCollection <TemplateModel> treeLevel, EDBEntities eDB) { try { if (treeLevel != null) { foreach (var templateItem in treeLevel) { if (templateItem.IsNew) { tblTemplate NewRec = new tblTemplate(); var Rec = eDB.tblTemplates.Add(NewRec); Rec.ID = templateItem.ID; Rec.Parent_ID = templateItem.Parent_ID; Rec.TemplateName = templateItem.TemplateName; Rec.Description = templateItem.Description; Rec.TemplateType_ID = templateItem.TemplateType_ID; Rec.Project_ID = templateItem.Project_ID; templateItem.IsNew = false; } if (templateItem.IsChanged) { tblTemplate Rec = eDB.tblTemplates.Where(o => o.ID == templateItem.ID).FirstOrDefault(); Rec.Parent_ID = templateItem.Parent_ID; Rec.TemplateName = templateItem.TemplateName; Rec.Description = templateItem.Description; Rec.TemplateType_ID = templateItem.TemplateType_ID; Rec.Project_ID = templateItem.Project_ID; templateItem.IsChanged = false; } // Recursive call if (templateItem.ChildTemplates != null) { SaveLevel(templateItem.ChildTemplates, eDB); } } } } catch (Exception ex) { RadWindow.Alert(new DialogParameters() { Header = "Error", Content = "Fault while adding/updating to database:\n" + ex.Message }); } }
public void Save() { EDBEntities eDB = new EDBEntities(); foreach (var typeItem in Types) { if (typeItem.IsNew) { tblType NewRec = new tblType(); var Rec = eDB.tblTypes.Add(NewRec); Rec.Type = typeItem.Type; Rec.Description = typeItem.Description; Rec.Image = typeItem.Image; Rec.TypeGroup = typeItem.TypeGroup; Rec.ShowOrder = typeItem.ShowOrder; Rec.Project_ID = Globals.Project_ID; typeItem.IsNew = false; typeItem.IsChanged = false; } if (typeItem.IsChanged) { tblType Rec = eDB.tblTypes.Where(o => o.ID == typeItem.ID).FirstOrDefault(); Rec.Type = typeItem.Type; Rec.Description = typeItem.Description; Rec.Image = typeItem.Image; Rec.ShowOrder = typeItem.ShowOrder; typeItem.IsChanged = false; } if (typeItem.IsDeleted) { tblType Rec = eDB.tblTypes.Where(o => o.ID == typeItem.ID).FirstOrDefault(); if (Rec != null) { eDB.tblTypes.Remove(Rec); } } } try { eDB.SaveChanges(); } catch (Exception ex) { RadWindow.Alert("Fault while saving object types: " + ex.Message); } }
/// <summary> /// Load all object types defined in tblObjectTypes table (This is project independent /// </summary> public void Load() { using (EDBEntities eDB = new EDBEntities()) { foreach (tblAttribute Rec in (from a in eDB.tblAttributes where (a.Project_ID == Globals.Project_ID) orderby a.Attribute select a)) { AttributeModel attributeItem = new AttributeModel { ID = Rec.ID, Project_ID = Rec.Project_ID, Attribute = Rec.Attribute, Description = Rec.Description, IsDeleted = false }; Attributes.Add(attributeItem); } } }
/// <summary> /// Loads the records from the DbSet into the ViewModel. This function designed for recursive use /// </summary> /// <param name="Project_ID"></param> /// <param name="Parent_ID"></param> /// <returns>Observable collection of VMObjects</returns> private TD.ObservableItemCollection <PropertyModel> Load(Guid?Parent_ID) { TD.ObservableItemCollection <PropertyModel> childProperties = new TD.ObservableItemCollection <PropertyModel>(); using (EDBEntities eDB = new EDBEntities()) { foreach (tblProperty Rec in (from o in eDB.tblProperties where (o.Project_ID == Globals.Project_ID && o.Parent_ID == Parent_ID) orderby o.PropertyName select o)) { PropertyModel propertyItem = new PropertyModel { ID = Rec.ID, Parent_ID = Rec.Parent_ID, Project_ID = Rec.Project_ID, PropertyName = Rec.PropertyName, Description = Rec.Description, PropertyType_ID = (int)Rec.PropertyType_ID, Aspect = Rec.Aspect, Attribute1 = Rec.Attribute1, Attribute2 = Rec.Attribute2, Attribute3 = Rec.Attribute3, Value = Rec.Value, IsChanged = false, IsNew = false, IsDeleted = false }; propertyItem.ChildProperties = Load(Rec.ID); // If the parent ID is null, this is a root object and needs to be added to the VM class // Else it is a child object which needs to be added to the childobjectlist if (Rec.Parent_ID == null) { Properties.Add(propertyItem); } else { childProperties.Add(propertyItem); } } } return(childProperties); }
private TD.ObservableItemCollection <RequirementModel> Load(Guid?Parent_ID) { TD.ObservableItemCollection <RequirementModel> childRequirements = new TD.ObservableItemCollection <RequirementModel>(); using (EDBEntities eDB = new EDBEntities()) { foreach (tblRequirement Rec in (from o in eDB.tblRequirements where (o.Project_ID == Globals.Project_ID && o.Parent_ID == Parent_ID) orderby o.ArticleNo select o)) { RequirementModel requirementItem = new RequirementModel { ID = Rec.ID, Parent_ID = Rec.Parent_ID, Project_ID = Globals.Project_ID, // Rec.Project_ID, ArticleNo = Rec.ArticleNo, ArticleHeader = Rec.ArticleHeader, RequirementType_ID = (int)Rec.RequirementType_ID, Content = Rec.Content, Version = Rec.Version, IsChanged = false }; // Load objects with a parent_ID equal to the ID of this object requirementItem.ChildRequirements = Load(Rec.ID); // If the parent ID is null, this is a root object and needs to be added to the collection that is the itemsource of the object tree // Else it is a child object which needs to be added to the childobjectlist if (Rec.Parent_ID == null) { Requirements.Add(requirementItem); } else { childRequirements.Add(requirementItem); } } } IsChanged = false; return(childRequirements); }
/// <summary> /// Loads the records from the DbSet into the ViewModel. This function designed for recursive use /// </summary> /// <param name="Project_ID"></param> /// <param name="Parent_ID"></param> /// <returns>Observable collection of VMObjects</returns> private TD.ObservableItemCollection <ObjectModel> Load(Guid?Parent_ID) { TD.ObservableItemCollection <ObjectModel> childObjects = new TD.ObservableItemCollection <ObjectModel>(); // TD.ObservableItemCollection<ObjectModel> personalLayout = new TD.ObservableItemCollection<ObjectModel>(); using (EDBEntities eDB = new EDBEntities()) { foreach (tblObject Rec in (from o in eDB.tblObjects where (o.Project_ID == Globals.Project_ID && o.Parent_ID == Parent_ID) orderby o.ObjectName select o)) { ObjectModel objectItem = new ObjectModel { ID = Rec.ID, Parent_ID = Rec.Parent_ID, Project_ID = Rec.Project_ID, ObjectName = Rec.ObjectName, Description = Rec.Description, ObjectType_ID = (int)Rec.ObjectType_ID, IsChanged = false, }; // Load objects with a parent_ID equal to the ID of this object objectItem.ChildObjects = Load(Rec.ID); // If the parent ID is null, this is a root object and needs to be added to the collection that is the itemsource of the object tree // Else it is a child object which needs to be added to the childobjectlist if (Rec.Parent_ID == null) { Objects.Add(objectItem); } else { childObjects.Add(objectItem); } } } IsChanged = false; return(childObjects); }
/// <summary> /// Load all object types defined in tblObjectTypes table (This is project independent /// </summary> public void Load() { using (EDBEntities eDB = new EDBEntities()) { foreach (tblAspect Rec in (from a in eDB.tblAspects where (a.Project_ID == Globals.Project_ID) orderby a.AspectName select a)) { AspectModel aspectItem = new AspectModel { ID = Rec.ID, AspectName = Rec.AspectName, Description = Rec.Description, HardIO = Rec.HardIO.GetValueOrDefault(), ExtIO = Rec.ExtIO.GetValueOrDefault(), PLCTag = Rec.PLCTag.GetValueOrDefault(), SCADATag = Rec.SCADATag.GetValueOrDefault(), AlarmTag = Rec.AlarmTag.GetValueOrDefault(), TrendTag = Rec.TrendTag.GetValueOrDefault(), Note = Rec.Note }; Aspects.Add(aspectItem); } } }
/// <summary> /// Load all object types defined in tblObjectTypes table (This is project independent /// </summary> public void Load() { using (EDBEntities eDB = new EDBEntities()) { foreach (var Rec in (from o in eDB.tblObjects join a in eDB.tblObjectAssociations on o.ID equals a.Object_ID join p in eDB.tblProperties on a.Association_ID equals p.ID join ap in eDB.tblAspects on p.Aspect equals ap.AspectName join t in eDB.tblTypes on o.ObjectType_ID equals t.ID where (o.Project_ID == Globals.Project_ID && ap.Project_ID == Globals.Project_ID && ap.HardIO == true) orderby o.ObjectName select new { ObjectName = o.ObjectName, Description = o.Description, PropertyName = p.PropertyName })) { HardIOModel hardIOItem = new HardIOModel { ObjectName = Rec.ObjectName, Description = Rec.Description, PropertyName = Rec.PropertyName }; HardIO.Add(hardIOItem); } } }
/// <summary> /// Loads the records from the DbSet into the ViewModel. This function designed for recursive use /// </summary> /// <param name="Project_ID"></param> /// <param name="Parent_ID"></param> /// <returns>Observable collection of VMObjects</returns> private TD.ObservableItemCollection <TemplateModel> Load(Guid?Parent_ID) { TD.ObservableItemCollection <TemplateModel> childTemplates = new TD.ObservableItemCollection <TemplateModel>(); using (EDBEntities eDB = new EDBEntities()) { foreach (tblTemplate Rec in (from o in eDB.tblTemplates where (o.Project_ID == Globals.Project_ID && o.Parent_ID == Parent_ID) select o)) { TemplateModel templateItem = new TemplateModel { ID = Rec.ID, Parent_ID = Rec.Parent_ID, Project_ID = Rec.Project_ID, TemplateName = Rec.TemplateName, Description = Rec.Description, TemplateType_ID = (int)Rec.TemplateType_ID, IsChanged = false, IsNew = false, IsDeleted = false }; templateItem.ChildTemplates = Load(Rec.ID); // // If the parent ID is null, this is a root template and needs to be added to the VM class // // Else it is a child object which needs to be added to the ChildTemplate list if (Rec.Parent_ID == null) { Templates.Add(templateItem); } else { childTemplates.Add(templateItem); } } } return(childTemplates); }
public void Save() { EDBEntities eDB = new EDBEntities(); // To determine which items have been deleted in the collection, get all ControlObject of the project stored in the database table first var tblControlObjects = eDB.tblControlObjects.Where(p => p.Project_ID == Globals.Project_ID); // Check if each object of the table exists in the ControlObject collection // if not, delete the object in the table foreach (var ControllerRec in tblControlObjects) { var controllerItem = GetController(ControllerRec.ID); if (controllerItem == null) // object not found in collection { eDB.tblControlObjects.Remove(ControllerRec); } } // Add and update ControlObject recursively SaveLevel(ControlObjects, eDB); try { eDB.SaveChanges(); } catch (Exception ex) { RadWindow.Alert(new DialogParameters() { Header = "Error", Content = "Fault while saving ControlObject:\n" + ex.Message }); } SaveTreeState(); IsChanged = false; }
/// <summary> /// Saves all changes to the ViewModel /// </summary> private void Save() { EDBEntities eDB = new EDBEntities(); eDB.SaveChanges(); }
/// <summary> /// Saves all changes to the ViewModel /// </summary> private void SaveLevel(TD.ObservableItemCollection <PropertyModel> treeLevel, EDBEntities eDB) { try { if (treeLevel != null) { foreach (var propertyItem in treeLevel) { if (propertyItem.IsNew) { tblProperty NewRec = new tblProperty(); var Rec = eDB.tblProperties.Add(NewRec); Rec.ID = propertyItem.ID; Rec.Parent_ID = propertyItem.Parent_ID; Rec.PropertyName = propertyItem.PropertyName; Rec.Description = propertyItem.Description; Rec.Project_ID = propertyItem.Project_ID; Rec.PropertyType_ID = propertyItem.PropertyType_ID; Rec.Aspect = propertyItem.Aspect; Rec.Attribute1 = propertyItem.Attribute1; Rec.Attribute2 = propertyItem.Attribute2; Rec.Attribute3 = propertyItem.Attribute3; Rec.Value = propertyItem.Value; propertyItem.IsNew = false; } if (propertyItem.IsChanged) { tblProperty Rec = eDB.tblProperties.Where(o => o.ID == propertyItem.ID).FirstOrDefault(); Rec.Parent_ID = propertyItem.Parent_ID; Rec.PropertyName = propertyItem.PropertyName; Rec.Description = propertyItem.Description; Rec.Project_ID = propertyItem.Project_ID; Rec.PropertyType_ID = propertyItem.PropertyType_ID; Rec.Aspect = propertyItem.Aspect; Rec.Attribute1 = propertyItem.Attribute1; Rec.Attribute2 = propertyItem.Attribute2; Rec.Attribute3 = propertyItem.Attribute3; Rec.Value = propertyItem.Value; propertyItem.IsChanged = false; } // DeleteRecursive call to add/Update children if (propertyItem.ChildProperties != null) { SaveLevel(propertyItem.ChildProperties, eDB); } } } } catch (Exception ex) { RadWindow.Alert(new DialogParameters() { Header = "Error", Content = "Fault while adding/updating to database:\n" + ex.Message }); } }
/// <summary> /// Saves all changes to the ViewModel /// </summary> private void SaveLevel(ObservableCollection <ObjectAssociationModel> treeLevel, EDBEntities eDB) { try { if (treeLevel != null) { foreach (var objectAssociationItem in treeLevel) { if (objectAssociationItem.IsNew) { tblObjectAssociation NewRec = new tblObjectAssociation(); var Rec = eDB.tblObjectAssociations.Add(NewRec); Rec.ID = objectAssociationItem.ID; Rec.Object_ID = objectAssociationItem.Object_ID; Rec.Association_ID = objectAssociationItem.Association_ID; Rec.Project_ID = Globals.Project_ID; Rec.AssociationType = objectAssociationItem.AssociationType; Rec.Value = objectAssociationItem.Value; objectAssociationItem.IsNew = false; } // Only save changes if the value has changed and the value = not empty or null if (objectAssociationItem.IsChanged && !string.IsNullOrEmpty(objectAssociationItem.Value)) { tblObjectAssociation Rec = eDB.tblObjectAssociations.Where(o => o.Object_ID == objectAssociationItem.Object_ID && o.Association_ID == objectAssociationItem.Association_ID).FirstOrDefault(); // If the association is in the table, save the value if (Rec != null) { Rec.Value = objectAssociationItem.Value; } // Otherwise add a record to the association table and save the value. // Note: child associations normally are not saved to the association table but inherited from the templates or properties else { tblObjectAssociation NewRec = new tblObjectAssociation(); Rec = eDB.tblObjectAssociations.Add(NewRec); Rec.ID = objectAssociationItem.ID; Rec.Object_ID = objectAssociationItem.Object_ID; Rec.Association_ID = objectAssociationItem.Association_ID; Rec.Project_ID = Globals.Project_ID; Rec.AssociationType = objectAssociationItem.AssociationType; Rec.Value = objectAssociationItem.Value; } objectAssociationItem.IsChanged = false; } // Recursive call if (objectAssociationItem.ChildAssociations != null) { SaveLevel(objectAssociationItem.ChildAssociations, eDB); } } } } catch (Exception ex) { RadWindow.Alert(new DialogParameters() { Header = "Error", Content = "Fault while adding/updating to database:\n" + ex.Message }); } }
private void Load(Guid?associationParent_ID) { // Check if the classes and properties have ben loaded. Necessary because of the various background workers try { using (EDBEntities eDB = new EDBEntities()) { foreach (tblTemplateAssociation Rec in (from o in eDB.tblTemplateAssociations where (o.Project_ID == Globals.Project_ID) select o)) { TemplateAssociationModel templateAssociationItem = new TemplateAssociationModel { ID = Rec.ID, Project_ID = Rec.Project_ID, Template_ID = Rec.Template_ID, Association_ID = Rec.Association_ID, Value = Rec.Value, AssociationType = Rec.AssociationType, IsChanged = false, IsNew = false, IsDeleted = false, ChildAssociations = new TD.ObservableItemCollection <TemplateAssociationModel>() }; switch (templateAssociationItem.AssociationType) { case "Property": var propertyItem = PropertyViewModelLocator.GetPropertyVM().GetProperty(templateAssociationItem.Association_ID, null); if (propertyItem != null) { templateAssociationItem.Name = propertyItem.PropertyName; templateAssociationItem.Description = propertyItem.Description; templateAssociationItem.AssociationType_ID = propertyItem.PropertyType_ID; foreach (var childItem in propertyItem.ChildProperties) { TemplateAssociationModel item = new TemplateAssociationModel { ID = Rec.ID, Project_ID = childItem.Project_ID, Template_ID = templateAssociationItem.Template_ID, Association_ID = childItem.ID, Name = childItem.PropertyName, Description = childItem.Description, AssociationType = "Property", AssociationType_ID = childItem.PropertyType_ID, ChildAssociations = new TD.ObservableItemCollection <TemplateAssociationModel>() }; templateAssociationItem.ChildAssociations.Add(item); } } else { throw new System.InvalidOperationException(String.Format("Association without source\nProperty ID: {0}\nFix in database", templateAssociationItem.Association_ID)); } break; case "TemplateProperty": break; } TemplateAssociations.Add(templateAssociationItem); } } } catch (Exception ex) { Application.Current.Dispatcher.Invoke((Action) delegate { RadWindow.Alert(ex.Message); }); } }
private void Load(Guid?associationParent_ID) { // Check if the templates and properties have ben loaded. Necessary because of the various background workers //while (!TemplateViewModelLocator.IsLoaded() || !PropertyViewModelLocator.IsLoaded()); try { using (EDBEntities eDB = new EDBEntities()) { foreach (tblObjectAssociation Rec in (from o in eDB.tblObjectAssociations where (o.Project_ID == Globals.Project_ID) orderby o.AssociationType select o)) { ObjectAssociationModel objectAssociationItem = new ObjectAssociationModel { ID = Rec.ID, Project_ID = Rec.Project_ID, Object_ID = Rec.Object_ID, Association_ID = Rec.Association_ID, AssociationType = Rec.AssociationType, IsChanged = false, IsNew = false, IsDeleted = false, ChildAssociations = new TD.ObservableItemCollection <ObjectAssociationModel>() }; switch (objectAssociationItem.AssociationType) { case "Template": // Get detail info of the template var templateItem = TemplateViewModelLocator.GetTemplateVM().GetTemplate(objectAssociationItem.Association_ID, null); if (templateItem != null) { objectAssociationItem.Name = templateItem.TemplateName; objectAssociationItem.Description = templateItem.Description; objectAssociationItem.AssociationType_ID = templateItem.TemplateType_ID; // and get any child items foreach (var childItem in templateItem.ChildTemplates) { ObjectAssociationModel item = new ObjectAssociationModel { ID = Rec.ID, Project_ID = childItem.Project_ID, Object_ID = objectAssociationItem.Object_ID, Association_ID = childItem.ID, Name = childItem.TemplateName, Description = childItem.Description, AssociationType = "Template", AssociationType_ID = childItem.TemplateType_ID, ChildAssociations = new TD.ObservableItemCollection <ObjectAssociationModel>() }; objectAssociationItem.ChildAssociations.Add(item); LoadTemplateProperties(item); } LoadTemplateProperties(objectAssociationItem); } else { throw new System.InvalidOperationException(String.Format("Association without source\nTemplate ID: {0}\nFix in database", objectAssociationItem.Association_ID)); } break; case "Property": var propertyItem = PropertyViewModelLocator.GetPropertyVM().GetProperty(objectAssociationItem.Association_ID, null); if (propertyItem != null) { objectAssociationItem.Name = propertyItem.PropertyName; objectAssociationItem.Description = propertyItem.Description; objectAssociationItem.AssociationType_ID = propertyItem.PropertyType_ID; // If the Object Association has a value in the table, use this as the associated value // otherwise use the value defined in the property if (!String.IsNullOrEmpty(Rec.Value)) { objectAssociationItem.Value = Rec.Value; } else { objectAssociationItem.Value = propertyItem.Value; } foreach (var childItem in propertyItem.ChildProperties) { ObjectAssociationModel item = new ObjectAssociationModel { ID = Rec.ID, Project_ID = childItem.Project_ID, Object_ID = objectAssociationItem.Object_ID, Association_ID = childItem.ID, Name = childItem.PropertyName, Description = childItem.Description, AssociationType = "Property", AssociationType_ID = childItem.PropertyType_ID, ChildAssociations = new TD.ObservableItemCollection <ObjectAssociationModel>() }; objectAssociationItem.ChildAssociations.Add(item); } } else { throw new System.InvalidOperationException(String.Format("Association without source\nProperty ID: {0}\nFix in database", objectAssociationItem.Association_ID)); } break; case "TemplateProperty": break; } ObjectAssociations.Add(objectAssociationItem); } } } catch (Exception ex) { Application.Current.Dispatcher.Invoke((Action) delegate { RadWindow.Alert(ex.Message); }); } }
private void SaveLevel(TD.ObservableItemCollection <ObjectRequirementModel> treeLevel, EDBEntities eDB) { try { if (treeLevel != null) { foreach (var objectRequirementItem in treeLevel) { if (objectRequirementItem.IsNew) { tblObjectRequirement NewRec = new tblObjectRequirement(); var Rec = eDB.tblObjectRequirements.Add(NewRec); Rec.Object_ID = objectRequirementItem.Object_ID; Rec.Requirement_ID = objectRequirementItem.Requirement_ID; Rec.PreFATOk = objectRequirementItem.PreFATOk; Rec.FATOk = objectRequirementItem.FATOk; Rec.FATBy = objectRequirementItem.FATBy; Rec.FATDate = objectRequirementItem.FATDate; Rec.SATOk = objectRequirementItem.SATOk; Rec.SATBy = objectRequirementItem.SATBy; Rec.SATDate = objectRequirementItem.SATDate; Rec.Project_ID = Globals.Project_ID; //Rec.RequirementType_ID = objectRequirementItem.RequirementType_ID; objectRequirementItem.IsNew = false; RequirementViewModel requirementVM = RequirementViewModelLocator.GetRequirementVM(); RequirementModel requirementItem = requirementVM.GetRequirement(objectRequirementItem.Requirement_ID); } if (objectRequirementItem.IsChanged) { tblObjectRequirement Rec = eDB.tblObjectRequirements.Where(o => o.Object_ID == objectRequirementItem.Object_ID && o.Requirement_ID == objectRequirementItem.Requirement_ID).FirstOrDefault(); Rec.PreFATOk = objectRequirementItem.PreFATOk; Rec.FATOk = objectRequirementItem.FATOk; Rec.FATBy = objectRequirementItem.FATBy; Rec.FATDate = objectRequirementItem.FATDate; Rec.SATOk = objectRequirementItem.SATOk; Rec.SATBy = objectRequirementItem.SATBy; Rec.SATDate = objectRequirementItem.SATDate; objectRequirementItem.IsChanged = false; } // Recursive call } } } catch (Exception ex) { RadWindow.Alert("Fault while saving to database: " + ex.Message); } }
/// <summary> /// Saves all changes to the ViewModel /// </summary> private void SaveLevel(ObservableCollection <TemplateAssociationModel> treeLevel, EDBEntities eDB) { try { if (treeLevel != null) { foreach (var templateAssociationItem in treeLevel) { if (templateAssociationItem.IsNew) { tblTemplateAssociation NewRec = new tblTemplateAssociation(); var Rec = eDB.tblTemplateAssociations.Add(NewRec); Rec.ID = templateAssociationItem.ID; Rec.Template_ID = templateAssociationItem.Template_ID; Rec.Association_ID = templateAssociationItem.Association_ID; Rec.Project_ID = Globals.Project_ID; Rec.AssociationType = templateAssociationItem.AssociationType; Rec.Value = templateAssociationItem.Value; templateAssociationItem.IsNew = false; } if (templateAssociationItem.IsChanged) { tblTemplateAssociation Rec = eDB.tblTemplateAssociations.Where(o => o.ID == templateAssociationItem.ID).FirstOrDefault(); Rec.Value = templateAssociationItem.Value; } // Recursive call //if (propertyItem.ChildProperties != null) SaveLevel(propertyItem.ChildProperties, eDB); } } } catch (Exception ex) { RadWindow.Alert("Fault while saving to database: " + ex.Message); } }
/// <summary> /// Saves all changes to the ViewModel /// </summary> private void SaveLevel(TD.ObservableItemCollection <AttributeModel> treeLevel, EDBEntities eDB) { try { if (treeLevel != null) { foreach (var attributeItem in treeLevel) { if (attributeItem.IsNew) { tblAttribute NewRec = new tblAttribute(); var Rec = eDB.tblAttributes.Add(NewRec); Rec.ID = attributeItem.ID; Rec.Attribute = attributeItem.Attribute; Rec.Description = attributeItem.Description; Rec.Project_ID = Globals.Project_ID; attributeItem.IsNew = false; } if (attributeItem.IsChanged) { tblAttribute Rec = eDB.tblAttributes.Where(o => o.ID == attributeItem.ID).FirstOrDefault(); Rec.Attribute = attributeItem.Attribute; Rec.Description = attributeItem.Description; Rec.Project_ID = attributeItem.Project_ID; attributeItem.IsChanged = false; } if (attributeItem.IsDeleted) { tblAttribute Rec = eDB.tblAttributes.Where(o => o.Attribute == attributeItem.Attribute).FirstOrDefault(); if (Rec != null) { eDB.tblAttributes.Remove(Rec); } } } } } catch (Exception ex) { RadWindow.Alert("Fault while saving to database: " + ex.Message); } }