BOOL CDomainListBox::SetCurrentStocks( int nType, LPCTSTR lpszDomain, CDomainContainer & groups ) { // Delete All ResetContent( ); CStockContainer & container = AfxGetStockContainer(); CStockContainer cntn; BOOL bOK = FALSE; if( nType == CStockContainer::typeGroup ) { CSPStringArray astrSpecify; if( groups.GetDomainStocks( lpszDomain, astrSpecify ) ) bOK = cntn.RetrieveSpecify( astrSpecify ); // Not Set dwDate } else { bOK = cntn.RetrieveFromStatic( nType, lpszDomain, NULL, -1 ); } if( bOK ) { InitStorage( cntn.GetSize(), 32 ); for( int i=0; i<cntn.GetSize(); i++ ) { CStockInfo & info = cntn.ElementAt(i); CString strItem = CString(info.GetStockCode()) + "(" + info.GetStockShortName() + ") "; while( strItem.GetLength() < 16 ) strItem += " "; strItem += info.GetStockName() ; int nItem = AddString( strItem ); } } return bOK; }
void CStockContainer::CopyData( CStockContainer & src ) { CSPMutex::Scoped l(m_mutex); SetSize( src.GetSize() ); for( int i=0; i<src.GetSize(); i++ ) { CStockInfo & info = src.ElementAt(i); SetAt( i, info ); } }
int AfxRefreshStockContainerMinute( CStockContainer & container, LONG lStockType, int nSecondsToRead ) { container.Lock(); time_t tmTradeLatest = -1; int nCount = 0; for( int i=0; i<container.GetSize(); i++ ) { CStockInfo & info = container.ElementAt(i); if( info.GetType() != lStockType ) continue; CStock stock; stock.SetStockInfo( &info ); stock.SetDatabase( &AfxGetDB() ); AfxGetDB().LoadMinute( &stock ); info.m_minute.RemoveAll(); CMinute & minstock = stock.GetMinute(); if( -1 == tmTradeLatest && stock.GetMinute().GetSize() > 0 ) tmTradeLatest = CSPTime::GetTimeTradeLatest( minstock[0].m_time ); for( int i=0; i<minstock.GetSize(); i++ ) { if( -1 == nSecondsToRead || tmTradeLatest-minstock[i].m_time<nSecondsToRead ) info.m_minute.Add( minstock[i] ); } nCount ++; } container.UnLock(); return nCount; }
BOOL CSelectStk::OnInitDialog() { CPropertyPageEx::OnInitDialog(); CWaitCursor waitcursor; // TODO: Add extra initialization here CDomainContainer & groups = AfxGetGroupContainer( ); CDomainContainer & domains = AfxGetDomainContainer( ); CStockContainer & container = AfxGetStockContainer(); // Src m_comboGroupSrc.InitStrings( TRUE, TRUE, groups ); m_comboGroupSrc.SetCurSel( 0 ); OnSelchangeComboGroupsrc(); // Dest m_listStockDest.InitStorage( m_listStockSrc.GetCount(), 32 ); CStockContainer cntn; if( cntn.RetrieveSpecify( m_domainTemp ) ) { for( int i=0; i<cntn.GetSize(); i++ ) { CStockInfo & info = cntn.ElementAt(i); CString strItem = CString(info.GetStockCode()) + "(" + info.GetStockShortName() + ") "; while( strItem.GetLength() < 16 ) strItem += " "; strItem += info.GetStockName() ; int nItem = m_listStockDest.AddString( strItem ); } } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
BOOL CDomainContainer::GetAllDomainInfo( CStockContainer * pContainer, DWORD dwDate ) { SP_ASSERT( pContainer ); if( NULL == pContainer ) return FALSE; DWORD dwDateLatest = -1; AfxGetStockContainer().GetLatestTechDate( &dwDateLatest ); for( int nDomain=0; nDomain<GetSize(); nDomain++ ) { CDomain & domain = ElementAt(nDomain); CStockContainer cntn; if( cntn.RetrieveSpecify( domain ) ) { if( -1 != dwDate && dwDateLatest != dwDate ) { for( int i=0; i<cntn.GetSize(); i++ ) { CStockInfo & info = cntn.ElementAt(i); info.StatBaseIndex( dwDate ); info.StatTechIndex( dwDate ); } } // cntn.SetMap( ); cntn.SetAverage( ); CStockInfo info = cntn.GetAverage( ); info.SetStockName( domain.m_strName ); info.SetStockShortName( domain.m_strName ); pContainer->Add( info ); } } pContainer->SetMap(); pContainer->SetAverage(); return TRUE; }
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 ); } }
BOOL CSListView::SetAverageItem( CGridCtrl &grid, CStockContainer & container, BOOL bRedraw ) { if( grid.GetColumnCount() <= 0 ) return FALSE; container.Lock(); // Get LPARAM CUIntArray anParams; anParams.SetSize( 0, grid.GetColumnCount() ); for( int nCol=0; nCol < grid.GetColumnCount(); nCol ++ ) { LPARAM lParam = grid.GetItemData( 0, nCol ); anParams.Add( lParam ); } // Set Average CStockInfo & infoAve = container.GetAverage( ); CStockInfo & infoWAve = container.GetWeightAverage( ); int iRowAve=0, iRowWAve=0; if( grid.GetRowCount() >= 3 && grid.GetItemData(grid.GetRowCount()-2,0) == (LPARAM)ID_STOCKCNTN_AVERAGE && grid.GetItemData(grid.GetRowCount()-1,0) == (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE ) { // get item id iRowAve = grid.GetRowCount()-2; iRowWAve = grid.GetRowCount()-1; } else { // Insert item iRowAve = grid.InsertRow( infoAve.GetStockName() ); grid.SetItemData( iRowAve, 0, (LPARAM)ID_STOCKCNTN_AVERAGE ); iRowWAve = grid.InsertRow( infoWAve.GetStockName() ); grid.SetItemData( iRowWAve, 0, (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE ); } // Set Average for( nCol=0; nCol<anParams.GetSize(); nCol++ ) { grid.SetItemText( iRowAve, nCol, AfxGetVariantDispString(anParams[nCol], infoAve, NULL) ); grid.SetItemBkColour( iRowAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); grid.SetItemFgColour( iRowAve, nCol, AfxGetVariantColor( anParams[nCol], infoAve ) ); } // Set Weight Average for( nCol=0; nCol<anParams.GetSize(); nCol++ ) { grid.SetItemText( iRowWAve, nCol, AfxGetVariantDispString(anParams[nCol], infoWAve, NULL) ); grid.SetItemBkColour( iRowWAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); grid.SetItemFgColour( iRowWAve, nCol, AfxGetVariantColor( anParams[nCol], infoWAve ) ); } // Set Param which is // SLH_MARKETVALUE, SLH_MARKETVALUEA, SLH_MARKETVALUEB and etc, and more than SLH_USERDEFINE_BEGIN for( nCol=0; nCol < anParams.GetSize(); nCol ++ ) { UINT lParam = anParams[nCol]; if( SLH_DIFF == lParam || SLH_DIFFPERCENT == lParam || SLH_SCOPE == lParam || SLH_DIFFPERCENT_MIN5 == lParam || SLH_PE == lParam || SLH_PMAININCOME == lParam || SLH_RATIO_PCASH == lParam || SLH_RATIO_CURRENCY == lParam || SLH_RATIO_CHANGEHAND == lParam || SLH_RATIO_VOLUME == lParam || SLH_RS == lParam || SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam || SLH_MARKETVALUEB == lParam || lParam >= SLH_USERDEFINE_BEGIN ) { double dc = 0., average = 0.; double wsum = 0.0001, waverage = 0., w = 0.; for( int iRow=1; iRow<grid.GetRowCount(); iRow++ ) { if( iRow == iRowAve || iRow == iRowWAve ) continue; int id = grid.GetItemData(iRow,0); if( id < 0 || id > container.GetSize() ) continue; CStockInfo & info = container.ElementAt(id); w = info.m_fShare_count_total; double dValue = 0.; if( !AfxGetVariantValue( lParam, info, &dValue, &container ) ) continue; average = (average * dc + dValue)/(dc+1); waverage = (waverage * wsum + dValue * w)/(wsum+w); dc += 1; wsum += w; } CString strText; if( SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam || SLH_MARKETVALUEB == lParam ) { strText.Format( "%u", (DWORD)average ); grid.SetItemText( iRowAve, nCol, strText ); grid.SetItemText( iRowWAve, nCol, "-" ); } else { strText.Format( "%.2f", average ); grid.SetItemText( iRowAve, nCol, strText ); strText.Format( "%.2f", waverage ); grid.SetItemText( iRowWAve, nCol, strText ); } } } container.UnLock(); if( bRedraw ) { grid.RedrawRow( iRowAve ); grid.RedrawRow( iRowWAve ); } return TRUE; }