PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/StockTrader RI/Desktop/StockTraderRI.Modules.Position/PositionSummary/PositionSummaryItem.cs

#
C# | 132 lines | 101 code | 15 blank | 16 comment | 6 complexity | e2cc6b2aaed75e387676f2f22b0af346 MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. using Microsoft.Practices.Prism.ViewModel;
  18. namespace StockTraderRI.Modules.Position.PositionSummary
  19. {
  20. public class PositionSummaryItem : NotificationObject
  21. {
  22. public PositionSummaryItem(string tickerSymbol, decimal costBasis, long shares, decimal currentPrice)
  23. {
  24. TickerSymbol = tickerSymbol;
  25. CostBasis = costBasis;
  26. Shares = shares;
  27. CurrentPrice = currentPrice;
  28. }
  29. private string _tickerSymbol;
  30. public string TickerSymbol
  31. {
  32. get
  33. {
  34. return _tickerSymbol;
  35. }
  36. set
  37. {
  38. if (value == null)
  39. {
  40. value = string.Empty;
  41. }
  42. if (!value.Equals(_tickerSymbol))
  43. {
  44. _tickerSymbol = value;
  45. this.RaisePropertyChanged(() => this.TickerSymbol);
  46. }
  47. }
  48. }
  49. private decimal _costBasis;
  50. public decimal CostBasis
  51. {
  52. get
  53. {
  54. return _costBasis;
  55. }
  56. set
  57. {
  58. if (!value.Equals(_costBasis))
  59. {
  60. _costBasis = value;
  61. this.RaisePropertyChanged(() => this.CostBasis);
  62. this.RaisePropertyChanged(() => this.GainLossPercent);
  63. }
  64. }
  65. }
  66. private long _shares;
  67. public long Shares
  68. {
  69. get
  70. {
  71. return _shares;
  72. }
  73. set
  74. {
  75. if (!value.Equals(_shares))
  76. {
  77. _shares = value;
  78. this.RaisePropertyChanged(() => this.Shares);
  79. this.RaisePropertyChanged(() => this.MarketValue);
  80. this.RaisePropertyChanged(() => this.GainLossPercent);
  81. }
  82. }
  83. }
  84. private decimal _currentPrice;
  85. public decimal CurrentPrice
  86. {
  87. get
  88. {
  89. return _currentPrice;
  90. }
  91. set
  92. {
  93. if (!value.Equals(_currentPrice))
  94. {
  95. _currentPrice = value;
  96. this.RaisePropertyChanged(() => this.CurrentPrice);
  97. this.RaisePropertyChanged(() => this.MarketValue);
  98. this.RaisePropertyChanged(() => this.GainLossPercent);
  99. }
  100. }
  101. }
  102. public decimal MarketValue
  103. {
  104. get
  105. {
  106. return (_shares * _currentPrice);
  107. }
  108. }
  109. public decimal GainLossPercent
  110. {
  111. get
  112. {
  113. return ((CurrentPrice * Shares - CostBasis) * 100 / CostBasis);
  114. }
  115. }
  116. }
  117. }