QuoteItemBase.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. using GalaSoft.MvvmLight;
  2. using System.Windows.Media;
  3. namespace Muchinfo.MTPClient.Data.Model.QuoteItem
  4. {
  5. /// <summary>
  6. /// QuoteItemBase类
  7. /// </summary>
  8. public class QuoteItemBase : ObservableObject
  9. {
  10. #region Fields
  11. protected static readonly Brush AscBrush = new SolidColorBrush(Color.FromRgb(255, 50, 50));
  12. protected static readonly Brush DecBrush = new SolidColorBrush(Color.FromRgb(0, 255, 0));
  13. protected static readonly Brush DefaultBrush = new SolidColorBrush(Colors.White);
  14. protected static readonly string DefaultString = "-";
  15. /// <summary>
  16. /// 分类
  17. /// </summary>
  18. private string _sort;
  19. /// <summary>
  20. /// 代码
  21. /// </summary>
  22. private int _code;
  23. /// <summary>
  24. /// 现价
  25. /// </summary>
  26. private decimal _currentPrice;
  27. /// <summary>
  28. /// 时间
  29. /// </summary>
  30. private string _date;
  31. /// <summary>
  32. /// 最高
  33. /// </summary>
  34. private decimal _high;
  35. /// <summary>
  36. /// 昨收
  37. /// </summary>
  38. private decimal _lastClose;
  39. /// <summary>
  40. /// 最低
  41. /// </summary>
  42. private decimal _low;
  43. /// <summary>
  44. /// 市场
  45. /// </summary>
  46. private string _market;
  47. /// <summary>
  48. /// 名称
  49. /// </summary>
  50. private string _name;
  51. /// <summary>
  52. /// 今开
  53. /// </summary>
  54. private decimal _open;
  55. #endregion Fields
  56. #region Properties
  57. #region Public Properties
  58. /// <summary>
  59. /// 振幅 ((最高-最低)/昨收)
  60. /// </summary>
  61. public decimal Amplitude
  62. {
  63. get
  64. {
  65. if (LastClose != 0)
  66. {
  67. return (High - Low) / LastClose;
  68. }
  69. else
  70. {
  71. return (High - Low);
  72. }
  73. }
  74. }
  75. /// <summary>
  76. /// 振幅颜色
  77. /// </summary>
  78. public Brush AmplitudeColor
  79. {
  80. get
  81. {
  82. return GetBrush(Amplitude, 0);
  83. }
  84. }
  85. /// <summary>
  86. /// Gets the amplitude display.
  87. /// </summary>
  88. public string AmplitudeDisplay
  89. {
  90. get
  91. {
  92. return Amplitude.ToString("P2");
  93. }
  94. }
  95. /// <summary>
  96. /// 分类
  97. /// </summary>
  98. public string Sort
  99. {
  100. get
  101. {
  102. return _sort;
  103. }
  104. set
  105. {
  106. Set(() => Sort, ref _sort, value);
  107. }
  108. }
  109. /// <summary>
  110. /// 代码
  111. /// </summary>
  112. public int Code
  113. {
  114. get
  115. {
  116. return _code;
  117. }
  118. set
  119. {
  120. Set(() => Code, ref _code, value);
  121. }
  122. }
  123. /// <summary>
  124. /// 现价
  125. /// </summary>
  126. public decimal CurrentPrice
  127. {
  128. get
  129. {
  130. return _currentPrice;
  131. }
  132. set
  133. {
  134. Set(() => CurrentPrice, ref _currentPrice, value);
  135. ////RaisePropertyChanged(() => IncreasePercent);
  136. RaisePropertyChanged(() => IncreasePercentDisplay);
  137. RaisePropertyChanged(() => IncreaseValue);
  138. RaisePropertyChanged(() => IncreasePercentColor);
  139. RaisePropertyChanged(() => IncreaseValueColor);
  140. RaisePropertyChanged(() => CurrentPriceColor);
  141. }
  142. }
  143. /// <summary>
  144. /// 现价颜色
  145. /// </summary>
  146. public Brush CurrentPriceColor
  147. {
  148. get
  149. {
  150. return GetBrush(_currentPrice, _lastClose);
  151. }
  152. }
  153. /// <summary>
  154. /// 时间
  155. /// </summary>
  156. public string Date
  157. {
  158. get
  159. {
  160. return _date;
  161. }
  162. set
  163. {
  164. Set(() => Date, ref _date, value);
  165. }
  166. }
  167. /// <summary>
  168. /// Gets the color of the code.
  169. /// </summary>
  170. public Brush DefaultColor
  171. {
  172. get
  173. {
  174. return DefaultBrush;
  175. }
  176. }
  177. /// <summary>
  178. /// 交易所代码
  179. /// </summary>
  180. public string Exchange
  181. {
  182. get;
  183. set;
  184. }
  185. /// <summary>
  186. /// 最高
  187. /// </summary>
  188. public decimal High
  189. {
  190. get
  191. {
  192. return _high;
  193. }
  194. set
  195. {
  196. Set(() => High, ref _high, value);
  197. RaisePropertyChanged(() => AmplitudeDisplay);
  198. RaisePropertyChanged(() => AmplitudeColor);
  199. }
  200. }
  201. /// <summary>
  202. /// 最高颜色
  203. /// </summary>
  204. public Brush HighColor
  205. {
  206. get
  207. {
  208. return GetBrush(_high, _lastClose);
  209. }
  210. }
  211. /// <summary>
  212. /// 涨幅%((现价-昨收)/昨收)
  213. /// </summary>
  214. public decimal IncreasePercent
  215. {
  216. get
  217. {
  218. if (LastClose != 0)
  219. {
  220. return (CurrentPrice - LastClose) / LastClose;
  221. }
  222. return (CurrentPrice - LastClose);
  223. }
  224. }
  225. /// <summary>
  226. /// 涨幅%颜色
  227. /// </summary>
  228. public Brush IncreasePercentColor
  229. {
  230. get
  231. {
  232. return GetBrush(IncreasePercent, 0);
  233. }
  234. }
  235. /// <summary>
  236. /// Gets the increase percent display.
  237. /// </summary>
  238. public string IncreasePercentDisplay
  239. {
  240. get
  241. {
  242. return IncreasePercent.ToString("P2");
  243. }
  244. }
  245. /// <summary>
  246. /// 涨跌(现价-昨收)
  247. /// </summary>
  248. public decimal IncreaseValue
  249. {
  250. get
  251. {
  252. var value = (CurrentPrice - LastClose);
  253. return decimal.Parse(value.ToString("#.00"));
  254. }
  255. }
  256. /// <summary>
  257. /// 涨跌颜色
  258. /// </summary>
  259. public Brush IncreaseValueColor
  260. {
  261. get
  262. {
  263. return GetBrush(IncreaseValue, 0);
  264. }
  265. }
  266. /// <summary>
  267. /// 昨收
  268. /// </summary>
  269. public decimal LastClose
  270. {
  271. get
  272. {
  273. return _lastClose;
  274. }
  275. set
  276. {
  277. Set(() => LastClose, ref _lastClose, value);
  278. }
  279. }
  280. /// <summary>
  281. /// 最低
  282. /// </summary>
  283. public decimal Low
  284. {
  285. get
  286. {
  287. return _low;
  288. }
  289. set
  290. {
  291. Set(() => Low, ref _low, value);
  292. RaisePropertyChanged(() => AmplitudeDisplay);
  293. RaisePropertyChanged(() => AmplitudeColor);
  294. }
  295. }
  296. /// <summary>
  297. /// 最低颜色
  298. /// </summary>
  299. public Brush LowColor
  300. {
  301. get
  302. {
  303. return GetBrush(_low, 0);
  304. }
  305. }
  306. /// <summary>
  307. /// 市场
  308. /// </summary>
  309. public string Market
  310. {
  311. get
  312. {
  313. return _market;
  314. }
  315. set
  316. {
  317. Set(() => Market, ref _market, value);
  318. }
  319. }
  320. /// <summary>
  321. /// 名称
  322. /// </summary>
  323. public string Name
  324. {
  325. get
  326. {
  327. return _name;
  328. }
  329. set
  330. {
  331. Set(() => Name, ref _name, value);
  332. }
  333. }
  334. /// <summary>
  335. /// Gets the color of the name.
  336. /// </summary>
  337. public Brush NameColor
  338. {
  339. get
  340. {
  341. return new SolidColorBrush(Colors.Yellow);
  342. }
  343. }
  344. /// <summary>
  345. /// 今开
  346. /// </summary>
  347. public decimal Open
  348. {
  349. get
  350. {
  351. return _open;
  352. }
  353. set
  354. {
  355. Set(() => Open, ref _open, value);
  356. RaisePropertyChanged(() => OpenColor);
  357. }
  358. }
  359. /// <summary>
  360. /// 今开颜色
  361. /// </summary>
  362. public Brush OpenColor
  363. {
  364. get
  365. {
  366. return GetBrush(_open, _lastClose);
  367. }
  368. }
  369. #endregion Public Properties
  370. #endregion Properties
  371. #region Methods
  372. #region Public Methods
  373. /// <summary>
  374. /// 更新对象属性值(只更新需要字段)
  375. /// </summary>
  376. /// <param name="item">The item.</param>
  377. public virtual void UpdateFrom(QuoteItemBase item)
  378. {
  379. //只更新需要字段
  380. if (!this.CurrentPrice.Equals(item.CurrentPrice))
  381. {
  382. this.CurrentPrice = item.CurrentPrice;
  383. }
  384. if (!this.High.Equals(item.High))
  385. {
  386. this.High = item.High;
  387. }
  388. if (!this.Low.Equals(item.Low))
  389. {
  390. this.Low = item.Low;
  391. }
  392. }
  393. #endregion Public Methods
  394. #region Protected Methods
  395. /// <summary>
  396. /// Gets the brush.
  397. /// </summary>
  398. /// <param name="source">The source.</param>
  399. /// <param name="destination">The destination.</param>
  400. /// <returns>Brush.</returns>
  401. protected Brush GetBrush(decimal source, decimal destination)
  402. {
  403. if (source > destination)
  404. {
  405. return AscBrush;
  406. }
  407. if (source < destination)
  408. {
  409. return DecBrush;
  410. }
  411. return DefaultBrush;
  412. }
  413. #endregion Protected Methods
  414. #endregion Methods
  415. }
  416. }