GoodsBase.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using GalaSoft.MvvmLight;
  2. using System;
  3. using GalaSoft.MvvmLight.Messaging;
  4. using Muchinfo.MTPClient.Data.Enums;
  5. namespace Muchinfo.MTPClient.Data.Model
  6. {
  7. /// <summary>
  8. /// GoodsBase类
  9. /// </summary>
  10. public abstract class GoodsBase : ObservableObject, IEquatable<GoodsBase>
  11. {
  12. #region Fields
  13. /// <summary>
  14. /// 交易所代码
  15. /// </summary>
  16. private string _exchHqCode;
  17. /// <summary>
  18. /// 商品代码
  19. /// </summary>
  20. private string _goodsCode;
  21. /// <summary>
  22. /// 商品Id
  23. /// </summary>
  24. private uint _goodsId;
  25. /// <summary>
  26. /// 序号
  27. /// </summary>
  28. private int _showIndex;
  29. #endregion Fields
  30. #region Constructors
  31. /// <summary>
  32. /// 构造一个基础商品
  33. /// </summary>
  34. /// <param name="exchangeCode">交易所代码</param>
  35. /// <param name="goodsCode">商品代码</param>
  36. /// <param name="goodsHqCode">商品代码</param>
  37. /// <exception cref="System.ArgumentNullException"></exception>
  38. protected GoodsBase(string exchangeCode, string goodsCode,string goodsHqCode)
  39. {
  40. //if (string.IsNullOrEmpty(exchangeCode))
  41. //{
  42. // throw new ArgumentNullException("exchangeCode");
  43. //}
  44. if (string.IsNullOrEmpty(goodsCode))
  45. {
  46. throw new ArgumentNullException("goodsCode");
  47. }
  48. //if (string.IsNullOrEmpty(goodsHqCode))
  49. //{
  50. // throw new ArgumentNullException("goodsHqCode");
  51. //}
  52. _exchHqCode = "250";//exchangeCode;
  53. _goodsCode = goodsCode;
  54. GoodsHqCode = goodsHqCode;
  55. }
  56. #endregion Constructors
  57. #region Properties
  58. #region Public Properties
  59. /// <summary>
  60. /// 获取基础商品的交易所代码
  61. /// </summary>
  62. public string ExchHqCode
  63. {
  64. get
  65. {
  66. return _exchHqCode;
  67. }
  68. set
  69. {
  70. Set(() => ExchHqCode, ref _exchHqCode, value);
  71. }
  72. }
  73. /// <summary>
  74. /// 获取基础商品的商品代码
  75. /// </summary>
  76. public string GoodsCode
  77. {
  78. get
  79. {
  80. return _goodsCode;
  81. }
  82. set
  83. {
  84. Set(() => GoodsCode, ref _goodsCode, value);
  85. }
  86. }
  87. /// <summary>
  88. /// 获取基础商品的商品Id
  89. /// </summary>
  90. public uint GoodsId
  91. {
  92. get
  93. {
  94. return _goodsId;
  95. }
  96. set
  97. {
  98. Set(() => GoodsId, ref _goodsId, value);
  99. }
  100. }
  101. private string _GoodsClassCode;
  102. /// <summary>
  103. /// 获取基础商品的商品品种代码
  104. /// </summary>
  105. public string GoodsClassCode
  106. {
  107. get
  108. {
  109. return _GoodsClassCode;
  110. }
  111. set
  112. {
  113. Set(() => GoodsClassCode, ref _GoodsClassCode, value);
  114. }
  115. }
  116. private string _GoodsClassName;
  117. /// <summary>
  118. /// 获取基础商品的商品品种名称
  119. /// </summary>
  120. public string GoodsClassName
  121. {
  122. get
  123. {
  124. return _GoodsClassName;
  125. }
  126. set
  127. {
  128. Set(() => GoodsClassName, ref _GoodsClassName, value);
  129. }
  130. }
  131. /// <summary>
  132. /// 获取和设置标签(获取行情时用)
  133. /// </summary>
  134. public string Symbol
  135. {
  136. get
  137. {
  138. return _exchHqCode.PadLeft(3, ' ') + GoodsHqCode.PadLeft(6, ' ');
  139. }
  140. }
  141. public string GoodsHqCode { get; set; }
  142. /// <summary>
  143. /// 序号
  144. /// </summary>
  145. public int ShowIndex
  146. {
  147. get
  148. {
  149. return _showIndex;
  150. }
  151. set
  152. {
  153. Set(() => ShowIndex, ref _showIndex, value);
  154. }
  155. }
  156. #endregion Public Properties
  157. #endregion Properties
  158. #region Methods
  159. #region Public Methods
  160. /// <summary>
  161. /// 比较与另一个对象是否指向相同一个事物
  162. /// </summary>
  163. /// <param name="obj">另一个对象</param>
  164. /// <returns>是否相同</returns>
  165. public override bool Equals(object obj)
  166. {
  167. if (obj != null)
  168. {
  169. var goods = obj as GoodsBase;
  170. if (goods != null)
  171. {
  172. return Equals(goods);
  173. }
  174. }
  175. return false;
  176. }
  177. /// <summary>
  178. /// 比较与另一个基础商品是否指向相同一个事物
  179. /// </summary>
  180. /// <param name="other">另一个基础商品</param>
  181. /// <returns>是否相同</returns>
  182. public bool Equals(GoodsBase other)
  183. {
  184. if (other == null)
  185. {
  186. return false;
  187. }
  188. return this.Symbol.Equals(other.Symbol);
  189. }
  190. /// <summary>
  191. /// 返回这个商品的HashCode
  192. /// </summary>
  193. /// <returns></returns>
  194. public override int GetHashCode()
  195. {
  196. return Symbol.GetHashCode();
  197. }
  198. /// <summary>
  199. /// 获取基础商品的字符串表达形式
  200. /// </summary>
  201. /// <returns></returns>
  202. public override string ToString()
  203. {
  204. return "[" + Symbol + "]";
  205. }
  206. #endregion Public Methods
  207. #endregion Methods
  208. }
  209. }