} // getMergeInfo() private void _addMergeNodes(MergeInfoData ret, CswPrimaryKey NodeId1, CswPrimaryKey NodeId2, CswNbtMetaDataNodeTypeProp NodeReferenceProp = null) { CswNbtNode Node1 = _CswNbtResources.Nodes[NodeId1]; CswNbtNode Node2 = _CswNbtResources.Nodes[NodeId2]; if (null != Node1 && null != Node2) { // Make sure there isn't already a node pair for these nodes if (false == ret.NodePairs.Any(np => (np.Node1Id == Node1.NodeId.ToString() && np.Node2Id == Node2.NodeId.ToString()) || (np.Node1Id == Node2.NodeId.ToString() && np.Node2Id == Node1.NodeId.ToString()))) { CswNbtMetaDataNodeType Node1NT = Node1.getNodeType(); MergeInfoData.MergeInfoNodePair NodePair = new MergeInfoData.MergeInfoNodePair(); NodePair.NodeReferences = new Collection <MergeInfoData.MergeInfoNodeReference>(); NodePair.NodeTypeName = Node1NT.NodeTypeName; NodePair.Node1Id = Node1.NodeId.ToString(); NodePair.Node2Id = Node2.NodeId.ToString(); NodePair.Node1Name = Node1.NodeName; NodePair.Node2Name = Node2.NodeName; if (null != NodeReferenceProp) { NodePair.NodeReferencePropId = NodeReferenceProp.PropId; } else { NodePair.NodeReferencePropId = Int32.MinValue; } foreach (CswNbtNodePropWrapper Prop1 in Node1.Properties.Where(p => (null == NodeReferenceProp || p.NodeTypePropId != NodeReferenceProp.PropId))) { CswNbtNodePropWrapper Prop2 = Node2.Properties[Prop1.NodeTypePropId]; if (null == Prop2 || Prop1.Gestalt != Prop2.Gestalt) { NodePair.Properties.Add(new MergeInfoData.MergeInfoProperty() { PropName = Prop1.PropName, NodeTypePropId = Prop1.NodeTypePropId, Node1Value = Prop1.Gestalt, Node2Value = Prop2.Gestalt }); } // if( null == Prop2 || Prop1.Gestalt != Prop2.Gestalt ) } // foreach( CswNbtNodePropWrapper Prop1 in Node1.Properties ) ret.NodePairs.Add(NodePair); // If two nodes that formerly related to each of node1 and node2 now relate to the merged target, // and they now would be compound unique violations, we have to merge those too. // First, find references that point to the merged nodes foreach (CswNbtMetaDataNodeTypeProp thisProp in _CswNbtResources.MetaData.getNodeTypeProps().Where(p => p.IsNodeReference() && p.FkMatches(Node1.getNodeType()))) { // Find unique key sets for nodes using this reference that point to either node1 or node2 Dictionary <CswDelimitedString, CswPrimaryKey> Node1UniqueKeysDict = _getUniqueKeysDict(NodePair, Node1, thisProp); Dictionary <CswDelimitedString, CswPrimaryKey> Node2UniqueKeysDict = _getUniqueKeysDict(NodePair, Node2, thisProp); // Look for redundant keys to indicate a potential unique violation foreach (CswDelimitedString key in Node1UniqueKeysDict.Keys) { if (Node2UniqueKeysDict.ContainsKey(key)) { // unique violation! gotta merge these too. _addMergeNodes(ret, Node1UniqueKeysDict[key], Node2UniqueKeysDict[key], thisProp); } } // foreach( CswDelimitedString key in Node1UniqueKeysDict.Keys ) } // foreach( CswNbtMetaDataNodeTypeProp thisProp in _CswNbtResources.MetaData.getNodeTypeProps().Where( p => p.IsNodeReference() ) ) // Special case: UserSelect properties if (Node1NT.getObjectClassValue() == CswEnumNbtObjectClass.UserClass) { foreach (CswNbtMetaDataNodeTypeProp thisUserSelProp in _CswNbtResources.MetaData.getNodeTypeProps(CswEnumNbtFieldType.UserSelect)) { // Create a view of nodes that point to either merged node via this reference CswNbtView view = new CswNbtView(_CswNbtResources); CswNbtViewRelationship rel1 = view.AddViewRelationship(thisUserSelProp.getNodeType(), false); view.AddViewPropertyAndFilter(rel1, thisUserSelProp, Conjunction: CswEnumNbtFilterConjunction.And, FilterMode: CswEnumNbtFilterMode.Contains, Value: Node1.NodeId.PrimaryKey.ToString()); view.AddViewPropertyAndFilter(rel1, thisUserSelProp, Conjunction: CswEnumNbtFilterConjunction.Or, FilterMode: CswEnumNbtFilterMode.Contains, Value: Node2.NodeId.PrimaryKey.ToString()); // Add nodes with matching UserSelect properties to NodeReferences for later updating ICswNbtTree tree = _CswNbtResources.Trees.getTreeFromView(view, RequireViewPermissions: false, IncludeHiddenNodes: true, IncludeSystemNodes: true); for (Int32 c = 0; c < tree.getChildNodeCount(); c++) { tree.goToNthChild(c); NodePair.NodeReferences.Add(new MergeInfoData.MergeInfoNodeReference() { NodeId = tree.getNodeIdForCurrentPosition().ToString(), NodeTypePropId = thisUserSelProp.PropId }); tree.goToParentNode(); } // for( Int32 c = 0; c < tree.getChildNodeCount(); c++ ) } // foreach( CswNbtMetaDataNodeTypeProp thisUserSelProp in _CswNbtResources.MetaData.getNodeTypeProps( CswEnumNbtFieldType.UserSelect ) ) } // if( Node1NT.getObjectClassValue() == CswEnumNbtObjectClass.UserClass ) } // if(false == ret.NodePairs.Any( ... )) } // if( null != Node1 && null != Node2 ) } // _addMergeNodes()
/// <summary> /// Create a dictionary of the unique key values of related nodes /// As a side effect, also populate MergeInfoData.NodePair.NodeReferences /// </summary> private Dictionary <CswDelimitedString, CswPrimaryKey> _getUniqueKeysDict(MergeInfoData.MergeInfoNodePair NodePair, CswNbtNode Node, CswNbtMetaDataNodeTypeProp NodeReferenceProp) { Dictionary <CswDelimitedString, CswPrimaryKey> ret = new Dictionary <CswDelimitedString, CswPrimaryKey>(); char delimiter = '|'; // Find unique properties for this reference's nodetype IEnumerable <CswNbtMetaDataNodeTypeProp> UniqueProps = NodeReferenceProp.getNodeType().getUniqueProps(); // Create a view of nodes that point to the target node via this reference CswNbtView view = new CswNbtView(_CswNbtResources); CswNbtViewRelationship rel1 = view.AddViewRelationship(Node.getNodeType(), false); rel1.NodeIdsToFilterIn.Add(Node.NodeId); CswNbtViewRelationship rel2 = view.AddViewRelationship(rel1, CswEnumNbtViewPropOwnerType.Second, NodeReferenceProp, false); foreach (CswNbtMetaDataNodeTypeProp uniqueProp in UniqueProps) { view.AddViewProperty(rel2, uniqueProp); } // Iterate children and store unique property values in a dictionary key ICswNbtTree tree = _CswNbtResources.Trees.getTreeFromView(view, RequireViewPermissions: false, IncludeHiddenNodes: true, IncludeSystemNodes: true); if (tree.getChildNodeCount() > 0) { tree.goToNthChild(0); for (Int32 c = 0; c < tree.getChildNodeCount(); c++) { tree.goToNthChild(c); CswPrimaryKey thisNodeId = tree.getNodeIdForCurrentPosition(); // Populate MergeInfoData.NodePair.NodeReferences while we're here NodePair.NodeReferences.Add(new MergeInfoData.MergeInfoNodeReference() { NodeId = thisNodeId.ToString(), NodeTypePropId = NodeReferenceProp.PropId }); CswDelimitedString key; if (_AllUniqueKeys.ContainsKey(thisNodeId)) { // If we've seen this node before, use the existing key but override the merge property // (this will allow us to merge correctly if a nodetype has // multiple compound unique references that are all involved in the merge) key = _AllUniqueKeys[thisNodeId]; for (Int32 u = 0; u < UniqueProps.Count(); u++) { if (UniqueProps.ElementAt(u).PropId == NodeReferenceProp.PropId) { // This value will be equal after the merge key[u] = "[mergeresult]"; } } // foreach( CswNbtMetaDataNodeTypeProp uniqueProp in UniqueProps ) } // if( _AllUniqueKeys.ContainsKey( thisNodeId ) ) else { // generate a new key key = new CswDelimitedString(delimiter); foreach (CswNbtMetaDataNodeTypeProp uniqueProp in UniqueProps) { CswNbtTreeNodeProp prop = tree.getChildNodePropsOfNode().FirstOrDefault(p => p.NodeTypePropId == uniqueProp.PropId); if (null != prop) { if (prop.NodeTypePropId == NodeReferenceProp.PropId) { // This value will be equal after the merge key.Add("[mergeresult]"); } else { key.Add(prop.Gestalt); } } else { key.Add(""); } } // foreach( CswNbtMetaDataNodeTypeProp uniqueProp in UniqueProps ) } // if-else( _AllUniqueKeys.ContainsKey( thisNodeId ) ) if (key.Count > 0) { ret.Add(key, thisNodeId); _AllUniqueKeys[thisNodeId] = key; } tree.goToParentNode(); } // for( Int32 c = 0; c < tree.getChildNodeCount(); c++ ) } // if( tree.getChildNodeCount() > 0 ) return(ret); } // _getUniqueKeysDict()
public Node(CswPrimaryKey inNodeId, string inNodeName) { NodeId = inNodeId; NodeName = inNodeName; }
public CswNbtNode(CswNbtResources CswNbtResources, CswNbtNodeWriter CswNbtNodeWriter, Int32 NodeTypeId, CswEnumNbtNodeSpecies NodeSpecies, CswPrimaryKey NodeId, Int32 UniqueId, CswDateTime Date, bool IsTemp = false) { _CswNbtResources = CswNbtResources; _CswNbtNodeWriter = CswNbtNodeWriter; _UniqueId = UniqueId; _NodeId = NodeId; _NodeTypeId = NodeTypeId; _NodeSpecies = NodeSpecies; _IsTemp = IsTemp; _Date = Date; _CswNbtNodePropColl = new CswNbtNodePropColl(CswNbtResources, this); }//ctor()
} // getViews() public CswNbtViewId getViewIdByName(string ViewName, CswEnumNbtViewVisibility Visibility, CswPrimaryKey VisibilityRoleId, CswPrimaryKey VisibilityUserId) { CswTableSelect ViewsTable = _CswNbtResources.makeCswTableSelect("CswNbtViewSelect_viewExists_select", "node_views"); string WhereClause = "where viewname = '" + CswTools.SafeSqlParam(ViewName) + "'"; if (Visibility == CswEnumNbtViewVisibility.Role) { WhereClause += " and visibility = 'Role' and roleid = " + VisibilityRoleId.PrimaryKey.ToString(); } else if (Visibility == CswEnumNbtViewVisibility.User) { WhereClause += " and visibility = 'User' and userid = " + VisibilityUserId.PrimaryKey.ToString(); } else { WhereClause += " and visibility = '" + Visibility.ToString() + "'"; } return(new CswNbtViewId(Convert.ToInt32(ViewsTable.getTable(new CswCommaDelimitedString("nodeviewid"), WhereClause).Rows[0]["nodeviewid"]))); }
public void assignPropsToLocations( string LocationNodeKeys, bool UpdateInventoryGroup, string SelectedInventoryGroupNodeId, bool UpdateAllowInventory, string AllowInventory, bool UpdateControlZone, string SelectedControlZoneNodeId, bool UpdateStorageCompatability, string SelectedImages ) { if( false == string.IsNullOrEmpty( LocationNodeKeys ) ) { ///we don't pre-load he allowinventory value because there's no extra expense ///to doing so repeatedly in the loop CswNbtNode InventoryGroupNode = null; if( ( true == UpdateInventoryGroup ) && ( false == string.IsNullOrEmpty( SelectedInventoryGroupNodeId ) ) ) { CswPrimaryKey IGKey = new CswPrimaryKey(); IGKey.FromString( SelectedInventoryGroupNodeId ); InventoryGroupNode = _CswNbtResources.Nodes[IGKey]; } CswNbtNode ControlZoneNode = null; if( ( true == UpdateControlZone ) && ( false == string.IsNullOrEmpty( SelectedControlZoneNodeId ) ) ) { CswPrimaryKey IGKey = new CswPrimaryKey(); IGKey.FromString( SelectedControlZoneNodeId ); ControlZoneNode = _CswNbtResources.Nodes[IGKey]; } CswDelimitedString Images = new CswDelimitedString( ',' ); if( true == UpdateStorageCompatability ) { if( false == string.IsNullOrEmpty( SelectedImages ) ) { Images.FromString( SelectedImages ); } } foreach( string CurrentLocationKey in LocationNodeKeys.Split( ',' ) ) { if( false == string.IsNullOrEmpty( CurrentLocationKey ) ) { CswNbtNodeKey LKey = new CswNbtNodeKey( CurrentLocationKey ); CswNbtObjClassLocation CurrentLocationNode = _CswNbtResources.Nodes[LKey]; if( null != CurrentLocationNode ) { if( true == UpdateInventoryGroup ) { if( null != InventoryGroupNode ) { CurrentLocationNode.InventoryGroup.RelatedNodeId = InventoryGroupNode.NodeId; } else { CurrentLocationNode.InventoryGroup.RelatedNodeId = null; } } if( true == UpdateControlZone ) { if( null != ControlZoneNode ) { CurrentLocationNode.ControlZone.RelatedNodeId = ControlZoneNode.NodeId; } else { CurrentLocationNode.ControlZone.RelatedNodeId = null; } } if( UpdateAllowInventory ) { CurrentLocationNode.AllowInventory.Checked = CswConvert.ToTristate( AllowInventory ); } if( UpdateStorageCompatability ) { CurrentLocationNode.StorageCompatibility.Value = Images; } CurrentLocationNode.postChanges( true ); }//if current key yielded a node } //if there is a location keye } //iterate locations }//if we have location keys }//assignInventoryGroupToLocations()
public bool triggerOnButtonClick(NbtButtonData ButtonData) { bool Ret = false; //1: We have Button Data if (null != ButtonData) { //2: Before the Button Click, Save the Node if any tabs and properties have been provided Collection <Int32> TabIds = new Collection <int>(); if (null != ButtonData.TabIds) { TabIds = ButtonData.TabIds.ToIntCollection(ExcludeMinVal: true, ExcludeDuplicates: true); } if (TabIds.Count > 0) { foreach (Int32 TabId in TabIds) { _onBeforeButtonClickSaveProps(CswConvert.ToString(TabId), ButtonData); } } else { if (_CswNbtResources.EditMode == CswEnumNbtNodeEditMode.Add) { //Client-side, we are defining a tabid as EditMode + '_tab'. This isn't great, but it's what we've got right now. _onBeforeButtonClickSaveProps(CswEnumNbtNodeEditMode.Add + "_tab", ButtonData); } } //3: If we're adding, we're always refreshing on add as the default option if (_CswNbtResources.EditMode == CswEnumNbtNodeEditMode.Add) { ButtonData.Action = CswEnumNbtButtonAction.refreshonadd; } //4: If this is the Save property, we're done; else execute the click event if (null != ButtonData.NodeTypeProp && ButtonData.NodeTypeProp.IsSaveProp) { Ret = true; } else { Ret = onButtonClick(ButtonData); } //5: If we had tabs or props coming in, we should get the current values to send back (they probably changed after the button click) if (TabIds.Count > 0) { foreach (Int32 TabId in TabIds) { _onAfterButtonClickSaveProps(CswConvert.ToString(TabId), ButtonData); } if (ButtonData.NodeIds.Count > 1) { Collection <CswPrimaryKey> MultiNodePks = new Collection <CswPrimaryKey>(); foreach (string CopyToNodeId in ButtonData.NodeIds) { CswPrimaryKey MultiNodePk = CswConvert.ToPrimaryKey(CopyToNodeId); if (null != MultiNodePk && MultiNodePk != NodeId) { MultiNodePks.Add(MultiNodePk); } } if (ButtonData.NodeIds.Count >= CswNbtBatchManager.getBatchThreshold(_CswNbtResources)) { if (ButtonData.PropIds.Count > 0) { Collection <Int32> NodeTypePropIds = new Collection <Int32>(); foreach (string PropIdAttrStr in ButtonData.PropIds) { CswPropIdAttr PropIdAttr = new CswPropIdAttr(PropIdAttrStr); NodeTypePropIds.Add(PropIdAttr.NodeTypePropId); } CswNbtBatchOpMultiEdit op = new CswNbtBatchOpMultiEdit(_CswNbtResources); CswNbtObjClassBatchOp Batch = op.makeBatchOp(Node, MultiNodePks, NodeTypePropIds); ButtonData.Action = CswEnumNbtButtonAction.batchop; ButtonData.Data["batch"] = Batch.Node.NodeLink; } if (ButtonData.MultiClick && null != ButtonData.NodeTypeProp) { CswNbtBatchOpMultiButtonClick op = new CswNbtBatchOpMultiButtonClick(_CswNbtResources); CswNbtObjClassBatchOp Batch = op.makeBatchOp(MultiNodePks, ButtonData.NodeTypeProp.PropId); ButtonData.Action = CswEnumNbtButtonAction.batchop; ButtonData.Data["batch"] = Batch.Node.NodeLink; } } else { if (ButtonData.PropIds.Count > 0) { CswNbtSdTabsAndProps Sd = new CswNbtSdTabsAndProps(_CswNbtResources); Sd.copyPropValues(Node, ButtonData.NodeIds, ButtonData.PropIds); } if (ButtonData.MultiClick) { foreach (CswPrimaryKey MultiNodeId in MultiNodePks) { CswNbtNode MultiNode = _CswNbtResources.Nodes[MultiNodeId]; if (null != MultiNode) { MultiNode.ObjClass.onButtonClick(ButtonData); } } } } } } else { if (_CswNbtResources.EditMode == CswEnumNbtNodeEditMode.Add) { _onAfterButtonClickSaveProps(CswEnumNbtNodeEditMode.Add + "_tab", ButtonData); } } } return(Ret); }
// TODO This is probably a performance problem! private CswNbtObjClassRole _getRole(CswPrimaryKey RoleId) { return(_CswNbtResources.Nodes[RoleId]); }
public static void makeLocationsTreeView(ref CswNbtView LocationsView, CswNbtResources CswNbtResources, Int32 loc_max_depth = Int32.MinValue, CswPrimaryKey NodeIdToFilterOut = null, bool RequireAllowInventory = false, IEnumerable <CswPrimaryKey> InventoryGroupIds = null, bool DisableLowestLevel = false, CswEnumNbtFilterResultMode ResultMode = null, string FullPathFilter = "") { _makeLocationsTreeView(ref LocationsView, CswNbtResources.MetaData, CswNbtResources.ConfigVbls, loc_max_depth, NodeIdToFilterOut, RequireAllowInventory, InventoryGroupIds, DisableLowestLevel, ResultMode ?? CswEnumNbtFilterResultMode.Disabled, FullPathFilter); }
private static void _makeLocationsTreeView(ref CswNbtView LocationsView, CswNbtMetaData MetaData, CswConfigurationVariables ConfigVbls, Int32 loc_max_depth, CswPrimaryKey NodeIdToFilterOut, bool RequireAllowInventory, IEnumerable <CswPrimaryKey> InventoryGroupIds, bool DisableLowestLevel, CswEnumNbtFilterResultMode ResultMode, string FullPathFilter = "") { if (null != LocationsView) { CswNbtMetaDataObjectClass LocationOC = MetaData.getObjectClass(CswEnumNbtObjectClass.LocationClass); CswNbtMetaDataObjectClassProp LocationLocationOCP = LocationOC.getObjectClassProp(PropertyName.Location); CswNbtMetaDataObjectClassProp LocationOrderOCP = LocationOC.getObjectClassProp(PropertyName.Order); CswNbtMetaDataObjectClassProp LocationAllowInventoryOCP = LocationOC.getObjectClassProp(PropertyName.AllowInventory); CswNbtMetaDataObjectClassProp LocationInventoryGroupOCP = LocationOC.getObjectClassProp(PropertyName.InventoryGroup); CswNbtMetaDataObjectClassProp LocationNameOCP = LocationOC.getObjectClassProp(PropertyName.Name); CswNbtMetaDataObjectClassProp LocationFullPathOCP = LocationOC.getObjectClassProp(PropertyName.FullPath); LocationsView.Root.ChildRelationships.Clear(); CswNbtViewRelationship LocReln = LocationsView.AddViewRelationship(LocationOC, true); LocationsView.AddViewProperty(LocReln, LocationLocationOCP); if (null != NodeIdToFilterOut) { LocReln.NodeIdsToFilterOut.Add(NodeIdToFilterOut); } CswNbtViewProperty InGroupVp = LocationsView.AddViewProperty(LocReln, LocationInventoryGroupOCP); InGroupVp.Width = 100; if (null != InventoryGroupIds) { CswCommaDelimitedString Pks = new CswCommaDelimitedString(); foreach (CswPrimaryKey InventoryGroupId in InventoryGroupIds) { Pks.Add(InventoryGroupId.PrimaryKey.ToString()); } LocationsView.AddViewPropertyFilter(InGroupVp, Conjunction: CswEnumNbtFilterConjunction.And, ResultMode: ResultMode, FilterMode: CswEnumNbtFilterMode.In, SubFieldName: CswNbtFieldTypeRuleRelationship.SubFieldName.NodeID, Value: Pks.ToString()); } CswNbtViewProperty OrderVPn = LocationsView.AddViewProperty(LocReln, LocationOrderOCP); LocationsView.setSortProperty(OrderVPn, CswEnumNbtViewPropertySortMethod.Ascending, false); if (RequireAllowInventory) { LocationsView.AddViewPropertyAndFilter(LocReln, LocationAllowInventoryOCP, Conjunction: CswEnumNbtFilterConjunction.And, ResultMode: ResultMode, FilterMode: CswEnumNbtFilterMode.Equals, Value: CswEnumTristate.True.ToString()); } // Filter on Full Path property if (false == string.IsNullOrEmpty(FullPathFilter)) { LocationsView.AddViewPropertyAndFilter(LocReln, LocationFullPathOCP, Conjunction: CswEnumNbtFilterConjunction.And, SubFieldName: CswEnumNbtSubFieldName.Value, FilterMode: CswEnumNbtFilterMode.Contains, Value: FullPathFilter); } else { LocationsView.AddViewProperty(LocReln, LocationFullPathOCP); } // Add the Name property to the view LocationsView.AddViewProperty(LocReln, LocationNameOCP); } // if( null != LocationsView ) } // makeLocationsTreeView()
}//ctor public void update(Int32 NodeTypeId, CswPrimaryKey RelationalId, DataTable PropsTable) { if (CswTools.IsPrimaryKey(RelationalId)) { CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(NodeTypeId); string TableName = NodeType.TableName; if (TableName != "nodes") { string PkColumnName = _CswNbtResources.getPrimeKeyColName(TableName); CswTableUpdate CswTableUpdate = null; DataTable DataTable = null; DataRow DataRow = null; // horrible special case for Design // We need to use CswNbtMetaDataResources objects, or else we have dirty-write problems if (NodeType.TableName.StartsWith("nodetype")) { switch (NodeType.TableName) { case "nodetypes": CswTableUpdate = _CswNbtResources.MetaData._CswNbtMetaDataResources.NodeTypeTableUpdate; CswNbtMetaDataNodeType relatedNT = _CswNbtResources.MetaData.getNodeType(RelationalId.PrimaryKey, null, true); DataTable = relatedNT._DataRow.Table; DataRow = relatedNT._DataRow; break; case "nodetype_tabset": CswTableUpdate = _CswNbtResources.MetaData._CswNbtMetaDataResources.NodeTypeTabTableUpdate; CswNbtMetaDataNodeTypeTab relatedNTT = _CswNbtResources.MetaData.getNodeTypeTab(RelationalId.PrimaryKey, true); DataTable = relatedNTT._DataRow.Table; DataRow = relatedNTT._DataRow; break; case "nodetype_props": CswTableUpdate = _CswNbtResources.MetaData._CswNbtMetaDataResources.NodeTypePropTableUpdate; CswNbtMetaDataNodeTypeProp relatedNTP = _CswNbtResources.MetaData.getNodeTypeProp(RelationalId.PrimaryKey, null, true); DataTable = relatedNTP._DataRow.Table; DataRow = relatedNTP._DataRow; break; } } // if( NodeType.TableName.StartsWith( "nodetype" ) ) if (null == DataTable || null == CswTableUpdate) { CswTableUpdate = _CswNbtResources.makeCswTableUpdate("CswNbtNodePropCollDataRelational_update", TableName); DataTable = CswTableUpdate.getTable(null, PkColumnName, RelationalId.PrimaryKey, string.Empty, false); DataRow = DataTable.Rows[0]; } if (null != DataRow) { CswTableSelect MappingSelect = _CswNbtResources.makeCswTableSelect("PropCollDataRelational_mapping", "jct_dd_ntp"); DataTable MappingTable = MappingSelect.getTable("where nodetypepropid in (select nodetypepropid from nodetype_props where nodetypeid =" + NodeTypeId.ToString() + ")"); foreach (DataRow CurrentRow in PropsTable.Rows) { CswNbtMetaDataNodeTypeProp thisNTP = NodeType.getNodeTypeProp(CswConvert.ToInt32(CurrentRow["nodetypepropid"])); if (null != thisNTP) { foreach (CswNbtSubField CurrentSubField in thisNTP.getFieldTypeRule().SubFields) { DataRow MappingRow = MappingTable.Rows.Cast <DataRow>() .FirstOrDefault(r => CswConvert.ToInt32(r["nodetypepropid"]) == thisNTP.PropId && r["subfieldname"].ToString() == CurrentSubField.Name.ToString()); if (null != MappingRow) { _CswNbtResources.DataDictionary.setCurrentColumn(CswConvert.ToInt32(MappingRow["datadictionaryid"])); if (_CswNbtResources.DataDictionary.ColumnName != string.Empty) { if (CurrentRow[CurrentSubField.Column.ToString()].ToString() == string.Empty) { DataRow[_CswNbtResources.DataDictionary.ColumnName] = DBNull.Value; } else if (_CswNbtResources.DataDictionary.ColumnName == CswEnumNbtPropertyAttributeColumn.Defaultvalueid) { // Special case for Default Value: we need to sync the jctnodepropid row, not the value DataRow[_CswNbtResources.DataDictionary.ColumnName] = CurrentRow["jctnodepropid"]; } else { object value = CurrentRow[CurrentSubField.Column.ToString()]; // Special case for Multi: translate "Single" and "Multiple" to 0 and 1 resp. if (_CswNbtResources.DataDictionary.ColumnName == CswEnumNbtPropertyAttributeColumn.Multi) { if (value.ToString() == CswEnumNbtPropertySelectMode.Single.ToString()) { value = 1; } else { value = 0; } } // Special case for booleans and tristates else if (thisNTP.getFieldTypeValue() == CswEnumNbtFieldType.Logical) { value = CswConvert.TristateToDbVal(CswConvert.ToTristate(CurrentRow[CurrentSubField.Column.ToString()])); } // Special case for relationships and locations, if the related entity is also relational else if (CurrentSubField.Name == CswNbtFieldTypeRuleRelationship.SubFieldName.NodeID && (thisNTP.getFieldTypeValue() == CswEnumNbtFieldType.Relationship || thisNTP.getFieldTypeValue() == CswEnumNbtFieldType.Location)) { CswNbtNode RelatedNode = _CswNbtResources.Nodes[new CswPrimaryKey("nodes", CswConvert.ToInt32(value))]; if (null != RelatedNode && RelatedNode.getNodeType().DoRelationalSync) { // Remap the foreign key reference to the relational primary key value = RelatedNode.RelationalId.PrimaryKey; } } DataRow[_CswNbtResources.DataDictionary.ColumnName] = value; //CurrentRow[CurrentSubField.Column.ToString()]; } } // if( _CswNbtResources.DataDictionary.ColumnName != string.Empty ) } // if( null != MappingRow ) } // foreach( CswNbtSubField CurrentSubField in thisNTP.getFieldTypeRule().SubFields ) } // if( null != thisNTP ) } // foreach( DataRow CurrentRow in PropsTable.Rows ) CswTableUpdate.update(DataTable); } // if( null != DataRow ) } // if( TableName != "nodes" ) } // if( CswTools.IsPrimaryKey( RelationalId ) ) } //update()
public void HandleLoadReport(CswPrimaryKey ReportId) { _CswNbtStatisticsEvents.OnLoadReport(ReportId); }
} // _treeNodeJObject() public JObject runTree(CswPrimaryKey IncludeNodeId, CswNbtNodeKey IncludeNodeKey, bool IncludeNodeRequired, bool IncludeInQuickLaunch, string DefaultSelect, string AccessedByObjClassId = "") { JObject ReturnObj = new JObject(); if (null != _View) //&& ( _View.ViewMode == NbtViewRenderingMode.Tree || _View.ViewMode == NbtViewRenderingMode.List ) ) { ICswNbtTree Tree = _CswNbtResources.Trees.getTreeFromView(_View, true, false, false); _View.SaveToCache(IncludeInQuickLaunch); if (IncludeNodeId != null && IncludeNodeId.PrimaryKey != Int32.MinValue && IncludeNodeKey == null) { IncludeNodeKey = Tree.getNodeKeyByNodeId(IncludeNodeId); if (IncludeNodeRequired && IncludeNodeKey == null) { CswNbtMetaDataNodeType IncludeKeyNodeType = _CswNbtResources.Nodes[IncludeNodeId].getNodeType(); _View = IncludeKeyNodeType.CreateDefaultView(); _View.ViewName = "New " + IncludeKeyNodeType.NodeTypeName; _View.Root.ChildRelationships[0].NodeIdsToFilterIn.Add(IncludeNodeId); _View.SaveToCache(IncludeInQuickLaunch); // case 22713 ReturnObj["newviewid"] = _View.SessionViewId.ToString(); ReturnObj["newviewmode"] = _View.ViewMode.ToString(); Tree = _CswNbtResources.Trees.getTreeFromView(_View, true, false, false); } } if (IncludeNodeRequired && IncludeNodeKey != null && Tree.getNodeKeyByNodeId(IncludeNodeKey.NodeId) == null) { CswNbtMetaDataNodeType IncludeKeyNodeType = _CswNbtResources.MetaData.getNodeType(IncludeNodeKey.NodeTypeId); _View = IncludeKeyNodeType.CreateDefaultView(); _View.ViewName = "New " + IncludeKeyNodeType.NodeTypeName; _View.Root.ChildRelationships[0].NodeIdsToFilterIn.Add(IncludeNodeKey.NodeId); _View.SaveToCache(IncludeInQuickLaunch); // case 22713 ReturnObj["newviewid"] = _View.SessionViewId.ToString(); ReturnObj["newviewmode"] = _View.ViewMode.ToString(); Tree = _CswNbtResources.Trees.getTreeFromView(_View, true, false, false); } Tree.goToRoot(); bool HasResults = (Tree.getChildNodeCount() > 0); ReturnObj["result"] = HasResults.ToString().ToLower(); ReturnObj["types"] = getTypes(); //ReturnObj["pagesize"] = _CswNbtResources.CurrentNbtUser.PageSize.ToString(); if (HasResults) { // Determine the default selected node: // If the requested node to select is on the tree, return it. // If the requested node to select is not on the tree, return the first child of the root. if (IncludeNodeKey != null) { Tree.makeNodeCurrent(IncludeNodeKey); if (Tree.isCurrentNodeDefined()) { //ReturnObj["selectid"] = _IdPrefix + IncludeNodeKey.NodeId.ToString(); ReturnObj["selectid"] = _IdPrefix + IncludeNodeKey.ToString(); } } if (ReturnObj["selectid"] == null) { switch (DefaultSelect) { case "none": break; case "root": ReturnObj["selectid"] = _IdPrefix + "root"; break; case "firstchild": Tree.goToRoot(); CswNbtNodeKey CurrentKey = Tree.getNodeKeyForCurrentPosition(); while (CurrentKey != null && CurrentKey.NodeSpecies != CswEnumNbtNodeSpecies.Plain && Tree.getChildNodeCount() > 0) { Tree.goToNthChild(0); CurrentKey = Tree.getNodeKeyForCurrentPosition(); } if (CurrentKey != null && CurrentKey.NodeSpecies == CswEnumNbtNodeSpecies.Plain) { // ReturnObj["selectid"] = _IdPrefix + Tree.getNodeIdForCurrentPosition().ToString(); ReturnObj["selectid"] = _IdPrefix + CurrentKey.ToString(); } break; } // switch( DefaultSelect ) } // if( ReturnObj["selectid"] == null ) } // if( HasResults ) else { ReturnObj["selectid"] = _IdPrefix + "root"; } Tree.goToRoot(); ReturnObj["root"] = new JObject(); ReturnObj["root"]["data"] = _View.ViewName; ReturnObj["root"]["attr"] = new JObject(); ReturnObj["root"]["attr"]["id"] = _IdPrefix + "root"; ReturnObj["root"]["attr"]["rel"] = "root"; ReturnObj["root"]["attr"]["disabled"] = false == Tree.getNodeIncludedForCurrentPosition(); //Tree.goToRoot(); //ReturnObj["attr"]["nodekey"] = Tree.getNodeKeyForCurrentPosition().ToString(); ReturnObj["root"]["state"] = "open"; ReturnObj["root"]["children"] = new JArray(); if (HasResults) { Tree.goToRoot(); _runTreeNodesRecursive(Tree, (JArray)ReturnObj["root"]["children"], true); } else { JObject NoResultsObj = new JObject(); NoResultsObj["state"] = "leaf"; NoResultsObj["data"] = "No Results"; ((JArray)ReturnObj["root"]["children"]).Add(NoResultsObj); } } return(ReturnObj); } // runTree()
/// <summary> /// Restore search from row in 'search' table /// </summary> public void FromSearchRow(DataRow SearchRow) { FromJObject(JObject.Parse(SearchRow["searchdata"].ToString())); SearchId = new CswPrimaryKey(CswNbtSearchManager.SearchTableName, CswConvert.ToInt32(SearchRow["searchid"])); }
public CswNbtAPIGenericRequest(string MetaDataNameIn, string Id) { NodeId = new CswPrimaryKey("nodes", CswConvert.ToInt32(Id)); MetaDataName = MetaDataNameIn; }
private void _initPermissionInfo(CswNbtObjClassRole CswNbtObjClassRole, ICswNbtUser CswNbtUser, CswNbtMetaDataNodeType NodeType, CswEnumNbtNodeTypePermission Permission, CswPrimaryKey CswPrimaryKey = null, CswNbtMetaDataNodeTypeProp PropType = null) { if (null == CswNbtObjClassRole) { CswPrimaryKey RoleId = null; if (null != CswNbtUser) { RoleId = CswNbtUser.RoleId; } else { if (null != _CswNbtResources.CurrentNbtUser) { CswNbtUser = _CswNbtResources.CurrentNbtUser; RoleId = CswNbtUser.RoleId; } }//if the user we got is null if (null != RoleId) { CswNbtObjClassRole = _getRole(RoleId); } //if we were able to get a roleid } //if the role we got is null if (null != CswNbtObjClassRole) { CswNbtPermitInfoKey CswNbtPermitInfoKey = new CswNbtPermitInfoKey(CswNbtObjClassRole, NodeType); if (_PermitInfoItems.ContainsKey(CswNbtPermitInfoKey)) { _CswNbtPermitInfo = _PermitInfoItems[CswNbtPermitInfoKey]; //must reset these per-request because they change per request for the same role and nodetype (e.g., see allowAny() ) if (null != CswPrimaryKey) { _CswNbtPermitInfo.NodePrimeKey = CswPrimaryKey; } if (null != PropType) { _CswNbtPermitInfo.PropType = PropType; } _CswNbtPermitInfo.NodeTypePermission = Permission; } else { _CswNbtPermitInfo = new CswNbtPermitInfo(_CswNbtResources, CswNbtUser, CswNbtObjClassRole, NodeType, Permission, CswPrimaryKey, PropType); _PermitInfoItems.Add(CswNbtPermitInfoKey, _CswNbtPermitInfo); } } else //the permit info in this case is not catalogued, and permit info won't allow any ops to proceed { _CswNbtPermitInfo = new CswNbtPermitInfo(_CswNbtResources, CswNbtUser, CswNbtObjClassRole, NodeType, Permission, CswPrimaryKey, PropType); } //if we were able to retrieve a role } //_initPermissionInfo()
private CswNbtObjClassContainer _createChildContainer(string ContainerNodeTypeId, CswPrimaryKey UnitId, string Barcode) { CswNbtObjClassContainer ChildContainer = null; CswNbtMetaDataNodeType ContainerNT = _CswNbtResources.MetaData.getNodeType(CswConvert.ToInt32(ContainerNodeTypeId)); if (ContainerNT != null) { _CswNbtResources.Nodes.makeNodeFromNodeTypeId(ContainerNT.NodeTypeId, delegate(CswNbtNode CopyNode) { CopyNode.copyPropertyValues(_SourceContainer.Node); ChildContainer = CopyNode; if (false == String.IsNullOrEmpty(Barcode)) { ChildContainer.Barcode.setBarcodeValueOverride(Barcode, false); } else { ChildContainer.Barcode.setBarcodeValue(); } ChildContainer.ReceiptLot.RelatedNodeId = null; ChildContainer.ExpirationDate.DateTimeValue = _SourceContainer.ExpirationDate.DateTimeValue; ChildContainer.SourceContainer.RelatedNodeId = _SourceContainer.NodeId; ChildContainer.Quantity.Quantity = 0; ChildContainer.Quantity.UnitId = UnitId; ChildContainer.Disposed.Checked = CswEnumTristate.False; _ContainersToView.Add(ChildContainer.NodeId); }); } return(ChildContainer); }
} // _CanNodeTypeImpl() #endregion NodeType #region Tabs /// <summary> /// Determines if the User has permission on this Tab (and only this Tab) /// </summary> public bool canTab(CswEnumNbtNodeTypePermission Permission, CswNbtMetaDataNodeType NodeType, CswNbtMetaDataNodeTypeTab NodeTypeTab, ICswNbtUser User = null, CswPrimaryKey NodeId = null) { _initPermissionInfo(null, User, NodeType, Permission, NodeId); return(_canTabImpl(NodeTypeTab)); }//canTab()
/// <summary> /// Get a DataTable with a single view, by name and visibility /// </summary> public DataTable getView(string ViewName, CswEnumNbtViewVisibility Visibility, CswPrimaryKey VisibilityRoleId, CswPrimaryKey VisibilityUserId) { CswTableSelect ViewsTable = _CswNbtResources.makeCswTableSelect("CswNbtViewSelect_viewExists_select", "node_views"); string WhereClause = "where viewname = '" + CswTools.SafeSqlParam(ViewName) + "'"; if (Visibility == CswEnumNbtViewVisibility.Role) { WhereClause += " and visibility = 'Role' and roleid = " + VisibilityRoleId.PrimaryKey.ToString(); } else if (Visibility == CswEnumNbtViewVisibility.User) { WhereClause += " and visibility = 'User' and userid = " + VisibilityUserId.PrimaryKey.ToString(); } else { WhereClause += " and visibility = '" + Visibility.ToString() + "'"; } return(ViewsTable.getTable(WhereClause)); } // getViews()