| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2017/2/23 16:26:59
- //Author
- //Description Create
- //----------------------------------------------------------------
- using System.Windows;
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Infrastructure.Cache;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Infrastructure.MessageBox;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.Resources;
- using Muchinfo.PC.Common.Extensions;
- namespace Muchinfo.MTPClient.Account.ViewModels
- {
- public class TradeParamsSetViewModel:ViewModelBase
- {
- #region 交易参数设置、自动止盈止损
- private SettingTadIndex _tabControlIndex = SettingTadIndex.TRADE_SETTING;// 默认tab选中了哪一个
- /// <summary>
- /// 用于影藏和显示交易参数设置、自动止盈止损
- /// </summary>
- public SettingTadIndex SettingTadIndex
- {
- get { return _tabControlIndex; }
- set { Set(() => SettingTadIndex, ref _tabControlIndex, value); }
- }
- #endregion
- public TradeParamsSetViewModel()
- {
- var userInfo = UserManager.GetCurrentUserInfo() ;
- if (userInfo.TradeParams == null)
- {
- this.TradeParams = new TradeParams();
- }
- else
- {
- TradeParams=new TradeParams()
- {
- IsCancelComfrim = userInfo.TradeParams.IsCancelComfrim,
- IsSuccessComfrim = userInfo.TradeParams.IsSuccessComfrim,
- IsOrderComfrim = userInfo.TradeParams.IsOrderComfrim,
- LockScreenTime = userInfo.TradeParams.LockScreenTime,
- AllGoodsForAutoEntrust = userInfo.TradeParams.AllGoodsForAutoEntrust,// 用于自动止损止盈
- };
- }
- if (TradeParams.AllGoodsForAutoEntrust.Count == 0) // 如果没有存储,那就在本地加载吧
- {
- // 这里是加载商品配置的地方,如果内存中已经有了,那就不用本地来计算了
- List<QuoteGoods> goods = CacheManager.CacheGoodsBaseInfos;
- AllGoodsForAutoEntrustModel.Clear(); // 不管如何,都需要清理下
- foreach (QuoteGoods t in goods)
- {
- // 创建买卖方向的数据
- GoodsForAutoEntrustModel buy = new GoodsForAutoEntrustModel
- {
- GoodsId = t.GoodsId,
- Direction = 0,
- GoodsName = t.Name,
- GoodsCode = t.GoodsCode,
- Profit = 0, // 界面手动输入的
- Loss = 0, // 界面手动输入
- };
- GoodsForAutoEntrustModel sell = new GoodsForAutoEntrustModel
- {
- GoodsId = t.GoodsId,
- Direction = 1,
- GoodsName = t.Name,
- GoodsCode = t.GoodsCode,
- Profit = 0, // 界面手动输入的
- Loss = 0, // 界面手动输入
- };
- AllGoodsForAutoEntrustModel.Add(buy);
- AllGoodsForAutoEntrustModel.Add(sell);
- }
- this.TradeParams.AllGoodsForAutoEntrust = AllGoodsForAutoEntrustModel;
- userInfo.TradeParams = this.TradeParams;
- UserManager.SaveTradeAccount(userInfo); ////保存用户设置信息
- }
- else // 有,就赋值,并且排个序
- {
- /*TradeParams.AllGoodsForAutoEntrust.OrderBy(goods => goods.SortNum, new SortNumComparer());// 先排个序*/
- AllGoodsForAutoEntrustModel = new ObservableCollection<GoodsForAutoEntrustModel>(TradeParams.AllGoodsForAutoEntrust.OrderByDescending(goods => goods.SortNum > 0));
- }
- }
- /// <summary>
- /// 设置下单是否要确认
- /// </summary>
- public Dictionary<bool, string> OrderComfrimItems
- {
- get
- {
- var orderC = new Dictionary<bool, string>();
- orderC.Add(true,Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_Yes);
- orderC.Add(false, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_No);
- return orderC;
- }
- }
- /// <summary>
- /// 设置下单是否要关窗口
- /// </summary>
- public Dictionary<bool, string> SuccessItems
- {
- get
- {
- var orderC = new Dictionary<bool, string>();
- orderC.Add(true, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_Yes);
- orderC.Add(false, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_No);
- return orderC;
- }
- }
- /// <summary>
- /// 设置 撤单是否要
- /// </summary>
- public Dictionary<bool, string> CancelItems
- {
- get
- {
- var orderC = new Dictionary<bool, string>();
- orderC.Add(true, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_Yes);
- orderC.Add(false, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_No);
- return orderC;
- }
- }
-
- /// <summary>
- /// 设置 撤单是否要
- /// </summary>
- public Dictionary<int, string> LockScreenItems
- {
- get
- {
- var orderC = new Dictionary<int, string>();
- orderC.Add(0, Muchinfo.MTPClient.Resources.Client_Resource.Content_NoLockScreen);
- orderC.Add(5, Muchinfo.MTPClient.Resources.Client_Resource.Content_Minute5);
- orderC.Add(10, Muchinfo.MTPClient.Resources.Client_Resource.Content_Minute10);
- orderC.Add(15, Muchinfo.MTPClient.Resources.Client_Resource.Content_Minute15);
- orderC.Add(20, Muchinfo.MTPClient.Resources.Client_Resource.Content_Minute20);
- orderC.Add(30, Muchinfo.MTPClient.Resources.Client_Resource.Content_Minute30);
- return orderC;
- }
- }
- private TradeParams _tradeParams;
- /// <summary>
- /// 交易参数
- /// </summary>
- public TradeParams TradeParams
- {
- get { return _tradeParams; }
- set { Set(() => TradeParams, ref _tradeParams, value); }
- }
- /// <summary>
- /// 确定
- /// </summary>
- public RelayCommand<Window> OKCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- if (TradeParams != null)
- {
- var userInfo= UserManager.GetTradeAccount(UserManager.CurrentTradeAccount.LoginID.ToString());
- if (userInfo != null)
- {
- userInfo.TradeParams = this.TradeParams;
- UserManager.SaveTradeAccount(userInfo); ////保存用户设置信息
- MessengerHelper.DefaultSend(true, MessengerTokens.InitLockTimer);
- }
- }
- dialog.Close();
- });
- }
- }
- /// <summary>
- /// 取消
- /// </summary>
- public RelayCommand<Window> CancelCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- dialog.DialogResult = false;
- });
- }
- }
- #region 自动止盈止损相关
- /// <summary>
- /// 自动止盈止损数据集合
- /// </summary>
- private ObservableCollection<GoodsForAutoEntrustModel> _allGoodsForAutoEntrustModels = new ObservableCollection<GoodsForAutoEntrustModel>();
- public ObservableCollection<GoodsForAutoEntrustModel> AllGoodsForAutoEntrustModel
- {
- get
- {
- return _allGoodsForAutoEntrustModels;
- }
- set
- {
- Set(() => AllGoodsForAutoEntrustModel, ref _allGoodsForAutoEntrustModels, value);
- }
- }
- private GoodsForAutoEntrustModel _currentGoodsForAutoEntrustModel;
- public GoodsForAutoEntrustModel CurrentGoodsForAutoEntrustModel
- {
- get { return _currentGoodsForAutoEntrustModel; }
- set
- {
- Set(() => CurrentGoodsForAutoEntrustModel, ref _currentGoodsForAutoEntrustModel, value);
-
- }
- }
- /// <summary>
- /// 全部复位
- /// </summary>
- public RelayCommand<Window> ResetCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- if (AllGoodsForAutoEntrustModel != null && AllGoodsForAutoEntrustModel.Any())
- {
- foreach (GoodsForAutoEntrustModel goodsForAutoEntrustModel in AllGoodsForAutoEntrustModel)
- {
- goodsForAutoEntrustModel.Loss = 0;
- goodsForAutoEntrustModel.Profit = 0;
- }
- AllGoodsForAutoEntrustModel = new ObservableCollection<GoodsForAutoEntrustModel>(AllGoodsForAutoEntrustModel);
- }
- });
- }
- }
- /// <summary>
- /// 保存设置到本地
- /// </summary>
- public RelayCommand<Window> SetAutoCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- // 保存设置到本地
- if (TradeParams != null)
- {
- var userInfo = UserManager.GetTradeAccount(UserManager.CurrentTradeAccount.LoginID.ToString());
- if (userInfo != null)
- {
- this.TradeParams.AllGoodsForAutoEntrust = AllGoodsForAutoEntrustModel;
- userInfo.TradeParams = this.TradeParams;
- UserManager.SaveTradeAccount(userInfo); ////保存用户设置信息
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- MessageBoxHelper.ShowSuccess(Client_Resource.Delivery_SaveSuccess,
- Client_Resource.DeliveryOrderView_WarningTipsTitle);
- }));
- }
- }
- });
- }
- }
- /// <summary>
- /// 止损输入框的变化
- /// </summary>
- public RelayCommand<int> SL_TextChanged
- {
- get
- {
- return new RelayCommand<int>((i) =>
- {
- if (CurrentGoodsForAutoEntrustModel != null)
- {
- CurrentGoodsForAutoEntrustModel.Loss = i;
- }
- });
- }
- }
- /// <summary>
- /// 止盈的输入框变化
- /// </summary>
- public RelayCommand<int> SP_TextChanged
- {
- get
- {
- return new RelayCommand<int>((i) =>
- {
- if (CurrentGoodsForAutoEntrustModel != null)
- {
- CurrentGoodsForAutoEntrustModel.Profit = i;
- }
- });
- }
- }
- #endregion
- }
- }
|