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