using GalaSoft.MvvmLight;
using System;
using GalaSoft.MvvmLight.Messaging;
using Muchinfo.MTPClient.Data.Enums;
namespace Muchinfo.MTPClient.Data.Model
{
///
/// GoodsBase类
///
public abstract class GoodsBase : ObservableObject, IEquatable
{
#region Fields
///
/// 交易所代码
///
private string _exchHqCode;
///
/// 商品代码
///
private string _goodsCode;
///
/// 商品Id
///
private uint _goodsId;
///
/// 序号
///
private int _showIndex;
#endregion Fields
#region Constructors
///
/// 构造一个基础商品
///
/// 交易所代码
/// 商品代码
/// 商品代码
///
protected GoodsBase(string exchangeCode, string goodsCode,string goodsHqCode)
{
//if (string.IsNullOrEmpty(exchangeCode))
//{
// throw new ArgumentNullException("exchangeCode");
//}
if (string.IsNullOrEmpty(goodsCode))
{
throw new ArgumentNullException("goodsCode");
}
//if (string.IsNullOrEmpty(goodsHqCode))
//{
// throw new ArgumentNullException("goodsHqCode");
//}
_exchHqCode = "250";//exchangeCode;
_goodsCode = goodsCode;
GoodsHqCode = goodsHqCode;
}
#endregion Constructors
#region Properties
#region Public Properties
///
/// 获取基础商品的交易所代码
///
public string ExchHqCode
{
get
{
return _exchHqCode;
}
set
{
Set(() => ExchHqCode, ref _exchHqCode, value);
}
}
///
/// 获取基础商品的商品代码
///
public string GoodsCode
{
get
{
return _goodsCode;
}
set
{
Set(() => GoodsCode, ref _goodsCode, value);
}
}
///
/// 获取基础商品的商品Id
///
public uint GoodsId
{
get
{
return _goodsId;
}
set
{
Set(() => GoodsId, ref _goodsId, value);
}
}
private string _GoodsClassCode;
///
/// 获取基础商品的商品品种代码
///
public string GoodsClassCode
{
get
{
return _GoodsClassCode;
}
set
{
Set(() => GoodsClassCode, ref _GoodsClassCode, value);
}
}
private string _GoodsClassName;
///
/// 获取基础商品的商品品种名称
///
public string GoodsClassName
{
get
{
return _GoodsClassName;
}
set
{
Set(() => GoodsClassName, ref _GoodsClassName, value);
}
}
///
/// 获取和设置标签(获取行情时用)
///
public string Symbol
{
get
{
return _exchHqCode.PadLeft(3, ' ') + GoodsHqCode.PadLeft(6, ' ');
}
}
public string GoodsHqCode { get; set; }
///
/// 序号
///
public int ShowIndex
{
get
{
return _showIndex;
}
set
{
Set(() => ShowIndex, ref _showIndex, value);
}
}
#endregion Public Properties
#endregion Properties
#region Methods
#region Public Methods
///
/// 比较与另一个对象是否指向相同一个事物
///
/// 另一个对象
/// 是否相同
public override bool Equals(object obj)
{
if (obj != null)
{
var goods = obj as GoodsBase;
if (goods != null)
{
return Equals(goods);
}
}
return false;
}
///
/// 比较与另一个基础商品是否指向相同一个事物
///
/// 另一个基础商品
/// 是否相同
public bool Equals(GoodsBase other)
{
if (other == null)
{
return false;
}
return this.Symbol.Equals(other.Symbol);
}
///
/// 返回这个商品的HashCode
///
///
public override int GetHashCode()
{
return Symbol.GetHashCode();
}
///
/// 获取基础商品的字符串表达形式
///
///
public override string ToString()
{
return "[" + Symbol + "]";
}
#endregion Public Methods
#endregion Methods
}
}