Esempio n. 1
0
//////////////////////////////////////////////////////////////////////////////////
// database functions
BOOL AfxInitializeDB( LPSTR lpErr, UINT nMaxSize )
{
	if( lpErr && nMaxSize > 0 )
		memset( lpErr, 0, nMaxSize );

	if( !CStDatabase::CreateSelfDB( AfxGetProfile().GetSelfDBPath() ) )
	{
		if( lpErr )	strncpy( lpErr, db_errcreateselfdb, min(nMaxSize-1,strlen(db_errcreateselfdb)) );
		return FALSE;
	}

	if( !AfxGetDB().SetRootPath( AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB ) )
	{
		if( lpErr )	strncpy( lpErr, db_errrootpath, min(nMaxSize-1,strlen(db_errrootpath)) );
		return FALSE;
	}

	CSPString	strQianlongPath	=	AfxGetProfile().GetQianlongPath();
	if( strQianlongPath.GetLength() > 0
		&& !AfxGetDB().AddAssistantRootPath( strQianlongPath, IStStore::dbtypeQianlong ) )
	{
		if( lpErr )	strncpy( lpErr, db_errqianlongpath, min(nMaxSize-1,strlen(db_errqianlongpath)) );
		return FALSE;
	}

	return TRUE;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
BOOL CSetKDataDlg::DeleteKData( CString strStockCode )
{
	if( strStockCode.GetLength() <= 0 )
		return FALSE;

	UpdateData( );

	if( m_tmDate.GetTime() == -1 )
		return FALSE;

	CStockInfo info;
	CStock	stock;
	if( !info.SetStockCode( CStock::marketUnknown, strStockCode ) )
		return FALSE;
	stock.SetStockInfo( &info );
	
	int nKType = m_comboKType.GetSelect();
	AfxPrepareStockData( &AfxGetDB(), stock, nKType,  CKData::formatOriginal, CKData::mdtypeClose, FALSE, TRUE );
	CKData & kdata = stock.GetKData(nKType);

	CSPTime sptime = m_tmDate.GetTime();
	int nIndex = kdata.GetIndexByDate( sptime.ToStockTime(CKData::IsDayOrMin(kdata.GetKType())) );
	if( nIndex >= 0 && nIndex < kdata.GetSize() )
	{
		kdata.RemoveAt(nIndex);
		AfxGetDB().InstallKData( kdata, TRUE );
		return TRUE;
	}
	return FALSE;
}
Esempio n. 4
0
BOOL CStkUIApp::OnDBChanged( BOOL bRecalculate )
{
	CWaitCursor	waitcursor;

	// Reload DB
	AfxGetStockContainer().Load( &AfxGetDB(), NULL, NULL );
	AfxGetDomainContainer().Load( AfxGetProfile().GetDomainFile() );
	AfxGetGroupContainer().Load( AfxGetProfile().GetGroupFile() );
	AfxGetDB().LoadKDataCache( AfxGetStockContainer(), NULL, NULL, 0, STKLIB_MAX_PROGRESS );
	AfxGetStockContainer().OnDataChanged( );

	AfxGetStkReceiver().RefreshStockContainer( AfxGetStockContainer(), TRUE );

	// Reload AfxGetStockMain()
	AfxReloadStockMain( );

	// Recalcuate Yield
	if( bRecalculate && IDYES == AfxMessageBox( IDS_INSTALLPAC_IFRECALCULATE, MB_YESNO|MB_ICONINFORMATION ) )
	{
		AfxRecalculateYield( AfxGetProfile().GetYieldAverageDays(), TRUE );
		AfxGetStockContainer().ReloadBase( &AfxGetDB() );
	}

	// Update SListBar
	CMainFrame	* pMainFrame	=	AfxGetMainFrame();
	if( pMainFrame )
	{
		pMainFrame->m_SearchBox.InitStocks( TRUE, TRUE, TRUE );
		pMainFrame->m_SearchBox.SetCurrentWindowText( );
		//pMainFrame->m_DateBox.InitDates( );
		//pMainFrame->m_DateBox.SetCurrentWindowText( );
	}

	// Update Views
	AfxGetSListStockContainer().ReRetrieveFromStatic( AfxGetActiveStrategy(), TRUE );
	AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_SLISTVIEW, NULL );
	AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_GRAPHVIEW, NULL );
	AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_BASEVIEW, NULL );
	AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_SIMUVIEW_REREALRUN, NULL );
	AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_SELECTORVIEW, NULL );
	::PostMessage( AfxGetGroupView()->GetSafeHwnd(), WM_USER_UPDATEGROUPS, 0, 0 );

	return TRUE;
}
Esempio n. 5
0
void CSetKDataDlg::LoadKData( CString strStockCode )
{
	if( strStockCode.GetLength() <= 0 )
		return;

	UpdateData();

	m_strOpen.Empty();
	m_strHigh.Empty();
	m_strLow.Empty();
	m_strClose.Empty();
	m_dwVolume = 0;
	m_dwAmount = 0;

	if( m_tmDate.GetTime() == -1 )
	{
		UpdateData( FALSE );
		return;
	}

	CStockInfo info;
	CStock	stock;
	if( !info.SetStockCode( CStock::marketUnknown, strStockCode ) )
		return;
	stock.SetStockInfo( &info );
	
	int nKType = m_comboKType.GetSelect();
	AfxPrepareStockData( &AfxGetDB(), stock, nKType,  CKData::formatOriginal, CKData::mdtypeClose, FALSE, TRUE );
	CKData & kdata = stock.GetKData(nKType);

	// 价格小数位数格式串
	CString strPriceFmt;
	strPriceFmt.Format( "%%.%df", info.DigitBit() );

	CSPTime sptime = m_tmDate.GetTime();
	int nIndex = kdata.GetIndexByDate( sptime.ToStockTime(CKData::IsDayOrMin(kdata.GetKType())) );
	if( nIndex >= 0 && nIndex < kdata.GetSize() )
	{
		KDATA kd = kdata.ElementAt(nIndex);

		m_strOpen.Format( strPriceFmt, kd.m_fOpen );
		m_strHigh.Format( strPriceFmt, kd.m_fHigh );
		m_strLow.Format( strPriceFmt, kd.m_fLow );
		m_strClose.Format( strPriceFmt, kd.m_fClose );
		m_dwVolume	=	(DWORD)(kd.m_fVolume/100);
		m_dwAmount	=	(DWORD)(kd.m_fAmount/1000);
	}

	UpdateData( FALSE );
}
Esempio n. 6
0
UINT LoadKDataCacheMain(LPVOID pParam)
{
	AfxGetDB().LoadKDataCache( AfxGetStockContainer(), NULL, NULL, 0, STKLIB_MAX_PROGRESS );
	AfxGetStockContainer().OnDataChanged( );

	AfxGetStkReceiver().RefreshStockContainer( AfxGetStockContainer(), TRUE );

	AfxReloadStockMain( );

	::PostMessage( AfxGetMainWnd()->GetSafeHwnd(), WM_USER_UPDATESLISTVIEW,0, 0 );
	::PostMessage( AfxGetMainWnd()->GetSafeHwnd(), WM_USER_INITDATES, 0, 0 );

	AfxEndThread( 0, TRUE );
	return 0;
}
Esempio n. 7
0
LRESULT CDownloadDlg::OnStkReceiverData(WPARAM wParam, LPARAM lParam)
{
	PCOMMPACKET	pCommPacket	=	(PCOMMPACKET)lParam;

	switch( wParam )
	{
	case CStock::dataReport:
		if( pCommPacket && CStock::dataReport == pCommPacket->m_dwDataType 
			&& pCommPacket->m_dwCount > 0 )
		{
			m_nReportCount += pCommPacket->m_dwCount;
			for( DWORD i=0; i<pCommPacket->m_dwCount; i++ )
			{
				CKData kdata;
				kdata.SetKType( CKData::ktypeDay );
				KDATA kd;
				if( UpdateKDATAByREPORT( kd, &(pCommPacket->m_pReport[i]) ) )
				{
					kdata.Add( kd );
					AfxGetDB().InstallKData( kdata, FALSE );
				}
			}

			CStockContainer & container = AfxGetStockContainer();
			if( m_nReportRequestSent - m_nReportCount < 64 && m_nReportRequestSent < (UINT)container.GetSize() )
			{
				container.Lock();
				m_nReportRequestSent += AfxGetStkReceiver().RequestStockData( CStock::dataReport, container.GetData()+m_nReportRequestSent, min(160,container.GetSize()-m_nReportRequestSent), 0, 0 );
				container.UnLock();
			}

			if( !m_bReportFinished && m_nReportCount > 0.95 * m_nReportTotal )
			{
				m_bReportFinished = TRUE;
				::SendMessage( GetSafeHwnd(), WM_USER_DOWNLOAD_PROGRESS, STKLIB_MAX_PROGRESS, NULL );
				AfxBeginThread( DownloadMain, (LPVOID)m_pDownloadInfo,THREAD_PRIORITY_NORMAL);
			}
			else if( !m_bReportFinished && m_nReportTotal > 0 )
			{
				DWORD dwProgress = STKLIB_MAX_PROGRESS * m_nReportCount / m_nReportTotal;
				::SendMessage( GetSafeHwnd(), WM_USER_DOWNLOAD_PROGRESS, dwProgress, NULL );
			}
		}
		break;
	}
	return 0L;
}
Esempio n. 8
0
BOOL CSetKDataDlg::StoreKData( CString strStockCode )
{
	if( strStockCode.GetLength() <= 0 )
		return FALSE;

	UpdateData( );

	if( m_tmDate.GetTime() == -1 )
		return FALSE;

	if( !IsNumber(m_strOpen,FALSE) || !IsNumber(m_strHigh,FALSE) || !IsNumber(m_strLow,FALSE)
		|| !IsNumber(m_strClose,FALSE) )
	{
		AfxMessageBox( IDS_SETKDATA_NOTNUMBER );
		return FALSE;
	}

	DWORD dwMarket = CStock::marketUnknown;
	CStockInfo info;
	if( info.SetStockCode(dwMarket, strStockCode) )
		dwMarket = info.GetMarket();
	
	int nKType = m_comboKType.GetSelect();

	CSPTime sptime = m_tmDate.GetTime();
	KDATA kd;
	memset( &kd, 0, sizeof(kd) );
	kd.m_dwMarket = dwMarket;
	strncpy( kd.m_szCode, strStockCode, min(sizeof(kd.m_szCode)-1,strStockCode.GetLength()) );
	kd.m_time = m_tmDate.GetTime();
	kd.m_date = sptime.ToStockTime(CKData::IsDayOrMin(nKType));
	kd.m_fOpen	=	(float)atof(m_strOpen);
	kd.m_fHigh	=	(float)atof(m_strHigh);
	kd.m_fLow		=	(float)atof(m_strLow);
	kd.m_fClose	=	(float)atof(m_strClose);
	kd.m_fVolume	=	(float)m_dwVolume*100;
	kd.m_fAmount	=	(float)m_dwAmount*1000;

	CKData kdata(nKType);
	kdata.Add( kd );
	AfxGetDB().InstallKData( kdata );

	return TRUE;
}
Esempio n. 9
0
void CBaseView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if( UPDATE_HINT_BASEVIEW != lHint )
		return;
	if( IsWindowVisible() )
		SetFocus( );

	CStockInfo	info;
	if( !AfxGetProfile().GetCurrentStock( &info ) )
		return;
	
	CString	strHeader	=	info.GetStockCode();
	strHeader	+=	"  ";
	strHeader	+=	info.GetStockName();
	strHeader	+=	"\r\n\r\n ";
	GetEditCtrl().SetWindowText( strHeader );
	GetEditCtrl().SetSel( strHeader.GetLength()-1, strHeader.GetLength()-1 );

	m_stock.Clear( );
	m_stock.SetStockInfo( &info );
	m_stock.SetDatabase( &AfxGetDB() );

	m_stock.PrepareBaseInfo( TRUE );

	char	* pText	=	m_stock.GetBaseTextPtr();
	int		nLength	=	m_stock.GetBaseTextLength();
	if( pText && nLength > 0 )
	{
		GetEditCtrl().ReplaceSel( pText );
	}
	else
	{
		CString	strNoBaseData;
		strNoBaseData.LoadString( IDS_BASEVIEW_NOBASEDATA );
		GetEditCtrl().ReplaceSel( strNoBaseData );
	}

	GetEditCtrl().SetSel( 0, 0 );

	AfxGetStkReceiver().RequestStockData( CStock::dataBasetext, &info, 1, 0, 0 );
}
Esempio n. 10
0
BOOL AfxReloadStock( CStock & stock )
{
	CStockInfo info = stock.GetStockInfo();

	// Reload AfxGetStockMain()
	AfxGetStockContainer().GetStockInfo( info.GetStockCode(), &info );

	stock.Clear( );
	stock.SetStockInfo( &info );
	stock.SetDatabase( &AfxGetDB() );
	stock.PrepareData( CStock::dataK, CKData::ktypeDay );
	
	// Merge New
	stock.GetKDataDay().MergeKData( &(info.m_kdata) );
	
	stock.PrepareData( CStock::dataK, CKData::ktypeWeek );
	stock.PrepareData( CStock::dataK, CKData::ktypeMonth );
	stock.PrepareData( CStock::dataK, CKData::ktypeMin5 );
	stock.PrepareData( CStock::dataK, CKData::ktypeMin15 );
	stock.PrepareData( CStock::dataK, CKData::ktypeMin30 );
	stock.PrepareData( CStock::dataK, CKData::ktypeMin60 );
	return TRUE;
}
Esempio n. 11
0
UINT AfxRecalculateYield( int nDays, BOOL bReport )
{
	// 计算市场年平均收益率
	double	market_yield_average = 0.0, market_yield_d = 0.0;
	double	market_dayyield_average = 0.0, market_dayyield_d = 0.0;
	CKData	& kdayMain	=	AfxGetStockMain().GetKDataDay();

	if( kdayMain.GetSize() <= nDays )
	{
		if( bReport )
			AfxMessageBox( IDS_RECALYIELD_NOSZZS, MB_OK | MB_ICONINFORMATION );
		return 0;
	}
	BOOL bmarket_yield_ok = CalculateYieldYear( kdayMain, &market_yield_average, &market_yield_d, nDays );
	BOOL bmarket_dayyield_ok = CalculateYieldDay( kdayMain, &market_dayyield_average, &market_dayyield_d, nDays );

	if( !bmarket_yield_ok && !bmarket_dayyield_ok )
	{
		if( bReport )
			AfxMessageBox( IDS_RECALYIELD_NOSZZS, MB_OK | MB_ICONINFORMATION );
	}
	
	// 开始生成结果数据
	CStockContainer & container = AfxGetStockContainer();
	int	nCount	=	0;
	// 等待对话框
	CWaitDlg	*	pWait	=	NULL;
	if( bReport )
	{
		pWait	=	new CWaitDlg( AfxGetMainWnd() );
		pWait->SetProgressRange( 0, container.GetSize()-1 );
	}
	for( int i=0; i<container.GetSize(); i++ )
	{
		if( pWait )
		{
			pWait->SetProgress( i );
			if( pWait->WaitForCancel( ) )
				break;
		}

		CStockInfo	& info	=	container.ElementAt(i);

		LONG	stocktype	=	info.GetType();
		if( CStock::typeshIndex != stocktype && CStock::typeshA != stocktype && CStock::typeshB != stocktype
			&& CStock::typeszIndex != stocktype && CStock::typeszA != stocktype && CStock::typeszB != stocktype )
			continue;

		CStock	stock;
		stock.SetStockInfo( &info );
		AfxPrepareStockData(&AfxGetDB(),stock,CKData::ktypeDay,CKData::formatXDRup,CKData::mdtypeClose,TRUE,TRUE);
		CKData	& kday	=	stock.GetKDataDay();

		info.m_fYield_average		=	(float)STKLIB_DATA_INVALID;
		info.m_fYield_stddev		=	(float)STKLIB_DATA_INVALID;
		info.m_fBeite				=	(float)STKLIB_DATA_INVALID;

		double	yield_average = 0., yield_d = 0., beite = 0. ;
		if( CalculateYieldYear( kday, &yield_average, &yield_d, nDays ) )
		{
			info.m_fYield_average	=	(float)( 100. * yield_average );
			info.m_fYield_stddev	=	(float)( 100. * yield_d );
			if( bmarket_yield_ok && CalculateBeiteYear( kday, kdayMain, market_yield_average, market_yield_d, &beite, nDays ) )
				info.m_fBeite		=	(float)( beite );
			else if( bmarket_dayyield_ok && CalculateBeiteDay( kday, kdayMain, market_dayyield_average, market_dayyield_d, &beite, nDays ) )
				info.m_fBeite		=	(float)( beite );
		}
		else if( CalculateYieldDay( kday, &yield_average, &yield_d, nDays ) )
		{
			info.m_fYield_average	=	(float)( 100. * (pow(1+yield_average,STKLIB_DAYS_INONEYEAR)-1) );
			info.m_fYield_stddev	=	(float)( 100. * sqrt((double)STKLIB_DAYS_INONEYEAR) * yield_d );
			if( bmarket_dayyield_ok && CalculateBeiteDay( kday, kdayMain, market_dayyield_average, market_dayyield_d, &beite, nDays ) )
				info.m_fBeite		=	(float)( beite );
		}

		nCount	++;
	}

	// 保存到硬盘文件
	AfxGetDB().StoreBasetable( container );

	// 关闭等待对话框和目标文件
	if( pWait )
	{
		pWait->DestroyWindow();
		delete	pWait;
	}

	return nCount;
}
Esempio n. 12
0
void CSetBaseDlg::OnStart() 
{
	UpdateData( );

	CNetDatabase	netdb;
	if( !netdb.SetRootPath( AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB ) )
	{
		AfxMessageBox( IDS_ROOTPATH_ERROR, MB_OK | MB_ICONINFORMATION );
		return;
	}

	if( ( m_strFileF10.IsEmpty() && m_strFileTdx.IsEmpty() && m_strFileFxj.IsEmpty() && m_strPathFxjBlock.IsEmpty() )
		|| ( 0 != access(m_strFileF10,0) && 0 != access(m_strFileTdx,0) && 0 != access(m_strFileFxj,0) && 0 != access(m_strPathFxjBlock,0) ) )
	{
		AfxMessageBox( IDS_SETBASE_FILENOTEXISTS, MB_OK|MB_ICONINFORMATION );
		return;
	}

	m_btnStart.EnableWindow( FALSE );

	AfxGetApp()->WriteProfileString( "setbasedlg", "filef10", m_strFileF10 );
	AfxGetApp()->WriteProfileString( "setbasedlg", "filetdx", m_strFileTdx );
	AfxGetApp()->WriteProfileString( "setbasedlg", "filefxj", m_strFileFxj );
	AfxGetApp()->WriteProfileString( "setbasedlg", "pathfxjblock", m_strPathFxjBlock );

	m_ctrlProgress.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
	m_ctrlProgress.SetRange( 0, STKLIB_MAX_PROGRESS );
	m_ctrlProgress.SetPos( 0 );

	if( m_strFileF10.GetLength() > 0 )
	{
		CPackage	pac;
		pac.m_nType		=	CPackage::packageBasetext;
		pac.m_bIsZipped	=	( m_strFileF10.GetLength() > 4 && 0 == m_strFileF10.Right(4).CompareNoCase(".zip") );
		pac.m_strDescript	=	m_strFileF10;
		if( netdb.InstallPackageEx( pac, m_strFileF10, InstallBaseCallback, GetSafeHwnd() ) )
			AfxMessageBox( IDS_SETBASE_INSTALLF10OK, MB_OK|MB_ICONINFORMATION );
		else
			AfxMessageBox( IDS_SETBASE_INSTALLF10FAIL, MB_OK|MB_ICONINFORMATION );
	}
	
	if( m_strFileTdx.GetLength() > 0 )
	{
		CPackage	pac;
		pac.m_nType		=	CPackage::packageBasetable;
		pac.m_bIsZipped	=	( m_strFileTdx.GetLength() > 4 && 0 == m_strFileTdx.Right(4).CompareNoCase(".zip") );
		pac.m_strDescript	=	m_strFileTdx;
		if( netdb.InstallPackageEx( pac, m_strFileTdx, NULL, NULL ) )
			AfxMessageBox( IDS_SETBASE_INSTALLTDXOK, MB_OK|MB_ICONINFORMATION );
		else
			AfxMessageBox( IDS_SETBASE_INSTALLTDXFAIL, MB_OK|MB_ICONINFORMATION );
	}
	
	if( m_strFileFxj.GetLength() > 0 )
	{
		CPackage	pac;
		pac.m_nType		=	CPackage::packageBasetable;
		pac.m_bIsZipped	=	( m_strFileFxj.GetLength() > 4 && 0 == m_strFileFxj.Right(4).CompareNoCase(".zip") );
		pac.m_strDescript	=	m_strFileFxj;
		if( netdb.InstallPackageEx( pac, m_strFileFxj, NULL, NULL ) )
			AfxMessageBox( IDS_SETBASE_INSTALLFXJOK, MB_OK|MB_ICONINFORMATION );
		else
			AfxMessageBox( IDS_SETBASE_INSTALLFXJFAIL, MB_OK|MB_ICONINFORMATION );
	}

	if( m_strPathFxjBlock.GetLength() > 0 )
	{
		CPackage	pac;
		pac.m_nType		=	CPackage::packageCode;
		pac.m_bIsZipped	=	( m_strPathFxjBlock.GetLength() > 4 && 0 == m_strPathFxjBlock.Right(4).CompareNoCase(".zip") );
		pac.m_strDescript	=	m_strPathFxjBlock;

		BOOL bOK = FALSE;
		int	nFileCountTotal	=	CNetDatabase::GetFileCount( m_strPathFxjBlock, FALSE );

		DWORD	attr = GetFileAttributes( m_strPathFxjBlock );
		if( 0xFFFFFFFF != attr && (attr & FILE_ATTRIBUTE_DIRECTORY) )
			bOK =	netdb.InstallPackagePath( pac, m_strPathFxjBlock, InstallBaseCallback, GetSafeHwnd(), nFileCountTotal, 0, FALSE );
		else
			bOK =	netdb.InstallPackage( pac, m_strPathFxjBlock, InstallBaseCallback, GetSafeHwnd() );

		if( bOK )
		{
			AfxGetDomainContainer().Store( AfxGetProfile().GetDomainFile() );
			AfxMessageBox( IDS_SETBASE_INSTALLFXJBLOCKOK, MB_OK|MB_ICONINFORMATION );
		}
		else
			AfxMessageBox( IDS_SETBASE_INSTALLFXJBLOCKFAIL, MB_OK|MB_ICONINFORMATION );
	}

	m_ctrlProgress.SetPos( STKLIB_MAX_PROGRESS );
	m_btnStart.EnableWindow( TRUE );

	AfxGetStockContainer().ReloadBase( &AfxGetDB() );
	AfxGetSListStockContainer().ReRetrieveFromStatic( AfxGetActiveStrategy() );
	AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_GRAPHVIEW, NULL );
	AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_BASEVIEW, NULL );
	AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_SLISTVIEW, NULL );
	AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_SELECTORVIEW, NULL );
}
Esempio n. 13
0
BOOL AfxReleaseDB( )
{
	AfxGetDB().SetRootPath( NULL );
	AfxGetDB().RemoveAllAssistant( );
	return TRUE;
}
Esempio n. 14
0
void CSetColumnDlg::OnOK() 
{
	// TODO: Add extra validation here
	m_btnOK.EnableWindow( FALSE );

	// Store Show Items
	CSPDWordArray	& anShow	= AfxGetProfile().GetSListColumnsShow( );
	CSPDWordArray	& anOrder	= AfxGetProfile().GetSListColumnsOrder( );
	anShow.RemoveAll();
	anOrder.RemoveAll();
	for( int i=0; i<m_listColumn.GetItemCount(); i++ )
	{
		UINT	nID	=	m_listColumn.GetItemData( i );
		anOrder.Add( nID );

		if( m_listColumn.GetCheck( i ) )
			anShow.Add( nID );
	}

	if( 0 == anShow.GetSize() && IDNO == AfxMessageBox( IDS_SETCOLUMN_NOSELECT, MB_YESNO ) )
		return;

	// Store Parameters
	m_listColumn.HideItemComboBox( );
	for( int nItem=0; nItem<m_listColumn.GetItemCount(); nItem++ )
	{
		// Set Item Text
		UINT	nID	=	m_listColumn.GetItemData(nItem);

		// Set Column Combo Text
		CString	strParam;
		if( SLH_DIFF == nID )
		{
			strParam	=	m_listColumn.GetItemText( nItem, 2 );
			int	nDays	=	atol( strParam );
			AfxGetProfile().SetDiffDays( nDays );
		}
		else if( SLH_DIFFPERCENT == nID )
		{
			strParam	=	m_listColumn.GetItemText( nItem, 2 );
			int	nDays	=	atol( strParam );
			AfxGetProfile().SetDiffPercentDays( nDays );
		}
		else if( SLH_SCOPE == nID )
		{
			strParam	=	m_listColumn.GetItemText( nItem, 2 );
			int	nDays	=	atol( strParam );
			AfxGetProfile().SetScopeDays( nDays );
		}
		else if( SLH_RATIO_CHANGEHAND == nID )
		{
			strParam	=	m_listColumn.GetItemText( nItem, 2 );
			int	nDays	=	atol( strParam );
			AfxGetProfile().SetRatioChangeHandDays( nDays );
		}
		else if( SLH_RATIO_VOLUME == nID )
		{
			strParam	=	m_listColumn.GetItemText( nItem, 2 );
			int	nDays	=	atol( strParam );
			AfxGetProfile().SetRatioVolumeDays( nDays );
		}
		else if( SLH_RS == nID )
		{
			strParam	=	m_listColumn.GetItemText( nItem, 2 );
			int	nDays	=	atol( strParam );
			AfxGetProfile().SetRSDays( nDays );
		}
		else if( SLH_ANNGAINS_AVERAGE == nID )
		{
			strParam	=	m_listColumn.GetItemText( nItem, 2 );
			int	nDays	=	atol( strParam );
			AfxGetProfile().SetYieldAverageDays( nDays );
		}
	}
	
	AfxGetProfile().StoreProfile( );

	CXFDialog::OnOK();

	//CMainFrame	* pMainFrame	=	AfxGetMainFrame();
	//if( pMainFrame )
	//{
	//	pMainFrame->m_DateBox.InitDates( );
	//	pMainFrame->m_DateBox.SetCurrentWindowText( );
	//}

	// Recalculate Yield Average
	if( AfxGetProfile().GetYieldAverageDays() != m_nYieldAverageDaysOld )
	{
		// Need Recalculate
		if( IDYES == AfxMessageBox( IDS_SETCOLUMN_IFRECALCULATE, MB_YESNO|MB_ICONINFORMATION ) )
		{
			AfxRecalculateYield( AfxGetProfile().GetYieldAverageDays(), TRUE );
			AfxGetStockContainer().ReloadBase( &AfxGetDB() );
			AfxGetSListStockContainer().ReRetrieveFromStatic( AfxGetActiveStrategy() );
		}
	}
	
	//	Clear the User Defined Index Cache
	if( m_bUserIndexModified )
		AfxGetSListStockContainer().ClearVariantSaveValue();
}
Esempio n. 15
0
BOOL CStkUIApp::InitInstance()
{
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.
	AfxSocketInit( );

	AfxOleInit();

	// 程序只能启动一个实例
	m_pMutex = CreateMutex(NULL, FALSE, _T("TsKing"));
	if (m_pMutex != NULL)
	{
		if (GetLastError() == ERROR_ALREADY_EXISTS)
		{
			CloseHandle(m_pMutex);
			m_pMutex = NULL;

			return FALSE;
		}
	}

	GetVersionNumber();

	AfxGetProfile().LoadProfile( );
	::SetCurrentDirectory( AfxGetProfile().GetWorkDirectory() );
	AfxGetSView().Load( AfxGetProfile().GetSViewFile() );

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	// SetRegistryKey( szRegKeyCompany );
	AfxRegSetValue( szRegKeyCompany, szRegKeyApp, "Install", "Path", AfxGetProfile().GetWorkDirectory() );
	AfxRegSetValue( szRegKeyCompany, szRegKeyApp, "Install", "Version", AfxGetProfile().GetVersion() );

	// change profile ( INI file )
	BOOL bEnable = AfxEnableMemoryTracking(FALSE);
	if( m_pszProfileName )	free((void*)m_pszProfileName);
	m_pszProfileName = _tcsdup(AfxGetProfile().GetWorkDirectory()+m_pszExeName+".ini");
	AfxEnableMemoryTracking(bEnable);

	LoadStdProfileSettings(64);  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	// Enable DDE Execute open
	EnableShellOpen();
	AfxUnregisterShellFileTypes();
	// AfxRegisterShellFileTypes(FALSE);

	// Empty Temp Directory
	{
		CNetDatabase netdb;
		if (netdb.SetRootPath(AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB))
			netdb.EmptyTempDirectory();
	}
	AfxSetDB(&AfxGetNetDB());
	//*/

	// Load Data
	char szErr[1024];
	if (!AfxInitializeDB(szErr, sizeof(szErr)))
	{
		AfxMessageBox(szErr, MB_OK | MB_ICONINFORMATION);
		return FALSE;
	}

	// 初始化
	AfxGetStockContainer().Load(&AfxGetDB(), NULL, NULL);				// 读取证券信息,代码表、财务、除权等
	AfxGetDomainContainer().Load(AfxGetProfile().GetDomainFile());		// 读取板块
	AfxGetGroupContainer().Load(AfxGetProfile().GetGroupFile());		// 读取自选板块

	// 分析标准外壳命令、DDE、打开文件操作的命令行
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

#ifdef _TSK_MAINFRAME
	// 注册应用程序的文档模板。文档模板
	// 将用作文档、框架窗口和视图之间的连接
	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CStaticDoc),
		RUNTIME_CLASS(CMainFrame),       // 主 SDI 框架窗口
		RUNTIME_CLASS(CSListView));
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);

	// 调度在命令行中指定的命令。如果
	// 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
#else
	// Create MainFrame and Static Doc and child frames and static views
	CStaticDoc* pStaticDoc = CStaticDoc::OpenDocumentFile(NULL);
	if (pStaticDoc == NULL)
	{
		AfxMessageBox(IDS_STATICDOC_FAILED, MB_OK | MB_ICONINFORMATION);
		return FALSE;
	}
	pStaticDoc->m_bAutoDelete = FALSE;
	CString	strAppTitle;
	strAppTitle.LoadString(AFX_IDS_APP_TITLE);
	pStaticDoc->SetTitle(strAppTitle);
	SetStaticDoc(pStaticDoc);

	// Create MainFrame
	CMainFrame* pMainFrame = CMainFrame::CreateNewFrame();
	if (pMainFrame == NULL)
	{
		AfxMessageBox(IDS_STATICDOC_FAILED, MB_OK | MB_ICONINFORMATION);
		delete pStaticDoc;
		SetStaticDoc(NULL);
		return FALSE;
	}
	SetMainWnd(pMainFrame);
#endif

	// 股票行情接收
	AfxGetStkReceiver().CreateReceiver(m_pMainWnd);
	AfxGetStkReceiver().NetEngineSetAutoReport(FALSE);

	/* Show Startup Window
	CStartupDlg startup;
	CBitmap	bmp;
	bmp.LoadBitmap(IDB_DLGLEFTLOGO);
	startup.SetBitmap((HBITMAP)bmp.GetSafeHandle());
	startup.SetLoadProgramFunc(LoadProgram);
	if (IDOK != startup.DoModal())
	{
		pMainFrame->SendMessage(WM_CLOSE);
		return FALSE;
	}
	//*/

	/* Show Splash Window
	CSplashDlg splash;
	CBitmap bmp;
	bmp.LoadBitmap(IDB_SPLASH);
	splash.SetBitmap(HBITMAP(bmp.GetSafeHandle()));
	splash.Create(NULL, 0, AfxGetSView().GetU(), AfxGetSView().GetS(), AfxGetVersionString(), FALSE, 0, STKLIB_MAX_PROGRESS);
	splash.ShowWindow(SW_SHOW);
	splash.UpdateWindow();
	LoadProgram(splash.GetSafeHwnd(), 0, STKLIB_MAX_PROGRESS);
	splash.DestroyWindow();
	//*/

	// //////////////////////////////////////////////////////////////

	// Open Simulation Strategy
	if (GetFirstStrategyPosition() == NULL)
	{
		if (OpenLastOpenedStrategy() == 0)
			OpenDefaultStrategy();
	}

	//if (!AfxGetStaticDoc()->GetViewIfExist(RUNTIME_CLASS(CSListView)))
	//	AfxGetStaticDoc()->ShowStaticView(RUNTIME_CLASS(CSListView), TRUE);

	//AfxSwitchToStaticView(RUNTIME_CLASS(CSListView));

	AfxGetProfile().SetCurrentStock(STKLIB_CODE_SZZS, FALSE);
	((CMainFrame*)m_pMainWnd)->m_SearchBox.InitStocks( TRUE, TRUE, TRUE );
	((CMainFrame*)m_pMainWnd)->m_SearchBox.SetCurrentWindowText();

	//*//////////////////////////////////////////////////////////////

	// Dispatch commands specified on the command line
	if( CCommandLineInfo::AppUnregister == cmdInfo.m_nShellCommand )
	{
		AfxUnregisterShellFileTypes();
		if (!cmdInfo.m_bRunEmbedded)
			AfxMessageBox(AFX_IDP_UNREG_DONE, MB_OK | MB_ICONINFORMATION);
		if (m_pCmdInfo == NULL)
		{
			m_pCmdInfo = new CCommandLineInfo;
			m_pCmdInfo->m_nShellCommand = CCommandLineInfo::AppUnregister;
		}
		return FALSE;
	}

	// Dispatch commands specified on the command line
	if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileOpen)
	{
		OpenStrategyFile(cmdInfo.m_strFileName);
		AfxSwitchToStaticView(RUNTIME_CLASS(CSimuView));
	}

	// 启动通视接收系统,不显示选择接收系统对话框
	//AfxGetStkReceiver().EngineBeginWorking(FALSE);

	// The one and only window has been initialized, so show and update it.
	// Load Last WindowPlacement
	WINDOWPLACEMENT wp;
	if (AfxGetProfile().GetWindowPlacement(&wp))
		m_pMainWnd->SetWindowPlacement(&wp);
	else
		m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);

	// Enable drag/drop open
	//m_pMainWnd->DragAcceptFiles();

	// Check New Version
	m_pMainWnd->SetTimer(TIMER_AUTOUPDATE, 5000, NULL);

	return TRUE;
}
Esempio n. 16
0
BOOL CALLBACK LoadProgram( HWND hWnd, int nMinProgress, int nMaxProgress )
{
	int nMin = nMinProgress;
	int nMax = nMaxProgress;
	int nRange = nMaxProgress-nMinProgress;
	CStkUIApp * pApp = AfxGetStkUIApp();
	if( NULL == pApp )
		return FALSE;

	CStaticDoc * pStaticDoc = pApp->GetStaticDoc();
	CMainFrame * pMainFrame = AfxGetMainFrame();

	HINSTANCE hInstanceOld = AfxGetResourceHandle();
	AfxSetResourceHandle( AfxGetInstanceHandle() );

	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin, 0 );

	AfxGetStockContainer().Load( &AfxGetDB(), NULL, NULL );
	AfxGetDomainContainer().Load( AfxGetProfile().GetDomainFile() );
	AfxGetGroupContainer().Load( AfxGetProfile().GetGroupFile() );
	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*4/30, 0 );

	pMainFrame->m_SearchBox.InitStocks( TRUE, TRUE, TRUE );
	//pMainFrame->m_DateBox.InitDates( );
	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*8/30, 0 );

	// Open Simulation Strategy
	if( NULL == pApp->GetFirstStrategyPosition() )
	{
		if( 0 == pApp->OpenLastOpenedStrategy( ) )
			pApp->OpenDefaultStrategy( );
	}
	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*12/30, 0 );

	// Show Views
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CWizardView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CWizardView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*14/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CSimuView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CSimuView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*16/30, 0 );
	if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CSListView) ) )
		pStaticDoc->ShowStaticView( RUNTIME_CLASS(CSListView), TRUE );
	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*18/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CRealTimeView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CRealTimeView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*20/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CMultiSortView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CMultiSortView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*22/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CGraphView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CGraphView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*24/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CBaseView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CBaseView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*26/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CInfoView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CInfoView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*28/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CSelectorView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CSelectorView), TRUE );

	AfxSwitchToStaticView( RUNTIME_CLASS(CSListView) );

	AfxGetProfile().SetCurrentStock( STKLIB_CODE_SZZS, FALSE );
	pMainFrame->m_SearchBox.SetCurrentWindowText( );
	//pMainFrame->m_DateBox.SetWindowPos(NULL,0,0,135,200,SWP_NOMOVE|SWP_SHOWWINDOW|SWP_NOZORDER|SWP_NOREDRAW);

	AfxBeginThread( LoadKDataCacheMain, NULL, THREAD_PRIORITY_NORMAL);

	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMax, 0 );

	AfxSetResourceHandle( hInstanceOld );

	return TRUE;
}