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

📄 setrule.cpp.svn-base

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

#include "stdafx.h"

#include "SetRule.h"
#include "../ParamDlg/SetParamDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSetRule property page

#define	SETRULE_MAINLEFT	228
#define	SETRULE_MAINTOP		23


IMPLEMENT_DYNCREATE(CSetRule, CPropertyPageEx)

CSetRule::CSetRule() : CPropertyPageEx(CSetRule::IDD)
{
	//{{AFX_DATA_INIT(CSetRule)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_pParamDlg			=	NULL;
	m_pTechParameters	=	NULL;
	m_panSelectedTechs	=	NULL;

	m_dwButtonFlags	=	PSWIZB_BACK | PSWIZB_NEXT;
	m_bModified		=	FALSE;
}

CSetRule::CSetRule( UINT nIDCaption, UINT nIDTitle, UINT nIDSubTitle )
		 : CPropertyPageEx(CSetRule::IDD,nIDCaption, nIDTitle, nIDSubTitle)
{
	m_pParamDlg			=	NULL;
	m_pTechParameters	=	NULL;
	m_panSelectedTechs	=	NULL;

	m_dwButtonFlags	=	PSWIZB_BACK | PSWIZB_NEXT;
	m_bModified		=	FALSE;
}

CSetRule::~CSetRule()
{
	if( m_pParamDlg )
	{
		delete	m_pParamDlg;
		m_pParamDlg	=	NULL;
	}
}

void CSetRule::SetTechParameters( CTechParameters * pParam, CSPDWordArray *panSelectedTechs )
{
	ASSERT( pParam && panSelectedTechs );
	m_pTechParameters	=	pParam;
	m_panSelectedTechs	=	panSelectedTechs;
	m_anSelectedTechs.RemoveAll();
	m_anSelectedTechs.Copy( *panSelectedTechs );
}

BOOL CSetRule::InitTreeTechs( )
{
	if( NULL == m_ImageList.GetSafeHandle() )
	{
		m_ImageList.Create(IDB_TECHSVIEW_ICONS, 16, 1, RGB(0,255,0));
		m_tree.SetImageList (&m_ImageList, TVSIL_NORMAL);
	}

	m_tree.DeleteAllItems();

	CString	strClassLast;
	HTREEITEM	hTechClass = NULL, hTech = NULL, hTechFirstSelected = NULL;
	UINT nTechUserCount = CTechUser::GetTechUserCount();
	for( UINT i=STT_MIN; i <= STT_MAX+nTechUserCount; i ++ )
	{
		UINT	nTech	=	i;
		if( nTech > STT_MAX )
			nTech	=	i-STT_MAX-1+STT_USER_MIN;

		if( STT_PV == nTech || STT_DJ == nTech || STT_CW == nTech || STT_MIKE == nTech
			|| STT_AD == nTech || STT_CI == nTech || STT_R == nTech || STT_DMI == nTech
			|| STT_CDP == nTech )
			continue;

		CString	strClass	=	AfxGetSTTClassName(nTech);
		if( strClass.GetLength() > 0 && 0 != strClass.Compare(strClassLast) )
		{
			hTechClass = m_tree.InsertItem(strClass,IMG_TECHCLASS,IMG_TECHCLASS_SEL);
			m_tree.SetItemData( hTechClass, 0 );
			m_anClassChecked.Add( 0 );
		}

		strClassLast	=	strClass;

		if( NULL == hTechClass )
			hTechClass	=	TVI_ROOT;
		CString	strTechName	=	AfxGetSTTFullName(nTech);
		hTech	=	m_tree.InsertItem(strTechName,IMG_TECH,IMG_TECH_SEL,hTechClass);
		m_tree.SetItemData( hTech, nTech );

		for( int i=0; i<m_anSelectedTechs.GetSize(); i++ )
		{
			if( m_anSelectedTechs[i] == nTech )
			{
				m_tree.SetCheck( hTech, TRUE );
				if( NULL == hTechFirstSelected )
					hTechFirstSelected	=	hTech;
			}
		}
	}

	HTREEITEM	hParent	=	m_tree.GetParentItem(hTechFirstSelected);
	if( NULL == hParent )
		hParent	=	m_tree.GetRootItem();
	m_tree.Expand( hParent, TVE_EXPAND );
	m_tree.Select( hTechFirstSelected, TVGN_CARET );
	
	::PostMessage( GetSafeHwnd(), WM_USER_SETRULECLICKTREE, 0, 0 );
	return TRUE;
}

void CSetRule::GetCurrentSelectedTechs( CSPDWordArray & au )
{
	au.RemoveAll();
	HTREEITEM	hItem	=	m_tree.GetRootItem();
	while( hItem )
	{
		HTREEITEM	hChild	=	m_tree.GetChildItem( hItem );
		while( hChild )
		{
			if( m_tree.GetCheck( hChild ) )
			{
				UINT	nTech	=	m_tree.GetItemData(hChild);
				if( (nTech >= STT_MIN && nTech <= STT_MAX) || nTech >= STT_USER_MIN )
					au.Add( nTech );
			}
			hChild	=	m_tree.GetNextItem( hChild, TVGN_NEXT );
		}
		
		hItem = m_tree.GetNextItem( hItem, TVGN_NEXT );
	}
}

BOOL CSetRule::ValidData( )
{
	if( m_pParamDlg && ::IsWindow(m_pParamDlg->GetSafeHwnd()) )
	{
		if( !m_pParamDlg->RefreshData( TRUE ) )
		{
			AfxMessageBox( IDS_SETPARAM_INVALID, MB_OK | MB_ICONINFORMATION );
			return FALSE;
		}
	}

	GetCurrentSelectedTechs( m_anSelectedTechs );
	if( m_anSelectedTechs.GetSize() <= 0 )
	{
		AfxMessageBox( IDS_SETRULE_NOSELECTED, MB_OK | MB_ICONINFORMATION );
		return FALSE;
	}

	return TRUE;
}

BOOL CSetRule::StoreData( )
{
	GetCurrentSelectedTechs( m_anSelectedTechs );
	if( m_panSelectedTechs )
		m_bModified = (m_bModified || !m_panSelectedTechs->IsEqualTo(m_anSelectedTechs) );
	if( m_panSelectedTechs )
		m_panSelectedTechs->Copy( m_anSelectedTechs );

	if( m_pParamDlg && ::IsWindow(m_pParamDlg->GetSafeHwnd()) )
	{
		m_pParamDlg->OnCmdMsg( IDOK, 0, NULL, NULL );
		delete	m_pParamDlg;
		m_pParamDlg	=	NULL;
	}
	return TRUE;
}

void CSetRule::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPageEx::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetRule)
	DDX_Control(pDX, IDC_TREE, m_tree);
	DDX_Control(pDX, IDC_ALLDEFAULT, m_btnAllDefault);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSetRule, CPropertyPageEx)
	//{{AFX_MSG_MAP(CSetRule)
	ON_BN_CLICKED(IDC_ALLDEFAULT, OnAlldefault)
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
	ON_NOTIFY(TVN_SELCHANGING, IDC_TREE, OnSelchangingTree)
	ON_NOTIFY(NM_CLICK, IDC_TREE, OnClickTree)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_USER_SETRULECLICKTREE, OnSetRuleClickTree)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetRule message handlers

BOOL CSetRule::OnInitDialog() 
{
	CPropertyPageEx::OnInitDialog();
	
	InitTreeTechs( );

	UpdateData( FALSE );

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CSetRule::OnKillActive() 
{
	// TODO: Add your specialized code here and/or call the base class
	UpdateData( );
	if( !ValidData( ) )
		return FALSE;
	StoreData( );
	return CPropertyPageEx::OnKillActive();
}

LRESULT CSetRule::OnWizardBack() 
{
	// TODO: Add your specialized code here and/or call the base class
	UpdateData( );

⌨️ 快捷键说明

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