TradeParamsSetViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. //----------------------------------------------------------------
  7. //Module Name: $safeprojectname$
  8. //Purpose:
  9. //CopyRight: Muchinfo
  10. //History:
  11. //----------------------------------------------------------------
  12. //DateTime 2017/2/23 16:26:59
  13. //Author
  14. //Description Create
  15. //----------------------------------------------------------------
  16. using System.Windows;
  17. using GalaSoft.MvvmLight;
  18. using GalaSoft.MvvmLight.Command;
  19. using Muchinfo.MTPClient.Data;
  20. using Muchinfo.MTPClient.Data.Enums;
  21. using Muchinfo.MTPClient.Data.Model;
  22. using Muchinfo.MTPClient.Infrastructure.Cache;
  23. using Muchinfo.MTPClient.Infrastructure.Helpers;
  24. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  25. using Muchinfo.MTPClient.Infrastructure.Utilities;
  26. using Muchinfo.MTPClient.Resources;
  27. using Muchinfo.PC.Common.Extensions;
  28. namespace Muchinfo.MTPClient.Account.ViewModels
  29. {
  30. public class TradeParamsSetViewModel:ViewModelBase
  31. {
  32. #region 交易参数设置、自动止盈止损
  33. private SettingTadIndex _tabControlIndex = SettingTadIndex.TRADE_SETTING;// 默认tab选中了哪一个
  34. /// <summary>
  35. /// 用于影藏和显示交易参数设置、自动止盈止损
  36. /// </summary>
  37. public SettingTadIndex SettingTadIndex
  38. {
  39. get { return _tabControlIndex; }
  40. set { Set(() => SettingTadIndex, ref _tabControlIndex, value); }
  41. }
  42. #endregion
  43. public TradeParamsSetViewModel()
  44. {
  45. var userInfo = UserManager.GetCurrentUserInfo() ;
  46. if (userInfo.TradeParams == null)
  47. {
  48. this.TradeParams = new TradeParams();
  49. }
  50. else
  51. {
  52. TradeParams=new TradeParams()
  53. {
  54. IsCancelComfrim = userInfo.TradeParams.IsCancelComfrim,
  55. IsSuccessComfrim = userInfo.TradeParams.IsSuccessComfrim,
  56. IsOrderComfrim = userInfo.TradeParams.IsOrderComfrim,
  57. LockScreenTime = userInfo.TradeParams.LockScreenTime,
  58. AllGoodsForAutoEntrust = userInfo.TradeParams.AllGoodsForAutoEntrust,// 用于自动止损止盈
  59. };
  60. }
  61. if (TradeParams.AllGoodsForAutoEntrust.Count == 0) // 如果没有存储,那就在本地加载吧
  62. {
  63. // 这里是加载商品配置的地方,如果内存中已经有了,那就不用本地来计算了
  64. List<QuoteGoods> goods = CacheManager.CacheGoodsBaseInfos;
  65. AllGoodsForAutoEntrustModel.Clear(); // 不管如何,都需要清理下
  66. foreach (QuoteGoods t in goods)
  67. {
  68. // 创建买卖方向的数据
  69. GoodsForAutoEntrustModel buy = new GoodsForAutoEntrustModel
  70. {
  71. GoodsId = t.GoodsId,
  72. Direction = 0,
  73. GoodsName = t.Name,
  74. GoodsCode = t.GoodsCode,
  75. Profit = 0, // 界面手动输入的
  76. Loss = 0, // 界面手动输入
  77. };
  78. GoodsForAutoEntrustModel sell = new GoodsForAutoEntrustModel
  79. {
  80. GoodsId = t.GoodsId,
  81. Direction = 1,
  82. GoodsName = t.Name,
  83. GoodsCode = t.GoodsCode,
  84. Profit = 0, // 界面手动输入的
  85. Loss = 0, // 界面手动输入
  86. };
  87. AllGoodsForAutoEntrustModel.Add(buy);
  88. AllGoodsForAutoEntrustModel.Add(sell);
  89. }
  90. this.TradeParams.AllGoodsForAutoEntrust = AllGoodsForAutoEntrustModel;
  91. userInfo.TradeParams = this.TradeParams;
  92. UserManager.SaveTradeAccount(userInfo); ////保存用户设置信息
  93. }
  94. else // 有,就赋值,并且排个序
  95. {
  96. /*TradeParams.AllGoodsForAutoEntrust.OrderBy(goods => goods.SortNum, new SortNumComparer());// 先排个序*/
  97. AllGoodsForAutoEntrustModel = new ObservableCollection<GoodsForAutoEntrustModel>(TradeParams.AllGoodsForAutoEntrust.OrderByDescending(goods => goods.SortNum > 0));
  98. }
  99. }
  100. /// <summary>
  101. /// 设置下单是否要确认
  102. /// </summary>
  103. public Dictionary<bool, string> OrderComfrimItems
  104. {
  105. get
  106. {
  107. var orderC = new Dictionary<bool, string>();
  108. orderC.Add(true,Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_Yes);
  109. orderC.Add(false, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_No);
  110. return orderC;
  111. }
  112. }
  113. /// <summary>
  114. /// 设置下单是否要关窗口
  115. /// </summary>
  116. public Dictionary<bool, string> SuccessItems
  117. {
  118. get
  119. {
  120. var orderC = new Dictionary<bool, string>();
  121. orderC.Add(true, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_Yes);
  122. orderC.Add(false, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_No);
  123. return orderC;
  124. }
  125. }
  126. /// <summary>
  127. /// 设置 撤单是否要
  128. /// </summary>
  129. public Dictionary<bool, string> CancelItems
  130. {
  131. get
  132. {
  133. var orderC = new Dictionary<bool, string>();
  134. orderC.Add(true, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_Yes);
  135. orderC.Add(false, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_No);
  136. return orderC;
  137. }
  138. }
  139. /// <summary>
  140. /// 设置 撤单是否要
  141. /// </summary>
  142. public Dictionary<int, string> LockScreenItems
  143. {
  144. get
  145. {
  146. var orderC = new Dictionary<int, string>();
  147. orderC.Add(0, Muchinfo.MTPClient.Resources.Client_Resource.Content_NoLockScreen);
  148. orderC.Add(5, Muchinfo.MTPClient.Resources.Client_Resource.Content_Minute5);
  149. orderC.Add(10, Muchinfo.MTPClient.Resources.Client_Resource.Content_Minute10);
  150. orderC.Add(15, Muchinfo.MTPClient.Resources.Client_Resource.Content_Minute15);
  151. orderC.Add(20, Muchinfo.MTPClient.Resources.Client_Resource.Content_Minute20);
  152. orderC.Add(30, Muchinfo.MTPClient.Resources.Client_Resource.Content_Minute30);
  153. return orderC;
  154. }
  155. }
  156. private TradeParams _tradeParams;
  157. /// <summary>
  158. /// 交易参数
  159. /// </summary>
  160. public TradeParams TradeParams
  161. {
  162. get { return _tradeParams; }
  163. set { Set(() => TradeParams, ref _tradeParams, value); }
  164. }
  165. /// <summary>
  166. /// 确定
  167. /// </summary>
  168. public RelayCommand<Window> OKCommand
  169. {
  170. get
  171. {
  172. return new RelayCommand<Window>((dialog) =>
  173. {
  174. if (TradeParams != null)
  175. {
  176. var userInfo= UserManager.GetTradeAccount(UserManager.CurrentTradeAccount.LoginID.ToString());
  177. if (userInfo != null)
  178. {
  179. userInfo.TradeParams = this.TradeParams;
  180. UserManager.SaveTradeAccount(userInfo); ////保存用户设置信息
  181. MessengerHelper.DefaultSend(true, MessengerTokens.InitLockTimer);
  182. }
  183. }
  184. dialog.Close();
  185. });
  186. }
  187. }
  188. /// <summary>
  189. /// 取消
  190. /// </summary>
  191. public RelayCommand<Window> CancelCommand
  192. {
  193. get
  194. {
  195. return new RelayCommand<Window>((dialog) =>
  196. {
  197. dialog.DialogResult = false;
  198. });
  199. }
  200. }
  201. #region 自动止盈止损相关
  202. /// <summary>
  203. /// 自动止盈止损数据集合
  204. /// </summary>
  205. private ObservableCollection<GoodsForAutoEntrustModel> _allGoodsForAutoEntrustModels = new ObservableCollection<GoodsForAutoEntrustModel>();
  206. public ObservableCollection<GoodsForAutoEntrustModel> AllGoodsForAutoEntrustModel
  207. {
  208. get
  209. {
  210. return _allGoodsForAutoEntrustModels;
  211. }
  212. set
  213. {
  214. Set(() => AllGoodsForAutoEntrustModel, ref _allGoodsForAutoEntrustModels, value);
  215. }
  216. }
  217. private GoodsForAutoEntrustModel _currentGoodsForAutoEntrustModel;
  218. public GoodsForAutoEntrustModel CurrentGoodsForAutoEntrustModel
  219. {
  220. get { return _currentGoodsForAutoEntrustModel; }
  221. set
  222. {
  223. Set(() => CurrentGoodsForAutoEntrustModel, ref _currentGoodsForAutoEntrustModel, value);
  224. }
  225. }
  226. /// <summary>
  227. /// 全部复位
  228. /// </summary>
  229. public RelayCommand<Window> ResetCommand
  230. {
  231. get
  232. {
  233. return new RelayCommand<Window>((dialog) =>
  234. {
  235. if (AllGoodsForAutoEntrustModel != null && AllGoodsForAutoEntrustModel.Any())
  236. {
  237. foreach (GoodsForAutoEntrustModel goodsForAutoEntrustModel in AllGoodsForAutoEntrustModel)
  238. {
  239. goodsForAutoEntrustModel.Loss = 0;
  240. goodsForAutoEntrustModel.Profit = 0;
  241. }
  242. AllGoodsForAutoEntrustModel = new ObservableCollection<GoodsForAutoEntrustModel>(AllGoodsForAutoEntrustModel);
  243. }
  244. });
  245. }
  246. }
  247. /// <summary>
  248. /// 保存设置到本地
  249. /// </summary>
  250. public RelayCommand<Window> SetAutoCommand
  251. {
  252. get
  253. {
  254. return new RelayCommand<Window>((dialog) =>
  255. {
  256. // 保存设置到本地
  257. if (TradeParams != null)
  258. {
  259. var userInfo = UserManager.GetTradeAccount(UserManager.CurrentTradeAccount.LoginID.ToString());
  260. if (userInfo != null)
  261. {
  262. this.TradeParams.AllGoodsForAutoEntrust = AllGoodsForAutoEntrustModel;
  263. userInfo.TradeParams = this.TradeParams;
  264. UserManager.SaveTradeAccount(userInfo); ////保存用户设置信息
  265. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  266. {
  267. MessageBoxHelper.ShowSuccess(Client_Resource.Delivery_SaveSuccess,
  268. Client_Resource.DeliveryOrderView_WarningTipsTitle);
  269. }));
  270. }
  271. }
  272. });
  273. }
  274. }
  275. /// <summary>
  276. /// 止损输入框的变化
  277. /// </summary>
  278. public RelayCommand<int> SL_TextChanged
  279. {
  280. get
  281. {
  282. return new RelayCommand<int>((i) =>
  283. {
  284. if (CurrentGoodsForAutoEntrustModel != null)
  285. {
  286. CurrentGoodsForAutoEntrustModel.Loss = i;
  287. }
  288. });
  289. }
  290. }
  291. /// <summary>
  292. /// 止盈的输入框变化
  293. /// </summary>
  294. public RelayCommand<int> SP_TextChanged
  295. {
  296. get
  297. {
  298. return new RelayCommand<int>((i) =>
  299. {
  300. if (CurrentGoodsForAutoEntrustModel != null)
  301. {
  302. CurrentGoodsForAutoEntrustModel.Profit = i;
  303. }
  304. });
  305. }
  306. }
  307. #endregion
  308. }
  309. }