public void beforeDeleteNode(bool DeleteAllRequiredRelatedNodes, bool ValidateRequiredRelationships) { beforeDeleteNodeLogic(); if (ValidateRequiredRelationships) { // case 22486 - Don't allow deleting targets of required relationships CswTableSelect JctSelect = _CswNbtResources.makeCswTableSelect("defaultBeforeDeleteNode_jnp_select", "jct_nodes_props"); // Case CIS-52536 - Delete validation should ignore temp nodes string WhereClause = @"np WHERE nodetypepropid IN (SELECT nodetypepropid FROM nodetype_props WHERE isrequired = '1') AND field1_fk = " + _CswNbtNode.NodeId.PrimaryKey.ToString() + @" AND (SELECT istemp FROM nodes n WHERE n.nodeid = np.nodeid) <> '1' "; CswCommaDelimitedString SelectClause = new CswCommaDelimitedString() { "nodeid" }; DataTable MatchTable = JctSelect.getTable(SelectClause, WhereClause); if (MatchTable.Rows.Count > 0) { CswCommaDelimitedString InUseStr = new CswCommaDelimitedString(); foreach (DataRow MatchRow in MatchTable.Rows) { CswPrimaryKey MatchNodePk = new CswPrimaryKey("nodes", CswConvert.ToInt32(MatchRow["nodeid"])); if (DeleteAllRequiredRelatedNodes) { CswNbtNode NodeToDelete = _CswNbtResources.Nodes.GetNode(MatchNodePk); if (null != NodeToDelete) { NodeToDelete.delete(DeleteAllRequiredRelatedNodes: DeleteAllRequiredRelatedNodes); } } else { CswNbtNode RelatedNode = _CswNbtResources.Nodes[MatchNodePk]; if (null != RelatedNode) { InUseStr.Add(RelatedNode.NodeLink); } } } // foreach( DataRow MatchRow in MatchTable.Rows ) if (false == DeleteAllRequiredRelatedNodes) { throw new CswDniException(CswEnumErrorType.Warning, "This " + _CswNbtNode.getNodeType().NodeTypeName + " cannot be deleted because it is in use by: " + InUseStr, "Current user (" + _CswNbtResources.CurrentUser.Username + ") tried to delete a " + _CswNbtNode.getNodeType().NodeTypeName + " that is in use by: " + InUseStr); } } // if( MatchTable.Rows.Count > 0 ) } // if( ValidateRequiredRelationships ) } // baseBeforeDeleteNode()
} // copyPropertyValues() /// <summary> /// Sets the values of all relationships whose target matches /// the ParentNode's nodetypeid or objectclassid to the ParentNode's nodeid. /// </summary> public void RelateToNode(CswNbtNode ParentNode, CswNbtView View) { CswNbtNodePropWrapper Prop = null; // BZ 10372 - Iterate all relationships foreach (CswNbtViewRelationship ViewRelationship in View.Root.GetAllChildrenOfType(CswEnumNbtViewNodeType.CswNbtViewRelationship)) { // BZ 8355 - Set relationships on children pointing to parents, not the other way if (ViewRelationship.PropOwner == CswEnumNbtViewPropOwnerType.Second) { //if( ( ( ViewRelationship.SecondType == NbtViewRelatedIdType.NodeTypeId && ViewRelationship.SecondId == this.NodeTypeId ) || // ( ViewRelationship.SecondType == NbtViewRelatedIdType.ObjectClassId && ViewRelationship.SecondId == this.getObjectClassId() ) ) && // ( ( ViewRelationship.FirstType == NbtViewRelatedIdType.NodeTypeId && ViewRelationship.FirstId == ParentNode.NodeTypeId ) || // ( ViewRelationship.FirstType == NbtViewRelatedIdType.ObjectClassId && ViewRelationship.FirstId == ParentNode.getObjectClassId() ) ) ) if (ViewRelationship.SecondMatches(this.getNodeType()) && ViewRelationship.FirstMatches(ParentNode.getNodeType())) { if (ViewRelationship.PropType == CswEnumNbtViewPropIdType.NodeTypePropId) { Prop = this.Properties[_CswNbtResources.MetaData.getNodeTypeProp(ViewRelationship.PropId)]; } else if (ViewRelationship.PropType == CswEnumNbtViewPropIdType.ObjectClassPropId) { Prop = this.Properties[_CswNbtResources.MetaData.getObjectClassProp(ViewRelationship.PropId).PropName]; } if (Prop != null) { CswEnumNbtFieldType FT = Prop.getFieldTypeValue(); if (FT == CswEnumNbtFieldType.Relationship) { Prop.AsRelationship.RelatedNodeId = ParentNode.NodeId; Prop.AsRelationship.RefreshNodeName(); } if (FT == CswEnumNbtFieldType.Location) { Prop.AsLocation.SelectedNodeId = ParentNode.NodeId; Prop.AsLocation.RefreshNodeName(); } } } } // if( ViewRelationship.PropOwner == PropOwnerType.Second ) } // foreach( CswNbtViewRelationship ViewRelationship in View.Root.GetAllChildrenOfType( NbtViewNodeType.CswNbtViewRelationship ) ) } // RelateToNode()
/// <summary> /// Extract report parameters for a report /// </summary> /// <param name="UserNode">Use this user for matching parameter values</param> /// <param name="SourceNode">Use this node for matching parameter values</param> /// <returns></returns> public Dictionary <string, string> ExtractReportParams(CswNbtObjClassUser UserNode = null, CswNbtNode SourceNode = null) { Dictionary <string, string> reportParams = new Dictionary <string, string>(); MatchCollection matchedParams = null; if (false == string.IsNullOrEmpty(WebService.Text)) { matchedParams = Regex.Matches(WebService.Text, @"\{([\s\w0-9])+\}"); } else if (false == string.IsNullOrEmpty(SQL.Text)) { matchedParams = Regex.Matches(SQL.Text, @"\{([\s\w0-9])+\}"); } foreach (Match match in matchedParams) { string paramName = match.Value.Replace('{', ' ').Replace('}', ' ').Trim(); //remove the '{' and '}' and whitespace string replacementVal = ""; if (null != UserNode) { if (paramName == ControlledParams.UserId || paramName == ControlledParams.NodeId) { replacementVal = UserNode.Node.NodeId.PrimaryKey.ToString(); } else if (paramName == ControlledParams.RoleId) { replacementVal = UserNode.RoleId.PrimaryKey.ToString(); } else { CswNbtMetaDataNodeTypeProp userNTP = UserNode.NodeType.getNodeTypeProp(paramName); if (null != userNTP) { replacementVal = UserNode.Node.Properties[userNTP].Gestalt; } } } // if( null != UserNode ) if (null != SourceNode) { CswNbtMetaDataNodeTypeProp sourceNTP = SourceNode.getNodeType().getNodeTypeProp(paramName); if (null != sourceNTP) { replacementVal = SourceNode.Properties[sourceNTP].Gestalt; } } if (false == string.IsNullOrEmpty(SQL.Text)) { if (CswSqlAnalysis.doesSqlContainDmlOrDdl(replacementVal)) { throw (new CswDniException("Parameter contains sql: " + paramName)); } } if (false == reportParams.ContainsKey(paramName)) { reportParams.Add(paramName, replacementVal); } } return(reportParams); }