/
DlgETradeLoginStatus.cpp
367 lines (286 loc) · 11.5 KB
/
DlgETradeLoginStatus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// DlgETradeLoginStatus.cpp : implementation file
//
#include "stdafx.h"
#include "TradingSystem.h"
#include "DlgETradeLoginStatus.h"
#include "afxdialogex.h"
#include "DataConverter.h"
#include "IXingAPI.h"
#include "TradingSystem.h"
#include "DlgLoginStatusTabBar.h"
#include "packet/JIF.h"
using namespace std;
// CDlgETradeLoginStatus dialog
IMPLEMENT_DYNAMIC(CDlgETradeLoginStatus, CDialog)
BEGIN_MESSAGE_MAP(CDlgETradeLoginStatus, CDialog)
ON_WM_TIMER()
END_MESSAGE_MAP()
CDlgETradeLoginStatus::CDlgETradeLoginStatus(CWnd* pParent /*=NULL*/)
: CDialog(CDlgETradeLoginStatus::IDD, pParent){
CTradingSystemApp* app = (CTradingSystemApp*)AfxGetApp();
this->xingAPI = app->xingAPI;
}
CDlgETradeLoginStatus::~CDlgETradeLoginStatus(){
}
void CDlgETradeLoginStatus::DoDataExchange(CDataExchange* pDX){
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_DATETIMEPICKER_TIME_START, this->timeCtrlStart);
DDX_Control(pDX, IDC_DATETIMEPICKER_TIME_END, this->timeCtrlEnd);
DDX_Control(pDX, IDC_CHECK_AND_KEEP_LOGIN, this->checkKeepLogin);
}
BOOL CDlgETradeLoginStatus::OnInitDialog(){
CDialog::OnInitDialog();
this->WriteLoginInfoText(this->loginInfo);
// auto login에 따라 xingAPI 로긴 함수 호출 및 로긴창 Disable
if(this->loginInfo.GetAutoLogin()==TRUE){
this->DisableLoginInfo();
// XingAPI.Login();
BOOL logged = this->LogIn();
}
else{
this->EnableLoginInfo();
}
this->timerIDKeepLogin = (UINT_PTR)(&this->checkKeepLogin);
this->checkKeepLogin.SetCheck(loginInfo.GetLoginTime().GetChecker());
if(this->checkKeepLogin.GetCheck()==TRUE){
this->SetTimer(this->timerIDKeepLogin, 5000, NULL);
}
return FALSE;
}
void CDlgETradeLoginStatus::WriteLoginInfoText(const ETradeLoginInfo& loginInfo){
this->loginInfo = loginInfo;
this->SetLoginTime();
this->WriteUserInfoText(this->loginInfo.GetUserInfo());
this->WriteServerInfoText(this->loginInfo.GetServerInfo());
this->CheckAutoLogin(this->loginInfo.GetAutoLogin());
}
void CDlgETradeLoginStatus::SetLoginTime(){
CTime currentTime = CTime::GetCurrentTime();
CTime timeStartToSet(currentTime.GetYear(), currentTime.GetMonth(), currentTime.GetDay(), 8, 50, 0);
CTime timeEndToSet(currentTime.GetYear(), currentTime.GetMonth(), currentTime.GetDay(), 15, 30, 0);
this->timeCtrlStart.SetTime(&timeStartToSet);
this->timeCtrlEnd.SetTime(&timeEndToSet);
this->checkKeepLogin.SetCheck(loginInfo.GetLoginTime().GetChecker());
}
void CDlgETradeLoginStatus::CheckAutoLogin(BOOL autoLogin){
if(autoLogin==TRUE){
this->CheckDlgButton(IDC_CHECK_AUTO_LOGIN, TRUE);
}
else{
this->CheckDlgButton(IDC_CHECK_AUTO_LOGIN, FALSE);
}
}
void CDlgETradeLoginStatus::CheckBoxLogInStatus(BOOL status){
this->CheckDlgButton(IDC_CHECK_LOGIN_STATUS, status);
}
//void CDlgETradeLoginStatus::UncheckLogInStatus(){
// this->CheckDlgButton(IDC_CHECK_LOGIN_STATUS, FALSE);
//}
void CDlgETradeLoginStatus::WriteUserInfoText(const ETradeUserInfo& userInfo){
((CEdit*)this->GetDlgItem(IDC_EDIT_ID))->SetWindowText(userInfo.GetID().c_str());
((CEdit*)this->GetDlgItem(IDC_EDIT_PASSWORD))->SetWindowText(userInfo.GetPassword().c_str());
((CEdit*)this->GetDlgItem(IDC_EDIT_AUTHORIZING_PASSWORD))->SetWindowText(userInfo.GetAuthorizingPassword().c_str());
if(userInfo.GetAuthorizingPasswordErrorMsg()==TRUE){
this->CheckDlgButton(IDC_CHECK_ERROR_MESSAGE, TRUE);
}
else{
this->CheckDlgButton(IDC_CHECK_ERROR_MESSAGE, FALSE);
}
}
void CDlgETradeLoginStatus::WriteServerInfoText(const ETradeServerInfo& serverInfo){
DataConverter dataConverter;
if(serverInfo.GetServerType()>0){
((CButton*)(this->GetDlgItem(IDC_RADIO_REAL)))->SetCheck(TRUE);
}
else{
((CButton*)(this->GetDlgItem(IDC_RADIO_SIMULATION)))->SetCheck(TRUE);
}
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_NAME))->SetWindowText(serverInfo.GetServerName().c_str());
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_ADDRESS))->SetWindowText(serverInfo.GetServerAddress().c_str());
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_PORT))->SetWindowText(dataConverter.ConvertIntToString(serverInfo.GetServerPort()).c_str());
((CEdit*)this->GetDlgItem(IDC_EDIT_MAX_TRANSFER_SIZE))->SetWindowText(dataConverter.ConvertIntToString(serverInfo.GetMaxTransferSize()).c_str());
((CEdit*)this->GetDlgItem(IDC_EDIT_CONNECTING_TIME))->SetWindowText(dataConverter.ConvertIntToString(serverInfo.GetConnectingTime()).c_str());
}
ETradeLoginInfo CDlgETradeLoginStatus::ReadLoginInfoText(){
ETradeLoginInfo loginInfo(this->ReadAutoLogin(),
this->ReadUserInfoText(),
this->ReadServerInfoText(),
this->ReadLoginTime());
this->loginInfo = loginInfo;
return this->loginInfo;
}
BOOL CDlgETradeLoginStatus::ReadAutoLogin(){
return this->IsDlgButtonChecked(IDC_CHECK_AUTO_LOGIN);
}
ETradeUserInfo CDlgETradeLoginStatus::ReadUserInfoText(){
ETradeUserInfo userInfo;
CString id;
CString pw;
CString authorPW;
BOOL errorMsg=FALSE;
((CEdit*)this->GetDlgItem(IDC_EDIT_ID))->GetWindowText(id);
((CEdit*)this->GetDlgItem(IDC_EDIT_PASSWORD))->GetWindowText(pw);
((CEdit*)this->GetDlgItem(IDC_EDIT_AUTHORIZING_PASSWORD))->GetWindowText(authorPW);
errorMsg = this->IsDlgButtonChecked(IDC_CHECK_ERROR_MESSAGE);
userInfo.AssignUserInfo((LPCTSTR)id, (LPCTSTR)pw, (LPCTSTR)authorPW, errorMsg);
return userInfo;
}
ETradeServerInfo CDlgETradeLoginStatus::ReadServerInfoText(){
ETradeServerInfo serverInfo;
int checkedButton;
int serverType;
CString name;
CString address;
CString port;
CString maxTransferSize;
CString connectingTime;
DataConverter dataConverter;
checkedButton = this->GetCheckedRadioButton(IDC_RADIO_REAL, IDC_RADIO_SIMULATION);
switch(checkedButton){
case IDC_RADIO_REAL:
serverType = TRUE;
break;
case IDC_RADIO_SIMULATION:
serverType = FALSE;
break;
default:
serverType = FALSE;
break;
}
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_NAME))->GetWindowText(name);
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_ADDRESS))->GetWindowText(address);
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_PORT))->GetWindowText(port);
((CEdit*)this->GetDlgItem(IDC_EDIT_MAX_TRANSFER_SIZE))->GetWindowText(maxTransferSize);
((CEdit*)this->GetDlgItem(IDC_EDIT_CONNECTING_TIME))->GetWindowText(connectingTime);
serverInfo.AssignServerInfo(serverType, (LPCTSTR)name, (LPCTSTR)address,
dataConverter.ConvertStringToInt((LPCTSTR)port),
dataConverter.ConvertStringToInt((LPCTSTR)maxTransferSize),
dataConverter.ConvertStringToInt((LPCTSTR)connectingTime));
return serverInfo;
}
LoginTime CDlgETradeLoginStatus::ReadLoginTime(){
CTime cTimeTemp;
DWORD dwordTemp;
dwordTemp = this->timeCtrlStart.GetTime(cTimeTemp);
CString cstrTimeStart= cTimeTemp.Format(_T("%H:%M:%S"));
tstring timeStart(cstrTimeStart);
dwordTemp = this->timeCtrlEnd.GetTime(cTimeTemp);
CString cstrTimeEnd = cTimeTemp.Format(_T("%H:%M:%S"));
tstring timeEnd(cstrTimeEnd);
bool checker;
LoginTime ret(timeStart, timeEnd, checker);
return ret;
}
void CDlgETradeLoginStatus::DisableLoginInfo(){
(CButton*)(this->GetDlgItem(IDC_CHECK_AUTO_LOGIN))->EnableWindow(FALSE);
((CEdit*)this->GetDlgItem(IDC_EDIT_ID))->EnableWindow(FALSE);
((CEdit*)this->GetDlgItem(IDC_EDIT_PASSWORD))->EnableWindow(FALSE);
((CEdit*)this->GetDlgItem(IDC_EDIT_AUTHORIZING_PASSWORD))->EnableWindow(FALSE);
(CButton*)(this->GetDlgItem(IDC_CHECK_ERROR_MESSAGE))->EnableWindow(FALSE);
(CButton*)(this->GetDlgItem(IDC_RADIO_REAL))->EnableWindow(FALSE);
(CButton*)(this->GetDlgItem(IDC_RADIO_SIMULATION))->EnableWindow(FALSE);
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_NAME))->EnableWindow(FALSE);
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_ADDRESS))->EnableWindow(FALSE);
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_PORT))->EnableWindow(FALSE);
((CEdit*)this->GetDlgItem(IDC_EDIT_MAX_TRANSFER_SIZE))->EnableWindow(FALSE);
((CEdit*)this->GetDlgItem(IDC_EDIT_CONNECTING_TIME))->EnableWindow(FALSE);
this->editable=FALSE;
}
void CDlgETradeLoginStatus::EnableLoginInfo(){
(CButton*)(this->GetDlgItem(IDC_CHECK_AUTO_LOGIN))->EnableWindow(TRUE);
((CEdit*)this->GetDlgItem(IDC_EDIT_ID))->EnableWindow(TRUE);
((CEdit*)this->GetDlgItem(IDC_EDIT_PASSWORD))->EnableWindow(TRUE);
((CEdit*)this->GetDlgItem(IDC_EDIT_AUTHORIZING_PASSWORD))->EnableWindow(TRUE);
(CButton*)(this->GetDlgItem(IDC_CHECK_ERROR_MESSAGE))->EnableWindow(TRUE);
(CButton*)(this->GetDlgItem(IDC_RADIO_REAL))->EnableWindow(TRUE);
(CButton*)(this->GetDlgItem(IDC_RADIO_SIMULATION))->EnableWindow(TRUE);
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_NAME))->EnableWindow(TRUE);
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_ADDRESS))->EnableWindow(TRUE);
((CEdit*)this->GetDlgItem(IDC_EDIT_SERVER_PORT))->EnableWindow(TRUE);
((CEdit*)this->GetDlgItem(IDC_EDIT_MAX_TRANSFER_SIZE))->EnableWindow(TRUE);
((CEdit*)this->GetDlgItem(IDC_EDIT_CONNECTING_TIME))->EnableWindow(TRUE);
this->editable=TRUE;
}
BOOL CDlgETradeLoginStatus::ConnectServer(){
BOOL ret = FALSE;
if( this->xingAPI->IsConnected()==TRUE){
this->xingAPI->Disconnect();
}
ETradeServerInfo serverInfo = this->ReadServerInfoText();
ret = this->xingAPI->Connect(GetSafeHwnd(),
serverInfo.GetServerAddress().c_str(),
serverInfo.GetServerPort(),
WM_USER,
serverInfo.GetConnectingTime(),
serverInfo.GetMaxTransferSize());
if( ret == FALSE ){
int nErrorCode = this->xingAPI->GetLastError();
CString strMsg = this->xingAPI->GetErrorMessage( nErrorCode );
MessageBox( strMsg, TEXT("서버접속실패"), MB_ICONSTOP );
}
return ret;
}
BOOL CDlgETradeLoginStatus::LogIn(){
BOOL ret = FALSE;
BOOL connected = this->ConnectServer();
if(connected==TRUE){
ETradeLoginInfo loginInfo = this->GetLoginInfo();
ret = this->xingAPI->Login(GetSafeHwnd(),
loginInfo.GetUserInfo().GetID().c_str(),
loginInfo.GetUserInfo().GetPassword().c_str(),
loginInfo.GetUserInfo().GetAuthorizingPassword().c_str(),
loginInfo.GetServerInfo().GetServerType(),
FALSE);
if( ret == FALSE ){
int nErrorCode = this->xingAPI->GetLastError();
CString strMsg = this->xingAPI->GetErrorMessage( nErrorCode );
MessageBox( strMsg, TEXT("로그인 실패"), MB_ICONSTOP );
this->CheckBoxLogInStatus(FALSE);
}
else{
this->CheckBoxLogInStatus(TRUE);
}
}
return ret;
}
BOOL CDlgETradeLoginStatus::LogOut(){
BOOL ret = FALSE;
this->xingAPI->Disconnect();
ret = this->xingAPI->Logout(GetSafeHwnd());
if(ret = TRUE){
this->CheckBoxLogInStatus(FALSE);
}
return ret;
}
void CDlgETradeLoginStatus::OnTimer(UINT_PTR nIDEvent){
if(this->checkKeepLogin.GetCheck()==TRUE && this->BetweenBusinessHours()==TRUE){
if(nIDEvent == this->timerIDKeepLogin){
this->KeepConnectedAndLoggedIn();
this->checkKeepLogin.SetCheck(TRUE);
}
else{
}
}
}
BOOL CDlgETradeLoginStatus::KeepConnectedAndLoggedIn(){
BOOL ret = TRUE;
BOOL connected = this->xingAPI->IsConnected();
if(connected == FALSE){
ret = this->LogIn();
// ret가 TRUE면 여기서 DlgDataFeedingModule에 신호 보낸다. (Dialog 존재하면)
AfxGetMainWnd()->SendMessage(WMU_READVISE_DATA_FEEDING, NULL, NULL);
}
return ret;
}
BOOL CDlgETradeLoginStatus::BetweenBusinessHours(){
BOOL ret = FALSE;
CTime currentTime = CTime::GetCurrentTime();
CTime cTimeStart;
this->timeCtrlStart.GetTime(cTimeStart);
CTime cTimeEnd;
this->timeCtrlEnd.GetTime(cTimeEnd);
if(currentTime>=cTimeStart && currentTime <=cTimeEnd){
ret = TRUE;
}
return ret;
}