DeliveryOrderViewModel.cs 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689
  1. using System.Text;
  2. using GalaSoft.MvvmLight;
  3. using GalaSoft.MvvmLight.Command;
  4. using GalaSoft.MvvmLight.Ioc;
  5. using Muchinfo.MTPClient.Data;
  6. using Muchinfo.MTPClient.Data.Enums;
  7. using Muchinfo.MTPClient.Data.Model;
  8. using Muchinfo.MTPClient.Data.Model.Account;
  9. using Muchinfo.MTPClient.Data.Model.Delivery;
  10. using Muchinfo.MTPClient.Infrastructure.Cache;
  11. using Muchinfo.MTPClient.Infrastructure.Helpers;
  12. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  13. using Muchinfo.MTPClient.Infrastructure.Utilities;
  14. using Muchinfo.MTPClient.IService;
  15. using Muchinfo.MTPClient.Resources;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Timers;
  20. using System.Windows;
  21. namespace Muchinfo.MTPClient.Delivery.ViewModels
  22. {
  23. /// <summary>
  24. /// 交割申报
  25. /// </summary>
  26. public class DeliveryOrderViewModel : ViewModelBase
  27. {
  28. #region "Private Data Members"
  29. private Window _openWindow; ///下单窗口
  30. private IDeliveryService _deliveryService;
  31. private IGoodsService _goodsService;
  32. private eDeliveryContractLink _currentLinkModel;
  33. private eMoneyMode _currentMoneyMode;
  34. private long _currentDeliveryGoodsId;//当前交割商品ID
  35. private decimal tempOtherCanMatchQty;
  36. private decimal usableFunds = UserManager.CurrentAccountUsableFunds();
  37. private DeliveryOrderMessage _parameterInfo;
  38. #endregion "Private Data Members"
  39. #region "Constructor/Initialization"
  40. /// <summary>
  41. /// 构造函数
  42. /// </summary>
  43. public DeliveryOrderViewModel()
  44. {
  45. this._parameterInfo = null;
  46. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  47. _goodsService = SimpleIoc.Default.GetInstance<IGoodsService>();
  48. // 初始化交割商品列表数据
  49. InitData();
  50. }
  51. public DeliveryOrderViewModel(DeliveryOrderMessage info)
  52. {
  53. this._parameterInfo = info;
  54. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  55. _goodsService = SimpleIoc.Default.GetInstance<IGoodsService>();
  56. // 初始化交割商品列表数据
  57. InitData();
  58. if (_parameterInfo != null && _parameterInfo.GoodsId > 0)
  59. {
  60. BuyOrSell = _parameterInfo.Direction;
  61. }
  62. }
  63. #endregion "Constructor/Initialization"
  64. #region "Interface implementation Or override"
  65. //To do interface implementation
  66. #endregion "Interface implementation Or override"
  67. #region "Public Properties To Get/Set "
  68. #region 当前账号提货人信息
  69. private DepositPersonalInfoRspModel _currentDepositPersonalInfo;
  70. /// <summary>
  71. /// 当前账号提货人信息
  72. /// </summary>
  73. public DepositPersonalInfoRspModel CurrentDepositPersonalInfo
  74. {
  75. get
  76. {
  77. return _currentDepositPersonalInfo;
  78. }
  79. set
  80. {
  81. Set(() => CurrentDepositPersonalInfo, ref _currentDepositPersonalInfo, value);
  82. }
  83. }
  84. #endregion
  85. #region 收货人
  86. private string _RecievePerson = string.Empty;
  87. /// <summary>
  88. /// 收货人
  89. /// </summary>
  90. public string RecievePerson
  91. {
  92. get
  93. {
  94. return _RecievePerson;
  95. }
  96. set
  97. {
  98. Set(() => RecievePerson, ref _RecievePerson, value);
  99. }
  100. }
  101. #endregion
  102. #region 收货地址
  103. private string _RecieveAddress = string.Empty;
  104. /// <summary>
  105. /// 收货地址
  106. /// </summary>
  107. public string RecieveAddress
  108. {
  109. get
  110. {
  111. return _RecieveAddress;
  112. }
  113. set
  114. {
  115. Set(() => RecieveAddress, ref _RecieveAddress, value);
  116. }
  117. }
  118. #endregion
  119. #region 联系方式
  120. private string _PhoneNum = string.Empty;
  121. /// <summary>
  122. /// 联系方式
  123. /// </summary>
  124. public string PhoneNum
  125. {
  126. get
  127. {
  128. return _PhoneNum;
  129. }
  130. set
  131. {
  132. Set(() => PhoneNum, ref _PhoneNum, value);
  133. }
  134. }
  135. #endregion
  136. #region 联系方式
  137. private string _IdCardNum = string.Empty;
  138. /// <summary>
  139. /// 联系方式
  140. /// </summary>
  141. public string IdCardNum
  142. {
  143. get
  144. {
  145. return _IdCardNum;
  146. }
  147. set
  148. {
  149. Set(() => IdCardNum, ref _IdCardNum, value);
  150. }
  151. }
  152. #endregion
  153. //------以下为卖交割相关------------------------
  154. #region 剩余可配对数量
  155. /// <summary>
  156. /// 剩余可配对数量
  157. /// </summary>
  158. private decimal preOtherCanMatchQty = 0;
  159. private decimal _otherCanMatchQty = 0;
  160. /// <summary>
  161. /// 剩余可配对数量
  162. /// </summary>
  163. public decimal OtherCanMatchQty
  164. {
  165. get
  166. {
  167. return _otherCanMatchQty;
  168. }
  169. set
  170. {
  171. value = Math.Round(value, 0);
  172. Set(() => OtherCanMatchQty, ref _otherCanMatchQty, value);
  173. }
  174. }
  175. #endregion
  176. #region 已配对数量
  177. private decimal _aleadyMatchQty = 0;
  178. /// <summary>
  179. /// 已配对数量
  180. /// </summary>
  181. public decimal AlreadyMatchQty
  182. {
  183. get
  184. {
  185. return _aleadyMatchQty;
  186. }
  187. set
  188. {
  189. value = Math.Round(value, 0);
  190. Set(() => AlreadyMatchQty, ref _aleadyMatchQty, value);
  191. }
  192. }
  193. #endregion
  194. #region 显示当卖交割
  195. private Visibility _isVisibilitySellModel_Show = Visibility.Collapsed;
  196. /// <summary>
  197. /// 显示卖交割
  198. /// </summary>
  199. public Visibility IsVisibilitySellModel_Show
  200. {
  201. get
  202. {
  203. return _isVisibilitySellModel_Show;
  204. }
  205. set
  206. {
  207. Set(() => IsVisibilitySellModel_Show, ref _isVisibilitySellModel_Show, value);
  208. }
  209. }
  210. #endregion
  211. #region 隐藏当卖交割
  212. private Visibility _isVisibilitySellModel = Visibility.Collapsed;
  213. /// <summary>
  214. /// 隐藏卖交割
  215. /// </summary>
  216. public Visibility IsVisibilitySellModel
  217. {
  218. get
  219. {
  220. return _isVisibilitySellModel;
  221. }
  222. set
  223. {
  224. Set(() => IsVisibilitySellModel, ref _isVisibilitySellModel, value);
  225. }
  226. }
  227. #endregion
  228. #region 是否隐藏持仓价格
  229. private Visibility _isVisibilityHolderPrice = Visibility.Collapsed;
  230. /// <summary>
  231. /// Sets and gets the IsVisibilityFrezzMoney property.
  232. /// Changes to that property's value raise the PropertyChanged event.
  233. /// </summary>
  234. public Visibility IsVisibilityHolderPrice
  235. {
  236. get
  237. {
  238. return _isVisibilityHolderPrice;
  239. }
  240. set
  241. {
  242. Set(() => IsVisibilityHolderPrice, ref _isVisibilityHolderPrice, value);
  243. }
  244. }
  245. #endregion
  246. #region 申报仓单配对列表
  247. public List<DeliveryWhRecieptInfo> TempDeliveryMatchOrderList = new List<DeliveryWhRecieptInfo>();
  248. private List<DeliveryWhRecieptInfo> _deliveryMatchOrderList = new List<DeliveryWhRecieptInfo>();
  249. /// <summary>
  250. /// 申报仓单配对列表
  251. /// </summary>
  252. public List<DeliveryWhRecieptInfo> DeliveryMatchOrderList
  253. {
  254. get { return _deliveryMatchOrderList; }
  255. set
  256. {
  257. Set(() => DeliveryMatchOrderList, ref _deliveryMatchOrderList, value);
  258. }
  259. }
  260. #endregion
  261. #region 当前勾选单据LIST
  262. private List<WrDetailModel> _currentSelectedWrDetail = null;
  263. /// <summary>
  264. /// 当前勾选的仓单配对
  265. /// </summary>
  266. public List<WrDetailModel> CurrentSelectedWrDetail
  267. {
  268. get
  269. {
  270. return _currentSelectedWrDetail;
  271. }
  272. set
  273. {
  274. Set(() => CurrentSelectedWrDetail, ref _currentSelectedWrDetail, value);
  275. }
  276. }
  277. #endregion
  278. #region 买方向是否可用
  279. private bool _isBuyEnable = true;
  280. /// <summary>
  281. /// Sets and gets the IsBuyEnable property.
  282. /// </summary>
  283. public bool IsBuyEnable
  284. {
  285. get
  286. {
  287. return _isBuyEnable;
  288. }
  289. set
  290. {
  291. Set(() => IsBuyEnable, ref _isBuyEnable, value);
  292. }
  293. }
  294. #endregion
  295. #region 卖方向是否可用
  296. private bool _IsSellEnable = true;
  297. /// <summary>
  298. /// 卖方向是否可用
  299. /// </summary>
  300. public bool IsSellEnable
  301. {
  302. get
  303. {
  304. return _IsSellEnable;
  305. }
  306. set
  307. {
  308. Set(() => IsSellEnable, ref _IsSellEnable, value);
  309. }
  310. }
  311. #endregion
  312. #region 买卖方向
  313. private Direction _buyOrSell = Direction.Bid;
  314. /// <summary>
  315. /// Sets and gets the BuyOrSell property.
  316. /// </summary>
  317. public Direction BuyOrSell
  318. {
  319. get
  320. {
  321. return _buyOrSell;
  322. }
  323. set
  324. {
  325. Set(() => BuyOrSell, ref _buyOrSell, value);
  326. if (value == Direction.unSet)
  327. {
  328. value = Direction.Bid;
  329. }
  330. SetDeliveryCount();
  331. }
  332. }
  333. #endregion
  334. //------以上为卖交割相关------------------------
  335. #region 关联交易商品-错误信息提示
  336. private string _relationGoodsErrorMsg = string.Empty;//Client_Resource.DeliveryOrderView_RelationGoodsInfoNotFound;
  337. /// <summary>
  338. /// 错误信息提示
  339. /// </summary>
  340. public string RelationGoodsErrorMsg
  341. {
  342. get
  343. {
  344. return _relationGoodsErrorMsg;
  345. }
  346. set
  347. {
  348. Set(() => RelationGoodsErrorMsg, ref _relationGoodsErrorMsg, value);
  349. }
  350. }
  351. #endregion
  352. #region 合计冻结货款[保证金、全额]
  353. private string _totalFreezenMoneyText = Client_Resource.DeliveryOrderView_FreezeDeliveryMoney;
  354. /// <summary>
  355. /// 合计冻结货款[保证金、全额]
  356. /// </summary>
  357. public string TotalFreezenMoneyText
  358. {
  359. get
  360. {
  361. return _totalFreezenMoneyText;
  362. }
  363. set
  364. {
  365. Set(() => TotalFreezenMoneyText, ref _totalFreezenMoneyText, value);
  366. }
  367. }
  368. #endregion
  369. #region 温馨提示内容
  370. private string _warningTips = Client_Resource.DeliveryOrderView_WarningTips;
  371. /// <summary>
  372. /// 温馨提示内容
  373. /// </summary>
  374. public string WarningTips
  375. {
  376. get
  377. {
  378. return _warningTips;
  379. }
  380. set
  381. {
  382. Set(() => WarningTips, ref _warningTips, value);
  383. }
  384. }
  385. #endregion
  386. #region 错误信息提示
  387. private string _errorMsg = Client_Resource.DeliveryOrderView_MinMaxErrVisibility;
  388. /// <summary>
  389. /// 错误信息提示
  390. /// </summary>
  391. public string ErrorMsg
  392. {
  393. get
  394. {
  395. return _errorMsg;
  396. }
  397. set
  398. {
  399. Set(() => ErrorMsg, ref _errorMsg, value);
  400. }
  401. }
  402. #endregion
  403. #region 交割关系表LIST
  404. private List<GoodsDeliveryRelationModel> _goodsDeliveryRelationList;
  405. public List<GoodsDeliveryRelationModel> GoodsDeliveryRelationList
  406. {
  407. get { return _goodsDeliveryRelationList; }
  408. set { _goodsDeliveryRelationList = value; }
  409. }
  410. #endregion
  411. #region 窗体标题
  412. private string _title = string.Empty;
  413. /// <summary>
  414. /// 窗体标题
  415. /// Changes to that property's value raise the PropertyChanged event.
  416. /// </summary>
  417. public string Title
  418. {
  419. get
  420. {
  421. return _title = Client_Resource.DeliveryOrderView_DeliveryDeclaration;
  422. }
  423. //set
  424. //{
  425. // Set(() => Title, ref _title, value);
  426. //}
  427. }
  428. #endregion
  429. #region 交割商品列表
  430. private List<GoodsDeliveryRelationModel> _deliveryGoodsList;
  431. /// <summary>
  432. /// 交割商品列表
  433. /// </summary>
  434. public List<GoodsDeliveryRelationModel> DeliveryGoodsList
  435. {
  436. get { return _deliveryGoodsList; }
  437. set
  438. {
  439. Set(() => DeliveryGoodsList, ref _deliveryGoodsList, value);
  440. }
  441. }
  442. #endregion
  443. #region 持仓数量
  444. private decimal _holdCount = 0;
  445. /// <summary>
  446. /// 当前商品持仓数量
  447. /// </summary>
  448. public decimal HoldCount
  449. {
  450. get
  451. {
  452. return _holdCount;
  453. }
  454. set
  455. {
  456. Set(() => HoldCount, ref _holdCount, value);
  457. }
  458. }
  459. #endregion
  460. #region 申报数量
  461. private decimal _deliveryCount = 0;
  462. /// <summary>
  463. /// 申报数量
  464. /// </summary>
  465. public decimal DeliveryCount
  466. {
  467. get
  468. {
  469. return _deliveryCount;
  470. }
  471. set
  472. {
  473. Set(() => DeliveryCount, ref _deliveryCount, value);
  474. if (BuyOrSell == Direction.Ask)
  475. {
  476. RollBackMatchOrderList();
  477. }
  478. DeliveryRelationInfoTrigger();
  479. DeliveryCountEvent();
  480. }
  481. }
  482. #endregion
  483. #region 合约单位名称枚举-交易商品
  484. /// <summary>
  485. /// 合约单位名称枚举-交易商品
  486. /// </summary>
  487. public string AgreeUnitType
  488. {
  489. get
  490. {
  491. if (CurrentGoods == null)
  492. {
  493. return string.Empty;
  494. }
  495. return CacheManager.TradeGoodsUnit.Where(x => x.UNITID == CurrentGoods.currentGoodsunit).Select(x => x.GOODSUNITNAME).FirstOrDefault();
  496. }
  497. }
  498. #endregion
  499. #region 合约单位名称枚举-交割商品
  500. private string _deliveryAgreeUnitType = string.Empty;
  501. /// <summary>
  502. /// 合约单位名称枚举-交割商品
  503. /// </summary>
  504. public string DeliveryAgreeUnitType
  505. {
  506. get
  507. {
  508. return _deliveryAgreeUnitType;
  509. }
  510. set
  511. {
  512. Set(() => DeliveryAgreeUnitType, ref _deliveryAgreeUnitType, value);
  513. }
  514. }
  515. #endregion
  516. #region 冻结头寸数量
  517. /// <summary>
  518. /// 冻结头寸数量
  519. /// </summary>
  520. private decimal _positionFzQty;
  521. /// <summary>
  522. /// 冻结头寸数量
  523. /// </summary>
  524. public decimal PositionFzQty
  525. {
  526. get { return _positionFzQty; }
  527. set { _positionFzQty = value; }
  528. }
  529. #endregion
  530. #region 冻结货款=交易货款+差价款
  531. /// <summary>
  532. /// 冻结货款=交易货款+申报数量/兑换系数*交割合约单位*差价升贴水
  533. /// 交易货款(保证金)=解占用扣全款
  534. /// 交易货款(全款)=交割申报手数*持仓单对应的持仓金额
  535. /// </summary>
  536. private decimal _freezeDeliveryMoney = decimal.Zero;
  537. /// <summary>
  538. /// 冻结货款
  539. /// </summary>
  540. public decimal FreezeDeliveryMoney
  541. {
  542. get
  543. {
  544. return _freezeDeliveryMoney;
  545. }
  546. set
  547. {
  548. Set(() => FreezeDeliveryMoney, ref _freezeDeliveryMoney, value);
  549. RaisePropertyChanged(() => FreezeDeliveryMoneyFormat);
  550. }
  551. }
  552. /// <summary>
  553. /// 冻结货款 -格式化
  554. /// </summary>
  555. public string FreezeDeliveryMoneyFormat
  556. {
  557. get
  558. {
  559. return FreezeDeliveryMoney.ToString("f2");
  560. }
  561. }
  562. #endregion
  563. #region P交易商品冻结交易货款
  564. private decimal _freezeTradeMoney = decimal.Zero;
  565. /// <summary>
  566. /// P交易商品冻结交易货款
  567. /// </summary>
  568. public decimal FreezeTradeMoney
  569. {
  570. get
  571. {
  572. return _freezeTradeMoney;
  573. }
  574. set
  575. {
  576. Set(() => FreezeTradeMoney, ref _freezeTradeMoney, value);
  577. RaisePropertyChanged(() => FreezeTradeMoneyFormat);
  578. RaisePropertyChanged(() => FreezeTradeMoneyTooltip);
  579. }
  580. }
  581. /// <summary>
  582. /// 冻结交易货款 -格式化
  583. /// </summary>
  584. public string FreezeTradeMoneyFormat
  585. {
  586. get
  587. {
  588. return FreezeTradeMoney.ToString("f2");
  589. }
  590. }
  591. /// <summary>
  592. /// 冻结交易货款提示
  593. /// </summary>
  594. public string FreezeTradeMoneyTooltip
  595. {
  596. get
  597. {
  598. var TempItem = CurrentGoodsDeliveryRelation;
  599. if (TempItem != null)
  600. {
  601. var sbBuilder = new StringBuilder();
  602. decimal pfreeze = 0m;
  603. if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  604. {
  605. //交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 关联交易商品合约单位-(单手占用资金 * 申报数量)
  606. sbBuilder.AppendLine(Muchinfo.MTPClient.Resources.Client_Resource.PGoods_FreezeTradeMoneyTooltip);
  607. pfreeze = DeliveryCount * Math.Round(DeliveryPrice, 2, MidpointRounding.AwayFromZero) * CurrentGoods.currentAgreeunit;
  608. sbBuilder.AppendLine(
  609. string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Calc_FreezeTradeMoneyTooltip,
  610. Math.Round(pfreeze, 2, MidpointRounding.AwayFromZero),
  611. DeliveryCount, DeliveryPriceFormat, CurrentGoods.currentAgreeunit));
  612. }
  613. if (TempItem.RelationMode == eDeliveryContractLink.PAndX)//&& CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN
  614. {
  615. var RelationGoodsItem = FindRelationGoodsInfoByID(TempItem.RelationGoodsId);
  616. if (RelationGoodsItem != null && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  617. {
  618. //关联交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 关联交易商品合约单位
  619. sbBuilder.AppendLine(Muchinfo.MTPClient.Resources.Client_Resource.XGoods_FreezeTradeMoneyTooltip);
  620. var xfreeze = DeliveryCount * Math.Round(RelationGoodsHoldPrice, 2, MidpointRounding.AwayFromZero) * RelationGoodsItem.RelationAgreeunit;
  621. sbBuilder.AppendLine(
  622. string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Calc_FreezeTradeMoneyTooltip,
  623. Math.Round(xfreeze, 2, MidpointRounding.AwayFromZero),
  624. DeliveryCount, RelationGoodsHoldPriceFormat, RelationGoodsItem.RelationAgreeunit));
  625. if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  626. {
  627. sbBuilder.AppendLine(Muchinfo.MTPClient.Resources.Client_Resource.Sum_FreezeTradeMoneyTooltip);
  628. sbBuilder.AppendLine(string.Format("{0} ={1} + {2}", Math.Round(pfreeze + xfreeze, 2, MidpointRounding.AwayFromZero), Math.Round(pfreeze, 2, MidpointRounding.AwayFromZero), Math.Round(xfreeze, 2, MidpointRounding.AwayFromZero)));
  629. }
  630. }
  631. }
  632. return sbBuilder.ToString();
  633. }
  634. return string.Empty;
  635. }
  636. }
  637. #endregion
  638. #region X交易商品冻结交易货款
  639. private decimal _freezeDeliveryTradeMoney = decimal.Zero;
  640. /// <summary>
  641. /// X交易商品冻结交易货款
  642. /// </summary>
  643. public decimal FreezeDeliveryTradeMoney
  644. {
  645. get
  646. {
  647. return _freezeDeliveryTradeMoney;
  648. }
  649. set
  650. {
  651. Set(() => FreezeDeliveryTradeMoney, ref _freezeDeliveryTradeMoney, value);
  652. RaisePropertyChanged(() => FreezeDeliveryTradeMoneyFormat);
  653. }
  654. }
  655. /// <summary>
  656. /// 交割商品冻结交易货款 -格式化
  657. /// </summary>
  658. public string FreezeDeliveryTradeMoneyFormat
  659. {
  660. get
  661. {
  662. return FreezeDeliveryTradeMoney.ToString("f2");
  663. }
  664. }
  665. #endregion
  666. #region 冻结差价款
  667. private decimal _freezePriceMoveMoney = decimal.Zero;
  668. /// <summary>
  669. /// 冻结差价款
  670. /// </summary>
  671. public decimal FreezePriceMoveMoney
  672. {
  673. get
  674. {
  675. return _freezePriceMoveMoney;
  676. }
  677. set
  678. {
  679. Set(() => FreezePriceMoveMoney, ref _freezePriceMoveMoney, value);
  680. RaisePropertyChanged(() => FreezePriceMoveMoneyFormat);
  681. RaisePropertyChanged(() => FreezePriceMoveMoneyTooltip);
  682. }
  683. }
  684. /// <summary>
  685. /// 冻结差价款 -格式化
  686. /// </summary>
  687. public string FreezePriceMoveMoneyFormat
  688. {
  689. get
  690. {
  691. return FreezePriceMoveMoney.ToString("f2");
  692. }
  693. }
  694. /// <summary>
  695. /// 冻结差价款提示
  696. /// </summary>
  697. public string FreezePriceMoveMoneyTooltip
  698. {
  699. get
  700. {
  701. // var TempItem = tempDeliveryConfigList.FirstOrDefault();
  702. var TempItem = CurrentGoodsDeliveryRelation;
  703. //差价款=申报数量/兑换系数*交割合约单位*差价升贴水
  704. //FreezePriceMoveMoney = _deliveryCount / TempItem.Conversion * TempItem.AgreeUnit * TempItem.DeliveryPriceMove;
  705. if (TempItem != null)
  706. {
  707. return string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Deliviery_FreezePriceMoveMoneyTip, Math.Round(FreezePriceMoveMoney, 2, MidpointRounding.AwayFromZero), DeliveryCount, TempItem.Conversion, TempItem.currentAgreeunit, TempItem.DeliveryPriceMove);
  708. }
  709. return string.Empty;
  710. }
  711. }
  712. #endregion
  713. #region 交割价格
  714. private decimal _deliveryPrice = decimal.Zero;
  715. /// <summary>
  716. /// 交割价格
  717. /// Changes to that property's value raise the PropertyChanged event.
  718. /// </summary>
  719. public decimal DeliveryPrice
  720. {
  721. get
  722. {
  723. return _deliveryPrice;
  724. }
  725. set
  726. {
  727. Set(() => DeliveryPrice, ref _deliveryPrice, value);
  728. RaisePropertyChanged(() => DeliveryPriceFormat);
  729. }
  730. }
  731. /// <summary>
  732. /// 交割价格-格式化
  733. /// </summary>
  734. public string DeliveryPriceFormat
  735. {
  736. get
  737. {
  738. if (DeliveryPrice > decimal.Zero)
  739. {
  740. return DeliveryPrice.ToString("f2");
  741. }
  742. else
  743. {
  744. return "-";
  745. }
  746. }
  747. }
  748. #endregion
  749. #region 交割价格-类型【0持仓价-1结算价-2协议价-3最新价】
  750. private string _deliveryPriceTypeDisplay = string.Empty;
  751. /// <summary>
  752. /// 交割价格-类型【0持仓价-1结算价-2协议价-3最新价】
  753. /// Changes to that property's value raise the PropertyChanged event.
  754. /// </summary>
  755. public string DeliveryPriceTypeDisplay
  756. {
  757. get
  758. {
  759. return _deliveryPriceTypeDisplay;
  760. }
  761. set
  762. {
  763. Set(() => DeliveryPriceTypeDisplay, ref _deliveryPriceTypeDisplay, value);
  764. }
  765. }
  766. #endregion
  767. #region 最小交割数量
  768. private decimal _minDeliveryUnit = 1;
  769. /// <summary>
  770. /// 最小交割数量
  771. /// </summary>
  772. public decimal MinDeliveryUnit
  773. {
  774. get
  775. {
  776. return _minDeliveryUnit;
  777. }
  778. set
  779. {
  780. Set(() => MinDeliveryUnit, ref _minDeliveryUnit, value);
  781. }
  782. }
  783. #endregion
  784. #region 最大交割数量
  785. private decimal _maxDeliveryUnit = 1;
  786. /// <summary>
  787. /// 最大交割数量
  788. /// </summary>
  789. public decimal MaxDeliveryUnit
  790. {
  791. get
  792. {
  793. return _maxDeliveryUnit;
  794. }
  795. set
  796. {
  797. Set(() => MaxDeliveryUnit, ref _maxDeliveryUnit, value);
  798. }
  799. }
  800. #endregion
  801. #region 交易规则转换单位
  802. private string _tradeRuleTrans = string.Empty;
  803. /// <summary>
  804. /// 交易规则转换单位
  805. /// </summary>
  806. public string TradeRuleTrans
  807. {
  808. get
  809. {
  810. return _tradeRuleTrans;
  811. }
  812. set
  813. {
  814. Set(() => TradeRuleTrans, ref _tradeRuleTrans, value);
  815. }
  816. }
  817. #endregion
  818. #region 是否显示交易规则转换单位
  819. private Visibility _isVisibilityTradeRule = Visibility.Collapsed;
  820. /// <summary>
  821. /// 是否显示交易规则转换单位
  822. /// </summary>
  823. public Visibility IsVisibilityTradeRule
  824. {
  825. get
  826. {
  827. return _isVisibilityTradeRule;
  828. }
  829. set
  830. {
  831. Set(() => IsVisibilityTradeRule, ref _isVisibilityTradeRule, value);
  832. }
  833. }
  834. #endregion
  835. #region 是否隐藏冻结资金
  836. private Visibility _isVisibilityFreezeMoney = Visibility.Collapsed;
  837. /// <summary>
  838. /// Sets and gets the IsVisibilityFrezzMoney property.
  839. /// Changes to that property's value raise the PropertyChanged event.
  840. /// </summary>
  841. public Visibility IsVisibilityFreezeMoney
  842. {
  843. get
  844. {
  845. return _isVisibilityFreezeMoney;
  846. }
  847. set
  848. {
  849. Set(() => IsVisibilityFreezeMoney, ref _isVisibilityFreezeMoney, value);
  850. }
  851. }
  852. #endregion
  853. #region 是否隐藏交易货款
  854. private Visibility _isVisibilityDeliveryTradeMoney = Visibility.Collapsed;
  855. /// <summary>
  856. /// Sets and gets the IsVisibilityMoneryModeMargin property.
  857. /// </summary>
  858. public Visibility IsVisibilityDeliveryTradeMoney
  859. {
  860. get
  861. {
  862. return _isVisibilityDeliveryTradeMoney;
  863. }
  864. set
  865. {
  866. Set(() => IsVisibilityDeliveryTradeMoney, ref _isVisibilityDeliveryTradeMoney, value);
  867. }
  868. }
  869. #endregion
  870. #region 当前选择交易商品
  871. private GoodsDeliveryRelationModel _currentGoods;
  872. /// <summary>
  873. /// 当前选择交易商品
  874. /// </summary>
  875. public GoodsDeliveryRelationModel CurrentGoods
  876. {
  877. get { return _currentGoods; }
  878. set
  879. {
  880. Set(() => CurrentGoods, ref _currentGoods, value);
  881. if (_currentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  882. {
  883. //if (FreezeTradeMoney > decimal.Zero)
  884. IsVisibilityDeliveryTradeMoney = Visibility.Visible;
  885. //保证金开启冻结:提示,温馨提示 和全额保存一致 20161228
  886. // WarningTips = Client_Resource.DeliveryOrderView_WarningTips_MONEYMODE_MARGIN;
  887. // TotalFreezenMoneyText = Client_Resource.DeliveryOrderView_FreezeDeliveryMoney_MONEYMODE_MARGIN;
  888. }
  889. else
  890. {
  891. IsVisibilityDeliveryTradeMoney = Visibility.Collapsed;
  892. //WarningTips = Client_Resource.DeliveryOrderView_WarningTips;
  893. //TotalFreezenMoneyText = Client_Resource.DeliveryOrderView_FreezeDeliveryMoney;
  894. }
  895. if (BuyOrSell == Direction.Ask)
  896. {
  897. RollBackMatchOrderList();
  898. }
  899. //BuyOrSell = Direction.Bid;//重置买方向
  900. SetDeliveryCount();
  901. }
  902. }
  903. #endregion
  904. #region 当前商品的持仓单
  905. private List<HoldingOrder> _holdDetails;
  906. /// <summary>
  907. /// 当前商品的持仓单
  908. /// </summary>
  909. public List<HoldingOrder> HoldDetails
  910. {
  911. get { return _holdDetails; }
  912. set { Set(() => HoldDetails, ref _holdDetails, value); }
  913. }
  914. #endregion
  915. #region 持仓汇总
  916. /// <summary>
  917. /// 持仓汇总
  918. /// </summary>
  919. private decimal _totalHoldDetails;
  920. /// <summary>
  921. /// 持仓汇总
  922. /// </summary>
  923. public decimal TotalHoldDetails
  924. {
  925. get
  926. {
  927. return _totalHoldDetails;
  928. }
  929. set
  930. {
  931. Set(() => TotalHoldDetails, ref _totalHoldDetails, value);
  932. }
  933. }
  934. #endregion
  935. #region 填写范围错误提示
  936. private Visibility _MinMaxErrVisibility = Visibility.Hidden;
  937. /// <summary>
  938. /// 填写范围错误提示
  939. /// </summary>
  940. public Visibility MinMaxErrVisibility
  941. {
  942. get
  943. {
  944. //if (MinMaxDeliNumVisibility != Visibility.Visible)
  945. //{
  946. // _MinMaxErrVisibility = Visibility.Visible;
  947. //}
  948. return _MinMaxErrVisibility;
  949. }
  950. }
  951. #endregion
  952. #region 是否显示填写范围
  953. private Visibility _minMaxDeliNumVisibility = Visibility.Visible;
  954. /// <summary>
  955. /// 是否显示填写范围
  956. /// </summary>
  957. public Visibility MinMaxDeliNumVisibility
  958. {
  959. get
  960. {
  961. if (AvailHoldQty > 0 && MinDeliveryUnit <= MaxDeliveryUnit)
  962. {
  963. _minMaxDeliNumVisibility = Visibility.Visible;
  964. _MinMaxErrVisibility = Visibility.Hidden;
  965. }
  966. else //if(AvailHoldQty <= 0)
  967. {
  968. _minMaxDeliNumVisibility = Visibility.Hidden;
  969. _MinMaxErrVisibility = Visibility.Visible;
  970. }
  971. RaisePropertyChanged(() => MinMaxErrVisibility);
  972. return _minMaxDeliNumVisibility;
  973. }
  974. }
  975. #endregion
  976. #region 可用持仓数量
  977. private decimal _availHoldQty = decimal.Zero;
  978. /// <summary>
  979. /// 可用持仓数量
  980. /// </summary>
  981. public decimal AvailHoldQty
  982. {
  983. get
  984. {
  985. return _availHoldQty;
  986. }
  987. set
  988. {
  989. Set(() => AvailHoldQty, ref _availHoldQty, value);
  990. }
  991. }
  992. #endregion
  993. #region 当前持仓明细表
  994. //private HoldingOrder _selectOrder;
  995. ///// <summary>
  996. ///// 当前持仓明细表商品
  997. ///// </summary>
  998. //public HoldingOrder SelectOrder
  999. //{
  1000. // get { return _selectOrder; }
  1001. // set
  1002. // {
  1003. // Set(() => SelectOrder, ref _selectOrder, value);
  1004. // if (value != null)
  1005. // {
  1006. // //当前持仓可用数量
  1007. // DeliveryCount = HoldCount = SelectOrder.AvailQty;
  1008. // }
  1009. // }
  1010. //}
  1011. #endregion
  1012. #region 申报数量-转交割数量
  1013. private decimal _relationNum = decimal.Zero;
  1014. /// <summary>
  1015. /// 申报数量-转交割数量
  1016. /// </summary>
  1017. public decimal RelationNum
  1018. {
  1019. get
  1020. {
  1021. return _relationNum;
  1022. }
  1023. set
  1024. {
  1025. Set(() => RelationNum, ref _relationNum, value);
  1026. RaisePropertyChanged(() => RelationNumDisplay);
  1027. }
  1028. }
  1029. /// <summary>
  1030. /// 申报数量-转交割数量-格式化
  1031. /// </summary>
  1032. public string RelationNumDisplay
  1033. {
  1034. get { return RelationNum.ToString("f2"); }
  1035. }
  1036. #endregion
  1037. #region 【置灰】设置按键不可用
  1038. private bool _oKButtonEnabled = true;
  1039. /// <summary>
  1040. ///设置按键不可用
  1041. /// </summary>
  1042. public bool OKButtonEnabled
  1043. {
  1044. get
  1045. {
  1046. return _oKButtonEnabled;
  1047. }
  1048. set
  1049. {
  1050. Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
  1051. }
  1052. }
  1053. #endregion
  1054. #region 是否忙
  1055. private bool _isBusy;
  1056. /// <summary>
  1057. /// 是否忙
  1058. /// </summary>
  1059. public bool IsBusy
  1060. {
  1061. get { return _isBusy; }
  1062. set { Set(() => IsBusy, ref _isBusy, value); }
  1063. }
  1064. #endregion
  1065. #region 服务忙提示
  1066. private string _busyTips;
  1067. /// <summary>
  1068. /// 服务忙提示
  1069. /// </summary>
  1070. public string BusyTips
  1071. {
  1072. get
  1073. {
  1074. return _busyTips;
  1075. }
  1076. set
  1077. {
  1078. Set(() => BusyTips, ref _busyTips, value);
  1079. }
  1080. }
  1081. #endregion
  1082. #region 错误信息提示
  1083. private string _ShowErrorInfo = string.Empty;
  1084. /// <summary>
  1085. /// Sets and gets the ShowErrorInfo property.
  1086. /// </summary>
  1087. public string ShowErrorInfo
  1088. {
  1089. get
  1090. {
  1091. return _ShowErrorInfo;
  1092. }
  1093. set
  1094. {
  1095. Set(() => ShowErrorInfo, ref _ShowErrorInfo, value);
  1096. }
  1097. }
  1098. private Visibility _IsShowErrorInfo = Visibility.Collapsed;
  1099. /// <summary>
  1100. /// Sets and gets the IsShowErrorInfo property.
  1101. /// </summary>
  1102. public Visibility IsShowErrorInfo
  1103. {
  1104. get
  1105. {
  1106. return _IsShowErrorInfo;
  1107. }
  1108. set
  1109. {
  1110. Set(() => IsShowErrorInfo, ref _IsShowErrorInfo, value);
  1111. }
  1112. }
  1113. #endregion
  1114. #region 当前交割配置明细/当前交割配置List
  1115. public List<DeliveryConfig> tempDeliveryConfigList = new List<DeliveryConfig>();
  1116. private DeliveryConfig _currentDeliveryGoodsConfig = null;
  1117. /// <summary>
  1118. /// 当前交割配置明细
  1119. /// Changes to that property's value raise the PropertyChanged event.
  1120. /// </summary>
  1121. public DeliveryConfig CurrentDeliveryGoodsConfig
  1122. {
  1123. get
  1124. {
  1125. return _currentDeliveryGoodsConfig;
  1126. }
  1127. set
  1128. {
  1129. Set(() => CurrentDeliveryGoodsConfig, ref _currentDeliveryGoodsConfig, value);
  1130. }
  1131. }
  1132. public List<GoodsDeliveryRelationModel> tempGoodsDeliveryRelationList = new List<GoodsDeliveryRelationModel>();
  1133. private GoodsDeliveryRelationModel _currentGoodsDeliveryRelation = null;
  1134. /// <summary>
  1135. /// 当前交割配置明细
  1136. /// Changes to that property's value raise the PropertyChanged event.
  1137. /// </summary>
  1138. public GoodsDeliveryRelationModel CurrentGoodsDeliveryRelation
  1139. {
  1140. get
  1141. {
  1142. return _currentGoodsDeliveryRelation;
  1143. }
  1144. set
  1145. {
  1146. Set(() => CurrentGoodsDeliveryRelation, ref _currentGoodsDeliveryRelation, value);
  1147. }
  1148. }
  1149. #endregion
  1150. #region 可申报数量
  1151. private int _canDeliveryCount = 0;
  1152. /// <summary>
  1153. /// 可申报数量
  1154. /// Changes to that property's value raise the PropertyChanged event.
  1155. /// </summary>
  1156. public int CanDeliveryCount
  1157. {
  1158. get
  1159. {
  1160. return _canDeliveryCount;
  1161. }
  1162. set
  1163. {
  1164. Set(() => CanDeliveryCount, ref _canDeliveryCount, value);
  1165. }
  1166. }
  1167. #endregion
  1168. #region 是否隐藏关联交易商品[P+X]
  1169. private Visibility _isVisibilityRelationGoodsInfo = Visibility.Collapsed;
  1170. /// <summary>
  1171. /// 是否隐藏关联交易商品[P+X]
  1172. /// </summary>
  1173. public Visibility IsVisibilityRelationGoodsInfo
  1174. {
  1175. get
  1176. {
  1177. return _isVisibilityRelationGoodsInfo;
  1178. }
  1179. set
  1180. {
  1181. Set(() => IsVisibilityRelationGoodsInfo, ref _isVisibilityRelationGoodsInfo, value);
  1182. }
  1183. }
  1184. #endregion
  1185. #region 关联交易商品名称[P+X]
  1186. private string _relationGoods = string.Empty;
  1187. /// <summary>
  1188. /// 关联交易商品名称[P+X]
  1189. /// </summary>
  1190. public string RelationGoodsName
  1191. {
  1192. get
  1193. {
  1194. return _relationGoods;
  1195. }
  1196. set
  1197. {
  1198. Set(() => RelationGoodsName, ref _relationGoods, value);
  1199. }
  1200. }
  1201. #endregion
  1202. #region 关联交易商品持仓数量[P+X]
  1203. private decimal _relationGoodsHoldQty = decimal.Zero;
  1204. /// <summary>
  1205. /// 关联交易商品持仓数量[P+X]
  1206. /// </summary>
  1207. public decimal RelationGoodsHoldQty
  1208. {
  1209. get
  1210. {
  1211. return _relationGoodsHoldQty;
  1212. }
  1213. set
  1214. {
  1215. Set(() => RelationGoodsHoldQty, ref _relationGoodsHoldQty, value);
  1216. }
  1217. }
  1218. #endregion
  1219. #region 关联交易商品交割价格[P+X]
  1220. private decimal _relationGoodsHoldPrice = decimal.Zero;
  1221. /// <summary>
  1222. /// 关联交易商品交割价格[P+X]
  1223. /// </summary>
  1224. public decimal RelationGoodsHoldPrice
  1225. {
  1226. get
  1227. {
  1228. return _relationGoodsHoldPrice;
  1229. }
  1230. set
  1231. {
  1232. Set(() => RelationGoodsHoldPrice, ref _relationGoodsHoldPrice, value);
  1233. RaisePropertyChanged(() => RelationGoodsHoldPriceFormat);
  1234. }
  1235. }
  1236. /// <summary>
  1237. /// 关联交易商品交割价格[P+X]格式化
  1238. /// </summary>
  1239. public string RelationGoodsHoldPriceFormat
  1240. {
  1241. get
  1242. {
  1243. if (RelationGoodsHoldPrice > decimal.Zero)
  1244. {
  1245. return RelationGoodsHoldPrice.ToString("f2");
  1246. }
  1247. else
  1248. {
  1249. return "-";
  1250. }
  1251. }
  1252. }
  1253. #endregion
  1254. #region 当前关联交易商品的持仓单[P+X]
  1255. private List<HoldingOrder> _relationholdDetails;
  1256. /// <summary>
  1257. /// 当前关联交易商品的持仓单[P+X]
  1258. /// </summary>
  1259. public List<HoldingOrder> RelationHoldDetails
  1260. {
  1261. get { return _relationholdDetails; }
  1262. set { Set(() => RelationHoldDetails, ref _relationholdDetails, value); }
  1263. }
  1264. #endregion
  1265. #region 差价升贴水
  1266. private string _deliveryPriceMoveDisplay = string.Empty;
  1267. /// <summary>
  1268. /// 差价升贴水
  1269. /// </summary>
  1270. public string DeliveryPriceMoveDisplay
  1271. {
  1272. get
  1273. {
  1274. return _deliveryPriceMoveDisplay;
  1275. }
  1276. set
  1277. {
  1278. Set(() => DeliveryPriceMoveDisplay, ref _deliveryPriceMoveDisplay, value);
  1279. }
  1280. }
  1281. #endregion
  1282. #region 关联商品占用保证金均价
  1283. private decimal _relationPerUsedMargin = decimal.Zero;
  1284. /// <summary>
  1285. /// 占用保证金均价RelationPerUsedMargin
  1286. /// </summary>
  1287. public decimal RelationPerUsedMargin
  1288. {
  1289. get
  1290. {
  1291. return _relationPerUsedMargin;
  1292. }
  1293. set
  1294. {
  1295. Set(() => RelationPerUsedMargin, ref _relationPerUsedMargin, value);
  1296. }
  1297. }
  1298. #endregion
  1299. #region 当前商品占用保证金均价
  1300. private decimal _currentPerUsedMargin = decimal.Zero;
  1301. /// <summary>
  1302. /// 当前商品占用保证金均价
  1303. /// </summary>
  1304. public decimal CurrentPerUsedMargin
  1305. {
  1306. get
  1307. {
  1308. return _currentPerUsedMargin;
  1309. }
  1310. set
  1311. {
  1312. Set(() => CurrentPerUsedMargin, ref _currentPerUsedMargin, value);
  1313. }
  1314. }
  1315. private decimal _deliveryFee;
  1316. /// <summary>
  1317. /// 每手交割手续费
  1318. /// </summary>
  1319. public decimal DeliveryFee
  1320. {
  1321. get { return _deliveryFee; }
  1322. set { Set(() => DeliveryFee, ref _deliveryFee, value); }
  1323. }
  1324. private decimal _freezeFax;
  1325. /// <summary>
  1326. /// 每手交割税款
  1327. /// </summary>
  1328. public decimal FreezeFax
  1329. {
  1330. get
  1331. {
  1332. return _freezeFax;
  1333. }
  1334. set { Set(() => FreezeFax, ref _freezeFax, value); }
  1335. }
  1336. /// <summary>
  1337. /// 交割总税款
  1338. /// </summary>
  1339. public decimal TotalFreezeFax
  1340. {
  1341. get
  1342. {
  1343. return Math.Round(FreezeFax * DeliveryCount, 2, MidpointRounding.AwayFromZero);
  1344. }
  1345. }
  1346. /// <summary>
  1347. /// 交割交割手续费
  1348. /// </summary>
  1349. public decimal TotalDeliveryFee
  1350. {
  1351. get
  1352. {
  1353. return Math.Round(DeliveryFee * DeliveryCount, 2, MidpointRounding.AwayFromZero); ;
  1354. }
  1355. }
  1356. #endregion
  1357. #endregion "Public Properties To Get/Set "
  1358. #region "Public Commands"
  1359. #region 选中Command
  1360. /// <summary>
  1361. /// 选中
  1362. /// </summary>
  1363. private RelayCommand<string> selectCommand;
  1364. public RelayCommand<string> SelectCommand
  1365. {
  1366. get
  1367. {
  1368. return selectCommand ?? (selectCommand = new RelayCommand<string>(
  1369. (x) =>
  1370. {
  1371. var sourceList = DeliveryMatchOrderList.ToList().FindAll(p => p.WRCode == x);
  1372. for (int i = 0; i < sourceList.Count(); i++)
  1373. {
  1374. if (sourceList[i].NumSort == int.MaxValue)
  1375. {
  1376. sourceList[i].NumSort = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true).Count();
  1377. }
  1378. }
  1379. SettlementDeliveryMatchNum();
  1380. }));
  1381. }
  1382. }
  1383. #endregion
  1384. #region 取消选中Command
  1385. /// <summary>
  1386. /// 取消选中
  1387. /// </summary>
  1388. private RelayCommand<string> unSelectCommand;
  1389. public RelayCommand<string> UnSelectCommand
  1390. {
  1391. get
  1392. {
  1393. return unSelectCommand ?? (unSelectCommand = new RelayCommand<string>(
  1394. (x) =>
  1395. {
  1396. var sourceList = DeliveryMatchOrderList.ToList().FindAll(p => p.WRCode == x);
  1397. for (int i = 0; i < sourceList.Count(); i++)
  1398. {
  1399. if (sourceList[i].NumSort != int.MaxValue)
  1400. {
  1401. sourceList[i].NumSort = int.MaxValue;
  1402. }
  1403. }
  1404. SettlementDeliveryMatchNum();
  1405. }));
  1406. }
  1407. }
  1408. #endregion
  1409. /// <summary>
  1410. /// 下单窗口取消
  1411. /// </summary>
  1412. public RelayCommand<Window> CancelCommand
  1413. {
  1414. get
  1415. {
  1416. return new RelayCommand<Window>((dialog) =>
  1417. {
  1418. dialog.DialogResult = false;
  1419. });
  1420. }
  1421. }
  1422. /// <summary>
  1423. /// 下单确定
  1424. /// </summary>
  1425. public RelayCommand<Window> OKCommand
  1426. {
  1427. get
  1428. {
  1429. return new RelayCommand<Window>((dialog) =>
  1430. {
  1431. OKButtonEnabled = false;
  1432. string errorMsg = string.Empty;
  1433. bool validateBool = Validated(ref errorMsg); ////内容验证
  1434. if (validateBool)
  1435. {
  1436. IsBusy = true;
  1437. _openWindow = dialog;
  1438. var newOrder = new DeliveryOrderReqModel()
  1439. {
  1440. };
  1441. //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  1442. // UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  1443. //{
  1444. // newOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  1445. //}
  1446. //else
  1447. //{
  1448. // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId;
  1449. //}
  1450. try
  1451. {
  1452. //InitTimer();
  1453. //按照头寸交割单
  1454. _deliveryService.DeliveryApplyOrder(newOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  1455. }
  1456. finally
  1457. {
  1458. //DisposeTimer();
  1459. }
  1460. }
  1461. else
  1462. {
  1463. MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
  1464. OKButtonEnabled = true;
  1465. }
  1466. });
  1467. }
  1468. }
  1469. #region 测试提交Command
  1470. private RelayCommand buttonCommand;
  1471. public RelayCommand ButtonCommand
  1472. {
  1473. get
  1474. {
  1475. return buttonCommand ?? (buttonCommand = new RelayCommand(
  1476. () =>
  1477. {
  1478. int count = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true).Count;
  1479. for (int i = 0; i < count; i++)
  1480. MessageBox.Show(DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true)[i].WRCode + "," + DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true)[i].EnableQty);
  1481. }));
  1482. }
  1483. }
  1484. #endregion
  1485. #endregion "Public Commands"
  1486. #region "Private Methods"
  1487. private void DeliveryCountEvent()
  1488. {
  1489. ShowErrorInfo = string.Empty;
  1490. if (FreezeDeliveryMoney > usableFunds)
  1491. {
  1492. ShowErrorInfo = Client_Resource.DeliveryOrderViewModel_usableFundsNotEnough;// "资金不足,请修改交割数量";
  1493. }
  1494. if (DeliveryCount > MaxDeliveryUnit)
  1495. {
  1496. ShowErrorInfo = Client_Resource.DeliveryOrderViewModel_HolderNotEnough;// "持仓数量不足,请修改交割数量";
  1497. }
  1498. if ((UserManager.CurrentTradeAccount.AccountType != eUserType.USERTYPE_INVESTOR&& CurrentGoods.currentTradeMode == eTradeMode.TRADEMODE_MARKETMAKE))
  1499. {
  1500. ShowErrorInfo = Client_Resource.DeliveryOrderViewModel_AccountTypeNotEnough;// "交易员账户,且商品是做市商品时,不可以发起交割申报";
  1501. }
  1502. IsEnableButtonEvent();
  1503. }
  1504. /// <summary>
  1505. /// 交割关联商品信息触发
  1506. /// </summary>
  1507. private void DeliveryRelationInfoTrigger()
  1508. {
  1509. if (CurrentGoodsDeliveryRelation != null)
  1510. {
  1511. //var TempItem = tempDeliveryConfigList.FirstOrDefault();
  1512. var TempItem = CurrentGoodsDeliveryRelation;
  1513. //交易商品数量-》转交割商品数量
  1514. RelationNum = _deliveryCount / TempItem.Conversion * TempItem.currentAgreeunit;
  1515. //差价款=申报数量/兑换系数*交割合约单位*差价升贴水
  1516. FreezePriceMoveMoney = _deliveryCount / TempItem.Conversion * TempItem.currentAgreeunit * TempItem.DeliveryPriceMove;
  1517. FreezeDeliveryTradeMoney = decimal.Zero;
  1518. FreezeTradeMoney = decimal.Zero;
  1519. FreezeDeliveryMoney = decimal.Zero;
  1520. if (TempItem.RelationMode == eDeliveryContractLink.PAndX)
  1521. {
  1522. //X交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 交易商品合约单位
  1523. //var RelationGoodsItem = CacheManager.CacheGoodsBaseInfos.Find(x => x.GoodsParameters.GoodsId == TempItem.RelationGoodsId);
  1524. var RelationGoodsItem = FindRelationGoodsInfoByID(TempItem.RelationGoodsId);
  1525. if (RelationGoodsItem != null)
  1526. {
  1527. if (TempItem.RelationMode == eDeliveryContractLink.PAndX && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN)//&& CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN
  1528. {
  1529. FreezeDeliveryTradeMoney = _deliveryCount * Math.Round(RelationGoodsHoldPrice, 2, MidpointRounding.AwayFromZero) * RelationGoodsItem.RelationAgreeunit;
  1530. }
  1531. if (CurrentGoods.currentMoneymode != eMoneyMode.MONEYMODE_MARGIN && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  1532. {
  1533. //交易货款=X交易货款
  1534. FreezeTradeMoney = FreezeDeliveryTradeMoney;
  1535. }
  1536. }
  1537. }
  1538. if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  1539. {
  1540. //P交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 交易商品合约单位
  1541. FreezeTradeMoney = (_deliveryCount * Math.Round(DeliveryPrice, 2, MidpointRounding.AwayFromZero) * CurrentGoods.currentAgreeunit) + FreezeDeliveryTradeMoney;
  1542. }
  1543. //冻结货款=P交易货款+差价款+x交易货款
  1544. FreezeDeliveryMoney = FreezeTradeMoney + FreezePriceMoveMoney;
  1545. FreezeDeliveryMoney += (TotalFreezeFax + TotalDeliveryFee);
  1546. RaisePropertyChanged(() => TotalFreezeFax);
  1547. RaisePropertyChanged(() => TotalDeliveryFee);
  1548. }
  1549. else
  1550. {
  1551. FreezeDeliveryTradeMoney = FreezeDeliveryMoney = FreezeTradeMoney = FreezePriceMoveMoney = RelationNum = decimal.Zero;
  1552. }
  1553. }
  1554. /// <summary>
  1555. /// 回滚仓单数据选择
  1556. /// </summary>
  1557. private void RollBackMatchOrderList()
  1558. {
  1559. #region 重置勾选单据
  1560. CurrentSelectedWrDetail = null;
  1561. if (DeliveryMatchOrderList != null && DeliveryMatchOrderList.Count() > 0)
  1562. {
  1563. var sourceList = DeliveryMatchOrderList.ToList();
  1564. for (int i = 0; i < sourceList.Count(); i++)
  1565. {
  1566. sourceList[i].IsSelected = false;
  1567. sourceList[i].IsEnabled = true;
  1568. }
  1569. }
  1570. OtherCanMatchQty = RelationNum;//tempOtherCanMatchQty;
  1571. AlreadyMatchQty = 0;
  1572. #endregion
  1573. IsEnableButtonEvent();
  1574. }
  1575. /// <summary>
  1576. /// 计算可配数量、剩余数量
  1577. /// </summary>
  1578. private void SettlementDeliveryMatchNum()
  1579. {
  1580. #region 配对数量仅能大于 等于 申报数量
  1581. AlreadyMatchQty = 0;
  1582. preOtherCanMatchQty = OtherCanMatchQty = RelationNum;
  1583. _currentSelectedWrDetail = new List<WrDetailModel>();
  1584. decimal leaveCount = preOtherCanMatchQty;
  1585. var sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true);
  1586. for (int i = 0; i < sourceList.Count(); i++)
  1587. {
  1588. if (sourceList[i].PriceMove == int.MinValue)
  1589. {
  1590. //sourceList[i].PriceMove = 0;
  1591. }
  1592. if (leaveCount >= sourceList[i].EnableQty)
  1593. {
  1594. //CurrentSelectedWrDetail.Add(new WrDetailModel() { WRId = (sourceList[i].WRID), DeliveryQty = (long)sourceList[i].EnableQty });
  1595. }
  1596. else
  1597. {
  1598. if (leaveCount > 0)
  1599. {
  1600. //CurrentSelectedWrDetail.Add(new WrDetailModel() { WRId = (sourceList[i].WRID), DeliveryQty = (long)leaveCount });
  1601. }
  1602. }
  1603. leaveCount = leaveCount - sourceList[i].EnableQty;
  1604. AlreadyMatchQty += sourceList[i].EnableQty;
  1605. }
  1606. OtherCanMatchQty = OtherCanMatchQty - AlreadyMatchQty;
  1607. if (OtherCanMatchQty < 0)
  1608. {
  1609. OtherCanMatchQty = 0;
  1610. AlreadyMatchQty = preOtherCanMatchQty;
  1611. }
  1612. #endregion
  1613. #region 屏蔽剩余勾选框
  1614. var sourceList_False = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == false);
  1615. if (OtherCanMatchQty == 0)
  1616. {
  1617. for (int i = 0; i < sourceList_False.Count(); i++)
  1618. {
  1619. sourceList_False[i].IsEnabled = false;
  1620. }
  1621. }
  1622. else
  1623. {
  1624. for (int i = 0; i < sourceList_False.Count(); i++)
  1625. {
  1626. sourceList_False[i].IsEnabled = true;
  1627. }
  1628. }
  1629. #endregion
  1630. IsEnableButtonEvent();
  1631. }
  1632. /// <summary>
  1633. /// 触发提交按钮是否可用
  1634. /// </summary>
  1635. private void IsEnableButtonEvent()
  1636. {
  1637. //交易员账户,且商品是做市商品时,不可以发起交割申报
  1638. if (BuyOrSell == Direction.Ask)
  1639. {
  1640. if (CurrentSelectedWrDetail != null
  1641. && CurrentSelectedWrDetail.Any()
  1642. && CurrentSelectedWrDetail.Count() > 0
  1643. && AlreadyMatchQty == preOtherCanMatchQty
  1644. && CurrentGoods != null
  1645. && FreezeDeliveryMoney <= usableFunds
  1646. && DeliveryCount <= MaxDeliveryUnit && DeliveryCount > 0
  1647. && (UserManager.CurrentTradeAccount.AccountType == eUserType.USERTYPE_INVESTOR || CurrentGoods.currentTradeMode != eTradeMode.TRADEMODE_MARKETMAKE)
  1648. )
  1649. {
  1650. OKButtonEnabled = true;
  1651. }
  1652. else
  1653. {
  1654. OKButtonEnabled = false;
  1655. }
  1656. }
  1657. else
  1658. {
  1659. if (MaxDeliveryUnit <= 0 || MinDeliveryUnit <= 0 || CurrentGoods == null || FreezeDeliveryMoney > usableFunds
  1660. || DeliveryCount > MaxDeliveryUnit || DeliveryCount <= 0
  1661. || (UserManager.CurrentTradeAccount.AccountType != eUserType.USERTYPE_INVESTOR && CurrentGoods.currentTradeMode == eTradeMode.TRADEMODE_MARKETMAKE)
  1662. )
  1663. {
  1664. OKButtonEnabled = false;
  1665. }
  1666. else
  1667. {
  1668. OKButtonEnabled = true;
  1669. }
  1670. }
  1671. }
  1672. #region 初始化下单计时时间
  1673. /// <summary>
  1674. /// 初始化下单计时时间
  1675. /// </summary>
  1676. //private void InitTimer()
  1677. //{
  1678. // _countTime = ApplicationParameter.ServerTimeOut;
  1679. // this._timer = new Timer(1000);
  1680. // this._timer.AutoReset = true;
  1681. // this._timer.Elapsed += _timer_Elapsed;
  1682. // this._timer.Start();
  1683. // //IsOrderVisible = true;
  1684. // BusyTips = string.Format(Client_Resource.Busy_Summit_Wait, _countTime);
  1685. //}
  1686. //void _timer_Elapsed(object sender, ElapsedEventArgs e)
  1687. //{
  1688. // _countTime--;
  1689. // BusyTips = string.Format(Client_Resource.Busy_Summit_Wait, _countTime);
  1690. //}
  1691. ///// <summary>
  1692. ///// 清除计时器
  1693. ///// </summary>
  1694. //private void DisposeTimer()
  1695. //{
  1696. // this._timer.Stop();
  1697. // this._timer.Elapsed -= _timer_Elapsed;
  1698. // this._timer.Close();
  1699. // //IsOrderVisible = false;
  1700. //}
  1701. #endregion
  1702. /// <summary>
  1703. /// 提交成功返回
  1704. /// </summary>
  1705. /// <param name="order"></param>
  1706. private void EntrurstSuccessCallBack(DeliveryOrderRspModel order)
  1707. {
  1708. IsBusy = false;
  1709. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  1710. {
  1711. OKButtonEnabled = true;
  1712. MessageBoxHelper.ShowSuccess(Client_Resource.Order_Success_Result,
  1713. Client_Resource.UI2014_Tips);
  1714. if (_openWindow != null)
  1715. {
  1716. _openWindow.Close();
  1717. this.Cleanup();
  1718. }
  1719. }));
  1720. //刷新正常单
  1721. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
  1722. }
  1723. /// <summary>
  1724. /// 委托失败返回
  1725. /// </summary>
  1726. /// <param name="errorEntity"></param>
  1727. private void EntrurstErrorCallBack(ErrorEntity errorEntity)
  1728. {
  1729. IsBusy = false;
  1730. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  1731. {
  1732. OKButtonEnabled = true;
  1733. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  1734. if (_openWindow != null)
  1735. {
  1736. _openWindow.Close();
  1737. //MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.HolderRefresh);
  1738. //MessengerHelper.DefaultSend(string.Empty, MessengerTokens.OrderRefresh);
  1739. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.HolderUpdate);
  1740. this.Cleanup();
  1741. }
  1742. }));
  1743. }
  1744. /// <summary>
  1745. /// 交割提货个人信息-成功返回
  1746. /// </summary>
  1747. /// <param name="orders"></param>
  1748. protected void QueryDepositPersonalInfoSuccess(DepositPersonalInfoRspModel itemModel)
  1749. {
  1750. if (itemModel != null)
  1751. {
  1752. CurrentDepositPersonalInfo = itemModel;
  1753. if (CurrentDepositPersonalInfo != null)
  1754. {
  1755. RecieveAddress = CurrentDepositPersonalInfo.address;
  1756. RecievePerson = CurrentDepositPersonalInfo.personName;
  1757. PhoneNum = CurrentDepositPersonalInfo.telphone;
  1758. }
  1759. }
  1760. IsBusy = false;
  1761. }
  1762. /// <summary>
  1763. /// 查询-交割规则-成功返回
  1764. /// </summary>
  1765. /// <param name="orders"></param>
  1766. protected void QueryRelationSuccess(List<GoodsDeliveryRelationModel> itemList)
  1767. {
  1768. if (itemList != null)
  1769. {
  1770. GoodsDeliveryRelationList = itemList;
  1771. #region 初始化交割商品
  1772. List<GoodsDeliveryRelationModel> tempGoods = new List<GoodsDeliveryRelationModel>();
  1773. //过滤全额商品->显示所有商品
  1774. //var GoodsList = CacheManager.CacheGoodsBaseInfos;//.Where(x => x.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY);
  1775. if (UserManager.GetCacheOrders<HoldingOrder>() != null && UserManager.GetCacheOrders<HoldingOrder>().Distinct().ToList().Count() > 0)
  1776. { //所有持仓单
  1777. var AllDeliveryGoodsIDList = UserManager.GetCacheOrders<HoldingOrder>().Select((item) => item.GoodsId).Distinct().ToList();
  1778. foreach (var id in AllDeliveryGoodsIDList)
  1779. {
  1780. foreach (var item in GoodsDeliveryRelationList)
  1781. {
  1782. if (id == item.GoodsId && !tempGoods.Exists(x => x.GoodsId == item.GoodsId))
  1783. {
  1784. tempGoods.Add(item);
  1785. }
  1786. }
  1787. }
  1788. }
  1789. DeliveryGoodsList = tempGoods;
  1790. if (DeliveryGoodsList != null && DeliveryGoodsList.Any() && DeliveryGoodsList.Count() > 0)
  1791. {
  1792. CurrentGoods = DeliveryGoodsList.FirstOrDefault();
  1793. if (_parameterInfo != null && _parameterInfo.GoodsId > 0)
  1794. {
  1795. CurrentGoods = DeliveryGoodsList.FirstOrDefault(x => x.GoodsId == _parameterInfo.GoodsId);
  1796. }
  1797. GetDepositPersonalInfo();
  1798. }
  1799. #endregion
  1800. }
  1801. IsBusy = false;
  1802. }
  1803. /// <summary>
  1804. /// 卖交割仓单信息查询-成功返回
  1805. /// </summary>
  1806. /// <param name="itemList"></param>
  1807. protected void WhRecieptInfoSuccess(List<DeliveryWhRecieptInfo> itemList)
  1808. {
  1809. if (itemList != null)
  1810. {
  1811. DeliveryMatchOrderList = itemList.Where(x => x.EnableQty > 0).ToList();
  1812. }
  1813. IsBusy = false;
  1814. }
  1815. /// <summary>
  1816. /// 交割商品关系配置失败返回
  1817. /// </summary>
  1818. /// <param name="errorEntity"></param>
  1819. private void DeliveryGoodsCallBack(ErrorEntity errorEntity)
  1820. {
  1821. IsBusy = false;
  1822. }
  1823. /// <summary>
  1824. /// 获取交割提货个人信息失败返回
  1825. /// </summary>
  1826. /// <param name="errorEntity"></param>
  1827. private void QueryDepositPersonalInfoCallBack(ErrorEntity errorEntity)
  1828. {
  1829. IsBusy = false;
  1830. }
  1831. /// <summary>
  1832. /// 初始化交割商品列表数据
  1833. /// </summary>
  1834. private void InitData()
  1835. {
  1836. IsBusy = true;
  1837. _currentLinkModel = eDeliveryContractLink.None;
  1838. _currentMoneyMode = eMoneyMode.MONEYMODE_MARGIN;
  1839. _deliveryService.QueryGoodsDeliveryRelationList(QueryRelationSuccess, DeliveryGoodsCallBack);
  1840. SetDeliveryCount();
  1841. }
  1842. /// <summary>
  1843. /// 重置数据初始值
  1844. /// </summary>
  1845. private void ResetData()
  1846. {
  1847. IsVisibilityRelationGoodsInfo = Visibility.Collapsed;
  1848. RelationGoodsHoldPrice = decimal.Zero;
  1849. RelationGoodsHoldQty = decimal.Zero;
  1850. DeliveryPrice = decimal.Zero;
  1851. AvailHoldQty = decimal.Zero;
  1852. CurrentGoodsDeliveryRelation = null;
  1853. DeliveryPriceMoveDisplay = "";
  1854. IsVisibilityHolderPrice = Visibility.Collapsed;
  1855. IsVisibilitySellModel = Visibility.Collapsed;
  1856. IsVisibilitySellModel_Show = Visibility.Collapsed;
  1857. OKButtonEnabled = true;
  1858. DeliveryMatchOrderList = null;
  1859. }
  1860. /// <summary>
  1861. /// 默认数据当没有获取到交割关系时
  1862. /// </summary>
  1863. private void DefaultDataWhenNoRelation()
  1864. {
  1865. CanDeliveryCount = 0;
  1866. DeliveryPriceTypeDisplay = "-";
  1867. DeliveryPrice = 0;
  1868. TradeRuleTrans = "-";
  1869. MinDeliveryUnit = 0;
  1870. MaxDeliveryUnit = 0;
  1871. }
  1872. /// <summary>
  1873. /// 设置可交收数量
  1874. /// </summary>
  1875. private void SetDeliveryCount()
  1876. {
  1877. ResetData();
  1878. if (CurrentGoods != null)
  1879. {
  1880. CurrentGoodsDeliveryRelation = GoodsDeliveryRelationList.FindAll(x => x.GoodsId == CurrentGoods.GoodsId).FirstOrDefault();
  1881. CheckIsSellEnable();
  1882. //P+X商品信息
  1883. GetPAndXDeliveryGoodsInfo();
  1884. IsBusy = false;
  1885. #region 参数赋值
  1886. if (CurrentGoodsDeliveryRelation != null)
  1887. {
  1888. //当前交割商品ID
  1889. _currentDeliveryGoodsId = CurrentGoodsDeliveryRelation.DeliveryGoodsId;
  1890. if (BuyOrSell == Direction.Ask)
  1891. {
  1892. GetSellDeliveryWhRecieptInfo();
  1893. }
  1894. _currentLinkModel = CurrentGoodsDeliveryRelation.RelationMode;
  1895. if (CurrentGoodsDeliveryRelation.RelationMode != eDeliveryContractLink.None)
  1896. {
  1897. //最大最小交割手数设置
  1898. MinMaxDeliveryHandQty();
  1899. }
  1900. else
  1901. {
  1902. DeliveryCount = MinDeliveryUnit = 1;
  1903. if (CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX && BuyOrSell == Direction.Bid)
  1904. {
  1905. var tempAvailHoldQty = Math.Min(RelationGoodsHoldQty, AvailHoldQty);
  1906. MaxDeliveryUnit = tempAvailHoldQty;
  1907. }
  1908. else
  1909. {
  1910. MaxDeliveryUnit = AvailHoldQty;
  1911. }
  1912. IsVisibilityFreezeMoney = Visibility.Collapsed;
  1913. }
  1914. DeliveryAgreeUnitType = CacheManager.TradeGoodsUnit.Where(x => x.UNITID == CurrentGoodsDeliveryRelation.GoodsUnitId).Select(x => x.GOODSUNITNAME).FirstOrDefault();
  1915. //交割价格-类型[//固定写死=》持仓价计算申报 20161209 xiaobao]
  1916. DeliveryPriceTypeDisplay = Resources.Client_Resource.ReckonPriceCalcMethod_HolderPrice;
  1917. if (BuyOrSell != Direction.Ask)//卖方向时候,屏蔽P+X信息
  1918. {
  1919. IsVisibilityRelationGoodsInfo = CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX ? Visibility.Visible : Visibility.Collapsed;
  1920. DeliveryPriceMoveDisplay = CurrentGoodsDeliveryRelation.DeliveryPriceMove != decimal.Zero ? CurrentGoodsDeliveryRelation.DeliveryPriceMove.ToString("f2") : "0";
  1921. if (IsVisibilityFreezeMoney == Visibility.Visible)
  1922. {
  1923. IsVisibilityHolderPrice = Visibility.Visible;
  1924. }
  1925. IsVisibilitySellModel = Visibility.Visible;
  1926. MessengerHelper.DefaultSend(650, MessengerTokens.DeliveryBuyOrSellChanged);
  1927. }
  1928. else
  1929. {
  1930. IsVisibilitySellModel_Show = Visibility.Visible;
  1931. MessengerHelper.DefaultSend(550, MessengerTokens.DeliveryBuyOrSellChanged);
  1932. }
  1933. //P+X 交割商品信息
  1934. //GetPAndXDeliveryGoodsInfo();
  1935. //交割算法取值
  1936. GetDeliveryPriceCalcMethod();
  1937. var maxLot = MaxDeliveryLots(); ////当前金额可交割数量 //&& _currentGoods.currentMoneymode != eMoneyMode.MONEYMODE_MARGIN 保证金也需要计算手数
  1938. if (FreezeDeliveryMoney != decimal.Zero && CurrentGoodsDeliveryRelation.RelationMode != eDeliveryContractLink.None)
  1939. {
  1940. MaxDeliveryUnit = Math.Min(maxLot, MaxDeliveryUnit);
  1941. }
  1942. }
  1943. else
  1944. {
  1945. //默认数据当没有获取到交割关系时
  1946. DefaultDataWhenNoRelation();
  1947. }
  1948. if (FreezeDeliveryMoney == decimal.Zero)
  1949. {
  1950. IsVisibilityFreezeMoney = Visibility.Collapsed;
  1951. }
  1952. #endregion
  1953. }
  1954. IsEnableButtonEvent();
  1955. RaisePropertyChanged(() => MinMaxDeliNumVisibility);
  1956. }
  1957. /// <summary>
  1958. /// 检测卖方向是否可用
  1959. /// </summary>
  1960. private void CheckIsSellEnable()
  1961. {
  1962. IsSellEnable = false;
  1963. if (CurrentGoods != null)
  1964. {
  1965. var currentGoodsMoneymode = CurrentGoods.currentMoneymode;
  1966. var currentGoodsTradeMode = CurrentGoods.currentTradeMode;
  1967. decimal AvailQty = decimal.Zero;
  1968. var holders = UserManager.GetCacheOrders<HoldingOrder>();
  1969. if (holders != null && holders.Any())
  1970. {
  1971. HoldDetails = holders.Where((item) => item.GoodsId == CurrentGoods.GoodsId && item.Direction == Direction.Ask).ToList();//卖方向持仓
  1972. if (HoldDetails != null && HoldDetails.Any())
  1973. {
  1974. var tempFzQty = HoldDetails.FirstOrDefault().PositionFzQty;
  1975. var totalHoldQty = HoldDetails.Sum((order) => order.Lot - order.LockQty);
  1976. AvailQty = totalHoldQty - tempFzQty;
  1977. }
  1978. }
  1979. //无卖持仓时,卖方向不可选置灰,仅竞价与混合-保证金商品-才可以发起卖交割
  1980. if (AvailQty > decimal.Zero && CurrentGoodsDeliveryRelation != null && CurrentGoodsDeliveryRelation.Sponsor == eSponsorType.Both && currentGoodsMoneymode == eMoneyMode.MONEYMODE_MARGIN && (currentGoodsTradeMode == eTradeMode.TRADEMODE_BIDDING || currentGoodsTradeMode == eTradeMode.TRADEMODE_BIDDINGMARKETMAKE))
  1981. {
  1982. IsSellEnable = true;
  1983. }
  1984. }
  1985. }
  1986. /// <summary>
  1987. /// 获取交割提货个人信息
  1988. /// </summary>
  1989. private void GetDepositPersonalInfo()
  1990. {
  1991. if (CurrentGoods != null)
  1992. {
  1993. var accountid = UserManager.CurrentTradeAccount.AccountId;
  1994. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  1995. //{
  1996. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  1997. //}
  1998. var ReqModel = new DepositPersonalInfoReqModel();
  1999. ReqModel.accountId = (long)accountid;
  2000. IsBusy = true;
  2001. //交割提货个人信息查询
  2002. _deliveryService.SearchDepositPersonalInfoReq(ReqModel, QueryDepositPersonalInfoSuccess, QueryDepositPersonalInfoCallBack);
  2003. }
  2004. }
  2005. /// <summary>
  2006. /// 获取卖交割仓单信息
  2007. /// </summary>
  2008. private void GetSellDeliveryWhRecieptInfo()
  2009. {
  2010. if (_currentDeliveryGoodsId > 0)
  2011. {
  2012. var accountid = UserManager.CurrentTradeAccount.AccountId;
  2013. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  2014. //{
  2015. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  2016. //}
  2017. IsBusy = true;
  2018. //卖交割仓单查询
  2019. _deliveryService.QueryDeliveryWhRecieptInfo((uint)accountid, (uint)_currentDeliveryGoodsId, WhRecieptInfoSuccess, DeliveryGoodsCallBack);
  2020. }
  2021. }
  2022. /// <summary>
  2023. /// 获取P+X交割商品信息
  2024. /// </summary>
  2025. private void GetPAndXDeliveryGoodsInfo()
  2026. {
  2027. var holders = UserManager.GetCacheOrders<HoldingOrder>();
  2028. if (holders != null && holders.Any())
  2029. {
  2030. HoldDetails = holders.Where((item) => item.GoodsId == CurrentGoods.GoodsId && item.Direction == BuyOrSell).ToList();//买卖方向持仓
  2031. if (HoldDetails != null && HoldDetails.Any())
  2032. {
  2033. #region 买卖方向持仓逻辑
  2034. _positionFzQty = HoldDetails.FirstOrDefault().PositionFzQty;
  2035. _totalHoldDetails = HoldDetails.Sum((order) => order.Lot - order.LockQty);
  2036. AvailHoldQty = _totalHoldDetails - _positionFzQty;
  2037. if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  2038. {
  2039. CurrentPerUsedMargin = HoldDetails.Sum((order) => order.UsedMargin) / HoldDetails.Sum((order) => order.Lot - order.LockQty);
  2040. }
  2041. #region [P+X]商品信息
  2042. if (CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX)
  2043. {
  2044. if (CurrentGoodsDeliveryRelation.RelationGoodsId != 0 && CurrentGoodsDeliveryRelation.RelationGoodsId > 0)
  2045. {
  2046. if (GoodsDeliveryRelationList.Find(x => x.RelationGoodsId == CurrentGoodsDeliveryRelation.RelationGoodsId) != null)//未找到关联交易商品
  2047. {
  2048. RelationGoodsName = FindRelationGoodsInfoByID(CurrentGoodsDeliveryRelation.RelationGoodsId).RelationGoodsname;
  2049. //当前关联交易商品的持仓单[P+X]
  2050. RelationHoldDetails = holders.Where((item) => item.GoodsId == CurrentGoodsDeliveryRelation.RelationGoodsId && item.Direction == BuyOrSell).ToList();
  2051. }
  2052. else
  2053. {
  2054. OKButtonEnabled = false;
  2055. }
  2056. }
  2057. if (RelationHoldDetails != null && RelationHoldDetails.Any())
  2058. {
  2059. var RelationGoodsItem = FindRelationGoodsInfoByID(CurrentGoodsDeliveryRelation.RelationGoodsId);
  2060. RelationGoodsHoldPrice = RelationHoldDetails.Sum((order) => order.HoldAmount - order.lockHolderAmount) / RelationHoldDetails.Sum((item) => item.Lot - item.LockQty) / RelationGoodsItem.RelationAgreeunit;
  2061. //X交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 交易商品合约单位
  2062. if (CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX && RelationGoodsItem != null && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN)//&& CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN
  2063. {
  2064. RelationPerUsedMargin = RelationHoldDetails.Sum((order) => order.UsedMargin) / RelationHoldDetails.Sum((item) => item.Lot - item.LockQty);
  2065. FreezeDeliveryTradeMoney = DeliveryCount * Math.Round(RelationGoodsHoldPrice, 2, MidpointRounding.AwayFromZero) * RelationGoodsItem.RelationAgreeunit;
  2066. IsVisibilityDeliveryTradeMoney = Visibility.Visible;
  2067. }
  2068. //关联交易商品持仓可用数量=持仓总数-冻结头寸
  2069. RelationGoodsHoldQty = RelationHoldDetails.Sum((order) => order.Lot - order.LockQty) - RelationHoldDetails.FirstOrDefault().PositionFzQty;
  2070. if (AvailHoldQty > RelationGoodsHoldQty && RelationGoodsHoldQty >= 0 && BuyOrSell == Direction.Bid)
  2071. {
  2072. //最大可申报数量 以小的为标准
  2073. MaxDeliveryUnit = Math.Min((RelationGoodsHoldQty - RelationGoodsHoldQty % MinDeliveryUnit), MaxDeliveryUnit);
  2074. }
  2075. }
  2076. }
  2077. #endregion
  2078. #endregion
  2079. }
  2080. }
  2081. }
  2082. /// <summary>
  2083. /// 交割算法取值
  2084. /// </summary>
  2085. private void GetDeliveryPriceCalcMethod()
  2086. {
  2087. switch (CurrentGoodsDeliveryRelation.DeliveryPriceCalcMethod)
  2088. {
  2089. case eReckonPriceCalcMethodType.LastPrice:
  2090. case eReckonPriceCalcMethodType.HolderPriceMove:
  2091. case eReckonPriceCalcMethodType.AgreedPrice:
  2092. case eReckonPriceCalcMethodType.ReckonPrice:
  2093. case eReckonPriceCalcMethodType.HolderPrice:
  2094. //持仓价
  2095. if (HoldDetails != null && HoldDetails.Any())
  2096. {
  2097. #region 按先建先冻原则计算持仓均价
  2098. //HoldDetails = HoldDetails.OrderBy(x => x.OpenDate).ToList();
  2099. /////交易货款
  2100. //var tempDeliveryPrice = decimal.Zero;
  2101. ////申报数量
  2102. //var tempDeliveryCount = DeliveryCount;// *CurrentGoodsDeliveryRelation.Conversion;
  2103. //foreach (var item in HoldDetails)
  2104. //{
  2105. // //可用数量
  2106. // var currentLot = (item.Lot - item.LockQty);
  2107. // if (currentLot <= 0)
  2108. // {
  2109. // continue;
  2110. // }
  2111. // if (tempDeliveryCount >= currentLot)
  2112. // {
  2113. // //先建先冻原则=>总价+=建仓总价
  2114. // tempDeliveryPrice += (item.HoldAmount);
  2115. // tempDeliveryCount = tempDeliveryCount - currentLot;
  2116. // }
  2117. // else
  2118. // {
  2119. // //总价+=建仓单价 * 申报剩余数量
  2120. // tempDeliveryPrice += (item.HoldAmount / currentLot) * tempDeliveryCount;
  2121. // tempDeliveryCount = 0;
  2122. // break;
  2123. // }
  2124. //}
  2125. ////持仓价均价=交割价格
  2126. //DeliveryPrice = tempDeliveryPrice / DeliveryCount / _CurrentGoods.currentAgreeunit;
  2127. ////交易货款=交割申报手数*持仓单对应的持仓金额
  2128. //FreezeTradeMoney = tempDeliveryPrice;
  2129. ////差价款=申报数量/兑换系数*交割合约单位*差价升贴水
  2130. //FreezePriceMoveMoney=DeliveryCount / CurrentGoodsDeliveryRelation.Conversion * _CurrentGoods.currentAgreeunit * CurrentGoodsDeliveryRelation.DeliveryPriceMove;
  2131. #endregion
  2132. //持仓价=持仓价均价
  2133. DeliveryPrice = decimal.Zero;
  2134. //#26006 N模式的交割申报不需要显示交割价格
  2135. if (HoldDetails.Sum((item) => item.Lot - item.LockQty) > 0)
  2136. DeliveryPrice = HoldDetails.Sum((order) => order.HoldAmount - order.lockHolderAmount) / HoldDetails.Sum((item) => item.Lot - item.LockQty) / CurrentGoods.currentAgreeunit;
  2137. //差价款=申报数量/兑换系数*交割合约单位*差价升贴水
  2138. FreezePriceMoveMoney = DeliveryCount / CurrentGoodsDeliveryRelation.Conversion * CurrentGoodsDeliveryRelation.currentAgreeunit * CurrentGoodsDeliveryRelation.DeliveryPriceMove;
  2139. FreezeTradeMoney = decimal.Zero;
  2140. FreezeDeliveryMoney = decimal.Zero;
  2141. if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  2142. {
  2143. //交易货款=交割申报手数*持仓单对应的持仓价均价+X交易货款
  2144. FreezeTradeMoney = DeliveryCount * Math.Round(DeliveryPrice, 2, MidpointRounding.AwayFromZero) * CurrentGoods.currentAgreeunit + FreezeDeliveryTradeMoney;
  2145. }
  2146. if (CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX)
  2147. {
  2148. //var RelationGoodsItem = CacheManager.CacheGoodsBaseInfos.Find(x => x.GoodsParameters.GoodsId == CurrentGoodsDeliveryRelation.RelationGoodsId);
  2149. var RelationGoodsItem = FindRelationGoodsInfoByID(CurrentGoodsDeliveryRelation.RelationGoodsId);
  2150. if (RelationGoodsItem != null && CurrentGoods.currentMoneymode != eMoneyMode.MONEYMODE_MARGIN && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  2151. {
  2152. //交易货款=X交易货款
  2153. FreezeTradeMoney = FreezeDeliveryTradeMoney;
  2154. }
  2155. }
  2156. //冻结货款=P交易货款+差价款+X交易货款
  2157. FreezeDeliveryMoney = FreezeTradeMoney + FreezePriceMoveMoney;
  2158. }
  2159. break;
  2160. }
  2161. }
  2162. /// <summary>
  2163. /// 最大最小交割手数
  2164. /// </summary>
  2165. private void MinMaxDeliveryHandQty()
  2166. {
  2167. if (GoodsDeliveryRelationList.Find(x => x.GoodsId == CurrentGoods.GoodsId) != null)
  2168. {
  2169. MinDeliveryUnit = GoodsDeliveryRelationList.Find(x => x.GoodsId == CurrentGoods.GoodsId).minDeliveryQty;
  2170. //最小交割手数转换为交易手数
  2171. MinDeliveryUnit = Math.Round(MinDeliveryUnit * CurrentGoodsDeliveryRelation.Conversion, 2, MidpointRounding.AwayFromZero);
  2172. }
  2173. else
  2174. {
  2175. //ShowErrorInfo = "没有设置最小交割手数" + "\r";
  2176. }
  2177. if (GoodsDeliveryRelationList.Find(x => x.GoodsId == CurrentGoods.GoodsId) != null)
  2178. {
  2179. MaxDeliveryUnit = GoodsDeliveryRelationList.Find(x => x.GoodsId == CurrentGoods.GoodsId).maxDeliveryQty;
  2180. //最大交割手数转换为交易手数
  2181. var tempMaxDeliveryUnit = Math.Round(MaxDeliveryUnit * CurrentGoodsDeliveryRelation.Conversion, 2, MidpointRounding.AwayFromZero);
  2182. MaxDeliveryUnit = tempMaxDeliveryUnit - tempMaxDeliveryUnit % MinDeliveryUnit;
  2183. if (CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX && BuyOrSell == Direction.Bid)
  2184. {
  2185. var tempAvailHoldQty = Math.Min(RelationGoodsHoldQty, AvailHoldQty);
  2186. MaxDeliveryUnit = Math.Min((tempAvailHoldQty - tempAvailHoldQty % MinDeliveryUnit), MaxDeliveryUnit);
  2187. }
  2188. else
  2189. {
  2190. MaxDeliveryUnit = Math.Min((AvailHoldQty - AvailHoldQty % MinDeliveryUnit), MaxDeliveryUnit);
  2191. }
  2192. }
  2193. else
  2194. {
  2195. //ShowErrorInfo = "没有设置最大交割手数" + "\r";
  2196. }
  2197. DeliveryCount = MinDeliveryUnit;
  2198. //交易商品数量-》转交割商品数量
  2199. RelationNum = DeliveryCount / CurrentGoodsDeliveryRelation.Conversion * CurrentGoodsDeliveryRelation.currentAgreeunit;
  2200. IsVisibilityFreezeMoney = Visibility.Visible;
  2201. }
  2202. /// <summary>
  2203. /// 资金计算最大可下单数据
  2204. /// </summary>
  2205. /// <returns></returns>
  2206. private long MaxDeliveryLots()
  2207. {
  2208. //错误信息提示
  2209. if (FreezeDeliveryMoney > usableFunds)
  2210. {
  2211. ErrorMsg = Resources.Client_Resource.DeliveryOrderView_MinMaxErrVisibility_LowMoney;
  2212. }
  2213. usableFunds = usableFunds >= 0 ? usableFunds : 0;
  2214. var pirce = GetDeliveryGoodsPay();
  2215. FreezeDeliveryMoney += (TotalFreezeFax + TotalDeliveryFee);
  2216. RaisePropertyChanged(() => TotalFreezeFax);
  2217. RaisePropertyChanged(() => TotalDeliveryFee);
  2218. return pirce == 0 ? 0 : (long)Math.Floor(usableFunds / pirce);
  2219. }
  2220. /// <summary>
  2221. /// 查找商品信息BY商品ID
  2222. /// </summary>
  2223. private GoodsDeliveryRelationModel FindGoodsInfoByID(long goodsId)
  2224. {
  2225. if (GoodsDeliveryRelationList.Any() && GoodsDeliveryRelationList.Count > 0)
  2226. {
  2227. return GoodsDeliveryRelationList.Find(x => x.GoodsId == goodsId);
  2228. }
  2229. return null;
  2230. }
  2231. /// <summary>
  2232. /// 查找关联商品信息BY商品ID
  2233. /// </summary>
  2234. private GoodsDeliveryRelationModel FindRelationGoodsInfoByID(long RelationGoodsId)
  2235. {
  2236. if (GoodsDeliveryRelationList.Any() && GoodsDeliveryRelationList.Count > 0)
  2237. {
  2238. return GoodsDeliveryRelationList.Find(x => x.RelationGoodsId == RelationGoodsId);
  2239. }
  2240. return null;
  2241. }
  2242. /// <summary>
  2243. /// 计算每个交割单位的冻结金额
  2244. /// </summary>
  2245. /// <returns></returns>
  2246. private decimal GetDeliveryGoodsPay()
  2247. {
  2248. var TempItem = CurrentGoodsDeliveryRelation;
  2249. // 1、全款模式
  2250. //最大申报手数=可用资金/[交割合约单位*(手续费+差价升贴水)/兑换系数]
  2251. //2、保证金模式
  2252. //最大申报手数=可用资金/[交割合约单位*(手续费+差价升贴水)/兑换系数+持仓均价*交易合约单位]
  2253. var payMargin = TempItem.currentAgreeunit * TempItem.DeliveryPriceMove / TempItem.Conversion; //差价升贴水+手续费
  2254. if (TempItem.RelationMode == eDeliveryContractLink.PAndX)
  2255. {
  2256. //var RelationGoodsItem = CacheManager.CacheGoodsBaseInfos.Find(x => x.GoodsParameters.GoodsId == TempItem.RelationGoodsId);
  2257. var RelationGoodsItem = FindRelationGoodsInfoByID(TempItem.RelationGoodsId);
  2258. if (RelationGoodsItem != null && TempItem.RelationMode == eDeliveryContractLink.PAndX &&
  2259. RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  2260. {
  2261. payMargin += RelationGoodsHoldPrice * RelationGoodsItem.RelationAgreeunit; //X 持仓均价*交易合约单位
  2262. }
  2263. }
  2264. if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN)
  2265. {
  2266. //P交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 交易商品合约单位
  2267. payMargin += DeliveryPrice * CurrentGoods.currentAgreeunit; //p 持仓均价*交易合约单位
  2268. }
  2269. //买卖交割手续费
  2270. decimal tempDeliveryFee = (BuyOrSell == Direction.Bid ? TempItem.buyDeliveryFee : TempItem.AskDeliveryFee);
  2271. //var payfee = TempItem.buyDeliveryMode == (int)eCalMode.CALMODE_FIXEDRATIO //百分比
  2272. // ? DeliveryFeePercentCalculate()
  2273. // : tempDeliveryFee;
  2274. var payfee = tempDeliveryFee;
  2275. DeliveryFee = TempItem.buyDeliveryMode == (int)eCalMode.CALMODE_FIXEDRATIO ? DeliveryFeePercentCalculate() : TempItem.currentAgreeunit * payfee / TempItem.Conversion; ////手续费
  2276. payMargin += DeliveryFee;
  2277. FreezeFax = TempItem.currentAgreeunit * TempItem.BasePrice * TempItem.FaxValue / 100 / TempItem.Conversion;
  2278. payMargin += FreezeFax; ////税款
  2279. return payMargin;
  2280. }
  2281. #endregion
  2282. /// <summary>
  2283. /// 按比例买卖交割单手手续费-计算
  2284. /// </summary>
  2285. private decimal DeliveryFeePercentCalculate()
  2286. {
  2287. var TempItem = CurrentGoodsDeliveryRelation;
  2288. decimal result = decimal.Zero;
  2289. #region P模式-手续费公式要求
  2290. //手续费设置为固定金额时:交割申报手数/兑换系数*交易合约单位*手续费单价
  2291. //手续费设置为比例时:(交易货款+差价款)*手续费比例
  2292. //其中交易货款=持仓均价*交割手数*交易合约单位
  2293. //其中差价款=申报手数*交易合约单位/兑换系数*差价升贴水
  2294. #endregion
  2295. #region P+X模式-手续费公式要求
  2296. // 手续费设置为固定金额时:交割申报手数/兑换系数*交易合约单位*手续费单价
  2297. // 手续费设置为比例时:(交易货款+差价款)*手续费比例
  2298. //其中交易货款=主商品持仓均价*交割手数*主商品交易合约单位+辅商品持仓均价*交割手数*辅商品交易合约单位
  2299. //其中差价款=申报手数*主商品交易合约单位/兑换系数*差价升贴水
  2300. #endregion
  2301. if (TempItem.RelationMode != eDeliveryContractLink.None)
  2302. {
  2303. //交易货款=持仓均价*交割手数*交易合约单位
  2304. var tempDeliveryTradeMoney = Math.Round(DeliveryPrice, 2, MidpointRounding.AwayFromZero) * CurrentGoods.currentAgreeunit;
  2305. //差价款=申报手数*交易合约单位/兑换系数*差价升贴水
  2306. var tempPriceMoveMoney = TempItem.currentAgreeunit * TempItem.DeliveryPriceMove / TempItem.Conversion;
  2307. //手续费参数值
  2308. decimal tempDeliveryFee = (BuyOrSell == Direction.Bid ? TempItem.buyDeliveryFee : TempItem.AskDeliveryFee);
  2309. switch (TempItem.RelationMode)
  2310. {
  2311. case eDeliveryContractLink.Normal:
  2312. //手续费 =(交易货款+差价款)*手续费比例
  2313. result = (Math.Round(tempDeliveryTradeMoney, 2, MidpointRounding.AwayFromZero) + Math.Round(tempPriceMoveMoney, 2, MidpointRounding.AwayFromZero)) * tempDeliveryFee;
  2314. break;
  2315. case eDeliveryContractLink.PAndX:
  2316. var RelationGoodsItem = FindRelationGoodsInfoByID(TempItem.RelationGoodsId);
  2317. //X交易货=款辅商品持仓均价*交割手数*辅商品交易合约单位
  2318. var tempXDeliveryTradeMoney = RelationGoodsHoldPrice * RelationGoodsItem.RelationAgreeunit;
  2319. //手续费 =(交易货款+差价款)*手续费比例
  2320. result = (Math.Round(tempDeliveryTradeMoney, 2, MidpointRounding.AwayFromZero) + Math.Round(tempXDeliveryTradeMoney, 2, MidpointRounding.AwayFromZero) + Math.Round(tempPriceMoveMoney, 2, MidpointRounding.AwayFromZero)) * tempDeliveryFee;
  2321. break;
  2322. }
  2323. }
  2324. return result;
  2325. }
  2326. #region "Other Methods like Validated"
  2327. /// <summary>
  2328. /// 数据验证
  2329. /// </summary>
  2330. /// <param name="msg"></param>
  2331. /// <returns></returns>
  2332. public bool Validated(ref string msg)
  2333. {
  2334. //申报数量 > 最大可申报数量
  2335. if (DeliveryCount > MaxDeliveryUnit)
  2336. {
  2337. msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_OpenLotGreatThanMaxLot, MaxDeliveryUnit);
  2338. return false;
  2339. }
  2340. //申报数量应为最小交割数量的整数倍
  2341. if (MinDeliveryUnit != 0 && DeliveryCount % MinDeliveryUnit != 0 && _currentLinkModel != eDeliveryContractLink.None)
  2342. {
  2343. msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.DeliveryCountShoutBeMinUnitDouble, MinDeliveryUnit); ;
  2344. return false;
  2345. }
  2346. if (DeliveryCount <= 0 || DeliveryCount == decimal.Zero)
  2347. {
  2348. //数量不在正确范围内
  2349. msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Delivery_ChooseCorrectDeclareNum, MaxDeliveryUnit); ;
  2350. return false;
  2351. }
  2352. if (RecievePerson.Trim() == "")
  2353. {
  2354. msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecievePerson + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
  2355. return false;
  2356. }
  2357. if (RecieveAddress.Trim() == "")
  2358. {
  2359. msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecieveAddress + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
  2360. return false;
  2361. }
  2362. if (PhoneNum.Trim() == "")
  2363. {
  2364. msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNum + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
  2365. return false;
  2366. }
  2367. if (PhoneNum.Trim() != "" && !PhoneNum.StartsWith("1") || PhoneNum.Length != 11 || !ValidationHelper.IsMobile(PhoneNum))
  2368. {
  2369. msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNumErrFormat;
  2370. return false;
  2371. }
  2372. return true;
  2373. }
  2374. #endregion
  2375. }
  2376. }