📄 slistview.cpp.svn-base
字号:
// SListView.cpp : implementation of the CSListView class
//
#include "stdafx.h"
#include "../StaticDoc.h"
#include "SListView.h"
#include "../Dialog/ListExportDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSListView
#define SLV_TIMER_REFRESH 1
#define IDC_SLISTVIEW_GRID 100
#define IDC_SLISTVIEW_WORKTAB 101
#define SL_WORKTAB_CLASS 0
#define SL_WORKTAB_A 1
#define SL_WORKTAB_MSMALL 2
#define SL_WORKTAB_SHB 3
#define SL_WORKTAB_SZNB 4
#define SL_WORKTAB_BOND 5
#define SL_WORKTAB_FUND 6
#define SL_WORKTAB_RIGHT 7
#define SL_WORKTAB_SELF 8
#define SL_WORKTAB_GROUP 9
#define SL_WORKTAB_DOMAIN 10
IMPLEMENT_DYNCREATE(CSListView, CFormView)
BEGIN_MESSAGE_MAP(CSListView, CFormView)
//{{AFX_MSG_MAP(CSListView)
ON_WM_CREATE()
ON_WM_ERASEBKGND()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_COMMAND(ID_SLIST_EXPORTLIST, OnSlistExportlist)
ON_WM_SIZE()
ON_WM_SETFOCUS()
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint)
ON_NOTIFY(TCN_SELCHANGE, IDC_SLISTVIEW_WORKTAB, OnSelchangeWorktab)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_USER_GETVIEWTITLE, OnGetViewTitle)
ON_MESSAGE(WM_USER_GETVIEWCMDID, OnGetViewCmdid)
ON_MESSAGE(WM_USER_COLORCHANGE, OnColorChange)
ON_MESSAGE(WM_APP_STKRECEIVER_DATA, OnStkReceiverData)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSListView construction/destruction
CSListView::CSListView() : CFormView(CSListView::IDD)
{
m_nColSort = -1;
m_bSortAscend = FALSE;
m_bShouldUpdate = FALSE;
m_bFirstUpdate = TRUE;
}
CSListView::~CSListView()
{
}
void CSListView::SetFont( LPLOGFONT pLogFont )
{
ASSERT( pLogFont );
HFONT hFont = ::CreateFontIndirect(pLogFont);
m_Grid.SendMessage( WM_SETFONT, (WPARAM)hFont, MAKELPARAM(1, 0) );
m_Grid.AutoSize( );
DeleteObject(hFont);
}
void CSListView::GetSelectedStocks( CSPStringArray & astr )
{
CStockContainer & container = AfxGetSListStockContainer();
container.Lock();
int nTotalCount = m_Grid.GetSelectedCount();
astr.RemoveAll();
astr.SetSize( 0, nTotalCount > 10 ? nTotalCount : -1 );
for( int nRow=1; nRow<m_Grid.GetRowCount(); nRow++ )
{
BOOL bSelected = FALSE;
for( int nCol=0; nCol<m_Grid.GetColumnCount(); nCol ++ )
bSelected |= ( m_Grid.GetItemState(nRow,nCol) & GVIS_SELECTED );
if( !bSelected )
continue;
LPARAM id = m_Grid.GetItemData(nRow,0);
CStockInfo & info = container.GetStockInfoByID(id);
astr.Add( info.GetStockCode() );
}
container.UnLock();
}
void CSListView::ExportList( CListExportDlg * pDlg )
{
ASSERT( pDlg );
if( NULL == pDlg )
return;
int nColumnCount = m_Grid.GetColumnCount();
ASSERT( nColumnCount > 0 );
if( nColumnCount <= 0 )
return;
CStockContainer & container = AfxGetSListStockContainer();
// Get Current StockList Time
DWORD dwDate;
CSPTime sptime;
CSPTime time;
if( container.GetCurrentType( NULL, NULL, &dwDate )
&& (-1 != dwDate || container.GetLatestTechDate(&dwDate))
&& sptime.FromStockTimeDay( dwDate ) )
time = CSPTime( sptime.GetTime() );
// Set Column
CStringArray astrColumn;
CUIntArray anWidth;
CUIntArray anParams;
for(int nCol = 0; nCol < nColumnCount; nCol ++ )
{
astrColumn.Add( m_Grid.GetItemText(0,nCol) );
anWidth.Add( m_Grid.GetColumnWidth(nCol) );
anParams.Add( m_Grid.GetItemData(0,nCol) );
}
if( ! pDlg->ExportBegin( astrColumn, anWidth, TRUE )
|| ! pDlg->ExportOpenTable( time, TRUE ) )
return;
container.Lock();
// set Item
int nCount = 0, nTotalCount = 0;
if( pDlg->m_bItemAll )
{
nTotalCount = m_Grid.GetRowCount()-1;
pDlg->SetProgressRange( 0, nTotalCount );
for( int nRow=1; nRow<m_Grid.GetRowCount(); nRow++ )
{
CStringArray astrItemText;
astrItemText.SetSize( 0, nColumnCount+1 );
LPARAM id = m_Grid.GetItemData(nRow,0);
CStockInfo & info = container.GetStockInfoByID(id);
for(int nCol=0; nCol<anParams.GetSize(); nCol++ )
{
astrItemText.Add( m_Grid.GetItemText( nRow, nCol ) );
}
pDlg->ExportAddItem( astrItemText );
nCount ++;
pDlg->SetProgress( nCount );
}
}
else if( pDlg->m_bItemSelected )
{
nTotalCount = m_Grid.GetSelectedCount();
pDlg->SetProgressRange( 0, nTotalCount );
for( int nRow=1; nRow<m_Grid.GetRowCount(); nRow++ )
{
BOOL bSelected = FALSE;
for( int nCol=0; nCol<m_Grid.GetColumnCount(); nCol ++ )
bSelected |= ( m_Grid.GetItemState(nRow,nCol) & GVIS_SELECTED );
if( !bSelected )
continue;
CStringArray astrItemText;
astrItemText.SetSize( 0, nColumnCount+1 );
LPARAM id = m_Grid.GetItemData(nRow,0);
CStockInfo & info = container.GetStockInfoByID(id);
for( int nCol=0; nCol<anParams.GetSize(); nCol++ )
{
astrItemText.Add( m_Grid.GetItemText( nRow, nCol ) );
}
pDlg->ExportAddItem( astrItemText );
nCount ++;
pDlg->SetProgress( nCount );
}
}
else if( pDlg->m_bItemDefine )
{
nTotalCount = min(m_Grid.GetRowCount()-1,pDlg->m_nItemEnd) - max(1,pDlg->m_nItemBegin) + 1;
pDlg->SetProgressRange( 0, nTotalCount );
for( int nRow=max(1,pDlg->m_nItemBegin); nRow<=min(m_Grid.GetRowCount()-1,pDlg->m_nItemEnd); nRow++ )
{
CStringArray astrItemText;
astrItemText.SetSize( 0, nColumnCount+1 );
LPARAM id = m_Grid.GetItemData(nRow,0);
CStockInfo & info = container.GetStockInfoByID(id);
for( int nCol=0; nCol<anParams.GetSize(); nCol++ )
{
astrItemText.Add( m_Grid.GetItemText( nRow, nCol ) );
}
pDlg->ExportAddItem( astrItemText );
nCount ++;
pDlg->SetProgress( nCount );
}
}
container.UnLock();
pDlg->ExportFinish( );
}
void CSListView::RemoveSortSign( )
{
if( m_nColSort < 0 || m_nColSort >= m_Grid.GetColumnCount() )
return;
LPARAM lParam = m_Grid.GetItemData( 0, m_nColSort );
CString strColTitle = AfxGetVariantName(lParam,TRUE);
m_Grid.SetItemText( 0, m_nColSort, strColTitle );
m_nColSort = -1;
m_bSortAscend = FALSE;
}
void CSListView::SetSortSign( )
{
if( m_nColSort < 0 || m_nColSort >= m_Grid.GetColumnCount() )
return;
CString strPrefix, strColTitle;
if( m_bSortAscend )
strPrefix.LoadString( IDS_SLISTVIEW_UP );
else
strPrefix.LoadString( IDS_SLISTVIEW_DOWN );
LPARAM lParam = m_Grid.GetItemData( 0, m_nColSort );
strColTitle = AfxGetVariantName(lParam,TRUE);
strColTitle = strPrefix + strColTitle;
m_Grid.SetItemText( 0, m_nColSort, strColTitle );
}
void CSListView::SetSortVariant( UINT nVariant )
{
RemoveSortSign( );
for( int nCol=0; nCol < m_Grid.GetColumnCount(); nCol++ )
{
LPARAM lParam = m_Grid.GetItemData( 0, nCol );
if( (UINT)lParam == nVariant )
{
m_nColSort = nCol;
m_bSortAscend = FALSE;
SetSortSign();
break;
}
}
}
void CSListView::SetCurrentStatus( int nType, LPCTSTR lpszDomain, DWORD dwDate )
{
AfxGetSListStockContainer().RetrieveFromStatic( nType, lpszDomain, AfxGetActiveStrategy(), dwDate );
OnUpdate( NULL, UPDATE_HINT_SLISTVIEW, NULL );
//CMainFrame * pFrame = AfxGetMainFrame();
//if( pFrame )
// pFrame->m_DateBox.SetCurrentWindowText( );
}
void CSListView::StoreColumnOrderArray( )
{
// Now The CGridCtrl cannot drag and drop columns, so nothing to do
// in this function
return;
}
void CSListView::ResetColumns( )
{
CStockContainer & container = AfxGetSListStockContainer();
container.Lock();
// its list control through a call to GetListCtrl().
CSPDWordArray & auint = AfxGetProfile().GetSListColumnsShow( );
ASSERT( auint.GetSize() > 0 );
m_Grid.SetRedraw( FALSE );
m_Grid.DeleteAllItems();
m_Grid.SetRowCount(1);
m_Grid.SetFixedRowCount(1);
m_Grid.SetFixedColumnCount(1);
m_Grid.SetColumnCount(auint.GetSize());
for( int nCol=0; nCol<auint.GetSize(); nCol++ )
{
CString string = AfxGetVariantName(auint[nCol],TRUE);
m_Grid.SetItemText( 0, nCol, string );
m_Grid.SetItemData( 0, nCol, auint[nCol] );
m_Grid.SetItemFormat( 0, nCol, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
m_Grid.SetItemBkColour( 0, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
m_Grid.SetItemFgColour( 0, nCol, AfxGetProfile().GetColor(CColorClass::clrTitle) );
}
m_Grid.AutoSizeColumns();
m_Grid.SetRedraw( TRUE, TRUE );
m_Grid.Invalidate( );
container.UnLock();
}
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( int 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( int 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( int 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -