newntui/discovermdi/src/qatree.cpp
//---------------------------------------------------------------------------------------
// This recursive function will add complete sub-tree to the node "to"
// using the path "path"
//---------------------------------------------------------------------------------------
This recursive function will add complete sub-tree to the node "to"
using the path "path"
This recursive function will add complete sub - tree to the node " to " using the path " path "
void CQATree::AddChildren(HTREEITEM to, CString& path,BOOL folderStatus) {
register i;
CString query;
CString status;
CString name;
CString type;
BSTR sysQuery;
int amount;
CString childList;
CString childPath;
     amount=QueryChildren(path,childList);
	 if(amount==0) return;
	 CString token;
	 for(i=0;i<childList.GetLength();i++) {
		 if(childList[i]=='\n') {
			  if(to!=TVI_ROOT)
                 childPath=path+"/"+token;
			  else
                 childPath=path+token;
              query.Format("sev_get {%s} type",childPath);
              sysQuery=query.AllocSysString();
              type=DataSourceAccessSync(&sysQuery);
	          SysFreeString(sysQuery); 
              query.Format("sev_get {%s} on",childPath);
              sysQuery=query.AllocSysString();
              status=DataSourceAccessSync(&sysQuery);
	          SysFreeString(sysQuery); 
              query.Format("sev_get {%s} name",childPath);
              sysQuery=query.AllocSysString();
              name=DataSourceAccessSync(&sysQuery);
	          SysFreeString(sysQuery); 
			  if(name[0]!='.') {
              TV_ITEM tvItem;
			  CTreeNodeInfo* info;
			  info=new CTreeNodeInfo;
			  info->m_NodeName=childPath;
			  info->m_NodeType=type;
			  info->m_RootEnabled=folderStatus;
	          tvItem.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
              tvItem.pszText        = (char *)(LPCSTR)name;
	          tvItem.cchTextMax     = name.GetLength();
			  tvItem.lParam         = (long)info;
			  if(type=="folder") {
				  if(status=="1" && folderStatus==TRUE) {
	                 tvItem.iImage         = 1;
	                 tvItem.iSelectedImage = 0;
				  } else {
	                 tvItem.iImage         = 7;
	                 tvItem.iSelectedImage = 6;
				  }
			  }
			  if(type=="query_0") {
				  if(status=="1" && folderStatus==TRUE) {
	                 tvItem.iImage         = 3;
	                 tvItem.iSelectedImage = 2;
				  } else  {
	                 tvItem.iImage         = 9;
	                 tvItem.iSelectedImage = 8;
				  }
			  }
			  if(type=="query_1") {
				  if(status=="1" && folderStatus==TRUE) {
	                 tvItem.iImage         = 5;
	                 tvItem.iSelectedImage = 4;
				  } else {
	                 tvItem.iImage         = 9;
	                 tvItem.iSelectedImage = 8;
				  }
			  }
 	          TV_INSERTSTRUCT tvInsert;
	          tvInsert.hParent      = to;
	          tvInsert.hInsertAfter = TVI_LAST;
	          tvInsert.item         = tvItem;
	          HTREEITEM newItem= m_Tree.InsertItem(&tvInsert);
			  if(type=="folder") 
				  AddChildren(newItem,childPath, (status=="1" && folderStatus==TRUE) );
			  }
			  token="";
			  continue;
		 }
		 token+=childList[i];
	 }
}
void CQATree :: AddChildren ( HTREEITEM to , CString & path , BOOL folderStatus ) { register i ; CString query ; CString status ; CString name ; CString type ; BSTR sysQuery ; int amount ; CString childList ; CString childPath ; amount = QueryChildren ( path , childList ) ; if ( amount == 0 ) return ; CString token ; for ( i = 0 ; i < childList . GetLength ( ) ; i ++ ) { if ( childList [ i ] == ' \n ' ) { if ( to != TVI_ROOT ) childPath = path + " " + token ; else childPath = path + token ; query . Format ( " " , childPath ) ; sysQuery = query . AllocSysString ( ) ; type = DataSourceAccessSync ( & sysQuery ) ; SysFreeString ( sysQuery ) ; query . Format ( " " , childPath ) ; sysQuery = query . AllocSysString ( ) ; status = DataSourceAccessSync ( & sysQuery ) ; SysFreeString ( sysQuery ) ; query . Format ( " " , childPath ) ; sysQuery = query . AllocSysString ( ) ; name = DataSourceAccessSync ( & sysQuery ) ; SysFreeString ( sysQuery ) ; if ( name [ 0 ] != ' ' ) { TV_ITEM tvItem ; CTreeNodeInfo * info ; info = new CTreeNodeInfo ; info -> m_NodeName = childPath ; info -> m_NodeType = type ; info -> m_RootEnabled = folderStatus ; tvItem . mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE ; tvItem . pszText = ( char * ) ( LPCSTR ) name ; tvItem . cchTextMax = name . GetLength ( ) ; tvItem . lParam = ( long ) info ; if ( type == " " ) { if ( status == " " && folderStatus == TRUE ) { tvItem . iImage = 1 ; tvItem . iSelectedImage = 0 ; } else { tvItem . iImage = 7 ; tvItem . iSelectedImage = 6 ; } } if ( type == " " ) { if ( status == " " && folderStatus == TRUE ) { tvItem . iImage = 3 ; tvItem . iSelectedImage = 2 ; } else { tvItem . iImage = 9 ; tvItem . iSelectedImage = 8 ; } } if ( type == " " ) { if ( status == " " && folderStatus == TRUE ) { tvItem . iImage = 5 ; tvItem . iSelectedImage = 4 ; } else { tvItem . iImage = 9 ; tvItem . iSelectedImage = 8 ; } } TV_INSERTSTRUCT tvInsert ; tvInsert . hParent = to ; tvInsert . hInsertAfter = TVI_LAST ; tvInsert . item = tvItem ; HTREEITEM newItem = m_Tree . InsertItem ( & tvInsert ) ; if ( type == " " ) AddChildren ( newItem , childPath , ( status == " " && folderStatus == TRUE ) ) ; } token = " " ; continue ; } token += childList [ i ] ; } }
This recursive function will add complete sub-tree to the node "to"
using the path "path"
This recursive function will add complete sub - tree to the node " to " using the path " path "
// Query the server for the existing nodes // If this node has no children -  exit. // Getting the type of the node // Getting the node status // Getting the node name //------- Inserting item into the tree -------------------- // New node info structure will be added to the UI node // to keep information about real name and folder status // If the tree node is of type "Folder" we will show it // depending on the current folder status // If the tree node is of type "Query 0" we will show it // depending on it's status // If the tree node is of type "Query 1" we will show it // depending on it's status //---------------------------------------------------------