DeliveryEntructViewModel.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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/8/5 9:23:51
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using System.Windows;
  16. using System.Windows.Input;
  17. using GalaSoft.MvvmLight;
  18. using GalaSoft.MvvmLight.Command;
  19. using GalaSoft.MvvmLight.Ioc;
  20. using Muchinfo.MTPClient.Data;
  21. using Muchinfo.MTPClient.Data.Enums;
  22. using Muchinfo.MTPClient.Data.Model.Account;
  23. using Muchinfo.MTPClient.Data.Model.Delivery;
  24. using Muchinfo.MTPClient.Infrastructure.Helpers;
  25. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  26. using Muchinfo.MTPClient.Infrastructure.Utilities;
  27. using Muchinfo.MTPClient.Infrastructure.Windows;
  28. using Muchinfo.MTPClient.IService;
  29. using Muchinfo.MTPClient.Resources;
  30. namespace Muchinfo.MTPClient.Delivery.ViewModels
  31. {
  32. /// <summary>
  33. /// 交割申报查询ViewModel
  34. /// </summary>
  35. public class DeliveryEntructViewModel : QueryPanelModelBase//QueryPanelPageModelBase<DeliveryEntrustOrder>
  36. {
  37. #region "私有字段/Private Data Members"
  38. protected IDeliveryService _deliveryService;
  39. #endregion "Private Data Members"
  40. #region "构造函数/Constructor/Initialization"
  41. public DeliveryEntructViewModel()
  42. {
  43. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  44. }
  45. #endregion "Constructor/Initialization"
  46. #region "接口重写/Interface implementation Or override"
  47. /// <summary>
  48. /// 初始化注册消息
  49. /// </summary>RefreshContent
  50. public override void RegisterMessage()
  51. {
  52. EndTime = ApplicationParameter.ServerTimeNow;
  53. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
  54. RefreshCommand.Execute(null);
  55. MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.OrderNotify);
  56. MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.OrderNotify, (e) =>
  57. {
  58. //接收通知时,防止时间设置错误,弹出错误提示
  59. EndTime = ApplicationParameter.ServerTimeNow;
  60. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
  61. RefreshCommand.Execute(null);
  62. });
  63. }
  64. public override void UnRegisterMessage()
  65. {
  66. MessengerHelper.DefaultUnregister(this);
  67. }
  68. /// <summary>
  69. /// 查询交收申报单
  70. /// </summary>
  71. public override void RefreshContent()
  72. {
  73. if (!Vailed())
  74. {
  75. return;
  76. }
  77. IsBusy = true;
  78. var queryList = new List<QueryCommonParam>();
  79. queryList.Add(new QueryCommonParam() { ParamKey = "userid", ParamValue = UserManager.CurrentTradeAccount.CustomerId + string.Empty });
  80. queryList.Add(new QueryCommonParam() { ParamKey = "starttime", ParamValue = StartTime.ToString() + string.Empty });
  81. queryList.Add(new QueryCommonParam() { ParamKey = "endtime", ParamValue = EndTime.ToString() + string.Empty });
  82. _deliveryService.QueryDeliveryDeclareByCapitalAccount(QueryStatement.QueryDeliverEntrustOrder, queryList, QuerySuccessCallBackNew, QueryErrorCallbackNew);
  83. }
  84. private void QuerySuccessCallBackNew(List<DeliveryEntrustOrder> orders)
  85. {
  86. UpdateItemSource(orders);
  87. IsBusy = false;
  88. }
  89. private void QueryErrorCallbackNew(ErrorEntity error)
  90. {
  91. IsBusy = false;
  92. }
  93. #endregion "Interface implementation Or override"
  94. #region "Public Properties To Get/Set "
  95. #region 开始时间
  96. private DateTime startTime;
  97. /// <summary>
  98. /// 开始时间
  99. /// </summary>
  100. public DateTime StartTime
  101. {
  102. get { return startTime; }
  103. set { Set(() => StartTime, ref startTime, value); }
  104. }
  105. #endregion
  106. #region 结束时间
  107. private DateTime _endTime;
  108. /// <summary>
  109. /// 结束时间
  110. /// </summary>
  111. public DateTime EndTime
  112. {
  113. get { return _endTime; }
  114. set { Set(() => EndTime, ref _endTime, value); }
  115. }
  116. #endregion
  117. #region 未审核ListSource
  118. private List<DeliveryEntrustOrder> _unAduitOrders;
  119. /// <summary>
  120. /// 未审核ListSource
  121. /// </summary>
  122. public List<DeliveryEntrustOrder> UnAduitOrders
  123. {
  124. get { return _unAduitOrders; }
  125. set { Set(() => UnAduitOrders, ref _unAduitOrders, value); }
  126. }
  127. #endregion
  128. #region 审核不通过的ListSource
  129. private List<DeliveryEntrustOrder> _refuseOrders;
  130. /// <summary>
  131. /// 审核不通过的ListSource
  132. /// </summary>
  133. public List<DeliveryEntrustOrder> RefuseOrders
  134. {
  135. get { return _refuseOrders; }
  136. set { Set(() => RefuseOrders, ref _refuseOrders, value); }
  137. }
  138. #endregion
  139. #region 所有单据ListSource【“待审核”、“未通过”、“已通过”、“已配对”】
  140. private List<DeliveryEntrustOrder> _allOrders;
  141. /// <summary>
  142. /// 所有单据ListSource
  143. /// </summary>
  144. public List<DeliveryEntrustOrder> AllOrders
  145. {
  146. get { return _allOrders; }
  147. set { Set(() => AllOrders, ref _allOrders, value); }
  148. }
  149. #endregion
  150. #region 选择当前行【实体】
  151. private DeliveryEntrustOrder _selectEntrustOrder;
  152. /// <summary>
  153. /// 选择 行
  154. /// </summary>
  155. public DeliveryEntrustOrder SelectEntrustOrder
  156. {
  157. get { return _selectEntrustOrder; }
  158. set { Set(() => SelectEntrustOrder, ref _selectEntrustOrder, value); }
  159. }
  160. #endregion
  161. #endregion "Public Properties To Get/Set "
  162. #region "Public Commands"
  163. #region 交割申报下单命令Command
  164. private RelayCommand _deliveryCommand;
  165. /// <summary>
  166. /// Gets the DeliveryCommand.
  167. /// </summary>
  168. public RelayCommand DeliveryCommand
  169. {
  170. get
  171. {
  172. return _deliveryCommand
  173. ?? (_deliveryCommand = new RelayCommand(
  174. () =>
  175. {
  176. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.DeliveryDeclare);
  177. }));
  178. }
  179. }
  180. #endregion
  181. #region 重置查询时间命令Command
  182. private RelayCommand _resetCommand;
  183. /// <summary>
  184. /// Gets the ResetCommand.
  185. /// </summary>
  186. public RelayCommand ResetCommand
  187. {
  188. get
  189. {
  190. return _resetCommand
  191. ?? (_resetCommand = new RelayCommand(
  192. () =>
  193. {
  194. EndTime = ApplicationParameter.ServerTimeNow;
  195. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
  196. }));
  197. }
  198. }
  199. #endregion
  200. #region 撤销命令Command
  201. public ICommand CancelCommand
  202. {
  203. get
  204. {
  205. return new RelayCommand(() =>
  206. {
  207. if (SelectEntrustOrder != null)
  208. {
  209. }
  210. });
  211. }
  212. }
  213. #endregion
  214. #region 撤销或配对命令Command
  215. private RelayCommand _cancelOrMatchCommand;
  216. /// <summary>
  217. /// Gets the CancelOrMatchCommand.
  218. /// </summary>
  219. public RelayCommand CancelOrMatchCommand
  220. {
  221. get
  222. {
  223. return _cancelOrMatchCommand
  224. ?? (_cancelOrMatchCommand = new RelayCommand(
  225. () =>
  226. {
  227. switch (SelectEntrustOrder.OrderStatus)
  228. {
  229. default:
  230. break;
  231. }
  232. }));
  233. }
  234. }
  235. /// <summary>
  236. /// 撤销命令
  237. /// </summary>
  238. public RelayCommand CancelCammand
  239. {
  240. get
  241. {
  242. return new RelayCommand(() =>
  243. {
  244. MessageBoxHelper.ShowInfo("功能开发中,敬请期待", Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  245. return;
  246. //if (SelectEntrustOrder == null) return;
  247. //PostCancelOrder();
  248. }, () => CanCancelOrderDetial());
  249. }
  250. }
  251. /// <summary>
  252. /// 撤销操作Event
  253. /// </summary>
  254. private void PostCancelOrder()
  255. {
  256. if (SelectEntrustOrder != null)
  257. {
  258. //var orderBuild = BuildEntrustOrder();
  259. //long orderNumber = orderBuild.RelateOrderID;
  260. ////var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureCancel + orderNumber + Muchinfo.MTPClient.Resources.Client_Resource.Models_Bill,
  261. //// Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips);
  262. //var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToCancel,
  263. // Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips);
  264. //if (boxResult == MessageBoxResult.Yes)
  265. //{
  266. // IsBusy = true;
  267. // _deliveryService.DeliveryApplyOrder(orderBuild, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  268. //}
  269. }
  270. }
  271. /// <summary>
  272. /// 是否可撤单
  273. /// </summary>
  274. /// <returns></returns>
  275. public bool CanCancelOrderDetial()
  276. {
  277. var result = false;
  278. return result;
  279. }
  280. #endregion
  281. #region 查看详情
  282. private RelayCommand<DeliveryEntrustOrder> _seeMoreDetailCommand;
  283. /// <summary>
  284. /// 查看详情
  285. /// </summary>
  286. public RelayCommand<DeliveryEntrustOrder> SeeMoreDetailCommand
  287. {
  288. get
  289. {
  290. return _seeMoreDetailCommand
  291. ?? (_seeMoreDetailCommand = new RelayCommand<DeliveryEntrustOrder>(
  292. p =>
  293. {
  294. MessengerHelper.DefaultSend(SelectEntrustOrder, MessengerTokens.DeliveryEntructOrderDetail);
  295. }));
  296. }
  297. }
  298. #endregion
  299. #region 撤销命令
  300. private RelayCommand _cancelsCommand;
  301. /// <summary>
  302. /// 撤销命令
  303. /// </summary>
  304. public RelayCommand CancelsCommand
  305. {
  306. get
  307. {
  308. return _cancelsCommand
  309. ?? (_cancelsCommand = new RelayCommand(
  310. () =>
  311. {
  312. PostCancelOrder();
  313. }));
  314. }
  315. }
  316. #endregion
  317. #region 点选仓单命令
  318. private RelayCommand _matchCommand;
  319. /// <summary>
  320. /// 点选仓单命令
  321. /// </summary>
  322. public RelayCommand MatchCommand
  323. {
  324. get
  325. {
  326. return _matchCommand
  327. ?? (_matchCommand = new RelayCommand(
  328. () =>
  329. {
  330. MessageBoxHelper.ShowInfo("功能开发中,敬请期待", Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  331. if (SelectEntrustOrder.accountid == 0)
  332. {
  333. SelectEntrustOrder.accountid = UserManager.CurrentTradeAccount.FundsAccountId;
  334. }
  335. //MessengerHelper.DefaultSend(SelectEntrustOrder, MessengerTokens.DeliveryMatchDeclare);
  336. }));
  337. }
  338. }
  339. #endregion
  340. #endregion "Public Commands"
  341. #region "Private Methods"
  342. #region 创建下单委托对象
  343. /// <summary>
  344. /// 创建下单委托对象
  345. /// </summary>
  346. /// <returns>下单委托对象</returns>
  347. private DeliveryOrderReqModel BuildEntrustOrder()
  348. {
  349. //string loginCode, string tradeCode, long orderId, long entrustId, decimal quantity, string goodsCode
  350. //var entrustId = CurrentLimitOrder.EntrustId;
  351. var newOrder = new DeliveryOrderReqModel()
  352. {
  353. };
  354. //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  355. // UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  356. //{
  357. // newOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  358. //}
  359. //else
  360. //{
  361. // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId;
  362. //}
  363. return newOrder;
  364. }
  365. #endregion
  366. /// 撤销成功返回
  367. /// </summary>
  368. /// <param name="order"></param>
  369. private void EntrurstSuccessCallBack(DeliveryOrderRspModel order)
  370. {
  371. IsBusy = false;
  372. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  373. {
  374. MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Account_CancelSuccess,
  375. Client_Resource.Cancel_MessageBox_Title);
  376. //MessageBoxHelper.ShowSuccess(Client_Resource.Order_Success_Result,
  377. // Client_Resource.Cancel_MessageBox_Title);
  378. //if (_openWindow != null)
  379. //{
  380. // _openWindow.Close();
  381. // this.Cleanup();
  382. //}
  383. }));
  384. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
  385. }
  386. /// <summary>
  387. /// 撤销失败返回
  388. /// </summary>
  389. /// <param name="errorEntity"></param>
  390. private void EntrurstErrorCallBack(ErrorEntity errorEntity)
  391. {
  392. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  393. {
  394. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  395. IsBusy = false;
  396. }));
  397. }
  398. /// <summary>
  399. /// 查询成功返回
  400. /// </summary>
  401. /// <param name="orders"></param>
  402. protected void MarketOrderSuccess(List<DeliveryEntrustOrder> orders)
  403. {
  404. UpdateItemSource(orders);
  405. IsBusy = false;
  406. }
  407. /// <summary>
  408. /// 查询失败返回
  409. /// </summary>
  410. /// <param name="errorEntity"></param>
  411. public override void QueryErrorCallback(ErrorEntity errorEntity)
  412. {
  413. IsBusy = false;
  414. var errorMsg = string.Format("{0}:{1}", errorEntity.RequestFunc, ErrorManager.FormatErrorMsg(errorEntity)); //错误信息显示到状态
  415. MessengerHelper.DefaultSend(errorMsg, MessengerTokens.ErrorMessage);
  416. // base.QueryErrorCallback();
  417. }
  418. /// <summary>
  419. /// 更新数据源
  420. /// </summary>
  421. /// <param name="orders"></param>
  422. private void UpdateItemSource(List<DeliveryEntrustOrder> orders)
  423. {
  424. if (orders != null)
  425. {
  426. foreach (var orderitem in orders)
  427. {
  428. if (orderitem.PPriceMode == 1)
  429. {
  430. orderitem.IsVisibility_RelationModeP = Visibility.Visible;
  431. }
  432. else
  433. {
  434. orderitem.IsVisibility_RelationModeP = Visibility.Collapsed;
  435. }
  436. if (orderitem.P2PriceMode == 1)
  437. {
  438. orderitem.IsVisibility_RelationModeP2 = Visibility.Visible;
  439. }
  440. else
  441. {
  442. orderitem.IsVisibility_RelationModeP2 = Visibility.Collapsed;
  443. }
  444. }
  445. AllOrders = orders.OrderByDescending(x => x.OrderTime).ToList();//所有单据
  446. }
  447. }
  448. #endregion "Private Methods"
  449. #region "Other Methods like Validated"
  450. /// <summary>
  451. /// 数据验证
  452. /// </summary>
  453. /// <returns></returns>
  454. private bool Vailed()
  455. {
  456. if (StartTime > EndTime)
  457. {
  458. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_StartEnd, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  459. return false;
  460. }
  461. else if ((EndTime - StartTime).Days > 30)
  462. {
  463. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_Over30days, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  464. return false;
  465. }
  466. return true;
  467. }
  468. #endregion "Other Methods like Validated"
  469. }
  470. }