DeliveryMatchViewModel.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Ioc;
  3. using Muchinfo.MTPClient.Data;
  4. using Muchinfo.MTPClient.Data.Model.Delivery;
  5. using Muchinfo.MTPClient.Infrastructure.Utilities;
  6. using Muchinfo.MTPClient.IService;
  7. using Muchinfo.MTPClient.Resources;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Windows;
  11. using System.Linq;
  12. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  13. using GalaSoft.MvvmLight.Command;
  14. using System.Collections.ObjectModel;
  15. using Muchinfo.MTPClient.Infrastructure.Helpers;
  16. using Muchinfo.MTPClient.Data.Enums;
  17. using Muchinfo.MTPClient.Infrastructure.Cache;
  18. using System.Text;
  19. using System.Windows.Input;
  20. using System.Windows.Controls;
  21. namespace Muchinfo.MTPClient.Delivery.ViewModels
  22. {
  23. /// <summary>
  24. /// 交割配对
  25. /// <para>
  26. /// </para>
  27. /// </summary>
  28. public class DeliveryMatchViewModel : ViewModelBase
  29. {
  30. #region "=========私有成员/Private Data Members"
  31. private IDeliveryService _deliveryService;
  32. private Window _openWindow;
  33. //private decimal usableFunds = 0;
  34. private decimal tempOtherCanMatchQty;
  35. private bool _action = false;
  36. private bool _isCheckAction = false;
  37. private DeliveryEntrustOrder _deliveryEntrustOrder;
  38. private decimal totalQty = decimal.Zero;
  39. private decimal AllCanUseQty = decimal.Zero;
  40. private string WrCodeListStr = string.Empty;
  41. #endregion "Private Data Members"
  42. #region "=========构造函数/Constructor/Initialization"
  43. public DeliveryMatchViewModel(DeliveryEntrustOrder itemOrder)
  44. {
  45. this._deliveryEntrustOrder = itemOrder;
  46. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  47. InitData();
  48. }
  49. #endregion "Constructor/Initialization"
  50. #region "=========接口重写/Interface implementation Or override"
  51. //To do interface implementation
  52. #endregion "Interface implementation Or override"
  53. #region "=========公共属性/Public Properties To Get/Set "
  54. #region 错误信息提示
  55. private string _ErrorMessage = string.Empty;
  56. /// <summary>
  57. /// 错误信息提示
  58. /// </summary>
  59. public string ErrorMessage
  60. {
  61. get
  62. {
  63. return _ErrorMessage;
  64. }
  65. set
  66. {
  67. Set(() => ErrorMessage, ref _ErrorMessage, value);
  68. }
  69. }
  70. #endregion
  71. #region 当前仓单详细
  72. private DeliveryWarehouse _currentWarehouseDetail;
  73. /// <summary>
  74. /// 当前仓单详细
  75. /// </summary>
  76. public DeliveryWarehouse CurrentWarehouseDetail
  77. {
  78. get
  79. {
  80. return _currentWarehouseDetail;
  81. }
  82. set
  83. {
  84. Set(() => CurrentWarehouseDetail, ref _currentWarehouseDetail, value);
  85. }
  86. }
  87. #endregion
  88. #region 所有当前用户仓单
  89. private List<DeliveryWarehouse> _allWarehouseOrders;
  90. /// <summary>
  91. /// 所有当前用户仓单
  92. /// </summary>
  93. public List<DeliveryWarehouse> AllWarehouseOrders
  94. {
  95. get { return _allWarehouseOrders; }
  96. set { Set(() => AllWarehouseOrders, ref _allWarehouseOrders, value); }
  97. }
  98. #endregion
  99. #region 选择预览数据
  100. private ObservableCollection<WrPairDetailModel> _chooseMatchOrderList = new ObservableCollection<WrPairDetailModel>();
  101. /// <summary>
  102. /// 选择预览数据
  103. /// </summary>
  104. public ObservableCollection<WrPairDetailModel> ChooseMatchOrderList
  105. {
  106. get
  107. {
  108. return _chooseMatchOrderList;
  109. }
  110. set
  111. {
  112. Set(() => ChooseMatchOrderList, ref _chooseMatchOrderList, value);
  113. }
  114. }
  115. #endregion
  116. #region 当前选择仓单
  117. private WrPairDetailModel _currentSelectedItem;
  118. /// <summary>
  119. /// 当前选择仓单
  120. /// </summary>
  121. public WrPairDetailModel CurrentSelectedItem
  122. {
  123. get
  124. {
  125. return _currentSelectedItem;
  126. }
  127. set
  128. {
  129. Set(() => CurrentSelectedItem, ref _currentSelectedItem, value);
  130. }
  131. }
  132. #endregion
  133. #region 主数据-是否显示
  134. private Visibility _isVisibility_Main = Visibility.Visible;
  135. /// <summary>
  136. /// 主数据-是否显示
  137. /// </summary>
  138. public Visibility IsVisibility_Main
  139. {
  140. get
  141. {
  142. return _isVisibility_Main;
  143. }
  144. set
  145. {
  146. Set(() => IsVisibility_Main, ref _isVisibility_Main, value);
  147. }
  148. }
  149. #endregion
  150. #region 预览数据-是否显示
  151. private Visibility _IsVisibility_PreView = Visibility.Collapsed;
  152. /// <summary>
  153. /// 预览数据-是否显示
  154. /// </summary>
  155. public Visibility IsVisibility_PreView
  156. {
  157. get
  158. {
  159. return _IsVisibility_PreView;
  160. }
  161. set
  162. {
  163. Set(() => IsVisibility_PreView, ref _IsVisibility_PreView, value);
  164. }
  165. }
  166. #endregion
  167. #region 仓单详细-是否显示
  168. private Visibility _isVisibility_Warehouse = Visibility.Collapsed;
  169. /// <summary>
  170. /// 仓单详细-是否显示
  171. /// </summary>
  172. public Visibility IsVisibility_Warehouse
  173. {
  174. get
  175. {
  176. return _isVisibility_Warehouse;
  177. }
  178. set
  179. {
  180. Set(() => IsVisibility_Warehouse, ref _isVisibility_Warehouse, value);
  181. }
  182. }
  183. #endregion
  184. #region 标题
  185. private string _title = Resources.Client_Resource.DeliveryEntructOrderView_Matched;
  186. /// <summary>
  187. /// 标题
  188. /// </summary>
  189. public string Title
  190. {
  191. get
  192. {
  193. return _title;
  194. }
  195. set
  196. {
  197. Set(() => Title, ref _title, value);
  198. }
  199. }
  200. #endregion
  201. #region 按钮是否可用
  202. private bool _oKButtonEnabled = true;
  203. /// <summary>
  204. ///按钮是否可用
  205. /// </summary>
  206. public bool OKButtonEnabled
  207. {
  208. get
  209. {
  210. return _oKButtonEnabled;
  211. }
  212. set
  213. {
  214. Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
  215. }
  216. }
  217. #endregion
  218. #region 是否繁忙
  219. private bool _isBusy = false;
  220. /// <summary>
  221. /// Sets and gets the IsBusy property.
  222. /// Changes to that property's value raise the PropertyChanged event.
  223. /// </summary>
  224. public bool IsBusy
  225. {
  226. get
  227. {
  228. return _isBusy;
  229. }
  230. set
  231. {
  232. Set(() => IsBusy, ref _isBusy, value);
  233. }
  234. }
  235. #endregion
  236. #region 交割仓单配对列表
  237. public List<WrPairDetailModel> TempDeliveryMatchOrderList = new List<WrPairDetailModel>();
  238. private List<WrPairDetailModel> _deliveryMatchOrderList = new List<WrPairDetailModel>();
  239. /// <summary>
  240. /// 交割仓单配对列表
  241. /// </summary>
  242. public List<WrPairDetailModel> DeliveryMatchOrderList
  243. {
  244. get { return _deliveryMatchOrderList; }
  245. set
  246. {
  247. Set(() => DeliveryMatchOrderList, ref _deliveryMatchOrderList, value);
  248. }
  249. }
  250. #endregion
  251. #region 预查询数据
  252. private List<WrPairDetailModel> _searchMatchOrderList;
  253. /// <summary>
  254. /// 预查询数据
  255. /// </summary>
  256. public List<WrPairDetailModel> SearchMatchOrderList
  257. {
  258. get
  259. {
  260. return _searchMatchOrderList;
  261. }
  262. set
  263. {
  264. Set(() => SearchMatchOrderList, ref _searchMatchOrderList, value);
  265. }
  266. }
  267. #endregion
  268. #region 仓库下拉列表
  269. private List<string> _deliveryWarehouseList = new List<string>();
  270. /// <summary>
  271. /// 仓库下拉列表
  272. /// </summary>
  273. public List<string> DeliveryWarehouseList
  274. {
  275. get { return _deliveryWarehouseList; }
  276. set
  277. {
  278. Set(() => DeliveryWarehouseList, ref _deliveryWarehouseList, value);
  279. }
  280. }
  281. #endregion
  282. #region 品牌下拉列表
  283. private ObservableCollection<string> _deliveryBrandList = new ObservableCollection<string>();
  284. /// <summary>
  285. /// 品牌下拉列表
  286. /// </summary>
  287. public ObservableCollection<string> DeliveryBrandList
  288. {
  289. get { return _deliveryBrandList; }
  290. set
  291. {
  292. Set(() => DeliveryBrandList, ref _deliveryBrandList, value);
  293. }
  294. }
  295. #endregion
  296. #region 等级下拉列表
  297. private ObservableCollection<string> _deliveryLevelList = new ObservableCollection<string>();
  298. /// <summary>
  299. /// 等级下拉列表
  300. /// </summary>
  301. public ObservableCollection<string> DeliveryLevelList
  302. {
  303. get { return _deliveryLevelList; }
  304. set
  305. {
  306. Set(() => DeliveryLevelList, ref _deliveryLevelList, value);
  307. }
  308. }
  309. #endregion
  310. #region 当前选中仓库
  311. private string _currentWarehouse;
  312. /// <summary>
  313. /// 当前选中仓库
  314. /// </summary>
  315. public string CurrentWarehouse
  316. {
  317. get { return _currentWarehouse; }
  318. set
  319. {
  320. Set(() => CurrentWarehouse, ref _currentWarehouse, value);
  321. }
  322. }
  323. #endregion
  324. #region 当前选中品牌
  325. private string _currentBrand;
  326. /// <summary>
  327. /// 当前选中品牌
  328. /// </summary>
  329. public string CurrentBrand
  330. {
  331. get { return _currentBrand; }
  332. set
  333. {
  334. Set(() => CurrentBrand, ref _currentBrand, value);
  335. }
  336. }
  337. #endregion
  338. #region 当前选中等级
  339. private string _currentLevel;
  340. /// <summary>
  341. /// 当前选中等级
  342. /// </summary>
  343. public string CurrentLevel
  344. {
  345. get { return _currentLevel; }
  346. set
  347. {
  348. Set(() => CurrentLevel, ref _currentLevel, value);
  349. }
  350. }
  351. #endregion
  352. #region 是否显示还需配对数量提示
  353. private Visibility _isVisibility_NeedMatchQty = Visibility.Collapsed;
  354. /// <summary>
  355. /// 是否显示还需配对数量提示
  356. /// </summary>
  357. public Visibility IsVisibility_NeedMatchQty
  358. {
  359. get
  360. {
  361. return _isVisibility_NeedMatchQty;
  362. }
  363. set
  364. {
  365. Set(() => IsVisibility_NeedMatchQty, ref _isVisibility_NeedMatchQty, value);
  366. }
  367. }
  368. #endregion
  369. #region 当前勾选单据LIST
  370. //【OrderMatchDetailModel】
  371. private List<OrderMatchDetailModel> _currentSelectedOrderMatchDetail = null;
  372. /// <summary>
  373. /// 当前勾选的仓单配对
  374. /// </summary>
  375. public List<OrderMatchDetailModel> CurrentSelectedOrderMatchDetail
  376. {
  377. get
  378. {
  379. return _currentSelectedOrderMatchDetail;
  380. }
  381. set
  382. {
  383. Set(() => CurrentSelectedOrderMatchDetail, ref _currentSelectedOrderMatchDetail, value);
  384. }
  385. }
  386. #endregion
  387. #region 是否勾选
  388. private bool _isCheckedCurrentBox = false;
  389. /// <summary>
  390. /// 是否勾选
  391. /// </summary>
  392. public bool IsCheckedCurrentBox
  393. {
  394. get
  395. {
  396. return _isCheckedCurrentBox;
  397. }
  398. set
  399. {
  400. Set(() => IsCheckedCurrentBox, ref _isCheckedCurrentBox, value);
  401. }
  402. }
  403. #endregion
  404. #region 已配对数量
  405. private decimal _aleadyMatchQty = decimal.Zero;
  406. /// <summary>
  407. /// 已配对数量
  408. /// </summary>
  409. public decimal AlreadyMatchQty
  410. {
  411. get
  412. {
  413. return _aleadyMatchQty;
  414. }
  415. set
  416. {
  417. //value = Math.Round(value, 0);
  418. Set(() => AlreadyMatchQty, ref _aleadyMatchQty, value);
  419. }
  420. }
  421. #endregion
  422. #region 剩余可配对数量
  423. /// <summary>
  424. /// 剩余可配对数量
  425. /// </summary>
  426. private decimal preOtherCanMatchQty = 0;
  427. private decimal _otherCanMatchQty = 0;
  428. /// <summary>
  429. /// 剩余可配对数量
  430. /// </summary>
  431. public decimal OtherCanMatchQty
  432. {
  433. get
  434. {
  435. return _otherCanMatchQty;
  436. }
  437. set
  438. {
  439. //value = Math.Round(value, 0);
  440. Set(() => OtherCanMatchQty, ref _otherCanMatchQty, value);
  441. }
  442. }
  443. #endregion
  444. #region 是否全选
  445. private bool _isSelectAll = false;
  446. /// <summary>
  447. /// 是否全选
  448. /// Changes to that property's value raise the PropertyChanged event.
  449. /// </summary>
  450. public bool IsSelectAll
  451. {
  452. get
  453. {
  454. return _isSelectAll;
  455. }
  456. set
  457. {
  458. Set(() => IsSelectAll, ref _isSelectAll, value);
  459. }
  460. }
  461. #endregion
  462. #region 合计点选升帖水
  463. private decimal _totalDeliveryPriceMove = 0;
  464. /// <summary>
  465. /// 合计点选升帖水
  466. /// </summary>
  467. public decimal TotalDeliveryPriceMove
  468. {
  469. get
  470. {
  471. return _totalDeliveryPriceMove;
  472. }
  473. set
  474. {
  475. //value = Math.Round(value, 2); ////显示两位小数
  476. Set(() => TotalDeliveryPriceMove, ref _totalDeliveryPriceMove, value);
  477. }
  478. }
  479. #endregion
  480. #region 交易商品名称
  481. private string _goodsName = string.Empty;
  482. /// <summary>
  483. /// 交易商品名称
  484. /// </summary>
  485. public string GoodsName
  486. {
  487. get
  488. {
  489. return _goodsName;
  490. }
  491. set
  492. {
  493. Set(() => GoodsName, ref _goodsName, value);
  494. }
  495. }
  496. #endregion
  497. #region 申报单号
  498. private string _OrderNumber = string.Empty;
  499. /// <summary>
  500. /// 申报单号
  501. /// </summary>
  502. public string OrderNumber
  503. {
  504. get
  505. {
  506. return _OrderNumber;
  507. }
  508. set
  509. {
  510. Set(() => OrderNumber, ref _OrderNumber, value);
  511. }
  512. }
  513. #endregion
  514. #region 转换单位
  515. private string _agreeUnitString = string.Empty;
  516. /// <summary>
  517. /// 转换单位
  518. /// </summary>
  519. public string AgreeUnitString
  520. {
  521. get
  522. {
  523. return _agreeUnitString;
  524. }
  525. set
  526. {
  527. Set(() => AgreeUnitString, ref _agreeUnitString, value);
  528. }
  529. }
  530. #endregion
  531. #region 折合数量-转换手数
  532. private decimal _discountNum = decimal.Zero;
  533. /// <summary>
  534. /// 折合数量
  535. /// </summary>
  536. public decimal DiscountNum
  537. {
  538. get
  539. {
  540. return _discountNum;
  541. }
  542. set
  543. {
  544. //value = Math.Round(value, 0);
  545. Set(() => DiscountNum, ref _discountNum, value);
  546. }
  547. }
  548. #endregion
  549. #region 申报手数
  550. private decimal _deliveryCount = decimal.Zero;
  551. /// <summary>
  552. /// 申报手数
  553. /// </summary>
  554. public decimal DeliveryCount
  555. {
  556. get
  557. {
  558. return _deliveryCount;
  559. }
  560. set
  561. {
  562. Set(() => DeliveryCount, ref _deliveryCount, value);
  563. }
  564. }
  565. #endregion
  566. #region 当前交割配置明细/当前交割配置List
  567. public List<DeliveryConfig> tempDeliveryConfigList = new List<DeliveryConfig>();
  568. private DeliveryConfig _currentDeliveryGoodsConfig = null;
  569. /// <summary>
  570. /// 当前交割配置明细
  571. /// Changes to that property's value raise the PropertyChanged event.
  572. /// </summary>
  573. public DeliveryConfig CurrentDeliveryGoodsConfig
  574. {
  575. get
  576. {
  577. return _currentDeliveryGoodsConfig;
  578. }
  579. set
  580. {
  581. Set(() => CurrentDeliveryGoodsConfig, ref _currentDeliveryGoodsConfig, value);
  582. }
  583. }
  584. #endregion
  585. #endregion "Public Properties To Get/Set "
  586. #region "=========公共命令/Public Commands"
  587. #region 窗口取消Command
  588. /// <summary>
  589. /// 窗口取消
  590. /// </summary>
  591. public RelayCommand<Window> CancelCommand
  592. {
  593. get
  594. {
  595. return new RelayCommand<Window>((dialog) =>
  596. {
  597. dialog.DialogResult = false;
  598. });
  599. }
  600. }
  601. #endregion
  602. #region 提交确定Command
  603. /// <summary>
  604. /// 提交确定
  605. /// </summary>
  606. public RelayCommand<Window> OKCommand
  607. {
  608. get
  609. {
  610. return new RelayCommand<Window>((dialog) =>
  611. {
  612. OKButtonEnabled = false;
  613. string errorMsg = string.Empty;
  614. bool validateBool = Validated(ref errorMsg); ////内容验证
  615. if (validateBool)
  616. {
  617. IsBusy = true;
  618. _openWindow = dialog;
  619. var newOrder = new DeliveryOrderMatchReqModel()
  620. {
  621. OrderId = this._deliveryEntrustOrder.DeliveryOrderId,
  622. MatchType = eMatchType.MATCHTYPE_NORMAL,//默认指定类型
  623. matchDetails = _currentSelectedOrderMatchDetail
  624. };
  625. //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  626. // UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  627. //{
  628. // newOrder.OperatorID = newOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  629. //}
  630. //else
  631. //{
  632. // newOrder.OperatorID = newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId;
  633. //}
  634. try
  635. {
  636. _deliveryService.SubmitDeliveryMatchOrder(newOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  637. }
  638. finally
  639. {
  640. }
  641. }
  642. else
  643. {
  644. MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
  645. OKButtonEnabled = true;
  646. }
  647. });
  648. }
  649. }
  650. #endregion
  651. #region 选中Command
  652. /// <summary>
  653. /// 选中
  654. /// </summary>
  655. private RelayCommand<string> selectCommand;
  656. public RelayCommand<string> SelectCommand
  657. {
  658. get
  659. {
  660. return selectCommand ?? (selectCommand = new RelayCommand<string>(
  661. (x) =>
  662. {
  663. if (_action == false)
  664. {
  665. _isCheckAction = true;
  666. var sourceList = DeliveryMatchOrderList.ToList().FindAll(p => p.WrCode == x);
  667. for (int i = 0; i < sourceList.Count(); i++)
  668. {
  669. if (sourceList[i].NumSort == int.MaxValue)
  670. {
  671. sourceList[i].NumSort = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true).Count();
  672. }
  673. }
  674. SettlementDeliveryMatchNum(CommandFromType.SelectedCommand);
  675. }
  676. }));
  677. }
  678. }
  679. #endregion
  680. #region 取消选中Command
  681. /// <summary>
  682. /// 取消选中
  683. /// </summary>
  684. private RelayCommand<string> unSelectCommand;
  685. public RelayCommand<string> UnSelectCommand
  686. {
  687. get
  688. {
  689. return unSelectCommand ?? (unSelectCommand = new RelayCommand<string>(
  690. (x) =>
  691. {
  692. if (_action == false)
  693. {
  694. _isCheckAction = true;
  695. var sourceList = DeliveryMatchOrderList.ToList().FindAll(p => p.WrCode == x);
  696. for (int i = 0; i < sourceList.Count(); i++)
  697. {
  698. if (sourceList[i].NumSort != int.MaxValue)
  699. {
  700. sourceList[i].NumSort = int.MaxValue;
  701. }
  702. }
  703. SettlementDeliveryMatchNum(CommandFromType.UnSelectedCommand);
  704. }
  705. }));
  706. }
  707. }
  708. #endregion
  709. #region 测试提交Command
  710. private RelayCommand buttonCommand;
  711. public RelayCommand ButtonCommand
  712. {
  713. get
  714. {
  715. return buttonCommand ?? (buttonCommand = new RelayCommand(
  716. () =>
  717. {
  718. int count = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true).Count;
  719. for (int i = 0; i < count; i++)
  720. MessageBox.Show(DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true)[i].WrCode + "," + DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true)[i].EnableQty);
  721. }));
  722. }
  723. }
  724. #endregion
  725. #region WarehouseSelectionChangedCommand
  726. private RelayCommand _warehouseSelectionChanged;
  727. /// <summary>
  728. /// Gets the WarehouseSelectionChanged.
  729. /// </summary>
  730. public RelayCommand WarehouseSelectionChanged
  731. {
  732. get
  733. {
  734. return _warehouseSelectionChanged
  735. ?? (_warehouseSelectionChanged = new RelayCommand(
  736. () =>
  737. {
  738. FilteMatchOrderListByCombox();
  739. }));
  740. }
  741. }
  742. #endregion
  743. #region BrandSelectionChangedCommand
  744. private RelayCommand _brandSelectionChanged;
  745. /// <summary>
  746. /// Gets the BrandSelectionChanged.
  747. /// </summary>
  748. public RelayCommand BrandSelectionChanged
  749. {
  750. get
  751. {
  752. return _brandSelectionChanged
  753. ?? (_brandSelectionChanged = new RelayCommand(
  754. () =>
  755. {
  756. FilteMatchOrderListByCombox();
  757. }));
  758. }
  759. }
  760. #endregion
  761. #region RankSelectionChangedCommand
  762. private RelayCommand _rankSelectionChanged;
  763. /// <summary>
  764. /// Gets the RankSelectionChangedCommand.
  765. /// </summary>
  766. public RelayCommand RankSelectionChanged
  767. {
  768. get
  769. {
  770. return _rankSelectionChanged
  771. ?? (_rankSelectionChanged = new RelayCommand(
  772. () =>
  773. {
  774. FilteMatchOrderListByCombox();
  775. }));
  776. }
  777. }
  778. #endregion
  779. #region 预览命令
  780. private RelayCommand _preViewCommand;
  781. /// <summary>
  782. /// 预览命令.
  783. /// </summary>
  784. public RelayCommand PreViewCommand
  785. {
  786. get
  787. {
  788. return _preViewCommand
  789. ?? (_preViewCommand = new RelayCommand(
  790. () =>
  791. {
  792. Title = Resources.Client_Resource.DeliveryEntructOrderView_ComfirmMatchWarehouse;//"确认点选仓单";
  793. IsVisibility_Main = Visibility.Collapsed;
  794. IsVisibility_PreView = Visibility.Visible;
  795. IsVisibility_Warehouse = Visibility.Collapsed;
  796. }));
  797. }
  798. }
  799. #endregion
  800. #region 返回命令
  801. private RelayCommand _returnCommand;
  802. /// <summary>
  803. /// 返回命令
  804. /// </summary>
  805. public RelayCommand ReturnCommand
  806. {
  807. get
  808. {
  809. return _returnCommand
  810. ?? (_returnCommand = new RelayCommand(
  811. () =>
  812. {
  813. Title = Resources.Client_Resource.DeliveryEntructOrderView_Matched;
  814. IsVisibility_Main = Visibility.Visible;
  815. IsVisibility_PreView = Visibility.Collapsed;
  816. IsVisibility_Warehouse = Visibility.Collapsed;
  817. }));
  818. }
  819. }
  820. #endregion
  821. #region 文本改变命令Command
  822. private RelayCommand<WrPairDetailModel> _selectQtyTextChangedCommand;
  823. /// <summary>
  824. /// 文本改变命令Command
  825. /// </summary>
  826. public RelayCommand<WrPairDetailModel> SelectQtyTextChangedCommand
  827. {
  828. get
  829. {
  830. return _selectQtyTextChangedCommand
  831. ?? (_selectQtyTextChangedCommand = new RelayCommand<WrPairDetailModel>(
  832. p =>
  833. {
  834. //if (CurrentSelectedItem != null)
  835. //{
  836. // CurrentSelectedItem.SelectQty = LeaveOnlyNumbers(p);
  837. //}
  838. //if (p != null)
  839. //{
  840. // p.IsSelected = !string.IsNullOrWhiteSpace(p.SelectQty) ||
  841. // !"0".Equals(p.SelectQty.Trim());
  842. //}
  843. CurrentSelectedItem = p;
  844. if (_action == false)
  845. {
  846. _action = true;
  847. _isCheckAction = false;
  848. SettlementDeliveryMatchNum(CommandFromType.TextCommand);
  849. _action = false;
  850. }
  851. }));
  852. }
  853. }
  854. #endregion
  855. #region 仓单号详细命令
  856. private RelayCommand<string> _WrCode_MouseLeftButtonDownCommand;
  857. /// <summary>
  858. /// 仓单号详细命令
  859. /// </summary>
  860. public RelayCommand<string> WrCode_MouseLeftButtonDownCommand
  861. {
  862. get
  863. {
  864. return _WrCode_MouseLeftButtonDownCommand
  865. ?? (_WrCode_MouseLeftButtonDownCommand = new RelayCommand<string>(
  866. p =>
  867. {
  868. Title = Resources.Client_Resource.DeliveryEntructOrderView_Warehouse;//"仓单";
  869. IsVisibility_Main = Visibility.Collapsed;
  870. IsVisibility_PreView = Visibility.Collapsed;
  871. IsVisibility_Warehouse = Visibility.Visible;
  872. #region 仓单变更流水查询
  873. var accountid = UserManager.CurrentTradeAccount.AccountId;
  874. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  875. //{
  876. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  877. //}
  878. //IsBusy = true;
  879. //_deliveryService.SearchWRChangeFlow(accountid, p, WRChangeFlowOrderSuccess, DeliveryGoodsCallBack);
  880. #endregion
  881. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  882. {
  883. if (AllWarehouseOrders != null && AllWarehouseOrders.Any() && AllWarehouseOrders.Count() > 0)
  884. {
  885. CurrentWarehouseDetail = AllWarehouseOrders.FirstOrDefault(x => x.WRCode == p);
  886. }
  887. }));
  888. }));
  889. }
  890. }
  891. #endregion
  892. #region 查询命令
  893. private RelayCommand _searchCommand;
  894. /// <summary>
  895. /// 查询命令
  896. /// </summary>
  897. public RelayCommand SearchCommand
  898. {
  899. get
  900. {
  901. return _searchCommand
  902. ?? (_searchCommand = new RelayCommand(
  903. () =>
  904. {
  905. SearchMatchOrderList = DeliveryMatchOrderList;
  906. }));
  907. }
  908. }
  909. #endregion
  910. #endregion "Public Commands"
  911. #region "=========私有方法/Private Methods"
  912. /// <summary>
  913. /// 检查输入是否为多个小数点
  914. /// </summary>
  915. /// <param name="inString"></param>
  916. /// <returns></returns>
  917. private string LeaveOnlyNumbers(String inString)
  918. {
  919. var occur = false;
  920. StringBuilder ans = new StringBuilder();
  921. for (int i = 0; i < inString.Length; ++i)
  922. {
  923. if (System.Text.RegularExpressions.Regex.IsMatch(inString[i].ToString(), "^[0-9\\.]*$"))
  924. {
  925. if (inString[i] == '.')
  926. {
  927. if (!occur)
  928. {
  929. occur = true;
  930. ans.Append(inString[i]);
  931. }
  932. }
  933. else ans.Append(inString[i]);
  934. }
  935. }
  936. return ans.ToString();
  937. }
  938. /// <summary>
  939. /// 触发提交按钮是否可用
  940. /// </summary>
  941. private void IsEnableButtonEvent()
  942. {
  943. OKButtonEnabled = false;
  944. if (_currentSelectedOrderMatchDetail != null
  945. && _currentSelectedOrderMatchDetail.Any()
  946. && _currentSelectedOrderMatchDetail.Count() > 0
  947. && AlreadyMatchQty == preOtherCanMatchQty
  948. )//&& (decimal)TotalDeliveryPriceMove <= usableFunds //错误 #28975 账户可用资金小于升贴水资金,交割配对点选界面限制不允许交割点选配对
  949. {
  950. OKButtonEnabled = true;
  951. }
  952. else
  953. {
  954. OKButtonEnabled = false;
  955. }
  956. }
  957. /// <summary>
  958. /// 计算可配数量、剩余数量
  959. /// </summary>
  960. private void SettlementDeliveryMatchNum(CommandFromType commandType)
  961. {
  962. _action = true;
  963. try
  964. {
  965. #region 不是来自CheckCommand
  966. var sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true);
  967. AlreadyMatchQty = 0;
  968. TotalDeliveryPriceMove = 0;
  969. preOtherCanMatchQty = OtherCanMatchQty = (decimal)DiscountNum;//_deliveryEntrustOrder.OrderQty;
  970. CurrentSelectedOrderMatchDetail = new List<OrderMatchDetailModel>();
  971. var leaveCount = preOtherCanMatchQty;
  972. if (_isCheckAction != true)
  973. {
  974. if (CurrentSelectedItem != null && CurrentSelectedItem.SelectQty != string.Empty)
  975. {
  976. CurrentSelectedItem.IsSelected = true;
  977. sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true);
  978. }
  979. else
  980. {
  981. CurrentSelectedItem.IsSelected = false;
  982. }
  983. }
  984. else
  985. {
  986. if (commandType != CommandFromType.UnSelectedCommand)
  987. {
  988. if (sourceList.Count == 0)
  989. {
  990. ResetData();
  991. }
  992. else
  993. {
  994. leaveCount = GetAlreadyWriteNum(sourceList, leaveCount);
  995. sourceList = sourceList.Where(x => x.SelectQty == "").ToList();
  996. }
  997. }
  998. else
  999. {
  1000. if (sourceList.Count == 0)
  1001. {
  1002. ResetData();
  1003. }
  1004. else
  1005. {
  1006. CurrentSelectedItem.SelectQty = "";
  1007. leaveCount = GetAlreadyWriteNum(sourceList, leaveCount);
  1008. sourceList = DeliveryMatchOrderList.Where(x => x.SelectQty == "").ToList();
  1009. return;
  1010. }
  1011. }
  1012. }
  1013. #endregion
  1014. #region 配对数量仅能大于 等于 申报数量
  1015. // var sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true);
  1016. for (int i = 0; i < sourceList.Count(); i++)
  1017. {
  1018. if (sourceList[i].DeliveryPriceMove == int.MinValue)
  1019. {
  1020. sourceList[i].DeliveryPriceMove = 0;
  1021. }
  1022. if (leaveCount >= (decimal)sourceList[i].EnableQty)
  1023. {
  1024. if (_isCheckAction != true)
  1025. {
  1026. //文本事件处理
  1027. if (Convert.ToDecimal(sourceList[i].SelectQty)>0)
  1028. CurrentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WrId), DeliveryQty = Convert.ToDecimal(sourceList[i].SelectQty), DeliverySellOrderId = sourceList[i].DeliverySellOrderId });
  1029. TotalDeliveryPriceMove += (decimal)sourceList[i].DeliveryPriceMove * Convert.ToDecimal(sourceList[i].SelectQty);
  1030. CurrentSelectedItem.IsError = "0";
  1031. if (Convert.ToDouble(sourceList[i].SelectQty) > sourceList[i].EnableQty || Convert.ToDecimal(sourceList[i].SelectQty) > OtherCanMatchQty)
  1032. {
  1033. CurrentSelectedItem.IsError = "1";
  1034. }
  1035. }
  1036. else
  1037. {
  1038. if ((decimal)sourceList[i].EnableQty > 0)
  1039. CurrentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WrId), DeliveryQty = (decimal)sourceList[i].EnableQty, DeliverySellOrderId = sourceList[i].DeliverySellOrderId });
  1040. TotalDeliveryPriceMove += (decimal)sourceList[i].DeliveryPriceMove * (decimal)sourceList[i].EnableQty;
  1041. sourceList[i].SelectQty = sourceList[i].EnableQty.ToString();
  1042. }
  1043. }
  1044. else
  1045. {
  1046. if (leaveCount > 0)
  1047. {
  1048. if (_isCheckAction != true)
  1049. {
  1050. //文本事件处理
  1051. if (Convert.ToDecimal(sourceList[i].SelectQty) > 0)
  1052. CurrentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WrId), DeliveryQty = Convert.ToDecimal(sourceList[i].SelectQty), DeliverySellOrderId = sourceList[i].DeliverySellOrderId });
  1053. TotalDeliveryPriceMove += (decimal)sourceList[i].DeliveryPriceMove * Convert.ToDecimal(sourceList[i].SelectQty);
  1054. CurrentSelectedItem.IsError = "0";
  1055. if (Convert.ToDecimal(sourceList[i].SelectQty) > leaveCount)
  1056. {
  1057. CurrentSelectedItem.IsError = "1";
  1058. }
  1059. }
  1060. else
  1061. {
  1062. if ((decimal)leaveCount > 0)
  1063. CurrentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WrId), DeliveryQty = (decimal)leaveCount, DeliverySellOrderId = sourceList[i].DeliverySellOrderId });
  1064. TotalDeliveryPriceMove += (decimal)sourceList[i].DeliveryPriceMove * leaveCount;
  1065. sourceList[i].SelectQty = leaveCount.ToString();
  1066. }
  1067. }
  1068. }
  1069. if (_isCheckAction != true)
  1070. {
  1071. //文本事件处理
  1072. leaveCount = leaveCount - Convert.ToDecimal(sourceList[i].SelectQty);
  1073. AlreadyMatchQty =AlreadyMatchQty + Convert.ToDecimal(sourceList[i].SelectQty);
  1074. }
  1075. else
  1076. {
  1077. leaveCount = leaveCount - (decimal)sourceList[i].EnableQty;
  1078. AlreadyMatchQty += (decimal)sourceList[i].EnableQty;
  1079. }
  1080. }
  1081. OtherCanMatchQty = OtherCanMatchQty - AlreadyMatchQty;
  1082. if (OtherCanMatchQty < 0)
  1083. {
  1084. OtherCanMatchQty = 0;
  1085. AlreadyMatchQty = preOtherCanMatchQty;
  1086. }
  1087. #region 是否隐藏提示信息
  1088. IsVisibility_NeedMatchQty = Visibility.Collapsed;
  1089. if (sourceList != null && sourceList.Any() && sourceList.Count() > 0)
  1090. {
  1091. if (OtherCanMatchQty > 0)
  1092. {
  1093. IsVisibility_NeedMatchQty = Visibility.Visible;
  1094. ErrorMessage = string.Format(Client_Resource.DeliveryMatchView_ErrorMessage_NeedToChoseLot, OtherCanMatchQty);//string.Format("还需选择商品数量{0},申报数量需一次选完",OtherCanMatchQty);
  1095. }
  1096. }
  1097. #endregion
  1098. #endregion
  1099. #region 屏蔽剩余勾选框
  1100. var sourceList_False = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == false);
  1101. if (OtherCanMatchQty == 0)
  1102. {
  1103. for (int i = 0; i < sourceList_False.Count(); i++)
  1104. {
  1105. sourceList_False[i].IsEnabled = false;
  1106. //sourceList[i].SelectQty = string.Empty;
  1107. }
  1108. }
  1109. else
  1110. {
  1111. for (int i = 0; i < sourceList_False.Count(); i++)
  1112. {
  1113. sourceList_False[i].IsEnabled = true;
  1114. }
  1115. }
  1116. #endregion
  1117. IsEnableButtonEvent();
  1118. ReCheckData();
  1119. PreViewDataHandle();
  1120. }
  1121. catch (Exception ex)
  1122. {
  1123. _action = false;
  1124. }
  1125. finally
  1126. {
  1127. _action = false;
  1128. }
  1129. }
  1130. /// <summary>
  1131. /// 获取已经填写的数量
  1132. /// </summary>
  1133. private decimal GetAlreadyWriteNum(List<WrPairDetailModel> sourceList, decimal leaveCount)
  1134. {
  1135. sourceList = sourceList.Where(x => x.SelectQty != "").ToList();
  1136. for (int i = 0; i < sourceList.Count(); i++)
  1137. {
  1138. //文本事件处理
  1139. if (Convert.ToDecimal(sourceList[i].SelectQty) > 0)
  1140. CurrentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WrId), DeliveryQty = Convert.ToDecimal(sourceList[i].SelectQty), DeliverySellOrderId = sourceList[i].DeliverySellOrderId });
  1141. TotalDeliveryPriceMove += (decimal)sourceList[i].DeliveryPriceMove * Convert.ToDecimal(sourceList[i].SelectQty);
  1142. //文本事件处理
  1143. leaveCount = leaveCount - Convert.ToDecimal(sourceList[i].SelectQty);
  1144. AlreadyMatchQty += Convert.ToDecimal(sourceList[i].SelectQty);
  1145. }
  1146. OtherCanMatchQty = OtherCanMatchQty - AlreadyMatchQty;
  1147. return leaveCount;
  1148. }
  1149. /// <summary>
  1150. /// 预览数据转换
  1151. /// </summary>
  1152. private void PreViewDataHandle()
  1153. {
  1154. var sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true);
  1155. ChooseMatchOrderList.Clear();
  1156. foreach (var item in sourceList)
  1157. {
  1158. if (!ChooseMatchOrderList.Any(x => x.WrId == item.WrId))
  1159. {
  1160. ChooseMatchOrderList.Add(item);
  1161. }
  1162. }
  1163. }
  1164. /// <summary>
  1165. /// 回滚数据
  1166. /// </summary>
  1167. private void ResetData()
  1168. {
  1169. for (int i = 0; i < DeliveryMatchOrderList.Where(x=>x.IsSelected !=true).Count(); i++)
  1170. {
  1171. DeliveryMatchOrderList[i].SelectQty = string.Empty;
  1172. }
  1173. }
  1174. /// <summary>
  1175. /// 复查数据
  1176. /// </summary>
  1177. private void ReCheckData()
  1178. {
  1179. var sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true);
  1180. #region 如果没有勾选则没有错误显示
  1181. if (sourceList.Count() == 0)
  1182. {
  1183. for (int i = 0; i < DeliveryMatchOrderList.Count(); i++)
  1184. {
  1185. DeliveryMatchOrderList[i].IsError = "0";
  1186. DeliveryMatchOrderList[i].SelectQty = "";
  1187. }
  1188. }
  1189. #endregion
  1190. totalQty = decimal.Zero;
  1191. AllCanUseQty = decimal.Zero;
  1192. for (int i = 0; i < sourceList.Count(); i++)
  1193. {
  1194. totalQty += Convert.ToDecimal(sourceList[i].SelectQty);
  1195. AllCanUseQty += Convert.ToDecimal(sourceList[i].EnableQty);
  1196. }
  1197. if (totalQty == DiscountNum && AllCanUseQty >= totalQty)
  1198. {
  1199. for (int i = 0; i < DeliveryMatchOrderList.Count(); i++)
  1200. {
  1201. DeliveryMatchOrderList[i].IsError = "0";
  1202. }
  1203. }
  1204. if (totalQty > DiscountNum || AllCanUseQty < totalQty)
  1205. {
  1206. OKButtonEnabled = false;
  1207. IsVisibility_NeedMatchQty = Visibility.Visible;
  1208. ErrorMessage = Client_Resource.DeliveryMatchView_ErrorMessage_ChoseLotBiggerThanLeave;//"选择数量大于可选数量";
  1209. }
  1210. }
  1211. /// <summary>
  1212. /// 初始化数据
  1213. /// </summary>
  1214. private void InitData()
  1215. {
  1216. if (_deliveryEntrustOrder.DeliveryGoodsId != 0)
  1217. {
  1218. IsBusy = true;
  1219. //加载-仓单配对-数据
  1220. _deliveryService.SearchMatchWarehouseReq(BuildEntrustOrder(), SearchSuccessCallBack, SearchErrorCallBack);
  1221. }
  1222. //手动添加默认选择数据
  1223. TempDeliveryMatchOrderList.Add(new WrPairDetailModel() { StorePlace = Client_Resource.DeliveryMatchView_AllWareHouse, Brand = Client_Resource.DeliveryMatchView_AllBrand, Rank = Client_Resource.DeliveryMatchView_AllRank });
  1224. #region 测试数据
  1225. //for (int i = 0; i < 5; i++)
  1226. //{
  1227. // TempDeliveryMatchOrderList.Add(new WrPairDetailModel() { StorePlace = "仓库" + i.ToString(), DeliveryGoodsName = "商品" + i.ToString(), Brand = i.ToString(), Rank = i.ToString(), WrId = i + 1003, WrCode = (i + 1).ToString(), EnableQty = i + 1 });
  1228. // DeliveryMatchOrderList.Add(new WrPairDetailModel() { StorePlace = "仓库" + i.ToString(), DeliveryGoodsName = "商品" + i.ToString(), Brand = i.ToString(), Rank = i.ToString(), WrId = i + 1003, WrCode = (i + 1).ToString(), EnableQty = i + 1 });
  1229. //}
  1230. //FilteMatchOrderListByCombox();
  1231. #endregion
  1232. IsEnableButtonEvent();
  1233. }
  1234. /// <summary>
  1235. /// 交割商品关系配置成功返回
  1236. /// </summary>
  1237. /// <param name="itemList"></param>
  1238. protected void DeliveryGoodsRelationConfigSuccess(List<DeliveryConfig> itemList)
  1239. {
  1240. if (itemList != null && itemList.Count() > 0)
  1241. {
  1242. tempDeliveryConfigList = itemList;
  1243. CurrentDeliveryGoodsConfig = itemList.FirstOrDefault();
  1244. if (CurrentDeliveryGoodsConfig != null)
  1245. {
  1246. DiscountNum = _deliveryEntrustOrder.DeliveryQty;
  1247. //关联交割商品-单位
  1248. AgreeUnitString = CacheManager.TradeGoodsUnit.Where(x => x.UNITID == CurrentDeliveryGoodsConfig.GoodsUnitId).Select(x => x.GOODSUNITNAME).FirstOrDefault();
  1249. OtherCanMatchQty = (decimal)DiscountNum;
  1250. tempOtherCanMatchQty = (decimal)DiscountNum;
  1251. }
  1252. }
  1253. }
  1254. /// <summary>
  1255. /// 查询成功返回
  1256. /// </summary>
  1257. /// <param name="orders"></param>
  1258. protected void MarketOrderSuccess(List<DeliveryWarehouse> orders)
  1259. {
  1260. UpdateItemSource(orders);
  1261. IsBusy = false;
  1262. }
  1263. /// <summary>
  1264. /// 更新数据源
  1265. /// </summary>
  1266. /// <param name="orders"></param>
  1267. private void UpdateItemSource(List<DeliveryWarehouse> orders)
  1268. {
  1269. if (orders != null)
  1270. {
  1271. //foreach (var item in orders)
  1272. //{
  1273. // #region 合约单位转换
  1274. // var goodsUnit = CacheManager.TradeGoodsUnit.FirstOrDefault((x) => x.GOODSUNITID == item.GoodsUnitId);
  1275. // if (goodsUnit != null)
  1276. // {
  1277. // item.GoodsUnitIdDisplay = goodsUnit.NAME;
  1278. // }
  1279. // #endregion
  1280. // #region 是否可提货
  1281. // if (item.Status == eWRStatus.Normal && (item.Qty - item.FreezeQty - item.PayQty) > 0)
  1282. // {
  1283. // item.IsVisibility = Visibility.Visible;
  1284. // }
  1285. // #endregion
  1286. //}
  1287. AllWarehouseOrders = orders; //所有单据
  1288. }
  1289. }
  1290. /// <summary>
  1291. /// 交割商品关系配置失败返回
  1292. /// </summary>
  1293. /// <param name="errorEntity"></param>
  1294. private void DeliveryGoodsCallBack(ErrorEntity errorEntity)
  1295. {
  1296. IsBusy = false;
  1297. }
  1298. /// <summary>
  1299. /// 查询配对仓单实体
  1300. /// </summary>
  1301. /// <returns></returns>
  1302. private WrPairReqModel BuildEntrustOrder()
  1303. {
  1304. var newOrder = new WrPairReqModel();
  1305. //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  1306. // UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  1307. //{
  1308. // newOrder.OperatorId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  1309. //}
  1310. //else
  1311. //{
  1312. // newOrder.OperatorId = UserManager.CurrentTradeAccount.AccountId;
  1313. //}
  1314. return newOrder;
  1315. }
  1316. /// <summary>
  1317. /// 过滤仓单数据BY下拉列表
  1318. /// </summary>
  1319. private void FilteMatchOrderListByCombox()
  1320. {
  1321. #region 重置勾选单据
  1322. _currentSelectedOrderMatchDetail = null;
  1323. var sourceList = DeliveryMatchOrderList.ToList();
  1324. for (int i = 0; i < sourceList.Count(); i++)
  1325. {
  1326. sourceList[i].IsSelected = false;
  1327. sourceList[i].IsEnabled = true;
  1328. }
  1329. OtherCanMatchQty = tempOtherCanMatchQty;
  1330. AlreadyMatchQty = 0;
  1331. TotalDeliveryPriceMove = 0;
  1332. #endregion
  1333. #region 数据过滤条件
  1334. DeliveryMatchOrderList = new List<WrPairDetailModel>(TempDeliveryMatchOrderList);//数据回归
  1335. DeliveryWarehouseList = DeliveryMatchOrderList.Where(x => x.StorePlace != "").Select(x => x.StorePlace).Distinct().ToList();
  1336. if (CurrentWarehouse != null && CurrentWarehouse != Client_Resource.DeliveryMatchView_AllWareHouse)//全部仓库
  1337. {
  1338. DeliveryMatchOrderList = DeliveryMatchOrderList.Where(x => x.StorePlace == CurrentWarehouse || x.StorePlace == Client_Resource.DeliveryMatchView_AllWareHouse).ToList();
  1339. DeliveryBrandList = new ObservableCollection<string>(DeliveryMatchOrderList.Where(x => x.Brand != "").Select(x => x.Brand).Distinct());
  1340. }
  1341. else
  1342. {
  1343. DeliveryBrandList = new ObservableCollection<string>(DeliveryMatchOrderList.Where(x => x.Brand != "").Select(x => x.Brand).Distinct()); ;
  1344. }
  1345. if (CurrentBrand != null && CurrentBrand != Client_Resource.DeliveryMatchView_AllBrand)//全部品牌
  1346. {
  1347. DeliveryMatchOrderList = DeliveryMatchOrderList.Where(x => x.Brand == CurrentBrand || x.Brand == Client_Resource.DeliveryMatchView_AllBrand).ToList();
  1348. DeliveryLevelList = new ObservableCollection<string>(DeliveryMatchOrderList.Where(x => x.Rank != "").Select(x => x.Rank).Distinct());
  1349. }
  1350. else
  1351. {
  1352. DeliveryLevelList = new ObservableCollection<string>(DeliveryMatchOrderList.Where(x => x.Rank != "").Select(x => x.Rank).Distinct());
  1353. }
  1354. if (CurrentLevel != null && CurrentLevel != Client_Resource.DeliveryMatchView_AllRank)//全部等级
  1355. {
  1356. DeliveryMatchOrderList = DeliveryMatchOrderList.Where(x => x.Rank == CurrentLevel || x.Rank == Client_Resource.DeliveryMatchView_AllRank).ToList();
  1357. }
  1358. #endregion
  1359. #region 默认选择
  1360. DeliveryMatchOrderList = DeliveryMatchOrderList.FindAll(x => x.StorePlace != Client_Resource.DeliveryMatchView_AllWareHouse);//过滤手动添加数据
  1361. if (CurrentWarehouse == null)
  1362. {
  1363. CurrentWarehouse = DeliveryWarehouseList.FirstOrDefault(x => x == Client_Resource.DeliveryMatchView_AllWareHouse);//默认选择
  1364. }
  1365. if (CurrentLevel == null)
  1366. {
  1367. CurrentLevel = DeliveryLevelList.FirstOrDefault(x => x == Client_Resource.DeliveryMatchView_AllRank);//默认选择
  1368. }
  1369. if (CurrentBrand == null)
  1370. {
  1371. CurrentBrand = DeliveryBrandList.FirstOrDefault(x => x == Client_Resource.DeliveryMatchView_AllBrand);//默认选择
  1372. }
  1373. #endregion
  1374. IsEnableButtonEvent();
  1375. }
  1376. /// <summary>
  1377. /// 查询成功返回,绑定数据源
  1378. /// </summary>
  1379. /// <param name="itemList">The item list.</param>
  1380. protected void SearchSuccessCallBack(WrPairRspModel itemList)
  1381. {
  1382. if (itemList.WrPairDetails != null && itemList.WrPairDetails.Any() && itemList.WrPairDetails.Count() > 0)
  1383. {
  1384. foreach (var item in itemList.WrPairDetails)
  1385. {
  1386. #region 合约单位转换
  1387. var goodsUnit = CacheManager.TradeGoodsUnit.FirstOrDefault((x) => x.UNITID == item.GoodsUnitId);
  1388. if (goodsUnit != null)
  1389. {
  1390. item.GoodsUnitIdDisplay = goodsUnit.GOODSUNITNAME;
  1391. }
  1392. #endregion
  1393. #region 当前仓单WrCode列表
  1394. if (WrCodeListStr == string.Empty)
  1395. {
  1396. WrCodeListStr = "'" + item.WrCode + "'";
  1397. }
  1398. else
  1399. {
  1400. WrCodeListStr += "," + "'" + item.WrCode + "'";
  1401. }
  1402. #endregion
  1403. }
  1404. TempDeliveryMatchOrderList = itemList.WrPairDetails.Where(x => x.EnableQty != 0).ToList();
  1405. SearchMatchOrderList = itemList.WrPairDetails.Where(x => x.EnableQty != 0).ToList();
  1406. //手动添加默认选择数据
  1407. TempDeliveryMatchOrderList.Add(new WrPairDetailModel() { StorePlace = Client_Resource.DeliveryMatchView_AllWareHouse, Brand = Client_Resource.DeliveryMatchView_AllBrand, Rank = Client_Resource.DeliveryMatchView_AllRank });
  1408. DeliveryMatchOrderList = TempDeliveryMatchOrderList;
  1409. FilteMatchOrderListByCombox();
  1410. }
  1411. IsBusy = false;
  1412. #region 仓单查询
  1413. var accountid = UserManager.CurrentTradeAccount.AccountId;
  1414. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  1415. //{
  1416. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  1417. //}
  1418. if (WrCodeListStr != string.Empty)
  1419. {
  1420. _deliveryService.QueryDeliveryWarehouseOrders(SearchWarehouseOrdersType.WRCode, WrCodeListStr, accountid, DateTime.MinValue, DateTime.Now.AddDays(1), MarketOrderSuccess, DeliveryGoodsCallBack);
  1421. }
  1422. #endregion
  1423. }
  1424. /// <summary>
  1425. /// 查询失败返回
  1426. /// </summary>
  1427. /// <param name="itemList">The item list.</param>
  1428. protected void SearchErrorCallBack(ErrorEntity errorEntity)
  1429. {
  1430. IsBusy = false;
  1431. //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  1432. //{
  1433. // ErrorManager.ShowReturnError(errorEntity, Client_Resource.APP_Tips, false);
  1434. //}));
  1435. }
  1436. /// <summary>
  1437. /// 提交配对成功返回
  1438. /// </summary>
  1439. /// <param name="order"></param>
  1440. private void EntrurstSuccessCallBack(DeliveryOrderMatchRspModel order)
  1441. {
  1442. IsBusy = false;
  1443. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  1444. {
  1445. OKButtonEnabled = true;
  1446. MessageBoxHelper.ShowSuccess(Client_Resource.OrderMatch_Success_Result,
  1447. Client_Resource.UI2014_Tips);
  1448. if (_openWindow != null)
  1449. {
  1450. _openWindow.Close();
  1451. this.Cleanup();
  1452. }
  1453. }));
  1454. //刷新正常单
  1455. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
  1456. }
  1457. /// <summary>
  1458. /// 委托失败返回
  1459. /// </summary>
  1460. /// <param name="errorEntity"></param>
  1461. private void EntrurstErrorCallBack(ErrorEntity errorEntity)
  1462. {
  1463. IsBusy = false;
  1464. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  1465. {
  1466. OKButtonEnabled = true;
  1467. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  1468. if (_openWindow != null)
  1469. {
  1470. _openWindow.Close();
  1471. this.Cleanup();
  1472. }
  1473. }));
  1474. }
  1475. #endregion "Private Methods"
  1476. #region "=========其它方法/Other Methods"
  1477. /// <summary>
  1478. /// 数据验证
  1479. /// </summary>
  1480. /// <param name="msg"></param>
  1481. /// <returns></returns>
  1482. public bool Validated(ref string msg)
  1483. {
  1484. ////申报数量 > 持仓数量
  1485. if (AlreadyMatchQty > preOtherCanMatchQty)
  1486. {
  1487. msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_OpenLotGreatThanMaxLot, preOtherCanMatchQty);
  1488. return false;
  1489. }
  1490. return true;
  1491. }
  1492. #endregion "Other Methods"
  1493. }
  1494. }