| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- 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
- {
- /// <summary>
- /// TraditionLayout.xaml 的交互逻辑
- /// </summary>
- public partial class TraditionLayout : UserControl
- {
- private IFavoriteService _ifavoriteService;
- public TraditionLayout()
- {
- LogInfoHelper.WriteInfo("TraditionLayout");
- InitializeComponent();
- MessengerHelper.DefaultRegister<string>(this, MessengerTokens.SaveLayout, (s) =>
- {
- ////保存布局
- var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
- if (homeView.IsTradeVisible)
- {
- SaveLayout();
- }
- });
- this.Loaded += TraditionLayout_Loaded;
- if (UserManager.IsAccountLogin)
- {
- this.Unloaded += TraditionLayout_Unloaded;
- }
- _ifavoriteService = SimpleIoc.Default.GetInstance<IFavoriteService>();
- }
- /// <summary>
- /// 获取本地配置
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
- private void TraditionLayout_Loaded(object sender, RoutedEventArgs e)
- {
- var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
- if (UserManager.IsAccountLogin && homeView.IsTradeVisible)
- {
- MessengerHelper.DefaultRegister<MarketsInfoModel>(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;
- }
- }
- /// <summary>
- /// 保存配置
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
- private void TraditionLayout_Unloaded(object sender, RoutedEventArgs e)
- {
- var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
- if (UserManager.IsAccountLogin && homeView.IsSaveLayout)
- {
- ////保存布局
- SaveLayout();
- }
-
- MessengerHelper.DefaultUnregister(this);
- }
- /// <summary>
- /// 保存布局
- /// </summary>
- 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;
- }
- }
- }
|