摘要:
板块数据的安装
1.连接数据服务器,下载板块数据,然后调用通用函数装入容器
2.在界面选择数据导入,只有selDB.cpp实现了安装板块数据
3.主程序启动时,从group.dat读取板块数据到容器。程序退出时,板块容器数据写入group.dat。
一、点击主菜单的菜单项,弹出对话框
主菜单
src/Client/StkUI/StkUI.rc
MENUITEM "历史数据下载(&H)...", ID_DATA_DOWNLOAD
点击菜单项
src/Client/StkUI/MainFrm.cpp
ON_COMMAND(ID_DATA_DOWNLOAD, OnDataDownload)
弹出对话框 CDownloadDlg窗口
////////////////////////////////////////////////////////////////////////////////
// “数据”菜单
// 数据
void CMainFrame::OnDataDownload()
{
CDownloadDlg* dlg = new CDownloadDlg;
dlg->Create(CDownloadDlg::IDD, this);
dlg->SetAutoDelete(TRUE);
dlg->CenterWindow(this);
dlg->SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOSIZE);
}
二、主菜单-数据(D)-历史数据下载(H)-CDownloadDlg弹出框
step 1:弹出框资源定义
G:\stock\TskingVS2019\src\Client\StkUI\StkUI.rc
IDD_DOWNLOAD DIALOGEX 0, 0, 338, 291
STYLE DS_SETFONT | DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "数据下载"
FONT 9, "宋体", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "开始",IDOK,125,259,50,14,BS_FLAT
PUSHBUTTON "停止",IDC_STOP,194,259,50,14,BS_FLAT
PUSHBUTTON "关闭",IDCANCEL,263,259,50,14,BS_FLAT
COMBOBOX IDC_COMBO_SERVERS,34,26,174,87,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "更新服务器列表",IDC_REFRESH_SERVERS,225,26,76,14,BS_FLAT
PUSHBUTTON "停止更新",IDC_STOP_REFRESH,225,43,76,14,BS_FLAT
PUSHBUTTON "代理设置...",IDC_PROXY_SET,225,60,76,14,BS_FLAT
CONTROL "转档当日行情(收盘作业)",IDC_CHECK_REPORT,"Button",BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP,33,97,114,10
CONTROL "日线数据 开始日期",IDC_CHECK_DAY,"Button",BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP,33,114,88,10
CONTROL "DateTimePicker1",IDC_TIME_DAYFROM,"SysDateTimePick32",DTS_RIGHTALIGN | WS_TABSTOP,122,112,63,15
CONTROL "DateTimePicker1",IDC_TIME_DAYTO,"SysDateTimePick32",DTS_RIGHTALIGN | WS_TABSTOP,235,112,63,15
CONTROL "财务资料 -下载最新股票财务资料。",IDC_CHECK_BASE,"Button",BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP,33,148,193,10
CONTROL "除权数据 -下载股票历年除权数据。",IDC_CHECK_XDR,"Button",BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP,33,166,197,10
CONTROL "5分钟数据 开始日期",IDC_CHECK_MIN5,"Button",BS_AUTOCHECKBOX | BS_FLAT | WS_TABSTOP,33,184,88,10
CONTROL "DateTimePicker1",IDC_TIME_MIN5FROM,"SysDateTimePick32",DTS_RIGHTALIGN | WS_TABSTOP,122,180,63,15
CONTROL "DateTimePicker1",IDC_TIME_MIN5TO,"SysDateTimePick32",DTS_RIGHTALIGN | WS_TABSTOP,236,180,63,15
LTEXT "正在下载数据,请稍候...",IDC_STATIC_STATUS,27,221,278,28
LTEXT "正在更新服务器列表,请稍候...",IDC_STATIC_REFRESH,35,44,169,8
LTEXT "结束日期",IDC_STATIC,197,114,33,8
CONTROL "Progress1",IDC_DL_PROGRESS,"msctls_progress32",PBS_SMOOTH,26,208,250,10,WS_EX_STATICEDGE
GROUPBOX "选择下载数据",IDC_STATIC,22,84,293,117
GROUPBOX "选择下载服务器",IDC_STATIC,23,11,292,68
LTEXT "结束日期",IDC_STATIC,196,184,33,8
LTEXT "",IDC_STATIC_PROGRESS,282,208,33,9
LTEXT "本地最新日线数据日期:",IDC_STATIC,87,131,89,8
LTEXT "",IDC_STATIC_LATEST,183,131,118,9
CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME,0,253,337,1,WS_EX_STATICEDGE
END
开始导入按钮定义
G:\stock\TskingVS2019\src\Client\StkUI\Dialog\SetBaseDlg.cpp
BEGIN_MESSAGE_MAP(CSetBaseDlg, CPropertyPageEx)
//{{AFX_MSG_MAP(CSetBaseDlg)
ON_BN_CLICKED(IDC_START, OnStart) //数据管理(&M)...开始导入
ON_BN_CLICKED(IDC_TDXFILE_EXPLORER, OnTdxfileExplorer)
ON_BN_CLICKED(IDC_F10FILE_EXPLORER, OnF10fileExplorer)
ON_BN_CLICKED(IDC_FXJFILE_EXPLORER, OnFxjfileExplorer)
ON_BN_CLICKED(IDC_FXJBLOCKPATH_EXPLORER, OnFxjblockpathExplorer)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_USER_INSTALLBASEPROGRESS, OnInstallBaseProgress)
END_MESSAGE_MAP()
开始导入按钮事件
G:\stock\TskingVS2019\src\Client\StkUI\Dialog\SetBaseDlg.cpp
void CSetBaseDlg::OnStart()
{
...
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 );
}
...
}
G:\stock\TskingVS2019\src\Client\StkNet\Src\NetDB.cpp
BOOL CNetDatabase::InstallPackagePath( CPackage &pac, const char *path,
PROGRESS_CALLBACK fnCallback, void *cookie,
int nTotalCount, int nFinishCount, BOOL bDeleteAfterInstall )
{
if( NULL == path || strlen(path) == 0 )
return FALSE;
CString strFinder = path;
if( strFinder[strFinder.GetLength()-1] != '\\' && strFinder[strFinder.GetLength()-1] != '/' )
strFinder += STRING_DIRSEP;
strFinder += "*";
BOOL bRet = TRUE;
CFileFind finder;
BOOL bWorking = finder.FindFile( strFinder );
while( bWorking )
{
bWorking = finder.FindNextFile();
DWORD attr = GetFileAttributes( finder.GetFilePath() );
if( 0xFFFFFFFF != attr && (attr & FILE_ATTRIBUTE_DIRECTORY) )
{
CString strName = finder.GetFileName();
if( 0 != strName.CompareNoCase(".") && 0 != strName.CompareNoCase("..") )
{
bRet &= InstallPackagePath( pac, finder.GetFilePath() + STRING_DIRSEP,
fnCallback, cookie, nTotalCount, nFinishCount );
if( bDeleteAfterInstall )
RemoveDirectory( finder.GetFilePath() );
}
}
if( 0xFFFFFFFF != attr && !(attr & FILE_ATTRIBUTE_DIRECTORY) )
{
if( 1 == nTotalCount )
bRet &= InstallPackage( pac, finder.GetFilePath(), fnCallback, cookie );
else
bRet &= InstallPackage( pac, finder.GetFilePath(), fnCallback, cookie );
if( bDeleteAfterInstall )
DeleteFile( finder.GetFilePath() );
nFinishCount ++;
if( fnCallback && nTotalCount > 1 )
fnCallback( PROG_PROGRESS, DWORD(STKLIB_MAXF_PROGRESS*nFinishCount/nTotalCount), NULL, cookie );
}
}
finder.Close();
if( fnCallback )
fnCallback( PROG_PROGRESS, STKLIB_MAX_PROGRESS, NULL, cookie );
return bRet;
}
BOOL CNetDatabase::InstallPackage( CPackage &pac, const char *pacfile,
PROGRESS_CALLBACK fnCallback, void *cookie )
{
CString strFilenameOrg;
if( pac.m_bIsZipped )
strFilenameOrg = pacfile;
else if( !pac.m_strURL.IsEmpty() )
strFilenameOrg = pac.m_strURL;
else
strFilenameOrg = pacfile;
int nIndex = strFilenameOrg.ReverseFind( '/' );
if( -1 != nIndex )
strFilenameOrg = strFilenameOrg.Mid( nIndex + 1 );
nIndex = strFilenameOrg.ReverseFind( '\\' );
if( -1 != nIndex )
strFilenameOrg = strFilenameOrg.Mid( nIndex + 1 );
BOOL bOK = strFilenameOrg.GetLength() > 4;
if( bOK && CPackage::packageCode == pac.m_nType )
{
CString strDomainFile = AfxGetProfile().GetDomainFile();
int nIndex = strDomainFile.ReverseFind( '/' );
if( -1 != nIndex )
strDomainFile = strDomainFile.Mid( nIndex + 1 );
nIndex = strDomainFile.ReverseFind( '\\' );
if( -1 != nIndex )
strDomainFile = strDomainFile.Mid( nIndex + 1 );
if( 0 == strFilenameOrg.CompareNoCase( strDomainFile ) ) //安装板块数据
bOK = (InstallCodetblBlock( pacfile, strFilenameOrg ) >= 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".blk" ) ) // 安装分析家板块数据
bOK = (InstallCodetblFxjBlock( pacfile, strFilenameOrg ) >= 0 );
else
bOK = (InstallCodetbl( pacfile, strFilenameOrg ) > 0 );
}
else if( bOK && CPackage::packageDay == pac.m_nType )
{
if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".stk" ) ) // 通用格式
bOK = ( InstallKDataTy( pacfile, CKData::ktypeDay, fnCallback, cookie ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".dad" ) ) // 分析家格式
bOK = ( InstallKDataFxj( pacfile, CKData::ktypeDay, fnCallback, cookie ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".txt" ) ) // 说明文件
bOK = TRUE;
else
bOK = FALSE;
}
else if( bOK && CPackage::packageMin5 == pac.m_nType )
{
if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".stk" ) ) // 通用格式
bOK = ( InstallKDataTy( pacfile, CKData::ktypeMin5, fnCallback, cookie ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".dad" ) ) // 分析家格式
bOK = ( InstallKDataFxj( pacfile, CKData::ktypeMin5, fnCallback, cookie ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".txt" ) ) // 说明文件
bOK = TRUE;
else
bOK = FALSE;
}
else if( bOK && CPackage::packageDR == pac.m_nType )
{
if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".dat" ) ) // 普通格式
bOK = ( InstallDRDataClk( pacfile, strFilenameOrg ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".pwr" ) ) // 分析家除权格式
bOK = ( InstallDRDataFxj( pacfile ) > 0 );
else
bOK = FALSE;
}
else if( bOK && CPackage::packageBasetext == pac.m_nType )
{
if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".txt" ) ) // 文本资料
bOK = ( InstallBaseText( pacfile, strFilenameOrg ) > 0 );
else
bOK = FALSE;
}
else if( bOK && CPackage::packageBasetable == pac.m_nType )
{
if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".bst" ) ) // 财务格式
bOK = ( InstallBasetable( pacfile, strFilenameOrg ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".dbf" ) ) // 通达信财务格式
bOK = ( InstallBasetableTdx( pacfile ) > 0 );
else if( 0 == strFilenameOrg.Right(4).CompareNoCase( ".fin" ) ) // 分析家财务格式
bOK = ( InstallBasetableFxj( pacfile ) > 0 );
else
bOK = FALSE;
}
else
bOK = FALSE;
if( !bOK )
{
CFileStatus rStatus;
if( ! (CFile::GetStatus( pacfile, rStatus ) && rStatus.m_size > 0) )
bOK = TRUE;
}
if( !bOK && fnCallback )
{
CString string = pac.m_strDescript;
fnCallback( PROG_ERRORPAC, 0, string.GetBuffer(string.GetLength()+1), cookie );
string.ReleaseBuffer();
}
return bOK;
}
G:\stock\TskingVS2019\src\Client\StkLib\Src\Database.cpp
int CStDatabase::InstallCodetblFxjBlock( const char * filename, const char *orgname ) //安装分析家板块
{ if(!IsOK()) return 0;
return m_pStore->InstallCodetblFxjBlock( filename, orgname ); }
G:\stock\TskingVS2019\src\Client\StkLib\Src\SelfDB.cpp
int CSelfDB::InstallCodetblFxjBlock(const char * filename, const char *orgname)
{
if (NULL == filename || strlen(filename) == 0
|| NULL == orgname || strlen(orgname) == 0)
return 0;
CSPString sName = orgname;
int nIndex = sName.Find('.');
if (-1 != nIndex)
sName = sName.Left(nIndex);
CDomain domain;
domain.m_strName = sName;
int nRet = domain.AddFxjDomain(filename);
if (nRet > 0)
{
AfxGetDomainContainer().AddDomainReplace(domain);
}
return nRet;
}
G:\stock\TskingVS2019\src\Client\StkLib\Src\Container.cpp
nt CDomain::AddFxjDomain( LPCTSTR lpszFile )
{
CSPFile file;
DWORD dwMagic;
if( !file.Open( lpszFile, CSPFile::modeRead )
|| sizeof(dwMagic) != file.Read(&dwMagic,sizeof(dwMagic)) || dwMagic != 0xFF5100A5 )
return 0;
int nCount = 0;
struct fxj_block_t stock;
while( sizeof(stock) == file.Read(&stock,sizeof(stock)) )
{
if( 0 == stock.szCode[6] )
{
CSPString sCode = stock.szCode;
if( sCode.GetLength() == 4 )
sCode = "00" + sCode;
if( sCode.GetLength() == 6 )
AddStock( sCode );
}
}
return GetSize();
}
调用链:onstart-数据接口->Container里的AddFxjDomain()读取文件写入容器
通达信财务板块数据导入
G:\stock\TskingVS2019\src\Client\StkUI\Dialog\SetBaseDlg.cpp
//数据管理-通达信财务数据导入-选择文件
void CSetBaseDlg::OnTdxfileExplorer()
{
UpdateData( );
CKSFileDialog dlg (TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_ENABLESIZING,
"Tdx Finance Data files (*.zip,*.dbf)|*.zip;*.dbf|All files (*.*)|*.*||", NULL);
if( IDOK == dlg.DoModal() )
{
m_strFileTdx = dlg.GetPathName(); //数据管理-通达信财务数据导入,文件名 by freeman
UpdateData( FALSE );
}
}