SaleTradeViewModel.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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/25 10:08:08
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using GalaSoft.MvvmLight.Ioc;
  16. using Muchinfo.MTPClient.Data;
  17. using Muchinfo.MTPClient.Data.Enums;
  18. using Muchinfo.MTPClient.Data.Model;
  19. using Muchinfo.MTPClient.Data.Model.Account;
  20. using Muchinfo.MTPClient.IService;
  21. using Muchinfo.MTPClient.Infrastructure.Utilities;
  22. using Muchinfo.MTPClient.Data.Model.GoodRules;
  23. using Muchinfo.MTPClient.Infrastructure.Cache;
  24. namespace Muchinfo.MTPClient.Trade.ViewModels
  25. {
  26. public class SaleTradeViewModel :TradeBaseViewModel
  27. {
  28. public SaleTradeViewModel(QuoteGoods goods, Direction direction)
  29. : base(goods, Direction.Bid) //申购目前只有买入
  30. {
  31. PriceMode = ePriceMode.PRICEMODE_MARKET;
  32. ExecutePrice = goods.GoodsParameters.IssuePrice;
  33. SetMinMaxQtyVaule(); //设置数量
  34. }
  35. public override void PostOrder(Action<OrderDetail> successAction, Action<ErrorEntity> errorAction)
  36. {
  37. var entrustOrder = BuildEntrustOrder();
  38. entrustOrder.BuildType = OpenCloseMode.BUILDTYPE_OPEN; //发售只建仓
  39. var saleService = SimpleIoc.Default.GetInstance<ISaleService>();
  40. saleService.SaleEntrurstOrder(entrustOrder, successAction, errorAction);
  41. }
  42. public override bool IsPriceModeVisible
  43. {
  44. get { return false; }
  45. }
  46. /// <summary>
  47. /// 发售不显示卖
  48. /// </summary>
  49. public override bool IsSellVsb
  50. {
  51. get { return false; }
  52. }
  53. public override string BuyTitle
  54. {
  55. get
  56. {
  57. return Muchinfo.MTPClient.Resources.Client_Resource.Order_Sale_Buy;
  58. }
  59. }
  60. #region 申购单位
  61. private decimal _perOrderQty = decimal.Zero;
  62. /// <summary>
  63. /// 申购单位
  64. /// </summary>
  65. public decimal PerOrderQty
  66. {
  67. get
  68. {
  69. return _perOrderQty;
  70. }
  71. set
  72. {
  73. Set(() => PerOrderQty, ref _perOrderQty, value);
  74. }
  75. }
  76. #endregion
  77. public override bool Validated(ref string msg)
  78. {
  79. if (Lot.ToString().Length <= 0 || Lot <= 0 || Lot == decimal.Zero || Lot > MaxLot)
  80. {
  81. //数量不在正确范围内
  82. msg = Muchinfo.MTPClient.Resources.Client_Resource.ErrorNumRange;
  83. return false;
  84. }
  85. if (Lot > MaxLot)
  86. {
  87. //msg = "申购数量超过单笔最大申购数量";
  88. msg = Muchinfo.MTPClient.Resources.Client_Resource.ErrorSaleNum;
  89. return false;
  90. }
  91. if (Lot < MinLot)
  92. {
  93. //msg = "申购数量应大于单笔最小申购数量";
  94. msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Error_SaleNum, MinLot);
  95. return false;
  96. }
  97. if (Lot != 0 && (Lot % PerOrderQty) != 0)
  98. {
  99. //数量输入有误!应为{设定申购单位}的倍数.
  100. msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.SaleOrderViewModel_InputNumShouldBeRight, PerOrderQty);
  101. return false;
  102. }
  103. return true;
  104. }
  105. public override bool IsExecutePriceVbs
  106. {
  107. get { return true; }
  108. }
  109. protected new void SetMinMaxQtyVaule()
  110. {
  111. var minQty = _goodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId, _currentGoods.TradeMode, GoodsTradeConts.MINOPENTRADEQTY);
  112. var maxQty = _goodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId, _currentGoods.TradeMode, GoodsTradeConts.MAXOPENTRADEQTY);
  113. //NEW 申购单位 【错误 #29137】
  114. var tempPerOrderQty = _goodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId, _currentGoods.TradeMode, GoodsTradeConts.MinSalePerOrderQty);
  115. PerOrderQty = tempPerOrderQty.FeeValue;
  116. MaxLot = maxQty == null ? defaut_maxLot : Math.Round(maxQty.FeeValue, 2, MidpointRounding.AwayFromZero);
  117. MinLot = minQty == null ? defaut_minLot : Math.Round(minQty.FeeValue, 2, MidpointRounding.AwayFromZero);
  118. Lot = PerOrderQty;
  119. var enableOpenNum = GetEnableNum(ExecutePrice); //根据资金算出可建仓数
  120. enableOpenNum = MinLot == 0 ? enableOpenNum : Math.Floor(enableOpenNum / PerOrderQty) * PerOrderQty; ////下单数量应该为申购单位整数倍
  121. enableOpenNum = Math.Max(0, enableOpenNum); ////是大于等0
  122. MaxLot = Math.Min(enableOpenNum, MaxLot);
  123. MaxLot = Math.Round(MaxLot, 2, MidpointRounding.AwayFromZero);
  124. MinLot = Math.Round(MinLot, 2, MidpointRounding.AwayFromZero);
  125. }
  126. }
  127. }