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

金融证券系统

开发平台:

Visual C++

  1. // SetBasedataDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "SetBasedataDlg.h"
  5. #include <io.h>
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CSetBasedataDlg dialog
  13. IMPLEMENT_DYNCREATE(CSetBasedataDlg, CPropertyPageEx)
  14. CSetBasedataDlg::CSetBasedataDlg( )
  15. : CPropertyPageEx(CSetBasedataDlg::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CSetBasedataDlg)
  18. m_strA = _T("");
  19. m_strB = _T("");
  20. m_strH = _T("");
  21. m_strNational = _T("");
  22. m_strCorp = _T("");
  23. m_strTotal = _T("");
  24. //}}AFX_DATA_INIT
  25. }
  26. void CSetBasedataDlg::EnableEdit( BOOL bEnable )
  27. {
  28. m_editA.EnableWindow( bEnable );
  29. m_editB.EnableWindow( bEnable );
  30. m_editH.EnableWindow( bEnable );
  31. m_editNational.EnableWindow( bEnable );
  32. m_editCorp.EnableWindow( bEnable );
  33. m_editTotal.EnableWindow( bEnable );
  34. }
  35. void CSetBasedataDlg::LoadBasedata( CString strStockCode )
  36. {
  37. if( strStockCode.GetLength() <= 0 )
  38. return;
  39. CStockInfo info;
  40. if( AfxGetStockContainer().GetStockInfo( strStockCode, &info ) )
  41. {
  42. m_strA.Format( "%.0f", info.m_fShare_count_a * 0.0001f );
  43. m_strB.Format( "%.0f", info.m_fShare_count_b * 0.0001f );
  44. m_strH.Format( "%.0f", info.m_fShare_count_h * 0.0001f );
  45. m_strNational.Format( "%.0f", info.m_fShare_count_national * 0.0001f );
  46. m_strCorp.Format( "%.0f", info.m_fShare_count_corp * 0.0001f );
  47. m_strTotal.Format( "%.0f", info.m_fShare_count_total * 0.0001f );
  48. }
  49. UpdateData( FALSE );
  50. }
  51. BOOL CSetBasedataDlg::StoreBasedata( CString strStockCode )
  52. {
  53. if( strStockCode.GetLength() <= 0 )
  54. return TRUE;
  55. UpdateData( );
  56. if( !IsNumber(m_strA,TRUE) || !IsNumber(m_strB,TRUE) || !IsNumber(m_strH,TRUE)
  57. || !IsNumber(m_strNational,TRUE) || !IsNumber(m_strCorp,TRUE) || !IsNumber(m_strTotal,TRUE) )
  58. {
  59. AfxMessageBox( IDS_SETBASEDATA_NOTNUMBER );
  60. return FALSE;
  61. }
  62. CStockInfo info;
  63. int id = 0;
  64. CStockContainer & container = AfxGetStockContainer();
  65. if( container.GetStockInfo( strStockCode, &info, &id ) )
  66. {
  67. info.m_fShare_count_a = (float)(atof(m_strA) * 10000);
  68. info.m_fShare_count_b = (float)(atof(m_strB) * 10000);
  69. info.m_fShare_count_h = (float)(atof(m_strH) * 10000);
  70. info.m_fShare_count_national = (float)(atof(m_strNational) * 10000);
  71. info.m_fShare_count_corp = (float)(atof(m_strCorp) * 10000);
  72. info.m_fShare_count_total = (float)(atof(m_strTotal) * 10000);
  73. int nBaseIdx = info.m_basedata.GetSize()-1;
  74. if( nBaseIdx >= 0 )
  75. {
  76. info.m_basedata.ElementAt(nBaseIdx).m_fShare_count_a = info.m_fShare_count_a;
  77. info.m_basedata.ElementAt(nBaseIdx).m_fShare_count_b = info.m_fShare_count_b;
  78. info.m_basedata.ElementAt(nBaseIdx).m_fShare_count_h = info.m_fShare_count_h;
  79. info.m_basedata.ElementAt(nBaseIdx).m_fShare_count_national = info.m_fShare_count_national;
  80. info.m_basedata.ElementAt(nBaseIdx).m_fShare_count_corp = info.m_fShare_count_corp;
  81. info.m_basedata.ElementAt(nBaseIdx).m_fShare_count_total = info.m_fShare_count_total;
  82. }
  83. float temp = info.m_fShare_count_a+info.m_fShare_count_b+info.m_fShare_count_h+info.m_fShare_count_national+info.m_fShare_count_corp;
  84. if( info.m_fShare_count_total+1 < temp )
  85. {
  86. AfxMessageBox( IDS_SETBASEDATA_SHARENOTMATCH );
  87. return FALSE;
  88. }
  89. if( id >= 0 && id < container.GetSize() )
  90. AfxGetStockContainer().ElementAt( id ) = info;
  91. }
  92. return TRUE;
  93. }
  94. void CSetBasedataDlg::DoDataExchange(CDataExchange* pDX)
  95. {
  96. CPropertyPageEx::DoDataExchange(pDX);
  97. //{{AFX_DATA_MAP(CSetBasedataDlg)
  98. DDX_Control(pDX, IDC_SAVE, m_btnSave);
  99. DDX_Control(pDX, IDC_EDITTOTAL, m_editTotal);
  100. DDX_Control(pDX, IDC_EDITCORP, m_editCorp);
  101. DDX_Control(pDX, IDC_EDITNATIONAL, m_editNational);
  102. DDX_Control(pDX, IDC_EDITH, m_editH);
  103. DDX_Control(pDX, IDC_EDITB, m_editB);
  104. DDX_Control(pDX, IDC_EDITA, m_editA);
  105. DDX_Control(pDX, IDC_STATICSTOCK, m_staticStock);
  106. DDX_Control(pDX, IDC_LIST_STOCKSRC, m_listStockSrc);
  107. DDX_Control(pDX, IDC_COMBO_GROUPSRC, m_comboGroupSrc);
  108. DDX_Control(pDX, IDC_EDITCODE, m_editCode);
  109. DDX_Text(pDX, IDC_EDITA, m_strA);
  110. DDX_Text(pDX, IDC_EDITB, m_strB);
  111. DDX_Text(pDX, IDC_EDITH, m_strH);
  112. DDX_Text(pDX, IDC_EDITNATIONAL, m_strNational);
  113. DDX_Text(pDX, IDC_EDITCORP, m_strCorp);
  114. DDX_Text(pDX, IDC_EDITTOTAL, m_strTotal);
  115. //}}AFX_DATA_MAP
  116. }
  117. BEGIN_MESSAGE_MAP(CSetBasedataDlg, CPropertyPageEx)
  118. //{{AFX_MSG_MAP(CSetBasedataDlg)
  119. ON_EN_CHANGE(IDC_EDITCODE, OnChangeEditcode)
  120. ON_CBN_SELCHANGE(IDC_COMBO_GROUPSRC, OnSelchangeComboGroupsrc)
  121. ON_LBN_SELCHANGE(IDC_LIST_STOCKSRC, OnSelchangeListStocksrc)
  122. ON_BN_CLICKED(IDC_SAVE, OnSave)
  123. //}}AFX_MSG_MAP
  124. END_MESSAGE_MAP()
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CSetBasedataDlg message handlers
  127. BOOL CSetBasedataDlg::OnInitDialog()
  128. {
  129. CPropertyPageEx::OnInitDialog();
  130. EnableEdit( FALSE );
  131. CWaitCursor waitcursor;
  132. // TODO: Add extra initialization here
  133. CDomainContainer & groups = AfxGetGroupContainer( );
  134. CDomainContainer & domains = AfxGetDomainContainer( );
  135. CStockContainer & container = AfxGetStockContainer();
  136. // Src
  137. m_comboGroupSrc.InitStrings( TRUE, TRUE, groups );
  138. m_comboGroupSrc.SetCurSel( 0 );
  139. OnSelchangeComboGroupsrc();
  140. OnSelchangeListStocksrc();
  141. return TRUE;  // return TRUE unless you set the focus to a control
  142.               // EXCEPTION: OCX Property Pages should return FALSE
  143. }
  144. void CSetBasedataDlg::OnChangeEditcode() 
  145. {
  146. // TODO: If this is a RICHEDIT control, the control will not
  147. // send this notification unless you override the CPropertyPageEx::OnInitDialog()
  148. // function and call CRichEditCtrl().SetEventMask()
  149. // with the ENM_CHANGE flag ORed into the mask.
  150. // TODO: Add your control notification handler code here
  151. CString strText;
  152. m_editCode.GetWindowText( strText );
  153. strText.TrimLeft();
  154. strText.TrimLeft();
  155. if( strText.GetLength() > 0 )
  156. {
  157. int nSel = m_comboGroupSrc.GetCurSel();
  158. if( CB_ERR == nSel ||
  159. CStockContainer::typeAll != (int)(m_comboGroupSrc.GetItemData( nSel )) )
  160. {
  161. m_comboGroupSrc.SelectGroupAll( );
  162. OnSelchangeComboGroupsrc();
  163. }
  164. }
  165. if( !m_listStockSrc.SelectCode( 0, strText ) )
  166. m_listStockSrc.SelectShortname( 0, strText );
  167. OnSelchangeListStocksrc( );
  168. }
  169. void CSetBasedataDlg::OnSelchangeComboGroupsrc() 
  170. {
  171. // TODO: Add your control notification handler code here
  172. int nType = m_comboGroupSrc.GetCurSelType();
  173. CString strName = m_comboGroupSrc.GetCurSelName();
  174. m_listStockSrc.SetCurrentStocks( nType, strName, AfxGetGroupContainer() );
  175. }
  176. BOOL CSetBasedataDlg::PreTranslateMessage(MSG* pMsg) 
  177. {
  178. // TODO: Add your specialized code here and/or call the base class
  179. if( WM_KEYDOWN == pMsg->message )
  180. {
  181. if( VK_UP == pMsg->wParam )
  182. {
  183. if( ::GetFocus() == m_editCode.GetSafeHwnd() )
  184. {
  185. m_listStockSrc.SelectUp( );
  186. OnSelchangeListStocksrc( );
  187. return TRUE;
  188. }
  189. }
  190. else if( VK_DOWN == pMsg->wParam )
  191. {
  192. if( ::GetFocus() == m_editCode.GetSafeHwnd() )
  193. {
  194. m_listStockSrc.SelectDown( );
  195. OnSelchangeListStocksrc( );
  196. return TRUE;
  197. }
  198. }
  199. else if( VK_PRIOR == pMsg->wParam )
  200. {
  201. if( ::GetFocus() == m_editCode.GetSafeHwnd() )
  202. {
  203. m_listStockSrc.SelectPrior( );
  204. OnSelchangeListStocksrc( );
  205. return TRUE;
  206. }
  207. }
  208. else if( VK_NEXT == pMsg->wParam )
  209. {
  210. if( ::GetFocus() == m_editCode.GetSafeHwnd() )
  211. {
  212. m_listStockSrc.SelectNext( );
  213. OnSelchangeListStocksrc( );
  214. return TRUE;
  215. }
  216. }
  217. else if( VK_RETURN == pMsg->wParam )
  218. {
  219. if( ::GetFocus() == m_editCode.GetSafeHwnd() )
  220. {
  221. m_editCode.SetWindowText( NULL );
  222. return TRUE;
  223. }
  224. }
  225. }
  226. return CPropertyPageEx::PreTranslateMessage(pMsg);
  227. }
  228. void CSetBasedataDlg::OnSelchangeListStocksrc() 
  229. {
  230. // TODO: Add your control notification handler code here
  231. HWND hWndFocus = ::GetFocus( );
  232. int nSel = m_listStockSrc.GetCurSel( );
  233. //if( !StoreBasedata( m_strCurStockCode ) )
  234. //{
  235. // m_listStockSrc.SelectCode( 0, m_strCurStockCode );
  236. // return;
  237. //}
  238. if( LB_ERR != nSel )
  239. {
  240. CString rString, strStockCode;
  241. m_listStockSrc.GetText(nSel,rString);
  242. int nIndex = rString.Find( '(' );
  243. if( -1 != nIndex )
  244. strStockCode = rString.Left( nIndex );
  245. m_staticStock.SetWindowText( rString );
  246. m_strCurStockCode = strStockCode;
  247. LoadBasedata( m_strCurStockCode );
  248. }
  249. else
  250. {
  251. CString strNoStock;
  252. strNoStock.LoadString( IDS_SETBASEDATA_NOSTOCK );
  253. m_staticStock.SetWindowText( strNoStock );
  254. m_strCurStockCode.Empty();
  255. }
  256. EnableEdit( m_strCurStockCode.GetLength() > 0 );
  257. ::SetFocus( hWndFocus );
  258. }
  259. void CSetBasedataDlg::OnCompleted( )
  260. {
  261. // StoreBasedata( m_strCurStockCode );
  262. AfxGetDB().StoreBasetable( AfxGetStockContainer() );
  263. AfxGetSListStockContainer().ReRetrieveFromStatic( AfxGetActiveStrategy() );
  264. AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_GRAPHVIEW, NULL );
  265. AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_BASEVIEW, NULL );
  266. AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_SLISTVIEW, NULL );
  267. AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_SELECTORVIEW, NULL );
  268. }
  269. void CSetBasedataDlg::OnOK() 
  270. {
  271. OnCompleted( );
  272. CPropertyPageEx::OnOK();
  273. }
  274. void CSetBasedataDlg::OnCancel() 
  275. {
  276. OnCompleted( );
  277. CPropertyPageEx::OnCancel();
  278. }
  279. BOOL CSetBasedataDlg::OnKillActive() 
  280. {
  281. OnCompleted( );
  282. return CPropertyPageEx::OnKillActive();
  283. }
  284. void CSetBasedataDlg::OnSave() 
  285. {
  286. StoreBasedata( m_strCurStockCode );
  287. }