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

金融证券系统

开发平台:

Visual C++

  1. /*
  2. Cross Platform Core Code.
  3. Copyright(R) 2001-2002 Balang Software.
  4. All rights reserved.
  5. Using:
  6. class CExpress;
  7. class CIndex;
  8. class CIndexContainer;
  9. */
  10. #include "stdafx.h"
  11. #include "../Include/Express.h"
  12. #include <math.h>
  13. #ifdef _DEBUG
  14. #undef THIS_FILE
  15. static char THIS_FILE[]=__FILE__;
  16. #define new DEBUG_NEW
  17. #endif
  18. SLH_DATA slh_data_array[SLH_MAX+1] = {
  19. { SLH_NONE, "", 100, "" },
  20. { SLH_CODE, "", 100, "" },
  21. { SLH_NAME, "", 110, "" },
  22. // 技术数据
  23. { SLH_DATE, "", 110, "" },
  24. { SLH_LASTCLOSE, "", 100, "lastclose" },
  25. { SLH_OPEN, "", 100, "open" },
  26. { SLH_CLOSE, "", 100, "close" },
  27. { SLH_HIGH, "", 100, "high" },
  28. { SLH_LOW, "", 100, "low" },
  29. { SLH_AVERAGE, "", 100, "average" },
  30. { SLH_DIFF, "", 100, "diff" },
  31. { SLH_DIFFPERCENT, "", 100, "diffpercent" },
  32. { SLH_SCOPE, "", 100, "scope" },
  33. { SLH_VOLUME, "", 140, "volume" },
  34. { SLH_AMOUNT, "", 140, "amount" },
  35. { SLH_VOLUP, "", 100, "volup" },
  36. { SLH_VOLDOWN, "", 100, "voldown" },
  37. { SLH_DIFFPERCENT_MIN5, "", 100, "diffpercent_min5" },
  38. { SLH_SELLBUYRATIO, "", 100, "sellbuyratio" },
  39. { SLH_SELLBUYDIFF, "", 100, "sellbuydiff" },
  40. { SLH_BUYPRICE3, "", 100, "buyprice3" },
  41. { SLH_BUYPRICE2, "", 100, "buyprice2" },
  42. { SLH_BUYPRICE1, "", 100, "buyprice1" },
  43. { SLH_SELLPRICE1, "", 100, "sellprice1" },
  44. { SLH_SELLPRICE2, "", 100, "sellprice2" },
  45. { SLH_SELLPRICE3, "", 100, "sellprice3" },
  46. { SLH_BUYVOLUME3, "", 100, "buyvolume3" },
  47. { SLH_BUYVOLUME2, "", 100, "buyvolume2" },
  48. { SLH_BUYVOLUME1, "", 100, "buyvolume1" },
  49. { SLH_SELLVOLUME1, "", 100, "sellvolume1" },
  50. { SLH_SELLVOLUME2, "", 100, "sellvolume2" },
  51. { SLH_SELLVOLUME3, "", 100, "sellvolume3" },
  52. // 主要基本指标
  53. { SLH_REPORTTYPE, "", 100, "" },
  54. { SLH_PE, "", 100, "pe" },
  55. { SLH_PNETASSET, "", 100, "pnetasset" },
  56. { SLH_PMAININCOME, "", 100, "pmainincome" },
  57. { SLH_RATIO_PCASH, "", 100, "ratio_pcash" },
  58. { SLH_RATIO_CURRENCY, "", 100, "ratio_currency" },
  59. { SLH_RATIO_CHANGEHAND, "", 100, "ratio_changehand" },
  60. { SLH_RATIO_VOLUME, "", 100, "ratio_volume" },
  61. { SLH_RS, "", 100, "rs" },
  62. { SLH_MARKETVALUE, "", 170, "marketvalue" },
  63. { SLH_MARKETVALUEA, "", 170, "marketvaluea" },
  64. { SLH_MARKETVALUEB, "", 170, "marketvalueb" },
  65. // ★偿债能力
  66. { SLH_RATIO_LIQUIDITY, "", 140, "ratio_liquidity" },
  67. { SLH_RATIO_QUICK, "", 140, "ratio_quick" },
  68. { SLH_VELOCITY_RECEIVABLES, "", 170, "velocity_receivables" },
  69. // ★经营能力
  70. { SLH_VELOCITY_MERCHANDISE, "", 150, "velocity_merchandise" },
  71. { SLH_MAIN_INCOME, "", 160, "main_income" },
  72. { SLH_CASH_PS, "", 170, "cash_ps" },
  73. // ★盈利能力
  74. { SLH_PROFIT_MARGIN, "", 170, "profit_margin" },
  75. { SLH_NETASSET_YIELD, "", 190, "netasset_yield" },
  76. // ★资本结构
  77. { SLH_DATE_BEGIN, "", 160, "" },
  78. { SLH_SHARE_COUNT_TOTAL, "", 160, "share_count_total" },
  79. { SLH_SHARE_COUNT_A, "", 140, "share_count_a" },
  80. { SLH_SHARE_COUNT_B, "", 140, "share_count_b" },
  81. { SLH_SHARE_COUNT_H, "", 140, "share_count_h" },
  82. { SLH_SHARE_COUNT_NATIONAL, "", 140, "share_count_national" },
  83. { SLH_SHARE_COUNT_CORP, "", 140, "share_count_corp" },
  84. { SLH_PROFIT_PSUD, "", 170, "profit_psud" },
  85. { SLH_ASSET, "", 140, "asset" },
  86. { SLH_RATIO_HOLDERRIGHT, "", 170, "ratio_holderright" },
  87. { SLH_RATIO_LONGDEBT, "", 170, "ratio_longdebt" },
  88. { SLH_RATIO_DEBT, "", 170, "ration_debt" },
  89. // ★投资收益能力
  90. { SLH_NETASSET_PS, "", 150, "netasset_ps" },
  91. { SLH_NETASSET_PS_REGULATE, "", 200, "netasset_ps_regulate" },
  92. { SLH_EPS, "", 140, "eps" },
  93. { SLH_EPS_DEDUCT, "", 170, "eps_deduct" },
  94. { SLH_NET_PROFIT, "", 140, "net_profit" },
  95. { SLH_MAIN_PROFIT, "", 140, "main_profit" },
  96. { SLH_TOTAL_PROFIT, "", 140, "total_profit" },
  97. { SLH_PROFIT_INC, "", 170, "profit_inc" },
  98. { SLH_INCOME_INC, "", 170, "income_inc" },
  99. { SLH_ASSET_INC, "", 190, "asset_inc" },
  100. { SLH_ANNGAINS_AVERAGE, "", 170, "anngains_average" },
  101. { SLH_ANNGAINS_STDDEV, "", 170, "anngains_stddev" },
  102. { SLH_BETA, "", 100, "beta" },
  103. { SLH_SHARP, "", 100, "sharp" },
  104. { SLH_TRADE, "", 100, "" },
  105. { SLH_PROVINCE, "", 100, "" },
  106. };
  107. CSPString AfxGetVariantName( UINT nVariantID, BOOL bWithParameter )
  108. {
  109. if( nVariantID >= SLH_USERDEFINE_BEGIN )
  110. {
  111. CIndexContainer & aindex = AfxGetProfile().GetSListColumnsUser();
  112. CIndex index = aindex.GetIndex( nVariantID );
  113. return index.m_strName;
  114. }
  115. if( nVariantID < SLH_MIN || nVariantID > SLH_MAX )
  116. return "";
  117. CSPString strResult;
  118. if( strResult.IsEmpty() )
  119. strResult = slh_data_array[nVariantID].string;
  120. if( strResult.IsEmpty() )
  121. {
  122. SP_ASSERT( nVariantID == slh_data_array[nVariantID].slh_id );
  123. strResult = AfxGetSLHTitle( nVariantID );
  124. int size = sizeof(slh_data_array[nVariantID].string);
  125. strncpy( slh_data_array[nVariantID].string, strResult, size-1 );
  126. slh_data_array[nVariantID].string[size-1] = 0;
  127. }
  128. if( bWithParameter )
  129. {
  130. if( SLH_DIFF == nVariantID || SLH_DIFFPERCENT == nVariantID || SLH_SCOPE == nVariantID
  131. || SLH_RATIO_CHANGEHAND == nVariantID || SLH_RATIO_VOLUME == nVariantID
  132. || SLH_RS == nVariantID || SLH_ANNGAINS_AVERAGE == nVariantID )
  133. {
  134. CSPString strSuf, strTemp;
  135. strSuf = slh_hdrday;
  136. if( SLH_DIFF == nVariantID )
  137. strTemp.Format( "%s-%d%s", (LPCTSTR)strResult, AfxGetProfile().GetDiffDays(), (LPCTSTR)strSuf );
  138. else if( SLH_DIFFPERCENT == nVariantID )
  139. strTemp.Format( "%s-%d%s", (LPCTSTR)strResult, AfxGetProfile().GetDiffPercentDays(), (LPCTSTR)strSuf );
  140. else if( SLH_SCOPE == nVariantID )
  141. strTemp.Format( "%s-%d%s", (LPCTSTR)strResult, AfxGetProfile().GetScopeDays(), (LPCTSTR)strSuf );
  142. else if( SLH_RATIO_CHANGEHAND == nVariantID )
  143. strTemp.Format( "%s-%d%s", (LPCTSTR)strResult, AfxGetProfile().GetRatioChangeHandDays(), (LPCTSTR)strSuf );
  144. else if( SLH_RATIO_VOLUME == nVariantID )
  145. strTemp.Format( "%s-%d%s", (LPCTSTR)strResult, AfxGetProfile().GetRatioVolumeDays(), (LPCTSTR)strSuf );
  146. else if( SLH_RS == nVariantID )
  147. strTemp.Format( "%s-%d%s", (LPCTSTR)strResult, AfxGetProfile().GetRSDays(), (LPCTSTR)strSuf );
  148. else if( SLH_ANNGAINS_AVERAGE == nVariantID )
  149. strTemp.Format( "%s-%d%s", (LPCTSTR)strResult, AfxGetProfile().GetYieldAverageDays(), (LPCTSTR)strSuf );
  150. else
  151. SP_ASSERT( FALSE );
  152. strResult = strTemp;
  153. }
  154. }
  155. return strResult;
  156. }
  157. BOOL AfxGetVariantNameArray( CSPStringArray & astr, BOOL bWithParameter )
  158. {
  159. astr.SetSize( 0, SLH_MAX+SLH_MIN+1 );
  160. for( int nVariantID = min(0,SLH_MIN); nVariantID <= SLH_MAX; nVariantID ++ )
  161. {
  162. if( strlen(slh_data_array[nVariantID].varname) > 0 )
  163. {
  164. CSPString strTemp = AfxGetVariantName( nVariantID, bWithParameter );
  165. astr.Add( strTemp );
  166. }
  167. else
  168. {
  169. astr.Add( "" );
  170. }
  171. }
  172. return TRUE;
  173. }
  174. UINT AfxGetVariantID( CSPString strName, BOOL bWithParameter )
  175. {
  176. for( int nVariantID = SLH_MIN; nVariantID <= SLH_MAX; nVariantID ++ )
  177. {
  178. CSPString strTemp = AfxGetVariantName( nVariantID, bWithParameter );
  179. if( 0 == strTemp.CompareNoCase( strName ) )
  180. return nVariantID;
  181. }
  182. CIndexContainer & aindex = AfxGetProfile().GetSListColumnsUser();
  183. CIndex index = aindex.GetIndex( strName );
  184. if( !index.IsInvalidID() )
  185. return index.m_nID;
  186. return SLH_INVALID;
  187. }
  188. CSPString AfxGetVariantVarName( int nVariantID )
  189. {
  190. if( nVariantID >= SLH_MIN && nVariantID <= SLH_MAX )
  191. return slh_data_array[nVariantID].varname;
  192. else
  193. return "";
  194. }
  195. CSPString AfxGetVariantVarName( CSPString strName, BOOL bWithParameter )
  196. {
  197. UINT nVariantID = AfxGetVariantID( strName, bWithParameter );
  198. return AfxGetVariantVarName( nVariantID );
  199. }
  200. /* 计算股票列表视图中某一列的值,其数值单位与股票列表视图中相同 */
  201. BOOL AfxGetVariantValue(UINT nVariantID, CStockInfo &info, double * pValue,
  202. CStockContainer *pContainer )
  203. {
  204. if( NULL == pValue )
  205. {
  206. SP_ASSERT( FALSE );
  207. return FALSE;
  208. }
  209. double factor = 1; // CStock::GetReportFactor( info.m_reporttype );
  210. if( nVariantID >= SLH_MIN && nVariantID <= SLH_MAX )
  211. {
  212. switch( nVariantID )
  213. {
  214. case SLH_LASTCLOSE: // 昨收
  215. *pValue = info.m_fLast;
  216. return ( info.m_fLast > 1e-4 );
  217. case SLH_OPEN: // 今开
  218. *pValue = info.m_fOpen;
  219. return ( info.m_fOpen > 1e-4 );
  220. case SLH_CLOSE: // 收盘价
  221. *pValue = info.m_fClose;
  222. return ( info.m_fClose > 1e-4 );
  223. case SLH_HIGH: // 最高价
  224. *pValue = info.m_fHigh;
  225. return ( info.m_fHigh > 1e-4 );
  226. case SLH_LOW: // 最低价
  227. *pValue = info.m_fLow;
  228. return ( info.m_fLow > 1e-4 );
  229. case SLH_AVERAGE: // 均价
  230. return info.GetAverage( pValue );
  231. case SLH_DIFF: // 涨跌
  232. return info.GetDiff( pValue, info.m_datetech, AfxGetProfile().GetDiffDays() );
  233. case SLH_DIFFPERCENT: // 涨幅
  234. return info.GetDiffPercent( pValue, info.m_datetech, AfxGetProfile().GetDiffPercentDays() );
  235. case SLH_SCOPE: // 震幅
  236. return info.GetScope( pValue, info.m_datetech, AfxGetProfile().GetScopeDays() );
  237. case SLH_VOLUME: // 成交量
  238. *pValue = info.m_fVolume*0.01;
  239. return ( info.m_fVolume > 1e-4 );
  240. case SLH_AMOUNT: // 成交额
  241. *pValue = info.m_fAmount*0.001;
  242. return ( info.m_fAmount > 1e-4 );
  243. case SLH_VOLUP: // 外盘
  244. if( info.m_minute.StatVolumeInfo( NULL, pValue, NULL ) )
  245. {
  246. *pValue = (*pValue) * 0.01;
  247. return TRUE;
  248. }
  249. break;
  250. case SLH_VOLDOWN: // 内盘
  251. if( info.m_minute.StatVolumeInfo( NULL, NULL, pValue ) )
  252. {
  253. *pValue = (*pValue) * 0.01;
  254. return TRUE;
  255. }
  256. break;
  257. case SLH_DIFFPERCENT_MIN5: // 五分钟涨幅%
  258. return info.GetDiffPercentMin5( pValue );
  259. case SLH_SELLBUYRATIO: // 委比%
  260. return info.GetSellBuyRatio( pValue, NULL );
  261. case SLH_SELLBUYDIFF: // 委量差
  262. if( info.GetSellBuyRatio( NULL, pValue ) )
  263. {
  264. *pValue = (*pValue) * 0.01;
  265. return TRUE;
  266. }
  267. break;
  268. case SLH_BUYPRICE3: // 买价三
  269. *pValue = info.m_fBuyPrice[2];
  270. return ( info.m_fBuyPrice[2] > 1e-4 );
  271. case SLH_BUYPRICE2: // 买价二
  272. *pValue = info.m_fBuyPrice[1];
  273. return ( info.m_fBuyPrice[1] > 1e-4 );
  274. case SLH_BUYPRICE1: // 买价一
  275. *pValue = info.m_fBuyPrice[0];
  276. return ( info.m_fBuyPrice[0] > 1e-4 );
  277. case SLH_SELLPRICE1: // 卖价一
  278. *pValue = info.m_fSellPrice[0];
  279. return ( info.m_fSellPrice[0] > 1e-4 );
  280. case SLH_SELLPRICE2: // 卖价二
  281. *pValue = info.m_fSellPrice[1];
  282. return ( info.m_fSellPrice[1] > 1e-4 );
  283. case SLH_SELLPRICE3: // 卖价三
  284. *pValue = info.m_fSellPrice[2];
  285. return ( info.m_fSellPrice[2] > 1e-4 );
  286. case SLH_BUYVOLUME3: // 买量三
  287. *pValue = info.m_fBuyVolume[2] * 0.01;
  288. return ( info.m_fBuyVolume[2] > 1e-4 );
  289. case SLH_BUYVOLUME2: // 买量二
  290. *pValue = info.m_fBuyVolume[1] * 0.01;
  291. return ( info.m_fBuyVolume[1] > 1e-4 );
  292. case SLH_BUYVOLUME1: // 买量一
  293. *pValue = info.m_fBuyVolume[0] * 0.01;
  294. return ( info.m_fBuyVolume[0] > 1e-4 );
  295. case SLH_SELLVOLUME1: // 卖量一
  296. *pValue = info.m_fSellVolume[0] * 0.01;
  297. return ( info.m_fSellVolume[0] > 1e-4 );
  298. case SLH_SELLVOLUME2: // 卖量二
  299. *pValue = info.m_fSellVolume[1] * 0.01;
  300. return ( info.m_fSellVolume[1] > 1e-4 );
  301. case SLH_SELLVOLUME3: // 卖量三
  302. *pValue = info.m_fSellVolume[2] * 0.01;
  303. return ( info.m_fSellVolume[2] > 1e-4 );
  304. // 主要基本指标
  305. case SLH_PE: // 市盈率
  306. return info.GetPE( pValue );
  307. case SLH_PNETASSET: // 市净率
  308. return info.GetPNetAsset( pValue );
  309. case SLH_PMAININCOME: // 市销率
  310. return info.GetPMainIncome( pValue );
  311. case SLH_RATIO_PCASH: // 价格净现金比
  312. return info.GetRatioPCash( pValue );
  313. case SLH_RATIO_CURRENCY: // 流通率
  314. return info.GetRatioCurrency( pValue );
  315. case SLH_RATIO_CHANGEHAND: // 换手率
  316. return info.GetRatioChangeHand( pValue, info.m_datetech, AfxGetProfile().GetRatioChangeHandDays() );
  317. case SLH_RATIO_VOLUME: // 量比
  318. return info.GetRatioVolume( pValue, info.m_datetech, AfxGetProfile().GetRatioVolumeDays() );
  319. case SLH_RS: // 相对强度
  320. return info.GetRS( pValue, info.m_datetech, AfxGetProfile().GetRSDays() );
  321. case SLH_MARKETVALUE: // 总市值
  322. if( info.GetMarketValue( pValue ) )
  323. {
  324. *pValue = (*pValue) * 0.0001;
  325. return TRUE;
  326. }
  327. break;
  328. case SLH_MARKETVALUEA: // A股市值
  329. if( info.GetMarketValueA( pValue ) )
  330. {
  331. *pValue = (*pValue) * 0.0001;
  332. return TRUE;
  333. }
  334. break;
  335. case SLH_MARKETVALUEB: // B股市值
  336. if( info.GetMarketValueB( pValue ) )
  337. {
  338. *pValue = (*pValue) * 0.0001;
  339. return TRUE;
  340. }
  341. break;
  342. // ★偿债能力
  343. case SLH_RATIO_LIQUIDITY: // 流动比率
  344. *pValue = info.m_fRatio_liquidity;
  345. return ( fabs(info.m_fRatio_liquidity) > 1e-4 );
  346. case SLH_RATIO_QUICK: // 速动比率
  347. *pValue = info.m_fRatio_quick;
  348. return ( fabs(info.m_fRatio_quick) > 1e-4 );
  349. case SLH_VELOCITY_RECEIVABLES: // 应收帐款周率
  350. *pValue = info.m_fVelocity_receivables;
  351. return ( fabs(info.m_fVelocity_receivables) > 1e-4 );
  352. // ★经营能力
  353. case SLH_VELOCITY_MERCHANDISE: // 存货周转率
  354. *pValue = info.m_fVelocity_merchandise;
  355. return ( fabs(info.m_fVelocity_merchandise) > 1e-4 );
  356. case SLH_MAIN_INCOME: // 主营业务收入
  357. *pValue = factor * info.m_fMain_income * 0.0001;
  358. return ( fabs(info.m_fMain_income) > 1e-4 );
  359. case SLH_CASH_PS: // 每股净现金流量
  360. *pValue = factor * info.m_fCash_ps;
  361. return ( fabs(info.m_fCash_ps) > 1e-4 );
  362. // ★盈利能力
  363. case SLH_PROFIT_MARGIN: // 主营业务利润率
  364. *pValue = info.m_fProfit_margin;
  365. return ( fabs(info.m_fProfit_margin) > 1e-4 );
  366. case SLH_NETASSET_YIELD: // 净资产收益率
  367. *pValue = factor * info.m_fNetasset_yield;
  368. return ( fabs(info.m_fNetasset_yield) > 1e-4 );
  369. // ★资本结构
  370. case SLH_SHARE_COUNT_TOTAL: // 总股本
  371. *pValue = info.m_fShare_count_total * 0.0001;
  372. return ( info.m_fShare_count_total > 1e-4 );
  373. case SLH_SHARE_COUNT_A: // 流通A股
  374. *pValue = info.m_fShare_count_a * 0.0001;
  375. return TRUE;
  376. case SLH_SHARE_COUNT_B: // 流通B股
  377. *pValue = info.m_fShare_count_b * 0.0001;
  378. return TRUE;
  379. case SLH_SHARE_COUNT_H: // 流通H股
  380. *pValue = info.m_fShare_count_h * 0.0001;
  381. return TRUE;
  382. case SLH_SHARE_COUNT_NATIONAL: // 国有股
  383. *pValue = info.m_fShare_count_national * 0.0001;
  384. return TRUE;
  385. case SLH_SHARE_COUNT_CORP: // 法人股
  386. *pValue = info.m_fShare_count_corp * 0.0001;
  387. return TRUE;
  388. case SLH_PROFIT_PSUD: // 每股未分配利润
  389. *pValue = info.m_fProfit_psud;
  390. return TRUE;
  391. case SLH_ASSET: // 总资产
  392. *pValue = info.m_fAsset * 0.0001;
  393. return ( fabs(info.m_fAsset) > 1e-4 );
  394. case SLH_RATIO_HOLDERRIGHT: // 股东权益比率
  395. *pValue = info.m_fRatio_holderright;
  396. return ( fabs(info.m_fRatio_holderright) > 1e-4 );
  397. case SLH_RATIO_LONGDEBT: // 长期负债率
  398. *pValue = info.m_fRatio_longdebt;
  399. return TRUE;
  400. case SLH_RATIO_DEBT: // 资产负债率
  401. *pValue = info.m_fRatio_debt;
  402. return ( fabs(info.m_fRatio_debt) > 1e-4 );
  403. // ★投资收益能力
  404. case SLH_NETASSET_PS: // 每股净资产
  405. *pValue = info.m_fNetasset_ps;
  406. return ( fabs(info.m_fNetasset_ps) > 1e-4 );
  407. case SLH_NETASSET_PS_REGULATE: // 调整每股净资产
  408. *pValue = info.m_fNetasset_ps_regulate;
  409. return ( fabs(info.m_fNetasset_ps_regulate) > 1e-4 );
  410. case SLH_EPS: // 每股收益
  411. *pValue = factor * info.m_fEps;
  412. return ( fabs(info.m_fEps) > 1e-4 );
  413. case SLH_EPS_DEDUCT: // 扣除后每股收益
  414. *pValue = factor * info.m_fEps_deduct;
  415. return ( fabs(info.m_fEps_deduct) > 1e-4 );
  416. case SLH_NET_PROFIT: // 净利润
  417. *pValue = factor * info.m_fNet_profit * 0.0001;
  418. return ( fabs(info.m_fNet_profit) > 1e-4 );
  419. case SLH_MAIN_PROFIT: // 主营业务利润
  420. *pValue = factor * info.m_fMain_profit * 0.0001;
  421. return ( fabs(info.m_fMain_profit) > 1e-4 );
  422. case SLH_TOTAL_PROFIT: // 利润总额
  423. *pValue = factor * info.m_fTotal_profit * 0.0001;
  424. return ( fabs(info.m_fTotal_profit) > 1e-4 );
  425. case SLH_PROFIT_INC: // 主营利润增长率
  426. *pValue = info.m_fProfit_inc;
  427. return TRUE;
  428. case SLH_INCOME_INC: // 主营收入增长率
  429. *pValue = info.m_fIncome_inc;
  430. return TRUE;
  431. case SLH_ASSET_INC: // 总资产增长率
  432. *pValue = info.m_fAsset_inc;
  433. return TRUE;
  434. case SLH_ANNGAINS_AVERAGE: // 年平均收益率
  435. *pValue = info.m_fYield_average;
  436. return ( fabs(STKLIB_DATA_INVALID - info.m_fYield_average) > 1e-4 );
  437. case SLH_ANNGAINS_STDDEV: // 收益标准差
  438. *pValue = info.m_fYield_stddev;
  439. return ( fabs(STKLIB_DATA_INVALID - info.m_fYield_stddev) > 1e-4 );
  440. case SLH_BETA: // β值
  441. *pValue = info.m_fBeite;
  442. return ( fabs(STKLIB_DATA_INVALID - info.m_fBeite) > 1e-4 );
  443. case SLH_SHARP: // 夏普风险指数
  444. return info.GetXiapu( pValue );
  445. default: ;
  446. }
  447. }
  448. else if( nVariantID >= SLH_USERDEFINE_BEGIN )
  449. {
  450. BOOL bNoValue = FALSE;
  451. if( pContainer && pContainer->GetVariantSaveValue( pValue, nVariantID, info, &bNoValue ) )
  452. return !bNoValue;
  453. CIndexContainer & container = AfxGetProfile().GetSListColumnsUser();
  454. CIndex & index = container.GetIndex( nVariantID );
  455. BOOL bSuccess = index.GetExpressResult( pValue, info, &bNoValue, NULL );
  456. if( pContainer && pValue )
  457. pContainer->SetVariantSaveValue( *pValue, nVariantID, info, bNoValue );
  458. return bSuccess;
  459. }
  460. return FALSE;
  461. }
  462. int dwordcmp( DWORD dw1, DWORD dw2 )
  463. {
  464. if( dw1 > dw2 )
  465. return 1;
  466. else if( dw1 < dw2 )
  467. return -1;
  468. else
  469. return 0;
  470. }
  471. int longcmp( LONG l1, LONG l2 )
  472. {
  473. if( l1 > l2 )
  474. return 1;
  475. else if( l1 < l2 )
  476. return -1;
  477. else
  478. return 0;
  479. }
  480. int doublecmp( double d1, double d2 )
  481. {
  482. if( d1 > d2 )
  483. return 1;
  484. else if( d1 < d2 )
  485. return -1;
  486. else
  487. return 0;
  488. }
  489. int AfxCompareVariantValue( int nVariantID, CStockInfo & info1, CStockInfo &info2,
  490.     CStockContainer * pContainer )
  491. {
  492. long x1 = 0, x2 = 0;
  493. double d1 = 0., d2 = 0.;
  494. BOOL bGet1 = FALSE, bGet2 = FALSE;
  495. switch( nVariantID )
  496. {
  497. case SLH_CODE: // 股票代码
  498. return strcmp( info1.GetStockCode(), info2.GetStockCode() );
  499. case SLH_NAME: // 股票名称
  500. return strcmp( info1.GetStockName(), info2.GetStockName() );
  501. // 技术数据
  502. case SLH_DATE: // 日期
  503. return dwordcmp( info1.m_datetech, info2.m_datetech );
  504. case SLH_DATE_BEGIN: // 上市日期
  505. return dwordcmp( info1.m_datebegin, info2.m_datebegin );
  506. // 主要基本指标
  507. case SLH_REPORTTYPE: // 报表类型
  508. return dwordcmp( info1.m_reporttype, info2.m_reporttype );
  509. case SLH_PE: // 市盈率
  510. case SLH_PNETASSET: // 市净率
  511. case SLH_PMAININCOME: // 市销率
  512. case SLH_RATIO_PCASH: // 价格净现金比
  513. bGet2 = AfxGetVariantValue( nVariantID, info2, &d2, pContainer );
  514. bGet1 = AfxGetVariantValue( nVariantID, info1, &d1, pContainer );
  515. if( !bGet2 && !bGet1 )
  516. return 0;
  517. if( !bGet2 ) return 1;
  518. if( !bGet1 ) return -1;
  519. if( d1 < 0 && d2 < 0 )
  520. return doublecmp( d1, d2 );
  521. if( d1 < 0 ) return 1;
  522. if( d2 < 0 ) return -1;
  523. return doublecmp( d1, d2 );
  524. case SLH_TRADE: // 行业
  525. return strcmp( info1.GetStockDomain(), info2.GetStockDomain() );
  526. case SLH_PROVINCE: // 省份
  527. return strcmp( info1.GetStockProvince(), info2.GetStockProvince() );
  528. default:
  529. bGet2 = AfxGetVariantValue( nVariantID, info2, &d2, pContainer );
  530. bGet1 = AfxGetVariantValue( nVariantID, info1, &d1, pContainer );
  531. if( !bGet2 && !bGet1 )
  532. return 0;
  533. if( !bGet2 ) return 1;
  534. if( !bGet1 ) return -1;
  535. return doublecmp( d1, d2 );
  536. }
  537. return 0;
  538. }
  539. CSPString AfxGetVariantDispString(UINT nVariantID, CStockInfo &info,
  540. CStockContainer * pContainer )
  541. {
  542. CSPString strTemp;
  543. int x = 0;
  544. double dTemp = 0;
  545. switch( nVariantID )
  546. {
  547. case SLH_CODE: // 股票代码
  548. strTemp = info.GetStockCode();
  549. break;
  550. case SLH_NAME: // 股票名称
  551. strTemp = info.GetStockName();
  552. break;
  553. // 技术数据
  554. case SLH_DATE: // 日期
  555. if( 0 != info.m_datetech )
  556. strTemp.Format( "%.2d/%.2d/%.2d", (info.m_datetech/10000)%100, (info.m_datetech%10000)/100, info.m_datetech%100 );
  557. break;
  558. case SLH_DATE_BEGIN: // 上市日期
  559. if( 0 != info.m_datebegin )
  560. strTemp.Format( "%.2d/%.2d/%.2d", (info.m_datebegin/10000)%100, (info.m_datebegin%10000)/100, info.m_datebegin%100 );
  561. break;
  562. case SLH_LASTCLOSE: // 昨收
  563. case SLH_OPEN: // 今开
  564. case SLH_CLOSE: // 收盘价
  565. case SLH_HIGH: // 最高价
  566. case SLH_LOW: // 最低价
  567. case SLH_AVERAGE: // 均价
  568. case SLH_DIFF: // 涨跌
  569. case SLH_BUYPRICE3: // 买价三
  570. case SLH_BUYPRICE2: // 买价二
  571. case SLH_BUYPRICE1: // 买价一
  572. case SLH_SELLPRICE1: // 卖价一
  573. case SLH_SELLPRICE2: // 卖价二
  574. case SLH_SELLPRICE3: // 卖价三
  575. if( AfxGetVariantValue( nVariantID, info, &dTemp, pContainer ) )
  576. {
  577. CSPString strPriceFmt;
  578. strPriceFmt.Format( "%%.%df", info.DigitBit() );
  579. strTemp.Format( strPriceFmt, dTemp );
  580. }
  581. break;
  582. case SLH_VOLUME: // 成交量
  583. case SLH_AMOUNT: // 成交额
  584. case SLH_VOLUP: // 外盘
  585. case SLH_VOLDOWN: // 内盘
  586. case SLH_SELLBUYDIFF: // 委量差
  587. case SLH_BUYVOLUME3: // 买量三
  588. case SLH_BUYVOLUME2: // 买量二
  589. case SLH_BUYVOLUME1: // 买量一
  590. case SLH_SELLVOLUME1: // 卖量一
  591. case SLH_SELLVOLUME2: // 卖量二
  592. case SLH_SELLVOLUME3: // 卖量三
  593. case SLH_MARKETVALUE: // 总市值
  594. case SLH_MARKETVALUEA: // A股市值
  595. case SLH_MARKETVALUEB: // B股市值
  596. case SLH_SHARE_COUNT_TOTAL: // 总股本
  597. case SLH_SHARE_COUNT_A: // 流通A股
  598. case SLH_SHARE_COUNT_B: // 流通B股
  599. case SLH_SHARE_COUNT_H: // 流通H股
  600. case SLH_SHARE_COUNT_NATIONAL: // 国有股
  601. case SLH_SHARE_COUNT_CORP: // 法人股
  602. if( AfxGetVariantValue( nVariantID, info, &dTemp, pContainer ) )
  603. strTemp.Format( "%.0f", dTemp );
  604. break;
  605. case SLH_MAIN_INCOME: // 主营业务收入
  606. case SLH_ASSET: // 总资产
  607. case SLH_NET_PROFIT: // 净利润
  608. case SLH_MAIN_PROFIT: // 主营业务利润
  609. case SLH_TOTAL_PROFIT: // 利润总额
  610. if( AfxGetVariantValue( nVariantID, info, &dTemp, pContainer ) )
  611. strTemp.Format( "%.0f", dTemp );
  612. break;
  613. case SLH_REPORTTYPE: // 报表类型
  614. strTemp = AfxGetReportTypeString( info.m_reporttype );
  615. break;
  616. case SLH_TRADE: // 行业
  617. strTemp = info.GetStockDomain();
  618. break;
  619. case SLH_PROVINCE: // 省份
  620. strTemp = info.GetStockProvince();
  621. break;
  622. default:
  623. if( AfxGetVariantValue( nVariantID, info, &dTemp, pContainer ) )
  624. strTemp.Format( "%.2f", dTemp );
  625. }
  626. if( strTemp.IsEmpty() )
  627. strTemp = "-";
  628. return strTemp;
  629. }
  630. COLORREF AfxGetVariantColor( UINT nVariantID, CStockInfo &info )
  631. {
  632. int x = 0;
  633. double dTemp = 0;
  634. COLORREF crText = AfxGetProfile().GetColor(CColorClass::clrPlane);
  635. if( nVariantID < SLH_MIN || nVariantID > SLH_MAX )
  636. return crText;
  637. switch( nVariantID )
  638. {
  639. case SLH_CODE: // 股票代码
  640. crText = AfxGetProfile().GetColor(CColorClass::clrTitle);
  641. break;
  642. case SLH_NAME: // 股票名称
  643. crText = AfxGetProfile().GetColor(CColorClass::clrTitle);
  644. break;
  645. case SLH_OPEN: // 今开
  646. if( info.m_fOpen > info.m_fLast )
  647. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  648. else if( info.m_fOpen < info.m_fLast )
  649. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  650. break;
  651. case SLH_CLOSE: // 收盘价
  652. if( info.m_fClose > info.m_fLast )
  653. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  654. else if( info.m_fClose < info.m_fLast )
  655. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  656. break;
  657. case SLH_HIGH: // 最高价
  658. if( info.m_fHigh > info.m_fLast )
  659. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  660. else if( info.m_fHigh < info.m_fLast )
  661. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  662. break;
  663. case SLH_LOW: // 最低价
  664. if( info.m_fLow > info.m_fLast )
  665. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  666. else if( info.m_fLow < info.m_fLast )
  667. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  668. break;
  669. case SLH_AVERAGE: // 均价
  670. if( info.GetAverage( &dTemp ) )
  671. {
  672. if( dTemp - info.m_fLast > 1e-4 )
  673. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  674. else if( dTemp - info.m_fLast < -1e-4 )
  675. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  676. }
  677. break;
  678. case SLH_DIFF: // 涨跌
  679. if( info.GetDiff( &dTemp, info.m_datetech, AfxGetProfile().GetDiffPercentDays() ) )
  680. {
  681. if( dTemp > 1e-4 )
  682. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  683. else if( dTemp < -1e-4 )
  684. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  685. }
  686. break;
  687. case SLH_DIFFPERCENT: // 涨幅
  688. if( info.GetDiffPercent( &dTemp, info.m_datetech, AfxGetProfile().GetDiffPercentDays() ) )
  689. {
  690. if( dTemp > 1e-4 )
  691. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  692. else if( dTemp < -1e-4 )
  693. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  694. }
  695. break;
  696. case SLH_VOLUME: // 成交量
  697. crText = AfxGetProfile().GetColor(CColorClass::clrText);
  698. break;
  699. case SLH_AMOUNT: // 成交额
  700. crText = AfxGetProfile().GetColor(CColorClass::clrText);
  701. break;
  702. case SLH_VOLUP: // 外盘
  703. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  704. break;
  705. case SLH_VOLDOWN: // 内盘
  706. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  707. break;
  708. case SLH_DIFFPERCENT_MIN5: // 五分钟涨幅%
  709. if( info.GetDiffPercentMin5( &dTemp ) )
  710. {
  711. if( dTemp > 1e-4 )
  712. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  713. else if( dTemp < -1e-4 )
  714. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  715. }
  716. break;
  717. case SLH_SELLBUYRATIO: // 委比%
  718. case SLH_SELLBUYDIFF: // 委量差
  719. if( info.GetSellBuyRatio( &dTemp, NULL ) )
  720. {
  721. if( dTemp > 1e-4 )
  722. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  723. else if( dTemp < -1e-4 )
  724. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  725. }
  726. break;
  727. case SLH_BUYPRICE3: // 买价三
  728. if( info.m_fBuyPrice[2] > info.m_fLast )
  729. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  730. else if( info.m_fBuyPrice[2] < info.m_fLast )
  731. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  732. break;
  733. case SLH_BUYPRICE2: // 买价二
  734. if( info.m_fBuyPrice[1] > info.m_fLast )
  735. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  736. else if( info.m_fBuyPrice[1] < info.m_fLast )
  737. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  738. break;
  739. case SLH_BUYPRICE1: // 买价一
  740. if( info.m_fBuyPrice[0] > info.m_fLast )
  741. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  742. else if( info.m_fBuyPrice[0] < info.m_fLast )
  743. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  744. break;
  745. case SLH_SELLPRICE1: // 卖价一
  746. if( info.m_fSellPrice[0] > info.m_fLast )
  747. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  748. else if( info.m_fSellPrice[0] < info.m_fLast )
  749. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  750. break;
  751. case SLH_SELLPRICE2: // 卖价二
  752. if( info.m_fSellPrice[1] > info.m_fLast )
  753. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  754. else if( info.m_fSellPrice[1] < info.m_fLast )
  755. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  756. break;
  757. case SLH_SELLPRICE3: // 卖价三
  758. if( info.m_fSellPrice[2] > info.m_fLast )
  759. crText = AfxGetProfile().GetColor(CColorClass::clrRise);
  760. else if( info.m_fSellPrice[2] < info.m_fLast )
  761. crText = AfxGetProfile().GetColor(CColorClass::clrFall);
  762. break;
  763. case SLH_BUYVOLUME3: // 买量三
  764. case SLH_BUYVOLUME2: // 买量二
  765. case SLH_BUYVOLUME1: // 买量一
  766. case SLH_SELLVOLUME1: // 卖量一
  767. case SLH_SELLVOLUME2: // 卖量二
  768. case SLH_SELLVOLUME3: // 卖量三
  769. case SLH_SCOPE:
  770. crText = AfxGetProfile().GetColor(CColorClass::clrPlane);
  771. break;
  772. // 主要基本指标
  773. case SLH_REPORTTYPE: // 报表类型
  774. crText = AfxGetProfile().GetColor(CColorClass::clrTitle);
  775. break;
  776. case SLH_PE: // 市盈率
  777. case SLH_PNETASSET: // 市净率
  778. case SLH_PMAININCOME: // 市销率
  779. case SLH_RATIO_PCASH: // 价格净现金比
  780. case SLH_RATIO_CURRENCY: // 流通率
  781. case SLH_RATIO_CHANGEHAND: // 换手率
  782. case SLH_RATIO_VOLUME: // 量比
  783. case SLH_RS: // 相对强度
  784. crText = AfxGetProfile().GetColor(CColorClass::clrPlane);
  785. break;
  786. case SLH_MARKETVALUE: // 总市值
  787. case SLH_MARKETVALUEA: // A股市值
  788. case SLH_MARKETVALUEB: // B股市值
  789. crText = AfxGetProfile().GetColor(CColorClass::clrText);
  790. break;
  791. // ★偿债能力
  792. case SLH_RATIO_LIQUIDITY: // 流动比率
  793. case SLH_RATIO_QUICK: // 速动比率
  794. case SLH_VELOCITY_RECEIVABLES: // 应收帐款周率
  795. crText = AfxGetProfile().GetColor(CColorClass::clrPlane);
  796. break;
  797. // ★经营能力
  798. case SLH_VELOCITY_MERCHANDISE: // 存货周转率
  799. crText = AfxGetProfile().GetColor(CColorClass::clrPlane);
  800. break;
  801. case SLH_MAIN_INCOME: // 主营业务收入
  802. case SLH_CASH_PS: // 每股净现金流量
  803. crText = AfxGetProfile().GetColor(CColorClass::clrText);
  804. break;
  805. // ★盈利能力
  806. case SLH_PROFIT_MARGIN: // 主营业务利润率
  807. case SLH_NETASSET_YIELD: // 净资产收益率
  808. crText = AfxGetProfile().GetColor(CColorClass::clrPlane);
  809. break;
  810. // ★资本结构
  811. case SLH_SHARE_COUNT_TOTAL: // 总股本
  812. case SLH_SHARE_COUNT_A: // 流通A股
  813. case SLH_SHARE_COUNT_B: // 流通B股
  814. case SLH_SHARE_COUNT_H: // 流通H股
  815. case SLH_SHARE_COUNT_NATIONAL: // 国有股
  816. case SLH_SHARE_COUNT_CORP: // 法人股
  817. case SLH_PROFIT_PSUD: // 每股未分配利润
  818. case SLH_ASSET: // 总资产
  819. crText = AfxGetProfile().GetColor(CColorClass::clrText);
  820. break;
  821. case SLH_RATIO_HOLDERRIGHT: // 股东权益比率
  822. case SLH_RATIO_LONGDEBT: // 长期负债率
  823. case SLH_RATIO_DEBT: // 资产负债率
  824. crText = AfxGetProfile().GetColor(CColorClass::clrPlane);
  825. break;
  826. // ★投资收益能力
  827. case SLH_NETASSET_PS: // 每股净资产
  828. case SLH_NETASSET_PS_REGULATE: // 调整每股净资产
  829. case SLH_EPS: // 每股收益
  830. case SLH_EPS_DEDUCT: // 扣除后每股收益
  831. case SLH_NET_PROFIT: // 净利润
  832. case SLH_MAIN_PROFIT: // 主营业务利润
  833. case SLH_TOTAL_PROFIT: // 利润总额
  834. crText = AfxGetProfile().GetColor(CColorClass::clrText);
  835. break;
  836. case SLH_PROFIT_INC: // 主营利润增长率
  837. case SLH_INCOME_INC: // 主营收入增长率
  838. case SLH_ASSET_INC: // 总资产增长率
  839. case SLH_ANNGAINS_AVERAGE: // 年平均收益率
  840. case SLH_ANNGAINS_STDDEV: // 收益标准差
  841. case SLH_BETA: // β值
  842. case SLH_SHARP: // 夏普风险指数
  843. crText = AfxGetProfile().GetColor(CColorClass::clrPlane);
  844. break;
  845. case SLH_TRADE: // 行业
  846. case SLH_PROVINCE: // 省份
  847. crText = AfxGetProfile().GetColor(CColorClass::clrTitle);
  848. break;
  849. default: ;
  850. }
  851. return crText;
  852. }
  853. //////////////////////////////////////////////////////////////////////
  854. // CExpress
  855. CExpress::CExpress( )
  856. {
  857. m_bIsModified = FALSE;
  858. m_nReserved = 0;
  859. }
  860. CExpress::CExpress( const CExpress &src )
  861. {
  862. *this = src;
  863. }
  864. CExpress::~CExpress( )
  865. {
  866. }
  867. CExpress &CExpress::operator = ( const CExpress &src )
  868. {
  869. m_strExpressOrg = src.m_strExpressOrg;
  870. m_strExpress = src.m_strExpress;
  871. m_bIsModified = src.m_bIsModified;
  872. m_nReserved = src.m_nReserved;
  873. return *this;
  874. }
  875. void CExpress::Serialize( CSPArchive &ar )
  876. {
  877. if( ar.IsStoring() )
  878. {
  879. ar << m_strExpressOrg;
  880. ar << m_nReserved;
  881. }
  882. else
  883. {
  884. ar >> m_strExpressOrg;
  885. ar >> m_nReserved;
  886. m_bIsModified = TRUE;
  887. m_strExpress = m_strExpressOrg;
  888. }
  889. }
  890. BOOL CExpress::SetExpressString( CSPString strExpressOrg )
  891. {
  892. m_strExpressOrg = strExpressOrg;
  893. m_bIsModified = TRUE;
  894. m_strExpress = m_strExpressOrg;
  895. return TRUE;
  896. }
  897. CSPString CExpress::GetExpressString( )
  898. {
  899. return m_strExpressOrg;
  900. }
  901. CSPString CExpress::GetLastErrorMsg( )
  902. {
  903. if( m_parser.IsError() )
  904. {
  905. int nErrorCode = m_parser.GetErrorCode( );
  906. switch( nErrorCode )
  907. {
  908. case MP_ErrParserStack: return express_errparserstack; break;
  909. case MP_ErrBadRange: return express_errbadrange; break;
  910. case MP_ErrExpression: return express_errexpression; break;
  911. case MP_ErrOperator: return express_erroperator; break;
  912. case MP_ErrOpenParen: return express_erropenparen; break;
  913. case MP_ErrOpCloseParen:return express_errcloseparen; break;
  914. case MP_ErrInvalidNum: return express_errinvalidnum; break;
  915. case MP_ErrMath: return express_errmath; break;
  916. default: return express_errunknown;
  917. }
  918. }
  919. return "";
  920. }
  921. BOOL CExpress::GetExpressResult( double * pResult, BOOL * pError )
  922. {
  923. if( !PreCompile( ) )
  924. {
  925. if( pError ) *pError = TRUE;
  926. return FALSE;
  927. }
  928. if( !InitParser( ) )
  929. {
  930. if( pError ) *pError = TRUE;
  931. return FALSE;
  932. }
  933. m_parser.Parse( );
  934. if( pError )
  935. *pError = m_parser.IsError( );
  936. if( m_parser.IsError() )
  937. return FALSE;
  938. if( pResult )
  939. *pResult = m_parser.GetResult( );
  940. return TRUE;
  941. }
  942. // 去掉空格、冒号、回车、换行等字符
  943. BOOL CExpress::PreCompile( )
  944. {
  945. if( m_bIsModified )
  946. {
  947. CSPString sTemp = m_strExpress;
  948. m_strExpress.Empty();
  949. for( int i=0; i<sTemp.GetLength(); i++ )
  950. {
  951. TCHAR ch = sTemp[i];
  952. if( ':' != ch && ' ' != ch && 't' != ch 
  953. && 'r' != ch && 'n' != ch )
  954. m_strExpress += ch;
  955. }
  956. m_bIsModified = FALSE;
  957. }
  958. return m_strExpress.GetLength() > 0;
  959. }
  960. // 初始化m_parser变量
  961. BOOL CExpress::InitParser( )
  962. {
  963. m_parser.SetParserString( m_strExpress );
  964. m_parser.InitVarMap( 10 );
  965. /* examples
  966. for( int i=0; i<nCount; i++ )
  967. {
  968. m_parser.AddVar( dValue, strName );
  969. }
  970. */
  971. return TRUE;
  972. }
  973. /////////////////////////////////////////////////////////////////////////////
  974. // CIndex
  975. CIndex::CIndex( )
  976. {
  977. m_nID = SLH_INVALID;
  978. }
  979. CIndex::CIndex( const CIndex &src )
  980. {
  981. *this = src;
  982. }
  983. CIndex::~CIndex( )
  984. {
  985. }
  986. CIndex &CIndex::operator = ( const CIndex &src )
  987. {
  988. *((CExpress *)this) = *((CExpress *)&src);
  989. m_nID = src.m_nID;
  990. m_strName = src.m_strName;
  991. m_strDescript = src.m_strDescript;
  992. m_strReserved = src.m_strReserved;
  993. m_adwVariant.Copy( src.m_adwVariant );
  994. return *this;
  995. }
  996. void CIndex::Serialize( CSPArchive & ar )
  997. {
  998. CExpress::Serialize( ar );
  999. if( ar.IsStoring() )
  1000. {
  1001. ar << m_nID;
  1002. ar << m_strName;
  1003. ar << m_strDescript;
  1004. ar << m_strReserved;
  1005. }
  1006. else
  1007. {
  1008. ar >> m_nID;
  1009. ar >> m_strName;
  1010. ar >> m_strDescript;
  1011. ar >> m_strReserved;
  1012. }
  1013. }
  1014. BOOL CIndex::IsInvalidID( )
  1015. {
  1016. return SLH_INVALID == m_nID;
  1017. }
  1018. BOOL CIndex::SetNextID( )
  1019. {
  1020. CIndexContainer &container = AfxGetProfile().GetSListColumnsUser();
  1021. m_nID = container.GetNextID( );
  1022. return TRUE;
  1023. }
  1024. BOOL CIndex::PreCompile( )
  1025. {
  1026. if( m_bIsModified )
  1027. {
  1028. // 缓存变量ID
  1029. m_adwVariant.RemoveAll();
  1030. // 将中文变量名替换成英文名
  1031. CSPStringArray astrVarName;
  1032. if( AfxGetVariantNameArray(astrVarName,FALSE) )
  1033. {
  1034. CSPDWordArray adwSortID;
  1035. astrVarName.GetSortIDArray( adwSortID );
  1036. for( int i=adwSortID.GetSize()-1; i>=0; i-- )
  1037. {
  1038. UINT nVariantID = adwSortID.GetAt(i);
  1039. if( strlen(slh_data_array[nVariantID].varname) > 0 )
  1040. {
  1041. if( m_strExpress.Replace( AfxGetVariantName(nVariantID,FALSE), slh_data_array[nVariantID].varname ) > 0 )
  1042. m_adwVariant.Add(nVariantID);
  1043. }
  1044. }
  1045. }
  1046. if( !CExpress::PreCompile( ) )
  1047. return FALSE;
  1048. m_bIsModified = FALSE;
  1049. }
  1050. return m_strExpress.GetLength() > 0;
  1051. }
  1052. // 初始化m_parser变量
  1053. BOOL CIndex::InitParser( CStockInfo &info, BOOL *pVariantNoValue )
  1054. {
  1055. if( pVariantNoValue )
  1056. *pVariantNoValue = FALSE;
  1057. m_parser.SetParserString( m_strExpress );
  1058. m_parser.InitVarMap( SLH_MAX );
  1059. for( int i=0; i<m_adwVariant.GetSize(); i++ )
  1060. {
  1061. UINT nVariantID = m_adwVariant.ElementAt(i);
  1062. // 加入变量及其值
  1063. double value = 1.0;
  1064. if( !AfxGetVariantValue( nVariantID, info, &value, NULL ) && pVariantNoValue )
  1065. *pVariantNoValue = TRUE;
  1066. m_parser.AddVar( value, slh_data_array[nVariantID].varname );
  1067. }
  1068. return TRUE;
  1069. }
  1070. BOOL CIndex::CheckExpressValid( )
  1071. {
  1072. CStockInfo info;
  1073. BOOL bError = FALSE;
  1074. double temp = 0;
  1075. GetExpressResult( &temp, info, NULL, &bError );
  1076. return !bError;
  1077. }
  1078. BOOL CIndex::GetExpressResult( double * pResult, CStockInfo &info, BOOL *pVariantNoValue, BOOL * pError )
  1079. {
  1080. if( !PreCompile( ) )
  1081. {
  1082. if( pVariantNoValue ) *pVariantNoValue = FALSE;
  1083. if( pError ) *pError = TRUE;
  1084. return FALSE;
  1085. }
  1086. BOOL bVariantNoValue = FALSE;
  1087. if( !InitParser( info, &bVariantNoValue ) )
  1088. {
  1089. if( pVariantNoValue ) *pVariantNoValue = bVariantNoValue;
  1090. if( pError ) *pError = TRUE;
  1091. return FALSE;
  1092. }
  1093. if( pVariantNoValue ) *pVariantNoValue = bVariantNoValue;
  1094. m_parser.Parse( );
  1095. if( pError )
  1096. *pError = m_parser.IsError( );
  1097. if( m_parser.IsError() )
  1098. return FALSE;
  1099. if( bVariantNoValue )
  1100. return FALSE;
  1101. if( pResult )
  1102. *pResult = m_parser.GetResult( );
  1103. return TRUE;
  1104. }
  1105. /////////////////////////////////////////////////////////////////////////////
  1106. // CIndexContainer
  1107. CIndexContainer::CIndexContainer( )
  1108. {
  1109. }
  1110. CIndexContainer::~CIndexContainer( )
  1111. {
  1112. RemoveAll( );
  1113. }
  1114. void CIndexContainer::RemoveIndex( UINT nID )
  1115. {
  1116. for( int i=0; i<GetSize(); i++ )
  1117. {
  1118. CIndex & col = ElementAt(i);
  1119. if( nID == col.m_nID )
  1120. {
  1121. RemoveAt( i );
  1122. return;
  1123. }
  1124. }
  1125. }
  1126. CIndex & CIndexContainer::GetIndex( UINT nID )
  1127. {
  1128. static CIndex idx;
  1129. for( int i=0; i<GetSize(); i++ )
  1130. {
  1131. CIndex & col = ElementAt(i);
  1132. if( nID == col.m_nID )
  1133. return col;
  1134. }
  1135. return idx;
  1136. }
  1137. CIndex & CIndexContainer::GetIndex( CSPString strName )
  1138. {
  1139. static CIndex idx;
  1140. for( int i=0; i<GetSize(); i++ )
  1141. {
  1142. CIndex & index = ElementAt(i);
  1143. if( 0 == strName.Compare( index.m_strName ) )
  1144. return index;
  1145. }
  1146. return idx;
  1147. }
  1148. BOOL CIndexContainer::EditIndex( CIndex &indexEdit )
  1149. {
  1150. for( int i=0; i<GetSize(); i++ )
  1151. {
  1152. CIndex & index = ElementAt(i);
  1153. if( indexEdit.m_nID == index.m_nID )
  1154. {
  1155. index = indexEdit;
  1156. return TRUE;
  1157. }
  1158. }
  1159. return FALSE;
  1160. }
  1161. UINT CIndexContainer::GetNextID( )
  1162. {
  1163. UINT nID = SLH_USERDEFINE_BEGIN;
  1164. for( int i=0; i<GetSize(); i++ )
  1165. {
  1166. CIndex & index = ElementAt(i);
  1167. if( index.m_nID >= nID )
  1168. {
  1169. nID = index.m_nID + 1;
  1170. }
  1171. }
  1172. return nID;
  1173. }
  1174. void CIndexContainer::FileSerialize( CSPArchive & ar )
  1175. {
  1176. if( ar.IsStoring() )
  1177. {
  1178. ar << GetSize();
  1179. for( int i=0; i<GetSize(); i++ )
  1180. {
  1181. CIndex & col = ElementAt(i);
  1182. col.Serialize( ar );
  1183. }
  1184. }
  1185. else
  1186. {
  1187. int size;
  1188. ar >> size;
  1189. SetSize( size );
  1190. for( int i=0; i<size; i++ )
  1191. {
  1192. CIndex col;
  1193. col.Serialize( ar );
  1194. SetAt( i, col );
  1195. }
  1196. }
  1197. }