PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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