QueryDepositApplyViewModel.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 2017/1/12 22:16:38
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using System.Windows;
  16. using System.Windows.Input;
  17. using GalaSoft.MvvmLight.Command;
  18. using GalaSoft.MvvmLight.Ioc;
  19. using Muchinfo.MTPClient.Data;
  20. using Muchinfo.MTPClient.Data.Enums;
  21. using Muchinfo.MTPClient.Data.Model;
  22. using Muchinfo.MTPClient.Data.Model.Delivery;
  23. using Muchinfo.MTPClient.Infrastructure.Helpers;
  24. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  25. using Muchinfo.MTPClient.Infrastructure.Utilities;
  26. using Muchinfo.MTPClient.Infrastructure.Windows;
  27. using Muchinfo.MTPClient.IService;
  28. using Muchinfo.MTPClient.Resources;
  29. using Muchinfo.MTPClient.Data.Model.Account;
  30. namespace Muchinfo.MTPClient.Sale.ViewModels
  31. {
  32. public class QueryDepositApplyViewModel : QueryPanelModelBase
  33. {
  34. #region 开始时间
  35. private DateTime startTime;
  36. /// <summary>
  37. /// 开始时间
  38. /// </summary>
  39. public DateTime StartTime
  40. {
  41. get { return startTime; }
  42. set { Set(() => StartTime, ref startTime, value); }
  43. }
  44. #endregion
  45. #region 结束时间
  46. private DateTime _endTime;
  47. /// <summary>
  48. /// 结束时间
  49. /// </summary>
  50. public DateTime EndTime
  51. {
  52. get { return _endTime; }
  53. set { Set(() => EndTime, ref _endTime, value); }
  54. }
  55. private List<DepositApplyModel> _depositApplyList;
  56. /// <summary>
  57. /// 查询托管申请单据
  58. /// </summary>
  59. public List<DepositApplyModel> DepositApplyList
  60. {
  61. get { return _depositApplyList; }
  62. set { Set(() => DepositApplyList, ref _depositApplyList, value); }
  63. }
  64. private DepositApplyModel _curApplyModel;
  65. /// <summary>
  66. /// 当前选择的单据
  67. /// </summary>
  68. public DepositApplyModel CurApplyModel
  69. {
  70. get { return _curApplyModel; }
  71. set { Set(() => CurApplyModel, ref _curApplyModel, value); }
  72. }
  73. #endregion
  74. #region 重置查询时间命令Command
  75. private RelayCommand _resetCommand;
  76. /// <summary>
  77. /// Gets the ResetCommand.
  78. /// </summary>
  79. public RelayCommand ResetCommand
  80. {
  81. get
  82. {
  83. return _resetCommand
  84. ?? (_resetCommand = new RelayCommand(
  85. () =>
  86. {
  87. EndTime = ApplicationParameter.ServerTimeNow.AddDays(1);
  88. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-29);
  89. }));
  90. }
  91. }
  92. #endregion
  93. #region 撤销命令Command
  94. private RelayCommand _cancelCommand;
  95. public ICommand CancelCommand
  96. {
  97. get
  98. {
  99. if (_cancelCommand == null)
  100. {
  101. _cancelCommand = new RelayCommand(() =>
  102. {
  103. CanceleOrder();
  104. });
  105. }
  106. return _cancelCommand;
  107. }
  108. }
  109. private void CanceleOrder()
  110. {
  111. if (CurApplyModel != null)
  112. {
  113. var accountId = UserManager.CurrentTradeAccount.AccountId;
  114. //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  115. // UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  116. //{
  117. // accountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  118. //}
  119. var orderBuild = new DepositOrder()
  120. {
  121. Accountid = accountId,
  122. BuildType = eBuildType.BUILDTYPE_CLOSE,
  123. StoreinId = CurApplyModel.StoreInId,
  124. };
  125. var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToCancel,
  126. Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips);
  127. if (boxResult == MessageBoxResult.Yes)
  128. {
  129. IsBusy = true;
  130. _depositService.DepositApply(orderBuild, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  131. }
  132. }
  133. }
  134. private RelayCommand _rightRelayCommand;
  135. public RelayCommand RightCancelCommand
  136. {
  137. get
  138. {
  139. if (_rightRelayCommand == null)
  140. {
  141. _rightRelayCommand = new RelayCommand(() =>
  142. {
  143. CanceleOrder();
  144. }, IsCanceledEnable);
  145. }
  146. return _rightRelayCommand;
  147. }
  148. }
  149. private bool IsCanceledEnable()
  150. {
  151. if (CurApplyModel == null)
  152. {
  153. return false;
  154. }
  155. else
  156. {
  157. return CurApplyModel.AuditStatus == eAuditStatus.AUDITSTATUS_CHECKING;
  158. }
  159. }
  160. #endregion
  161. private IDepositService _depositService;
  162. public QueryDepositApplyViewModel()
  163. {
  164. _depositService = SimpleIoc.Default.GetInstance<IDepositService>();
  165. }
  166. /// 撤销成功返回
  167. /// </summary>
  168. /// <param name="order"></param>
  169. private void EntrurstSuccessCallBack(DepositOrder order)
  170. {
  171. IsBusy = false;
  172. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  173. {
  174. MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Account_CancelSuccess,
  175. Client_Resource.Cancel_MessageBox_Title);
  176. //MessageBoxHelper.ShowSuccess(Client_Resource.Order_Success_Result,
  177. // Client_Resource.Cancel_MessageBox_Title);
  178. //if (_openWindow != null)
  179. //{
  180. // _openWindow.Close();
  181. // this.Cleanup();
  182. //}
  183. }));
  184. RefreshContent(); ////更新撤单状态
  185. }
  186. /// <summary>
  187. /// 撤销失败返回
  188. /// </summary>
  189. /// <param name="errorEntity"></param>
  190. private void EntrurstErrorCallBack(ErrorEntity errorEntity)
  191. {
  192. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  193. {
  194. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  195. IsBusy = false;
  196. }));
  197. }
  198. public override void RegisterMessage()
  199. {
  200. EndTime = ApplicationParameter.ServerTimeNow.AddDays(1);
  201. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-29);
  202. //RefreshContent();
  203. RefreshCommand.Execute(null);
  204. MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.DepositOrderToken);
  205. MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.DepositOrderToken, (e) =>
  206. {
  207. RefreshCommand.Execute(null);
  208. });
  209. }
  210. public override void UnRegisterMessage()
  211. {
  212. this.Cleanup();
  213. //base.UnRegisterMessage();
  214. }
  215. public override void RefreshContent()
  216. {
  217. if (Vailed())
  218. {
  219. var accountid = UserManager.CurrentTradeAccount.AccountId;
  220. //if (UserManager.CurrentTradeAccount.FundsAccounts != null &&
  221. // UserManager.CurrentTradeAccount.FundsAccounts.Any())
  222. //{
  223. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  224. //}
  225. _depositService.QueryDepositApply(accountid, startTime, EndTime, QueryDepositApplySuccess, ErrorQuery);
  226. }
  227. }
  228. private void QueryDepositApplySuccess(List<DepositApplyModel> list)
  229. {
  230. IsBusy = false;
  231. DepositApplyList = list;
  232. }
  233. private void ErrorQuery(ErrorEntity errorEntity)
  234. {
  235. IsBusy = false;
  236. ////todo:查询失败
  237. }
  238. #region "Other Methods like Validated"
  239. /// <summary>
  240. /// 数据验证
  241. /// </summary>
  242. /// <returns></returns>
  243. private bool Vailed()
  244. {
  245. if (StartTime > EndTime)
  246. {
  247. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_StartEnd, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  248. return false;
  249. }
  250. else if ((EndTime - StartTime).Days > 30)
  251. {
  252. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_Over30days, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  253. return false;
  254. }
  255. return true;
  256. }
  257. #endregion "Other Methods like Validated"
  258. }
  259. }