| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- 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;
-
- /// <summary>
- /// 当前MenuCommandType
- /// </summary>
- public MenuCommandType _currentMenuType;
- public MenuCommandType CurrentMenuType
- {
- get { return _currentMenuType; }
- set
- {
- Set(() => CurrentMenuType, ref _currentMenuType, value);
- }
- }
- private bool _isMemberTrade;
- /// <summary>
- /// 是否是要监控会员 交易员
- /// </summary>
- public bool IsMemberTrade
- {
- get { return _isMemberTrade; }
- set { Set(() => IsMemberTrade, ref _isMemberTrade, value); }
- }
- #endregion
- #region 属性
- /// <summary>
- /// 账号列表中的字符串表示
- /// </summary>
- public List<TradeAccount> AccountsList
- {
- get
- {
- var listAccount = new List<TradeAccount>();
- if (UserManager.TradeAccounts != null)
- {
- foreach (var tradeAccount in UserManager.TradeAccounts)
- {
- listAccount.Add(tradeAccount);
- }
- }
- return listAccount;
- }
- }
- /// <summary>
- /// 买入命令
- /// </summary>
- 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 工具栏
- /// <summary>
- /// 返回
- /// </summary>
- public RelayCommand BackCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- // MessengerHelper.DefaultSend(Direction.Bid, MessengerTokens.OpenOrderCmdMessage);
- MessengerHelper.DefaultSend(TabContetMode.QuoteList, MessengerTokens.MainContentChange);
-
- } );
- }
- }
- private bool _isShowListing;
- /// <summary>
- /// 是否显示挂牌
- /// </summary>
- 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;// 传统模式,就不需要显示了
- }
- }
- /// <summary>
- /// 交易设置
- /// </summary>
- 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();
- });
- }
- }
- /// <summary>
- /// 是否为已使用交易账号登录
- /// </summary>
- public bool IsAccountLogin
- {
- get { return UserManager.IsAccountLogin; }
- }
- private bool _isTradeVisible = false;
- /// <summary>
- /// 是否显示交易数据
- /// </summary>
- public bool IsTradeVisible
- {
- get { return _isTradeVisible; }
- set
- {
- Set(() => IsTradeVisible, ref _isTradeVisible, value);
- MessengerHelper.DefaultSend(value, MessengerTokens.SetHideExpandTradeToken);
- }
- }
- /// <summary>
- /// 刷新当前命令
- /// </summary>
- 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
- /// <summary>
- /// 买出命令
- /// </summary>
- 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<MOrderDetailViewModel>();
- orderDetail.CancelHoldingCammand.Execute(null);
- } );
- }
- }
-
- /// <summary>
- /// 持仓单
- /// </summary>
- public RelayCommand HoldCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- MessengerHelper.DefaultSend(MenuCommandType.Position, MessengerTokens.MenuSelectChange);
- });
- }
- }
- /// <summary>
- /// 命令类型
- /// </summary>
- /// <param name="commandType"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 当前选择的账号
- /// </summary>
- 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<QuoteGoods> _quoteGoodses;
- /// <summary>
- /// 持仓汇总商品
- /// </summary>
- public List<QuoteGoods> QuoteGoodses
- {
- get { return _quoteGoodses; }
- set { Set(() => QuoteGoodses, ref _quoteGoodses, value); }
- }
- private bool _isCancelEnable;
- /// <summary>
- /// 撤单是否可用
- /// </summary>
- public bool IsCancelEnable
- {
- get { return _isCancelEnable; }
- set
- {
- Set(() => IsCancelEnable, ref _isCancelEnable, value);
- }
- }
-
- #region 是否隐藏风险率
- private bool isNeedChecked;
- private bool _isHiddenWithoutFullPay;
- private bool isNeedCheckedGuest;
- /// <summary>
- /// 所有市场没有保证金模式的商品,则不显示:1) 账号信息行的“风险率” 2)资金信息的“风险率”列
- /// </summary>
- 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;
- /// <summary>
- /// 所有市场没有全额的商品,则不显示
- /// </summary>
- 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<IOrderService>();
- _currentTradeAccount = UserManager.CurrentTradeAccount;
-
- #region 是否隐藏风险率逻辑
- //所有市场=》没有保证金模式的商品
- // IsHiddenWithoutFullPay = CacheManager.CacheGoodsBaseInfos.Any((item) => item.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN);
-
-
- #endregion
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.CancelOrderEnable, (isEnable) =>
- IsCancelEnable = isEnable
- );
-
- MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.UpdateTradeAccount, (account) =>
- {
- ///账号信息对象改变时更新当前对象与缓存的一致
- if (_currentTradeAccount!=null&&_currentTradeAccount != UserManager.CurrentTradeAccount)
- {
- UserManager.CurrentTradeAccount.MemberAccountInfo = _currentTradeAccount.MemberAccountInfo;
- }
- CurrentTradeAccount = UserManager.CurrentTradeAccount;
- IsMemberTrade = UserManager.IsMonitorMember();
- });
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.MemberRolesToken, (val) =>
- {
- IsMemberTrade = val;
- });
- //锁屏控制是否显示交易数据
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.LockScreenSetHideExpandTradeToken, (val) =>
- {
- IsTradeVisible = val;
- });
- // MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.ShowChartMsg, (isShow) => IsShowCycles = isShow); ////显示图表
- }
- #endregion
- #region Method
- #endregion
- }
- }
|