Files
HLStock/MakeManualList/MakeManualListDlg.cpp
2013-08-22 05:26:36 +00:00

524 lines
16 KiB
C++

// MakeManualListDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MakeManualList.h"
#include "MakeManualListDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMakeManualListDlg dialog
CMakeManualListDlg::CMakeManualListDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMakeManualListDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMakeManualListDlg)
m_strOutputFileName = _T("수동_종목코드.txt");
m_nAmountDown = 100000;
m_nAmountUp = 100000000;
m_nCurDown = 500;
m_nCurUp = 50000;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMakeManualListDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMakeManualListDlg)
DDX_Control(pDX, IDC_RUN_PROGRESS, m_hRunProgress);
DDX_Text(pDX, IDC_OUTPUTFILENAME_EDIT, m_strOutputFileName);
DDX_Text(pDX, IDC_AMOUNT_DOWN_EDIT, m_nAmountDown);
DDX_Text(pDX, IDC_AMOUNT_UP_EDIT, m_nAmountUp);
DDX_Text(pDX, IDC_CUR_DOWN_EDIT, m_nCurDown);
DDX_Text(pDX, IDC_CUR_UP_EDIT, m_nCurUp);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMakeManualListDlg, CDialog)
//{{AFX_MSG_MAP(CMakeManualListDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_USING_AMOUNT_UP_CHECK, OnUsingAmountUpCheck)
ON_BN_CLICKED(IDC_USING_AMOUNT_DOWN_CHECK, OnUsingAmountDownCheck)
ON_BN_CLICKED(IDC_USING_CUR_UP_CHECK, OnUsingCurUpCheck)
ON_BN_CLICKED(IDC_USING_CUR_DOWN_CHECK, OnUsingCurDownCheck)
ON_BN_CLICKED(IDC_RUN_BTN, OnRunBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMakeManualListDlg message handlers
BOOL CMakeManualListDlg::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
((CButton*)GetDlgItem( IDC_USING_AMOUNT_UP_CHECK ))->SetCheck(g_AppConfig.bUsingAmountUp);
((CButton*)GetDlgItem( IDC_USING_AMOUNT_DOWN_CHECK ))->SetCheck(g_AppConfig.bUsingAmountDown);
((CButton*)GetDlgItem( IDC_USING_CUR_UP_CHECK ))->SetCheck(g_AppConfig.bUsingCurUp);
((CButton*)GetDlgItem( IDC_USING_CUR_DOWN_CHECK ))->SetCheck(g_AppConfig.bUsingCurDown);
((CButton*)GetDlgItem( IDC_USING_KOSDAQ_CHECK ))->SetCheck(g_AppConfig.bUsingKosdaq);
((CButton*)GetDlgItem( IDC_USING_EXCHANGE_CHECK ))->SetCheck(g_AppConfig.bUsingExchange);
((CWnd*)GetDlgItem( IDC_AMOUNT_UP_EDIT ))->EnableWindow( g_AppConfig.bUsingAmountUp );
((CWnd*)GetDlgItem( IDC_AMOUNT_DOWN_EDIT ))->EnableWindow( g_AppConfig.bUsingAmountDown );
((CWnd*)GetDlgItem( IDC_CUR_UP_EDIT ))->EnableWindow( g_AppConfig.bUsingCurUp );
((CWnd*)GetDlgItem( IDC_CUR_DOWN_EDIT ))->EnableWindow( g_AppConfig.bUsingCurDown );
m_nAmountDown = g_AppConfig.nAmountDown;
m_nAmountUp = g_AppConfig.nAmountUp;
m_nCurDown = g_AppConfig.nCurDown;
m_nCurUp = g_AppConfig.nCurUp;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMakeManualListDlg::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 CMakeManualListDlg::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 CMakeManualListDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMakeManualListDlg::OnClose()
{
CDialog::OnClose();
}
void CMakeManualListDlg::OnCancel()
{
CWnd* pWnd = (CWnd*)GetDlgItem( IDC_RUN_BTN );
DWORD dwStyle = pWnd->GetStyle();
if( dwStyle & WS_DISABLED )
{
CString str;
str.Format( "작업이 진행중입니다.\n프로그램을 종료하시겠습니까?" );
int nID = MessageBox( str, "프로그램 종료 질문", MB_ICONQUESTION|MB_YESNO );
if( nID == IDNO )
return;
}
UpdateData();
g_AppConfig.bUsingAmountUp = ((CButton*)GetDlgItem( IDC_USING_AMOUNT_UP_CHECK ))->GetCheck();
g_AppConfig.bUsingAmountDown = ((CButton*)GetDlgItem( IDC_USING_AMOUNT_DOWN_CHECK ))->GetCheck();
g_AppConfig.bUsingCurUp = ((CButton*)GetDlgItem( IDC_USING_CUR_UP_CHECK ))->GetCheck();
g_AppConfig.bUsingCurDown = ((CButton*)GetDlgItem( IDC_USING_CUR_DOWN_CHECK ))->GetCheck();
g_AppConfig.bUsingKosdaq = ((CButton*)GetDlgItem( IDC_USING_KOSDAQ_CHECK ))->GetCheck();
g_AppConfig.bUsingExchange = ((CButton*)GetDlgItem( IDC_USING_EXCHANGE_CHECK ))->GetCheck();
g_AppConfig.nAmountDown = m_nAmountDown;
g_AppConfig.nAmountUp = m_nAmountUp;
g_AppConfig.nCurDown = m_nCurDown;
g_AppConfig.nCurUp = m_nCurUp;
CDialog::OnCancel();
}
void CMakeManualListDlg::OnUsingAmountUpCheck()
{
BOOL bCheck = ((CButton*)GetDlgItem( IDC_USING_AMOUNT_UP_CHECK ))->GetCheck();
((CWnd*)GetDlgItem( IDC_AMOUNT_UP_EDIT ))->EnableWindow( bCheck );
}
void CMakeManualListDlg::OnUsingAmountDownCheck()
{
BOOL bCheck = ((CButton*)GetDlgItem( IDC_USING_AMOUNT_DOWN_CHECK ))->GetCheck();
((CWnd*)GetDlgItem( IDC_AMOUNT_DOWN_EDIT ))->EnableWindow( bCheck );
}
void CMakeManualListDlg::OnUsingCurUpCheck()
{
BOOL bCheck = ((CButton*)GetDlgItem( IDC_USING_CUR_UP_CHECK ))->GetCheck();
((CWnd*)GetDlgItem( IDC_CUR_UP_EDIT ))->EnableWindow( bCheck );
}
void CMakeManualListDlg::OnUsingCurDownCheck()
{
BOOL bCheck = ((CButton*)GetDlgItem( IDC_USING_CUR_DOWN_CHECK ))->GetCheck();
((CWnd*)GetDlgItem( IDC_CUR_DOWN_EDIT ))->EnableWindow( bCheck );
}
void CMakeManualListDlg::OnRunBtn()
{
UpdateData();
CFile * pFile=NULL;
HANDLE hFile;
CString _strFileName;
TCHAR szFilePath[_MAX_PATH]={0,};
CStatic *pStatus = (CStatic*)GetDlgItem( IDC_PROGRESS_STATIC );
int nTotal=0;
double ldAmountUp=0.0, ldAmountDown = 0.0;
long nCurUp=0, nCurDown=0;
BOOL bCheck_AmountUp;
BOOL bCheck_AmountDown;
BOOL bCheck_CurUp;
BOOL bCheck_CurDown;
BOOL bCheck_KO;
BOOL bCheck_EX;
CString str;
str.Format( "거부리스트 검사는 몇분이 소요됩니다.\n"
"이 작업은 옵션적용이 되므로, 옵션설정이 맞는지 확인하세요.\n"
"작업을 계속 진행하시겠습니까?" );
int nID = MessageBox( str, "수동 종목검색", MB_ICONQUESTION|MB_YESNO );
if( nID == IDNO )
goto _EXIT1_;
((CWnd*)GetDlgItem( IDC_RUN_BTN ))->EnableWindow(FALSE);
///////////////////////////////////////////////////////////////////
::GetModuleFileName(NULL, szFilePath, _MAX_PATH);
*(strrchr( szFilePath, '\\' ) + 1) = 0;
_strFileName.Format( "%s%s", szFilePath, m_strOutputFileName );
hFile = CreateFile(_strFileName,
GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
AfxMessageBox( _strFileName + " 파일을 만들 수 없습니다." );
goto _EXIT1_;
}
else
{
pFile = new CFile(hFile);
pFile->SeekToEnd();
}
///////////////////////////////////////////////////////////////////
bCheck_AmountUp = ((CButton*)GetDlgItem( IDC_USING_AMOUNT_UP_CHECK ))->GetCheck();
bCheck_AmountDown = ((CButton*)GetDlgItem( IDC_USING_AMOUNT_DOWN_CHECK ))->GetCheck();
bCheck_CurUp = ((CButton*)GetDlgItem( IDC_USING_CUR_UP_CHECK ))->GetCheck();
bCheck_CurDown = ((CButton*)GetDlgItem( IDC_USING_CUR_DOWN_CHECK ))->GetCheck();
bCheck_KO = ((CButton*)GetDlgItem( IDC_USING_KOSDAQ_CHECK ))->GetCheck();
bCheck_EX = ((CButton*)GetDlgItem( IDC_USING_EXCHANGE_CHECK ))->GetCheck();
if( bCheck_AmountUp )
ldAmountUp = m_nAmountUp*10000.;
if( bCheck_AmountDown )
ldAmountDown = m_nAmountDown*10000.;
if( bCheck_CurUp )
nCurUp = m_nCurUp;
if( bCheck_CurDown )
nCurDown = m_nCurDown;
if( (bCheck_AmountUp == FALSE) && (bCheck_AmountDown == FALSE) && (bCheck_CurUp == FALSE) && (bCheck_CurDown == FALSE) )
{
AfxMessageBox("시가총액/현재가 모두를 적용하지 않았습니다.\n\n적어도 하나는 지정하셔야 합니다.");
goto _EXIT1_;
}
if( (bCheck_KO == FALSE) && (bCheck_EX == FALSE) )
{
AfxMessageBox("코스닥/거래소 모두를 적용하지 않았습니다.\n\n적어도 하나는 지정하셔야 합니다.");
goto _EXIT1_;
}
try
{
HRESULT hr;
ICpStockCodePtr _objStockCode;
IDibPtr _objStockMst2;
CString strMsg;
long i;
CString strJCode="A000000";
short * TypeGuBun = new short[999999];
memset( TypeGuBun, NULL, sizeof(short)*999999 );
pStatus->SetWindowText( "최기화 검사중..." );
hr = _objStockCode.CreateInstance( CLSID_CpStockCode ); // 종목코드변환.
if (SUCCEEDED(hr))
hr = _objStockMst2.CreateInstance( CLSID_StockMst2 ); // 주식 복수 종목에 대해 일괄 조회를 요청하고 수신한다
if (SUCCEEDED(hr))
{
char szFormat[256]={0,};
wsprintf( szFormat, "' -------------------------------------------------------------------------- \r\n" );
pFile->Write(szFormat, strlen(szFormat));
char szDate[100], szTime[100];
_strdate( szDate ); _strtime( szTime );
wsprintf( szFormat, "' 수동종목 검사일시 : %s : %s \r\n", szDate, szTime );
pFile->Write(szFormat, strlen(szFormat));
wsprintf( szFormat, "' 수동종목 검사설정 : 시가총액이상(%s):%d만원, 시가총액이하(%s):%d만원 \r\n"
"' 현재가이상(%s):%d원, 현재가이하(%s):%d원 \r\n"
"' 코스닥(%s), 거래소(%s) \r\n",
bCheck_AmountUp?"O":"X", m_nAmountUp, bCheck_AmountDown?"O":"X", m_nAmountDown,
bCheck_CurUp?"O":"X", m_nCurUp, bCheck_CurDown?"O":"X", m_nCurDown,
bCheck_KO?"O":"X", bCheck_EX?"O":"X" );
pFile->Write(szFormat, strlen(szFormat));
wsprintf( szFormat, "' 종목코드, 현재가, 시가총액, 장구분 \r\n");
pFile->Write(szFormat, strlen(szFormat));
wsprintf( szFormat, "' -------------------------------------------------------------------------- \r\n");
pFile->Write(szFormat, strlen(szFormat));
pStatus->SetWindowText( "전종목 코드 검사중..." );
const long nCount = _objStockCode->GetCount();
//for(int _j=0; _j<nCount; _j++)
//{
// strJCode = (LPCSTR)(_bstr_t)_objStockCode->GetData(0, _j);
// i = atol( (LPSTR)(LPCTSTR)strJCode.Right(6) );
// // 1-장내, 5-코스닥, 6-제3시장
// TypeGuBun[ i ] = (short)_objStockCode->GetData( 4, _j );
//}
m_hRunProgress.SetRange32(0, nCount);
m_hRunProgress.SetPos(0);
char szCheck[100]={0,};
char szMergeCode[1024]={0,};
long nMergeCount;
short sType;
long nStockCurrent, nStockTotal;
double ldTotalMoney, ul1, ul2;
BOOL bWrite=FALSE;
int nIndex=0;
while( nIndex<nCount )
{
//////////////////////////////////////////////////////////
memset( &szMergeCode, NULL, 1024 );
nMergeCount=0;
for(; nMergeCount<110; nIndex++ )
{
if(nIndex>=nCount)
break;
sType = _objStockCode->GetData( 4, nIndex ); // 1-장내, 5-코스닥, 6-제3시장
strJCode = (LPSTR)(_bstr_t)_objStockCode->GetData(0, nIndex);
strcat( szMergeCode, (LPSTR)(LPCTSTR)strJCode );
strcat( szMergeCode, "," );
nMergeCount++;
//if( sType == 1 && bCheck_EX)
//{
// strcat( szMergeCode, (LPSTR)(LPCTSTR)strJCode );
// strcat( szMergeCode, "," );
// nMergeCount++;
//}
//else if( sType == 5 && bCheck_KO)
//{
// strcat( szMergeCode, (LPSTR)(LPCTSTR)strJCode );
// strcat( szMergeCode, "," );
// nMergeCount++;
//}
}
if( strlen( szMergeCode ) == 0 )
continue;
*(strrchr( szMergeCode, ',' )) = NULL;
//////////////////////////////////////////////////////////
_objStockMst2->SetInputValue( 0, szMergeCode );
_objStockMst2->BlockRequest();
strMsg.Format( "%d/%d 진행중", nIndex, nCount );
pStatus->SetWindowText( strMsg );
short nRecv = (short)_objStockMst2->GetHeaderValue(0);
if( nRecv == 0 )
{
AfxMessageBox("수신된 데이터가 없습니다. Cybosplus 서비스 시간대를 확인해주세요.");
break;
}
for( long k=0; k<nRecv; k++ )
{
strJCode = (LPSTR)(_bstr_t)_objStockMst2->GetDataValue(0, k); // 0 - (string) 종목 코드
i = atol( (LPSTR)(LPCTSTR)strJCode.Right(6) );
nStockCurrent = (long)_objStockMst2->GetDataValue(3, k); // 3 - (long) 현재가
nStockTotal = (long)_objStockMst2->GetDataValue(17, k); // 17 - (unsigned long) 상장주식수
ul1 = nStockCurrent; ul2 = nStockTotal;
ldTotalMoney = ul1 * ul2;
bWrite = FALSE;
if( bCheck_AmountUp )
if( ldTotalMoney >= ldAmountUp )
bWrite = TRUE;
if( bCheck_AmountDown )
if( ldTotalMoney <= ldAmountDown )
bWrite = TRUE;
if( bCheck_CurUp )
if( nStockCurrent >= nCurUp )
bWrite = TRUE;
if( bCheck_CurDown )
if( nStockCurrent <= nCurDown )
bWrite = TRUE;
if( bWrite )
{
char szFormat[256]={0,};
sprintf( szFormat, "%6s, %7d, %17.0f, [%d]\r\n",
(LPSTR)(LPCTSTR)strJCode.Right(6),
nStockCurrent, ldTotalMoney,
TypeGuBun[i] );
pFile->Write(szFormat, strlen(szFormat));
++nTotal;
}
}
m_hRunProgress.SetPos(nIndex);
}
}
_objStockCode.Release();
_objStockMst2.Release();
SAFE_DELETE( TypeGuBun );
strMsg.Format( "수동 종목검사: %d종목.", nTotal );
pStatus->SetWindowText( strMsg );
AfxMessageBox( strMsg );
}
catch( _com_error e )
{
AfxMessageBox( "프로그램을 실행 할 수 없습니다!" );
}
catch(...)
{
AfxMessageBox( "프로그램실행중 문제가 발생하였습니다." );
}
_EXIT1_:
if( pFile )
{
pFile->Close();
SAFE_DELETE( pFile );
}
((CWnd*)GetDlgItem( IDC_RUN_BTN ))->EnableWindow(TRUE);
}