/V2/trunk/RI/Desktop/StockTraderRI.Modules.Position/PositionSummary/PositionSummaryItem.cs

# · C# · 137 lines · 103 code · 18 blank · 16 comment · 4 complexity · 71f6f98c475bbfaf4bc13b3b7d507925 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 System.ComponentModel;
  18. using StockTraderRI.Infrastructure.Models;
  19. namespace StockTraderRI.Modules.Position.PositionSummary
  20. {
  21. public class PositionSummaryItem : INotifyPropertyChanged
  22. {
  23. private const string GAINLOSSPERCENTPROPERTYNAME = "GainLossPercent";
  24. private const string MARKETVALUEPROPERTYNAME = "MarketValue";
  25. public PositionSummaryItem(string tickerSymbol, decimal costBasis, long shares, decimal currentPrice)
  26. {
  27. TickerSymbol = tickerSymbol;
  28. CostBasis = costBasis;
  29. Shares = shares;
  30. CurrentPrice = currentPrice;
  31. }
  32. private string _tickerSymbol;
  33. public string TickerSymbol
  34. {
  35. get
  36. {
  37. return _tickerSymbol;
  38. }
  39. set
  40. {
  41. if (!value.Equals(_tickerSymbol))
  42. {
  43. _tickerSymbol = value;
  44. PropertyChanged(this, new PropertyChangedEventArgs("TickerSymbol"));
  45. }
  46. }
  47. }
  48. private decimal _costBasis;
  49. public decimal CostBasis
  50. {
  51. get
  52. {
  53. return _costBasis;
  54. }
  55. set
  56. {
  57. if (!value.Equals(_costBasis))
  58. {
  59. _costBasis = value;
  60. PropertyChanged(this, new PropertyChangedEventArgs("CostBasis"));
  61. PropertyChanged(this, new PropertyChangedEventArgs(GAINLOSSPERCENTPROPERTYNAME));
  62. }
  63. }
  64. }
  65. private long _shares;
  66. public long Shares
  67. {
  68. get
  69. {
  70. return _shares;
  71. }
  72. set
  73. {
  74. if (!value.Equals(_shares))
  75. {
  76. _shares = value;
  77. PropertyChanged(this, new PropertyChangedEventArgs("Shares"));
  78. PropertyChanged(this, new PropertyChangedEventArgs(MARKETVALUEPROPERTYNAME));
  79. PropertyChanged(this, new PropertyChangedEventArgs(GAINLOSSPERCENTPROPERTYNAME));
  80. }
  81. }
  82. }
  83. private decimal _currentPrice;
  84. public decimal CurrentPrice
  85. {
  86. get
  87. {
  88. return _currentPrice;
  89. }
  90. set
  91. {
  92. if (!value.Equals(_currentPrice))
  93. {
  94. _currentPrice = value;
  95. PropertyChanged(this, new PropertyChangedEventArgs("CurrentPrice"));
  96. PropertyChanged(this, new PropertyChangedEventArgs(MARKETVALUEPROPERTYNAME));
  97. PropertyChanged(this, new PropertyChangedEventArgs(GAINLOSSPERCENTPROPERTYNAME));
  98. }
  99. }
  100. }
  101. public decimal MarketValue
  102. {
  103. get
  104. {
  105. return (_shares * _currentPrice);
  106. }
  107. }
  108. public decimal GainLossPercent
  109. {
  110. get
  111. {
  112. return ((CurrentPrice * Shares - CostBasis) * 100 / CostBasis);
  113. }
  114. }
  115. #region INotifyPropertyChanged Members
  116. public event PropertyChangedEventHandler PropertyChanged = delegate { };
  117. #endregion
  118. }
  119. }