public int?ChooseTemplate(SiteExplorerNodeType templateType) { var picklist = new PickListWindow(User, "Select Template", () => { var service = new MaterialService(User); List <SiteExplorerNode> list = new List <SiteExplorerNode>(); switch (templateType) { case SiteExplorerNodeType.Site: list.AddRange(service.GetSiteTemplates()); break; case SiteExplorerNodeType.SiteVisit: list.AddRange(service.GetSiteVisitTemplates()); break; case SiteExplorerNodeType.Material: list.AddRange(service.GetMaterialTemplates()); break; } return(list.ConvertAll((node) => { return new SiteExplorerNodeViewModel(node); })); }, null); if (picklist.ShowDialog().GetValueOrDefault(false)) { var selected = picklist.SelectedValue as SiteExplorerNodeViewModel; if (selected != null) { return(selected.ElemID); } } return(null); }
protected int FindIDOfParentType(SiteExplorerNodeViewModel node, SiteExplorerNodeType nodeType, int defaultId = -1) { HierarchicalViewModelBase p = node; while (p != null && (p as SiteExplorerNodeViewModel).NodeType != nodeType) { p = p.Parent; } if (p != null) { return((p as SiteExplorerNodeViewModel).ElemID); } return(defaultId); }
public RapidDataEntry(MaterialExplorer explorer, User user, int objectId, SiteExplorerNodeType objectType, SiteExplorerNodeViewModel parent) : base(user, "RDE:" + objectType.ToString() + ":" + objectId) { // Bind input gestures to the commands... AddNewSiteCmd.InputGestures.Add(new KeyGesture(Key.T, ModifierKeys.Control)); AddNewSiteVisitCmd.InputGestures.Add(new KeyGesture(Key.I, ModifierKeys.Control)); AddNewMaterialCmd.InputGestures.Add(new KeyGesture(Key.M, ModifierKeys.Control)); MoveNextCmd.InputGestures.Add(new KeyGesture(Key.N, ModifierKeys.Control)); MovePreviousCmd.InputGestures.Add(new KeyGesture(Key.P, ModifierKeys.Control)); UnlockAllCmd.InputGestures.Add(new KeyGesture(Key.U, ModifierKeys.Control)); InitializeComponent(); _objectId = objectId; _objectType = objectType; ParentNode = parent; Explorer = explorer; Loaded += RapidDataEntryLoaded; ChangesCommitted += RapidDataEntryChangesCommitted; }
public static LookupType GetLookupTypeFromNodeType(SiteExplorerNodeType nodeType) { switch (nodeType) { case SiteExplorerNodeType.Material: return(LookupType.Material); case SiteExplorerNodeType.Region: return(LookupType.Region); case SiteExplorerNodeType.Site: return(LookupType.Site); case SiteExplorerNodeType.SiteVisit: return(LookupType.SiteVisit); case SiteExplorerNodeType.Trap: return(LookupType.Trap); default: return(LookupType.Unknown); } }
private void AddToMap(SiteExplorerNodeType sourceType, SiteExplorerNodeType destType, Action <SiteExplorerNodeViewModel, SiteExplorerNodeViewModel> action) { _DropMap[MakeDropMapKey(sourceType, destType)] = action; }
internal PinnableObject CreatePinnable(string elemType, int elemID) { SiteExplorerNodeType nodeType = (SiteExplorerNodeType)Enum.Parse(typeof(SiteExplorerNodeType), elemType); return(new PinnableObject(MaterialPlugin.MATERIAL_PLUGIN_NAME, GetLookupTypeFromNodeType(nodeType), elemID)); }
public List<SiteExplorerNode> GetTopLevelExplorerItems(SiteExplorerNodeType parentType = SiteExplorerNodeType.Region) { int parentId = 0; if (parentType == SiteExplorerNodeType.Unplaced) { parentId = -1; } return GetExplorerElementsForParent(parentId, parentType); }
public List<SiteExplorerNode> GetSiteExplorerNodeParentage(int elemId, SiteExplorerNodeType nodeType) { var results = new List<SiteExplorerNode>(); var node = GetSiteExplorerNode(elemId, nodeType); while (node != null) { results.Insert(0, node); node = GetSiteExplorerNode(node.ParentID, node.ParentNodeType); } return results; }
internal SiteExplorerNodeViewModel AddNewNode(HierarchicalViewModelBase parent, SiteExplorerNodeType nodeType, Func <SiteExplorerNodeViewModel, DatabaseCommand> commandFactoryFunction) { if (parent != null) { parent.IsExpanded = true; } var model = new SiteExplorerNode(); model.Name = string.Format("<New {0}>", nodeType.ToString()); if (parent is SiteExplorerNodeViewModel) { model.ParentID = (parent as SiteExplorerNodeViewModel).ElemID; } model.ElemType = nodeType.ToString(); model.ElemID = -1; model.RegionID = -1; var viewModel = new SiteExplorerNodeViewModel(model); if (parent != null) { viewModel.Parent = parent; parent.Children.Add(viewModel); } viewModel.IsSelected = true; viewModel.IsRenaming = true; if (commandFactoryFunction != null) { RegisterPendingChange(commandFactoryFunction(viewModel), this); } return(viewModel); }
private RDESiteViewModel BuildModel(int objectId, SiteExplorerNodeType objectType) { var service = new MaterialService(User); var supportService = new SupportService(User); RDESiteViewModel root = null; List<RDEMaterial> material; if (objectId < 0) { root = CreateSiteViewModel(new RDESite { LocalType=0 }); root.Locked = false; RegisterPendingChange(new InsertRDESiteCommand(root.Model)); var siteVisit = AddNewSiteVisit(root); AddNewMaterial(siteVisit); return root; } switch (objectType) { case SiteExplorerNodeType.Site: var sites = service.GetRDESites(new[] { objectId }); if (sites.Count > 0) { root = CreateSiteViewModel(sites[0]); var siteVisits = service.GetRDESiteVisits(new[] {root.SiteID}, RDEObjectType.Site); var idList = new List<Int32>(); // This collection will keep track of every site visit id for later use... root.SiteVisits = new ObservableCollection<ViewModelBase>(siteVisits.ConvertAll(sv => { var vm = CreateSiteVisitViewModel(sv, root); idList.Add(vm.SiteVisitID); return vm; })); // This service call gets all the material for all site visits, saving multiple round trips to the database material = service.GetRDEMaterial(idList.ToArray(), RDEObjectType.SiteVisit); // But now we have to attach the material to the right visit... foreach (RDESiteVisitViewModel sv in root.SiteVisits) { // select out which material belongs to the current visit... RDESiteVisitViewModel sv1 = sv; var selected = material.Where(m => m.SiteVisitID == sv1.SiteVisitID); // create the material view models and attach to the visit. sv.Material = CreateMaterialViewModels(selected, sv); } } break; case SiteExplorerNodeType.SiteVisit: var visits = service.GetRDESiteVisits(new[] { objectId }); if (visits.Count > 0) { // get the site ... sites = service.GetRDESites(new[] { visits[0].SiteID }); if (sites.Count > 0) { root = CreateSiteViewModel(sites[0]); var visitModel = CreateSiteVisitViewModel(visits[0], root); // get the material... material = service.GetRDEMaterial(new[] { visitModel.SiteVisitID }, RDEObjectType.SiteVisit); CreateMaterialViewModels(material, visitModel); } } break; case SiteExplorerNodeType.Material: material = service.GetRDEMaterial(new[] { objectId }); if (material.Count > 0) { var m = material[0]; // Get the Visit... visits = service.GetRDESiteVisits(new[] { m.SiteVisitID }); if (visits.Count > 0) { // Get the site... sites = service.GetRDESites(new[] { visits[0].SiteID }); if (sites.Count > 0) { root = CreateSiteViewModel(sites[0]); var siteVisit = CreateSiteVisitViewModel(visits[0], root); CreateMaterialViewModels(material, siteVisit); } } } break; } if (root != null) { // Get a single list of all the material view models loaded... var materialList = new List<RDEMaterialViewModel>(); root.SiteVisits.ForEach(vm => { var sv = vm as RDESiteVisitViewModel; if (sv != null) { sv.Material.ForEach(vm2 => { var m = vm2 as RDEMaterialViewModel; materialList.Add(m); }); } }); var materialIds = materialList.Select(m => m.MaterialID).ToArray(); // for the material id list we can extract all the subparts in one round trip... var subparts = service.GetMaterialParts(materialIds); // and associates as well. This means we only need one pass through the material list in order to // hook up subordinate records var associates = supportService.GetAssociates(TraitCategoryType.Material.ToString(), materialIds); // But we have to hook them back up to the right material. foreach (RDEMaterialViewModel m in materialList) { var mlocal = m; var selectedSubParts = subparts.Where(part => part.MaterialID == mlocal.MaterialID); m.SubParts = new ObservableCollection<ViewModelBase>(selectedSubParts.Select(part => { var vm = new MaterialPartViewModel(part) { Locked = mlocal.Locked }; vm.DataChanged += SubPartDataChanged; return vm; })); RDEMaterialViewModel m1 = m; var selectedAssociates = associates.Where(assoc => assoc.FromIntraCatID == m1.MaterialID || assoc.ToIntraCatID == m1.MaterialID); m.Associates = new ObservableCollection<ViewModelBase>(selectedAssociates.Select(assoc => { var vm = new AssociateViewModel(assoc); vm.DataChanged += AssociateDataChanged; return vm; })); } } return root; }
private string MakeDropMapKey(SiteExplorerNodeType sourceType, SiteExplorerNodeType destType) { return string.Format("{0}_{1}", sourceType.ToString(), destType.ToString()); }
private void AddToMap(SiteExplorerNodeType sourceType, SiteExplorerNodeType destType, Action<SiteExplorerNodeViewModel, SiteExplorerNodeViewModel> action) { _DropMap[MakeDropMapKey(sourceType, destType)] = action; }
internal SiteExplorerNodeViewModel AddNewNode(HierarchicalViewModelBase parent, SiteExplorerNodeType nodeType, Func<SiteExplorerNodeViewModel, DatabaseCommand> commandFactoryFunction) { if (parent != null) { parent.IsExpanded = true; } var model = new SiteExplorerNode(); model.Name = string.Format("<New {0}>", nodeType.ToString()); if (parent is SiteExplorerNodeViewModel) { model.ParentID = (parent as SiteExplorerNodeViewModel).ElemID; } model.ElemType = nodeType.ToString(); model.ElemID = -1; model.RegionID = -1; var viewModel = new SiteExplorerNodeViewModel(model); if (parent != null) { viewModel.Parent = parent; parent.Children.Add(viewModel); } viewModel.IsSelected = true; viewModel.IsRenaming = true; if (commandFactoryFunction != null) { RegisterPendingChange(commandFactoryFunction(viewModel), this); } return viewModel; }
public int? ChooseTemplate(SiteExplorerNodeType templateType) { var picklist = new PickListWindow(User, "Select Template", () => { var service = new MaterialService(User); List<SiteExplorerNode> list = new List<SiteExplorerNode>(); switch (templateType) { case SiteExplorerNodeType.Site: list.AddRange(service.GetSiteTemplates()); break; case SiteExplorerNodeType.SiteVisit: list.AddRange(service.GetSiteVisitTemplates()); break; case SiteExplorerNodeType.Material: list.AddRange(service.GetMaterialTemplates()); break; } return list.ConvertAll((node) => { return new SiteExplorerNodeViewModel(node); }); }, null); if (picklist.ShowDialog().GetValueOrDefault(false)) { var selected = picklist.SelectedValue as SiteExplorerNodeViewModel; if (selected != null) { return selected.ElemID; } } return null; }
public static LookupType GetLookupTypeFromNodeType(SiteExplorerNodeType nodeType) { switch (nodeType) { case SiteExplorerNodeType.Material: return LookupType.Material; case SiteExplorerNodeType.Region: return LookupType.Region; case SiteExplorerNodeType.Site: return LookupType.Site; case SiteExplorerNodeType.SiteVisit: return LookupType.SiteVisit; case SiteExplorerNodeType.Trap: return LookupType.Trap; default: return LookupType.Unknown; } }
private string MakeDropMapKey(SiteExplorerNodeType sourceType, SiteExplorerNodeType destType) { return(string.Format("{0}_{1}", sourceType.ToString(), destType.ToString())); }
public List<SiteExplorerNode> GetExplorerElementsForParent(int parentID, SiteExplorerNodeType parentElemType) { return GetExplorerElementsForParent(parentID, parentElemType.ToString()); }
public SiteExplorerNodeWithParentType GetSiteExplorerNode(int elemId, SiteExplorerNodeType nodeType) { var childList = GetExplorerElementsForParent(elemId, nodeType); switch (nodeType) { case SiteExplorerNodeType.Material: var m = GetMaterial(elemId); if (m != null) { var site = GetSite(m.SiteID); return new SiteExplorerNodeWithParentType {ParentNodeType = SiteExplorerNodeType.SiteVisit, ElemID = elemId, ElemType = nodeType.ToString(), IsTemplate = m.IsTemplate, Name = m.MaterialName, NumChildren = childList.Count, ParentID = m.SiteVisitID, RegionID = site.PoliticalRegionID, RegionName = site.PoliticalRegion }; } break; case SiteExplorerNodeType.SiteVisit: var visit = GetSiteVisit(elemId); if (visit != null) { var site = GetSite(visit.SiteID); if (site != null) { return new SiteExplorerNodeWithParentType {ParentNodeType = SiteExplorerNodeType.Site, ElemID = elemId, ElemType = nodeType.ToString(), IsTemplate = visit.IsTemplate, Name = visit.SiteVisitName, NumChildren = childList.Count, ParentID = visit.SiteID, RegionID = site.PoliticalRegionID, RegionName = site.PoliticalRegion }; } } break; case SiteExplorerNodeType.Site: var site2 = GetSite(elemId); if (site2 != null) { var parentType = site2.SiteGroupID > 0 ? SiteExplorerNodeType.SiteGroup : SiteExplorerNodeType.Region; return new SiteExplorerNodeWithParentType { ParentNodeType = parentType, ElemID = elemId, ElemType = nodeType.ToString(), IsTemplate = site2.IsTemplate, Name = site2.SiteName, NumChildren = childList.Count, ParentID = site2.SiteGroupID > 0 ? site2.SiteGroupID : site2.PoliticalRegionID, RegionID = site2.PoliticalRegionID, RegionName = site2.PoliticalRegion }; } break; case SiteExplorerNodeType.Trap: var trap = GetTrap(elemId); if (trap != null) { var site3 = GetSite(elemId); if (site3 != null) { var parentType = SiteExplorerNodeType.Site; return new SiteExplorerNodeWithParentType { ParentNodeType = parentType, ElemID = elemId, ElemType = nodeType.ToString(), IsTemplate = false, Name = trap.TrapName, NumChildren = childList.Count, ParentID = trap.SiteID, RegionID = site3.PoliticalRegionID, RegionName = site3.PoliticalRegion }; } } break; case SiteExplorerNodeType.Region: var region = GetRegion(elemId); if (region != null) { var parentId = GetRegionParentID(region); return new SiteExplorerNodeWithParentType { ParentNodeType = SiteExplorerNodeType.Region, ElemID = elemId, ElemType = nodeType.ToString(), IsTemplate = false, Name = region.Name, NumChildren = childList.Count, ParentID = parentId, RegionID = region.PoliticalRegionID, RegionName = region.Name }; } break; case SiteExplorerNodeType.SiteGroup: var group = GetSiteGroup(elemId); if (group != null) { var parentType = group.ParentType == 2 ? SiteExplorerNodeType.SiteGroup : SiteExplorerNodeType.Region; int parentId = parentType == SiteExplorerNodeType.SiteGroup ? group.ParentID : group.PoliticalRegionID; return new SiteExplorerNodeWithParentType { ParentNodeType = parentType, ElemID = elemId, ElemType = nodeType.ToString(), IsTemplate = false, Name = group.SiteGroupName, NumChildren = childList.Count, ParentID = parentId, RegionID = group.PoliticalRegionID, RegionName = "" }; } break; } return null; }
private SiteExplorerNodeViewModel ViewModelFromObjectID(SiteExplorerNodeType nodeType, int objectID) { var service = new MaterialService(User); SiteExplorerNode model = new SiteExplorerNode(); model.ElemType = nodeType.ToString(); switch (nodeType) { case SiteExplorerNodeType.Region: var region = service.GetRegion(objectID); if (region != null) { model.ElemID = region.PoliticalRegionID; model.Name = region.Name; model.RegionID = region.PoliticalRegionID; return(new SiteExplorerNodeViewModel(model)); } break; case SiteExplorerNodeType.Site: var site = service.GetSite(objectID); if (site != null) { model.ElemID = site.SiteID; model.Name = site.SiteName; model.RegionID = site.PoliticalRegionID; model.IsTemplate = site.IsTemplate; return(new SiteExplorerNodeViewModel(model)); } break; case SiteExplorerNodeType.SiteVisit: var sitevisit = service.GetSiteVisit(objectID); if (sitevisit != null) { model.ElemID = sitevisit.SiteVisitID; model.Name = sitevisit.SiteVisitName; model.IsTemplate = sitevisit.IsTemplate; return(new SiteExplorerNodeViewModel(model)); } break; case SiteExplorerNodeType.Trap: var trap = service.GetTrap(objectID); if (trap != null) { model.ElemID = trap.TrapID; model.Name = trap.TrapName; return(new SiteExplorerNodeViewModel(model)); } break; case SiteExplorerNodeType.Material: var material = service.GetMaterial(objectID); if (material != null) { model.ElemID = material.MaterialID; model.Name = material.MaterialName; model.IsTemplate = material.IsTemplate; return(new SiteExplorerNodeViewModel(model)); } break; default: throw new Exception("Unhandled node type: " + nodeType); } return(null); }
public static ContextMenu BuildForFavorite(SiteFavoriteViewModel fav, MaterialExplorer explorer) { if (fav == null) { return(null); } ContextMenuBuilder builder = new ContextMenuBuilder(null); builder.New("Refresh").Handler(() => { explorer.Refresh(); }).End(); if (!fav.IsGroup) { builder.Separator(); builder.New("Rename").Handler(() => { fav.IsRenaming = true; }).End(); // A little bit of a hack to reuse the edit code...simulate a site explorer node, although its not really there... SiteExplorerNode model = new SiteExplorerNode(); model.ElemID = fav.ElemID; model.ElemType = fav.ElemType; model.Name = fav.Name; var node = new SiteExplorerNodeViewModel(model); var pinnable = explorer.CreatePinnable(node); if (pinnable != null) { builder.Separator(); builder.New("_Pin to pin board").Handler(() => { PluginManager.Instance.PinObject(pinnable); }); } var mnuReports = CreateReportMenuItems(node, explorer); if (mnuReports.HasItems) { builder.Separator(); builder.AddMenuItem(mnuReports); } SiteExplorerNodeType type = (SiteExplorerNodeType)Enum.Parse(typeof(SiteExplorerNodeType), fav.ElemType); if (type != SiteExplorerNodeType.SiteGroup) { builder.Separator(); builder.New("Edit Details...").Handler(() => { switch (type) { case SiteExplorerNodeType.Region: explorer.EditRegion(node); break; case SiteExplorerNodeType.Site: explorer.EditSite(node); break; case SiteExplorerNodeType.SiteVisit: explorer.EditSiteVisit(node); break; case SiteExplorerNodeType.Trap: explorer.EditTrap(node); break; case SiteExplorerNodeType.Material: explorer.EditMaterial(node); break; default: throw new Exception("[Details] Unhandled site explorer element type: " + node.ElemType); } }).End(); var rdeNodeTypes = new List <SiteExplorerNodeType>(new SiteExplorerNodeType[] { SiteExplorerNodeType.Material, SiteExplorerNodeType.Site, SiteExplorerNodeType.SiteVisit }); if (node != null && rdeNodeTypes.Contains(node.NodeType)) { builder.New("Open in Rapid Data Entry...").Handler(() => { explorer.EditRDE(node); }).End(); } else { builder.New("Rapid Data Entry...").Handler(() => { explorer.EditRDE(node); }).End(); } } } return(builder.ContextMenu); }