SimuAdvancedDlg.cpp
上传用户:zhanglf88
上传日期:2013-11-19
资源大小:6036k
文件大小:7k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. // SimuAdvancedDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "SimuAdvancedDlg.h"
  5. #include "SetRule.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CSimuAdvancedDlg dialog
  13. CSimuAdvancedDlg::CSimuAdvancedDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CSimuAdvancedDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CSimuAdvancedDlg)
  17. m_strStopLosing = _T("");
  18. m_strStopProfit = _T("");
  19. //}}AFX_DATA_INIT
  20. m_pStrategy = NULL;
  21. m_bModified = FALSE;
  22. }
  23. void CSimuAdvancedDlg::SetStrategy( CStrategy * pStrategy )
  24. {
  25. m_pStrategy = pStrategy;
  26. }
  27. void CSimuAdvancedDlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDialog::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CSimuAdvancedDlg)
  31. DDX_Control(pDX, IDCANCEL, m_btnCancel);
  32. DDX_Control(pDX, IDOK, m_btnOK);
  33. DDX_Control(pDX, IDC_RULELONG, m_btnRuleLong);
  34. DDX_Control(pDX, IDC_RULEINDEX, m_btnRuleIndex);
  35. DDX_Control(pDX, IDC_KTYPELONG, m_cmbKTypeLong);
  36. DDX_Control(pDX, IDC_KTYPEINDEX, m_cmbKTypeIndex);
  37. DDX_Control(pDX, IDC_CHECKLONG, m_btnCheckLong);
  38. DDX_Control(pDX, IDC_CHECKINDEX, m_btnCheckIndex);
  39. DDX_Control(pDX, IDC_STOPPROFIT, m_editStopProfit);
  40. DDX_Control(pDX, IDC_STOPLOSING, m_editStopLosing);
  41. DDX_Control(pDX, IDC_CHECKSTOPPROFIT, m_btnCheckStopProfit);
  42. DDX_Control(pDX, IDC_CHECKSTOPLOSING, m_btnCheckStopLosing);
  43. DDX_Text(pDX, IDC_STOPLOSING, m_strStopLosing);
  44. DDX_Text(pDX, IDC_STOPPROFIT, m_strStopProfit);
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CSimuAdvancedDlg, CDialog)
  48. //{{AFX_MSG_MAP(CSimuAdvancedDlg)
  49. ON_WM_CLOSE()
  50. ON_BN_CLICKED(IDC_CHECKSTOPLOSING, OnCheckstoplosing)
  51. ON_BN_CLICKED(IDC_CHECKSTOPPROFIT, OnCheckstopprofit)
  52. ON_BN_CLICKED(IDC_CHECKLONG, OnChecklong)
  53. ON_BN_CLICKED(IDC_CHECKINDEX, OnCheckindex)
  54. ON_BN_CLICKED(IDC_RULELONG, OnRulelong)
  55. ON_BN_CLICKED(IDC_RULEINDEX, OnRuleindex)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CSimuAdvancedDlg message handlers
  60. BOOL CSimuAdvancedDlg::OnInitDialog() 
  61. {
  62. CDialog::OnInitDialog();
  63. ASSERT( m_pStrategy );
  64. COpParam & param = m_pStrategy->GetOpParam();
  65. // Stop
  66. m_btnCheckStopLosing.SetCheck( param.m_bStopLosing );
  67. m_btnCheckStopProfit.SetCheck( param.m_bStopProfit );
  68. CString strTemp;
  69. strTemp.Format( "%.2f", param.m_dStopLosing * 100 );
  70. m_editStopLosing.SetWindowText( strTemp );
  71. strTemp.Format( "%.2f", param.m_dStopProfit * 100 );
  72. m_editStopProfit.SetWindowText( strTemp );
  73. OnCheckstoplosing( );
  74. OnCheckstopprofit( );
  75. // Long Index
  76. m_btnCheckLong.SetCheck( param.m_bLongTrend );
  77. m_btnCheckIndex.SetCheck( param.m_bIndexTrend );
  78. OnChecklong();
  79. OnCheckindex();
  80. m_cmbKTypeLong.InitializeWeek();
  81. m_cmbKTypeIndex.InitializeDay();
  82. m_cmbKTypeLong.Select( param.m_nKTypeLong );
  83. m_cmbKTypeIndex.Select( param.m_nKTypeIndex );
  84. m_bModified = FALSE;
  85. return TRUE;  // return TRUE unless you set the focus to a control
  86.               // EXCEPTION: OCX Property Pages should return FALSE
  87. }
  88. void CSimuAdvancedDlg::OnOK() 
  89. {
  90. UpdateData( );
  91. ASSERT( m_pStrategy );
  92. // Stop
  93. if( m_btnCheckStopLosing.GetCheck() && !IsNumber(m_strStopLosing,FALSE) )
  94. {
  95. AfxMessageBox( IDS_SIMUADVANCED_NOTNUMBER, MB_OK|MB_ICONINFORMATION );
  96. return;
  97. }
  98. if( m_btnCheckStopProfit.GetCheck() && !IsNumber(m_strStopProfit,FALSE) )
  99. {
  100. AfxMessageBox( IDS_SIMUADVANCED_NOTNUMBER, MB_OK|MB_ICONINFORMATION );
  101. return;
  102. }
  103. if( m_btnCheckLong.GetCheck() && m_pStrategy->GetSelectedTechsLongTrend().GetSize() <= 0 )
  104. {
  105. AfxMessageBox( IDS_SIMUADVANCED_NOSELECTEDLONG, MB_OK|MB_ICONINFORMATION );
  106. return;
  107. }
  108. if( m_btnCheckIndex.GetCheck() && m_pStrategy->GetSelectedTechsIndexTrend().GetSize() <= 0 )
  109. {
  110. AfxMessageBox( IDS_SIMUADVANCED_NOSELECTEDINDEX, MB_OK|MB_ICONINFORMATION );
  111. return;
  112. }
  113. // Stop
  114. COpParam & param = m_pStrategy->GetOpParam();
  115. param.m_bStopLosing = m_btnCheckStopLosing.GetCheck();
  116. param.m_bStopProfit = m_btnCheckStopProfit.GetCheck();
  117. param.m_dStopLosing = atof(m_strStopLosing) / 100.;
  118. param.m_dStopProfit = atof(m_strStopProfit) / 100.;
  119. // Long Index
  120. param.m_bLongTrend = m_btnCheckLong.GetCheck();
  121. param.m_bIndexTrend = m_btnCheckIndex.GetCheck();
  122. param.m_nKTypeLong = m_cmbKTypeLong.GetSelect();
  123. param.m_nKTypeIndex = m_cmbKTypeIndex.GetSelect();
  124. CDialog::OnOK();
  125. }
  126. // 止损
  127. void CSimuAdvancedDlg::OnCheckstoplosing() 
  128. {
  129. int nCheck = m_btnCheckStopLosing.GetCheck();
  130. m_editStopLosing.EnableWindow( nCheck );
  131. m_bModified = TRUE;
  132. }
  133. // 止赢
  134. void CSimuAdvancedDlg::OnCheckstopprofit() 
  135. {
  136. int nCheck = m_btnCheckStopProfit.GetCheck();
  137. m_editStopProfit.EnableWindow( nCheck );
  138. m_bModified = TRUE;
  139. }
  140. // 长期趋势
  141. void CSimuAdvancedDlg::OnChecklong() 
  142. {
  143. int nCheck = m_btnCheckLong.GetCheck();
  144. m_cmbKTypeLong.EnableWindow( nCheck );
  145. m_btnRuleLong.EnableWindow( nCheck );
  146. m_bModified = TRUE;
  147. if( nCheck && m_pStrategy && m_pStrategy->GetSelectedTechsLongTrend().GetSize() <= 0 )
  148. {
  149. OnRulelong();
  150. m_cmbKTypeLong.Invalidate();
  151. }
  152. }
  153. // 指数趋势
  154. void CSimuAdvancedDlg::OnCheckindex() 
  155. {
  156. int nCheck = m_btnCheckIndex.GetCheck();
  157. m_cmbKTypeIndex.EnableWindow( nCheck );
  158. m_btnRuleIndex.EnableWindow( nCheck );
  159. m_bModified = TRUE;
  160. if( nCheck && m_pStrategy && m_pStrategy->GetSelectedTechsIndexTrend().GetSize() <= 0 )
  161. {
  162. OnRuleindex();
  163. m_cmbKTypeIndex.Invalidate();
  164. }
  165. }
  166. // 设定长期趋势参数
  167. void CSimuAdvancedDlg::OnRulelong() 
  168. {
  169. ASSERT( m_pStrategy );
  170. CSetRule setrule(IDS_STRATEGY_SETRULELONG, IDS_STRATEGY_SETRULELONG, NULL);
  171. setrule.SetTechParameters( &(m_pStrategy->GetTechParametersLongTrend()), &(m_pStrategy->GetSelectedTechsLongTrend()) );
  172. CPropertySheet sht;
  173. sht.AddPage( &setrule );
  174. sht.SetActivePage( &setrule );
  175. //CBitmap bmp;
  176. //bmp.LoadBitmap( IDB_BALANG );
  177. //sht.SetBitmap( (HBITMAP)bmp.GetSafeHandle() );
  178. sht.DoModal();
  179. m_bModified = setrule.m_bModified;
  180. }
  181. // 设定指数趋势参数
  182. void CSimuAdvancedDlg::OnRuleindex() 
  183. {
  184. ASSERT( m_pStrategy );
  185. CSetRule setrule(IDS_STRATEGY_SETRULEINDEX, IDS_STRATEGY_SETRULEINDEX, NULL);
  186. setrule.SetTechParameters( &(m_pStrategy->GetTechParametersIndexTrend()), &(m_pStrategy->GetSelectedTechsIndexTrend()) );
  187. CPropertySheet sht;
  188. sht.AddPage( &setrule );
  189. sht.SetActivePage( &setrule );
  190. //CBitmap bmp;
  191. //bmp.LoadBitmap( IDB_BALANG );
  192. //sht.SetBitmap( (HBITMAP)bmp.GetSafeHandle() );
  193. sht.DoModal();
  194. m_bModified = setrule.m_bModified;
  195. }