摘要:
板块数据的安装
1.连接数据服务器,下载板块数据,然后调用通用函数装入容器
2.在界面选择数据导入,只有selDB.cpp实现了安装板块数据
3.主程序启动时,从group.dat读取板块数据到容器。程序退出时,板块容器数据写入group.dat。
主菜单
MENUITEM "数据管理(&M)...", ID_DATA_MANAGE
点击菜单项
ON_COMMAND(ID_DATA_MANAGE, OnDataManage)
弹出Dlg窗口
void CMainFrame::OnDataManage()
{
CInstallPacDlg installdlg; //安装K线数据包
CTyDataDlg tydata; //导出K线数据包
CSetDrdataDlg setdr;//权息资料
CSetBaseDlg setbase;//板块财务F10导入
CSetBasedataDlg setbasedata;//基本资料修改
CSetKDataDlg setkdata;//K线修复
CPropertySheetEx sht;
sht.AddPage(&installdlg);
sht.AddPage(&tydata);
sht.AddPage(&setdr);
sht.AddPage(&setbase);
sht.AddPage(&setbasedata);
sht.AddPage(&setkdata);
sht.SetActivePage(&installdlg);
sht.DoModal();
}
step 1:主菜单-数据(D)-数据管理(M)-板块财务F10导入
G:\stock\TskingVS2019\src\Client\StkUI\StkUI.rc
IDD_SETBASE DIALOGEX 0, 0, 360, 209
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "板块财务F10导入"
FONT 9, "宋体", 0, 0, 0x1
BEGIN
EDITTEXT IDC_FILE_F10,78,28,186,12,ES_AUTOHSCROLL | NOT WS_BORDER,WS_EX_STATICEDGE
PUSHBUTTON "浏览...",IDC_F10FILE_EXPLORER,267,26,48,14,BS_FLAT
EDITTEXT IDC_FILE_TDX,78,66,186,12,ES_AUTOHSCROLL | NOT WS_BORDER,WS_EX_STATICEDGE
PUSHBUTTON "浏览...",IDC_TDXFILE_EXPLORER,267,64,48,14,BS_FLAT
EDITTEXT IDC_FILE_FXJ,78,104,186,12,ES_AUTOHSCROLL | NOT WS_BORDER,WS_EX_STATICEDGE
PUSHBUTTON "浏览...",IDC_FXJFILE_EXPLORER,267,102,48,14,BS_FLAT
EDITTEXT IDC_PATH_FXJBLOCK,78,142,186,12,ES_AUTOHSCROLL | NOT WS_BORDER,WS_EX_STATICEDGE
PUSHBUTTON "浏览...",IDC_FXJBLOCKPATH_EXPLORER,268,140,48,14,BS_FLAT
DEFPUSHBUTTON "开始导入",IDC_START,288,168,50,14,BS_FLAT
CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH | NOT WS_VISIBLE,21,170,203,10,WS_EX_STATICEDGE
LTEXT "",IDC_STATIC_PROGRESS,233,170,33,9
LTEXT "选择F10资料导入文件(.txt,.zip)",IDC_STATIC,34,15,86,8
LTEXT "选择通达信财务资料导入文件",IDC_STATIC,34,53,111,8
LTEXT "选择分析家财务资料导入文件",IDC_STATIC,34,91,111,8
LTEXT "选择分析家板块导入目录",IDC_STATIC,34,129,111,8
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 );
}
}
具体导入动作由int CSelfDB::InstallBasetableTdx(const char * filename)实现
G:\stock\TskingVS2019\src\Client\StkLib\Src\SelfDB.cpp
int CSelfDB::InstallBasetableTdx(const char * filename)
{
if (NULL == filename || strlen(filename) == 0)
return 0;
int nCount = 0;
CSPString sRoot = GetRootPath();
CSPString sFileNameSHSZ = sRoot + self_chna_basetbl;
CSPFile fileSHSZ, fileTdx;
if (fileSHSZ.Open(sFileNameSHSZ, CSPFile::modeWrite | CSPFile::modeCreate)
&& fileTdx.Open(filename, CSPFile::modeRead))
{
fileTdx.Seek(TDX_FHEADER_SIZE, CSPFile::begin);
TDX_BASEDATA tdxblock;
while(sizeof(tdxblock) == fileTdx.Read(&tdxblock, sizeof(tdxblock)))
{
BASEDATA block;
if (convert_TDX_BASEDATA_to_BASEDATA(&tdxblock, &block))
{
fileSHSZ.Write(&block, sizeof(block));
nCount ++;
}
}
}
return nCount;
}