private void RecurseLoadTemplate(DbSet<SigNode> nodeSet, TemplateViewModel template, ObservableCollection<TemplateNodeViewModel> nodes, Int64 parentId,List<TemplateNodeLayerViewModel> layersNodes) { List<SigNode> levelNodes = (from n in nodeSet where n.SigTemplateId == template.Id && n.ParentId == parentId orderby n.Order select n).ToList(); foreach (SigNode levelNode in levelNodes) { if (levelNode.SigCodeNode.Code.Equals("Folder")) { TemplateNodeFolderViewModel vm = new TemplateNodeFolderViewModel(levelNode); nodes.Add(vm); this.RecurseLoadTemplate(nodeSet, template, vm.Nodes, levelNode.Id, layersNodes); } else if (levelNode.SigCodeNode.Code.Equals("Layer")) { TemplateNodeLayerViewModel vm = new TemplateNodeLayerViewModel(levelNode); nodes.Add(vm); layersNodes.Add(vm); } } }
private void CreateTemplateExecute() { DbSet<SigTemplate> templateSet = this.DataService.GetDbSet<SigTemplate>(); SigTemplate template = this.EngineService.ShowAddDialog<SigTemplate>(); if (template != null) { TemplateViewModel vm = new TemplateViewModel(template); this.Templates.Add(vm); this.TemplatesView.MoveCurrentTo(vm); } }
private void LoadTemplate(TemplateViewModel template) { template.Nodes.Clear(); this.Map.Layers.Clear(); DbSet<SigNode> nodeSet = this.DataService.GetDbSet<SigNode>(); List<TemplateNodeLayerViewModel> layersNodes = new List<TemplateNodeLayerViewModel>(); this.RecurseLoadTemplate(nodeSet, template, template.Nodes, -1, layersNodes); Envelope env = new Envelope(); layersNodes = (from ln in layersNodes where ln.Model.SigLayer != null orderby ln.Model.SigLayer.MapOrder select ln).ToList(); foreach (TemplateNodeLayerViewModel layersNode in layersNodes) { layersNode.CreateLayers(); if (layersNode.Envelope != null) { env.ExpandToInclude(layersNode.Envelope); } foreach (IMapLayer mapLayer in layersNode.Layers) { this.Map.Layers.Add(mapLayer); } } this.Map.ViewExtents = env.ToExtent(); }
private void LoadTemplates() { DbSet<SigTemplate> templateSet = this.DataService.GetDbSet<SigTemplate>(); foreach (SigTemplate templateItem in templateSet) { TemplateViewModel vm = new TemplateViewModel(templateItem); this.Templates.Add(vm); } }
private void AddFolder(TemplateViewModel templateViewModel, TemplateNodeFolderViewModel parentFolder) { SigNode nodeFolder = new SigNode (); if (parentFolder != null) { nodeFolder.ParentId = parentFolder.Model.Id; nodeFolder.Order = parentFolder.Nodes.Count; } else { nodeFolder.ParentId = -1; nodeFolder.Order = templateViewModel.Nodes.Count; } nodeFolder.SigTemplateId = templateViewModel.Id; DbSet<SigCodeNode> codeNodes = this.DataService.GetDbSet<SigCodeNode>(); nodeFolder.SigCodeNode = (from c in codeNodes where c.Code.Equals("Folder") select c).FirstOrDefault(); nodeFolder = this.EngineService.ShowAddDialog<SigNode>(nodeFolder, new String[] {"Libelle" }); if (nodeFolder != null) { if (parentFolder == null) { templateViewModel.Nodes.Add(new TemplateNodeFolderViewModel(nodeFolder)); } else { parentFolder.Nodes.Add(new TemplateNodeFolderViewModel(nodeFolder)); } } }
private void AddLayerMetier(TemplateViewModel templateViewModel, TemplateNodeFolderViewModel parentFolder, EntityTableInfo tableInfo) { long nextMapOrder = this.GetNextMapOrder(); DbSet<SigNode> nodes = this.DataService.GetDbSet<SigNode>(); DbSet<SigLayer> layers = this.DataService.GetDbSet<SigLayer>(); DbSet<SigCodeNode> codeNodes = this.DataService.GetDbSet<SigCodeNode>(); DbSet<SigCodeLayer> codeLayers = this.DataService.GetDbSet<SigCodeLayer>(); SigNode nodeLayerMetier = new SigNode(); nodeLayerMetier.SigTemplateId = templateViewModel.Id; if (parentFolder != null) { nodeLayerMetier.ParentId = parentFolder.Model.Id; nodeLayerMetier.Order = parentFolder.Nodes.Count; } else { nodeLayerMetier.ParentId = -1; nodeLayerMetier.Order = templateViewModel.Nodes.Count; } nodeLayerMetier.SigCodeNode = (from c in codeNodes where c.Code.Equals("Layer") select c).FirstOrDefault(); nodeLayerMetier.Libelle = tableInfo.DisplayName; SigLayer layer = new SigLayer(); layer.Libelle = tableInfo.DisplayName; layer.MapOrder = nextMapOrder; layer.EntityName = tableInfo.EntityType.Name; layer.SigCodeLayer = (from c in codeLayers where c.Code.Equals("Geocodage") select c).FirstOrDefault(); layers.Add(layer); this.DataService.DataContext.SaveChanges(); nodeLayerMetier.SigLayer = layer; nodes.Add(nodeLayerMetier); this.DataService.DataContext.SaveChanges(); nodeLayerMetier.SigLayer = layer; nodeLayerMetier.SigLayerId = layer.Id; TemplateNodeLayerViewModel vm = new TemplateNodeLayerViewModel(nodeLayerMetier); if (parentFolder == null) { templateViewModel.Nodes.Add(vm); } else { parentFolder.Nodes.Add(vm); } vm.CreateLayers(); foreach (IMapLayer mapLayer in vm.Layers) {this.Map.Layers.Add(mapLayer);} }
private void RemoveLayerMetier(TemplateViewModel templateViewModel, TemplateNodeLayerViewModel templateNodeLayerViewModel) { DbSet<SigNode> nodes = this.DataService.GetDbSet<SigNode>(); DbSet<SigLayer> layers = this.DataService.GetDbSet<SigLayer>(); TemplateNodeFolderViewModel parentFolder = this.GetParentFolder(templateViewModel, templateViewModel.Nodes, templateNodeLayerViewModel); if (parentFolder != null) {parentFolder.Nodes.Remove(templateNodeLayerViewModel);} else {templateViewModel.Nodes.Remove(templateNodeLayerViewModel);} nodes.Remove(templateNodeLayerViewModel.Model); this.DataService.DataContext.Entry(templateNodeLayerViewModel.Model).Reload(); if (templateNodeLayerViewModel.Model.SigLayerId.HasValue) { SigLayer layerToRemove = (from l in layers where l.Id == templateNodeLayerViewModel.Model.SigLayerId.Value select l).FirstOrDefault(); if (layerToRemove != null) { layers.Remove(layerToRemove); } } this.DataService.DataContext.SaveChanges(); List<SigNode> nodeMaps = (from n in nodes where n.SigTemplateId == templateViewModel.Id && n.SigLayer != null orderby n.SigLayer.MapOrder select n).ToList(); int mapOrder = 0; foreach (SigNode nodeMap in nodeMaps) { nodeMap.SigLayer.MapOrder = mapOrder; mapOrder++; } this.DataService.DataContext.SaveChanges(); int nodeOrder = 0; if (parentFolder != null) { foreach (TemplateNodeViewModel child in parentFolder.Nodes) { child.Model.Order = nodeOrder; nodeOrder++; } } else { foreach (TemplateNodeViewModel child in templateViewModel.Nodes) { child.Model.Order = nodeOrder; nodeOrder++; } } this.DataService.DataContext.SaveChanges(); foreach (IMapLayer layer in templateNodeLayerViewModel.Layers) {this.Map.Layers.Remove(layer);} }
private void RemoveFolder(TemplateViewModel templateViewModel, TemplateNodeFolderViewModel folder) { DbSet<SigNode> nodes = this.DataService.GetDbSet<SigNode>(); List<TemplateNodeViewModel> nodeToRemoves = new List<TemplateNodeViewModel>(); List<TemplateNodeViewModel> subNodes = (from n in folder.Nodes select n).ToList(); TemplateNodeFolderViewModel parentFolder = null; foreach (TemplateNodeViewModel node in subNodes) { if (node is TemplateNodeLayerViewModel) { RemoveLayerMetier(templateViewModel, (node as TemplateNodeLayerViewModel)); } else if (node is TemplateNodeFolderViewModel) { TemplateNodeFolderViewModel subFolder = (node as TemplateNodeFolderViewModel); parentFolder = this.GetParentFolder(templateViewModel, templateViewModel.Nodes, subFolder); nodes.Remove(subFolder.Model); this.RemoveFolder(templateViewModel, subFolder); if (parentFolder != null) { parentFolder.Nodes.Remove(subFolder); } else templateViewModel.Nodes.Remove(subFolder); } } parentFolder = this.GetParentFolder(templateViewModel, templateViewModel.Nodes, folder); if (parentFolder != null) { parentFolder.Nodes.Remove(folder); } else templateViewModel.Nodes.Remove(folder); nodes.Remove(folder.Model); this.DataService.DataContext.SaveChanges(); }