ComfirmGoodsTicketsViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Command;
  3. using GalaSoft.MvvmLight.Ioc;
  4. using Muchinfo.MTPClient.Data.Enums;
  5. using Muchinfo.MTPClient.Data.Model.Delivery;
  6. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  7. using Muchinfo.MTPClient.Infrastructure.Utilities;
  8. using Muchinfo.MTPClient.IService;
  9. using System.Windows;
  10. using System.Linq;
  11. using Muchinfo.MTPClient.Resources;
  12. using System;
  13. using Muchinfo.MTPClient.Infrastructure.Helpers;
  14. using Muchinfo.MTPClient.Data;
  15. namespace Muchinfo.MTPClient.Delivery.ViewModels
  16. {
  17. /// <summary>
  18. /// 确认货票窗口
  19. /// </summary>
  20. public class ComfirmGoodsTicketsViewModel : ViewModelBase
  21. {
  22. #region "=========私有成员/Private Data Members"
  23. private DryHoldDetail _itemModel;
  24. private IDeliveryService _deliveryService;
  25. private Window _openWindow;
  26. private ePerformanceType _currentePerformanceType;
  27. private bool _isCheckGoods = false;
  28. private bool _isCheckTickets = false;
  29. #endregion "Private Data Members"
  30. #region "=========构造函数/Constructor/Initialization"
  31. public ComfirmGoodsTicketsViewModel(DryHoldDetail itemOrder)
  32. {
  33. this._itemModel = itemOrder;
  34. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  35. InitData();
  36. }
  37. #endregion "Constructor/Initialization"
  38. #region "=========接口重写/Interface implementation Or override"
  39. //To do interface implementation
  40. #endregion "Interface implementation Or override"
  41. #region "=========公共属性/Public Properties To Get/Set "
  42. public int countNum { get; set; }
  43. public string pValue_hValue_countNum { get; set; }
  44. public eDeliveryStatus DeliveryStatus { get; set; }
  45. private bool _isBusy;
  46. /// <summary>
  47. /// 是否在忙
  48. /// </summary>
  49. public bool IsBusy
  50. {
  51. get { return _isBusy; }
  52. set
  53. {
  54. Set(() => IsBusy, ref _isBusy, value);
  55. }
  56. }
  57. #endregion "Public Properties To Get/Set "
  58. #region "=========公共命令/Public Commands"
  59. #region 窗口取消Command
  60. /// <summary>
  61. /// 下单窗口取消
  62. /// </summary>
  63. public RelayCommand<Window> CancelCommand
  64. {
  65. get
  66. {
  67. return new RelayCommand<Window>((dialog) =>
  68. {
  69. dialog.DialogResult = false;
  70. });
  71. }
  72. }
  73. #endregion
  74. #region 确认付款Command
  75. private RelayCommand<Window> _confirmPayCommand;
  76. /// <summary>
  77. /// Gets the ConfirmPayCommand.
  78. /// </summary>
  79. public RelayCommand<Window> ConfirmPayCommand
  80. {
  81. get
  82. {
  83. return _confirmPayCommand
  84. ?? (_confirmPayCommand = new RelayCommand<Window>(
  85. (dialog) =>
  86. {
  87. #region 待审核处理
  88. if (_itemModel != null)
  89. {
  90. var orderBuild = BuildEntrustOrder();
  91. _openWindow = dialog;
  92. if (_isCheckGoods == false && _isCheckTickets == false)
  93. {
  94. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DeliveryHolderViewModel_MustCheckOneGoodsOrTicket, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  95. return;
  96. }
  97. ////勾选货
  98. //if (_isCheckGoods== true)
  99. //{
  100. // orderBuild.ConfirmType = (int)ePerformanceType.Confirm_Goods;
  101. // _currentePerformanceType = ePerformanceType.Confirm_Goods;
  102. //}
  103. ////勾选票
  104. //if (_isCheckTickets == true)
  105. //{
  106. // orderBuild.ConfirmType = (int)ePerformanceType.PERFORMANCETYPE_DELIVERY;
  107. // _currentePerformanceType = ePerformanceType.PERFORMANCETYPE_DELIVERY;
  108. //}
  109. ////同时勾选
  110. //if (_isCheckGoods == true && _isCheckTickets == true)
  111. //{
  112. // _currentePerformanceType = ePerformanceType.PERFORMANCETYPE_DELIVERY;
  113. //}
  114. long orderNumber = orderBuild.DeliveryId;
  115. var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToCommit,
  116. Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips);
  117. if (boxResult == MessageBoxResult.Yes && orderBuild!=null)
  118. {
  119. IsBusy = true;
  120. _deliveryService.SubmitReceiveConfirmReq(orderBuild, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  121. }
  122. }
  123. #endregion
  124. }));
  125. }
  126. }
  127. #endregion
  128. #region 选中GoodsCommand
  129. /// <summary>
  130. /// 选中
  131. /// </summary>
  132. private RelayCommand selectGoodsCommand;
  133. public RelayCommand SelectGoodsCommand
  134. {
  135. get
  136. {
  137. return selectGoodsCommand ?? (selectGoodsCommand = new RelayCommand(
  138. () =>
  139. {
  140. _isCheckGoods = true;
  141. }));
  142. }
  143. }
  144. #endregion
  145. #region 取消选中GoodsCommand
  146. /// <summary>
  147. /// 取消选中
  148. /// </summary>
  149. private RelayCommand unSelectGoodsCommand;
  150. public RelayCommand UnSelectGoodsCommand
  151. {
  152. get
  153. {
  154. return unSelectGoodsCommand ?? (unSelectGoodsCommand = new RelayCommand(
  155. () =>
  156. {
  157. _isCheckGoods = false;
  158. }));
  159. }
  160. }
  161. #endregion
  162. #region 选中TicketCommand
  163. /// <summary>
  164. /// 选中
  165. /// </summary>
  166. private RelayCommand selectTicketCommand;
  167. public RelayCommand SelectTicketCommand
  168. {
  169. get
  170. {
  171. return selectTicketCommand ?? (selectTicketCommand = new RelayCommand(
  172. () =>
  173. {
  174. _isCheckTickets = true;
  175. }));
  176. }
  177. }
  178. #endregion
  179. #region 取消选中TicketCommand
  180. /// <summary>
  181. /// 取消选中
  182. /// </summary>
  183. private RelayCommand unSelectTicketCommand;
  184. public RelayCommand UnSelectTicketCommand
  185. {
  186. get
  187. {
  188. return unSelectTicketCommand ?? (unSelectTicketCommand = new RelayCommand(
  189. () =>
  190. {
  191. _isCheckTickets = false;
  192. }));
  193. }
  194. }
  195. #endregion
  196. #endregion "Public Commands"
  197. #region "=========私有方法/Private Methods"
  198. /// <summary>
  199. /// 数据初始化
  200. /// </summary>
  201. private void InitData()
  202. {
  203. if (_itemModel != null)
  204. {
  205. countNum = this._itemModel.countNum;
  206. pValue_hValue_countNum = this._itemModel.pValue_hValue_countNum;
  207. DeliveryStatus = this._itemModel.DeliveryStatus;
  208. }
  209. }
  210. #region 创建下单委托对象
  211. /// <summary>
  212. /// 创建下单委托对象
  213. /// </summary>
  214. /// <returns>下单委托对象</returns>
  215. private ReceiveConfirmReqModel BuildEntrustOrder()
  216. {
  217. if (_itemModel != null)
  218. {
  219. var newOrder = new ReceiveConfirmReqModel()
  220. {
  221. DeliveryId = _itemModel.DeliveryId,
  222. //ConfirmType=(int)ePerformanceType.Confirm_Goods,
  223. GoodsId = (uint)_itemModel.DeliveryGoodsId,
  224. OperatorID = UserManager.CurrentTradeAccount.AccountId,
  225. AccountType = UserManager.CurrentTradeAccount.AccountType,
  226. //BuildType = eBuildType.BUILDTYPE_CANCEL,
  227. EntrurstTime = ApplicationParameter.ServerTimeNow,
  228. //OrderQty = SelectEntrustOrder.DeliveryQty,
  229. ValidType = ExpirationType.AlwaysValid,
  230. //RelateOrderID = SelectEntrustOrder.DeliveryOrderId,
  231. AccountId = UserManager.CurrentTradeAccount.AccountId,
  232. };
  233. //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  234. // UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  235. //{
  236. // newOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  237. //}
  238. //else
  239. //{
  240. // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId;
  241. //}
  242. return newOrder;
  243. }
  244. return null;
  245. }
  246. #endregion
  247. /// 确认收货、票成功返回
  248. /// </summary>
  249. /// <param name="order"></param>
  250. private void EntrurstSuccessCallBack(ReceiveConfirmRspModel order)
  251. {
  252. IsBusy = false;
  253. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  254. {
  255. // var orderBuild = BuildEntrustOrder();
  256. if (_currentePerformanceType == ePerformanceType.PERFORMANCETYPE_DELIVERY)
  257. {
  258. MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_ReceiveConfirmGoods_Success_Result,
  259. Client_Resource.Models_Tips);
  260. }
  261. else if (_currentePerformanceType == ePerformanceType.PERFORMANCETYPE_DELIVERY)
  262. {
  263. MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_ReceiveConfirmTicket_Success_Result,
  264. Client_Resource.Models_Tips);
  265. }
  266. else if (_currentePerformanceType == ePerformanceType.PERFORMANCETYPE_DELIVERY)
  267. {
  268. MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_ReceiveConfirmTicketAndGoods_Success_Result1,
  269. Client_Resource.Models_Tips);
  270. }
  271. if (_openWindow != null)
  272. {
  273. _openWindow.Close();
  274. this.Cleanup();
  275. }
  276. }));
  277. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
  278. }
  279. /// <summary>
  280. /// 确认收货、票失败返回
  281. /// </summary>
  282. /// <param name="errorEntity"></param>
  283. private void EntrurstErrorCallBack(ErrorEntity errorEntity)
  284. {
  285. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  286. {
  287. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  288. IsBusy = false;
  289. if (_openWindow != null)
  290. {
  291. _openWindow.Close();
  292. this.Cleanup();
  293. }
  294. }));
  295. }
  296. #endregion "Private Methods"
  297. #region "=========其它方法/Other Methods"
  298. //To to something
  299. #endregion "Other Methods"
  300. }
  301. }