TradeOrderViewModel.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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/7/22 16:03:12
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using System.Windows;
  16. using GalaSoft.MvvmLight;
  17. using GalaSoft.MvvmLight.Command;
  18. using Muchinfo.MTPClient.Data;
  19. using Muchinfo.MTPClient.Data.Enums;
  20. using Muchinfo.MTPClient.Data.Model;
  21. using Muchinfo.MTPClient.Data.Model.Account;
  22. using Muchinfo.MTPClient.Infrastructure.Cache;
  23. using Muchinfo.MTPClient.Infrastructure.Helpers;
  24. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  25. using Muchinfo.MTPClient.Infrastructure.Utilities;
  26. using Muchinfo.MTPClient.Resources;
  27. using System.Collections.ObjectModel;
  28. using System.Windows.Media;
  29. using Muchinfo.MTPClient.Data.Model.Delivery;
  30. using Muchinfo.MTPClient.IService;
  31. using GalaSoft.MvvmLight.Ioc;
  32. namespace Muchinfo.MTPClient.Trade.ViewModels
  33. {
  34. public class TradeOrderViewModel : ViewModelBase
  35. {
  36. private Window _openWindow; ///下单窗口
  37. private bool _isBusy;
  38. private bool _isDefautClose; //是否从平仓入口进入
  39. private IDeliveryService _deliveryService;
  40. private OrderModel _orderModel = OrderModel.Normal;
  41. public OrderModel OrderModel
  42. {
  43. get { return _orderModel; }
  44. }
  45. /// <summary>
  46. /// 选择商品后的入口
  47. /// </summary>
  48. /// <param name="goods"></param>
  49. /// <param name="tradeDirection"></param>
  50. public TradeOrderViewModel(QuoteGoods goods, Direction tradeDirection)
  51. {
  52. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  53. GoodsList =
  54. CacheManager.CacheGoodsBaseInfos.Where((item) => (item.ContainsGoodsSrc & (int)GoodsFromScr.Trade) == (int)GoodsFromScr.Trade)
  55. .ToList(); ////交易的商品
  56. GoodsList = GoodsList.Where((item) => ((item.TradeMode != eTradeMode.TRADEMODE_SALE))).ToList();//|| (item.TradeMode == eTradeMode.TRADEMODE_SALE && item.GoodsParameters.RunSteps == eRunStep.RUNSTEP_ISSUE_SUBSCRIPTING)
  57. if (goods == null || GoodsList.FirstOrDefault(item => item.GoodsId == goods.GoodsId) == null)
  58. {
  59. _currentGoods = GoodsList.FirstOrDefault();
  60. }
  61. else
  62. {
  63. _currentGoods = GoodsList.FirstOrDefault(item => item.GoodsId == goods.GoodsId);
  64. }
  65. _direction = tradeDirection;
  66. TradeViewModel = CreateTradeModeViewModel(_currentGoods, tradeDirection);
  67. ShowTradeArea();
  68. //绑定Popup关联交割商品信息
  69. SelectGoodsOfPAndX_ItemSource(_currentGoods);
  70. ShowLockGoods();
  71. }
  72. /// <summary>
  73. /// 选择单据的入口
  74. /// </summary>
  75. /// <param name="orderBase"></param>
  76. /// <param name="priceMode"></param>
  77. /// <param name="orderModel"></param>
  78. public TradeOrderViewModel(OrderBase orderBase, ePriceMode priceMode, OrderModel orderModel = OrderModel.Normal)
  79. {
  80. this._orderModel = orderModel;
  81. _isDefautClose = true;
  82. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  83. GoodsList =
  84. CacheManager.CacheGoodsBaseInfos.Where((item) => (item.ContainsGoodsSrc & (int)GoodsFromScr.Trade) == (int)GoodsFromScr.Trade)
  85. .ToList(); ////交易的商品
  86. GoodsList = GoodsList.Where((item) => ((item.TradeMode != eTradeMode.TRADEMODE_SALE) || (item.TradeMode == eTradeMode.TRADEMODE_SALE && item.GoodsParameters.RunSteps == eRunStep.RUNSTEP_BIDDINGCONTINUOUS))).ToList();
  87. if (orderBase == null || GoodsList.FirstOrDefault(item => item.GoodsId == orderBase.GoodsId) == null)
  88. {
  89. _currentGoods = GoodsList.FirstOrDefault();
  90. }
  91. else
  92. {
  93. _currentGoods = GoodsList.FirstOrDefault(item => item.GoodsId == orderBase.GoodsId);
  94. }
  95. TradeViewModel = CreateCloseViewModel(_currentGoods, orderBase, priceMode, orderModel);
  96. ShowTradeArea();
  97. //绑定Popup关联交割商品信息
  98. SelectGoodsOfPAndX_ItemSource(_currentGoods);
  99. ShowLockGoods();
  100. TradeViewModel.ChangeBuySellBackground(orderBase.Direction);
  101. }
  102. private void ShowTradeArea()
  103. {
  104. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  105. {
  106. // 没有商品界面是没有办法知道自己显示成什么样子的,所以
  107. MessengerHelper.DefaultSend(_currentGoods != null, MessengerTokens.TradeLoadGoods);
  108. }));
  109. }
  110. #region 只有传统模式的下单界面,才需要锁商品,除此之外就不需要了,因为其他的模式都是弹出框的下单界面。
  111. /// <summary>
  112. /// 判断传统下单方式下的锁商品按钮显示
  113. /// </summary>
  114. private void ShowLockGoods()
  115. {
  116. if (UserManager.GetCurrentLayoutStyle() == LayoutStyle.Tradition)
  117. {
  118. ShowGoodsLock = true;
  119. }
  120. else
  121. {
  122. ShowGoodsLock = false;
  123. }
  124. LockType = LockType.UnLock;
  125. }
  126. /// <summary>
  127. /// 是否显示锁商品按钮
  128. /// </summary>
  129. private bool _showGoodsLock = true;
  130. public bool ShowGoodsLock
  131. {
  132. get { return _showGoodsLock; }
  133. set { Set(() => ShowGoodsLock, ref _showGoodsLock, value); }
  134. }
  135. #endregion
  136. #region 当前资金账号,用户
  137. /// <summary>
  138. /// 当前资金账号
  139. /// </summary>
  140. public string CurrentFunAccount
  141. {
  142. get
  143. {
  144. ulong _currentFunAccount;
  145. //交易员账号和资金账号不一致
  146. if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  147. UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  148. {
  149. _currentFunAccount = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  150. }
  151. else
  152. {
  153. //投资者账号和资金账号一致
  154. _currentFunAccount = UserManager.CurrentTradeAccount.AccountId;
  155. }
  156. //string CustomerName = UserManager.CurrentTradeAccount.CustomerName;
  157. //if (CustomerName.Length > 10)
  158. //{
  159. // CustomerName = UserManager.CurrentTradeAccount.CustomerName.Substring(0, 10)+"...";
  160. //}
  161. return _currentFunAccount.ToString();
  162. }
  163. //set { _currentFunAccount = value; }
  164. }
  165. public string CurrentFunAccountNameFormat
  166. {
  167. get
  168. {
  169. string CustomerName = UserManager.CurrentTradeAccount.CustomerName;
  170. if (CustomerName.Length > 10)
  171. {
  172. CustomerName = UserManager.CurrentTradeAccount.CustomerName.Substring(0, 10) + "...";
  173. }
  174. return CustomerName;
  175. }
  176. }
  177. public string CurrentFunAccountName
  178. {
  179. get
  180. {
  181. string CustomerName = UserManager.CurrentTradeAccount.CustomerName;
  182. return CustomerName;
  183. }
  184. }
  185. #endregion
  186. #region 商品列表
  187. private List<QuoteGoods> _goodsList; //商品列表
  188. /// <summary>
  189. /// 商品列表
  190. /// </summary>
  191. public List<QuoteGoods> GoodsList
  192. {
  193. get { return _goodsList; }
  194. set
  195. {
  196. Set(() => GoodsList, ref _goodsList, value);
  197. }
  198. }
  199. #endregion
  200. #region 当前选择商品/所属市场【[混合]竞价/即期/竞价全额】
  201. private QuoteGoods _currentGoods;
  202. /// <summary>
  203. /// 当前选择商品
  204. /// </summary>
  205. public QuoteGoods CurrentGoods
  206. {
  207. get { return _currentGoods; }
  208. set
  209. {
  210. Set(() => CurrentGoods, ref _currentGoods, value);
  211. if (value != null)
  212. {
  213. if (_isDefautClose)
  214. {
  215. var holders = UserManager.GetCacheOrders<HoldingOrder>();
  216. if (holders != null)
  217. {
  218. var defaultHolder = holders.FirstOrDefault((item => item.GoodsId == value.GoodsId));
  219. if (defaultHolder != null)
  220. {
  221. TradeViewModel = CreateCloseViewModel(value, defaultHolder);
  222. return;
  223. }
  224. }
  225. }
  226. TradeViewModel = CreateTradeModeViewModel(CurrentGoods, _direction);
  227. //绑定Popup关联交割商品信息
  228. SelectGoodsOfPAndX_ItemSource(_currentGoods);
  229. if (!IsVisibilityGoodsOfPAndX)
  230. {
  231. IsChecked_IsPopupOpen = false;
  232. }
  233. //订阅当前交易选中的商品
  234. UserManager.CurrentGoodsId = (int) value.GoodsId;
  235. QuoteProxyHelper.QuoteSubscribe(GoodsFromScr.Trade);
  236. SelectGoods();
  237. }
  238. }
  239. }
  240. /// <summary>
  241. /// 选择商品,报价牌和图表也要联动
  242. /// </summary>
  243. private void SelectGoods()
  244. {
  245. if (_currentGoods == null) return;
  246. QuoteGoods quoteGoods = CacheManager.CacheGoodsBaseInfos.Find(g => _currentGoods.GoodsId == g.GoodsId);
  247. QuoteGoodsForSelectOrder quoteGoodsForSelectOrder = new QuoteGoodsForSelectOrder()
  248. {
  249. IsSelect = true,
  250. QuoteGoods = quoteGoods,
  251. };
  252. MessengerHelper.DefaultSend<QuoteGoodsForSelectOrder>(quoteGoodsForSelectOrder, MessengerTokens.SelectGoodsOrderChange);
  253. }
  254. private bool _hasGoods = false;
  255. public bool HasGoods
  256. {
  257. get { return _hasGoods; }
  258. set { Set(() => HasGoods, ref _hasGoods, value); }
  259. }
  260. #endregion
  261. #region 关联P+X配置列表
  262. private List<RelationperformConfigModel> _relationPerformConfigList = null;
  263. /// <summary>
  264. /// 关联P+X配置列表
  265. /// </summary>
  266. public List<RelationperformConfigModel> RelationPerformConfigList
  267. {
  268. get
  269. {
  270. return _relationPerformConfigList;
  271. }
  272. set
  273. {
  274. Set(() => RelationPerformConfigList, ref _relationPerformConfigList, value);
  275. }
  276. }
  277. #endregion
  278. #region 隐藏商品配比信息提示
  279. private Visibility _isVisibility_GoodsScale = Visibility.Visible;
  280. /// <summary>
  281. /// 隐藏商品配比信息提示
  282. /// </summary>
  283. public Visibility IsVisibility_GoodsScale
  284. {
  285. get
  286. {
  287. return _isVisibility_GoodsScale;
  288. }
  289. set
  290. {
  291. Set(() => IsVisibility_GoodsScale, ref _isVisibility_GoodsScale, value);
  292. }
  293. }
  294. #endregion
  295. #region Popup关联交割商品信息
  296. private ObservableCollection<GoodsOfPAndX> _goodsOfPAndXInfoList = new ObservableCollection<GoodsOfPAndX>();
  297. /// <summary>
  298. /// 选择商品的P+X商品数据源
  299. /// </summary>
  300. public ObservableCollection<GoodsOfPAndX> GoodsOfPandXInfoList
  301. {
  302. get
  303. {
  304. return _goodsOfPAndXInfoList;
  305. }
  306. set
  307. {
  308. Set(() => GoodsOfPandXInfoList, ref _goodsOfPAndXInfoList, value);
  309. }
  310. }
  311. #endregion
  312. #region 交易类型
  313. private TradeBaseViewModel _tradeViewModel;
  314. public TradeBaseViewModel TradeViewModel
  315. {
  316. get { return _tradeViewModel; }
  317. set
  318. {
  319. if (_tradeViewModel != null)
  320. {
  321. _tradeViewModel.Cleanup();
  322. }
  323. Set(() => TradeViewModel, ref _tradeViewModel, value);
  324. }
  325. }
  326. #endregion
  327. /// <summary>
  328. /// 打开窗口时的买卖方向
  329. /// </summary>
  330. private Direction _direction;
  331. public LockType LockType
  332. {
  333. get { return ApplicationParameter._LockType; }
  334. set { Set(() => LockType, ref ApplicationParameter._LockType, value); }
  335. }
  336. public RelayCommand LockImageCommand
  337. {
  338. get
  339. {
  340. return new RelayCommand(() =>
  341. {
  342. LockType = LockType == LockType.UnLock ? LockType.Lock : LockType.UnLock;
  343. });
  344. }
  345. }
  346. private TradeBaseViewModel CreateTradeModeViewModel(QuoteGoods goods, Direction direction)
  347. {
  348. if (goods != null)
  349. {
  350. #region switch goods.GoodsParameters.TradeMode
  351. switch (goods.TradeMode)
  352. {
  353. case eTradeMode.TRADEMODE_MARKETMAKE:
  354. return new MarketTradeViewModel(goods, direction);
  355. //case eTradeMode.Full_Transfer:
  356. // return new BidPayTradeViewModel(goods, direction);
  357. case eTradeMode.TRADEMODE_BIDDING://竞价
  358. if (goods.TradeProperty == eTradeProperty.TRADEPROPERTY_CANSHORT) //收益权【改名前=保证金】
  359. {
  360. return new BidTradeViewModel(goods, direction);
  361. }
  362. else
  363. {
  364. return new BidPayTradeViewModel(goods, direction);//所有权
  365. }
  366. case eTradeMode.TRADEMODE_LISTING_SELECT://挂牌点选
  367. goods.formType = eOrderFormType.Listting;
  368. if (goods.TradeProperty == eTradeProperty.TRADEPROPERTY_CANSHORT) //收益权【改名前=保证金】
  369. {
  370. return new TradeListingViewModel(goods, direction);
  371. }
  372. else
  373. {
  374. return new TradeListingFullViewModel(goods, direction); //所有权不能建空,只能买(建),卖(平)-》有头寸
  375. }
  376. //case eTradeMode.TRADEMODE_SALE:
  377. // return new SaleTradeViewModel(goods, direction);
  378. //case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
  379. // //if (goods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN)
  380. // if (goods.TradeProperty == eTradeProperty.TRADEPROPERTY_CANSHORT) //收益权【改名后】=保证金
  381. // {
  382. // return new MixTradeViewModel(goods, direction);
  383. // }
  384. // else
  385. // {
  386. // return new MixPayTradeViewModel(goods, direction);
  387. // }
  388. case eTradeMode.TRADEMODE_ENTRUST_HEDGE:
  389. //通道交易市场
  390. return new ChannelTradeViewMode(goods, direction);
  391. default:
  392. return new MarketTradeViewModel(goods, direction);
  393. }
  394. #endregion
  395. }
  396. else
  397. {
  398. return null;
  399. }
  400. }
  401. /// <summary>
  402. /// 持仓汇总平仓调用
  403. /// </summary>
  404. /// <param name="goods"></param>
  405. /// <param name="orderBase"></param>
  406. /// <param name="priceMode"></param>
  407. /// <returns></returns>
  408. private TradeBaseViewModel CreateCloseViewModel(QuoteGoods goods, OrderBase orderBase, ePriceMode priceMode = ePriceMode.PRICEMODE_MARKET, OrderModel orderModel = OrderModel.Normal)
  409. {
  410. switch (goods.TradeMode)
  411. {
  412. case eTradeMode.TRADEMODE_MARKETMAKE:
  413. return new MarketTradeViewModel(goods, orderBase);
  414. //case eTradeMode.Full_Transfer:
  415. // return new BidPayTradeViewModel(goods, orderBase);
  416. case eTradeMode.TRADEMODE_BIDDING://无报价商竞价
  417. if (goods.TradeProperty == eTradeProperty.TRADEPROPERTY_CANSHORT) //收益权【改名前=保证金】
  418. {
  419. return new BidTradeViewModel(goods, orderBase);
  420. }
  421. else
  422. {
  423. return new BidPayTradeViewModel(goods, orderBase);//所有权
  424. }
  425. case eTradeMode.TRADEMODE_LISTING_SELECT://挂牌点选
  426. goods.formType = eOrderFormType.Listting;
  427. if (goods.TradeProperty == eTradeProperty.TRADEPROPERTY_CANSHORT) //收益权【改名前=保证金】
  428. {
  429. return new TradeListingViewModel(goods, orderBase);
  430. }
  431. else
  432. {
  433. return new TradeListingFullViewModel(goods, orderBase); //所有权不能建空,只能买(建),卖(平)-》有头寸
  434. }
  435. //case eTradeMode.TRADEMODE_SALE:
  436. //case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
  437. //case eTradeMode.TRADEMODE_BIDDING:
  438. //case eTradeMode.TRADEMODE_MARKETMAKE:
  439. // if (priceMode == ePriceMode.PRICEMODE_MARKET)
  440. // {
  441. // return new MarketTradeViewModel(goods, orderBase);
  442. // }
  443. // else
  444. // {
  445. // return new MarketTradeViewModel(goods, orderBase, priceMode);
  446. // }
  447. //case eTradeMode.TRADEMODE_BIDDING:
  448. // if (goods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN)
  449. // {
  450. // return new BidTradeViewModel(goods, orderBase);
  451. // }
  452. // else
  453. // {
  454. // return new BidPayTradeViewModel(goods, orderBase);
  455. // }
  456. //case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
  457. // if (goods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN)
  458. // {
  459. // return new MixTradeViewModel(goods, orderBase);
  460. // }
  461. // else
  462. // {
  463. // return new MixPayTradeViewModel(goods, orderBase);
  464. // }
  465. //case eTradeMode.TRADEMODE_SALE:
  466. // return new SaleTradeViewModel(goods, Direction.Bid);
  467. case eTradeMode.TRADEMODE_ENTRUST_HEDGE:
  468. return new ChannelTradeViewMode(goods, orderBase, orderModel);
  469. default:
  470. if (priceMode != ePriceMode.PRICEMODE_MARKET)
  471. {
  472. return new MarketTradeViewModel(goods, orderBase);
  473. }
  474. else
  475. {
  476. return new MarketTradeViewModel(goods, orderBase, priceMode);
  477. }
  478. }
  479. }
  480. #region 【置灰】设置按键不可用
  481. private bool _oKButtonEnabled = true;
  482. /// <summary>
  483. ///设置按键不可用
  484. /// </summary>
  485. public bool OKButtonEnabled
  486. {
  487. get
  488. {
  489. return _oKButtonEnabled;
  490. }
  491. set
  492. {
  493. Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
  494. }
  495. }
  496. /// <summary>
  497. /// 传统模式显示确认
  498. /// </summary>
  499. public bool IsOKCommandVbs
  500. {
  501. get
  502. {
  503. return UserManager.GetCurrentLayoutStyle() == LayoutStyle.Tradition;
  504. }
  505. }
  506. #endregion
  507. #region 是否忙
  508. /// <summary>
  509. /// 是否忙
  510. /// </summary>
  511. public bool IsBusy
  512. {
  513. get { return _isBusy; }
  514. set { Set(() => IsBusy, ref _isBusy, value); }
  515. }
  516. #endregion
  517. #region "Public Commands"
  518. #region IsPopupOpenCheckedCommand
  519. private RelayCommand _isPopupOpenCheckedCommand;
  520. /// <summary>
  521. /// Gets the IsPopupOpenCheckedCommand.
  522. /// </summary>
  523. public RelayCommand IsPopupOpenCheckedCommand
  524. {
  525. get
  526. {
  527. return _isPopupOpenCheckedCommand
  528. ?? (_isPopupOpenCheckedCommand = new RelayCommand(
  529. () =>
  530. {
  531. if (IsChecked_IsPopupOpen)
  532. {
  533. IsDeliveryInfoStaysOpen = true;
  534. IsDeliveryInfoStaysOpen = false;
  535. IsChecked_IsPopupOpen = false;
  536. }
  537. else
  538. {
  539. IsDeliveryInfoStaysOpen = false;
  540. IsChecked_IsPopupOpen = true;
  541. }
  542. }));
  543. }
  544. }
  545. #endregion
  546. #region 窗口改变大小事件
  547. private RelayCommand _sizeChangedCommand;
  548. /// <summary>
  549. /// Gets the SizeChangedCommand.
  550. /// </summary>
  551. public RelayCommand SizeChangedCommand
  552. {
  553. get
  554. {
  555. return _sizeChangedCommand
  556. ?? (_sizeChangedCommand = new RelayCommand(
  557. () =>
  558. {
  559. if (IsChecked_IsPopupOpen && IsVisibilityGoodsOfPAndX)
  560. {
  561. IsChecked_IsPopupOpen = false;
  562. IsChecked_IsPopupOpen = true;
  563. }
  564. else
  565. {
  566. IsChecked_IsPopupOpen = false;
  567. }
  568. }));
  569. }
  570. }
  571. #endregion
  572. /// <summary>
  573. /// 快速下单窗口取消
  574. /// </summary>
  575. public RelayCommand<Window> CancelCommand
  576. {
  577. get
  578. {
  579. return new RelayCommand<Window>((dialog) =>
  580. {
  581. dialog.DialogResult = false;
  582. });
  583. }
  584. }
  585. /// <summary>
  586. /// 传统下单
  587. /// </summary>
  588. public RelayCommand<int> TradionOKCommand
  589. {
  590. get
  591. {
  592. return new RelayCommand<int>((i) =>
  593. {
  594. if (_currentGoods == null)
  595. {
  596. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  597. {
  598. MessageBoxHelper.ShowQuestion(Client_Resource.GoodsSelect_Vailed,
  599. Client_Resource.DeliveryOrderView_WarningTipsTitle);
  600. }));
  601. return;
  602. }
  603. TradeViewModel.Direction = (Direction)i;
  604. OKButtonEnabled = false;
  605. string errorMsg = string.Empty;
  606. bool validateBool = TradeViewModel.Validated(ref errorMsg); ////内容验证
  607. if (validateBool)
  608. {
  609. if (ComfirmCheck())
  610. {
  611. IsBusy = true;
  612. TradeViewModel.PostOrder(EntrurstSuccessCallBack, EntrurstErrorCallBack);
  613. }
  614. else
  615. {
  616. OKButtonEnabled = true;
  617. }
  618. }
  619. else
  620. {
  621. MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
  622. OKButtonEnabled = true;
  623. if (IsOKCommandVbs) ////传统下单
  624. {
  625. MessengerHelper.DefaultSend(true, MessengerTokens.SetOrderFoucsToken);
  626. }
  627. }
  628. });
  629. }
  630. }
  631. private bool ComfirmCheck()
  632. {
  633. var userInfo = UserManager.GetCurrentUserInfo(); ////交易菜单设置
  634. if (userInfo.TradeParams == null)
  635. {
  636. userInfo.TradeParams = new TradeParams();
  637. }
  638. var result = true;
  639. if (userInfo.TradeParams.IsOrderComfrim)
  640. {
  641. var comfim = new OrderComfirmModel()
  642. {
  643. GoodsName = TradeViewModel.CurrentGoods.Name,
  644. Lot = TradeViewModel.Lot,
  645. Direction = TradeViewModel.Direction,
  646. OrderPrice = TradeViewModel.ExecutePrice,
  647. };
  648. var comfirm = new OrderComfirm() { DataContext = comfim, Owner = Application.Current.MainWindow };
  649. if (comfirm.ShowDialog() != true)
  650. {
  651. result = false;
  652. }
  653. }
  654. return result;
  655. }
  656. /// <summary>
  657. /// 下单确定
  658. /// </summary>
  659. public RelayCommand<Window> OKCommand
  660. {
  661. get
  662. {
  663. return new RelayCommand<Window>((dialog) =>
  664. {
  665. OKButtonEnabled = false;
  666. string errorMsg = string.Empty;
  667. bool validateBool = TradeViewModel.Validated(ref errorMsg); ////内容验证
  668. if (validateBool)
  669. {
  670. if (ComfirmCheck() && TradeViewModel.CheckProfitLoss()/*新增加的判断,用于止盈止损下单界面,此方法已经有弹出框的提示,true表示放行*/)
  671. {
  672. IsBusy = true;
  673. _openWindow = dialog;
  674. TradeViewModel.PostOrder(EntrurstSuccessCallBack, EntrurstErrorCallBack);
  675. }
  676. else
  677. {
  678. OKButtonEnabled = true;
  679. }
  680. }
  681. else
  682. {
  683. MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
  684. OKButtonEnabled = true;
  685. if (IsOKCommandVbs) ////传统下单
  686. {
  687. MessengerHelper.DefaultSend(true, MessengerTokens.SetOrderFoucsToken);
  688. }
  689. }
  690. });
  691. }
  692. }
  693. #endregion "Public Commands"
  694. /// <summary>
  695. /// 提交成功返回
  696. /// </summary>
  697. /// <param name="order"></param>
  698. private void EntrurstSuccessCallBack(OrderDetail order)
  699. {
  700. IsBusy = false;
  701. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  702. {
  703. OKButtonEnabled = true;
  704. CloseOrderWin();
  705. if (IsOKCommandVbs) ////传统下单
  706. {
  707. MessengerHelper.DefaultSend(true, MessengerTokens.SetOrderFoucsToken);
  708. }
  709. }));
  710. if (TradeViewModel.OrderFlag == OrderMethods.NormalOrder)
  711. {
  712. //刷新正常单
  713. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
  714. //MessengerHelper.DefaultSend(string.Empty, MessengerTokens.UpdateCacheGoodsToken);
  715. }
  716. else
  717. {
  718. //刷新预埋单
  719. MessengerHelper.DefaultSend(false, MessengerTokens.PreOrderUpdate);
  720. }
  721. //MessengerHelper.DefaultSend(string.Empty, MessengerTokens.OrderRefresh);//下单成功后刷新界面
  722. }
  723. /// <summary>
  724. /// 下单关窗口
  725. /// </summary>
  726. private void CloseOrderWin()
  727. {
  728. var userInfo = UserManager.GetCurrentUserInfo(); ////交易菜单设置
  729. if (userInfo.TradeParams == null)
  730. {
  731. userInfo.TradeParams = new TradeParams();
  732. }
  733. if (userInfo.TradeParams.IsSuccessComfrim) ////下单成功是否提示
  734. {
  735. if (OpenCloseMode.BUILDTYPE_CLOSETHENOPEN == TradeViewModel.OpenCloseMode) // 自动开平
  736. {
  737. MessageBoxHelper.ShowSuccess("操作成功!",
  738. Client_Resource.UI2014_Tips);
  739. }
  740. else
  741. {
  742. MessageBoxHelper.ShowSuccess(Client_Resource.Order_Success_Result,
  743. Client_Resource.UI2014_Tips);
  744. }
  745. }
  746. if (_openWindow != null)
  747. {
  748. _openWindow.Close();
  749. this.Cleanup();
  750. }
  751. }
  752. /// <summary>
  753. /// 委托失败返回
  754. /// </summary>
  755. /// <param name="errorEntity"></param>
  756. private void EntrurstErrorCallBack(ErrorEntity errorEntity)
  757. {
  758. IsBusy = false;
  759. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  760. {
  761. #region 提示失败 也刷新单据
  762. if (TradeViewModel.OrderFlag == OrderMethods.NormalOrder)
  763. {
  764. //刷新正常单
  765. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
  766. }
  767. else
  768. {
  769. //刷新预埋单
  770. MessengerHelper.DefaultSend(false, MessengerTokens.PreOrderUpdate);
  771. }
  772. #endregion
  773. OKButtonEnabled = true;
  774. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  775. if (_openWindow != null)
  776. {
  777. _openWindow.Close();
  778. this.Cleanup();
  779. }
  780. if (IsOKCommandVbs) ////传统下单
  781. {
  782. MessengerHelper.DefaultSend(true, MessengerTokens.SetOrderFoucsToken);
  783. MessengerHelper.DefaultSend("", MessengerTokens.OrderChangeToRefeshTrade);// 刷新界面某个值
  784. }
  785. }));
  786. }
  787. private eDeliveryContractLink _relationMode;
  788. /// <summary>
  789. /// 关联模式
  790. /// </summary>
  791. public eDeliveryContractLink RelationMode
  792. {
  793. get
  794. {
  795. return _relationMode;
  796. }
  797. set
  798. {
  799. Set(() => RelationMode, ref _relationMode, value);
  800. }
  801. }
  802. private string _PDeliveryGoodsName;
  803. /// <summary>
  804. /// P交割模式商品
  805. /// </summary>
  806. public string PDeliveryGoodsName
  807. {
  808. get
  809. {
  810. return _PDeliveryGoodsName;
  811. }
  812. set
  813. {
  814. Set(() => PDeliveryGoodsName, ref _PDeliveryGoodsName, value);
  815. }
  816. }
  817. private string _BelowDeliveryInfoTips = Client_Resource.EntrustOrderView_DeliveryGoodsInfo_BelowIsDeliveryInfo;
  818. /// <summary>
  819. /// 交割模式信息提示
  820. /// </summary>
  821. public string BelowDeliveryInfoTips
  822. {
  823. get
  824. {
  825. return _BelowDeliveryInfoTips;
  826. }
  827. set
  828. {
  829. Set(() => BelowDeliveryInfoTips, ref _BelowDeliveryInfoTips, value);
  830. }
  831. }
  832. public bool IsDeliveryVisible
  833. {
  834. get
  835. {
  836. return ApplicationParameter.IsDeliveryVisible == 1 && UserManager.IsAccountLogin;
  837. }
  838. }
  839. private bool _isVisibilityGoodsOfPAndX = false;
  840. /// <summary>
  841. /// 是否显示P+X商品数据源LIST
  842. /// </summary>
  843. public bool IsVisibilityGoodsOfPAndX
  844. {
  845. get
  846. {
  847. return _isVisibilityGoodsOfPAndX;
  848. }
  849. set
  850. {
  851. Set(() => IsVisibilityGoodsOfPAndX, ref _isVisibilityGoodsOfPAndX, value);
  852. }
  853. }
  854. #region IsDeliveryInfoStaysOpen
  855. private bool _isDeliveryInfoStaysOpen = false;
  856. /// <summary>
  857. /// Sets and gets the IsDeliveryInfoStaysOpen property.
  858. /// </summary>
  859. public bool IsDeliveryInfoStaysOpen
  860. {
  861. get
  862. {
  863. return _isDeliveryInfoStaysOpen;
  864. }
  865. set
  866. {
  867. Set(() => IsDeliveryInfoStaysOpen, ref _isDeliveryInfoStaysOpen, value);
  868. }
  869. }
  870. #endregion
  871. #region 交割信息CheckBox按钮
  872. private bool _isChecked_IsPopupOpen = false;
  873. /// <summary>
  874. /// 交割信息CheckBox按钮
  875. /// </summary>
  876. public bool IsChecked_IsPopupOpen
  877. {
  878. get
  879. {
  880. return _isChecked_IsPopupOpen;
  881. }
  882. set
  883. {
  884. Set(() => IsChecked_IsPopupOpen, ref _isChecked_IsPopupOpen, value);
  885. }
  886. }
  887. #endregion
  888. /// <summary>
  889. /// 绑定关联交割商品信息
  890. /// </summary>
  891. /// <param name="goodsItem"></param>
  892. private void SelectGoodsOfPAndX_ItemSource(QuoteGoods goodsItem)
  893. {
  894. GoodsOfPandXInfoList.Clear();
  895. PDeliveryGoodsName = "";
  896. IsVisibilityGoodsOfPAndX = false;
  897. var tempPAndXList = CacheManager.AllDeliveryRelationList.Where(x => x.GoodsId == goodsItem.GoodsId).ToList();
  898. if (tempPAndXList != null && tempPAndXList.Count() > 0)
  899. {
  900. _deliveryService.SearchRelationPerformConfig(tempPAndXList.FirstOrDefault().RelationId, QueryRelationConfigSuccess, null);
  901. if (IsDeliveryVisible && tempPAndXList.FirstOrDefault().RelationMode != eDeliveryContractLink.None)
  902. {
  903. IsVisibilityGoodsOfPAndX = true;
  904. }
  905. foreach (var item in tempPAndXList)
  906. {
  907. if (string.IsNullOrEmpty(PDeliveryGoodsName))
  908. {
  909. IsVisibility_GoodsScale = Visibility.Visible;
  910. switch (item.RelationMode)
  911. {
  912. case eDeliveryContractLink.None:
  913. PDeliveryGoodsName = "N";
  914. BelowDeliveryInfoTips = Client_Resource.EntrustOrderView_DeliveryGoodsInfo_BelowIsDeliveryInfoN;
  915. break;
  916. case eDeliveryContractLink.Normal:
  917. PDeliveryGoodsName = "P";
  918. IsVisibility_GoodsScale = Visibility.Collapsed;
  919. break;
  920. case eDeliveryContractLink.PAndX:
  921. PDeliveryGoodsName = "P+X";
  922. break;
  923. }
  924. }
  925. if (!GoodsOfPandXInfoList.Any(x => x.GoodsId == item.GoodsId))
  926. {
  927. GoodsOfPandXInfoList.Add(new GoodsOfPAndX()
  928. {
  929. DeliveryGoodsName = item.deliverygoodsname,
  930. DeliveryGoodsCode = item.deliverygoodscode,
  931. RelationGoodsCode = item.RelationGoodscode,
  932. RelationGoodsName = item.RelationGoodsname,
  933. RelationGoodsNameCodeDisplay = item.RelationGoodsNameCodeDisplay,
  934. RelationMode = item.RelationMode,
  935. GoodsScale = item.GoodsScale,
  936. GoodsId = item.GoodsId,
  937. Conversion = item.Conversion,
  938. Deliverypricemove = item.DeliveryPriceMove,
  939. //AgreeUnit=item.AgreeUnit,
  940. GoodsUnitId = item.GoodsId,
  941. goodsUnitName = item.goodsUnitName,
  942. BrandList = item.BrandList,
  943. RankList = item.RankList,
  944. WarehouseList = item.WarehouseList
  945. });
  946. }
  947. }
  948. }
  949. if (!IsVisibilityGoodsOfPAndX)
  950. {
  951. IsChecked_IsPopupOpen = false;
  952. }
  953. }
  954. /// <summary>
  955. /// 设置订单价格
  956. /// </summary>
  957. /// <param name="price"></param>
  958. public void SetOrderPrice(decimal price)
  959. {
  960. if (this.TradeViewModel != null)
  961. {
  962. TradeViewModel.SetOrderPrice(price);
  963. }
  964. }
  965. public override void Cleanup()
  966. {
  967. if (this._tradeViewModel != null)
  968. {
  969. _tradeViewModel.Cleanup();
  970. }
  971. base.Cleanup();
  972. }
  973. /// <summary>
  974. /// 交割关系配置查询-成功返回
  975. /// </summary>
  976. /// <param name="itemList"></param>
  977. protected void QueryRelationConfigSuccess(List<RelationperformConfigModel> itemList)
  978. {
  979. if (itemList != null)
  980. {
  981. RelationPerformConfigList = itemList;
  982. }
  983. }
  984. /// <summary>
  985. /// 是否显示买卖价格的显示区域
  986. /// </summary>
  987. public bool ShowBuySellPriceArea
  988. {
  989. get { return ApplicationParameter.ShowBuyOrSellPrice; }
  990. }
  991. private bool _showOkCancel;
  992. public bool ShowOkCancel
  993. {
  994. get { return _showOkCancel; }
  995. set { Set(() => ShowOkCancel, ref _showOkCancel, value); }
  996. }
  997. }
  998. }