TakaDeliveryGoodsQueryViewModel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Ioc;
  3. using Muchinfo.MTPClient.Data;
  4. using Muchinfo.MTPClient.Data.Enums;
  5. using Muchinfo.MTPClient.Data.Model.Account;
  6. using Muchinfo.MTPClient.Infrastructure.Helpers;
  7. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  8. using Muchinfo.MTPClient.Infrastructure.Utilities;
  9. using Muchinfo.MTPClient.Infrastructure.Windows;
  10. using Muchinfo.MTPClient.IService;
  11. using Muchinfo.MTPClient.Resources;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Windows;
  15. using System.Linq;
  16. using Muchinfo.MTPClient.Data.Model.Delivery;
  17. using GalaSoft.MvvmLight.Command;
  18. using System.Windows.Input;
  19. namespace Muchinfo.MTPClient.Delivery.ViewModels
  20. {
  21. /// <summary>
  22. /// 提货查询
  23. /// </summary>
  24. public class TakaDeliveryGoodsQueryViewModel : QueryPanelModelBase
  25. {
  26. #region "=========私有成员/Private Data Members"
  27. protected IDeliveryService _deliveryService;
  28. #endregion "Private Data Members"
  29. #region "=========构造函数/Constructor/Initialization"
  30. public TakaDeliveryGoodsQueryViewModel()
  31. {
  32. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  33. }
  34. #endregion "Constructor/Initialization"
  35. #region "=========接口重写/Interface implementation Or override"
  36. /// <summary>
  37. /// 初始化注册消息
  38. /// </summary>
  39. public override void RegisterMessage()
  40. {
  41. EndTime = DateTime.Now;
  42. StartTime = DateTime.Now.AddDays(-30);
  43. RefreshCommand.Execute(null);
  44. MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.OrderNotify);
  45. MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.OrderNotify, (e) =>
  46. {
  47. //接收通知时,防止时间设置错误,弹出错误提示
  48. EndTime = ApplicationParameter.ServerTimeNow;
  49. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
  50. RefreshCommand.Execute(null);
  51. });
  52. }
  53. public override void UnRegisterMessage()
  54. {
  55. MessengerHelper.DefaultUnregister(this);
  56. }
  57. /// <summary>
  58. /// 查询交收申报单
  59. /// </summary>
  60. public override void RefreshContent()
  61. {
  62. if (!Vailed())
  63. {
  64. return;
  65. }
  66. IsBusy = true;
  67. var accountid = UserManager.CurrentTradeAccount.AccountId;
  68. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  69. //{
  70. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  71. //}
  72. _deliveryService.QueryTakaDeliveryGoodsOrders(accountid, StartTime.Date, EndTime.Date.AddHours(24), MarketOrderSuccess, QueryErrorCallback);
  73. }
  74. #endregion "Interface implementation Or override"
  75. #region "=========公共属性/Public Properties To Get/Set "
  76. #region 开始时间
  77. private DateTime startTime;
  78. /// <summary>
  79. /// 开始时间
  80. /// </summary>
  81. public DateTime StartTime
  82. {
  83. get { return startTime; }
  84. set { Set(() => StartTime, ref startTime, value); }
  85. }
  86. #endregion
  87. #region 结束时间
  88. private DateTime _endTime;
  89. /// <summary>
  90. /// 结束时间
  91. /// </summary>
  92. public DateTime EndTime
  93. {
  94. get { return _endTime; }
  95. set { Set(() => EndTime, ref _endTime, value); }
  96. }
  97. #endregion
  98. #region 所有提货仓单ListSource
  99. private List<TakaDeliveryGoodsQueryModel> _allTakaDeliveryGoodsOrderList;
  100. /// <summary>
  101. /// 所有提货仓单ListSource
  102. /// </summary>
  103. public List<TakaDeliveryGoodsQueryModel> AllTakaDeliveryGoodsOrderList
  104. {
  105. get { return _allTakaDeliveryGoodsOrderList; }
  106. set { Set(() => AllTakaDeliveryGoodsOrderList, ref _allTakaDeliveryGoodsOrderList, value); }
  107. }
  108. #endregion
  109. #region 选择当前行【实体】
  110. private TakaDeliveryGoodsQueryModel _selectEntrustOrder;
  111. /// <summary>
  112. /// 选择 行
  113. /// </summary>
  114. public TakaDeliveryGoodsQueryModel SelectEntrustOrder
  115. {
  116. get { return _selectEntrustOrder; }
  117. set { Set(() => SelectEntrustOrder, ref _selectEntrustOrder, value); }
  118. }
  119. #endregion
  120. #endregion "Public Properties To Get/Set "
  121. #region "=========公共命令/Public Commands"
  122. #region 提货申请命令Command
  123. private RelayCommand _takeDeliveryGoodsCommand;
  124. /// <summary>
  125. /// Gets the TakeDeliveryGoodsCommand.
  126. /// </summary>
  127. public RelayCommand TakeDeliveryGoodsCommand
  128. {
  129. get
  130. {
  131. return _takeDeliveryGoodsCommand
  132. ?? (_takeDeliveryGoodsCommand = new RelayCommand(
  133. () =>
  134. {
  135. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.TakeDeliveryGoodsApply);
  136. }));
  137. }
  138. }
  139. #endregion
  140. #region 重置查询时间命令Command
  141. private RelayCommand _resetCommand;
  142. /// <summary>
  143. /// Gets the ResetCommand.
  144. /// </summary>
  145. public RelayCommand ResetCommand
  146. {
  147. get
  148. {
  149. return _resetCommand
  150. ?? (_resetCommand = new RelayCommand(
  151. () =>
  152. {
  153. EndTime = DateTime.Now;
  154. StartTime = DateTime.Now.AddDays(-30);
  155. }));
  156. }
  157. }
  158. #endregion
  159. #region 撤销命令Command
  160. public ICommand CancelCommand
  161. {
  162. get
  163. {
  164. return new RelayCommand(() =>
  165. {
  166. PostCancelOrder();
  167. });
  168. }
  169. }
  170. #endregion
  171. /// <summary>
  172. /// 撤销命令
  173. /// </summary>
  174. public RelayCommand CancelOrderCammand
  175. {
  176. get
  177. {
  178. return new RelayCommand(() =>
  179. {
  180. if (SelectEntrustOrder == null) return;
  181. PostCancelOrder();
  182. }, () => CanCancelOrderDetial());
  183. }
  184. }
  185. /// <summary>
  186. /// 是否可撤单
  187. /// </summary>
  188. /// <returns></returns>
  189. public bool CanCancelOrderDetial()
  190. {
  191. var result = false;
  192. if (SelectEntrustOrder == null || SelectEntrustOrder.AuditStatus != eAuditStatus.AUDITSTATUS_CHECKING)
  193. {
  194. result = false;
  195. }
  196. else
  197. {
  198. result = true;
  199. }
  200. return result;
  201. }
  202. #region 查看详情Command
  203. private RelayCommand<TakaDeliveryGoodsQueryModel> _seeMoreDetailCommand;
  204. /// <summary>
  205. /// 查看详情Command
  206. /// </summary>
  207. public RelayCommand<TakaDeliveryGoodsQueryModel> SeeMoreDetailCommand
  208. {
  209. get
  210. {
  211. return _seeMoreDetailCommand
  212. ?? (_seeMoreDetailCommand = new RelayCommand<TakaDeliveryGoodsQueryModel>(
  213. p =>
  214. {
  215. MessengerHelper.DefaultSend(SelectEntrustOrder, MessengerTokens.TakeGoodsMoreDetail);
  216. }));
  217. }
  218. }
  219. #endregion
  220. #endregion "Public Commands"
  221. #region "=========私有方法/Private Methods"
  222. /// <summary>
  223. /// 撤销操作事务
  224. /// </summary>
  225. private void PostCancelOrder()
  226. {
  227. if (SelectEntrustOrder != null)
  228. {
  229. var orderBuild = BuildEntrustOrder();
  230. long orderNumber = orderBuild.StoreOutId;
  231. //var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureCancel + orderNumber + Muchinfo.MTPClient.Resources.Client_Resource.Models_Bill,
  232. // Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips);
  233. var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToCancel,
  234. Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips);
  235. if (boxResult == MessageBoxResult.Yes)
  236. {
  237. IsBusy = true;
  238. _deliveryService.SubmitOutStoreReq(orderBuild, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  239. }
  240. }
  241. }
  242. /// 撤销成功返回
  243. /// </summary>
  244. /// <param name="order"></param>
  245. private void EntrurstSuccessCallBack(OutStoreRspModel order)
  246. {
  247. IsBusy = false;
  248. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  249. {
  250. MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Account_CancelSuccess,
  251. Client_Resource.Cancel_MessageBox_Title);
  252. }));
  253. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
  254. }
  255. /// <summary>
  256. /// 撤销失败返回
  257. /// </summary>
  258. /// <param name="errorEntity"></param>
  259. private void EntrurstErrorCallBack(ErrorEntity errorEntity)
  260. {
  261. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  262. {
  263. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  264. IsBusy = false;
  265. }));
  266. }
  267. #region 创建下单委托对象
  268. /// <summary>
  269. /// 创建下单委托对象
  270. /// </summary>
  271. /// <returns>下单委托对象</returns>
  272. private OutStoreReqModel BuildEntrustOrder()
  273. {
  274. var newOrder = new OutStoreReqModel()
  275. {
  276. //申请
  277. OperateType = (int)TakaGoodsOperateType.Canceled,
  278. PhoneNum="1",
  279. RecieveAddress="address",
  280. RecievePerson = "Person",
  281. StoreOutId=SelectEntrustOrder.StoreOutId
  282. };
  283. if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  284. UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  285. {
  286. newOrder.AccountID = newOrder.OperatorID = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  287. }
  288. else
  289. {
  290. newOrder.AccountID = newOrder.OperatorID = UserManager.CurrentTradeAccount.AccountId;
  291. }
  292. return newOrder;
  293. }
  294. #endregion
  295. /// <summary>
  296. /// 查询成功返回
  297. /// </summary>
  298. /// <param name="orders"></param>
  299. protected void MarketOrderSuccess(List<TakaDeliveryGoodsQueryModel> orders)
  300. {
  301. UpdateItemSource(orders);
  302. IsBusy = false;
  303. }
  304. /// <summary>
  305. /// 查询失败返回
  306. /// </summary>
  307. /// <param name="errorEntity"></param>
  308. public override void QueryErrorCallback(ErrorEntity errorEntity)
  309. {
  310. IsBusy = false;
  311. //var errorMsg = string.Format("{0}:{1}", errorEntity.RequestFunc, ErrorManager.FormatErrorMsg(errorEntity)); //错误信息显示到状态
  312. //MessengerHelper.DefaultSend(errorMsg, MessengerTokens.ErrorMessage);
  313. // base.QueryErrorCallback();
  314. }
  315. /// <summary>
  316. /// 更新数据源-绑定数据源
  317. /// </summary>
  318. /// <param name="orders"></param>
  319. private void UpdateItemSource(List<TakaDeliveryGoodsQueryModel> orders)
  320. {
  321. if (orders != null)
  322. {
  323. AllTakaDeliveryGoodsOrderList = orders;//所有单据
  324. }
  325. }
  326. #endregion "Private Methods"
  327. #region "=========其它方法/Other Methods"
  328. /// <summary>
  329. /// 数据验证
  330. /// </summary>
  331. /// <returns></returns>
  332. private bool Vailed()
  333. {
  334. if (StartTime > EndTime)
  335. {
  336. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_StartEnd, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  337. return false;
  338. }
  339. else if ((EndTime - StartTime).Days > 30)
  340. {
  341. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_Over30days, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  342. return false;
  343. }
  344. return true;
  345. }
  346. #endregion "Other Methods"
  347. }
  348. }