//---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/6/18 17:43:11 //Author //Description Create //---------------------------------------------------------------- using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Infrastructure.Cache; using Muchinfo.MTPClient.Infrastructure.Helpers; using System; using System.Collections.Generic; using System.Linq; using System.Windows; namespace Muchinfo.MTPClient.Analysis.ViewModels { public class PirceCardViewModel : ViewModelBase, IDisposable { private QuoteGoods _currentGoods; public PirceCardViewModel(QuoteGoods goods) { Goods = goods; //RegisterMessage(); //InitData(); } /// /// 当前商品 /// public QuoteGoods Goods { get { return _currentGoods; } set { bool isupdate = _currentGoods == null || _currentGoods.Equals(value); Set(() => Goods, ref _currentGoods, value); if (isupdate) { RegisterMessage(); InitData(); //MessengerHelper.DefaultSend(value, MessengerTokens.GoodsChartChange); } } } /// /// 初始化数据 /// #region 是否显示换手率 private void InitData() { HiddenDataByMarket(); } /// /// 隐藏数据逻辑 /// private void HiddenDataByMarket() { if (_currentGoods != null ) switch (_currentGoods.TradeMode) { case eTradeMode.TRADEMODE_MARKETMAKE: case eTradeMode.TRADEMODE_BIDDING: case eTradeMode.TRADEMODE_LISTING_SELECT: IsVisibilityTurnoverRate = Visibility.Visible; break; case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE: //换手率混合市场应隐藏 IsVisibilityTurnoverRate = Visibility.Collapsed; break; default: IsVisibilityTurnoverRate = Visibility.Visible; break; } } private Visibility _isVisibilityTurnoverRate = Visibility.Visible; /// /// 是否显示换手率- /// public Visibility IsVisibilityTurnoverRate { get { return _isVisibilityTurnoverRate; } set { Set(() => IsVisibilityTurnoverRate, ref _isVisibilityTurnoverRate, value); } } #endregion private List _bidCommissions; /// /// 显示买入档 /// public List BidCommissions { get { return _bidCommissions; } set { Set(() => BidCommissions, ref _bidCommissions, value); } } private List _askCommissions; /// /// 显示卖出档 /// public List AskCommissions { get { return _askCommissions; } set { Set(() => AskCommissions, ref _askCommissions, value); } } /// /// 设置买卖档 /// /// if set to true [bid]. /// The commissions. /// List{Commission}. private List SortCommissions(bool bid, Commission[] commissions, string formatStr) { var commissionLsit = new List(); int index = 1; foreach (var commission in commissions) { commission.Index = index; commission.FormatString = formatStr; commissionLsit.Add(commission); index++; } if (!bid) { commissionLsit = commissionLsit.OrderByDescending((item) => item.Index).ToList(); } return commissionLsit; } private void RegisterMessage() { if (Goods.GoodsParameters.TradeMode == eTradeMode.TRADEMODE_BIDDINGMARKETMAKE || Goods.GoodsParameters.TradeMode != eTradeMode.TRADEMODE_BIDDINGMARKETMAKE) { AskCommissions = SortCommissions(false, Goods.AskList, Goods.FormatPrice); BidCommissions = SortCommissions(true, Goods.BidList, Goods.FormatPrice); MessengerHelper.DefaultUnregister>(this, MessengerTokens.ReceiveRealTimeQuote); MessengerHelper.QuoteRegister>(this, MessengerTokens.ReceiveRealTimeQuote, (quoteList) => { if (quoteList == null || !quoteList.Any()) return; foreach (var item in quoteList) { if (item == null) continue; if (Goods.Symbol.ToLower() == item.Symbol.ToLower()) { AskCommissions = SortCommissions(false, item.AskList, Goods.FormatPrice); BidCommissions = SortCommissions(true, item.BidList, Goods.FormatPrice); } } }); } } public void Dispose() { this.Cleanup(); } /// /// 下一商品 /// public RelayCommand NextCommand { get { return new RelayCommand(() => { MessengerHelper.DefaultSend(true, MessengerTokens.ChartGoodsChange); }, IsCanNext); } } /// /// 前一个商品 /// public RelayCommand ForwordCommand { get { return new RelayCommand(() => { MessengerHelper.DefaultSend(false, MessengerTokens.ChartGoodsChange); }, IsCanForword); } } /// /// 是否可前一个 /// /// private bool IsCanForword() { if (_currentGoods == null) { return false; } var goodsList = CacheManager.CacheGoodsBaseInfos.Where((item) => item.TradeMode != eTradeMode.TRADEMODE_SALE).ToList(); if (!goodsList.Any()) { return false; } var index= goodsList.FindIndex((item) => _currentGoods.Symbol == item.Symbol); return index!=-1&&index != 0; ///当前是否为第一个 } /// /// 是否可下一个商品 /// /// private bool IsCanNext() { if (_currentGoods == null) { return false; } var goodsList = CacheManager.CacheGoodsBaseInfos.Where((item) => item.TradeMode != eTradeMode.TRADEMODE_SALE).ToList(); if (!goodsList.Any()) { return false; } var index = goodsList.FindIndex((item) => _currentGoods.Symbol == item.Symbol); return index != -1 && index != goodsList.Count-1; ///当前是否为第一个 } } }