| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- //----------------------------------------------------------------
- //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();
- }
- /// <summary>
- /// 当前商品
- /// </summary>
- 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<QuoteGoods>(value, MessengerTokens.GoodsChartChange);
- }
- }
- }
- /// <summary>
- /// 初始化数据
- /// </summary>
-
- #region 是否显示换手率
- private void InitData()
- {
- HiddenDataByMarket();
- }
- /// <summary>
- /// 隐藏数据逻辑
- /// </summary>
- 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;
- /// <summary>
- /// 是否显示换手率-
- /// </summary>
- public Visibility IsVisibilityTurnoverRate
- {
- get
- {
- return _isVisibilityTurnoverRate;
- }
- set
- {
- Set(() => IsVisibilityTurnoverRate, ref _isVisibilityTurnoverRate, value);
- }
- }
- #endregion
-
- private List<Commission> _bidCommissions;
- /// <summary>
- /// 显示买入档
- /// </summary>
- public List<Commission> BidCommissions
- {
- get { return _bidCommissions; }
- set { Set(() => BidCommissions, ref _bidCommissions, value); }
- }
- private List<Commission> _askCommissions;
- /// <summary>
- /// 显示卖出档
- /// </summary>
- public List<Commission> AskCommissions
- {
- get { return _askCommissions; }
- set { Set(() => AskCommissions, ref _askCommissions, value); }
- }
-
- /// <summary>
- /// 设置买卖档
- /// </summary>
- /// <param name="bid">if set to <c>true</c> [bid].</param>
- /// <param name="commissions">The commissions.</param>
- /// <returns>List{Commission}.</returns>
- private List<Commission> SortCommissions(bool bid, Commission[] commissions, string formatStr)
- {
- var commissionLsit = new List<Commission>();
- 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<List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTimeQuote);
- MessengerHelper.QuoteRegister<List<QuoteGoods>>(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();
- }
- /// <summary>
- /// 下一商品
- /// </summary>
- public RelayCommand NextCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- MessengerHelper.DefaultSend<bool>(true, MessengerTokens.ChartGoodsChange);
- }, IsCanNext);
- }
- }
- /// <summary>
- /// 前一个商品
- /// </summary>
- public RelayCommand ForwordCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- MessengerHelper.DefaultSend<bool>(false, MessengerTokens.ChartGoodsChange);
- }, IsCanForword);
- }
- }
- /// <summary>
- /// 是否可前一个
- /// </summary>
- /// <returns></returns>
- 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; ///当前是否为第一个
- }
- /// <summary>
- /// 是否可下一个商品
- /// </summary>
- /// <returns></returns>
- 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; ///当前是否为第一个
- }
- }
- }
|