} // _populateDictionary() /// <summary> /// FOR DISPLAYING CHEMCAT RESULTS /// </summary> /// <param name="C3SearchResultsObj"></param> /// <param name="PropsToHide"></param> /// <returns></returns> private Int32 _populateDictionary( CswRetObjSearchResults C3SearchResultsObj, Collection<string> PropsToHide, string DataService ) { Int32 results = 0; for( int i = 0; i < C3SearchResultsObj.CswC3SearchResults.Count(); i++ )//todo: if results are null { TableNode thisNode = new TableNode(); //Note: For now, we are hardcoding the nodetype as "Chemical" for each results from ChemCatCentral. thisNode.NodeType = _CswNbtResources.MetaData.getObjectClass( CswEnumNbtObjectClass.ChemicalClass ).FirstNodeType; if( null != thisNode.NodeType ) { // default image, overridden below if( thisNode.NodeType.IconFileName != string.Empty ) { thisNode.ThumbnailUrl = CswNbtMetaDataObjectClass.IconPrefix100 + thisNode.NodeType.IconFileName; } else { thisNode.ThumbnailUrl = "Images/icons/300/_placeholder.gif"; } thisNode.AllowView = _CswNbtResources.Permit.canAnyTab( Security.CswEnumNbtNodeTypePermission.View, thisNode.NodeType ); thisNode.AllowEdit = _CswNbtResources.Permit.canAnyTab( Security.CswEnumNbtNodeTypePermission.Edit, thisNode.NodeType ); //C3 results are not nodes and hence they can't be deleted. thisNode.AllowDelete = false; //C3 results CAN however be imported into Nbt IF the user has Create Material Permissions thisNode.AllowImport = _CswNbtResources.Permit.can( CswEnumNbtActionName.Create_Material, _CswNbtResources.CurrentNbtUser ); thisNode.AllowRequest = _CswNbtResources.Permit.can( CswEnumNbtActionName.Submit_Request, _CswNbtResources.CurrentNbtUser ); // Properties int propIndex = 0; CswC3Product[] products = C3SearchResultsObj.CswC3SearchResults; CswC3Product product = products[i]; JObject productObject = JObject.FromObject( product ); IEnumerable properties = productObject.Properties(); foreach( JProperty prop in properties ) { string name = prop.Name; string value = prop.Value.ToString(); if( prop.Name == "TradeName" ) { thisNode.NodeName = prop.Value.ToString(); } if( prop.Name == "ProductId" ) { thisNode.C3ProductId = CswConvert.ToInt32( prop.Value ); } if( prop.Name == "Cdbregno" ) { thisNode.ACDCdbregno = CswConvert.ToInt32( prop.Value ); } TableProp thisProp = new TableProp(); if( PropsToHide == null || false == PropsToHide.Contains( name ) ) { thisProp.PropName = name; thisProp.Gestalt = value; thisNode.Props.Add( propIndex, thisProp ); } propIndex++; } // Thumbnail image -- set to molimage if we have one if( DataService.Equals( "C3" ) && false == String.IsNullOrEmpty( product.MolImage ) ) { thisNode.ThumbnailBase64Str = "data:image/jpeg;base64," + product.MolImage; } else if( DataService.Equals( "ACD" ) ) { thisNode.ThumbnailUrl = "Services/BlobData/getExternalImage?cdbregno=" + thisNode.ACDCdbregno + "&productid=" + product.ProductId + "&uid=" + CswRandom.RandomString(); } if( false == _TableDict.ContainsKey( thisNode.NodeType ) ) { _TableDict.Add( thisNode.NodeType, new Collection<TableNode>() ); } _TableDict[thisNode.NodeType].Add( thisNode ); results++; }//if (null != thisNode.NodeType) }//for( int i = 0; i < C3SearchResultsObj.CswC3SearchResults.Count(); i++ ) return results; } // _populateDictionary()
private Int32 _populateDictionary( ICswNbtTree Tree, Collection<Int32> PropsToHide, Int32 Page = 0, Int32 PageLimit = 0 ) { Int32 results = 0; for( Int32 c = Math.Max( 0, ( Page - 1 ) * PageLimit ); ( c < Tree.getChildNodeCount() && ( PageLimit < 1 || results < PageLimit ) ); c++ ) { Tree.goToNthChild( c ); TableNode thisNode = new TableNode(); thisNode.NodeKey = Tree.getNodeKeyForCurrentPosition(); // Note on FilterToNodeTypeId: // It would be better to filter inside the view, // but it's also much more work, and I'm not even sure this feature will be used. if( null != thisNode.NodeKey && ( Int32.MinValue == _FilterToNodeTypeId || _FilterToNodeTypeId == thisNode.NodeKey.NodeTypeId ) ) { thisNode.NodeType = _CswNbtResources.MetaData.getNodeType( thisNode.NodeKey.NodeTypeId ); if( null != thisNode.NodeType ) { thisNode.NodeId = Tree.getNodeIdForCurrentPosition(); thisNode.NodeName = Tree.getNodeNameForCurrentPosition(); thisNode.Locked = Tree.getNodeLockedForCurrentPosition(); thisNode.Disabled = ( false == Tree.getNodeIncludedForCurrentPosition() ); thisNode.IsFavorite = Tree.getNodeFavoritedForCurrentPosition(); thisNode.ThumbnailUrl = _getThumbnailUrl( Tree.getNodeIconForCurrentPosition() ); thisNode.AllowView = _CswNbtResources.Permit.canAnyTab( Security.CswEnumNbtNodeTypePermission.View, thisNode.NodeType ); thisNode.AllowEdit = _CswNbtResources.Permit.canAnyTab( Security.CswEnumNbtNodeTypePermission.Edit, thisNode.NodeType ); thisNode.AllowDelete = _CswNbtResources.Permit.canNodeType( Security.CswEnumNbtNodeTypePermission.Delete, thisNode.NodeType ); // Properties SortedSet<CswNbtSearchPropOrder.SearchOrder> orderDict = _CswNbtSearchPropOrder.getPropOrderDict( thisNode.NodeKey, _View ); foreach( CswNbtTreeNodeProp PropElm in Tree.getChildNodePropsOfNode() ) { TableProp thisProp = new TableProp(); if( false == PropElm.Hidden ) { thisProp.NodeTypePropId = PropElm.NodeTypePropId; thisProp.ObjectClassPropId = PropElm.ObjectClassPropId; if( PropsToHide == null || false == PropsToHide.Contains( thisProp.NodeTypePropId ) ) { thisProp.PropId = new CswPropIdAttr( thisNode.NodeId, thisProp.NodeTypePropId ); thisProp.FieldType = PropElm.FieldType; thisProp.PropName = PropElm.PropName; thisProp.Gestalt = _Truncate( PropElm.Gestalt ); thisProp.JctNodePropId = PropElm.JctNodePropId; // Special case: Image becomes thumbnail if( thisProp.FieldType == CswEnumNbtFieldType.Image ) { thisNode.ThumbnailUrl = CswNbtNodePropImage.getLink( thisProp.JctNodePropId, thisNode.NodeId ); } if( thisProp.FieldType == CswEnumNbtFieldType.MOL ) { thisNode.ThumbnailUrl = CswNbtNodePropMol.getLink( thisProp.JctNodePropId, thisNode.NodeId ); } else { CswNbtSearchPropOrder.SearchOrder thisOrder = orderDict.FirstOrDefault( Order => Order.NodeTypePropId == thisProp.NodeTypePropId || ( thisProp.ObjectClassPropId != Int32.MinValue && Order.ObjectClassPropId == thisProp.ObjectClassPropId ) ); if( null != thisOrder ) { thisProp.Source = thisOrder.Source; if( thisProp.FieldType == CswEnumNbtFieldType.Button ) { // Include full info for rendering the button // This was done in such a way as to prevent instancing the CswNbtNode object, // which we don't need for Buttons. CswNbtMetaDataNodeTypeProp NodeTypeProp = _CswNbtResources.MetaData.getNodeTypeProp( thisProp.NodeTypePropId ); CswNbtWebServiceTabsAndProps ws = new CswNbtWebServiceTabsAndProps( _CswNbtResources, _CswNbtStatisticsEvents ); Int32 TabId = Int32.MaxValue; if( null != NodeTypeProp.FirstEditLayout ) { TabId = NodeTypeProp.FirstEditLayout.TabId; } JProperty JpPropData = ws.makePropJson( thisNode.NodeId, TabId, NodeTypeProp, null, Int32.MinValue, Int32.MinValue, string.Empty, thisNode.Locked ); thisProp.PropData = (JObject) JpPropData.Value; JObject PropValues = new JObject(); CswNbtNodePropButton.AsJSON( NodeTypeProp, PropValues, PropElm.Field2, PropElm.Field1 ); thisProp.PropData["values"] = PropValues; } if( false == thisNode.Props.ContainsKey( thisOrder.Order ) && false == thisNode.Props.ContainsValue( thisProp ) ) { thisNode.Props.Add( thisOrder.Order, thisProp ); } else { throw new CswDniException( CswEnumErrorType.Error, "A search result with the same value and position already exists in the result set.", "{" + thisNode.NodeType.NodeTypeName + "} entity {" + thisNode.NodeName + "}, Id: {" + thisNode.NodeId + ", has a duplicate {" + thisProp.FieldType + "} property record for {" + thisProp.PropName + "} PropId: {" + thisProp.NodeTypePropId + "}" ); } } } } // if( false == PropsToHide.Contains( NodeTypePropId ) ) } //if (false == CswConvert.ToBoolean(PropElm["hidden"])) } // foreach( XElement PropElm in NodeElm.Elements() ) if( false == _TableDict.ContainsKey( thisNode.NodeType ) ) { _TableDict.Add( thisNode.NodeType, new Collection<TableNode>() ); } _TableDict[thisNode.NodeType].Add( thisNode ); results++; } // if( thisNode.NodeType != null ) } // if(null != thisNode.NodeKey && ( Int32.MinValue == _FilterToNodeTypeId || _FilterToNodeTypeId == thisNode.NodeKey.NodeTypeId ) ) Tree.goToParentNode(); } // for( Int32 c = 0; c < Tree.getChildNodeCount(); c++ ) return results; } // _populateDictionary()