| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- using GalaSoft.MvvmLight;
- using System.Windows.Media;
- namespace Muchinfo.MTPClient.Data.Model.QuoteItem
- {
- /// <summary>
- /// QuoteItemBase类
- /// </summary>
- public class QuoteItemBase : ObservableObject
- {
- #region Fields
- protected static readonly Brush AscBrush = new SolidColorBrush(Color.FromRgb(255, 50, 50));
- protected static readonly Brush DecBrush = new SolidColorBrush(Color.FromRgb(0, 255, 0));
- protected static readonly Brush DefaultBrush = new SolidColorBrush(Colors.White);
- protected static readonly string DefaultString = "-";
- /// <summary>
- /// 分类
- /// </summary>
- private string _sort;
- /// <summary>
- /// 代码
- /// </summary>
- private int _code;
- /// <summary>
- /// 现价
- /// </summary>
- private decimal _currentPrice;
- /// <summary>
- /// 时间
- /// </summary>
- private string _date;
- /// <summary>
- /// 最高
- /// </summary>
- private decimal _high;
- /// <summary>
- /// 昨收
- /// </summary>
- private decimal _lastClose;
- /// <summary>
- /// 最低
- /// </summary>
- private decimal _low;
- /// <summary>
- /// 市场
- /// </summary>
- private string _market;
- /// <summary>
- /// 名称
- /// </summary>
- private string _name;
- /// <summary>
- /// 今开
- /// </summary>
- private decimal _open;
- #endregion Fields
- #region Properties
- #region Public Properties
- /// <summary>
- /// 振幅 ((最高-最低)/昨收)
- /// </summary>
- public decimal Amplitude
- {
- get
- {
- if (LastClose != 0)
- {
- return (High - Low) / LastClose;
- }
- else
- {
- return (High - Low);
- }
- }
- }
- /// <summary>
- /// 振幅颜色
- /// </summary>
- public Brush AmplitudeColor
- {
- get
- {
- return GetBrush(Amplitude, 0);
- }
- }
- /// <summary>
- /// Gets the amplitude display.
- /// </summary>
- public string AmplitudeDisplay
- {
- get
- {
- return Amplitude.ToString("P2");
- }
- }
- /// <summary>
- /// 分类
- /// </summary>
- public string Sort
- {
- get
- {
- return _sort;
- }
- set
- {
- Set(() => Sort, ref _sort, value);
- }
- }
- /// <summary>
- /// 代码
- /// </summary>
- public int Code
- {
- get
- {
- return _code;
- }
- set
- {
- Set(() => Code, ref _code, value);
- }
- }
- /// <summary>
- /// 现价
- /// </summary>
- public decimal CurrentPrice
- {
- get
- {
- return _currentPrice;
- }
- set
- {
- Set(() => CurrentPrice, ref _currentPrice, value);
- ////RaisePropertyChanged(() => IncreasePercent);
- RaisePropertyChanged(() => IncreasePercentDisplay);
- RaisePropertyChanged(() => IncreaseValue);
- RaisePropertyChanged(() => IncreasePercentColor);
- RaisePropertyChanged(() => IncreaseValueColor);
- RaisePropertyChanged(() => CurrentPriceColor);
- }
- }
- /// <summary>
- /// 现价颜色
- /// </summary>
- public Brush CurrentPriceColor
- {
- get
- {
- return GetBrush(_currentPrice, _lastClose);
- }
- }
- /// <summary>
- /// 时间
- /// </summary>
- public string Date
- {
- get
- {
- return _date;
- }
- set
- {
- Set(() => Date, ref _date, value);
- }
- }
- /// <summary>
- /// Gets the color of the code.
- /// </summary>
- public Brush DefaultColor
- {
- get
- {
- return DefaultBrush;
- }
- }
- /// <summary>
- /// 交易所代码
- /// </summary>
- public string Exchange
- {
- get;
- set;
- }
- /// <summary>
- /// 最高
- /// </summary>
- public decimal High
- {
- get
- {
- return _high;
- }
- set
- {
- Set(() => High, ref _high, value);
- RaisePropertyChanged(() => AmplitudeDisplay);
- RaisePropertyChanged(() => AmplitudeColor);
- }
- }
- /// <summary>
- /// 最高颜色
- /// </summary>
- public Brush HighColor
- {
- get
- {
- return GetBrush(_high, _lastClose);
- }
- }
- /// <summary>
- /// 涨幅%((现价-昨收)/昨收)
- /// </summary>
- public decimal IncreasePercent
- {
- get
- {
- if (LastClose != 0)
- {
- return (CurrentPrice - LastClose) / LastClose;
- }
- return (CurrentPrice - LastClose);
- }
- }
- /// <summary>
- /// 涨幅%颜色
- /// </summary>
- public Brush IncreasePercentColor
- {
- get
- {
- return GetBrush(IncreasePercent, 0);
- }
- }
- /// <summary>
- /// Gets the increase percent display.
- /// </summary>
- public string IncreasePercentDisplay
- {
- get
- {
- return IncreasePercent.ToString("P2");
- }
- }
- /// <summary>
- /// 涨跌(现价-昨收)
- /// </summary>
- public decimal IncreaseValue
- {
- get
- {
- var value = (CurrentPrice - LastClose);
- return decimal.Parse(value.ToString("#.00"));
- }
- }
- /// <summary>
- /// 涨跌颜色
- /// </summary>
- public Brush IncreaseValueColor
- {
- get
- {
- return GetBrush(IncreaseValue, 0);
- }
- }
- /// <summary>
- /// 昨收
- /// </summary>
- public decimal LastClose
- {
- get
- {
- return _lastClose;
- }
- set
- {
- Set(() => LastClose, ref _lastClose, value);
- }
- }
- /// <summary>
- /// 最低
- /// </summary>
- public decimal Low
- {
- get
- {
- return _low;
- }
- set
- {
- Set(() => Low, ref _low, value);
- RaisePropertyChanged(() => AmplitudeDisplay);
- RaisePropertyChanged(() => AmplitudeColor);
- }
- }
- /// <summary>
- /// 最低颜色
- /// </summary>
- public Brush LowColor
- {
- get
- {
- return GetBrush(_low, 0);
- }
- }
- /// <summary>
- /// 市场
- /// </summary>
- public string Market
- {
- get
- {
- return _market;
- }
- set
- {
- Set(() => Market, ref _market, value);
- }
- }
- /// <summary>
- /// 名称
- /// </summary>
- public string Name
- {
- get
- {
- return _name;
- }
- set
- {
- Set(() => Name, ref _name, value);
- }
- }
- /// <summary>
- /// Gets the color of the name.
- /// </summary>
- public Brush NameColor
- {
- get
- {
- return new SolidColorBrush(Colors.Yellow);
- }
- }
- /// <summary>
- /// 今开
- /// </summary>
- public decimal Open
- {
- get
- {
- return _open;
- }
- set
- {
- Set(() => Open, ref _open, value);
- RaisePropertyChanged(() => OpenColor);
- }
- }
- /// <summary>
- /// 今开颜色
- /// </summary>
- public Brush OpenColor
- {
- get
- {
- return GetBrush(_open, _lastClose);
- }
- }
- #endregion Public Properties
- #endregion Properties
- #region Methods
- #region Public Methods
- /// <summary>
- /// 更新对象属性值(只更新需要字段)
- /// </summary>
- /// <param name="item">The item.</param>
- public virtual void UpdateFrom(QuoteItemBase item)
- {
- //只更新需要字段
- if (!this.CurrentPrice.Equals(item.CurrentPrice))
- {
- this.CurrentPrice = item.CurrentPrice;
- }
- if (!this.High.Equals(item.High))
- {
- this.High = item.High;
- }
- if (!this.Low.Equals(item.Low))
- {
- this.Low = item.Low;
- }
- }
- #endregion Public Methods
- #region Protected Methods
- /// <summary>
- /// Gets the brush.
- /// </summary>
- /// <param name="source">The source.</param>
- /// <param name="destination">The destination.</param>
- /// <returns>Brush.</returns>
- protected Brush GetBrush(decimal source, decimal destination)
- {
- if (source > destination)
- {
- return AscBrush;
- }
- if (source < destination)
- {
- return DecBrush;
- }
- return DefaultBrush;
- }
- #endregion Protected Methods
- #endregion Methods
- }
- }
|