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选中了哪一个 /// /// 用于影藏和显示交易参数设置、自动止盈止损 /// 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 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(TradeParams.AllGoodsForAutoEntrust.OrderByDescending(goods => goods.SortNum > 0)); } } /// /// 设置下单是否要确认 /// public Dictionary OrderComfrimItems { get { var orderC = new Dictionary(); orderC.Add(true,Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_Yes); orderC.Add(false, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_No); return orderC; } } /// /// 设置下单是否要关窗口 /// public Dictionary SuccessItems { get { var orderC = new Dictionary(); orderC.Add(true, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_Yes); orderC.Add(false, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_No); return orderC; } } /// /// 设置 撤单是否要 /// public Dictionary CancelItems { get { var orderC = new Dictionary(); orderC.Add(true, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_Yes); orderC.Add(false, Muchinfo.MTPClient.Resources.Client_Resource.Infrastructure_No); return orderC; } } /// /// 设置 撤单是否要 /// public Dictionary LockScreenItems { get { var orderC = new Dictionary(); 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; /// /// 交易参数 /// public TradeParams TradeParams { get { return _tradeParams; } set { Set(() => TradeParams, ref _tradeParams, value); } } /// /// 确定 /// public RelayCommand OKCommand { get { return new RelayCommand((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(); }); } } /// /// 取消 /// public RelayCommand CancelCommand { get { return new RelayCommand((dialog) => { dialog.DialogResult = false; }); } } #region 自动止盈止损相关 /// /// 自动止盈止损数据集合 /// private ObservableCollection _allGoodsForAutoEntrustModels = new ObservableCollection(); public ObservableCollection 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); } } /// /// 全部复位 /// public RelayCommand ResetCommand { get { return new RelayCommand((dialog) => { if (AllGoodsForAutoEntrustModel != null && AllGoodsForAutoEntrustModel.Any()) { foreach (GoodsForAutoEntrustModel goodsForAutoEntrustModel in AllGoodsForAutoEntrustModel) { goodsForAutoEntrustModel.Loss = 0; goodsForAutoEntrustModel.Profit = 0; } AllGoodsForAutoEntrustModel = new ObservableCollection(AllGoodsForAutoEntrustModel); } }); } } /// /// 保存设置到本地 /// public RelayCommand SetAutoCommand { get { return new RelayCommand((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); })); } } }); } } /// /// 止损输入框的变化 /// public RelayCommand SL_TextChanged { get { return new RelayCommand((i) => { if (CurrentGoodsForAutoEntrustModel != null) { CurrentGoodsForAutoEntrustModel.Loss = i; } }); } } /// /// 止盈的输入框变化 /// public RelayCommand SP_TextChanged { get { return new RelayCommand((i) => { if (CurrentGoodsForAutoEntrustModel != null) { CurrentGoodsForAutoEntrustModel.Profit = i; } }); } } #endregion } }