TradeOrderViewModel.cs 38 KB

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