66using Rappen . XRM . Helpers . Interfaces ;
77using Rappen . XTB . FetchXmlBuilder . Builder ;
88using Rappen . XTB . FetchXmlBuilder . Controls ;
9+ using Rappen . XTB . FetchXmlBuilder . ControlsClasses ;
910using Rappen . XTB . FetchXmlBuilder . Extensions ;
1011using Rappen . XTB . FetchXmlBuilder . Forms ;
1112using Rappen . XTB . FetchXmlBuilder . Views ;
@@ -202,6 +203,32 @@ internal FetchXmlElementControlBase GetCurrentControl()
202203 . Nodes . Cast < TreeNode > ( ) ?
203204 . FirstOrDefault ( n => n . Name == "attribute" && n . Value ( "name" ) == PrimaryIdName ) ;
204205
206+ internal List < EntityNode > GetEntityNodes ( TreeNode node = null , bool needsalias = false , bool excludefromfilter = false )
207+ {
208+ if ( node == null )
209+ {
210+ node = tvFetch . Nodes [ 0 ] ;
211+ }
212+ var result = new List < EntityNode > ( ) ;
213+ if ( node == null )
214+ {
215+ return result ;
216+ }
217+ if ( excludefromfilter && node . HeritanceOfFilter ( ) )
218+ {
219+ return result ;
220+ }
221+ if ( node . Name == "link-entity" && ( ! needsalias || ! string . IsNullOrWhiteSpace ( node . Value ( "alias" ) ) ) )
222+ {
223+ result . Add ( new EntityNode ( node ) ) ;
224+ }
225+ foreach ( TreeNode child in node . Nodes )
226+ {
227+ result . AddRange ( GetEntityNodes ( child , needsalias , excludefromfilter ) ) ;
228+ }
229+ return result ;
230+ }
231+
205232 private int GetUniqueLinkEntitySuffix ( TreeNode entity )
206233 {
207234 var root = tvFetch . Nodes . Cast < TreeNode > ( ) . FirstOrDefault ( n => n . Name == "fetch" ) ;
@@ -515,7 +542,7 @@ private static string GetNodeAsString(TreeNode node)
515542 XmlNode rootNode = doc . CreateElement ( "root" ) ;
516543 doc . AppendChild ( rootNode ) ;
517544 TreeNodeHelper . AddXmlNode ( node , rootNode ) ;
518- XDocument xdoc = XDocument . Parse ( rootNode . InnerXml ) ;
545+ var xdoc = XDocument . Parse ( rootNode . InnerXml ) ;
519546 var result = xdoc . ToString ( ) ;
520547 return result ;
521548 }
@@ -586,7 +613,10 @@ private XmlDocument GetFetchDocument(bool includelayout = false)
586613 private void HandleNodeMenuClick ( string ClickedTag )
587614 {
588615 if ( ClickedTag == null || ClickedTag == "Add" )
616+ {
589617 return ;
618+ }
619+
590620 TreeNode updateNode = null ;
591621 if ( ClickedTag == "Delete" )
592622 {
@@ -696,7 +726,7 @@ private void HandleNodeSelection(TreeNode node)
696726 }
697727
698728 ctrl = null ;
699- Control existingControl = panelContainer . Controls . Count > 0 ? panelContainer . Controls [ 0 ] : null ;
729+ var existingControl = panelContainer . Controls . Count > 0 ? panelContainer . Controls [ 0 ] : null ;
700730 if ( node != null )
701731 {
702732 TreeNodeHelper . AddContextMenu ( node , this , fxb . settings . QueryOptions ) ;
@@ -746,7 +776,7 @@ private void HandleNodeSelection(TreeNode node)
746776 }
747777 break ;
748778 }
749- AttributeMetadata [ ] attributes = fxb . GetDisplayAttributes ( entity ) . ToArray ( ) ;
779+ var attributes = fxb . GetDisplayAttributes ( entity ) . ToArray ( ) ;
750780 if ( node . Name == "attribute" )
751781 {
752782 ctrl = new attributeControl ( node , attributes , fxb , this ) ;
@@ -787,7 +817,11 @@ private void HandleNodeSelection(TreeNode node)
787817 ctrl . BringToFront ( ) ;
788818 ctrl . Dock = DockStyle . Top ;
789819 }
790- if ( existingControl != null ) panelContainer . Controls . Remove ( existingControl ) ;
820+ if ( existingControl != null )
821+ {
822+ panelContainer . Controls . Remove ( existingControl ) ;
823+ }
824+
791825 fxb . ShowMetadata ( ctrl ? . Metadata ( ) ) ;
792826 }
793827 ManageMenuDisplay ( ) ;
@@ -852,7 +886,7 @@ private void HandleTVKeyDown(KeyEventArgs e)
852886
853887 private void ManageMenuDisplay ( )
854888 {
855- TreeNode selectedNode = tvFetch . SelectedNode ;
889+ var selectedNode = tvFetch . SelectedNode ;
856890 moveUpToolStripMenuItem . Enabled = selectedNode != null && selectedNode . Parent != null &&
857891 selectedNode . Index != 0 ;
858892 moveDownToolStripMenuItem . Enabled = selectedNode != null && selectedNode . Parent != null &&
@@ -898,7 +932,7 @@ private void SelectAttributes()
898932 var i = 0 ;
899933 while ( i < entityNode . Nodes . Count )
900934 { // Remove unselected previously added attributes
901- TreeNode subnode = entityNode . Nodes [ i ] ;
935+ var subnode = entityNode . Nodes [ i ] ;
902936 var attributename = subnode . Value ( "name" ) ;
903937 if ( subnode . Name == "attribute" && ! selectedAttributes . Contains ( attributename ) )
904938 {
@@ -1019,13 +1053,13 @@ private void toolStripButtonMoveDown_Click(object sender, EventArgs e)
10191053 {
10201054 moveDownToolStripMenuItem . Enabled = false ;
10211055 fxb . working = true ;
1022- TreeNode tnmNode = tvFetch . SelectedNode ;
1023- TreeNode tnmNextNode = tnmNode . NextNode ;
1056+ var tnmNode = tvFetch . SelectedNode ;
1057+ var tnmNextNode = tnmNode . NextNode ;
10241058 if ( tnmNextNode != null )
10251059 {
1026- int idxBegin = tnmNode . Index ;
1027- int idxEnd = tnmNextNode . Index ;
1028- TreeNode tnmNodeParent = tnmNode . Parent ;
1060+ var idxBegin = tnmNode . Index ;
1061+ var idxEnd = tnmNextNode . Index ;
1062+ var tnmNodeParent = tnmNode . Parent ;
10291063 if ( tnmNodeParent != null )
10301064 {
10311065 tnmNode . Remove ( ) ;
@@ -1045,13 +1079,13 @@ private void toolStripButtonMoveUp_Click(object sender, EventArgs e)
10451079 {
10461080 moveUpToolStripMenuItem . Enabled = false ;
10471081 fxb . working = true ;
1048- TreeNode tnmNode = tvFetch . SelectedNode ;
1049- TreeNode tnmPreviousNode = tnmNode . PrevNode ;
1082+ var tnmNode = tvFetch . SelectedNode ;
1083+ var tnmPreviousNode = tnmNode . PrevNode ;
10501084 if ( tnmPreviousNode != null )
10511085 {
1052- int idxBegin = tnmNode . Index ;
1053- int idxEnd = tnmPreviousNode . Index ;
1054- TreeNode tnmNodeParent = tnmNode . Parent ;
1086+ var idxBegin = tnmNode . Index ;
1087+ var idxEnd = tnmPreviousNode . Index ;
1088+ var tnmNodeParent = tnmNode . Parent ;
10551089 if ( tnmNodeParent != null )
10561090 {
10571091 tnmNode . Remove ( ) ;
0 commit comments