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

📄 setgroupdlg.cpp.svn-base

📁 股票软件源码
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
// SetGroupDlg.cpp : implementation file
//

#include "stdafx.h"

#include "SetGroupDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDomainComboBox

CDomainComboBox::CDomainComboBox()
{
}

CDomainComboBox::~CDomainComboBox()
{
}

int CDomainComboBox::InitStrings( BOOL bHasClass, BOOL bHasDomain, CDomainContainer & groups )
{
	ResetContent( );

	CDomainContainer & domains = AfxGetDomainContainer( );
	CStockContainer & container = AfxGetStockContainer();

	int	nItemCount	=	groups.GetSize();
	if( bHasClass )		nItemCount	+=	8;
	if( bHasDomain )	nItemCount	+=	domains.GetSize();
	
	// Init Storage
	InitStorage( nItemCount, 32 );
	CString	strGroup;

	if( bHasClass )
	{
		strGroup.LoadString( IDS_DOMAIN_ALL );
		int nItem = AddString( strGroup );
		SetItemData( nItem, CStockContainer::typeAll );

		strGroup.LoadString( IDS_DOMAIN_INDEX );
		nItem = AddString( strGroup );
		SetItemData( nItem, CStockContainer::typeIndex );
		
		strGroup.LoadString( IDS_DOMAIN_CLASSSHAA );
		nItem = AddString( strGroup );
		SetItemData( nItem, CStockContainer::typeClassShaa );

		strGroup.LoadString( IDS_DOMAIN_CLASSSHAB );
		nItem = AddString( strGroup );
		SetItemData( nItem, CStockContainer::typeClassShab );

		strGroup.LoadString( IDS_DOMAIN_CLASSSZNA );
		nItem = AddString( strGroup );
		SetItemData( nItem, CStockContainer::typeClassSzna );

		strGroup.LoadString( IDS_DOMAIN_CLASSSZNB );
		nItem = AddString( strGroup );
		SetItemData( nItem, CStockContainer::typeClassSznb );

		strGroup.LoadString( IDS_DOMAIN_CLASSSHABOND );
		nItem = AddString( strGroup );
		SetItemData( nItem, CStockContainer::typeClassShabond );

		strGroup.LoadString( IDS_DOMAIN_CLASSSZNBOND );
		nItem = AddString( strGroup );
		SetItemData( nItem, CStockContainer::typeClassSznbond );
	}

	// Domains
	if( bHasDomain )
	{
		for( int i=0; i<domains.GetSize(); i++ )
		{
			CDomain	& domain = domains.ElementAt(i);
			int nItem = AddString( domain.m_strName );
			SetItemData( nItem, CStockContainer::typeDomain );
		}
	}

	// Groups
	for( int i=0; i<groups.GetSize(); i++ )
	{
		CDomain	& domain = groups.ElementAt(i);
		int nItem = AddString( domain.m_strName );
		SetItemData( nItem, CStockContainer::typeGroup );
	}

	return nItemCount;
}

int CDomainComboBox::AddGroup( CString strGroup )
{
	int nItem = AddString( strGroup );
	SetItemData( nItem, CStockContainer::typeGroup );
	return nItem;
}

BOOL CDomainComboBox::DeleteCurSel( )
{
	int nSel = GetCurSel();
	if( CB_ERR != nSel )
	{
		DeleteString( nSel );
		return TRUE;
	}
	return FALSE;
}

int CDomainComboBox::GetCurSelType( )
{
	int nSel = GetCurSel();
	if( CB_ERR != nSel )
		return GetItemData( nSel );
	return -1;
}

CString CDomainComboBox::GetCurSelName( )
{
	int nSel = GetCurSel();
	if( CB_ERR != nSel )
	{
		CString	rString;
		GetLBText( nSel, rString );
		return rString;
	}
	return "";
}

BOOL CDomainComboBox::SelectGroupAll( )
{
	for( int i=0; i<GetCount(); i++ )
	{
		int	nType	=	GetItemData( i );
		if( CStockContainer::typeAll == nType )
		{
			SetCurSel( i );
			return TRUE;
		}
	}
	return FALSE;
}

BEGIN_MESSAGE_MAP(CDomainComboBox, CGuiComboBoxExt)
	//{{AFX_MSG_MAP(CDomainComboBox)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDomainComboBox message handlers

int CDomainComboBox::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CGuiComboBoxExt::OnCreate(lpCreateStruct) == -1)
		return -1;

	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CDomainListBox

CDomainListBox::CDomainListBox()
{
}

CDomainListBox::~CDomainListBox()
{
}

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;
}

BOOL CDomainListBox::SelectCode( int nStart, CString strText )
{
	SelectItem( -1, FALSE );

	int	nLen	=	strText.GetLength();
	if( nLen <= 0 )
		return FALSE;

	CString	rString;
	int	nPos	=	nStart;
	for( int i=0; i<GetCount(); i++ )
	{
		if( nPos >= GetCount() || nPos < 0 )
			nPos	=	0;

		GetText( nPos, rString );
		if( 0 == strncmp( rString, strText, min(nLen,rString.GetLength()) ) )
		{
			SelectItem( i, TRUE );
			SetTopIndex( i > 6 ? i-6 : 0 );
			return TRUE;
		}

		nPos	++;
	}
	return FALSE;
}

BOOL CDomainListBox::SelectShortname( int nStart, CString strText )
{
	SelectItem( -1, FALSE );

	strText.MakeUpper();
	int	nLen	=	strText.GetLength();
	if( nLen <= 0 )
		return FALSE;

	CString	rString;
	int	nPos	=	nStart;
	for( int i=0; i<GetCount(); i++ )
	{
		if( nPos == GetCount() || nPos < 0 )
			nPos	=	0;

		GetText( nPos, rString );
		rString.MakeUpper();
		int	nIndex	=	rString.Find( '(' );
		if( -1 != nIndex )
		{
			rString	=	rString.Mid( nIndex+1 );
			if( 0 == strncmp( rString, strText, min(nLen,rString.GetLength()) ) )
			{
				SelectItem( i, TRUE );
				SetTopIndex( i > 6 ? i-6 : 0 );
				return TRUE;
			}
		}

		nPos	++;
	}
	return FALSE;
}

BOOL CDomainListBox::SelectUp( )
{
	for( int i=0; i<GetCount(); i++ )
	{
		int nStatus = GetSelected( i );
		if( LB_ERR != nStatus && nStatus )
		{
			SelectItem( -1, FALSE );
			SelectItem( i-1 < 0 ? 0 : i-1 );
			return TRUE;
		}
	}

	if( GetCount() > 0 )
		SelectItem( GetCount()-1, TRUE );

	return TRUE;
}

BOOL CDomainListBox::SelectDown( )
{
	int	nPageCount	=	GetCountPerPage( );

	for( int i=0; i<GetCount(); i++ )
	{
		int nStatus = GetSelected( i );
		if( LB_ERR != nStatus && nStatus )
		{
			SelectItem( -1, FALSE );
			int	nNewSel	=	(i+1 >= GetCount() ? GetCount()-1 : i+1);
			SelectAndShowItem( nNewSel );
			return TRUE;
		}
	}

	if( GetCount() > 0 )
		SelectItem( 0, TRUE );

	return TRUE;
}

// Page Up
BOOL CDomainListBox::SelectPrior( )
{
	int	nPageCount	=	GetCountPerPage( );

	for( int i=0; i<GetCount(); i++ )
	{
		int nStatus = GetSelected( i );
		if( LB_ERR != nStatus && nStatus )
		{
			SelectItem( -1, FALSE );
			SelectItem( i-nPageCount < 0 ? 0 : i-nPageCount );
			return TRUE;
		}
	}

	if( GetCount() > 0 )
		SelectItem( GetCount()-1, TRUE );

	return TRUE;
}

// Page Down
BOOL CDomainListBox::SelectNext( )
{
	int	nPageCount	=	GetCountPerPage( );

	for( int i=0; i<GetCount(); i++ )
	{
		int nStatus = GetSelected( i );
		if( LB_ERR != nStatus && nStatus )
		{
			SelectItem( -1, FALSE );
			int	nNewSel	=	(i+nPageCount >= GetCount() ? GetCount()-1 : i+nPageCount);
			SelectAndShowItem( nNewSel );
			return TRUE;
		}
	}

	if( GetCount() > 0 )
		SelectItem( 0, TRUE );

	return TRUE;
}

int CDomainListBox::GetCountPerPage( )
{
	int	nPageCount	=	6;
	CRect	rectItem, rectClient;
	GetClientRect( &rectClient );
	if( LB_ERR != GetItemRect( 0, &rectItem ) && rectItem.Height() > 0 )
		nPageCount	=	rectClient.Height() / rectItem.Height() - 1;

	return nPageCount;
}

BOOL CDomainListBox::SelectAndShowItem( int nSel )
{
	int	nPageCount	=	GetCountPerPage( );

	SelectItem( nSel, TRUE );
	int nTopIndex = GetTopIndex();
	if( LB_ERR != nTopIndex && nTopIndex+nPageCount<nSel )
		SetTopIndex( nSel-nPageCount );
	return TRUE;
}

int CDomainListBox::SelectItem( int nSel, BOOL bSelected )
{
	if( GetStyle( ) & LBS_MULTIPLESEL )
	{
		return SetSel( nSel, bSelected );
	}
	else
	{
		if( bSelected )
			return SetCurSel( nSel );
		else
		{
			if( GetCurSel() == nSel || -1 == nSel )
				return SetCurSel( -1 );
		}
		return -1;
	}
}

int CDomainListBox::GetSelected( int nItem )
{
	if( GetStyle( ) & LBS_MULTIPLESEL )
	{
		return GetSel( nItem );
	}
	else
	{
		if( -1 != nItem && GetCurSel() == nItem )
			return TRUE;
		return FALSE;
	}
}


BEGIN_MESSAGE_MAP(CDomainListBox, CListBox)
	//{{AFX_MSG_MAP(CDomainListBox)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDomainListBox message handlers

int CDomainListBox::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CListBox::OnCreate(lpCreateStruct) == -1)
		return -1;

	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CSetGroupDlg dialog

⌨️ 快捷键说明

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