using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Ioc; using GalaSoft.MvvmLight.Threading; using Muchinfo.MTPClient.Account.ViewModels; using Muchinfo.MTPClient.Analysis.ViewModels; using Muchinfo.MTPClient.Analysis.Views; using Muchinfo.MTPClient.Analysis.Views.PriceCard; using Muchinfo.MTPClient.Data.DTO; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Data.Model.Analysis; using Muchinfo.MTPClient.Data.Model.Listing; using Muchinfo.MTPClient.Infrastructure.Cache; using Muchinfo.MTPClient.Infrastructure.Enums; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.Interfaces; using Muchinfo.MTPClient.Infrastructure.MessengerArgs; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.Listing.ViewModel; using Muchinfo.MTPClient.Listing.Views; using Muchinfo.MTPClient.Report.Views; using System; using System.Collections.Generic; using System.Linq; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/2/17 17:33:10 //Author //Description Create //---------------------------------------------------------------- using System.Windows; namespace Muchinfo.MTPClient.UI.ViewModels { public class MainContentViewModel : ViewModelBase { private int _oldTabIndex; private IGoodsService _goodsService; private MarketsInfoModel _currentGroup; private SearchCommissionsParameter parameters; public MainContentViewModel() { //DataGrid currentDataGrid = QuoteDataGridHelper.FindChild(Application.Current.MainWindow, "QuoteListDataGrid"); //currentDataGrid.Focus(); //打开内容窗口 // MessengerHelper.DefaultRegister(this, MessengerTokens.AddContentPage, AddContentPage); _goodsService = SimpleIoc.Default.GetInstance(); // _oldTabIndex = 9; TabContetMode = TabContetMode.QuoteList; //todo: 默认显示的,改成由左边标签类型来做实现 //var window = new QuoteListView(null); //window.ShowWindow(); IsShowChart = !UserManager.IsAccountLogin; ////游客登录默认显示图表 MessengerHelper.DefaultRegister(this, MessengerTokens.SelectGoodsChange, SelectGoodsChange); ////此消息不能在Dispatcher线程处理,否则会使左边功能RadioButton显示出错 MessengerHelper.DefaultRegister(this, MessengerTokens.SelectGoodsGroupChange, SelectGoodsGrounpChange, false); MessengerHelper.DefaultRegister(this, MessengerTokens.OpenQuoteChartWindow, (e) => { TabContetMode = TabContetMode.QuoteChart; }); ///主窗口发送F10快捷键命令 MessengerHelper.DefaultRegister(this, MessengerTokens.ChangeGoodsInfo, (e) => { ShowF10(); }); ///主窗口发送五档历史 MessengerHelper.DefaultRegister(this, MessengerTokens.HistoryCommissionsTab, (e) => { this.parameters = e; TabContetMode = TabContetMode.HistoryCommissions; }); /// MessengerHelper.DefaultRegister(this, MessengerTokens.MainContentChange, (e) => { if (e == TabContetMode.QuoteChart) { if (_currentGroup == null || _currentGroup.TradeMode == eTradeMode.TRADEMODE_SALE || _currentGroup.TradeMode == eTradeMode.TRADEMODE_HANGTAG) { return; } } TabContetMode = e; }); ///布局改变时,图表需重新生成 MessengerHelper.DefaultRegister(this, MessengerTokens.UpdateLayoutChange, (layout) => { LogInfoHelper.WriteInfo(" Enter MessengerTokens.UpdateLayoutChange"); if (TabContetMode == TabContetMode.QuoteChart) { if (this.SelectedQuoteGoods != null) { if (Content != null && Content.DataContext is IDisposable) { Content.InputBindings.Clear(); (Content.DataContext as IDisposable).Dispose(); ////清除图表数据,注册消息 if (Content is IDisposable) { (Content as IDisposable).Dispose(); } } // var formchart = new FormChartView(new ChartWindowItem(string.Empty, this.SelectedQuoteGoods, CycleType.Minutes1)); var formchart = new CChartView(new ChartWindowItem(string.Empty, this.SelectedQuoteGoods, CycleType.Minutes1)); Content = formchart; } } }); ////显示历史Tik分笔 MessengerHelper.DefaultRegister(this, MessengerTokens.ShowTikDetail, (goods) => { if (TabContetMode != TabContetMode.QuoteChart) { TabContetMode = TabContetMode.QuoteChart; } var quoteTik =new QuoteTikDetailView(goods); Content = quoteTik; }); ////显示挂牌报价大厅 MessengerHelper.DefaultRegister(this, MessengerTokens.ShowListingBoard, (goods) => { if (TabContetMode != TabContetMode.ListingBoard) { TabContetMode = TabContetMode.ListingBoard; } else { var board = new ListingApplyBoard(goods); Content = board; } }); MessengerHelper.QuoteRegister>(this, MessengerTokens.ReceiveRealTimeQuote, (quoteList) => { //更新账户浮动盈亏 FloatPLExpressions.UpdateAccountTotalFloatPL(); }); MessengerHelper.DefaultRegister(this, MessengerTokens.UpdateAccountFloatPL, (e) => { //更新账户浮动盈亏 FloatPLExpressions.UpdateAccountTotalFloatPL(); }); //调用MOPosition,初始化持仓汇总MOHoldSummaryViewModel, 以便接收头寸变更通知更新持仓汇总缓存 var vm = ViewModelLocator.MOProsition; } private FrameworkElement _contentElement; /// /// 显示内容 /// public FrameworkElement Content { get { return _contentElement; } set { Set(() => Content, ref _contentElement, value); } } private UIElement _GoodsInfoContentElement; /// /// 显示内容 /// public UIElement GoodsInfoContent { get { return _GoodsInfoContentElement; } set { Set(() => GoodsInfoContent, ref _GoodsInfoContentElement, value); } } private UIElement _historyCmContentElement; /// /// 五档历史内容 /// public UIElement HistoryCmContent { get { return _historyCmContentElement; } set { Set(() => HistoryCmContent, ref _historyCmContentElement, value); } } private TabContetMode _tabContetMode; /// /// 当前选择的类型 /// public TabContetMode TabContetMode { get { return _tabContetMode; } set { if ((int)value == -1) return; ////F10弹窗显示 -- 嵌入显示则注释以下代码 if (value == TabContetMode.QuoteGoodsInfo) { MessengerHelper.DefaultSend(TabContetMode.QuoteGoodsInfo, MessengerTokens.ChangeGoodsInfo); return; } if (value != _tabContetMode) { SetSelectTabItem(value); } Set(() => TabContetMode, ref _tabContetMode, value); UserManager.QuotationWindowType = _tabContetMode; } } #region 是否显示行情报价面板 private Visibility _isVisibilityQuoteBorad = Visibility.Visible; /// /// 是否显示行情报价面板 /// public Visibility IsVisibilityQuoteBorad { get { return _isVisibilityQuoteBorad; } set { Set(() => IsVisibilityQuoteBorad, ref _isVisibilityQuoteBorad, value); } } #endregion #region 是否显示K线图面板 private Visibility _isVisibilityKline = Visibility.Collapsed; /// /// 是否显示K线图面板 /// public Visibility IsVisibilityKline { get { return _isVisibilityKline; } set { Set(() => IsVisibilityKline, ref _isVisibilityKline, value); } } #endregion #region 是否显示F10面板 private Visibility _isVisibilityFten = Visibility.Collapsed; /// /// 是否显示F10面板 /// public Visibility IsVisibilityFten { get { return _isVisibilityFten; } set { Set(() => IsVisibilityFten, ref _isVisibilityFten, value); } } #endregion #region 是否显示历史五档内容 private Visibility _isVisibilityHistoryCommissions = Visibility.Collapsed; /// /// 是否显示历史五档内容 /// public Visibility IsVisibilityHistoryCommissions { get { return _isVisibilityHistoryCommissions; } set { Set(() => IsVisibilityHistoryCommissions, ref _isVisibilityHistoryCommissions, value); } } #endregion #region 是否显示历史五档按钮 private Visibility _isVisHistoryCommissionsBtn = Visibility.Collapsed; /// ///是否显示历史五档按钮 /// public Visibility IsVisHistoryCommissionsBtn { get { return _isVisHistoryCommissionsBtn; } set { Set(() => IsVisHistoryCommissionsBtn, ref _isVisHistoryCommissionsBtn, value); } } #endregion #region 是否显示大字报价 private bool _isShowQuoteBoard; /// /// 是否显示大字报价 /// public bool IsShowQuoteBoard { get { var result = ApplicationParameter.IsShowQuoteBoard == 1 && UserManager.IsAccountLogin; //(游客登录不显示大字报价牌); ///是否显示报价牌 if (this._currentGroup == null) { return result; } else { switch (_currentGroup.TradeMode) { case eTradeMode.AllGoods: case eTradeMode.MySelected: case eTradeMode.TRADEMODE_MARKETMAKE: case eTradeMode.TRADEMODE_BIDDING: case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE: break; case eTradeMode.TRADEMODE_SALE: case eTradeMode.Deposit: case eTradeMode.TRADEMODE_HANGTAG: //case eTradeMode.TRADEMODE_AUCTION: //case eTradeMode.TRADEMODE_MALL: result = false; break; default: break; } return result; } } } #endregion #region 是否显示商品资料 private bool _isShowGoodsDetailInfo = false; /// /// 是否显示商品资料 /// public bool IsShowGoodsDetailInfo { get { return _isShowGoodsDetailInfo; } set { Set(() => IsShowGoodsDetailInfo, ref _isShowGoodsDetailInfo, value); } } #endregion /// /// 打开F10 /// private void ShowF10() { string exchHqCode = string.Empty, goodsCode = string.Empty; //F10嵌入显示 //TabContetMode = TabContetMode.QuoteGoodsInfo; if (_currentGroup != null && _currentGroup.TradeMode == eTradeMode.TRADEMODE_HANGTAG) { var viewModel = SimpleIoc.Default.GetInstance(); if (viewModel.CurrentGoods != null) { // exchHqCode = viewModel.CurrentGoods.ExchHqCode; goodsCode = viewModel.CurrentGoods.DeliveryGoodsCode; } } else {//F10弹窗显示 if (this.SelectedQuoteGoods != null) { exchHqCode = SelectedQuoteGoods.ExchHqCode; goodsCode = SelectedQuoteGoods.GoodsCode; } } if (!string.IsNullOrEmpty(ApplicationParameter.FtenAddress)) { DispatcherHelper.RunAsync(() => { var reportView = new F10View(exchHqCode, goodsCode) { Owner = Application.Current.MainWindow }; reportView.ShowDialog(); }); } } public QuoteGoods SelectedQuoteGoods { get; set; } /// /// 选择商品改变 /// /// The goods. private void SelectGoodsChange(QuoteGoodsDTO goods) { var quoteGoods = CacheManager.CacheGoodsBaseInfos.FirstOrDefault((item) => item.Symbol == goods.Symbol); // bool showChart; //if (quoteGoods != null && quoteGoods.GoodsParameters != null) //{ //todo: //if (goods.GoodsParameters.TradeMode == TradeModeType.BidGoods) //{ // showChart = ApplicationParameter.ShowChart == 2; //设置竞价商品才显示图表 //} // } //IsShowChart = ApplicationParameter.ShowChart == 1 || showChart; SelectedQuoteGoods = quoteGoods; if (!UserManager.IsAccountLogin) ////游客登录 { return; } if (string.IsNullOrEmpty(ApplicationParameter.FtenAddress)) { IsShowGoodsDetailInfo = false; } //Application.Current.Dispatcher.BeginInvoke(new Action(() => //{ // var tradeFunc = // UserManager.TradeFuncMenus.FirstOrDefault( // (item) => item.FuncMenuCode == (int) MenuCommandType.Sellout); // if (SelectedQuoteGoods != null &&tradeFunc != null ) // { // if (SelectedQuoteGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY ) // { // var holders = UserManager.GetCacheOrders(); // tradeFunc.IsEnabled = // holders.Any((hold) => hold.GoodsId == goods.GoodsId && hold.Direction == Direction.Bid); // } // else // { // tradeFunc.IsEnabled = true; // } // } //})); //卖出 } /// /// 选择商品组改变时 /// /// private void SelectGoodsGrounpChange(MarketsInfoModel goodsGroup) { IsVisibilityQuoteBorad = Visibility.Visible; IsVisibilityKline = Visibility.Collapsed; IsVisibilityFten = Visibility.Collapsed; UserManager.CurrentGroupHasGoods = false; _currentGroup = goodsGroup; RaisePropertyChanged(() => IsShowQuoteBoard); ////当选择市场改变时从图表切换回到行情列表 if (_tabContetMode == TabContetMode.QuoteChart || _tabContetMode == TabContetMode.QuoteGoodsInfo || _tabContetMode == TabContetMode.HistoryCommissions) { TabContetMode = TabContetMode.QuoteList; } if (!UserManager.IsAccountLogin) ////游客登录都是看有行情商品 { IsShowChart = goodsGroup.TradeMode != eTradeMode.TRADEMODE_SALE; IsChartEnable = true; return; } #region 是否显示挂牌 var instance = SimpleIoc.Default.GetInstance(); var isListingMarket = goodsGroup.TradeMode == eTradeMode.TRADEMODE_HANGTAG; instance.IsShowListing =isListingMarket; IsShowListingBoard = isListingMarket; #endregion var tradeFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == MenuCommandType.Sellout.ToString()); //卖出 var saleFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == MenuCommandType.SaleApply.ToString()); //申购 var buyFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == MenuCommandType.BuyIn.ToString()); //买入 switch (goodsGroup.TradeMode) { case eTradeMode.Deposit: case eTradeMode.TRADEMODE_HANGTAG: IsShowChart = false; if (tradeFunc != null) { tradeFunc.IsEnabled = false; } if (buyFunc != null) //买入是否可用 { buyFunc.IsEnabled = false; } IsShowGoodsDetailInfo = false; break; case eTradeMode.TRADEMODE_SALE: IsShowChart = false; if (tradeFunc != null) { tradeFunc.IsEnabled = false; } if (buyFunc != null) //买入是否可用 { buyFunc.IsEnabled = false; } if (saleFunc != null) { var result = CacheManager.CacheGoodsBaseInfos != null && CacheManager.CacheGoodsBaseInfos.Any( (item) => goodsGroup.MarketID == item.GoodsParameters.SortId && item.GoodsParameters.RunSteps == eRunStep.RUNSTEP_BIDDINGCONTINUOUS); saleFunc.IsEnabled = result; UserManager.CurrentGroupHasGoods = result; } break; case eTradeMode.MySelected: //自选不做特殊处理 //IsShowChart = ApplicationParameter.ShowChart == 1; //var ifavoriteService = SimpleIoc.Default.GetInstance(); //var goodsList = ifavoriteService.GetMyFavoriteGoodses(goodsGroup.MarketID); //bool enable = false; //enable = goodsList != null && _goodsService.ConvertGoodsDtos(goodsList.ToList()).Any(); //if (buyFunc != null) //买入是否可用 //{ // buyFunc.IsEnabled = enable; //} //if (tradeFunc != null) //{ // tradeFunc.IsEnabled = enable; //} //IsChartEnable = enable; ////当前商品组没有商品,不可点图表。 //UserManager.CurrentGroupHasGoods = enable; //break; default: IsShowChart = ApplicationParameter.ShowChart == 1; //var goodsarr = _goodsService.GetQuoteGoodsDTOList(MenuCommandType.MarketQuote, goodsGroup); //var isHasGoods = CacheManager.CacheGoodsBaseInfos != null &&goodsarr!=null&&goodsarr.Any(); //当前商品组无商品时是否可买入 var isHasGoods = CacheManager.CacheGoodsBaseInfos != null && CacheManager.CacheGoodsBaseInfos.Any(); if (tradeFunc != null) { tradeFunc.IsEnabled = isHasGoods; if (buyFunc != null) //买入是否可用 { buyFunc.IsEnabled = isHasGoods; } } if (saleFunc != null) { saleFunc.IsEnabled = false; } IsChartEnable = isHasGoods; ////当前商品组没有商品,不可点图表。 UserManager.CurrentGroupHasGoods = isHasGoods; break; } } /// /// Sets the select tab item. /// /// The tab contet mode. private void SetSelectTabItem(TabContetMode tabContetMode) { ////先发送RadioButton激活通知 MessengerHelper.DefaultSend(tabContetMode, MessengerTokens.ActiveMainRadio); if (Content != null && Content.DataContext is IDisposable) { Content.InputBindings.Clear(); (Content.DataContext as IDisposable).Dispose(); ////清除图表数据,注册消息 } #region 顶部买卖按钮与挂牌无关 //switch (tabContetMode) //{ // case TabContetMode.QuoteList: // case TabContetMode.QuoteGoodsInfo: // case TabContetMode.QuoteBoard: // case TabContetMode.QuoteChart: // MessengerHelper.DefaultSend(true, MessengerTokens.IsShowSellCommondBtn); // MessengerHelper.DefaultSend(true, MessengerTokens.IsShowBuyCommondBtn); // CacheManager.IsHasListingData = true; // MessengerHelper.DefaultSend(true, MessengerTokens.IsEnableBuyAndSellCommondBtn); // break; //} #endregion switch (tabContetMode) { case TabContetMode.QuoteList: CacheManager.FromType = eOrderFormType.Commom; //切换到系统默认的报价牌 //UserManager.QuotationWindowType = QuotationWindowType.List; //WindowHelper.OpenDefaultQuoteListView(false); IsVisibilityQuoteBorad = Visibility.Visible; IsVisibilityKline = Visibility.Collapsed; IsVisibilityFten = Visibility.Collapsed; IsVisHistoryCommissionsBtn=IsVisibilityHistoryCommissions = Visibility.Collapsed; MessengerHelper.DefaultSend(QuotationWindowType.List, MessengerTokens.ChangeQuote); break; #region cancel //case TabContetMode.QuoteList: // //切换到光标选中的(当前)商品合约K线 // // ExecuteCommand(new SysMenuItem(MenuNames.AnalysisCandlestick, MenuCommandType.CandleChart)); // //k线图因为没有执行树形控件的记录当前市场的方法,所以要手动记录当前市场 // MessengerHelper.DefaultSend(MenuCommandType.CandleChart, // MessengerTokens.UpdateCurrentMarketType); // break; //case 2: // //切换到光标选中的(当前)商品合约分时 // // ExecuteCommand(new SysMenuItem(MenuNames.AnalysisTimeSharing, MenuCommandType.TimeSharingChart)); // break; //case 3: // //切换到光标选中的(当前)商品合约实时 // // ExecuteCommand(new SysMenuItem(MenuNames.AnalysisTik, MenuCommandType.TikChart)); // break; #endregion case TabContetMode.QuoteGoodsInfo: CacheManager.FromType = eOrderFormType.Commom; //切换到F10基本资料 ShowF10(); IsVisibilityFten = Visibility.Visible; IsVisibilityQuoteBorad = Visibility.Collapsed; IsVisibilityKline = Visibility.Collapsed; IsVisHistoryCommissionsBtn=IsVisibilityHistoryCommissions = Visibility.Collapsed; break; #region cancel //case 5: // //切换到新闻资讯 // var newsCategory = CacheManager.CacheNewsCategory; // if (newsCategory != null && newsCategory.Any()) // { // var first = newsCategory.FirstOrDefault(); // if (first == null || string.IsNullOrWhiteSpace(first.ClassCode)) return; // WindowHelper.OpenNewsWindow(first.ClassCode); // } // break; //case 6: // //切换到经济数据 // break; //case 8: // MessengerHelper.DefaultSend(TradeTreeMenu.MyInvestmentContract, // MessengerTokens.AccountFunction); // //MessengerHelper.DefaultSend(WindowType.QueryFinacing, // // MessengerTokens.ActiveHomeTab); // break; #endregion case TabContetMode.QuoteBoard: CacheManager.FromType = eOrderFormType.Commom; //大字报价牌 IsVisibilityQuoteBorad = Visibility.Visible; IsVisibilityKline = Visibility.Collapsed; IsVisibilityFten = Visibility.Collapsed; IsVisHistoryCommissionsBtn = IsVisibilityHistoryCommissions = Visibility.Collapsed; MessengerHelper.DefaultSend(QuotationWindowType.Board, MessengerTokens.ChangeQuote); break; case TabContetMode.QuoteChart: CacheManager.FromType = eOrderFormType.Commom; IsVisibilityQuoteBorad = Visibility.Collapsed; IsVisibilityFten = Visibility.Collapsed; IsVisHistoryCommissionsBtn = IsVisibilityHistoryCommissions = Visibility.Collapsed; IsVisibilityKline = Visibility.Visible; //图表 // MessengerHelper.DefaultSend(QuotationWindowType.Board, MessengerTokens.); if (this.SelectedQuoteGoods != null) { // var formchart = new FormChartView(new ChartWindowItem(string.Empty, this.SelectedQuoteGoods, CycleType.Minutes1)); var formchart = new CChartView(new ChartWindowItem(string.Empty, this.SelectedQuoteGoods, CycleType.Minutes1)); Content = formchart; } break; case TabContetMode.ListingBoard: CacheManager.FromType = eOrderFormType.Commom; IsVisibilityQuoteBorad = Visibility.Collapsed; IsVisibilityFten = Visibility.Collapsed; IsVisHistoryCommissionsBtn = IsVisibilityHistoryCommissions = Visibility.Collapsed; IsVisibilityKline = Visibility.Visible; //图表 // MessengerHelper.DefaultSend(QuotationWindowType.Board, MessengerTokens.); var viewModel = SimpleIoc.Default.GetInstance(); if (viewModel.CurrentGoods != null) { var board = new ListingApplyBoard(viewModel.CurrentGoods); Content = board; } break; //历史五档 case TabContetMode.HistoryCommissions: CacheManager.FromType = eOrderFormType.Commom; IsVisibilityQuoteBorad = Visibility.Collapsed; IsVisibilityFten = Visibility.Collapsed; IsVisibilityKline = Visibility.Collapsed; IsVisHistoryCommissionsBtn = IsVisibilityHistoryCommissions = Visibility.Visible; var viewHistoryCommissionsListModel = SimpleIoc.Default.GetInstance(); if (viewHistoryCommissionsListModel != null) { var HistoryCommissionsContent = new HistoryCommissionsList(viewHistoryCommissionsListModel); HistoryCmContent = HistoryCommissionsContent; if (parameters != null) { MessengerHelper.DefaultSend(parameters, MessengerTokens.HistoryCommissions); } } break; } } private bool _isShowChart = true; /// /// 是否显示图表 /// public bool IsShowChart { get { return _isShowChart; } set { Set(() => IsShowChart, ref _isShowChart, value); } } private bool _isChartEnabled; private bool _isShowListingBoard; /// /// 是否显示报价大厅 /// public bool IsShowListingBoard { get { return _isShowListingBoard; } set { Set(() => IsShowListingBoard, ref _isShowListingBoard, value); } } /// /// 是否可用 /// public bool IsChartEnable { get { return _isChartEnabled; } set { Set(() => IsChartEnable, ref _isChartEnabled, value); } } /// /// 交易登录后在初始化的内容 /// public void InitMainPanel() { IsShowChart = ApplicationParameter.ShowChart == 1; } } }