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

📄 stock2txtdlg.cpp

📁 大智慧数据转换
💻 CPP
字号:
// Stock2TxtDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Stock2Txt.h"
#include "Stock2TxtDlg.h"
#include "global.h"
#include "cinifile.h"
#include "dirdialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStock2TxtDlg dialog

CStock2TxtDlg::CStock2TxtDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStock2TxtDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStock2TxtDlg)
	m_strSZPath = _T("");
	m_strDestPath = _T("");
	m_strSZZSPath = _T("");
	m_strMsg = _T("");
	m_StockNum= _T("000001");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CStock2TxtDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStock2TxtDlg)
	DDX_Control(pDX, IDC_PROGRESS1, m_Progress);
	DDX_Text(pDX, IDC_EDIT_SZ, m_strSZPath);
	DDX_Text(pDX, IDC_EDIT_DEST, m_strDestPath);
	DDX_Text(pDX, IDC_EDIT_SZZS, m_strSZZSPath);
	DDX_Text(pDX, IDC_STATIC_MSG, m_strMsg);
	DDX_Text(pDX, IDC_EDIT_STOCKNUM, m_StockNum);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CStock2TxtDlg, CDialog)
	//{{AFX_MSG_MAP(CStock2TxtDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
	ON_BN_CLICKED(IDC_BUTTON_BROW1, OnButtonBrow1)
	ON_BN_CLICKED(IDC_BUTTON_BROW2, OnButtonBrow2)
	ON_BN_CLICKED(IDC_BUTTON_BROW3, OnButtonBrow3)
	ON_BN_CLICKED(IDC_BUTTON_QUIT, OnButtonQuit)
	ON_BN_CLICKED(IDC_BUTTON_5MIN, OnButton5min)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStock2TxtDlg message handlers

BOOL CStock2TxtDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	bExit=false;
	bStart5Min=false;
	LoadIniPath();
	GetDlgItem(IDC_EDIT_SZ)->SetWindowText(m_strSZPath);
	GetDlgItem(IDC_EDIT_SZZS)->SetWindowText(m_strSZZSPath);
	GetDlgItem(IDC_EDIT_DEST)->SetWindowText(m_strDestPath);
	GetDlgItem(IDC_STATIC_MSG)->SetWindowText("");

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CStock2TxtDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CStock2TxtDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CStock2TxtDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CStock2TxtDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CStock2TxtDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void CStock2TxtDlg::OnButtonStart() 
{
	// TODO: Add your control notification handler code here

	GetDlgItem(IDC_STATIC_MSG)->SetWindowText("开始转换");
	m_Progress.SetRange(0,100);
	m_Progress.SetStep(1);
	m_Progress.SetPos(0);
	iSegPos=0;
ProcFun(m_strSZPath,m_strDestPath);
iSegPos=50;
ProcFun(m_strSZZSPath,m_strDestPath);
GetDlgItem(IDC_STATIC_MSG)->SetWindowText("转换结束");
//	ProcDayFile("E:\\程序测试\\Stock2Txt\\600358.day","E:\\程序测试\\Stock2Txt\\600358.txt");
}

BOOL CStock2TxtDlg::ProcDayFile(CString strPath, CString strDest)
{
	DAY_DATA_DZH55 dayData;
	CFile file;
	if(file.Open((LPCTSTR)strPath, CFile::modeRead|CFile::shareDenyNone))
	{
		CStdioFile fileDest;
		fileDest.Open((LPCTSTR)strDest, CFile::modeCreate|CFile::modeWrite|CFile::shareDenyNone);
		CString strMsg,strDate;

		
		while(file.Read((char*)&dayData,sizeof(DAY_DATA_DZH55)))
		{
			strDate.Format("%04d-%02d-%02d",dayData.date/10000,(dayData.date%10000)/100,dayData.date%100);
			strMsg.Format("%s %.3f %.3f %.3f %.3f %ld %ld\n",strDate,dayData.open/1000.0,dayData.high/1000.0,dayData.low/1000.0,dayData.close/1000.0,dayData.amount,dayData.money/10);
			fileDest.WriteString(strMsg);
		}
		file.Close();
		fileDest.Close();
	}   
	else 
		return false;

	return true;
}

void CStock2TxtDlg::OnButtonBrow1() 
{
	// TODO: Add your control notification handler code here
	CDirDialog	dlg;
	if (IDOK  == dlg.DoBrowse(this)) 
	{
		// 设置选中路径
		m_strSZPath = dlg.m_strPath;
		UpdateData(false);

		//setVal
		CIniFile mFile;
		CString strtemp;
		BOOL bRet;
		CString strPath=GetAppPath();
		strPath+="\\参数配置.ini";
		bRet=mFile.Create (strPath);
		if(!bRet)
			return ;
		bRet=mFile.SetVarStr ("参数配置","szzzPath",m_strSZPath); 

		mFile.CloseIniFile();
		
	}	
}

void CStock2TxtDlg::OnButtonBrow2() 
{
	// TODO: Add your control notification handler code here
	CDirDialog	dlg;
	if (IDOK  == dlg.DoBrowse(this)) 
	{
		// 设置选中路径
		m_strSZZSPath = dlg.m_strPath;
		UpdateData(false);


		//setVal
		CIniFile mFile;
		CString strtemp;
		BOOL bRet;
		CString strPath=GetAppPath();
		strPath+="\\参数配置.ini";
		bRet=mFile.Create (strPath);
		if(!bRet)
			return ;
		bRet=mFile.SetVarStr ("参数配置","szPath",m_strSZZSPath); 
		
		mFile.CloseIniFile();
		
	}	
}

void CStock2TxtDlg::OnButtonBrow3() 
{
	// TODO: Add your control notification handler code here
	CDirDialog	dlg;
	if (IDOK  == dlg.DoBrowse(this)) 
	{
		// 设置选中路径
		m_strDestPath = dlg.m_strPath;
		UpdateData(false);


		//setVal
		CIniFile mFile;
		CString strtemp;
		BOOL bRet;
		CString strPath=GetAppPath();
		strPath+="\\参数配置.ini";
		bRet=mFile.Create (strPath);
		if(!bRet)
			return ;
		bRet=mFile.SetVarStr ("参数配置","getPath",m_strDestPath); 
		
		mFile.CloseIniFile();
		
	}	
}

BOOL CStock2TxtDlg::LoadIniPath()
{
	CIniFile mFile;
	CString strtemp;
	BOOL bRet;
	//客户端连接信息
	CString strPath=GetAppPath();
	strPath+="\\参数配置.ini";
	bRet=mFile.Create (strPath);
	if(!bRet)
	{
		CString strInfo="[参数配置]\n;上证路径\nszPath=\n;深综路径\nszzzPath=\n;get路径\ngetPath=\n";
		CStdioFile fileDest;
		fileDest.Open((LPCTSTR)strPath, CFile::modeCreate|CFile::modeWrite);
		fileDest.WriteString(strInfo);
		fileDest.Close();

		return false;
	}

	strtemp="";
	bRet=mFile.GetVarStr ("参数配置","szPath",strtemp); 
	if(!bRet)
		return false;
	m_strSZZSPath=strtemp;

	strtemp="";
	bRet=mFile.GetVarStr ("参数配置","szzzPath",strtemp); 
	if(!bRet)
		return false;
	m_strSZPath=strtemp;
	strtemp="";
	bRet=mFile.GetVarStr ("参数配置","getPath",strtemp); 
	if(!bRet)
		return false;

	m_strDestPath=strtemp;

	mFile.CloseIniFile();
	return bRet;
}

CString CStock2TxtDlg::GetAppPath()
{
	char PathName[255];
	GetModuleFileName( AfxGetInstanceHandle(), PathName,sizeof( PathName ) );
    char *a,*b;
    a = b = PathName;  
    while(b)
    {
		b=strchr(a+1,'\\');
		if(b) a=b;
    } 
    *a='\0'; 
    return PathName;
}

void CStock2TxtDlg::OnButtonQuit() 
{
	// TODO: Add your control notification handler code here
	bExit=true;
	CDialog::OnOK();
}

BOOL CStock2TxtDlg::ProcFun(CString strSourPath, CString strDestPath)
{

	DWORD dwFileNUM=0,dwCurFileNUM=0;;
		int iCurPos;
	CFileFind ff;
	
	CString szDir =strSourPath;
	
	if(szDir.Right(1) != "\\")
		szDir += "\\";
	
	szDir += "*.day";
	
	BOOL res = ff.FindFile(szDir);
	while(res)
	{
		res = ff.FindNextFile();
	
		if(ff.IsDots()   ||   ff.IsDirectory())   continue;   
		dwFileNUM++;
	}


	res = ff.FindFile(szDir);
	while(res)
	{
		if(bExit) return true;;
		res = ff.FindNextFile();
		if(ff.IsDirectory() && !ff.IsDots())
		{//不处理
			//如果是一个子目录,用递归继续往深一层找
			CString strPath2 = ff.GetFilePath();
			CString strTitle = ff.GetFileTitle();
			//if(strTitle!="BackUp")//备份资料不传
			//	TransDirectFun(strPath2,false);
		}
		else if(!ff.IsDirectory() && !ff.IsDots())
		{
			//显示当前访问的文件
			CString strPath;
			CString strTitle;
			CString strFilename;
			strPath = ff.GetFilePath();
			strTitle = ff.GetFileTitle();
			strFilename=ff.GetFileName();


			iCurPos=iSegPos+(int)(50*(dwCurFileNUM/(1.0*dwFileNUM)));
			m_strMsg.Format("%d%% %s",iCurPos,strPath);
			GetDlgItem(IDC_STATIC_MSG)->SetWindowText(m_strMsg);

			ProcDayFile(strPath,strDestPath+"\\"+strTitle+".txt");


			
		}
		iCurPos=iSegPos+(int)(50*(++dwCurFileNUM/(1.0*dwFileNUM)));
		m_Progress.SetPos(iCurPos);
		DoEvent();
	}
	ff.Close();
	
	return true;

}


BOOL CStock2TxtDlg::ProcDirectFun(CString strPath, BOOL bRoot)
{

	return true;

}

void CStock2TxtDlg::DoEvent()
{
	MSG msg;
	while(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
	{
		::TranslateMessage(&msg);
		::DispatchMessage(&msg);
	}
}

void CStock2TxtDlg::OnButton5min() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	if(m_StockNum.IsEmpty()) return ;
	if(!bStart5Min)
	{
		bStart5Min=!bStart5Min;
		GetDlgItem(IDC_BUTTON_5MIN)->SetWindowText("停止");
		Proc5MinFun();
		SetTimer(0x01,30000,NULL);

	}
	else
	{
		KillTimer(0x01);
		bStart5Min=!bStart5Min;
		GetDlgItem(IDC_BUTTON_5MIN)->SetWindowText("5分钟");
	}
	
}

BOOL CStock2TxtDlg::Proc5MinFile(CString strPath, CString strDest)
{
	m_Progress.SetPos(0);
	long lCurNum=300;
	DAY_DATA_DZH55_5MIN dayData;
	CFile file;
	CTime ct=CTime::GetCurrentTime();
	CTimeSpan ctSpan(1,0,0,0);
	CTimeSpan ct365Span(-300,0,0,0);
	ct=ct+ct365Span;
	if(file.Open((LPCTSTR)strPath, CFile::shareDenyNone  |CFile::modeRead))
	{
		CStdioFile fileDest;
		fileDest.Open((LPCTSTR)strDest, CFile::modeCreate|CFile::modeWrite|CFile::shareDenyNone);
		CString strMsg,strDate;
		
		file.Seek(-lCurNum-- * sizeof(DAY_DATA_DZH55_5MIN),CFile::end  );
		while(lCurNum>=0 && file.Read((char*)&dayData,sizeof(DAY_DATA_DZH55_5MIN)))
		{
		//yyyy-mm-dd HH:MM
		//	strDate.Format("%04d-%02d-%02d %02d:%02d",dayData.date>>20,(dayData.date<<12)>>28,(dayData.date<<16)>>27,(dayData.date<<21)>>27,(dayData.date<<26)>>26);
		//yyyy-mm-dd
		//	strDate.Format("%04d-%02d-%02d",dayData.date>>20,(dayData.date<<12)>>28,(dayData.date<<16)>>27);	
			strDate=ct.Format("%Y-%m-%d");
			strMsg.Format("%s %.3f %.3f %.3f %.3f %ld %ld\n",strDate,dayData.open/1000.0,dayData.high/1000.0,dayData.low/1000.0,dayData.close/1000.0,dayData.amount,dayData.money/100);
			fileDest.WriteString(strMsg);
			int i=-lCurNum-- * sizeof(DAY_DATA_DZH55_5MIN);
			file.Seek(i,CFile::end  );
			ct=ct+ctSpan;
			m_Progress.SetPos(lCurNum/3);
			DoEvent();
		}
		file.Close();
		fileDest.Close();
	}   
	else 
		return false;
	
	return true;
}

void CStock2TxtDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default

	if(nIDEvent==0x01)
	{

		KillTimer(0x01);
		Proc5MinFun();
			SetTimer(0x01,30000,NULL);
	}

	CDialog::OnTimer(nIDEvent);
}

BOOL CStock2TxtDlg::Proc5MinFun()
{


	CString strMsg;
	CString strSour,strDest;
	
	if(m_StockNum>"000001" && m_StockNum<"600000")
	{
		long lpos=m_strSZPath.Find("Day");
		strSour.Format("%sMin\\%s.NMN",m_strSZPath.Left(lpos),m_StockNum);
		strDest.Format("%s\\%s.txt",m_strDestPath,m_StockNum);
		
	}
	else
	{
		long lpos=m_strSZZSPath.Find("Day");
		strSour.Format("%sMin\\%s.NMN",m_strSZZSPath.Left(lpos),m_StockNum);
		strDest.Format("%s\\%s.txt",m_strDestPath,m_StockNum);
		
	}
	Proc5MinFile(strSour,strDest);
	return true;
	

}

⌨️ 快捷键说明

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