using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model.Config; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Infrastructure.Cache; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.Infrastructure.Users; using Muchinfo.MTPClient.UI.ViewModels; namespace Muchinfo.MTPClient.UI.Views { /// /// TraditionLayout.xaml 的交互逻辑 /// public partial class TraditionLayout : UserControl { private IFavoriteService _ifavoriteService; public TraditionLayout() { LogInfoHelper.WriteInfo("TraditionLayout"); InitializeComponent(); MessengerHelper.DefaultRegister(this, MessengerTokens.SaveLayout, (s) => { ////保存布局 var homeView = SimpleIoc.Default.GetInstance(); if (homeView.IsTradeVisible) { SaveLayout(); } }); this.Loaded += TraditionLayout_Loaded; if (UserManager.IsAccountLogin) { this.Unloaded += TraditionLayout_Unloaded; } _ifavoriteService = SimpleIoc.Default.GetInstance(); } /// /// 获取本地配置 /// /// The source of the event. /// The instance containing the event data. private void TraditionLayout_Loaded(object sender, RoutedEventArgs e) { var homeView = SimpleIoc.Default.GetInstance(); if (UserManager.IsAccountLogin && homeView.IsTradeVisible) { MessengerHelper.DefaultRegister(this, MessengerTokens.SelectGoodsGroupChange, SelectGoodsGrounpChange); var userLayout = UserManager.GetLayoutStyle(LayoutStyle.Vertical); TraditionLayoutGrid.RowDefinitions[3] = new RowDefinition() { Height = new GridLength(userLayout.QuoteGridRowLengthValue, userLayout.QuoteGridRowLengthUnitType), // MinHeight = userLayout.QuoteGridRowMinHeight }; TraditionLayoutGrid.RowDefinitions[4] = new RowDefinition() { Height = new GridLength(userLayout.QueryGridRowLengthValue, userLayout.QueryGridRowLengthUnitType), // MinHeight = userLayout.QueryGridRowMinHeight }; homeView.IsSaveLayout = true; } else { TraditionLayoutGrid.RowDefinitions[4] = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto), }; homeView.IsSaveLayout = false; } ////重新布局 TraditionLayoutGrid.InvalidateMeasure(); } private void SelectGoodsGrounpChange(MarketsInfoModel goodsGroup) { this.OrderFrame.IsEnabled = true; //不需要Disable下单界面 return; switch (goodsGroup.TradeMode) { case eTradeMode.QuotePAndX: case eTradeMode.AllGoods: var countNumAllGoods = CacheManager.CacheGoodsBaseInfos.Count(); if (countNumAllGoods == 0) { this.OrderFrame.IsEnabled = false; } break; case eTradeMode.TRADEMODE_MARKETMAKE: case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE: case eTradeMode.TRADEMODE_BIDDING: var countNumByGroupId = CacheManager.CacheGoodsBaseInfos.Where(x => x.GoodsParameters.SortId == goodsGroup.MarketID).Count(); if (countNumByGroupId == 0) { this.OrderFrame.IsEnabled = false; } break; case eTradeMode.TRADEMODE_SALE: var countSaleNumByGroupId = CacheManager.CacheGoodsBaseInfos.Where(x => x.GoodsParameters.SortId == goodsGroup.MarketID && x.GoodsParameters.RunSteps == eRunStep.RUNSTEP_BIDDINGCONTINUOUS).Count(); if (countSaleNumByGroupId == 0) { this.OrderFrame.IsEnabled = false; } break; case eTradeMode.MySelected: if (_ifavoriteService.GetMyFavoriteGoodses(goodsGroup.MarketID) != null) { var MySelectedCount = _ifavoriteService.GetMyFavoriteGoodses(goodsGroup.MarketID).Count(); if (MySelectedCount == 0) { this.OrderFrame.IsEnabled = false; } } else { this.OrderFrame.IsEnabled = false; } break; case eTradeMode.Deposit: case eTradeMode.TRADEMODE_HANGTAG: this.OrderFrame.IsEnabled = false; break; default: break; } } /// /// 保存配置 /// /// The source of the event. /// The instance containing the event data. private void TraditionLayout_Unloaded(object sender, RoutedEventArgs e) { var homeView = SimpleIoc.Default.GetInstance(); if (UserManager.IsAccountLogin && homeView.IsSaveLayout) { ////保存布局 SaveLayout(); } MessengerHelper.DefaultUnregister(this); } /// /// 保存布局 /// private void SaveLayout() { UserManager.SaveLayoutStyle(LayoutStyle.Vertical, new UserLayout() { QuoteGridRowLengthValue = TraditionLayoutGrid.RowDefinitions[3].Height.Value, QuoteGridRowLengthUnitType = TraditionLayoutGrid.RowDefinitions[3].Height.GridUnitType, QuoteGridRowMinHeight = TraditionLayoutGrid.RowDefinitions[3].MinHeight, QueryGridRowLengthValue = TraditionLayoutGrid.RowDefinitions[4].Height.Value, QueryGridRowLengthUnitType = TraditionLayoutGrid.RowDefinitions[4].Height.GridUnitType, QueryGridRowMinHeight = TraditionLayoutGrid.RowDefinitions[4].MinHeight }); } private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e) { // btnMouseDown.Focus(); e.Handled = true; } } }