TradeParamerSetViewModel.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Command;
  3. using Muchinfo.MTPClient.Account.Views;
  4. using Muchinfo.MTPClient.Data.Model;
  5. using Muchinfo.MTPClient.Data.Model.Account;
  6. using Muchinfo.MTPClient.Infrastructure.Utilities;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. namespace Muchinfo.MTPClient.Account.ViewModels
  10. {
  11. /// <summary>
  12. /// 交易参数设置业务逻辑
  13. /// </summary>
  14. public class TradeParamerSetViewModel : ViewModelBase
  15. {
  16. #region Constructors
  17. public TradeParamerSetViewModel()
  18. {
  19. var temp = UserManager.GetTradeAccounts();
  20. if (temp == null || temp.Count <= 0)
  21. {
  22. IsBuy = true;
  23. IsSell = false;
  24. Hands = 1;
  25. }
  26. else
  27. {
  28. UserInfo userInfo = new UserInfo();
  29. foreach (var info in temp)
  30. {
  31. if (info.UserName.Equals(UserManager.CurrentTradeAccount.LoginCode))
  32. {
  33. userInfo = info;
  34. break;
  35. }
  36. }
  37. if (string.IsNullOrEmpty(userInfo.UserName))
  38. {
  39. userInfo = temp.FirstOrDefault();
  40. }
  41. if (userInfo.TradeParamer == null)
  42. {
  43. IsBuy = true;
  44. IsSell = false;
  45. Hands = 1;
  46. }
  47. else
  48. {
  49. IsBuy = userInfo.TradeParamer.DefaultBuy;
  50. IsSell = !userInfo.TradeParamer.DefaultBuy;
  51. Hands = userInfo.TradeParamer.DefaultHands;
  52. }
  53. }
  54. // var temp=UserManager.GetTradeAccounts().FirstOrDefault((t)=>t.UserName.Equals(UserManager.CurrentTradeAccount.TradeCode));
  55. //todo:从服务端获取
  56. MaxHands = 1000;
  57. MinHands = 1;
  58. //Hands = 100;
  59. MaxSpreed = 100;
  60. MinSpreed = 1;
  61. Spreed = 50;
  62. }
  63. #endregion Constructors
  64. #region Properties
  65. private bool _isAutoChoose;
  66. /// <summary>
  67. /// 是否自动选择
  68. /// </summary>
  69. public bool IsAutoChoose
  70. {
  71. get { return _isAutoChoose; }
  72. set
  73. {
  74. Set(() => IsAutoChoose, ref _isAutoChoose, value);
  75. }
  76. }
  77. private bool _isDefineGoods;
  78. /// <summary>
  79. /// 是否选中自定义商品
  80. /// </summary>
  81. public bool IsDefineGoods
  82. {
  83. get { return _isDefineGoods; }
  84. set
  85. {
  86. Set(() => IsDefineGoods, ref _isDefineGoods, value);
  87. }
  88. }
  89. private bool _isBuy;
  90. /// <summary>
  91. /// 是否选中买入
  92. /// </summary>
  93. public bool IsBuy
  94. {
  95. get { return _isBuy; }
  96. set
  97. {
  98. Set(() => IsBuy, ref _isBuy, value);
  99. }
  100. }
  101. private bool _isSell;
  102. /// <summary>
  103. /// 是否选中卖出
  104. /// </summary>
  105. public bool IsSell
  106. {
  107. get { return _isSell; }
  108. set
  109. {
  110. Set(() => IsSell, ref _isSell, value);
  111. }
  112. }
  113. /// <summary>
  114. /// 是否显示忙
  115. /// </summary>
  116. private bool _isBusy;
  117. /// <summary>
  118. /// 是否忙,显示等待控件
  119. /// </summary>
  120. public bool IsBusy
  121. {
  122. get { return _isBusy; }
  123. set { Set(() => IsBusy, ref _isBusy, value); }
  124. }
  125. /// <summary>
  126. /// 商品列表
  127. /// </summary>
  128. public ObservableCollection<Goods> Goods { get; set; }
  129. /// <summary>
  130. /// 选中商品
  131. /// </summary>
  132. public Goods ChooseGoods { get; set; }
  133. /// <summary>
  134. /// 最大手数
  135. /// </summary>
  136. public decimal MaxHands { get; set; }
  137. /// <summary>
  138. /// 最小手数
  139. /// </summary>
  140. public decimal MinHands { get; set; }
  141. /// <summary>
  142. /// 手数
  143. /// </summary>
  144. public decimal Hands { get; set; }
  145. /// <summary>
  146. /// 最大点差
  147. /// </summary>
  148. public decimal MaxSpreed { get; set; }
  149. /// <summary>
  150. /// 最小点差
  151. /// </summary>
  152. public decimal MinSpreed { get; set; }
  153. /// <summary>
  154. /// 点差
  155. /// </summary>
  156. public decimal Spreed { get; set; }
  157. #endregion Properties
  158. #region Command
  159. /// <summary>
  160. /// 取消
  161. /// </summary>
  162. public RelayCommand<TradeParamerSetView> CancelCommand
  163. {
  164. get
  165. {
  166. return new RelayCommand<TradeParamerSetView>((w) =>
  167. {
  168. w.DialogResult = false;
  169. });
  170. }
  171. }
  172. /// <summary>
  173. /// 确定
  174. /// </summary>
  175. public RelayCommand<TradeParamerSetView> OKCommand
  176. {
  177. get
  178. {
  179. return new RelayCommand<TradeParamerSetView>((w) =>
  180. {
  181. ////debug注释验证
  182. if (!ValidData())
  183. {
  184. return;
  185. }
  186. w.DialogResult = false;
  187. });
  188. }
  189. }
  190. #endregion
  191. #region Methods
  192. /// <summary>
  193. /// 客户端验证登录数据
  194. /// </summary>
  195. /// <returns></returns>
  196. private bool ValidData()
  197. {
  198. var lsUserInfo = UserManager.GetTradeAccounts();
  199. UserInfo userInfo = new UserInfo();
  200. if (lsUserInfo != null && lsUserInfo.Count > 0)
  201. {
  202. userInfo = lsUserInfo.FirstOrDefault();
  203. }
  204. userInfo.TradeParamer = new TradeParamer { DefaultHands = Hands, DefaultBuy = IsBuy };
  205. UserManager.SaveTradeAccount(userInfo);
  206. return true;
  207. }
  208. #endregion Methods
  209. }
  210. }