BOOL UpdateStockContainerByKData( CStockContainer &container, LPCTSTR lpszCode, CKData & kdata ) { container.Lock(); int id = 0; if( CKData::ktypeDay == kdata.GetKType() && container.GetStockInfo( lpszCode, NULL, &id ) ) { CStockInfo & info = container.ElementAt(id); if( kdata.GetSize() > (int)AfxGetProfile().GetCacheDays() ) { // 只使用AfxGetProfile().GetCacheDays()天的数据 CKData temp( kdata.GetKType() ); for( int i=kdata.GetSize()-AfxGetProfile().GetCacheDays(); i<kdata.GetSize(); i++ ) temp.Add( kdata.ElementAt(i) ); info.m_kdata.MergeKData( &temp ); } else info.m_kdata.MergeKData( &kdata ); // 指数涨跌家数 int nSize = info.m_kdata.GetSize(); if( nSize > 0 ) { info.m_dwAdvance = info.m_kdata.ElementAt(nSize-1).m_dwAdvance; info.m_dwDecline = info.m_kdata.ElementAt(nSize-1).m_dwDecline; } } container.UnLock(); return TRUE; }
// update CStockContainer by Report data BOOL UpdateStockContainerByREPORT( CStockContainer &container, REPORT * pReport, BOOL bAddIfNotExist, REPORT * pReportLast ) { SP_ASSERT( pReport ); if( NULL == pReport ) return FALSE; REPORT reportLast; memset( &reportLast, 0, sizeof(reportLast) ); int id = 0; if( container.GetStockInfo( pReport->m_szCode, NULL, &id ) ) { container.Lock(); CStockInfo & info = container.ElementAt(id); reportLast = info.m_reportLatest; UpdateStockInfoByREPORT( info, pReport ); container.UnLock(); } else if( bAddIfNotExist && strlen(pReport->m_szCode)>0 ) { CStockInfo info; info.SetStockCode( pReport->m_dwMarket, pReport->m_szCode ); if( UpdateStockInfoByREPORT( info, pReport ) ) { container.Add( info ); } } if( pReportLast ) memcpy( pReportLast, &reportLast, sizeof(reportLast) ); return TRUE; }