DeliveryCompleteViewModel.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //----------------------------------------------------------------
  6. //Module Name: $safeprojectname$
  7. //Purpose:
  8. //CopyRight: Muchinfo
  9. //History:
  10. //----------------------------------------------------------------
  11. //DateTime 2016/12/27 20:05:44
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using GalaSoft.MvvmLight.Command;
  16. using GalaSoft.MvvmLight.Ioc;
  17. using Muchinfo.MTPClient.Data;
  18. using Muchinfo.MTPClient.Data.Enums;
  19. using Muchinfo.MTPClient.Data.Model.Delivery;
  20. using Muchinfo.MTPClient.Infrastructure.Helpers;
  21. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  22. using Muchinfo.MTPClient.Infrastructure.Utilities;
  23. using Muchinfo.MTPClient.Infrastructure.Windows;
  24. using Muchinfo.MTPClient.IService;
  25. namespace Muchinfo.MTPClient.Delivery.ViewModels
  26. {
  27. public class DeliveryCompleteViewModel : QueryPanelModelBase
  28. {
  29. private IDeliveryService _deliveryService;
  30. public DeliveryCompleteViewModel()
  31. {
  32. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  33. }
  34. #region "接口重写/Interface implementation Or override"
  35. /// <summary>
  36. /// 初始化注册消息
  37. /// </summary>
  38. public override void RegisterMessage()
  39. {
  40. EndTime = ApplicationParameter.ServerTimeNow;
  41. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
  42. RefreshCommand.Execute(null);
  43. }
  44. public override void UnRegisterMessage()
  45. {
  46. MessengerHelper.DefaultUnregister(this);
  47. }
  48. /// <summary>
  49. /// 查询交收申报单
  50. /// </summary>
  51. public override void RefreshContent()
  52. {
  53. if (!Vailed())
  54. {
  55. return;
  56. }
  57. IsBusy = true;
  58. var accountid = UserManager.CurrentTradeAccount.AccountId;
  59. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  60. //{
  61. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  62. //}
  63. _deliveryService.QueryDeliveryComplete(accountid, StartTime.Date, EndTime.Date.AddHours(24), MarketOrderSuccess, QueryErrorCallback);
  64. }
  65. #endregion "Interface implementation Or override"
  66. #region "Public Properties To Get/Set "
  67. #region 开始时间
  68. private DateTime startTime;
  69. /// <summary>
  70. /// 开始时间
  71. /// </summary>
  72. public DateTime StartTime
  73. {
  74. get { return startTime; }
  75. set { Set(() => StartTime, ref startTime, value); }
  76. }
  77. #endregion
  78. #region 结束时间
  79. private DateTime _endTime;
  80. /// <summary>
  81. /// 结束时间
  82. /// </summary>
  83. public DateTime EndTime
  84. {
  85. get { return _endTime; }
  86. set { Set(() => EndTime, ref _endTime, value); }
  87. }
  88. #endregion
  89. private List<DeliveryCompleteModel> _deliveryCompleteModels;
  90. public List<DeliveryCompleteModel> DeliveryCompleteModels
  91. {
  92. get { return _deliveryCompleteModels; }
  93. set { Set(() => DeliveryCompleteModels, ref _deliveryCompleteModels, value); }
  94. }
  95. #endregion "Public Properties To Get/Set "
  96. #region 重置查询时间命令Command
  97. private RelayCommand _resetCommand;
  98. /// <summary>
  99. /// Gets the ResetCommand.
  100. /// </summary>
  101. public RelayCommand ResetCommand
  102. {
  103. get
  104. {
  105. return _resetCommand
  106. ?? (_resetCommand = new RelayCommand(
  107. () =>
  108. {
  109. EndTime = ApplicationParameter.ServerTimeNow;
  110. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
  111. }));
  112. }
  113. }
  114. #endregion
  115. #region "Other Methods like Validated"
  116. /// <summary>
  117. /// 数据验证
  118. /// </summary>
  119. /// <returns></returns>
  120. private bool Vailed()
  121. {
  122. if (StartTime > EndTime)
  123. {
  124. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_StartEnd, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  125. return false;
  126. }
  127. else if ((EndTime - StartTime).Days > 30)
  128. {
  129. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_Over30days, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  130. return false;
  131. }
  132. return true;
  133. }
  134. #endregion "Other Methods like Validated"
  135. /// <summary>
  136. /// 查询成功返回
  137. /// </summary>
  138. /// <param name="orders"></param>
  139. protected void MarketOrderSuccess(List<DeliveryCompleteModel> orders)
  140. {
  141. DeliveryCompleteModels = orders;
  142. IsBusy = false;
  143. }
  144. /// <summary>
  145. /// 查询失败返回
  146. /// </summary>
  147. /// <param name="errorEntity"></param>
  148. public override void QueryErrorCallback(ErrorEntity errorEntity)
  149. {
  150. IsBusy = false;
  151. var errorMsg = string.Format("{0}:{1}", errorEntity.RequestFunc, ErrorManager.FormatErrorMsg(errorEntity)); //错误信息显示到状态
  152. MessengerHelper.DefaultSend(errorMsg, MessengerTokens.ErrorMessage);
  153. // base.QueryErrorCallback();
  154. }
  155. }
  156. }