| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using GalaSoft.MvvmLight.Messaging;
- using Muchinfo.MTPClient.Data.DTO;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Infrastructure.Cache;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- namespace Muchinfo.MTPClient.Quotation.ViewModels
- {
- public class QuoteBoardViewModel : ViewModelBase
- {
- #region Fields
- private IGoodsService _goodsService;
- private IFavoriteService _ifavoriteService;
- private QuoteGoodsDTO _goodsItem;
- /// <summary>
- /// 数据集合
- /// </summary>
- private ObservableCollection<QuoteGoodsDTO> _itemsSource;
- private RelayCommand<QuoteGoodsDTO> _sellCommand;
- private RelayCommand<QuoteGoodsDTO> _buyCommand;
- #endregion Fields
- private bool _isVisibilityGoodsOfPAndX = false;
- /// <summary>
- /// 是否显示P+X商品数据源LIST
- /// </summary>
- public bool IsVisibilityGoodsOfPAndX
- {
- get
- {
- return _isVisibilityGoodsOfPAndX && (UserManager.CurrentGroupHasGoods && IsDeliveryVisible);
- }
- set
- {
- Set(() => IsVisibilityGoodsOfPAndX, ref _isVisibilityGoodsOfPAndX, value);
- }
- }
- private string _PDeliveryGoodsName;
- /// <summary>
- /// P交割模式商品
- /// </summary>
- public string PDeliveryGoodsName
- {
- get
- {
- return _PDeliveryGoodsName;
- }
- set
- {
- Set(() => PDeliveryGoodsName, ref _PDeliveryGoodsName, value);
- }
- }
- private eDeliveryContractLink _relationMode;
- /// <summary>
- /// 关联模式
- /// </summary>
- public eDeliveryContractLink RelationMode
- {
- get
- {
- return _relationMode;
- }
- set
- {
- Set(() => RelationMode, ref _relationMode, value);
- }
- }
- public QuoteGoods SelectedQuoteGoods { get; set; }
- private ObservableCollection<QuoteGoodsDTO> _goodsOfPAndXInfoList = new ObservableCollection<QuoteGoodsDTO>();
- /// <summary>
- /// 选择商品的P+X商品数据源
- /// </summary>
- public ObservableCollection<QuoteGoodsDTO> GoodsOfPandXInfoList
- {
- get
- {
- return _goodsOfPAndXInfoList;
- }
- set
- {
- Set(() => GoodsOfPandXInfoList, ref _goodsOfPAndXInfoList, value);
- }
- }
- #region 是否可交易
- #region P+X 信息显示高度
- private decimal _pXInfoHeight = decimal.Zero;
- /// <summary>
- /// P+X 信息显示高度
- /// </summary>
- public decimal PXInfoHeight
- {
- get
- {
- return _pXInfoHeight;
- }
- set
- {
- Set(() => PXInfoHeight, ref _pXInfoHeight, value);
- }
- }
- #endregion
- public bool IsDeliveryVisible
- {
- get
- {
- return ApplicationParameter.IsDeliveryVisible == 1 && UserManager.IsAccountLogin;
- }
- }
- /// <summary>
- /// 是否买入
- /// </summary>
- public bool IsBidEnable
- {
- get
- {
- //var buyFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == UserManager.GetMenuCommandValue(MenuCommandType.BuyIn));
- var buyFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == MenuCommandType.BuyIn.ToString());
- //买入
- if (buyFunc != null)
- {
- return buyFunc.IsEnabled;
- }
- return false;
- }
- }
- /// <summary>
- /// 是否卖出
- /// </summary>
- public bool IsAskEnable
- {
- get
- {
- //var tradeFunc =UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == UserManager.GetMenuCommandValue(MenuCommandType.Sellout));
- var tradeFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == MenuCommandType.Sellout.ToString());
- //卖出
- if (tradeFunc != null)
- {
- return tradeFunc.IsEnabled;
- }
- return false;
- }
- }
- #endregion
- #region Constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="QuoteDataGridViewModel" /> class.
- /// </summary>
- public QuoteBoardViewModel()
- : base()
- {
- _goodsService = SimpleIoc.Default.GetInstance<IGoodsService>();
- _ifavoriteService = SimpleIoc.Default.GetInstance<IFavoriteService>();
- _sellCommand = new RelayCommand<QuoteGoodsDTO>((dto) =>
- {
- MessengerHelper.DefaultSend<QuoteGoodsDTO>(dto, MessengerTokens.QuoteBoardSelectItemChange);
- MessengerHelper.DefaultSend<QuoteGoodsDTO>(dto, MessengerTokens.QuickSell);
- });
- _buyCommand = new RelayCommand<QuoteGoodsDTO>((dto) =>
- {
- MessengerHelper.DefaultSend<QuoteGoodsDTO>(dto, MessengerTokens.QuoteBoardSelectItemChange);
- MessengerHelper.DefaultSend<QuoteGoodsDTO>(dto, MessengerTokens.QuickBuy);
- });
- //注册消息
- RegisterMessages();
- }
- #endregion Constructors
- #region Properties
- #region Public Properties
- /// <summary>
- /// 获取和设置数据集合
- /// </summary>
- public ObservableCollection<QuoteGoodsDTO> ItemsSource
- {
- get
- {
- return _itemsSource;
- }
- private set
- {
- _itemsSource = value;
- RaisePropertyChanged(() => ItemsSource);
- }
- }
- #endregion Public Properties
- #endregion Properties
- #region Methods
- #region Public Methods
- public RelayCommand<QuoteGoodsDTO> SellCommand
- {
- get { return _sellCommand; }
- }
- public RelayCommand<QuoteGoodsDTO> BuyCommand
- {
- get { return _buyCommand; }
- }
- /// <summary>
- /// 命令类型改变时更新数据集合,并刷新盘面
- /// </summary>
- /// <param name="newType">The new type.</param>
- /// <param name="goodsGroup">The goods group.</param>
- public void RefreshList(MenuCommandType newType, MarketsInfoModel goodsGroup)
- {
- if (_itemsSource != null) ItemsSource.Clear();
- if (goodsGroup.TradeMode == eTradeMode.MySelected)
- {
- var goodsList = _ifavoriteService.GetMyFavoriteGoodses(goodsGroup.MarketID);
- ItemsSource = goodsList == null ? null : _goodsService.ConvertGoodsDtos(goodsList.ToList());
- }
- else
- {
- ItemsSource = _goodsService.GetQuoteGoodsDTOList(newType, goodsGroup);
- }
- ////重新订阅并查询盘面
- UserManager.CurrentGoodsIds = ItemsSource == null ? new List<int>() : ItemsSource.Select(z => (int)z.GoodsId).ToList();
- QuoteProxyHelper.QuoteSubscribe(GoodsFromScr.Trade);
- }
- #endregion Public Methods
- #region Private Methods
- /// <summary>
- /// Registers the resource change.
- /// </summary>
- private void RegisterMessages()
- {
- //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- //{
- // MessengerHelper.DefaultUnregister<string>(this, MessengerTokens.RegisterResourceChange);
- // MessengerHelper.DefaultRegister<string>(this, MessengerTokens.RegisterResourceChange, (e) =>
- // {
- // if (_itemsSource == null || !_itemsSource.Any()) return;
- // foreach (var item in _itemsSource)
- // {
- // if (item == null) continue;
- // item.UpdateNameColor(item.IsSelected);
- // }
- // });
- //}));
- ////注册实时行情消息
- MessengerHelper.QuoteRegister<List<QuoteGoods>>(this,
- MessengerTokens.ReceiveRealTimeQuote, (quoteList) =>
- {
- if (quoteList == null || !quoteList.Any() || _itemsSource == null || !_itemsSource.Any())
- return;
- foreach (var goods in quoteList)
- {
- if (goods == null) continue;
- var item = _itemsSource.FirstOrDefault(z => z.Symbol == goods.Symbol);
- if (item == null) continue;
- item.UpdateFromQuoteGoods(goods);
- }
- //更新X商品行情
- if (this._goodsItem != null)
- {
- SelectGoodsOfPAndX_ItemSource(_goodsItem);
- }
- });
- //MessengerHelper.DefaultRegister<QuoteGoodsDTO>(this, MessengerTokens.SelectGoodsChange, SelectGoodsOfPAndX_ItemSource);
- }
- /// <summary>
- /// 获取选择商品的P+X商品数据源
- /// </summary>
- public void SelectGoodsOfPAndX_ItemSource(QuoteGoodsDTO goodsItem)
- {
- //PXInfoHeight = 23;
- this._goodsItem = goodsItem;
- var quoteGoods = CacheManager.CacheGoodsBaseInfos.FirstOrDefault((item) => item.Symbol == goodsItem.Symbol);
- SelectedQuoteGoods = quoteGoods;
- IsVisibilityGoodsOfPAndX = false;
- var tempPAndXList = CacheManager.AllDeliveryRelationList.Where((item) => item.GoodsId == goodsItem.GoodsId).ToList();
- var dicModel = new List<QuoteGoods>();
- if (tempPAndXList != null && tempPAndXList.Count() > 0)
- {
- if (IsDeliveryVisible)
- {
- IsVisibilityGoodsOfPAndX = true;
- }
- foreach (var relationModel in tempPAndXList)
- {
- RelationMode = relationModel.RelationMode;
- QuoteGoods delivery_Goods = null;
- if (relationModel.RelationMode == eDeliveryContractLink.Normal)
- {
- delivery_Goods = quoteGoods;
- PDeliveryGoodsName = relationModel.deliverygoodsname;
- //PXInfoHeight = 51;
- }
- else if (relationModel.RelationMode == eDeliveryContractLink.PAndX)
- {
- delivery_Goods =
- CacheManager.CacheGoodsBaseInfos.FirstOrDefault((item) => relationModel.RelationGoodsId == item.GoodsId);
- // PXInfoHeight = 108;
- }
- if (delivery_Goods != null)
- {
- delivery_Goods.DeliveryGoodsName = relationModel.deliverygoodsname;
- dicModel.Add(delivery_Goods);
- } //// DeliveryGoodsName
- }
- var goodsDtos = _goodsService.ConvertGoodsDtos(dicModel.ToList());
- GoodsOfPandXInfoList = goodsDtos;
- }
-
- }
- /// <summary>
- /// Cleanups this instance.
- /// </summary>
- public override void Cleanup()
- {
- base.Cleanup();
- _itemsSource = null;
- }
- #endregion Private Methods
- #endregion Methods
- }
- }
|