⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topology.cpp

📁 一个通过矩阵运算得到图形连接关系的动态连接库
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		AV_RESULT_INFO* pResultInfo = resultList.GetNext(pos);
		memcpy(*resultInfo+i,pResultInfo,sizeof(AV_RESULT_INFO));
		delete pResultInfo;
		i ++;
	}
	resultList.RemoveAll();

	//释放临时内存分配
	for(i=0; i<g_arrayTagRecordset.GetSize(); i++)
	{
		CRecordset* pTagRecordset = (CRecordset*)g_arrayTagRecordset.GetAt(i);
		if(!pTagRecordset) continue;
		delete pTagRecordset;
	}
	g_arrayTagRecordset.RemoveAll();
	for(i=0; i<g_arrayEndRecordset.GetSize(); i++)
	{
		CRecordset* pEndRecordset = (CRecordset*)g_arrayEndRecordset.GetAt(i);
		if(!pEndRecordset) continue;
		delete pEndRecordset;
	}
	g_arrayEndRecordset.RemoveAll();

	return AV_NO_ERR;
}
#ifdef _ADOVER
/*****************************************************************************
【函数名称】       AVSearchComponentAdo(void* pDatabase,AV_SEARCH_INFO* infoSearch,AV_RESULT_INFO** resultInfo,int* nSum)
【函数功能】       从调用者指定的起始元件开始,搜索符合若干指定检索条件的元件,搜索过程也在若干指定的条件下结束
				   此函数由调用者指定数据库资源,而AVSearchComponent直接引用本系统内部资源
【输入参数】       终止条件或目标条件infoSearch
【输出参数】       搜索到的目标对象结果resultInfo以及目标对象数目nSum(resultInfo由二次开发者释放)
*****************************************************************************/
AV_EXPORT USHORT AVSearchComponentAdo(void* pDatabase,AV_SEARCH_INFO* infoSearch,AV_RESULT_INFO** resultInfo,int* nSum)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	//初始化结果数据
	*resultInfo = NULL;
	*nSum = 0;

	//搜索标志复位
	for(int i=0; i<g_netModel.nComponentSum; i++)
		(g_netModel.pComponentInfo+i)->bSearchedFlag = FALSE;
	
	//首先定位元件信息体
	AV_COMPONENT_INFO* pComponentStart = NULL;
	pComponentStart = GetComponentInfoByID(&infoSearch->keyInfo);
	if(pComponentStart == NULL) return AVERR_NOT_FOUND;
	pComponentStart->bSearchedFlag = TRUE;

	//性能优化
	g_arrayTagRecordset.RemoveAll();
	g_arrayEndRecordset.RemoveAll();
	if(pDatabase)
	{
		for(i=0; i<infoSearch->nTagInfoCount; i++)
		{
			CAdoRecordSet* pTagRecordset = new CAdoRecordSet((CAdoConnection*)pDatabase);
			g_arrayTagRecordset.Add(pTagRecordset);
		}
		for(i=0; i<infoSearch->nEndInfoCount; i++)
		{
			CAdoRecordSet* pEndRecordset = new CAdoRecordSet((CAdoConnection*)pDatabase);
			g_arrayEndRecordset.Add(pEndRecordset);
		}
	}

	//开始进行搜索
	CResultList resultList;
	if(infoSearch->refPortID == -1)
	{
		for(int i=0; i<pComponentStart->nPortSum; i++)
		{
			g_nTagPortID = i;
			SearchedComponentFromPortAdo(pDatabase,pComponentStart,i,infoSearch,&resultList);
			if(infoSearch->nTargetFlag == 1 && resultList.GetCount() > 0) break;
		}
	}
	else
	{
		if(infoSearch->refPortID < 0 || infoSearch->refPortID >= pComponentStart->nPortSum)
			return AVERR_OVER;
		g_nTagPortID = infoSearch->refPortID;
		SearchedComponentFromPortAdo(pDatabase,pComponentStart,infoSearch->refPortID,infoSearch,&resultList);
	}

	//输出结果
	*nSum = resultList.GetCount();
	if(*nSum <= 0) return AVERR_NOT_FOUND;
	*resultInfo = new AV_RESULT_INFO[*nSum];
	i = 0;
	POSITION pos = resultList.GetHeadPosition();
	while(pos)
	{
		AV_RESULT_INFO* pResultInfo = resultList.GetNext(pos);
		memcpy(*resultInfo+i,pResultInfo,sizeof(AV_RESULT_INFO));
		delete pResultInfo;
		i ++;
	}
	resultList.RemoveAll();

	//释放临时内存分配
	for(i=0; i<g_arrayTagRecordset.GetSize(); i++)
	{
		CAdoRecordSet* pTagRecordset = (CAdoRecordSet*)g_arrayTagRecordset.GetAt(i);
		if(!pTagRecordset) continue;
		delete pTagRecordset;
	}
	g_arrayTagRecordset.RemoveAll();
	for(i=0; i<g_arrayEndRecordset.GetSize(); i++)
	{
		CAdoRecordSet* pEndRecordset = (CAdoRecordSet*)g_arrayEndRecordset.GetAt(i);
		if(!pEndRecordset) continue;
		delete pEndRecordset;
	}
	g_arrayEndRecordset.RemoveAll();

	return AV_NO_ERR;
} 
AV_EXPORT USHORT AVSearchComponentInSingleTable(void* pDatabase,AV_SEARCH_INFO* infoSearch,//按条件搜索元件
								 AV_RESULT_INFO** resultInfo, int* nSum,
								 void * p_Element,int nEleCount,int nSearch, char* chSysCode)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	if(!pDatabase) return AVERR_BAD_PARAM;

	if(infoSearch->nTagInfoCount != 1 || infoSearch->nEndInfoCount != 1)
	{
		::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),"提示::AVSearchComponentInSingleTable搜索功能只支持单表查询!","AVInfoKernel",
			MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
		return AVERR_BAD_PARAM;
	}

	//初始化结果数据
	*resultInfo = NULL;
	*nSum = 0;

	//搜索标志复位
	for(int i=0; i<g_netModel.nComponentSum; i++)
		(g_netModel.pComponentInfo+i)->bSearchedFlag = FALSE;
	
	//首先定位元件信息体
	AV_COMPONENT_INFO* pComponentStart = NULL;
	pComponentStart = GetComponentInfoByID(&infoSearch->keyInfo);
	if(pComponentStart == NULL) return AVERR_NOT_FOUND;
	pComponentStart->bSearchedFlag = TRUE;

	//获取条件筛选、条件终止对象键值列表便于搜索
	g_listTagKey.RemoveAll();
	g_listEndKey.RemoveAll();
	CString m_Str = chSysCode;
	if (nEleCount > 0) //用内存搜索
	{
		CElement* pElement;
		pElement = (CElement*)p_Element;
		switch (nSearch)
		{
		case 0:
			for (i=0;i<nEleCount;i++)
			{
				if (pElement[i].Type == 6 ||
					pElement[i].Type == 15 ||
					pElement[i].Type == 4)
				{
				g_listTagKey.AddTail(pElement[i].SysCode);
				g_listEndKey.AddTail(pElement[i].SysCode);
				}
			}
			break;
		case 1:
			for (i=0;i<nEleCount;i++)
			{
				if (pElement[i].PhysicalType == 604 ||
					pElement[i].PhysicalType == 605 ||
					pElement[i].PhysicalType == 606)
				g_listTagKey.AddTail(pElement[i].SysCode);
				if (pElement[i].Type == 6 ||
					pElement[i].Type == 15 ||
					pElement[i].PhysicalType == 403 ||
					pElement[i].IsImpedance)
				g_listEndKey.AddTail(pElement[i].SysCode);
			}
			break;
		case 2:
			for (i=0;i<nEleCount;i++)
			{
				if (pElement[i].Type == 6 ||
					pElement[i].Type == 15 ||
					(pElement[i].Type == 4 && pElement[i].SysCode == m_Str))
				g_listTagKey.AddTail(pElement[i].SysCode);
				if (pElement[i].Type == 6 ||
					pElement[i].Type == 15 )
				g_listEndKey.AddTail(pElement[i].SysCode);
			}
			break;
		case 3:
			for (i=0;i<nEleCount;i++)
			{
				if (pElement[i].Type == 6 ||
					pElement[i].Type == 15 )
				g_listTagKey.AddTail(pElement[i].SysCode);
				if (pElement[i].Type == 6 ||
					pElement[i].Type == 15 ||
					pElement[i].Type == 4)
				g_listEndKey.AddTail(pElement[i].SysCode);
			}
			break;
		}
	}
	else
	{
		CAdoRecordSet* pTagRecordset = new CAdoRecordSet((CAdoConnection*)pDatabase);
		CAdoRecordSet* pEndRecordset = new CAdoRecordSet((CAdoConnection*)pDatabase);
		CString strFieldName = infoSearch->tagInfo->chFieldKey;//变电站名加编码,用逗号隔开syscode,twolinedescription
		CString strSQL = "Select "+ strFieldName + " from " + CString(infoSearch->tagInfo->chTableName) + " where " + CString(infoSearch->tagInfo->chFilter);
		if(pTagRecordset->Open(strSQL,adCmdText) == -1)
		{
			::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),strSQL,"提示::AVInfoKernel_CheckYourSQL",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
		}
		else
		{
			pTagRecordset->MoveFirst();
			while(!pTagRecordset->IsEOF())
			{
				CString strValue(_T("")),strStation;
				int nPos = strFieldName.Find(",",0);
				if(nPos == -1)//wxg
					pTagRecordset->GetValueString(strValue,strFieldName);
				else//wxg
				{
					pTagRecordset->GetValueString(strValue,0);//syscode
					pTagRecordset->GetValueString(strStation,1);//twolinedescription
					strValue = strStation+"@"+strValue;
				}
				g_listTagKey.AddTail(strValue);
				pTagRecordset->MoveNext();
			}		
		}
		strFieldName = infoSearch->endInfo->chFieldKey;
		strSQL = "Select "+ strFieldName + " from " + CString(infoSearch->endInfo->chTableName) + " where " + CString(infoSearch->endInfo->chFilter);
		if(pEndRecordset->Open(strSQL,adCmdText) == -1)
		{
			::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),strSQL,"提示::AVInfoKernel_CheckYourSQL",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
		}
		else
		{
			pEndRecordset->MoveFirst();
			while(!pEndRecordset->IsEOF())
			{
				CString strValue(_T("")),strStation;
				int nPos = strFieldName.Find(",",0);
				if(nPos == -1)//wxg
					pEndRecordset->GetValueString(strValue,strFieldName);
				else//wxg
				{
					pEndRecordset->GetValueString(strValue,0);//syscode
					pEndRecordset->GetValueString(strStation,1);//twolinedescription
					strValue = strStation+"@"+strValue;
				}
				g_listEndKey.AddTail(strValue);
				pEndRecordset->MoveNext();
			}		
		}
		//释放临时内存分配
		if(pTagRecordset) 
		{
			pTagRecordset->Close();
			delete pTagRecordset;
		}
		if(pEndRecordset)
		{
			pEndRecordset->Close();
			delete pEndRecordset;
		}
	}
	//开始进行搜索
	CResultList resultList;
	if(infoSearch->refPortID == -1)
	{
		for(int i=0; i<pComponentStart->nPortSum; i++)
		{
			g_nTagPortID = i;
			SearchedComponentFromPortInSingleTable(pDatabase,pComponentStart,i,infoSearch,&resultList);
			if(infoSearch->nTargetFlag == 1 && resultList.GetCount() > 0) break;
		}
	}
	else
	{
		if(infoSearch->refPortID < 0 || infoSearch->refPortID >= pComponentStart->nPortSum)
			return AVERR_OVER;
		g_nTagPortID = infoSearch->refPortID;
		SearchedComponentFromPortInSingleTable(pDatabase,pComponentStart,infoSearch->refPortID,infoSearch,&resultList);
	}

	//输出结果
	*nSum = resultList.GetCount();
	if(*nSum <= 0) return AVERR_NOT_FOUND;
	*resultInfo = new AV_RESULT_INFO[*nSum];
	i = 0;
	POSITION pos = resultList.GetHeadPosition();

	while(pos)
	{
		AV_RESULT_INFO* pResultInfo = resultList.GetNext(pos);
		memcpy(*resultInfo+i,pResultInfo,sizeof(AV_RESULT_INFO));
		delete pResultInfo;
		i ++;
	}
	resultList.RemoveAll();

	return AV_NO_ERR;
}
#endif
#ifdef __cplusplus
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -