using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Muchinfo.MTPClient.Data.Enums;
using Muchinfo.MTPClient.Data.DTO;
using Muchinfo.MTPClient.Data.Model.Account;
using Muchinfo.MTPClient.Data.Model.Delivery;
using Muchinfo.MTPClient.Infrastructure.Utilities;
using Muchinfo.MTPClient.IService;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using Muchinfo.MTPClient.Data;
using System.Collections.ObjectModel;
using Muchinfo.MTPClient.Data.Model;
using System;
using GalaSoft.MvvmLight.Command;
using Muchinfo.MTPClient.Resources;
using Muchinfo.MTPClient.Infrastructure.Cache;
using Muchinfo.MTPClient.Infrastructure.MessageBox;
using Muchinfo.MTPClient.Infrastructure.Helpers;
namespace Muchinfo.MTPClient.Delivery.ViewModels
{
///
/// 新交割申报
///
///
///
public class NDeliveryOrderViewModel : ViewModelBase
{
private QuoteGoodsDTO _goodsItem;
#region "=========私有成员/Private Data Members"
private Window _openWindow; ///下单窗口
private IDeliveryService _deliveryService;
private IGoodsService _goodsService;
private Direction _currentDirection = Direction.Bid;
private decimal usableFunds = UserManager.CurrentAccountUsableFunds();
private DeliveryOrderMessage _parameterInfo;
protected const int defaut_minLot = 1;
protected const int defaut_maxLot = int.MaxValue;
private bool _action = false;//控制点选仓库多次触发事件
private decimal submitDeliveryQty = decimal.Zero;//点选的交割总数量
#endregion "Private Data Members"
#region "=========构造函数/Constructor/Initialization"
public NDeliveryOrderViewModel(DeliveryOrderMessage parameterInfo)
{
this._parameterInfo = parameterInfo;
_deliveryService = SimpleIoc.Default.GetInstance();
_goodsService = SimpleIoc.Default.GetInstance();
// 初始化交割商品列表数据
InitData(parameterInfo);
}
#endregion "Constructor/Initialization"
private void RegisterMessages()
{
MessengerHelper.QuoteRegister>(this, MessengerTokens.ReceiveRealTimeQuote, (quoteList) =>
{
if (quoteList == null || !quoteList.Any()) return;
foreach (var goods in quoteList)
{
if (goods == null) continue;
if (this._goodsItem != null && this._goodsItem.GoodsCode == goods.GoodsCode)
{
this._goodsItem.UpdateFromQuoteGoods(goods);
this.XPriceFormat = this._goodsItem.CurrentPriceDisplay;
}
}
});
}
#region "=========接口重写/Interface implementation Or override"
//To do interface implementation
#endregion "Interface implementation Or override"
#region "=========公共属性/Public Properties To Get/Set "
#region 所有单据ListSource
private List _allOrders;
///
/// 所有单据ListSource
///
public List AllOrders
{
get { return _allOrders; }
set { Set(() => AllOrders, ref _allOrders, value); }
}
#endregion
#region 当前资金账户
private ulong _accountid;
public ulong AccountID
{
get { return _accountid; }
set { Set(() => AccountID, ref _accountid, value); }
}
#endregion
#region 主商品
public uint XGoodsID { get; set; }
private string _xgoodsCode;
public string XGoodsCode
{
get { return _xgoodsCode; }
set { Set(() => XGoodsCode, ref _xgoodsCode, value); }
}
private string _xgoodsName;
public string XGoodsName
{
get { return _xgoodsName; }
set { Set(() => XGoodsName, ref _xgoodsName, value); }
}
private string _deliveryFactor;
public string DeliveryFactor
{
get { return _deliveryFactor; }
set { Set(() => DeliveryFactor, ref _deliveryFactor, value); }
}
public string DisplayXGoods
{
get
{
return XGoodsCode + "/" + XGoodsName;
}
}
#endregion
#region 辅助商品
public uint P1GoodsID { get; set; }
private string _p1goodsCode;
public string P1GoodsCode
{
get { return _p1goodsCode; }
set { Set(() => P1GoodsCode, ref _p1goodsCode, value); }
}
private string _p1goodsName;
public string P1GoodsName
{
get { return _p1goodsName; }
set { Set(() => P1GoodsName, ref _p1goodsName, value); }
}
public uint P2GoodsID { get; set; }
private string _p2goodsCode;
public string P2GoodsCode
{
get { return _p2goodsCode; }
set { Set(() => P2GoodsCode, ref _p2goodsCode, value); }
}
private string _p2goodsName;
public string P2GoodsName
{
get { return _p2goodsName; }
set { Set(() => P2GoodsName, ref _p2goodsName, value); }
}
#endregion
#region 交割商品
private string _deliverygoodsCode;
public string DeliveryGoodsCode
{
get { return _deliverygoodsCode; }
set { Set(() => DeliveryGoodsCode, ref _deliverygoodsCode, value); }
}
private string _deliverygoodsName;
public string DeliveryGoodsName
{
get { return _deliverygoodsName; }
set { Set(() => DeliveryGoodsName, ref _deliverygoodsName, value); }
}
private string _deliverygoodsNamecode;
public string DeliveryGoodsNameCode
{
get { return _deliverygoodsNamecode; }
set { Set(() => DeliveryGoodsNameCode, ref _deliverygoodsNamecode, value); }
}
#endregion
#region 仓库ListSource
private ObservableCollection> _warehouselst;
public ObservableCollection> DeliveryWarehouseList
{
get { return _warehouselst; }
set { Set(() => DeliveryWarehouseList, ref _warehouselst, value); }
}
private KeyValuePair _selectedWareHouse;
public KeyValuePair SelectedWareHouse
{
get { return _selectedWareHouse; }
set { Set(() => SelectedWareHouse, ref _selectedWareHouse, value); }
}
#endregion
#region 品质ListSource
private List> _qualitylst;
public List> DeliveryQualityList
{
get { return _qualitylst; }
set { Set(() => DeliveryQualityList, ref _qualitylst, value); }
}
private KeyValuePair _selectedQuality;
public KeyValuePair SelectedQuality
{
get { return _selectedQuality; }
set { Set(() => SelectedQuality, ref _selectedQuality, value); }
}
#endregion
#region 规格ListSource
private List> _spelst;
public List> DeliverySpeciList
{
get { return _spelst; }
set { Set(() => DeliverySpeciList, ref _spelst, value); }
}
private KeyValuePair _selectedSpeci;
public KeyValuePair SelectedSpeci
{
get { return _selectedSpeci; }
set { Set(() => SelectedSpeci, ref _selectedSpeci, value); }
}
#endregion
#region 品质ListSource
private List> _brandlst;
public List> DeliveryBrandList
{
get { return _brandlst; }
set { Set(() => DeliveryBrandList, ref _brandlst, value); }
}
private KeyValuePair _selectedBrand;
public KeyValuePair SelectedBrand
{
get { return _selectedBrand; }
set { Set(() => SelectedBrand, ref _selectedBrand, value); }
}
#endregion
#region 过滤条件
private List> _filterlst = new List>();
public List> FilterList
{
get { return _filterlst; }
set { Set(() => FilterList, ref _filterlst, value); }
}
#endregion
#region 可用持仓数量
private decimal _availHoldQty = decimal.Zero;
///
/// 可用持仓数量
///
public decimal AvailHoldQty
{
get
{
return _availHoldQty;
}
set
{
Set(() => AvailHoldQty, ref _availHoldQty, value);
RaisePropertyChanged(() => AvailHoldQtyUnit);
}
}
private decimal _availHoldQtyUnit = decimal.Zero;
///
/// 可用持仓数量- 转- 交割可用数量
///
public decimal AvailHoldQtyUnit
{
get
{
return _availHoldQtyUnit;
}
set
{
Set(() => AvailHoldQtyUnit, ref _availHoldQtyUnit, value);
}
}
#endregion
#region 当前选择仓单
private DeliveryWhRecieptInfo _currentSelectedWhReciept;
///
/// 当前选择仓单详细
///
public DeliveryWhRecieptInfo CurrentSelectedWhReciept
{
get
{
return _currentSelectedWhReciept;
}
set
{
Set(() => CurrentSelectedWhReciept, ref _currentSelectedWhReciept, value);
}
}
private TradeWRPositionModel _currentSelectedWhRecieptEx;
///
/// 当前选择仓单详细
///
public TradeWRPositionModel CurrentSelectedWhRecieptEx
{
get
{
return _currentSelectedWhRecieptEx;
}
set
{
Set(() => CurrentSelectedWhRecieptEx, ref _currentSelectedWhRecieptEx, value);
}
}
#endregion
#region 交割点选仓单
private List _wrPairDetailsList = new List();
///
/// 交割点选仓单
///
public List WrPairDetailsList
{
get
{
return _wrPairDetailsList;
}
set
{
Set(() => WrPairDetailsList, ref _wrPairDetailsList, value);
}
}
private static List CachedPairDetailsList = new List();
private List _wrPairDetailsListEx = new List();
///
/// 交割点选仓单
///
public List WrPairDetailsListEx
{
get
{
return _wrPairDetailsListEx;
}
set
{
Set(() => WrPairDetailsListEx, ref _wrPairDetailsListEx, value);
}
}
#endregion
#region 最小交割数量/倍数
private decimal _MinMultiple = 1;
///
/// 最小交割数量/倍数
///
public decimal MinMultiple
{
get
{
return _MinMultiple;
}
set
{
Set(() => MinMultiple, ref _MinMultiple, value);
}
}
#endregion
#region 加载中 字符串显示
private string _BusyContent = Client_Resource.Content_GetBusy;
///
/// 加载中 字符串显示
///
public string BusyContent
{
get
{
return _BusyContent;
}
set
{
Set(() => BusyContent, ref _BusyContent, value);
}
}
#endregion
#region 当前账号提货人信息
private DepositPersonalInfoRspModel _currentDepositPersonalInfo;
///
/// 当前账号提货人信息
///
public DepositPersonalInfoRspModel CurrentDepositPersonalInfo
{
get
{
return _currentDepositPersonalInfo;
}
set
{
Set(() => CurrentDepositPersonalInfo, ref _currentDepositPersonalInfo, value);
}
}
#endregion
#region 收货人
private string _RecievePerson = string.Empty;
///
/// 收货人
///
public string RecievePerson
{
get
{
return _RecievePerson;
}
set
{
Set(() => RecievePerson, ref _RecievePerson, value);
}
}
#endregion
#region 收货地址
private string _RecieveAddress = string.Empty;
///
/// 收货地址
///
public string RecieveAddress
{
get
{
return _RecieveAddress;
}
set
{
Set(() => RecieveAddress, ref _RecieveAddress, value);
}
}
#endregion
#region 联系方式
private string _PhoneNum = string.Empty;
///
/// 联系方式
///
public string PhoneNum
{
get
{
return _PhoneNum;
}
set
{
Set(() => PhoneNum, ref _PhoneNum, value);
}
}
#endregion
#region 主商品-申报数量-错误提示
private bool _isError_DeliveryCount = false;
///
/// 主商品-申报数量-错误提示
///
public bool IsError_DeliveryCount
{
get
{
return _isError_DeliveryCount;
}
set
{
Set(() => IsError_DeliveryCount, ref _isError_DeliveryCount, value);
}
}
#endregion
#region 关联商品-申报数量-错误提示
private bool _isError_RelationDeliveryCount = false;
///
/// 关联商品-申报数量-错误提示
///
public bool IsError_RelationDeliveryCount
{
get
{
return _isError_RelationDeliveryCount;
}
set
{
Set(() => IsError_RelationDeliveryCount, ref _isError_RelationDeliveryCount, value);
}
}
private bool _isError_RelationDeliveryCount2 = false;
///
/// 关联商品-申报数量-错误提示
///
public bool IsError_RelationDeliveryCount2
{
get
{
return _isError_RelationDeliveryCount2;
}
set
{
Set(() => IsError_RelationDeliveryCount2, ref _isError_RelationDeliveryCount2, value);
}
}
#endregion
#region 买卖名称改变
private string _directionTitle = string.Empty;
///
/// 买卖名称改变
///
public string DirectionTitle
{
get
{
return _directionTitle;
}
set
{
Set(() => DirectionTitle, ref _directionTitle, value);
}
}
#endregion
#region 窗体标题
private string _title = string.Empty;
///
/// 窗体标题
///
public string Title
{
get
{
return _title = Client_Resource.DeliveryOrderView_DeliveryDeclaration + "(" + AccountID.ToString() + ")";
}
}
#endregion
#region 当前勾选单据LIST
private List _currentSelectedWrDetail = new List();
///
/// 当前勾选的仓单配对
///
public List CurrentSelectedWrDetail
{
get
{
return _currentSelectedWrDetail;
}
set
{
Set(() => CurrentSelectedWrDetail, ref _currentSelectedWrDetail, value);
}
}
#endregion
#region 合约单位名称枚举-当前商品
private string _currentGoodsUnitType = string.Empty;
///
/// 合约单位名称枚举-当前商品
///
public string CurrentGoodsUnitType
{
get
{
return _currentGoodsUnitType;
}
set
{
Set(() => CurrentGoodsUnitType, ref _currentGoodsUnitType, value);
}
}
#endregion
#region 合约单位名称枚举-关联商品商品
private string _relationGoodsUnitType = string.Empty;
///
/// 合约单位名称枚举-关联商品商品
///
public string RelationGoodsUnitType
{
get
{
return _relationGoodsUnitType;
}
set
{
Set(() => RelationGoodsUnitType, ref _relationGoodsUnitType, value);
}
}
#endregion
#region 合约单位名称枚举-交割商品
private string _deliveryAgreeUnitType = string.Empty;
///
/// 合约单位名称枚举-交割商品
///
public string DeliveryAgreeUnitType
{
get
{
return _deliveryAgreeUnitType;
}
set
{
Set(() => DeliveryAgreeUnitType, ref _deliveryAgreeUnitType, value);
}
}
#endregion
#region 交割商品数量-转换显示
private decimal _deliveryNum = decimal.Zero;
///
/// 交割商品数量-转换显示
///
public decimal DeliveryNum
{
get
{
return _deliveryNum;
}
set
{
Set(() => DeliveryNum, ref _deliveryNum, value);
if (CurrentGoods != null)
{
if (DeliveryNum > 0)
{
DeliveryCount = Math.Round(DeliveryNum * CurrentGoods.MinDeliveryQty * CurrentGoods.XDeliveryRatio / StandardQty, 0, MidpointRounding.AwayFromZero);//反推:得知交割数量,计算需要主商品数量 X数量 = 交割数量 * 最小交割单位 / 合约单位.
if (CurrentGoods.P1Type !=uint.MaxValue)
{
RelationDeliveryCount = Math.Round(DeliveryCount * CurrentGoods.PDeliveryRatio1 / CurrentGoods.XDeliveryRatio, 0, MidpointRounding.AwayFromZero);
}
else
{
RelationDeliveryCount = 0;
}
if (CurrentGoods.P2Type != uint.MaxValue)
{
RelationDeliveryCount2 = Math.Round(DeliveryCount * CurrentGoods.PDeliveryRatio2 /CurrentGoods.XDeliveryRatio, 0, MidpointRounding.AwayFromZero);
}
else
{
RelationDeliveryCount2 = 0;
}
RaisePropertyChanged(() => DeliveryNumDisplay);
}
}
}
}
public decimal StandardQty
{
get;
set;
}
public uint DeliveryGoodsID
{
get;
set;
}
///
/// 交割商品数量-转交-格式化
///
public string DeliveryNumDisplay
{
get { return DeliveryNum.ToString(); }
}
#endregion
#region 主商品数量-转换显示
private decimal _goodsNum = decimal.Zero;
///
/// 主商品数量-转换显示
///
public decimal GoodsNum
{
get
{
return _goodsNum;
}
set
{
Set(() => GoodsNum, ref _goodsNum, value);
RaisePropertyChanged(() => GoodsNumDisplay);
}
}
///
/// 主商品数量-转交-格式化
///
public string GoodsNumDisplay
{
get { return GoodsNum.ToString("f2"); }
}
#endregion
#region 关联商品申报数量-转换显示
private decimal _relationNum = decimal.Zero;
///
/// 关联商品申报数量-转换显示
///
public decimal RelationNum
{
get
{
return _relationNum;
}
set
{
Set(() => RelationNum, ref _relationNum, value);
RaisePropertyChanged(() => RelationNumDisplay);
RaisePropertyChanged(() => IsError);
}
}
public bool IsError
{
get
{
return _relationNum > _relationGoodsHoldQty;
}
}
///
/// 关联商品申报数量-转换显示-格式化
///
public string RelationNumDisplay
{
get { return RelationNum.ToString("f2"); }
}
#endregion
#region 关联交易商品持仓数量[P+X]
private decimal _relationGoodsHoldQty = decimal.Zero;
///
/// 关联交易商品持仓数量[P+X]
///
public decimal RelationGoodsHoldQty
{
get
{
return _relationGoodsHoldQty;
}
set
{
Set(() => RelationGoodsHoldQty, ref _relationGoodsHoldQty, value);
RaisePropertyChanged(() => RelationGoodsHoldQtyDisp);
RaisePropertyChanged(() => RelationGoodsHoldQtyUnit);
RaisePropertyChanged(() => IsError);
}
}
private decimal _relationGoodsHoldQty2 = decimal.Zero;
///
/// 关联交易商品持仓数量[P+X]2
///
public decimal RelationGoodsHoldQty2
{
get
{
return _relationGoodsHoldQty2;
}
set
{
Set(() => RelationGoodsHoldQty2, ref _relationGoodsHoldQty2, value);
RaisePropertyChanged(() => RelationGoodsHoldQty2Disp);
RaisePropertyChanged(() => IsError);
}
}
private decimal _relationGoodsHoldQtyUnit = decimal.Zero;
///
/// 关联交易商品持仓数量-转交割数量
///
public decimal RelationGoodsHoldQtyUnit
{
get
{
return _relationGoodsHoldQtyUnit;
}
set
{
Set(() => RelationGoodsHoldQtyUnit, ref _relationGoodsHoldQtyUnit, value);
}
}
#endregion
#region 关联交易商品交割价格[P+X]
private decimal _relationGoodsHoldPrice = decimal.Zero;
///
/// 关联交易商品交割价格[P+X]
///
public decimal RelationGoodsHoldPrice
{
get
{
return _relationGoodsHoldPrice;
}
set
{
Set(() => RelationGoodsHoldPrice, ref _relationGoodsHoldPrice, value);
RaisePropertyChanged(() => RelationGoodsHoldPriceFormat);
}
}
private decimal _relationGoodsHoldPrice2 = decimal.Zero;
///
/// 关联交易商品交割价格[P+X]
///
public decimal RelationGoodsHoldPrice2
{
get
{
return _relationGoodsHoldPrice2;
}
set
{
Set(() => RelationGoodsHoldPrice2, ref _relationGoodsHoldPrice2, value);
RaisePropertyChanged(() => RelationGoodsHoldPriceFormat2);
}
}
///
/// 关联交易商品交割价格[P+X]格式化
///
public string RelationGoodsHoldPriceFormat
{
get
{
if (RelationGoodsHoldPrice > decimal.Zero)
{
return RelationGoodsHoldPrice.ToString("f2");
}
else
{
return "--";
}
}
}
public string RelationGoodsHoldPriceFormat2
{
get
{
if (RelationGoodsHoldPrice2 > decimal.Zero)
{
return RelationGoodsHoldPrice2.ToString("f2");
}
else
{
return "--";
}
}
}
#endregion
#region 最小交割数量
private decimal _minDeliveryUnit = 1;
///
/// 最小交割数量
///
public decimal MinDeliveryUnit
{
get
{
return _minDeliveryUnit;
}
set
{
Set(() => MinDeliveryUnit, ref _minDeliveryUnit, value);
}
}
#endregion
#region 最大交割数量
private decimal _maxDeliveryUnit = 1;
///
/// 最大交割数量
///
public decimal MaxDeliveryUnit
{
get
{
return _maxDeliveryUnit;
}
set
{
Set(() => MaxDeliveryUnit, ref _maxDeliveryUnit, value);
}
}
#endregion
#region 仓单查询命令
private RelayCommand>> _searchCommand;
///
/// 仓单号详细命令
///
public RelayCommand>> SearchCommand
{
get
{
return _searchCommand
?? (_searchCommand = new RelayCommand>>(
p =>
{
string brandType=string.Empty;
string qualityType=string.Empty;
string speciType=string.Empty;
string warehouseType=string.Empty;
foreach (KeyValuePair item in p)
{
if (item.Key.Split('_')[0] == ((int)ePriceMoveType.PRICEMOVETYPE_BRAND).ToString())
{
brandType=item.Key;
}
if (item.Key.Split('_')[0] == ((int)ePriceMoveType.PRICEMOVETYPE_QUALITY).ToString())
{
qualityType = item.Key;
}
if (item.Key.Split('_')[0] == ((int)ePriceMoveType.PRICEMOVETYPE_SPECIFICATION).ToString())
{
speciType = item.Key;
}
if (item.Key.Split('_')[0] == ((int)ePriceMoveType.PRICEMOVETYPE_WAREHOUSE).ToString())
{
warehouseType = item.Key;
}
}
List localLst = new List();
if (string.IsNullOrEmpty(brandType))
{
foreach (TradeWRPositionModel item in CachedPairDetailsList)
{
localLst.Add(item);
}
}
else
{
localLst = CachedPairDetailsList.Where(x => x.BrandType == brandType).ToList();
}
if (!string.IsNullOrEmpty(qualityType))
{
localLst = localLst.Where(x => x.QualityType == qualityType).ToList();
}
if (!string.IsNullOrEmpty(speciType))
{
localLst = localLst.Where(x => x.SpecType == speciType).ToList();
}
if (!string.IsNullOrEmpty(warehouseType))
{
localLst = localLst.Where(x => x.WarehouseType == warehouseType).ToList();
}
WrPairDetailsListEx = localLst;
}));
}
}
#endregion
#region 冻结头寸数量
private decimal _positionFzQty;
///
/// 冻结头寸数量
///
public decimal PositionFzQty
{
get
{
return _positionFzQty;
}
set
{
Set(() => PositionFzQty, ref _positionFzQty, value);
}
}
#endregion
#region 申报数量
private decimal _deliveryCount = decimal.Zero;
///
/// 申报数量
/// X数量 = 交割数量 * 最小交割单位 / 合约单位.
///
public decimal DeliveryCount
{
get
{
return _deliveryCount;
}
set
{
Set(() => DeliveryCount, ref _deliveryCount, value);
if (DeliveryNum > 0)
{
MainGoodsToLot();
RaisePropertyChanged(() => DeliveryCountCalcAlgrithm);
}
//MainGoodsToRelationGoodsLot(value);
//RaisePropertyChanged(() => RelationDeliveryCount);
//DeclareToDeliveryLot();
//MainGoodsToLot();
//RelationGoodsToLot();
//DeliveryCountEvent();
}
}
public string DeliveryCountCalcAlgrithm
{
get
{
string calcAlgrithm = string.Empty;
if (DeliveryNum > 0)
{
calcAlgrithm = "(" + DeliveryNumDisplay + "*" + MinDeliveryUnit.ToString() + "*" + CurrentGoods.XDeliveryRatio + "/" + StandardQty.ToString() + ")";
}
return calcAlgrithm;
}
}
public string RelationDeliveryCountCalcAlgrithm
{
get
{
//DeliveryCount
string calcAlgrithm = string.Empty;
if (DeliveryNum > 0)
{
calcAlgrithm = "(" + DeliveryCount + "*(" + CurrentGoods.PDeliveryRatio1 + "/" + CurrentGoods.XDeliveryRatio + "))";
//calcAlgrithm = "(" + DeliveryNumDisplay + "*" + MinDeliveryUnit.ToString() + "*" + CurrentGoods.PDeliveryRatio1 + "/(" + StandardQty.ToString() + "*" + CurrentGoods.XDeliveryRatio + "))";
}
return calcAlgrithm;
}
}
public string RelationDeliveryCountCalcAlgrithm2
{
get
{
string calcAlgrithm = string.Empty;
if (DeliveryNum > 0)
{
calcAlgrithm = "(" + DeliveryCount + "*(" + CurrentGoods.PDeliveryRatio2 + "/" + CurrentGoods.XDeliveryRatio + "))";
//calcAlgrithm = "(" + DeliveryNumDisplay + "*" + MinDeliveryUnit.ToString() + "*" + CurrentGoods.PDeliveryRatio2 + "/(" + StandardQty.ToString() + "*" + CurrentGoods.XDeliveryRatio + "))";
}
return calcAlgrithm;
}
}
#endregion
#region 关联商品申报数量
private decimal _relationDeliveryCount =decimal.Zero;
///
/// 关联商品申报数量
/// P数量 = X数量 * P辅助商品转换系数 / X辅助商品转换系数.
///
public decimal RelationDeliveryCount
{
get
{
return _relationDeliveryCount;
}
set
{
Set(() => RelationDeliveryCount, ref _relationDeliveryCount, value);
RaisePropertyChanged(() => RelationDeliveryCountDisp);
RaisePropertyChanged(() => RelationDeliveryCountCalcAlgrithm);
RelationGoodsToLot();
}
}
public string RelationDeliveryCountDisp
{
get
{
if (RelationDeliveryCount == 0)
return "--";
return RelationDeliveryCount.ToString();
}
}
public string RelationGoodsHoldQtyDisp
{
get
{
if (RelationGoodsHoldQty == 0)
return "--";
return RelationGoodsHoldQty.ToString();
}
}
public string RelationGoodsHoldQty2Disp
{
get
{
if (RelationGoodsHoldQty2 == 0)
return "--";
return RelationGoodsHoldQty2.ToString();
}
}
private decimal _relationDeliveryCount2 = decimal.Zero;
///
/// 关联商品申报数量
/// P数量 = X数量 * P辅助商品转换系数 / X辅助商品转换系数.
///
public decimal RelationDeliveryCount2
{
get
{
return _relationDeliveryCount2;
}
set
{
Set(() => RelationDeliveryCount2, ref _relationDeliveryCount2, value);
RaisePropertyChanged(() => RelationDeliveryCountDisp2);
RaisePropertyChanged(() => RelationDeliveryCountCalcAlgrithm2);
RelationGoodsToLot();
}
}
public string RelationDeliveryCountDisp2
{
get
{
if (RelationDeliveryCount2 == 0)
return "--";
return RelationDeliveryCount2.ToString();
}
}
#endregion
#region 持仓汇总
private decimal _totalHoldDetails;
///
/// 持仓汇总
///
public decimal TotalHoldDetails
{
get
{
return _totalHoldDetails;
}
set
{
Set(() => TotalHoldDetails, ref _totalHoldDetails, value);
}
}
#endregion
#region 交割价格
private string _xpriceFormat;
public string XPriceFormat
{
get
{
return _xpriceFormat;
}
set
{
Set(() => XPriceFormat, ref _xpriceFormat, value);
}
}
private decimal _deliveryPrice = decimal.Zero;
///
/// 交割价格
///
public decimal DeliveryPrice
{
get
{
return _deliveryPrice;
}
set
{
Set(() => DeliveryPrice, ref _deliveryPrice, value);
RaisePropertyChanged(() => DeliveryPriceFormat);
}
}
///
/// 交割价格-格式化
///
public string DeliveryPriceFormat
{
get
{
if (DeliveryPrice > decimal.Zero)
{
return DeliveryPrice.ToString("f2");
}
else
{
return "--";
}
}
}
#endregion
#region 是否忙
private bool _isBusy;
///
/// 是否忙
///
public bool IsBusy
{
get { return _isBusy; }
set { Set(() => IsBusy, ref _isBusy, value); }
}
#endregion
#region 是否忙
private bool _isBusyWR;
///
/// 是否忙
///
public bool IsBusyWR
{
get { return _isBusyWR; }
set { Set(() => IsBusyWR, ref _isBusyWR, value); }
}
#endregion
#region 交割关系表LIST
private List _goodsDeliveryRelationList;
public List GoodsDeliveryRelationList
{
get { return _goodsDeliveryRelationList; }
set { _goodsDeliveryRelationList = value; }
}
#endregion
#region 当前选择交易商品
private QuoteGoods _currentGoods;
///
/// 当前选择交易商品
///
public QuoteGoods CurrentGoods
{
get { return _currentGoods; }
set
{
Set(() => CurrentGoods, ref _currentGoods, value);
}
}
#endregion
#region 关联交易商品LIST
private ObservableCollection _relationGoodsNameList = new ObservableCollection();
///
/// 关联交易商品LIST
///
public ObservableCollection RelationGoodsNameList
{
get { return _relationGoodsNameList; }
set { Set(() => RelationGoodsNameList, ref _relationGoodsNameList, value); }
}
private string _currentRelationGoodsName = string.Empty;
///
/// Sets and gets the CurrentRelationGoodsName property.
///
public string CurrentRelationGoodsName
{
get
{
return _currentRelationGoodsName;
}
set
{
Set(() => CurrentRelationGoodsName, ref _currentRelationGoodsName, value);
}
}
#endregion
#region 交割商品LIST
private ObservableCollection _deliveryGoodsNameList = new ObservableCollection();
///
/// 交割商品LIST
///
public ObservableCollection DeliveryGoodsNameList
{
get { return _deliveryGoodsNameList; }
set { Set(() => DeliveryGoodsNameList, ref _deliveryGoodsNameList, value); }
}
private string _currentDeliveryGoodsName = string.Empty;
///
/// Sets and gets the CurrentDeliveryGoodsName property.
///
public string CurrentDeliveryGoodsName
{
get
{
return _currentDeliveryGoodsName;
}
set
{
Set(() => CurrentDeliveryGoodsName, ref _currentDeliveryGoodsName, value);
}
}
#endregion
#region 买卖方向LIST
private ObservableCollection _directionList = new ObservableCollection();
///
/// 买卖方向LIST
///
public ObservableCollection DirectionList
{
get
{
_directionList.Clear();
_directionList.Add(new BuyOrSellDirection() { BuyOrSell = Direction.Bid, BuyOrSellTitle = Resources.Client_Resource.Domain_BuyIn });
_directionList.Add(new BuyOrSellDirection() { BuyOrSell = Direction.Ask, BuyOrSellTitle = Resources.Client_Resource.Domain_SellOut });
CurrentBuyOrSell = _directionList.FirstOrDefault();
return _directionList;
}
}
#endregion
#region 当前商品的持仓单
private List _holdDetails;
///
/// 当前商品的持仓单
///
public List HoldDetails
{
get { return _holdDetails; }
set { Set(() => HoldDetails, ref _holdDetails, value); }
}
#endregion
#region 当前买卖方向实体
private BuyOrSellDirection _currentBuyOrSell;
///
/// 当前买卖方向实体
///
public BuyOrSellDirection CurrentBuyOrSell
{
get
{
return _currentBuyOrSell;
}
set
{
Set(() => CurrentBuyOrSell, ref _currentBuyOrSell, value);
//SetDeliveryCount();
}
}
#endregion
#region 当前关联模式
private eDeliveryContractLink _currentRelationMode = eDeliveryContractLink.None;
///
/// 当前关联模式
///
public eDeliveryContractLink CurrentRelationMode
{
get
{
return _currentRelationMode;
}
set
{
Set(() => CurrentRelationMode, ref _currentRelationMode, value);
}
}
#endregion
#region 当前资金模式
private eMoneyMode _currentMoneyMode = eMoneyMode.MONEYMODE_MARGIN;
///
/// 当前资金模式
///
public eMoneyMode CurrentMoneyMode
{
get
{
return _currentMoneyMode;
}
set
{
Set(() => CurrentMoneyMode, ref _currentMoneyMode, value);
}
}
#endregion
#region 交割商品列表
private List _deliveryGoodsList;
///
/// 交割商品列表
///
public List DeliveryGoodsList
{
get { return _deliveryGoodsList; }
set
{
Set(() => DeliveryGoodsList, ref _deliveryGoodsList, value);
}
}
#endregion
#region 错误信息提示
private string _ShowErrorInfo = string.Empty;
///
/// Sets and gets the ShowErrorInfo property.
///
public string ShowErrorInfo
{
get
{
return _ShowErrorInfo;
}
set
{
Set(() => ShowErrorInfo, ref _ShowErrorInfo, value);
}
}
private Visibility _IsShowErrorInfo = Visibility.Collapsed;
///
/// Sets and gets the IsShowErrorInfo property.
///
public Visibility IsShowErrorInfo
{
get
{
return _IsShowErrorInfo;
}
set
{
Set(() => IsShowErrorInfo, ref _IsShowErrorInfo, value);
}
}
#endregion
#region N 模式需要隐藏字段
private Visibility _isVisibility_N = Visibility.Collapsed;
///
/// N 模式需要隐藏字段
///
public Visibility IsVisibility_N
{
get
{
return _isVisibility_N;
}
set
{
Set(() => IsVisibility_N, ref _isVisibility_N, value);
}
}
private Visibility _isVisibility_Type1 = Visibility.Collapsed;
public Visibility IsVisibility_Type1
{
get
{
return _isVisibility_Type1;
}
set
{
Set(() => IsVisibility_Type1, ref _isVisibility_Type1, value);
}
}
private Visibility _isVisibility_Type2 = Visibility.Collapsed;
public Visibility IsVisibility_Type2
{
get
{
return _isVisibility_Type2;
}
set
{
Set(() => IsVisibility_Type2, ref _isVisibility_Type2, value);
}
}
#endregion
#region P 模式需要隐藏字段
private Visibility _isVisibility_P = Visibility.Collapsed;
///
/// P 模式需要隐藏字段
///
public Visibility IsVisibility_P
{
get
{
return _isVisibility_P;
}
set
{
Set(() => IsVisibility_P, ref _isVisibility_P, value);
}
}
#endregion
#region 升贴水类型查询条件隐藏
private Visibility _isVisibility_WareHouse = Visibility.Collapsed;
public Visibility IsVisibility_WareHouse
{
get { return _isVisibility_WareHouse; }
set { Set(() => IsVisibility_WareHouse, ref _isVisibility_WareHouse, value); }
}
private Visibility _isVisibility_Brand = Visibility.Collapsed;
public Visibility IsVisibility_Brand
{
get { return _isVisibility_Brand; }
set { Set(() => IsVisibility_Brand, ref _isVisibility_Brand, value); }
}
private Visibility _isVisibility_Quality = Visibility.Collapsed;
public Visibility IsVisibility_Quality
{
get { return _isVisibility_Quality; }
set { Set(() => IsVisibility_Quality, ref _isVisibility_Quality, value); }
}
private Visibility _isVisibility_Spec = Visibility.Collapsed;
public Visibility IsVisibility_Spec
{
get { return _isVisibility_Spec; }
set { Set(() => IsVisibility_Spec, ref _isVisibility_Spec, value); }
}
private Visibility _isVisibility_BtnSearch = Visibility.Collapsed;
public Visibility IsVisibility_BtnSearch
{
get { return _isVisibility_BtnSearch; }
set { Set(() => IsVisibility_BtnSearch, ref _isVisibility_BtnSearch, value); }
}
#endregion
#region PAndX 模式需要隐藏字段
private Visibility _isVisibility_PAndX = Visibility.Visible;
///
/// PAndX 模式需要隐藏字段
///
public Visibility IsVisibility_PAndX
{
get
{
return _isVisibility_PAndX;
}
set
{
Set(() => IsVisibility_PAndX, ref _isVisibility_PAndX, value);
}
}
#endregion
#region N 模式需要显示字段
private Visibility _isVisibility_Only_N = Visibility.Collapsed;
///
/// N 模式需要显示字段
///
public Visibility IsVisibility_Only_N
{
get
{
return _isVisibility_Only_N;
}
set
{
Set(() => IsVisibility_Only_N, ref _isVisibility_Only_N, value);
}
}
#endregion
#region 买卖方向选择是否可用
private bool _isEnable_Direction = false;
///
/// 买卖方向选择是否可用
///
public bool IsEnable_Direction
{
get
{
return _isEnable_Direction;
}
set
{
Set(() => IsEnable_Direction, ref _isEnable_Direction, value);
}
}
#endregion
#region 【置灰】设置按键不可用
private bool _oKButtonEnabled = false;
///
///设置按键不可用
///
public bool OKButtonEnabled
{
get
{
return _oKButtonEnabled;
}
set
{
Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
}
}
#endregion
#region 提货方式
private TakeGoodsWay _takeGoodsWay;
///
/// 提货方式
///
public TakeGoodsWay TakeGoodsWay
{
get { return _takeGoodsWay; }
set { Set(() => TakeGoodsWay, ref _takeGoodsWay, value); }
}
#endregion
#region 身份证
private string _idCardNum;
///
/// 身份证号
///
public string IdCardNum
{
get { return _idCardNum; }
set { Set(() => IdCardNum, ref _idCardNum, value); }
}
#endregion
#endregion "Public Properties To Get/Set "
#region "=========公共命令/Public Commands"
///
/// 下单窗口取消
///
public RelayCommand CancelCommand
{
get
{
return new RelayCommand((dialog) =>
{
dialog.DialogResult = false;
});
}
}
///
/// 下单确定
///
public RelayCommand OKCommand
{
get
{
return new RelayCommand((dialog) =>
{
OKButtonEnabled = false;
string errorMsg = string.Empty;
bool validateBool = true; ////内容验证
if (validateBool)
{
//BusyContent = Client_Resource.Content_Busy;
//IsBusy = true;
_openWindow = dialog;
GetDataBeforeSubmit();
var newOrder = new DeliveryOrderReqModel()
{
AccountID = AccountID,
EntrustTime = ApplicationParameter.ServerTimeNow,
DeliveryGoodsID = DeliveryGoodsID,
DeliveryQty = (ulong)submitDeliveryQty,
OperatorID = (uint)AccountID,
PGoodsID = P1GoodsID,
PQty = ulong.Parse((RelationDeliveryCountDisp == "--") ? "0" : RelationDeliveryCountDisp),
P2GoodsID = P2GoodsID,
P2Qty = ulong.Parse((RelationDeliveryCountDisp2 == "--") ? "0" : RelationDeliveryCountDisp2),
XGoodsID = XGoodsID,
XQty = (ulong)DeliveryCount,
};
foreach (var writem in CurrentSelectedWrDetail)
{
newOrder.wrDetail = writem;
_deliveryService.DeliveryApplyOrder(newOrder, null, null);
}
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
OKButtonEnabled = true;
MessageBoxHelper.ShowSuccess("交割申请已提交",
Client_Resource.UI2014_Tips);
if (_openWindow != null)
{
_openWindow.Close();
this.Cleanup();
}
}));
}
else
{
MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
OKButtonEnabled = true;
}
});
}
}
#region 选中Command
///
/// 选中
///
private RelayCommand selectCommand;
public RelayCommand SelectCommand
{
get
{
return selectCommand ?? (selectCommand = new RelayCommand(
(x) =>
{
if (_action == false)
{
_action = true;
x.IsEnable = true;
CurrentSelectedWhRecieptEx = x;
SettlementDeliveryMatchNum(CommandFromType.SelectedCommand);
_action = false;
}
}));
}
}
#endregion
#region 取消选中Command
///
/// 取消选中
///
private RelayCommand unSelectCommand;
public RelayCommand UnSelectCommand
{
get
{
return unSelectCommand ?? (unSelectCommand = new RelayCommand(
(x) =>
{
if (_action == false)
{
_action = true;
CurrentSelectedWhRecieptEx = x;
CurrentSelectedWhRecieptEx.SelectQty = 0;
CurrentSelectedWhRecieptEx.SelectedQty = "0";
SettlementDeliveryMatchNum(CommandFromType.UnSelectedCommand);
_action = false;
}
}));
}
}
#endregion
#region 文本改变命令Command
private RelayCommand _selectQtyTextChangedCommand;
///
/// 文本改变命令Command
///
public RelayCommand SelectQtyTextChangedCommand
{
get
{
return _selectQtyTextChangedCommand
?? (_selectQtyTextChangedCommand = new RelayCommand(
p =>
{
if (_action == false)
{
_action = true;
CurrentSelectedWhRecieptEx = p;
SettlementDeliveryMatchNum(CommandFromType.TextCommand);
_action = false;
}
}));
}
}
#endregion
#endregion "Public Commands"
#region WarehouseSelectionChangedCommand
private RelayCommand _warehouseSelectionChanged;
///
/// Gets the WarehouseSelectionChanged.
///
public RelayCommand WarehouseSelectionChanged
{
get
{
return _warehouseSelectionChanged
?? (_warehouseSelectionChanged = new RelayCommand(
() =>
{
if (!string.IsNullOrEmpty(SelectedWareHouse.Key))
{
FilterList.Clear();
if (SelectedWareHouse.Key != "0")
{
FilterList.Add(SelectedWareHouse);
}
if (!string.IsNullOrEmpty(SelectedBrand.Key) && SelectedBrand.Key != "0")
{
FilterList.Add(SelectedBrand);
}
if (!string.IsNullOrEmpty(SelectedQuality.Key) && SelectedQuality.Key != "0")
{
FilterList.Add(SelectedQuality);
}
if (!string.IsNullOrEmpty(SelectedSpeci.Key) && SelectedSpeci.Key != "0")
{
FilterList.Add(SelectedSpeci);
}
}
}));
}
}
#endregion
#region BrandSelectionChanged
private RelayCommand _brandSelectionChanged;
///
/// Gets the BrandSelectionChanged.
///
public RelayCommand BrandSelectionChanged
{
get
{
return _brandSelectionChanged
?? (_brandSelectionChanged = new RelayCommand(
() =>
{
if (!string.IsNullOrEmpty(SelectedBrand.Key))
{
FilterList.Clear();
if (SelectedBrand.Key != "0")
{
FilterList.Add(SelectedBrand);
}
if (!string.IsNullOrEmpty(SelectedWareHouse.Key) && SelectedWareHouse.Key != "0")
{
FilterList.Add(SelectedWareHouse);
}
if (!string.IsNullOrEmpty(SelectedQuality.Key) && SelectedQuality.Key != "0")
{
FilterList.Add(SelectedQuality);
}
if (!string.IsNullOrEmpty(SelectedSpeci.Key) && SelectedSpeci.Key != "0")
{
FilterList.Add(SelectedSpeci);
}
}
}));
}
}
#endregion
#region QualitySelectionChangedCommand
private RelayCommand _qualitySelectionChanged;
///
/// Gets the RankSelectionChangedCommand.
///
public RelayCommand QualitySelectionChanged
{
get
{
return _qualitySelectionChanged
?? (_qualitySelectionChanged = new RelayCommand(
() =>
{
if (!string.IsNullOrEmpty(SelectedQuality.Key))
{
FilterList.Clear();
if (SelectedQuality.Key != "0")
{
FilterList.Add(SelectedQuality);
}
if (!string.IsNullOrEmpty(SelectedWareHouse.Key) && SelectedWareHouse.Key != "0")
{
FilterList.Add(SelectedWareHouse);
}
if (!string.IsNullOrEmpty(SelectedBrand.Key) && SelectedBrand.Key != "0")
{
FilterList.Add(SelectedBrand);
}
if (!string.IsNullOrEmpty(SelectedSpeci.Key) && SelectedSpeci.Key != "0")
{
FilterList.Add(SelectedSpeci);
}
}
}));
}
}
#endregion
#region SpeciSelectionChangedCommand
private RelayCommand _speciSelectionChanged;
///
/// Gets the RankSelectionChangedCommand.
///
public RelayCommand SpeciSelectionChanged
{
get
{
return _speciSelectionChanged
?? (_speciSelectionChanged = new RelayCommand(
() =>
{
if (!string.IsNullOrEmpty(SelectedSpeci.Key))
{
FilterList.Clear();
if (SelectedSpeci.Key != "0")
{
FilterList.Add(SelectedSpeci);
}
if (!string.IsNullOrEmpty(SelectedWareHouse.Key) && SelectedWareHouse.Key != "0")
{
FilterList.Add(SelectedWareHouse);
}
if (!string.IsNullOrEmpty(SelectedBrand.Key) && SelectedBrand.Key != "0")
{
FilterList.Add(SelectedBrand);
}
if (!string.IsNullOrEmpty(SelectedQuality.Key) && SelectedQuality.Key != "0")
{
FilterList.Add(SelectedQuality);
}
}
}));
}
}
#endregion
#region "=========私有方法/Private Methods"
///
/// 勾选仓单处理
///
///
private void SettlementDeliveryMatchNum(CommandFromType commandType)
{
switch (commandType)
{
case CommandFromType.TextCommand:
CurrentSelectedWhRecieptEx.SelectedQty = (CurrentSelectedWhRecieptEx.SelectQty * StandardQty).ToString();
//SelectQtyTextChangedHandleEvent();
break;
case CommandFromType.SelectedCommand:
CurrentSelectedWhRecieptEx.SelectedQty = (CurrentSelectedWhRecieptEx.SelectQty * StandardQty).ToString();
break;
case CommandFromType.UnSelectedCommand:
CurrentSelectedWhRecieptEx.IsEnable = false;
break;
default:
break;
}
CtrlDeliveryQtyChangeEvent();
}
///
/// 控制点选仓单时候,交割数量的变化事件
///
private void CtrlDeliveryQtyChangeEvent()
{
OKButtonEnabled = false;
var sourceList = WrPairDetailsListEx.FindAll(p => p.IsSelected == true);
DeliveryNum = decimal.Zero;
if (sourceList != null && sourceList.Count > 0)
{
foreach (var item in sourceList)
{
DeliveryNum += Convert.ToDecimal(item.SelectQty) * StandardQty;
}
}
if (DeliveryNum != decimal.Zero)
{
OKButtonEnabled = true;//是否已经点选仓单且数量大于零
}
}
///
/// DataGrid 选择文本改变处理事件
///
private void SelectQtyTextChangedHandleEvent()
{
if (CurrentSelectedWhRecieptEx.SelectQty>0)
{
CurrentSelectedWhRecieptEx.IsSelected = true;
}
else
{
CurrentSelectedWhRecieptEx.IsSelected = false;
}
}
///
/// 提交数据前获取选择的仓单ID/数量
///
private void GetDataBeforeSubmit()
{
if (CurrentSelectedWrDetail != null)
{
CurrentSelectedWrDetail.Clear();
}
var sourceList = WrPairDetailsListEx.FindAll(p => p.IsSelected == true);
submitDeliveryQty = decimal.Zero;//点选的交割总数量
foreach (var item in sourceList)
{
if (!CurrentSelectedWrDetail.Any(x => x.WRPositionID == item.WRPositionID))
{
var newWrDetail = getWrItem(item.WRPositionID);
CurrentSelectedWrDetail.Add(newWrDetail);
submitDeliveryQty += (decimal)newWrDetail.Qty;
}
}
}
///
/// 获取指定WrDetailModel实例
///
///
private WrDetailModel getWrItem(ulong wrcode)
{
var selectItem = WrPairDetailsListEx.Where(x => x.WRPositionID == wrcode).FirstOrDefault();
var item = new WrDetailModel()
{
AccountID=selectItem.AccountID,
BrandID=selectItem.BrandID,
DeliveryMonthID=selectItem.DeliveryMonthID,
Qty=ulong.Parse(selectItem.SelectedQty),
QualityID=selectItem.QualityID,
StandardID=selectItem.SpecID,
WarehouseID=selectItem.WarehouseID
};
return item;
}
///
/// 触发提交按钮是否可用
///
private void IsEnableButtonEvent()
{
//交易员账户,且商品是做市商品时,不可以发起交割申报
OKButtonEnabled = false;
if (_currentDirection == Direction.Ask)
{
if (CurrentSelectedWrDetail != null
&& CurrentSelectedWrDetail.Any()
&& CurrentSelectedWrDetail.Count() > 0
//&& AlreadyMatchQty == preOtherCanMatchQty
&& CurrentGoods != null
//&& FreezeDeliveryMoney <= usableFunds
&& DeliveryCount <= MaxDeliveryUnit && DeliveryCount > 0
&& (UserManager.CurrentTradeAccount.AccountType == eUserType.USERTYPE_INVESTOR )//|| CurrentGoods.currentTradeMode != eTradeMode.TRADEMODE_MARKETMAKE)
)
{
OKButtonEnabled = true;
}
else
{
OKButtonEnabled = false;
}
}
else
{
if (MaxDeliveryUnit <= 0 || MinDeliveryUnit <= 0 || CurrentGoods == null
|| DeliveryCount > MaxDeliveryUnit || DeliveryCount <= 0
|| (RelationDeliveryCount > RelationGoodsHoldQty && CurrentRelationMode == eDeliveryContractLink.PAndX)
|| (MinDeliveryUnit != 0 && DeliveryCount % MinDeliveryUnit != 0 )
)
{
OKButtonEnabled = false;
}
else
{
OKButtonEnabled = true;
}
}
}
private void DeliveryCountEvent()
{
ShowErrorInfo = string.Empty;
IsError_DeliveryCount = false;
IsError_RelationDeliveryCount = false;
IsError_RelationDeliveryCount2 = false;
if (CurrentGoods != null)
{
//if (FreezeDeliveryMoney > usableFunds)
//{
// ShowErrorInfo = Client_Resource.DeliveryOrderViewModel_usableFundsNotEnough;// "资金不足,请修改交割数量";
//}
var maxQty = Math.Min(AvailHoldQty, MaxDeliveryUnit);
if (MinDeliveryUnit != 0 && DeliveryCount % MinDeliveryUnit != 0)
{
IsError_DeliveryCount = true;
ShowErrorInfo = string.Format(Client_Resource.DeliveryOrderViewModel_MaxMin_Error, MinDeliveryUnit, maxQty, MinDeliveryUnit);// 申报数量需小于可用数量,且为最小交割数量{***}的整数倍
}
if (DeliveryCount > MaxDeliveryUnit || DeliveryCount < MinDeliveryUnit)
{
IsError_DeliveryCount = true;
ShowErrorInfo = string.Format(Client_Resource.DeliveryOrderViewModel_MaxMin_Error, MinDeliveryUnit, maxQty, MinDeliveryUnit);// 申报数量应当在最小申报数量{0}与最大申报数量之间。
}
if (RelationDeliveryCount > RelationGoodsHoldQty && CurrentRelationMode == eDeliveryContractLink.PAndX)
{
IsError_RelationDeliveryCount = true;
ShowErrorInfo = Client_Resource.DeliveryOrderViewModel_RelationHolderNotEnough;// 关联商品可用数量不足,请修改申报数量
}
//if ((UserManager.CurrentTradeAccount.AccountType == eLoginUserType.LOGINUSERTYPE_TRADER && CurrentGoods.currentTradeMode == eTradeMode.TRADEMODE_MARKETMAKE))
//{
// ShowErrorInfo = Client_Resource.DeliveryOrderViewModel_AccountTypeNotEnough;// "交易员账户,且商品是做市商品时,不可以发起交割申报";
//}
// IsEnableButtonEvent();
}
}
///
/// 提交成功返回
///
///
private void EntrurstSuccessCallBack(DeliveryOrderRspModel order)
{
//IsBusy = false;
//Application.Current.Dispatcher.BeginInvoke(new Action(() =>
//{
// OKButtonEnabled = true;
// MessageBoxHelper.ShowSuccess(Client_Resource.Order_Success_Result,
// Client_Resource.UI2014_Tips);
// if (_openWindow != null)
// {
// _openWindow.Close();
// this.Cleanup();
// }
//}));
//刷新正常单
MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
}
///
/// 委托失败返回
///
///
private void EntrurstErrorCallBack(ErrorEntity errorEntity)
{
IsBusy = false;
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
OKButtonEnabled = true;
ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
if (_openWindow != null)
{
_openWindow.Close();
MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.HolderUpdate);
this.Cleanup();
}
}));
}
///
/// 初始化交割商品列表数据
///
private void InitData(DeliveryOrderMessage parameterInfo)
{
IsBusy = true;
XGoodsID = parameterInfo.GoodsId;
AccountID = parameterInfo.AccountID;
Direction buyOrSell = parameterInfo.Direction;
CurrentGoods = CacheManager.CacheGoodsBaseInfos.FirstOrDefault(p => p.GoodsId == XGoodsID);
XGoodsCode = CurrentGoods.GoodsCode;
XGoodsName = CurrentGoods.Name;
this._goodsItem = new QuoteGoodsDTO(CurrentGoods);
XPriceFormat = this._goodsItem.CurrentPriceDisplay;
string deliveryFactorTips = string.Empty;
var goodsPMLst = CurrentGoods.GoodsPMList;
if (goodsPMLst != null)
{
foreach (var pm in goodsPMLst)
{
string pmTip = string.Empty;
if (pm.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_BRAND)
{
pmTip = "品牌:";
}
else if (pm.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_QUALITY)
{
pmTip = "品质:";
}
else if (pm.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_SPECIFICATION)
{
pmTip = "规格:";
}
else if (pm.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_WAREHOUSE)
{
pmTip = "仓库:";
}
pmTip += pm.PriceMoveDesc;
deliveryFactorTips += pmTip + ", ";
}
if (deliveryFactorTips.Length > 0)
{
deliveryFactorTips = deliveryFactorTips.Substring(0, deliveryFactorTips.Length - 5);
}
}
DeliveryFactor = deliveryFactorTips;
var currentHolding = CacheManager.HoldingSummaries[AccountID].FirstOrDefault(p => p.GoodsId == XGoodsID);
if (currentHolding != null)
{
if (buyOrSell == Direction.Bid)
{
this.AvailHoldQty = currentHolding.BuyCurPositionQty - currentHolding.BuyFrozenQty - currentHolding.BuyOtherFrozenQty;
}
else
{
this.AvailHoldQty = currentHolding.SellCurPositionQty = currentHolding.SellFrozenQty - currentHolding.SellOtherFrozenQty;
}
}
if (CurrentGoods.P1Type == uint.MaxValue && CurrentGoods.P2Type == uint.MaxValue)
{
IsVisibility_P = Visibility.Collapsed;
IsVisibility_Type1 = Visibility.Collapsed;
IsVisibility_Type2 = Visibility.Collapsed;
}
else
{
IsVisibility_P = Visibility.Visible;
if (CurrentGoods.P1Type != uint.MaxValue)
{
IsVisibility_Type1 = Visibility.Visible;
if (CurrentGoods.P1Type == 1)
{
var currentP1 = CacheManager.CacheGoodsBaseInfos.FirstOrDefault(p => p.GoodsId == CurrentGoods.PGoodsID1);
var P1Holding = CacheManager.HoldingSummaries[AccountID].FirstOrDefault(p => p.GoodsId == CurrentGoods.PGoodsID1);
if (P1Holding != null)
{
if (buyOrSell == Direction.Bid)
{
this.RelationGoodsHoldQty = P1Holding.BuyCurPositionQty - P1Holding.BuyFrozenQty - P1Holding.BuyOtherFrozenQty;
}
else
{
this.RelationGoodsHoldQty = P1Holding.SellCurPositionQty - P1Holding.SellFrozenQty - P1Holding.SellOtherFrozenQty;
}
}
P1GoodsName = currentP1.Name;
P1GoodsCode = currentP1.GoodsCode;
P1GoodsID = currentP1.GoodsId;
}
else
{
P1GoodsName = "固定价";
RelationGoodsHoldPrice = CurrentGoods.P1value;
}
}
else
{
IsVisibility_Type1 = Visibility.Collapsed;
}
if (CurrentGoods.P2Type != uint.MaxValue)
{
IsVisibility_Type2 = Visibility.Visible;
if (CurrentGoods.P2Type == 1)
{
var currentP2 = CacheManager.CacheGoodsBaseInfos.FirstOrDefault(p => p.GoodsId == CurrentGoods.PGoodsID2);
var P2Holding = CacheManager.HoldingSummaries[AccountID].FirstOrDefault(p => p.GoodsId == CurrentGoods.PGoodsID2);
if (P2Holding != null)
{
if (buyOrSell == Direction.Bid)
{
this.RelationGoodsHoldQty2 = P2Holding.BuyCurPositionQty - P2Holding.BuyFrozenQty - P2Holding.BuyOtherFrozenQty;
}
else
{
this.RelationGoodsHoldQty2 = P2Holding.SellCurPositionQty = P2Holding.SellFrozenQty - P2Holding.SellOtherFrozenQty;
}
}
P2GoodsName = currentP2.Name;
P2GoodsCode = currentP2.GoodsCode;
P2GoodsID = currentP2.GoodsId;
}
else
{
P2GoodsName = "固定价";
RelationGoodsHoldPrice2 = CurrentGoods.P2value;
}
}
else
{
IsVisibility_Type2 = Visibility.Collapsed;
}
}
DeliveryGoodsName = CurrentGoods.DeliveryGoodsName;
DeliveryGoodsCode = CurrentGoods.DeliveryGoodsCode;
DeliveryGoodsNameCode = CurrentGoods.DeliveryGoodsNameCode;
uint DeliveryGoodsID = CurrentGoods.DeliveryGoodsId;
uint TradeProperty = (uint)CurrentGoods.TradeProperty;
_deliveryService.QueryDeliveryWarehouseOrdersNew(XGoodsID, DeliveryGoodsID, TradeProperty, QuerySuccessCallBackNew, QueryErrorCallbackNew);
}
private void QuerySuccessCallBackNew(DeliveryWRRspModel model)
{
var currentDeliveryGoods = CacheManager.CacheDeliveryGoodsInfo.FirstOrDefault(p => p.DeliveryGoodsCode == DeliveryGoodsCode);
StandardQty = currentDeliveryGoods.StandardQty;
DeliveryGoodsID = currentDeliveryGoods.DeliveryGoodsID;
List goodsDryLst = model.GoodsDeliveryPriceList;
List tradeWRPositionLst = model.TradeWRPositionList;
List AllFilterLst = currentDeliveryGoods.DeliveryGoodsPMList;
List ExceptFilterLst = CurrentGoods.GoodsPMList;
foreach (var item in ExceptFilterLst)
{
AllFilterLst = AllFilterLst.FindAll(p => p.PriceMoveType != item.PriceMoveType);
}
if (AllFilterLst != null && AllFilterLst.Count > 0)
{
IsVisibility_BtnSearch=Visibility.Visible;
var brandLst = AllFilterLst.FindAll(p => p.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_BRAND);
if (brandLst.Count > 0)
{
IsVisibility_Brand = Visibility.Visible;
DeliveryBrandList = brandLst.Select(p => { return new KeyValuePair(p.PriceMoveType +"_"+ p.PriceMoveID.ToString(), p.PriceMoveDesc); }).ToList();
SelectedBrand = new KeyValuePair("0", "所有品牌");
DeliveryBrandList.Insert(0, SelectedBrand);
}
else
{
IsVisibility_Brand = Visibility.Collapsed;
}
var qualityLst = AllFilterLst.FindAll(p => p.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_QUALITY);
if (qualityLst.Count > 0)
{
IsVisibility_Quality = Visibility.Visible;
DeliveryQualityList = qualityLst.Select(p => { return new KeyValuePair(p.PriceMoveType +"_"+ p.PriceMoveID.ToString(), p.PriceMoveDesc); }).ToList();
SelectedQuality = new KeyValuePair("0", "所有品质");
DeliveryQualityList.Insert(0, SelectedQuality);
}
else
{
IsVisibility_Quality = Visibility.Collapsed;
}
var speciLst = AllFilterLst.FindAll(p => p.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_SPECIFICATION);
if (speciLst.Count > 0)
{
IsVisibility_Spec = Visibility.Visible;
DeliverySpeciList = speciLst.Select(p => { return new KeyValuePair(p.PriceMoveType +"_"+ p.PriceMoveID.ToString(), p.PriceMoveDesc); }).ToList();
SelectedSpeci = new KeyValuePair("0", "所有规格");
DeliverySpeciList.Insert(0, SelectedSpeci);
}
else
{
IsVisibility_Spec = Visibility.Collapsed;
}
var warehouseLst = AllFilterLst.FindAll(p => p.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_WAREHOUSE);
if (warehouseLst.Count > 0)
{
IsVisibility_WareHouse = Visibility.Visible;
List> wareLst = warehouseLst.Select(p => { return new KeyValuePair(p.PriceMoveType +"_"+ p.PriceMoveID.ToString(), p.PriceMoveDesc); }).ToList();
SelectedWareHouse = new KeyValuePair("0", "所有仓库");
wareLst.Insert(0, SelectedWareHouse);
DeliveryWarehouseList = new ObservableCollection>(wareLst);
}
else
{
IsVisibility_WareHouse = Visibility.Collapsed;
}
}
else
{
IsVisibility_Brand = Visibility.Collapsed;
IsVisibility_Quality = Visibility.Collapsed;
IsVisibility_Spec = Visibility.Collapsed;
IsVisibility_WareHouse = Visibility.Collapsed;
IsVisibility_BtnSearch = Visibility.Collapsed;
}
foreach (var tradeWR in tradeWRPositionLst)
{
tradeWR.BrandName = currentDeliveryGoods.DeliveryGoodsPMList.FirstOrDefault(p => p.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_BRAND && p.PriceMoveID == tradeWR.BrandID).PriceMoveDesc;
tradeWR.BrandType = ((int)ePriceMoveType.PRICEMOVETYPE_BRAND).ToString() +"_"+ tradeWR.BrandID;
tradeWR.MaximunQty = (uint)tradeWR.RestQty / (uint)StandardQty;
tradeWR.QualityName = currentDeliveryGoods.DeliveryGoodsPMList.FirstOrDefault(p => p.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_QUALITY && p.PriceMoveID == tradeWR.QualityID).PriceMoveDesc;
tradeWR.QualityType = ((int)ePriceMoveType.PRICEMOVETYPE_QUALITY).ToString() +"_"+ tradeWR.QualityID;
tradeWR.SpecName = currentDeliveryGoods.DeliveryGoodsPMList.FirstOrDefault(p => p.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_SPECIFICATION && p.PriceMoveID == tradeWR.SpecID).PriceMoveDesc;
tradeWR.SpecType = ((int)ePriceMoveType.PRICEMOVETYPE_SPECIFICATION).ToString() +"_"+ tradeWR.SpecID;
tradeWR.WarehouseName = currentDeliveryGoods.DeliveryGoodsPMList.FirstOrDefault(p => p.PriceMoveType == (uint)ePriceMoveType.PRICEMOVETYPE_WAREHOUSE && p.PriceMoveID == tradeWR.WarehouseID).PriceMoveDesc;
tradeWR.WarehouseType = ((int)ePriceMoveType.PRICEMOVETYPE_WAREHOUSE).ToString() + "_" + tradeWR.WarehouseID;
var brand = goodsDryLst.FirstOrDefault(p => p.PriceMoveType == ((uint)ePriceMoveType.PRICEMOVETYPE_BRAND).ToString() && p.PriceMoveID == tradeWR.BrandID);
if (brand != null)
{
tradeWR.PriceMove += brand.PriceMoveValue;
}
var quality = goodsDryLst.FirstOrDefault(p => p.PriceMoveType == ((uint)ePriceMoveType.PRICEMOVETYPE_QUALITY).ToString() && p.PriceMoveID == tradeWR.QualityID);
if (quality != null)
{
tradeWR.PriceMove += quality.PriceMoveValue;
}
var speci = goodsDryLst.FirstOrDefault(p => p.PriceMoveType == ((uint)ePriceMoveType.PRICEMOVETYPE_SPECIFICATION).ToString() && p.PriceMoveID == tradeWR.SpecID);
if (speci != null)
{
tradeWR.PriceMove += speci.PriceMoveValue;
}
var warehouse = goodsDryLst.FirstOrDefault(p => p.PriceMoveType == ((uint)ePriceMoveType.PRICEMOVETYPE_WAREHOUSE).ToString() && p.PriceMoveID == tradeWR.WarehouseID);
if (warehouse != null)
{
tradeWR.PriceMove += warehouse.PriceMoveValue;
}
}
WrPairDetailsListEx = tradeWRPositionLst;
CachedPairDetailsList = tradeWRPositionLst;
IsBusy = false;
}
private void QueryErrorCallbackNew(ErrorEntity error)
{
IsBusy = false;
}
///
/// 检测卖方向是否可用
///
private void CheckIsSellEnable()
{
IsEnable_Direction = false;
//if (CurrentGoods != null)
//{
// var currentGoodsTradeMode = CurrentGoods.TradeMode;
// var tempAvailHoldQty = LoadingHolder(CurrentGoods.RelationGoodsId, Direction.Ask);
// //无卖持仓时,卖方向不可选置灰,仅竞价与混合-保证金商品-才可以发起卖交割
// if (tempAvailHoldQty > decimal.Zero && CurrentGoods != null && CurrentGoods.Sponsor == eSponsorType.Both && CurrentMoneyMode == eMoneyMode.MONEYMODE_MARGIN && (currentGoodsTradeMode == eTradeMode.TRADEMODE_BIDDING || currentGoodsTradeMode == eTradeMode.TRADEMODE_BIDDINGMARKETMAKE))
// {
// IsEnable_Direction = true;
// }
//}
}
///
/// 加载最大最小交割数量
///
private void MinMaxDeliveryLot()
{
if (CurrentGoods != null)
{
var maxQty = _goodsService.GetGoodsParamerRule((int)CurrentGoods.GoodsId,
CurrentGoods.TradeMode, GoodsTradeConts.MaxDeliveryQty);
var minQty = _goodsService.GetGoodsParamerRule((int)CurrentGoods.GoodsId,
CurrentGoods.TradeMode, GoodsTradeConts.MinDeliveryQty);
MinDeliveryUnit = minQty == null ? defaut_minLot : minQty.FeeValue;
MaxDeliveryUnit = maxQty == null ? defaut_maxLot : maxQty.FeeValue;
MaxDeliveryUnit = Math.Min((AvailHoldQty - AvailHoldQty % MinDeliveryUnit), MaxDeliveryUnit);
#region #33584 最小交收数量(手数),最大交收数量(手数)改从申报商品的交易规则中取
//MinDeliveryUnit = CurrentGoods.minDeliveryQty;
////最小交割手数转换为交易手数
//MinDeliveryUnit = Math.Round(MinDeliveryUnit * CurrentGoods.Conversion, 2, MidpointRounding.AwayFromZero);
//MaxDeliveryUnit = CurrentGoods.maxDeliveryQty;
////最大交割手数转换为交易手数
//var tempMaxDeliveryUnit = Math.Round(MaxDeliveryUnit * CurrentGoods.Conversion, 2, MidpointRounding.AwayFromZero);
//MaxDeliveryUnit = tempMaxDeliveryUnit - tempMaxDeliveryUnit % MinDeliveryUnit;
//MaxDeliveryUnit = Math.Min((AvailHoldQty - AvailHoldQty % MinDeliveryUnit), MaxDeliveryUnit);
#endregion
DeliveryCount = (MinDeliveryUnit == decimal.Zero ? 1 : MinDeliveryUnit);//默认设置下单数量
}
else
{
MinDeliveryUnit = defaut_minLot;
MaxDeliveryUnit = defaut_maxLot;
}
}
///
/// 申报数量转交割数量
/// 交割数量 = 申报商品的申报手数 * 申报商品合约单位 * 兑换系数;
///
private void DeclareToDeliveryLot()
{
if (CurrentGoods != null)
{
DeliveryNum = (int)(DeliveryCount / CurrentGoods.PDeliveryRatio1) * CurrentGoods.MinDeliveryQty;//CurrentGoods.currentAgreeunit * CurrentGoods.Conversion;
}
}
///
/// 主商品申报手数-转-数量
///
private void MainGoodsToLot()
{
if (CurrentGoods != null)
{
GoodsNum = DeliveryCount* CurrentGoods.AgreeUnit;
}
}
///
/// 关联商品申报手数-转-数量
///
private void RelationGoodsToLot()
{
//if (CurrentGoods != null && (eDeliveryContractLink)CurrentGoods.RelationMode == eDeliveryContractLink.PAndX)
//{
// var RelationGoodsItem = FindRelationGoodsInfoByID(CurrentGoods.RelationGoodsId);
// //关联商品转换显示数量
// RelationNum = RelationDeliveryCount * RelationGoodsItem.AgreeUnit;
//}
}
///
/// 主商品-关联商品-配比转换
///
private void MainGoodsToRelationGoodsLot(decimal deliveryCount)
{
if (CurrentGoods != null)
{
RelationDeliveryCount = ((int)(deliveryCount / CurrentGoods.PDeliveryRatio1) * CurrentGoods.XDeliveryRatio);//deliveryCount * (CurrentGoods.goodsscale == 0 ? 1 : CurrentGoods.goodsscale);//商品配比,默认为1
}
}
///
/// 设置可交收数量
///
private void SetDeliveryCount()
{
ResetData();
if (CurrentGoods != null)
{
_deliveryService.QueryDeliveryWhRecieptInfo(AccountID, CurrentGoods.GoodsId, QueryWhRecieptSuccess, DeliveryGoodsCallBack);
MinMultiple = CurrentGoods.MinDeliveryQty;//默认值
_currentMoneyMode = eMoneyMode.MONEYMODE_MARGIN;//CurrentGoods.currentMoneymode;
_currentDirection = Direction.Bid;//CurrentBuyOrSell.BuyOrSell;
ChangeDirectionTitle();
AvailHoldQty = LoadingHolder(CurrentGoods.GoodsId, _currentDirection);
AvailHoldQtyUnit = AvailHoldQty * CurrentGoods.AgreeUnit;
DeliveryPrice = GetDeliveryPriceCalcMethod(CurrentGoods.GoodsId, GoodsOfCR.CurrentGoods);
SwichDeliveryGoodsInfo();
// DeclareToDeliveryLot();
//MainGoodsToLot();
//RelationGoodsToLot();
//MinMaxDeliveryLot();
CurrentGoodsUnitType = CurrentGoods.GoodsUnit;// CacheManager.TradeGoodsUnit.Where(x => x.UNITID == CurrentGoods.currentGoodsunit).Select(x => x.GOODSUNITNAME).FirstOrDefault();
DeliveryAgreeUnitType = CurrentGoods.DeliveryGoodsUnit;//CacheManager.TradeGoodsUnit.Where(x => x.UNITID == CurrentGoods.GoodsUnitId).Select(x => x.GOODSUNITNAME).FirstOrDefault();
//IsEnableButtonEvent();
switch (_currentRelationMode)
{
case eDeliveryContractLink.None:
RelationMode_N_HandleEvent(_currentMoneyMode);
break;
case eDeliveryContractLink.Normal:
RelationMode_P_HandleEvent(_currentMoneyMode);
break;
case eDeliveryContractLink.PAndX:
RelationMode_PAndX_HandleEvent(_currentMoneyMode);
break;
default:
break;
}
}
}
///
/// 买卖名称改变
///
private void ChangeDirectionTitle()
{
if (_currentDirection == Direction.Bid)
{
DirectionTitle = Resources.Client_Resource.Domain_BuyIn;
}
else
{
DirectionTitle = Resources.Client_Resource.Domain_SellOut;
}
}
///
/// 交割算法取值//持仓均价
///
private decimal GetDeliveryPriceCalcMethod(long goodsID, GoodsOfCR type)
{
HoldDetails = null;
var CurrentAgreeunit = CurrentGoods.AgreeUnit;
if (type == GoodsOfCR.RelationGoods)
{
CurrentAgreeunit = CacheManager.CacheGoodsBaseInfos.Where(x=>x.GoodsId==goodsID).Select(x=>x.AgreeUnit).FirstOrDefault();
}
//持仓价=持仓价均价
var TempDeliveryPrice = LoadingHolder(goodsID, _currentDirection);
switch (eReckonPriceCalcMethodType.HolderPriceMove)
{
case eReckonPriceCalcMethodType.LastPrice:
case eReckonPriceCalcMethodType.HolderPriceMove:
case eReckonPriceCalcMethodType.AgreedPrice:
case eReckonPriceCalcMethodType.ReckonPrice:
case eReckonPriceCalcMethodType.HolderPrice:
//持仓价
//if (HoldDetails != null && HoldDetails.Any())
//{
// if (HoldDetails.Sum((item) => item.Lot - item.LockQty) > 0)
// TempDeliveryPrice = HoldDetails.Sum((order) => order.HoldAmount - order.lockHolderAmount) / HoldDetails.Sum((item) => item.Lot - item.LockQty) / CurrentAgreeunit;
//}
TempDeliveryPrice = TempDeliveryPrice / CurrentAgreeunit;
break;
}
return TempDeliveryPrice;
}
///
/// N 模式处理
///
private void RelationMode_N_HandleEvent(eMoneyMode moneyMode)
{
IsVisibility_Only_N = Visibility.Visible;
IsVisibility_N = Visibility.Collapsed;
//MinDeliveryUnit = 1;
//MaxDeliveryUnit = AvailHoldQty;
if (_currentDirection == Direction.Bid)//买方向
{
if (moneyMode == eMoneyMode.MONEYMODE_MARGIN)//保证金
{
}
else
{
}
}
}
///
/// P 模式处理
///
private void RelationMode_P_HandleEvent(eMoneyMode moneyMode)
{
IsVisibility_Only_N = Visibility.Collapsed;
IsVisibility_P = Visibility.Collapsed;
if (_currentDirection == Direction.Bid)//买方向
{
if (moneyMode == eMoneyMode.MONEYMODE_MARGIN)//保证金
{
}
else
{
}
}
}
///
/// P+X 模式处理
///
private void RelationMode_PAndX_HandleEvent(eMoneyMode moneyMode)
{
IsVisibility_Only_N = Visibility.Collapsed;
IsVisibility_PAndX = Visibility.Visible;
LoadingRelationGoodsInfo();
if (_currentDirection == Direction.Bid)//买方向
{
//var tempAvailHoldQty = Math.Min(RelationGoodsHoldQty, AvailHoldQty);
//MaxDeliveryUnit = Math.Min((tempAvailHoldQty - tempAvailHoldQty % MinDeliveryUnit), MaxDeliveryUnit);
if (moneyMode == eMoneyMode.MONEYMODE_MARGIN)//保证金
{
}
else
{
}
}
else
{
}
}
///
/// 重置数据初始值
///
private void ResetData()
{
_currentRelationMode = eDeliveryContractLink.None;
_currentMoneyMode = eMoneyMode.MONEYMODE_MARGIN;
IsVisibility_N = Visibility.Visible;
IsVisibility_PAndX = Visibility.Visible;
AvailHoldQty = decimal.Zero;
DeliveryPrice = decimal.Zero;
RelationGoodsHoldQty = decimal.Zero;
RelationGoodsHoldPrice = decimal.Zero;
DeliveryCount = 0;
RelationDeliveryCount = 0;
DeliveryNum = 0;
MinMultiple = 0;
}
///
/// 查询-交割规则-成功返回
///
///
protected void QueryWhRecieptSuccess(List itemList)
{
if (WrPairDetailsList != null)
{
WrPairDetailsList = new List();
}
if (itemList.Any() && itemList.Count > 0)
{
WrPairDetailsList = itemList;
}
IsBusyWR = false;
}
///
/// 查询-交割规则 MTP2.0
///
///
protected void QueryRelationList()
{
#region 初始化交割商品
List tempGoods = new List();
if (CacheManager.CacheGoodsPositionList != null || CacheManager.CacheRealGoodsPositionList!=null)
{
//持仓头寸-商品ID LIST
var AdvanceGoodsIDList = CacheManager.CacheGoodsPositionList.Select((item) => item.GoodsId).Distinct().ToList();
var FullPayGoodsIDList = CacheManager.CacheRealGoodsPositionList.Select((item) => item.GoodsId).Distinct().ToList();
List AllDeliveryGoodsIDList = AdvanceGoodsIDList.Concat(FullPayGoodsIDList).ToList();
foreach (var id in AllDeliveryGoodsIDList)
{
//过滤可以交割的商品ID
foreach (var item in CacheManager.CacheGoodsBaseInfos.Where(x=>x.DeliveryFlag==1))
{
if (id == item.GoodsId && !tempGoods.Exists(x => x.GoodsId == item.GoodsId))
{
tempGoods.Add(item);
}
}
}
}
DeliveryGoodsList = tempGoods;
LoadingDeliveryGoods();
//Application.Current.Dispatcher.BeginInvoke(new Action(() =>
//{
// //GetDepositPersonalInfo();
//}));
#endregion
}
///
/// 判断商品是否在可交割期内
///
///
private bool IsGoodsBetweenDate(GoodsDeliveryRelationModel item)
{
bool flag = false;
#region 交割开始日期
if (item.MinDateDeliveryDate == DateTime.MinValue)
{
flag = true;
}
else if (item.MinDateDeliveryDate != DateTime.MinValue && ApplicationParameter.ServerTimeNow >= item.MinDateDeliveryDate)
{
flag = true;
}
else
{
flag = false;
}
#endregion
#region 交割结束日期
if (item.MaxDateDeliveryDate == DateTime.MinValue)
{
flag = true;
}
else if (item.MaxDateDeliveryDate != DateTime.MinValue && ApplicationParameter.ServerTimeNow <= item.MaxDateDeliveryDate)
{
flag = true;
}
else
{
flag = false;
}
#endregion
return flag;
}
///
/// 交割商品关系配置失败返回
///
///
private void DeliveryGoodsCallBack(ErrorEntity errorEntity)
{
IsBusyWR = false;
}
///
/// 获取交割提货个人信息
///
private void GetDepositPersonalInfo()
{
if (CurrentGoods != null)
{
var accountid = UserManager.CurrentTradeAccount.AccountId;
//if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
//{
// accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
//}
var ReqModel = new DepositPersonalInfoReqModel();
ReqModel.accountId = (long)accountid;
IsBusy = true;
//交割提货个人信息查询
//_deliveryService.SearchDepositPersonalInfoReq(ReqModel, QueryDepositPersonalInfoSuccess, QueryDepositPersonalInfoCallBack);
}
}
///
/// 交割提货个人信息-成功返回
///
///
protected void QueryDepositPersonalInfoSuccess(DepositPersonalInfoRspModel itemModel)
{
if (itemModel != null)
{
CurrentDepositPersonalInfo = itemModel;
if (CurrentDepositPersonalInfo != null)
{
RecieveAddress = CurrentDepositPersonalInfo.address;
RecievePerson = CurrentDepositPersonalInfo.personName;
PhoneNum = CurrentDepositPersonalInfo.telphone;
IdCardNum = CurrentDepositPersonalInfo.IdCardNum;
}
}
IsBusy = false;
}
///
/// 获取交割提货个人信息失败返回
///
///
private void QueryDepositPersonalInfoCallBack(ErrorEntity errorEntity)
{
IsBusy = false;
}
///
/// 【首次运行】加载交易商品
///
private void LoadingDeliveryGoods()
{
if (DeliveryGoodsList != null && DeliveryGoodsList.Any() && DeliveryGoodsList.Count() > 0)
{
CurrentGoods = DeliveryGoodsList.FirstOrDefault();
//MinMultiple = CurrentGoods.LimitSum;//默认值
//DeliveryCount = CurrentGoods.PlimitConversion;//默认值
_currentMoneyMode = eMoneyMode.MONEYMODE_MARGIN;//暂时固定为保证金//CurrentGoods.currentMoneymode;
DeliveryGoodsNameList.Clear();
DeliveryGoodsNameList.Add(DeliveryGoodsList.FirstOrDefault().DeliveryGoodsNameCode);
CurrentDeliveryGoodsName = DeliveryGoodsNameList.FirstOrDefault();
if (_parameterInfo != null && _parameterInfo.GoodsId > 0)
{
CurrentGoods = DeliveryGoodsList.FirstOrDefault(x => x.GoodsId == _parameterInfo.GoodsId);
DeliveryGoodsNameList.Clear();
DeliveryGoodsNameList.Add(DeliveryGoodsList.FirstOrDefault(x => x.GoodsId == _parameterInfo.GoodsId).DeliveryGoodsNameCode);
CurrentDeliveryGoodsName = DeliveryGoodsNameList.FirstOrDefault();
}
}
}
///
/// 加载持仓//可用持仓数量
///
private decimal LoadingHolder(long goodsID,Direction buyOrSell)
{
var TempAvailHoldQty = decimal.Zero;
var holders = CacheManager.CacheGoodsPositionList;//UserManager.GetCacheOrders();
if (holders != null && holders.Any())
{
#region MTP2.0 变动
//HoldDetails = holders.Where((item) => item.GoodsId == goodsID && item.Direction == buyOrSell).ToList();//买卖方向持仓
//if (HoldDetails != null && HoldDetails.Any())
//{
// var TempPositionFzQty = HoldDetails.FirstOrDefault().PositionFzQty;
// var TempTotalHoldDetails = HoldDetails.Sum((order) => order.Lot - order.LockQty);
// TempAvailHoldQty = TempTotalHoldDetails - TempPositionFzQty;
//}
#endregion
var TempInstan = holders.Where(x => x.GoodsId == goodsID).ToList().FirstOrDefault();
if (TempInstan != null)
{
if (buyOrSell == Direction.Bid)
{
TempAvailHoldQty = (decimal)(TempInstan.BuyCurPositionQty - TempInstan.BuyFrozenQty - TempInstan.BuyOtherFrozenQty);
}
else
{
TempAvailHoldQty = (decimal)(TempInstan.SellCurPositionQty - TempInstan.SellFrozenQty - TempInstan.SellOtherFrozenQty);
}
}
}
return TempAvailHoldQty;
}
///
/// 加载关联交易商品信息
///
private void LoadingRelationGoodsInfo()
{
//RelationGoodsHoldQty = LoadingHolder(CurrentGoods.RelationGoodsId, _currentDirection);
//RelationGoodsHoldPrice = GetDeliveryPriceCalcMethod(CurrentGoods.RelationGoodsId, GoodsOfCR.RelationGoods);
//var RelationGoodsItem =FindRelationGoodsInfoByID(CurrentGoods.RelationGoodsId);
//RelationGoodsUnitType = RelationGoodsItem.GoodsUnit;//CacheManager.TradeGoodsUnit.Where(x => x.UNITID == RelationGoodsItem.RelationGoodsunit).Select(x => x.GOODSUNITNAME).FirstOrDefault();
//var RelationGoodsName = RelationGoodsItem.DeliveryGoodsNameCode;
//RelationGoodsHoldQtyUnit = RelationGoodsHoldQty * RelationGoodsItem.AgreeUnit;
//RelationGoodsNameList.Clear();
//RelationGoodsNameList.Add(RelationGoodsName);
//CurrentRelationGoodsName = RelationGoodsNameList.FirstOrDefault();
//IsEnableButtonEvent();
//DeliveryCountEvent();
}
///
/// 查找关联商品信息BY商品ID
///
private QuoteGoods FindRelationGoodsInfoByID(long RelationGoodsId)
{
if (CacheManager.CacheGoodsBaseInfos!= null)
{
return CacheManager.CacheGoodsBaseInfos.Find(x => x.GoodsId == RelationGoodsId);
}
return null;
}
///
/// 切换交割商品信息
///
private void SwichDeliveryGoodsInfo()
{
DeliveryGoodsNameList.Clear();
DeliveryGoodsNameList.Add(CurrentGoods.DeliveryGoodsNameCode);
CurrentDeliveryGoodsName = DeliveryGoodsNameList.FirstOrDefault();
}
#endregion "Private Methods"
#region "=========其它方法/Other Methods"
///
/// 数据验证
///
///
///
public bool Validated(ref string msg)
{
//申报数量 > 最大可申报数量
if (DeliveryCount > MaxDeliveryUnit)
{
msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_OpenLotGreatThanMaxLot, MaxDeliveryUnit);
return false;
}
//申报数量应为最小交割数量的整数倍
if (MinDeliveryUnit != 0 && DeliveryCount % MinDeliveryUnit != 0 && CurrentRelationMode != eDeliveryContractLink.None)
{
msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.DeliveryCountShoutBeMinUnitDouble, MinDeliveryUnit); ;
return false;
}
if (DeliveryCount <= 0 || DeliveryCount == decimal.Zero)
{
//数量不在正确范围内
msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Delivery_ChooseCorrectDeclareNum, MaxDeliveryUnit); ;
return false;
}
#region MTP2.0 注销
//if (RecievePerson.Trim() == "" )
//{
// msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecievePerson + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
// return false;
//}
//if (RecieveAddress.Trim() == "" && TakeGoodsWay == TakeGoodsWay.Express)
//{
// msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecieveAddress + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
// return false;
//}
//if (PhoneNum.Trim() == "" )
//{
// msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNum + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
// return false;
//}
//if (PhoneNum.Trim() != "" && (!PhoneNum.StartsWith("1") || PhoneNum.Length != 11 || !ValidationHelper.IsMobile(PhoneNum)))
//{
// msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNumErrFormat;
// return false;
//}
//if (string.IsNullOrWhiteSpace(IdCardNum) || !ValidationHelper.IsIDcard(IdCardNum))
//{
// msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_IDCardNumErrFormat;
// return false;
//}
#endregion
return true;
}
#endregion "Other Methods"
}
public enum GoodsOfCR
{
///
/// 当前商品
///
CurrentGoods = 1,
///
/// 关联商品
///
RelationGoods = 2,
}
}