Пример #1
0
void CSListView::SendRequestQuote( BOOL bForced )
{
	static int nLastStart = -1;
	static int nLastCount = -1;

	BOOL bQuoteTipSended = FALSE;

	BOOL bInTrade = CSPTime::InTradeTime(CSPTime::GetCurrentTime().GetTime(),900);
	CView * pView = AfxGetStaticDoc()->GetActiveView();
	if( bForced )
	{
		CStockContainer stocks;
		CStockInfo	info;
		if( AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAIN, &info ) )
			stocks.Add(info);
		if( AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAINSZN, &info ) )
			stocks.Add(info);
		if( stocks.GetSize() > 0 )
			AfxGetStkReceiver().RequestStockData( CStock::dataReport, stocks.GetData(), stocks.GetSize(), 0, 0 );
	}
	if( bForced || pView == this )
	{
		CCellRange cr = m_Grid.GetVisibleNonFixedCellRange();
		int nStart = cr.GetMinRow() - 1;
		int nCount = cr.GetMaxRow() - cr.GetMinRow() + 1;
		CStockContainer & container = AfxGetSListStockContainer();
		container.Lock();
		if( nStart >= 0 && nCount > 0 && container.GetSize() > 0 && (bInTrade || bForced || nLastStart != nStart || nLastCount != nCount) )
		{
			nLastStart = nStart;
			nLastCount = nCount;
			AfxGetStkReceiver().RequestStockData( CStock::dataReport, container.GetData()+nStart, min(nCount,container.GetSize()-nStart), 0, 0 );
			bQuoteTipSended = (0 == nStart && nCount >= 9);
		}
		container.UnLock();
	}

	if( bInTrade )
	{
		// 预警系统所需股票行情刷新
		CAlarmCondContainer & conds = AfxGetProfile().GetAlarmCondContainer();
		CStockContainer stocks;
		stocks.SetSize( 0, conds.GetSize() + 5 );
		for( int i=0; i<conds.GetSize(); i++ )
		{
			ALARMCOND cond = conds.GetAt(i);
			CStockInfo info;
			if( AfxGetStockContainer().GetStockInfo( cond.m_szCode, &info ) )
				stocks.Add( info );
		}
		CStockInfo infoMain, infoMainSzn;
		if( AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAIN, &infoMain )
			&& AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAINSZN, &infoMainSzn ) )
		{
			stocks.Add( infoMain );
			stocks.Add( infoMainSzn );
		}

		//  行情QuoteTip 需要行情数据
		if( !bQuoteTipSended )
		{
			CStockContainer & container = AfxGetSListStockContainer();
			container.Lock();
			for( int i=0; i<9 && i<container.GetSize(); i++ )
				stocks.Add( container.ElementAt(i) );
			container.UnLock();
		}

		if( stocks.GetSize() > 0 )
			AfxGetStkReceiver().RequestStockData( CStock::dataReport, stocks.GetData(), stocks.GetSize(), 0, 0 );
	}
}