DistributeBallotViewModel.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using GalaSoft.MvvmLight.Command;
  2. using GalaSoft.MvvmLight.Ioc;
  3. //----------------------------------------------------------------
  4. //Module Name: $safeprojectname$
  5. //Purpose:
  6. //CopyRight: Muchinfo
  7. //History:
  8. //----------------------------------------------------------------
  9. //DateTime 2016/6/21 13:38:33
  10. //Author
  11. //Description Create
  12. //----------------------------------------------------------------
  13. using GalaSoft.MvvmLight.Messaging;
  14. using Muchinfo.MTPClient.Data;
  15. using Muchinfo.MTPClient.Data.Enums;
  16. using Muchinfo.MTPClient.Data.Model.Account;
  17. using Muchinfo.MTPClient.Data.Model.Sale;
  18. using Muchinfo.MTPClient.Infrastructure.Helpers;
  19. using Muchinfo.MTPClient.Infrastructure.Utilities;
  20. using Muchinfo.MTPClient.Infrastructure.Windows;
  21. using Muchinfo.MTPClient.IService;
  22. using System.Collections.Generic;
  23. using System.Linq;
  24. using System.Windows;
  25. namespace Muchinfo.MTPClient.Sale.ViewModels
  26. {
  27. /// <summary>
  28. /// 配号中签
  29. /// </summary>
  30. public class DistributeBallotViewModel : QueryPanelModelBase
  31. {
  32. #region "=========私有成员/Private Data Members"
  33. protected ISaleService _saleService;
  34. #endregion "Private Data Members"
  35. #region "=========构造函数/Constructor/Initialization"
  36. public DistributeBallotViewModel()
  37. {
  38. this._saleService = SimpleIoc.Default.GetInstance<ISaleService>();
  39. }
  40. #endregion "Constructor/Initialization"
  41. #region "=========接口重写/Interface implementation Or override"
  42. public override void RegisterMessage()
  43. {
  44. RefreshCommand.Execute(null);
  45. MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.OrderNotify);
  46. MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.OrderNotify, (e) =>
  47. {
  48. RefreshCommand.Execute(null);
  49. });
  50. }
  51. public override void UnRegisterMessage()
  52. {
  53. MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.OrderNotify);
  54. }
  55. public override void RefreshContent()
  56. {
  57. IsBusy = true;
  58. var queryCommonParams = new List<QueryCommonParam>();
  59. var accountid = UserManager.CurrentTradeAccount.AccountId;
  60. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  61. //{
  62. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  63. //}
  64. queryCommonParams.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = accountid + string.Empty });
  65. queryCommonParams.Add(new QueryCommonParam() { ParamKey = "Status", ParamValue = (int)eCommonResult.COMMONRESULT_OK + string.Empty });
  66. _saleService.QueryAccountDistributeBallot(queryCommonParams, MarketOrderSuccess, QueryErrorCallback);
  67. }
  68. #endregion "Interface implementation Or override"
  69. #region "=========公共属性/Public Properties To Get/Set "
  70. #region 数据源
  71. private List<DistributeBallot> _itemSource;
  72. public List<DistributeBallot> ItemSource
  73. {
  74. get { return _itemSource; }
  75. set { Set(() => ItemSource, ref _itemSource, value); }
  76. }
  77. #endregion
  78. #region 当前选择配号中签
  79. private DistributeBallot _currentDistributeBallotItem;
  80. /// <summary>
  81. /// 当前选择配号中签
  82. /// </summary>
  83. public DistributeBallot CurrentDistributeBallotItem
  84. {
  85. get
  86. {
  87. return _currentDistributeBallotItem;
  88. }
  89. set
  90. {
  91. Set(() => CurrentDistributeBallotItem, ref _currentDistributeBallotItem, value);
  92. }
  93. }
  94. #endregion
  95. #region 是否显示查看详细
  96. private Visibility _isVisibility_CheckSeeMoreDetail = Visibility.Collapsed;
  97. /// <summary>
  98. /// 是否显示查看详细
  99. /// </summary>
  100. public Visibility IsVisibility_CheckSeeMoreDetail
  101. {
  102. get
  103. {
  104. return _isVisibility_CheckSeeMoreDetail;
  105. }
  106. set
  107. {
  108. Set(() => IsVisibility_CheckSeeMoreDetail, ref _isVisibility_CheckSeeMoreDetail, value);
  109. }
  110. }
  111. #endregion
  112. #endregion "Public Properties To Get/Set "
  113. #region "=========公共命令/Public Commands"
  114. #region 查看详情
  115. private RelayCommand<DistributeBallot> _seeMoreDetailCommand;
  116. /// <summary>
  117. /// 查看详情
  118. /// </summary>
  119. public RelayCommand<DistributeBallot> SeeMoreDetailCommand
  120. {
  121. get
  122. {
  123. return _seeMoreDetailCommand
  124. ?? (_seeMoreDetailCommand = new RelayCommand<DistributeBallot>(
  125. p =>
  126. {
  127. MessengerHelper.DefaultSend(CurrentDistributeBallotItem, MessengerTokens.DistributeBallotDetail);
  128. }, CheckSeeMoreDetail));
  129. }
  130. }
  131. #endregion
  132. #endregion "Public Commands"
  133. #region "=========私有方法/Private Methods"
  134. protected void MarketOrderSuccess(List<DistributeBallot> orders)
  135. {
  136. #region 重构数据源
  137. //多个中签尾号,相同委托单号,只显示一个,中签尾号以逗号隔开
  138. Dictionary<string, DistributeBallot> dicList = new Dictionary<string, DistributeBallot>();
  139. List<DistributeBallot> FilterDistributeBallotList = new List<DistributeBallot>();
  140. if (orders != null && orders.Any())
  141. {
  142. string orderid = string.Empty;
  143. string winTailNo = string.Empty;
  144. foreach (var item in orders.OrderBy(x => x.OrderId))
  145. {
  146. if (orderid == string.Empty)
  147. {
  148. orderid = item.OrderId.ToString();
  149. winTailNo = item.WINTAILNO;
  150. dicList.Add(item.OrderId.ToString(), item);
  151. }
  152. else if (orderid == item.OrderId.ToString())
  153. {
  154. item.WINTAILNO = winTailNo = item.WINTAILNO + "," + winTailNo;
  155. dicList.Remove(item.OrderId.ToString());
  156. dicList.Add(item.OrderId.ToString(), item);
  157. }
  158. else if (orderid != item.OrderId.ToString())
  159. {
  160. orderid = item.OrderId.ToString();
  161. winTailNo = item.WINTAILNO;
  162. dicList.Add(item.OrderId.ToString(), item);
  163. }
  164. }
  165. }
  166. if (dicList != null && dicList.Any())
  167. {
  168. foreach (var item in dicList)
  169. {
  170. FilterDistributeBallotList.Add(item.Value);
  171. }
  172. }
  173. #endregion
  174. ItemSource = FilterDistributeBallotList.OrderByDescending((item) => item.OrderTime).ToList();
  175. IsBusy = false;
  176. }
  177. #endregion "Private Methods"
  178. #region "=========其它方法/Other Methods"
  179. /// <summary>
  180. /// 检查是否可查看详细
  181. /// </summary>
  182. /// <returns></returns>
  183. private bool CheckSeeMoreDetail(DistributeBallot order)
  184. {
  185. bool result = false;
  186. IsVisibility_CheckSeeMoreDetail = Visibility.Collapsed;
  187. if (this.CurrentDistributeBallotItem != null)
  188. {
  189. IsVisibility_CheckSeeMoreDetail = Visibility.Visible;
  190. result = true;
  191. }
  192. return result;
  193. }
  194. #endregion "Other Methods"
  195. }
  196. }