DeliveryWarehouseOrderViewModel.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. using System.Linq;
  2. using System.Windows;
  3. using System.Windows.Input;
  4. using GalaSoft.MvvmLight;
  5. using System.Collections.Generic;
  6. using GalaSoft.MvvmLight.Command;
  7. using GalaSoft.MvvmLight.Ioc;
  8. using Muchinfo.MTPClient.Data;
  9. using Muchinfo.MTPClient.Data.Enums;
  10. using Muchinfo.MTPClient.Data.Model.Account;
  11. using Muchinfo.MTPClient.Data.Model.Delivery;
  12. using System;
  13. using Muchinfo.MTPClient.Delivery.Views;
  14. using Muchinfo.MTPClient.Infrastructure.Helpers;
  15. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  16. using Muchinfo.MTPClient.Infrastructure.Utilities;
  17. using Muchinfo.MTPClient.Infrastructure.Windows;
  18. using Muchinfo.MTPClient.IService;
  19. using Muchinfo.MTPClient.Resources;
  20. using Muchinfo.MTPClient.Infrastructure.Cache;
  21. namespace Muchinfo.MTPClient.Delivery.ViewModels
  22. {
  23. /// <summary>
  24. /// This class contains properties that a View can data bind to.
  25. /// <para>
  26. /// See http://www.galasoft.ch/mvvm
  27. /// </para>
  28. /// </summary>
  29. public class DeliveryWarehouseOrderViewModel : QueryPanelModelBase
  30. {
  31. #region "=========私有成员/Private Data Members"
  32. protected IDeliveryService _deliveryService;
  33. #endregion "Private Data Members"
  34. #region "=========构造函数/Constructor/Initialization"
  35. public DeliveryWarehouseOrderViewModel()
  36. {
  37. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  38. }
  39. #endregion "Constructor/Initialization"
  40. #region "=========接口重写/Interface implementation Or override"
  41. /// <summary>
  42. /// 初始化注册消息
  43. /// </summary>
  44. public override void RegisterMessage()
  45. {
  46. EndTime = DateTime.Now;
  47. StartTime = DateTime.Now.AddDays(-30);
  48. RefreshCommand.Execute(null);
  49. MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.OrderNotify);
  50. MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.OrderNotify, (e) =>
  51. {
  52. //接收通知时,防止时间设置错误,弹出错误提示
  53. EndTime = ApplicationParameter.ServerTimeNow;
  54. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
  55. RefreshCommand.Execute(null);
  56. });
  57. }
  58. public override void UnRegisterMessage()
  59. {
  60. MessengerHelper.DefaultUnregister(this);
  61. }
  62. /// <summary>
  63. /// 查询交收申报单
  64. /// </summary>
  65. public override void RefreshContent()
  66. {
  67. if (!Vailed())
  68. {
  69. return;
  70. }
  71. IsBusy = true;
  72. var accountid = UserManager.CurrentTradeAccount.AccountId;
  73. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  74. //{
  75. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  76. //}
  77. _deliveryService.QueryDeliveryWarehouseOrders(SearchWarehouseOrdersType.AccountId,string.Empty,accountid, StartTime.Date, EndTime.Date.AddHours(24), MarketOrderSuccess, QueryErrorCallback);
  78. }
  79. #endregion "Interface implementation Or override"
  80. #region "=========公共属性/Public Properties To Get/Set "
  81. #region 开始时间
  82. private DateTime startTime;
  83. /// <summary>
  84. /// 开始时间
  85. /// </summary>
  86. public DateTime StartTime
  87. {
  88. get { return startTime; }
  89. set { Set(() => StartTime, ref startTime, value); }
  90. }
  91. #endregion
  92. #region 结束时间
  93. private DateTime _endTime;
  94. /// <summary>
  95. /// 结束时间
  96. /// </summary>
  97. public DateTime EndTime
  98. {
  99. get { return _endTime; }
  100. set { Set(() => EndTime, ref _endTime, value); }
  101. }
  102. #endregion
  103. #region 所有ListSource
  104. private List<DeliveryWarehouse> _allAduitOrders;
  105. /// <summary>
  106. /// 所有ListSource
  107. /// </summary>
  108. public List<DeliveryWarehouse> AllAduitOrders
  109. {
  110. get { return _allAduitOrders; }
  111. set { Set(() => AllAduitOrders, ref _allAduitOrders, value); }
  112. }
  113. #endregion
  114. #region 当前选择单据转换
  115. private List<OutStoreReqDetailModel> _currentSelectedOutStore = null;
  116. /// <summary>
  117. /// 当前勾选的提货单据LIST
  118. /// </summary>
  119. public List<OutStoreReqDetailModel> CurrentSelectedOutStore
  120. {
  121. get
  122. {
  123. return _currentSelectedOutStore;
  124. }
  125. set
  126. {
  127. Set(() => CurrentSelectedOutStore, ref _currentSelectedOutStore, value);
  128. }
  129. }
  130. #endregion
  131. #region 选择当前行【实体】
  132. private DeliveryWarehouse _selectEntrustOrder;
  133. /// <summary>
  134. /// 选择 行
  135. /// </summary>
  136. public DeliveryWarehouse SelectEntrustOrder
  137. {
  138. get { return _selectEntrustOrder; }
  139. set { Set(() => SelectEntrustOrder, ref _selectEntrustOrder, value); }
  140. }
  141. #endregion
  142. #endregion "Public Properties To Get/Set "
  143. #region "=========公共命令/Public Commands"
  144. #region 交割申报下单命令Command
  145. private RelayCommand _deliveryCommand;
  146. /// <summary>
  147. /// Gets the DeliveryCommand.
  148. /// </summary>
  149. public RelayCommand DeliveryCommand
  150. {
  151. get
  152. {
  153. return _deliveryCommand
  154. ?? (_deliveryCommand = new RelayCommand(
  155. () =>
  156. {
  157. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.DeliveryDeclare);
  158. }));
  159. }
  160. }
  161. #endregion
  162. #region 重置查询时间命令Command
  163. private RelayCommand _resetCommand;
  164. /// <summary>
  165. /// Gets the ResetCommand.
  166. /// </summary>
  167. public RelayCommand ResetCommand
  168. {
  169. get
  170. {
  171. return _resetCommand
  172. ?? (_resetCommand = new RelayCommand(
  173. () =>
  174. {
  175. EndTime = DateTime.Now;
  176. StartTime = DateTime.Now.AddDays(-30);
  177. }));
  178. }
  179. }
  180. #endregion
  181. #region 弹出窗口填写个人信息Command
  182. private RelayCommand _popUpRecieveInfoCommand;
  183. /// <summary>
  184. /// 弹出窗口填写个人信息Command
  185. /// </summary>
  186. public RelayCommand PopUpRecieveInfoCommand
  187. {
  188. get
  189. {
  190. return _popUpRecieveInfoCommand
  191. ?? (_popUpRecieveInfoCommand = new RelayCommand(
  192. () =>
  193. {
  194. MessengerHelper.DefaultSend(SelectEntrustOrder, MessengerTokens.WarehouseRecieveInfo);
  195. }));
  196. }
  197. }
  198. #endregion
  199. #region 提货命令Command
  200. public ICommand TakeGoodsCommand
  201. {
  202. get
  203. {
  204. return new RelayCommand(() =>
  205. {
  206. CurrentSelectedOutStore = new List<OutStoreReqDetailModel>();
  207. CurrentSelectedOutStore.Add(new OutStoreReqDetailModel() { WRId = (SelectEntrustOrder.WRID), StoreOutQty = (SelectEntrustOrder.Qty) });
  208. if (SelectEntrustOrder != null && CurrentSelectedOutStore.Count()>0)
  209. {
  210. var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToTakeGoods,
  211. Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips);
  212. if (boxResult == MessageBoxResult.Yes)
  213. {
  214. IsBusy = true;
  215. var newOrder = new OutStoreReqModel()
  216. {
  217. //申请
  218. OperateType = (int)TakaGoodsOperateType.Apply,
  219. OutStoreDetail = CurrentSelectedOutStore
  220. };
  221. if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  222. UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  223. {
  224. newOrder.AccountID = newOrder.OperatorID = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  225. }
  226. else
  227. {
  228. newOrder.AccountID = newOrder.OperatorID = UserManager.CurrentTradeAccount.AccountId;
  229. }
  230. try
  231. {
  232. _deliveryService.SubmitOutStoreReq(newOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  233. }
  234. finally
  235. {
  236. }
  237. }
  238. }
  239. });
  240. }
  241. }
  242. #endregion
  243. #region 仓单详情Command
  244. private RelayCommand<DeliveryWarehouse> _popDetailCommand;
  245. /// <summary>
  246. /// 信息Command
  247. /// </summary>
  248. public RelayCommand<DeliveryWarehouse> PopDetailCommand
  249. {
  250. get
  251. {
  252. return _popDetailCommand
  253. ?? (_popDetailCommand = new RelayCommand<DeliveryWarehouse>(
  254. (wareHouse) =>
  255. {
  256. var wareHouseView = new WareHouseOrderDetailView()
  257. {
  258. Owner = Application.Current.MainWindow,
  259. WindowStartupLocation = WindowStartupLocation.CenterOwner,
  260. DataContext = wareHouse,
  261. ShowInTaskbar = false
  262. };
  263. wareHouseView.ShowDialog();
  264. }));
  265. }
  266. }
  267. #endregion
  268. #endregion "Public Commands"
  269. #region "=========私有方法/Private Methods"
  270. /// <summary>
  271. /// 提交提货成功返回
  272. /// </summary>
  273. /// <param name="order"></param>
  274. private void EntrurstSuccessCallBack(OutStoreRspModel order)
  275. {
  276. IsBusy = false;
  277. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  278. {
  279. //OKButtonEnabled = true;
  280. //提货成功
  281. MessageBoxHelper.ShowSuccess(Client_Resource.Order_TakaDeliveryGoods_Success_Result,
  282. Client_Resource.UI2014_Tips);
  283. }));
  284. //刷新正常单
  285. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
  286. }
  287. /// <summary>
  288. /// 提货委托失败返回
  289. /// </summary>
  290. /// <param name="errorEntity"></param>
  291. private void EntrurstErrorCallBack(ErrorEntity errorEntity)
  292. {
  293. IsBusy = false;
  294. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  295. {
  296. //OKButtonEnabled = true;
  297. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  298. }));
  299. }
  300. /// <summary>
  301. /// 查询成功返回
  302. /// </summary>
  303. /// <param name="orders"></param>
  304. protected void MarketOrderSuccess(List<DeliveryWarehouse> orders)
  305. {
  306. UpdateItemSource(orders);
  307. IsBusy = false;
  308. }
  309. /// <summary>
  310. /// 查询失败返回
  311. /// </summary>
  312. /// <param name="errorEntity"></param>
  313. public override void QueryErrorCallback(ErrorEntity errorEntity)
  314. {
  315. IsBusy = false;
  316. var errorMsg = string.Format("{0}:{1}", errorEntity.RequestFunc, ErrorManager.FormatErrorMsg(errorEntity)); //错误信息显示到状态
  317. MessengerHelper.DefaultSend(errorMsg, MessengerTokens.ErrorMessage);
  318. }
  319. /// <summary>
  320. /// 更新数据源
  321. /// </summary>
  322. /// <param name="orders"></param>
  323. private void UpdateItemSource(List<DeliveryWarehouse> orders)
  324. {
  325. if (orders != null)
  326. {
  327. foreach (var item in orders)
  328. {
  329. #region 合约单位转换
  330. var goodsUnit = CacheManager.TradeGoodsUnit.FirstOrDefault((x) => x.UNITID == item.GoodsUnitId);
  331. if (goodsUnit != null)
  332. {
  333. item.GoodsUnitIdDisplay = goodsUnit.GOODSUNITNAME;
  334. }
  335. #endregion
  336. #region 是否可提货
  337. if (item.Status == eWRStatus.Normal && (item.Qty - item.FreezeQty - item.PayQty) > 0)
  338. {
  339. item.IsVisibility = Visibility.Visible;
  340. }
  341. #endregion
  342. try
  343. {
  344. var helper = new EncryptHelper();
  345. item.WarehouseAddress = item.AreaAddress +
  346. (string.IsNullOrWhiteSpace(item.DetailAddress)
  347. ? string.Empty
  348. : helper.AesDecrypt(item.DetailAddress));
  349. }
  350. catch (Exception)
  351. {
  352. }
  353. #region 存货货显本人
  354. item.WRSAVER = UserManager.CurrentTradeAccount.CustomerName;
  355. #endregion
  356. }
  357. AllAduitOrders = orders; //所有单据
  358. }
  359. }
  360. #endregion "Private Methods"
  361. #region "=========其它方法/Other Methods"
  362. /// <summary>
  363. /// 数据验证
  364. /// </summary>
  365. /// <returns></returns>
  366. private bool Vailed()
  367. {
  368. if (StartTime > EndTime)
  369. {
  370. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_StartEnd, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  371. return false;
  372. }
  373. else if ((EndTime - StartTime).Days > 30)
  374. {
  375. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_Over30days, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  376. return false;
  377. }
  378. return true;
  379. }
  380. #endregion "Other Methods"
  381. }
  382. }