TraditionLayout.xaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Muchinfo.MTPClient.Data.Enums;
  15. using Muchinfo.MTPClient.Data.Model.Config;
  16. using Muchinfo.MTPClient.Infrastructure.Helpers;
  17. using Muchinfo.MTPClient.Infrastructure.Utilities;
  18. using Muchinfo.MTPClient.Data.Model;
  19. using Muchinfo.MTPClient.Infrastructure.Cache;
  20. using GalaSoft.MvvmLight.Ioc;
  21. using Muchinfo.MTPClient.IService;
  22. using Muchinfo.MTPClient.Infrastructure.Users;
  23. using Muchinfo.MTPClient.UI.ViewModels;
  24. namespace Muchinfo.MTPClient.UI.Views
  25. {
  26. /// <summary>
  27. /// TraditionLayout.xaml 的交互逻辑
  28. /// </summary>
  29. public partial class TraditionLayout : UserControl
  30. {
  31. private IFavoriteService _ifavoriteService;
  32. public TraditionLayout()
  33. {
  34. LogInfoHelper.WriteInfo("TraditionLayout");
  35. InitializeComponent();
  36. MessengerHelper.DefaultRegister<string>(this, MessengerTokens.SaveLayout, (s) =>
  37. {
  38. ////保存布局
  39. var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
  40. if (homeView.IsTradeVisible)
  41. {
  42. SaveLayout();
  43. }
  44. });
  45. this.Loaded += TraditionLayout_Loaded;
  46. if (UserManager.IsAccountLogin)
  47. {
  48. this.Unloaded += TraditionLayout_Unloaded;
  49. }
  50. _ifavoriteService = SimpleIoc.Default.GetInstance<IFavoriteService>();
  51. }
  52. /// <summary>
  53. /// 获取本地配置
  54. /// </summary>
  55. /// <param name="sender">The source of the event.</param>
  56. /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
  57. private void TraditionLayout_Loaded(object sender, RoutedEventArgs e)
  58. {
  59. var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
  60. if (UserManager.IsAccountLogin && homeView.IsTradeVisible)
  61. {
  62. MessengerHelper.DefaultRegister<MarketsInfoModel>(this, MessengerTokens.SelectGoodsGroupChange,
  63. SelectGoodsGrounpChange);
  64. var userLayout = UserManager.GetLayoutStyle(LayoutStyle.Vertical);
  65. TraditionLayoutGrid.RowDefinitions[3] = new RowDefinition()
  66. {
  67. Height = new GridLength(userLayout.QuoteGridRowLengthValue, userLayout.QuoteGridRowLengthUnitType),
  68. // MinHeight = userLayout.QuoteGridRowMinHeight
  69. };
  70. TraditionLayoutGrid.RowDefinitions[4] = new RowDefinition()
  71. {
  72. Height = new GridLength(userLayout.QueryGridRowLengthValue, userLayout.QueryGridRowLengthUnitType),
  73. // MinHeight = userLayout.QueryGridRowMinHeight
  74. };
  75. homeView.IsSaveLayout = true;
  76. }
  77. else
  78. {
  79. TraditionLayoutGrid.RowDefinitions[4] = new RowDefinition()
  80. {
  81. Height = new GridLength(1, GridUnitType.Auto),
  82. };
  83. homeView.IsSaveLayout = false;
  84. }
  85. ////重新布局
  86. TraditionLayoutGrid.InvalidateMeasure();
  87. }
  88. private void SelectGoodsGrounpChange(MarketsInfoModel goodsGroup)
  89. {
  90. this.OrderFrame.IsEnabled = true;
  91. //不需要Disable下单界面
  92. return;
  93. switch (goodsGroup.TradeMode)
  94. {
  95. case eTradeMode.QuotePAndX:
  96. case eTradeMode.AllGoods:
  97. var countNumAllGoods = CacheManager.CacheGoodsBaseInfos.Count();
  98. if (countNumAllGoods == 0)
  99. {
  100. this.OrderFrame.IsEnabled = false;
  101. }
  102. break;
  103. case eTradeMode.TRADEMODE_MARKETMAKE:
  104. case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
  105. case eTradeMode.TRADEMODE_BIDDING:
  106. var countNumByGroupId = CacheManager.CacheGoodsBaseInfos.Where(x => x.GoodsParameters.SortId == goodsGroup.MarketID).Count();
  107. if (countNumByGroupId == 0)
  108. {
  109. this.OrderFrame.IsEnabled = false;
  110. }
  111. break;
  112. case eTradeMode.TRADEMODE_SALE:
  113. var countSaleNumByGroupId = CacheManager.CacheGoodsBaseInfos.Where(x => x.GoodsParameters.SortId == goodsGroup.MarketID &&
  114. x.GoodsParameters.RunSteps == eRunStep.RUNSTEP_BIDDINGCONTINUOUS).Count();
  115. if (countSaleNumByGroupId == 0)
  116. {
  117. this.OrderFrame.IsEnabled = false;
  118. }
  119. break;
  120. case eTradeMode.MySelected:
  121. if (_ifavoriteService.GetMyFavoriteGoodses(goodsGroup.MarketID) != null)
  122. {
  123. var MySelectedCount = _ifavoriteService.GetMyFavoriteGoodses(goodsGroup.MarketID).Count();
  124. if (MySelectedCount == 0)
  125. {
  126. this.OrderFrame.IsEnabled = false;
  127. }
  128. }
  129. else
  130. {
  131. this.OrderFrame.IsEnabled = false;
  132. }
  133. break;
  134. case eTradeMode.Deposit:
  135. case eTradeMode.TRADEMODE_HANGTAG:
  136. this.OrderFrame.IsEnabled = false;
  137. break;
  138. default:
  139. break;
  140. }
  141. }
  142. /// <summary>
  143. /// 保存配置
  144. /// </summary>
  145. /// <param name="sender">The source of the event.</param>
  146. /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
  147. private void TraditionLayout_Unloaded(object sender, RoutedEventArgs e)
  148. {
  149. var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
  150. if (UserManager.IsAccountLogin && homeView.IsSaveLayout)
  151. {
  152. ////保存布局
  153. SaveLayout();
  154. }
  155. MessengerHelper.DefaultUnregister(this);
  156. }
  157. /// <summary>
  158. /// 保存布局
  159. /// </summary>
  160. private void SaveLayout()
  161. {
  162. UserManager.SaveLayoutStyle(LayoutStyle.Vertical, new UserLayout()
  163. {
  164. QuoteGridRowLengthValue = TraditionLayoutGrid.RowDefinitions[3].Height.Value,
  165. QuoteGridRowLengthUnitType = TraditionLayoutGrid.RowDefinitions[3].Height.GridUnitType,
  166. QuoteGridRowMinHeight = TraditionLayoutGrid.RowDefinitions[3].MinHeight,
  167. QueryGridRowLengthValue = TraditionLayoutGrid.RowDefinitions[4].Height.Value,
  168. QueryGridRowLengthUnitType = TraditionLayoutGrid.RowDefinitions[4].Height.GridUnitType,
  169. QueryGridRowMinHeight = TraditionLayoutGrid.RowDefinitions[4].MinHeight
  170. });
  171. }
  172. private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
  173. {
  174. // btnMouseDown.Focus();
  175. e.Handled = true;
  176. }
  177. }
  178. }