using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; using GalaSoft.MvvmLight.Messaging; using GalaSoft.MvvmLight.Threading; using Muchinfo.MTPClient.Account.ViewModels.OrderViewModel; using Muchinfo.MTPClient.Account.Views; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Infrastructure.Cache; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using System; using System.Collections.Generic; using System.Windows; using System.Linq; namespace Muchinfo.MTPClient.Account.ViewModels { public class TradeHeaderViewModel : ViewModelBase { #region 字段 private IOrderService _orderService; private TradeAccount _currentTradeAccount; //private ILoginService _loginService; //private IGoodsService _goodsService; /// /// 当前MenuCommandType /// public MenuCommandType _currentMenuType; public MenuCommandType CurrentMenuType { get { return _currentMenuType; } set { Set(() => CurrentMenuType, ref _currentMenuType, value); } } private bool _isMemberTrade; /// /// 是否是要监控会员 交易员 /// public bool IsMemberTrade { get { return _isMemberTrade; } set { Set(() => IsMemberTrade, ref _isMemberTrade, value); } } #endregion #region 属性 /// /// 账号列表中的字符串表示 /// public List AccountsList { get { var listAccount = new List(); if (UserManager.TradeAccounts != null) { foreach (var tradeAccount in UserManager.TradeAccounts) { listAccount.Add(tradeAccount); } } return listAccount; } } /// /// 买入命令 /// public RelayCommand BuyCommand { get { return new RelayCommand(() => { CacheManager.FromType = eOrderFormType.Commom; //顶部买卖按钮与挂牌无关 var order = new OrderMessage() { Direction = Direction.Bid, OrderPriceMode = ePriceMode.PRICEMODE_MARKET }; MessengerHelper.DefaultSend(order, MessengerTokens.OrderMessageToken); },() => CanCommandEnable(MenuCommandType.BuyIn)); } } #region 工具栏 /// /// 返回 /// public RelayCommand BackCommand { get { return new RelayCommand(() => { // MessengerHelper.DefaultSend(Direction.Bid, MessengerTokens.OpenOrderCmdMessage); MessengerHelper.DefaultSend(TabContetMode.QuoteList, MessengerTokens.MainContentChange); } ); } } private bool _isShowListing; /// /// 是否显示挂牌 /// public bool IsShowListing { get { return _isShowListing; } set { Set(() => IsShowListing, ref _isShowListing, value); } } public RelayCommand ListingCommand { get { return new RelayCommand(() => { MessengerHelper.DefaultSend(Direction.Ask, MessengerTokens.OrderListingToken); }); } } public bool IsBidAskVbs { get { return !IsShowListing && UserManager.GetCurrentLayoutStyle() != LayoutStyle.Tradition;// 传统模式,就不需要显示了 } } /// /// 交易设置 /// public RelayCommand TradeSetCommand { get { return new RelayCommand(() => { // MessengerHelper.DefaultSend(Direction.Bid, MessengerTokens.OpenOrderCmdMessage); var tradeSet = new TradeParamSetView() { Owner = System.Windows.Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; tradeSet.ShowDialog(); }); } } /// /// 是否为已使用交易账号登录 /// public bool IsAccountLogin { get { return UserManager.IsAccountLogin; } } private bool _isTradeVisible = false; /// /// 是否显示交易数据 /// public bool IsTradeVisible { get { return _isTradeVisible; } set { Set(() => IsTradeVisible, ref _isTradeVisible, value); MessengerHelper.DefaultSend(value, MessengerTokens.SetHideExpandTradeToken); } } /// /// 刷新当前命令 /// public RelayCommand RefreshCommand { get { return new RelayCommand(() => { MessengerHelper.DefaultSend(string.Empty, MessengerTokens.OrderRefresh); }, () => { //todo:临时处理交易对象不一致问题 if (CurrentTradeAccount != UserManager.CurrentTradeAccount) { CurrentTradeAccount = UserManager.CurrentTradeAccount; } IsMemberTrade = UserManager.IsMonitorMember(); //RaisePropertyChanged(() => IsHiddenWithoutFullPay); //RaisePropertyChanged(() => IsHiddenWithoutMagin); return true; }); } } #endregion /// /// 买出命令 /// public RelayCommand SellCommand { get { return new RelayCommand(() => { CacheManager.FromType = eOrderFormType.Commom;//顶部买卖按钮与挂牌无关 var order = new OrderMessage() { Direction = Direction.Ask, OrderPriceMode = ePriceMode.PRICEMODE_MARKET }; MessengerHelper.DefaultSend(order, MessengerTokens.OrderMessageToken); }, () => CanCommandEnable(MenuCommandType.Sellout)); } } public RelayCommand CancelCommand { get { return new RelayCommand(() => { // MessengerHelper.DefaultSend(TradeTreeMenu.CancelOrder, MessengerTokens.CancalOrder); var orderDetail = SimpleIoc.Default.GetInstance(); orderDetail.CancelHoldingCammand.Execute(null); } ); } } /// /// 持仓单 /// public RelayCommand HoldCommand { get { return new RelayCommand(() => { MessengerHelper.DefaultSend(MenuCommandType.Position, MessengerTokens.MenuSelectChange); }); } } /// /// 命令类型 /// /// /// public bool CanCommandEnable(MenuCommandType commandType) { if (UserManager.TradeFuncMenus != null && UserManager.TradeFuncMenus.Any()) { var tradeFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == commandType.ToString()); if (tradeFunc != null) { return tradeFunc.IsEnabled; } } return false; } /// /// 当前选择的账号 /// public TradeAccount CurrentTradeAccount { get { return _currentTradeAccount; } set { var flag = _currentTradeAccount == null || value == null || _currentTradeAccount.Equals(value); _currentTradeAccount = value; Application.Current.Dispatcher.BeginInvoke(new Action(() => { RaisePropertyChanged(() => CurrentTradeAccount); if (flag) return; UserManager.CurrentTradeAccount = value; })); } } private List _quoteGoodses; /// /// 持仓汇总商品 /// public List QuoteGoodses { get { return _quoteGoodses; } set { Set(() => QuoteGoodses, ref _quoteGoodses, value); } } private bool _isCancelEnable; /// /// 撤单是否可用 /// public bool IsCancelEnable { get { return _isCancelEnable; } set { Set(() => IsCancelEnable, ref _isCancelEnable, value); } } #region 是否隐藏风险率 private bool isNeedChecked; private bool _isHiddenWithoutFullPay; private bool isNeedCheckedGuest; /// /// 所有市场没有保证金模式的商品,则不显示:1) 账号信息行的“风险率” 2)资金信息的“风险率”列 /// public bool IsHiddenWithoutFullPay { get { //if (isNeedChecked) //{ // return _isHiddenWithoutFullPay; //} //if (isNeedCheckedGuest) //{ // return _isHiddenWithoutFullPay; //} if (CacheManager.CacheGoodsBaseInfos == null || !CacheManager.CacheGoodsBaseInfos.Any()) { return false; } _isHiddenWithoutFullPay = CacheManager.CacheGoodsBaseInfos.Any((item) => item.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN); //isNeedChecked = true; if (UserManager.IsAccountLogin) { isNeedChecked = true; isNeedCheckedGuest = false; } else { isNeedChecked = false; isNeedCheckedGuest = true; } return _isHiddenWithoutFullPay; } } private bool isNeedCheckedMagin; private bool _isHiddenWithoutMagin; private bool isNeedCheckedMaginGuest; /// /// 所有市场没有全额的商品,则不显示 /// public bool IsHiddenWithoutMagin { get { //if (isNeedCheckedMagin) //{ // return _isHiddenWithoutMagin; //} //if (isNeedCheckedMaginGuest) //{ // return _isHiddenWithoutMagin; //} if (CacheManager.CacheGoodsBaseInfos == null || !CacheManager.CacheGoodsBaseInfos.Any()) { return false; } _isHiddenWithoutMagin = CacheManager.CacheGoodsBaseInfos.Any((item) => item.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY); //isNeedCheckedMagin = true; if (UserManager.IsAccountLogin) { isNeedCheckedMagin = true; isNeedCheckedMaginGuest = false; } else { isNeedCheckedMagin = false; isNeedCheckedMaginGuest = true; } return _isHiddenWithoutMagin; } } #endregion #endregion #region 构造函数 public TradeHeaderViewModel() { _orderService = SimpleIoc.Default.GetInstance(); _currentTradeAccount = UserManager.CurrentTradeAccount; #region 是否隐藏风险率逻辑 //所有市场=》没有保证金模式的商品 // IsHiddenWithoutFullPay = CacheManager.CacheGoodsBaseInfos.Any((item) => item.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN); #endregion MessengerHelper.DefaultRegister(this, MessengerTokens.CancelOrderEnable, (isEnable) => IsCancelEnable = isEnable ); MessengerHelper.DefaultRegister(this, MessengerTokens.UpdateTradeAccount, (account) => { ///账号信息对象改变时更新当前对象与缓存的一致 if (_currentTradeAccount!=null&&_currentTradeAccount != UserManager.CurrentTradeAccount) { UserManager.CurrentTradeAccount.MemberAccountInfo = _currentTradeAccount.MemberAccountInfo; } CurrentTradeAccount = UserManager.CurrentTradeAccount; IsMemberTrade = UserManager.IsMonitorMember(); }); MessengerHelper.DefaultRegister(this, MessengerTokens.MemberRolesToken, (val) => { IsMemberTrade = val; }); //锁屏控制是否显示交易数据 MessengerHelper.DefaultRegister(this, MessengerTokens.LockScreenSetHideExpandTradeToken, (val) => { IsTradeVisible = val; }); // MessengerHelper.DefaultRegister(this, MessengerTokens.ShowChartMsg, (isShow) => IsShowCycles = isShow); ////显示图表 } #endregion #region Method #endregion } }