public EquipmentUnitType(EquipmentUnitType copy) : base() { _name = copy.name; _description = copy.description; _unitCode = copy.unitCode; AcceptChanges(); }
private ObservableCollection <SearchResult> getChildItems(QueryResultEntitySelector resultEntitySelector, SearchFilterOptions searchFilter, SiteLocation site, EquipmentUnitType equip, SearchResult parent, IList <GenericItemResult> itemResults, ref GenericItemResult selectedItem) { try { // if called on an item (not module or bin) then just return immediately, assume nothing inside a non-container item //if ((parentItem != null) && !(parentItem.isModule || parentItem.isBin)) return null; var parentItem = parent as GenericItemResult; // will be null if not a item, item instance, or item type var bins = new ObservableCollection <SearchResult>(); var ghBins = new BinGroupHeader() { description = "Bins", parent = parent, children = bins }; var modules = new ObservableCollection <SearchResult>(); var ghModules = new ModuleGroupHeader() { description = "Modules", parent = parent, children = modules }; var items = new ObservableCollection <SearchResult>(); var ghItems = new ItemGroupHeader() { description = "Items", parent = parent, children = items }; foreach (var item in itemResults) { // must be child of current parent (null for top level items), and for current site and equipment unit if ((item != parentItem) && ((item.parentId == parentItem?.id) || ((resultEntitySelector == QueryResultEntitySelector.ItemInstance) && (item?.parentId == parentItem?.parentItemId)) || ((parentItem == null) && (Guid.Empty == item.parentId))) && ((site == null) || (item.siteLocationId == site.id)) && ((equip == null) || (item.unitTypeName.Equals(equip.name)))) { // bins if (item.isBin) { bins.Add(item); item.parent = ghBins; } // modules if (item.isModule) { modules.Add(item); item.parent = ghModules; } // items if (!(item.isModule || item.isBin)) { items.Add(item); item.parent = ghItems; } // iff a single item searched for, then select it ItemNumberParser itemNumberParser = new ItemNumberParser(searchFilter.SearchText); if (itemNumberParser.IsItemNumber()) { // itemNumber is ItemType.itemTypeId || '-' || Item.itemId for item instances and items if (string.Equals(item.itemNumber, itemNumberParser.itemTypeId + '-' + itemNumberParser.itemId, StringComparison.InvariantCultureIgnoreCase)) { item.IsExpanded = true; item.IsSelected = true; selectedItem = item; } } // find all children (and so on) for this item if (item.isBin || item.isModule) { item.children = getChildItems(resultEntitySelector, searchFilter, site, equip, item, itemResults, ref selectedItem); } } } // create our child collection, always contains headers and possible list of bins, modules, and items. var children = new ObservableCollection <SearchResult>(new List <GroupHeader>(3)); // bins are not contained within any other item, i.e. top level only; and there are bins if (/*(parentItem == null) &&*/ (bins.Count > 0)) { children.Add(ghBins); } // modules can be in bins or at the top level; and there are modules if (/*((parentItem == null) || (parentItem.isBin)) &&*/ (modules.Count > 0)) { children.Add(ghModules); } // items can be at any level, but only add if there items if (items.Count > 0) { children.Add(ghItems); } return(children); } catch (Exception e) { logger.Error(e, $"Exception in getChildItems - {e.Message}"); logger.Error(e.StackTrace); throw; } }