using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Model.Delivery; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.Resources; using System; using System.Collections.Generic; using System.Windows; using System.Linq; using Muchinfo.MTPClient.Infrastructure.MessageBox; using GalaSoft.MvvmLight.Command; using System.Collections.ObjectModel; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Infrastructure.Cache; using System.Text; using System.Windows.Input; using System.Windows.Controls; namespace Muchinfo.MTPClient.Delivery.ViewModels { /// /// 交割配对 /// /// /// public class DeliveryMatchViewModel : ViewModelBase { #region "=========私有成员/Private Data Members" private IDeliveryService _deliveryService; private Window _openWindow; //private decimal usableFunds = 0; private decimal tempOtherCanMatchQty; private bool _action = false; private bool _isCheckAction = false; private DeliveryEntrustOrder _deliveryEntrustOrder; private decimal totalQty = decimal.Zero; private decimal AllCanUseQty = decimal.Zero; private string WrCodeListStr = string.Empty; #endregion "Private Data Members" #region "=========构造函数/Constructor/Initialization" public DeliveryMatchViewModel(DeliveryEntrustOrder itemOrder) { this._deliveryEntrustOrder = itemOrder; _deliveryService = SimpleIoc.Default.GetInstance(); InitData(); } #endregion "Constructor/Initialization" #region "=========接口重写/Interface implementation Or override" //To do interface implementation #endregion "Interface implementation Or override" #region "=========公共属性/Public Properties To Get/Set " #region 错误信息提示 private string _ErrorMessage = string.Empty; /// /// 错误信息提示 /// public string ErrorMessage { get { return _ErrorMessage; } set { Set(() => ErrorMessage, ref _ErrorMessage, value); } } #endregion #region 当前仓单详细 private DeliveryWarehouse _currentWarehouseDetail; /// /// 当前仓单详细 /// public DeliveryWarehouse CurrentWarehouseDetail { get { return _currentWarehouseDetail; } set { Set(() => CurrentWarehouseDetail, ref _currentWarehouseDetail, value); } } #endregion #region 所有当前用户仓单 private List _allWarehouseOrders; /// /// 所有当前用户仓单 /// public List AllWarehouseOrders { get { return _allWarehouseOrders; } set { Set(() => AllWarehouseOrders, ref _allWarehouseOrders, value); } } #endregion #region 选择预览数据 private ObservableCollection _chooseMatchOrderList = new ObservableCollection(); /// /// 选择预览数据 /// public ObservableCollection ChooseMatchOrderList { get { return _chooseMatchOrderList; } set { Set(() => ChooseMatchOrderList, ref _chooseMatchOrderList, value); } } #endregion #region 当前选择仓单 private WrPairDetailModel _currentSelectedItem; /// /// 当前选择仓单 /// public WrPairDetailModel CurrentSelectedItem { get { return _currentSelectedItem; } set { Set(() => CurrentSelectedItem, ref _currentSelectedItem, value); } } #endregion #region 主数据-是否显示 private Visibility _isVisibility_Main = Visibility.Visible; /// /// 主数据-是否显示 /// public Visibility IsVisibility_Main { get { return _isVisibility_Main; } set { Set(() => IsVisibility_Main, ref _isVisibility_Main, value); } } #endregion #region 预览数据-是否显示 private Visibility _IsVisibility_PreView = Visibility.Collapsed; /// /// 预览数据-是否显示 /// public Visibility IsVisibility_PreView { get { return _IsVisibility_PreView; } set { Set(() => IsVisibility_PreView, ref _IsVisibility_PreView, 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); } } #endregion #region 标题 private string _title = Resources.Client_Resource.DeliveryEntructOrderView_Matched; /// /// 标题 /// public string Title { get { return _title; } set { Set(() => Title, ref _title, value); } } #endregion #region 按钮是否可用 private bool _oKButtonEnabled = true; /// ///按钮是否可用 /// public bool OKButtonEnabled { get { return _oKButtonEnabled; } set { Set(() => OKButtonEnabled, ref _oKButtonEnabled, value); } } #endregion #region 是否繁忙 private bool _isBusy = false; /// /// Sets and gets the IsBusy property. /// Changes to that property's value raise the PropertyChanged event. /// public bool IsBusy { get { return _isBusy; } set { Set(() => IsBusy, ref _isBusy, value); } } #endregion #region 交割仓单配对列表 public List TempDeliveryMatchOrderList = new List(); private List _deliveryMatchOrderList = new List(); /// /// 交割仓单配对列表 /// public List DeliveryMatchOrderList { get { return _deliveryMatchOrderList; } set { Set(() => DeliveryMatchOrderList, ref _deliveryMatchOrderList, value); } } #endregion #region 预查询数据 private List _searchMatchOrderList; /// /// 预查询数据 /// public List SearchMatchOrderList { get { return _searchMatchOrderList; } set { Set(() => SearchMatchOrderList, ref _searchMatchOrderList, value); } } #endregion #region 仓库下拉列表 private List _deliveryWarehouseList = new List(); /// /// 仓库下拉列表 /// public List DeliveryWarehouseList { get { return _deliveryWarehouseList; } set { Set(() => DeliveryWarehouseList, ref _deliveryWarehouseList, value); } } #endregion #region 品牌下拉列表 private ObservableCollection _deliveryBrandList = new ObservableCollection(); /// /// 品牌下拉列表 /// public ObservableCollection DeliveryBrandList { get { return _deliveryBrandList; } set { Set(() => DeliveryBrandList, ref _deliveryBrandList, value); } } #endregion #region 等级下拉列表 private ObservableCollection _deliveryLevelList = new ObservableCollection(); /// /// 等级下拉列表 /// public ObservableCollection DeliveryLevelList { get { return _deliveryLevelList; } set { Set(() => DeliveryLevelList, ref _deliveryLevelList, value); } } #endregion #region 当前选中仓库 private string _currentWarehouse; /// /// 当前选中仓库 /// public string CurrentWarehouse { get { return _currentWarehouse; } set { Set(() => CurrentWarehouse, ref _currentWarehouse, value); } } #endregion #region 当前选中品牌 private string _currentBrand; /// /// 当前选中品牌 /// public string CurrentBrand { get { return _currentBrand; } set { Set(() => CurrentBrand, ref _currentBrand, value); } } #endregion #region 当前选中等级 private string _currentLevel; /// /// 当前选中等级 /// public string CurrentLevel { get { return _currentLevel; } set { Set(() => CurrentLevel, ref _currentLevel, value); } } #endregion #region 是否显示还需配对数量提示 private Visibility _isVisibility_NeedMatchQty = Visibility.Collapsed; /// /// 是否显示还需配对数量提示 /// public Visibility IsVisibility_NeedMatchQty { get { return _isVisibility_NeedMatchQty; } set { Set(() => IsVisibility_NeedMatchQty, ref _isVisibility_NeedMatchQty, value); } } #endregion #region 当前勾选单据LIST //【OrderMatchDetailModel】 private List _currentSelectedOrderMatchDetail = null; /// /// 当前勾选的仓单配对 /// public List CurrentSelectedOrderMatchDetail { get { return _currentSelectedOrderMatchDetail; } set { Set(() => CurrentSelectedOrderMatchDetail, ref _currentSelectedOrderMatchDetail, value); } } #endregion #region 是否勾选 private bool _isCheckedCurrentBox = false; /// /// 是否勾选 /// public bool IsCheckedCurrentBox { get { return _isCheckedCurrentBox; } set { Set(() => IsCheckedCurrentBox, ref _isCheckedCurrentBox, value); } } #endregion #region 已配对数量 private decimal _aleadyMatchQty = decimal.Zero; /// /// 已配对数量 /// public decimal AlreadyMatchQty { get { return _aleadyMatchQty; } set { //value = Math.Round(value, 0); Set(() => AlreadyMatchQty, ref _aleadyMatchQty, value); } } #endregion #region 剩余可配对数量 /// /// 剩余可配对数量 /// private decimal preOtherCanMatchQty = 0; private decimal _otherCanMatchQty = 0; /// /// 剩余可配对数量 /// public decimal OtherCanMatchQty { get { return _otherCanMatchQty; } set { //value = Math.Round(value, 0); Set(() => OtherCanMatchQty, ref _otherCanMatchQty, value); } } #endregion #region 是否全选 private bool _isSelectAll = false; /// /// 是否全选 /// Changes to that property's value raise the PropertyChanged event. /// public bool IsSelectAll { get { return _isSelectAll; } set { Set(() => IsSelectAll, ref _isSelectAll, value); } } #endregion #region 合计点选升帖水 private decimal _totalDeliveryPriceMove = 0; /// /// 合计点选升帖水 /// public decimal TotalDeliveryPriceMove { get { return _totalDeliveryPriceMove; } set { //value = Math.Round(value, 2); ////显示两位小数 Set(() => TotalDeliveryPriceMove, ref _totalDeliveryPriceMove, value); } } #endregion #region 交易商品名称 private string _goodsName = string.Empty; /// /// 交易商品名称 /// public string GoodsName { get { return _goodsName; } set { Set(() => GoodsName, ref _goodsName, value); } } #endregion #region 申报单号 private string _OrderNumber = string.Empty; /// /// 申报单号 /// public string OrderNumber { get { return _OrderNumber; } set { Set(() => OrderNumber, ref _OrderNumber, value); } } #endregion #region 转换单位 private string _agreeUnitString = string.Empty; /// /// 转换单位 /// public string AgreeUnitString { get { return _agreeUnitString; } set { Set(() => AgreeUnitString, ref _agreeUnitString, value); } } #endregion #region 折合数量-转换手数 private decimal _discountNum = decimal.Zero; /// /// 折合数量 /// public decimal DiscountNum { get { return _discountNum; } set { //value = Math.Round(value, 0); Set(() => DiscountNum, ref _discountNum, value); } } #endregion #region 申报手数 private decimal _deliveryCount = decimal.Zero; /// /// 申报手数 /// public decimal DeliveryCount { get { return _deliveryCount; } set { Set(() => DeliveryCount, ref _deliveryCount, value); } } #endregion #region 当前交割配置明细/当前交割配置List public List tempDeliveryConfigList = new List(); private DeliveryConfig _currentDeliveryGoodsConfig = null; /// /// 当前交割配置明细 /// Changes to that property's value raise the PropertyChanged event. /// public DeliveryConfig CurrentDeliveryGoodsConfig { get { return _currentDeliveryGoodsConfig; } set { Set(() => CurrentDeliveryGoodsConfig, ref _currentDeliveryGoodsConfig, value); } } #endregion #endregion "Public Properties To Get/Set " #region "=========公共命令/Public Commands" #region 窗口取消Command /// /// 窗口取消 /// public RelayCommand CancelCommand { get { return new RelayCommand((dialog) => { dialog.DialogResult = false; }); } } #endregion #region 提交确定Command /// /// 提交确定 /// public RelayCommand OKCommand { get { return new RelayCommand((dialog) => { OKButtonEnabled = false; string errorMsg = string.Empty; bool validateBool = Validated(ref errorMsg); ////内容验证 if (validateBool) { IsBusy = true; _openWindow = dialog; var newOrder = new DeliveryOrderMatchReqModel() { OrderId = this._deliveryEntrustOrder.DeliveryOrderId, MatchType = eMatchType.MATCHTYPE_NORMAL,//默认指定类型 matchDetails = _currentSelectedOrderMatchDetail }; //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() && // UserManager.CurrentTradeAccount.FundsAccounts[0] != null) //{ // newOrder.OperatorID = newOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} //else //{ // newOrder.OperatorID = newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId; //} try { _deliveryService.SubmitDeliveryMatchOrder(newOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack); } finally { } } else { MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title); OKButtonEnabled = true; } }); } } #endregion #region 选中Command /// /// 选中 /// private RelayCommand selectCommand; public RelayCommand SelectCommand { get { return selectCommand ?? (selectCommand = new RelayCommand( (x) => { if (_action == false) { _isCheckAction = true; var sourceList = DeliveryMatchOrderList.ToList().FindAll(p => p.WrCode == x); for (int i = 0; i < sourceList.Count(); i++) { if (sourceList[i].NumSort == int.MaxValue) { sourceList[i].NumSort = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true).Count(); } } SettlementDeliveryMatchNum(CommandFromType.SelectedCommand); } })); } } #endregion #region 取消选中Command /// /// 取消选中 /// private RelayCommand unSelectCommand; public RelayCommand UnSelectCommand { get { return unSelectCommand ?? (unSelectCommand = new RelayCommand( (x) => { if (_action == false) { _isCheckAction = true; var sourceList = DeliveryMatchOrderList.ToList().FindAll(p => p.WrCode == x); for (int i = 0; i < sourceList.Count(); i++) { if (sourceList[i].NumSort != int.MaxValue) { sourceList[i].NumSort = int.MaxValue; } } SettlementDeliveryMatchNum(CommandFromType.UnSelectedCommand); } })); } } #endregion #region 测试提交Command private RelayCommand buttonCommand; public RelayCommand ButtonCommand { get { return buttonCommand ?? (buttonCommand = new RelayCommand( () => { int count = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true).Count; for (int i = 0; i < count; i++) MessageBox.Show(DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true)[i].WrCode + "," + DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true)[i].EnableQty); })); } } #endregion #region WarehouseSelectionChangedCommand private RelayCommand _warehouseSelectionChanged; /// /// Gets the WarehouseSelectionChanged. /// public RelayCommand WarehouseSelectionChanged { get { return _warehouseSelectionChanged ?? (_warehouseSelectionChanged = new RelayCommand( () => { FilteMatchOrderListByCombox(); })); } } #endregion #region BrandSelectionChangedCommand private RelayCommand _brandSelectionChanged; /// /// Gets the BrandSelectionChanged. /// public RelayCommand BrandSelectionChanged { get { return _brandSelectionChanged ?? (_brandSelectionChanged = new RelayCommand( () => { FilteMatchOrderListByCombox(); })); } } #endregion #region RankSelectionChangedCommand private RelayCommand _rankSelectionChanged; /// /// Gets the RankSelectionChangedCommand. /// public RelayCommand RankSelectionChanged { get { return _rankSelectionChanged ?? (_rankSelectionChanged = new RelayCommand( () => { FilteMatchOrderListByCombox(); })); } } #endregion #region 预览命令 private RelayCommand _preViewCommand; /// /// 预览命令. /// public RelayCommand PreViewCommand { get { return _preViewCommand ?? (_preViewCommand = new RelayCommand( () => { Title = Resources.Client_Resource.DeliveryEntructOrderView_ComfirmMatchWarehouse;//"确认点选仓单"; IsVisibility_Main = Visibility.Collapsed; IsVisibility_PreView = Visibility.Visible; IsVisibility_Warehouse = Visibility.Collapsed; })); } } #endregion #region 返回命令 private RelayCommand _returnCommand; /// /// 返回命令 /// public RelayCommand ReturnCommand { get { return _returnCommand ?? (_returnCommand = new RelayCommand( () => { Title = Resources.Client_Resource.DeliveryEntructOrderView_Matched; IsVisibility_Main = Visibility.Visible; IsVisibility_PreView = Visibility.Collapsed; IsVisibility_Warehouse = Visibility.Collapsed; })); } } #endregion #region 文本改变命令Command private RelayCommand _selectQtyTextChangedCommand; /// /// 文本改变命令Command /// public RelayCommand SelectQtyTextChangedCommand { get { return _selectQtyTextChangedCommand ?? (_selectQtyTextChangedCommand = new RelayCommand( p => { //if (CurrentSelectedItem != null) //{ // CurrentSelectedItem.SelectQty = LeaveOnlyNumbers(p); //} //if (p != null) //{ // p.IsSelected = !string.IsNullOrWhiteSpace(p.SelectQty) || // !"0".Equals(p.SelectQty.Trim()); //} CurrentSelectedItem = p; if (_action == false) { _action = true; _isCheckAction = false; SettlementDeliveryMatchNum(CommandFromType.TextCommand); _action = false; } })); } } #endregion #region 仓单号详细命令 private RelayCommand _WrCode_MouseLeftButtonDownCommand; /// /// 仓单号详细命令 /// public RelayCommand WrCode_MouseLeftButtonDownCommand { get { return _WrCode_MouseLeftButtonDownCommand ?? (_WrCode_MouseLeftButtonDownCommand = new RelayCommand( p => { Title = Resources.Client_Resource.DeliveryEntructOrderView_Warehouse;//"仓单"; IsVisibility_Main = Visibility.Collapsed; IsVisibility_PreView = Visibility.Collapsed; IsVisibility_Warehouse = Visibility.Visible; #region 仓单变更流水查询 var accountid = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) //{ // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} //IsBusy = true; //_deliveryService.SearchWRChangeFlow(accountid, p, WRChangeFlowOrderSuccess, DeliveryGoodsCallBack); #endregion Application.Current.Dispatcher.BeginInvoke(new Action(() => { if (AllWarehouseOrders != null && AllWarehouseOrders.Any() && AllWarehouseOrders.Count() > 0) { CurrentWarehouseDetail = AllWarehouseOrders.FirstOrDefault(x => x.WRCode == p); } })); })); } } #endregion #region 查询命令 private RelayCommand _searchCommand; /// /// 查询命令 /// public RelayCommand SearchCommand { get { return _searchCommand ?? (_searchCommand = new RelayCommand( () => { SearchMatchOrderList = DeliveryMatchOrderList; })); } } #endregion #endregion "Public Commands" #region "=========私有方法/Private Methods" /// /// 检查输入是否为多个小数点 /// /// /// private string LeaveOnlyNumbers(String inString) { var occur = false; StringBuilder ans = new StringBuilder(); for (int i = 0; i < inString.Length; ++i) { if (System.Text.RegularExpressions.Regex.IsMatch(inString[i].ToString(), "^[0-9\\.]*$")) { if (inString[i] == '.') { if (!occur) { occur = true; ans.Append(inString[i]); } } else ans.Append(inString[i]); } } return ans.ToString(); } /// /// 触发提交按钮是否可用 /// private void IsEnableButtonEvent() { OKButtonEnabled = false; if (_currentSelectedOrderMatchDetail != null && _currentSelectedOrderMatchDetail.Any() && _currentSelectedOrderMatchDetail.Count() > 0 && AlreadyMatchQty == preOtherCanMatchQty )//&& (decimal)TotalDeliveryPriceMove <= usableFunds //错误 #28975 账户可用资金小于升贴水资金,交割配对点选界面限制不允许交割点选配对 { OKButtonEnabled = true; } else { OKButtonEnabled = false; } } /// /// 计算可配数量、剩余数量 /// private void SettlementDeliveryMatchNum(CommandFromType commandType) { _action = true; try { #region 不是来自CheckCommand var sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true); AlreadyMatchQty = 0; TotalDeliveryPriceMove = 0; preOtherCanMatchQty = OtherCanMatchQty = (decimal)DiscountNum;//_deliveryEntrustOrder.OrderQty; CurrentSelectedOrderMatchDetail = new List(); var leaveCount = preOtherCanMatchQty; if (_isCheckAction != true) { if (CurrentSelectedItem != null && CurrentSelectedItem.SelectQty != string.Empty) { CurrentSelectedItem.IsSelected = true; sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true); } else { CurrentSelectedItem.IsSelected = false; } } else { if (commandType != CommandFromType.UnSelectedCommand) { if (sourceList.Count == 0) { ResetData(); } else { leaveCount = GetAlreadyWriteNum(sourceList, leaveCount); sourceList = sourceList.Where(x => x.SelectQty == "").ToList(); } } else { if (sourceList.Count == 0) { ResetData(); } else { CurrentSelectedItem.SelectQty = ""; leaveCount = GetAlreadyWriteNum(sourceList, leaveCount); sourceList = DeliveryMatchOrderList.Where(x => x.SelectQty == "").ToList(); return; } } } #endregion #region 配对数量仅能大于 等于 申报数量 // var sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true); for (int i = 0; i < sourceList.Count(); i++) { if (sourceList[i].DeliveryPriceMove == int.MinValue) { sourceList[i].DeliveryPriceMove = 0; } if (leaveCount >= (decimal)sourceList[i].EnableQty) { if (_isCheckAction != true) { //文本事件处理 if (Convert.ToDecimal(sourceList[i].SelectQty)>0) CurrentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WrId), DeliveryQty = Convert.ToDecimal(sourceList[i].SelectQty), DeliverySellOrderId = sourceList[i].DeliverySellOrderId }); TotalDeliveryPriceMove += (decimal)sourceList[i].DeliveryPriceMove * Convert.ToDecimal(sourceList[i].SelectQty); CurrentSelectedItem.IsError = "0"; if (Convert.ToDouble(sourceList[i].SelectQty) > sourceList[i].EnableQty || Convert.ToDecimal(sourceList[i].SelectQty) > OtherCanMatchQty) { CurrentSelectedItem.IsError = "1"; } } else { if ((decimal)sourceList[i].EnableQty > 0) CurrentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WrId), DeliveryQty = (decimal)sourceList[i].EnableQty, DeliverySellOrderId = sourceList[i].DeliverySellOrderId }); TotalDeliveryPriceMove += (decimal)sourceList[i].DeliveryPriceMove * (decimal)sourceList[i].EnableQty; sourceList[i].SelectQty = sourceList[i].EnableQty.ToString(); } } else { if (leaveCount > 0) { if (_isCheckAction != true) { //文本事件处理 if (Convert.ToDecimal(sourceList[i].SelectQty) > 0) CurrentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WrId), DeliveryQty = Convert.ToDecimal(sourceList[i].SelectQty), DeliverySellOrderId = sourceList[i].DeliverySellOrderId }); TotalDeliveryPriceMove += (decimal)sourceList[i].DeliveryPriceMove * Convert.ToDecimal(sourceList[i].SelectQty); CurrentSelectedItem.IsError = "0"; if (Convert.ToDecimal(sourceList[i].SelectQty) > leaveCount) { CurrentSelectedItem.IsError = "1"; } } else { if ((decimal)leaveCount > 0) CurrentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WrId), DeliveryQty = (decimal)leaveCount, DeliverySellOrderId = sourceList[i].DeliverySellOrderId }); TotalDeliveryPriceMove += (decimal)sourceList[i].DeliveryPriceMove * leaveCount; sourceList[i].SelectQty = leaveCount.ToString(); } } } if (_isCheckAction != true) { //文本事件处理 leaveCount = leaveCount - Convert.ToDecimal(sourceList[i].SelectQty); AlreadyMatchQty =AlreadyMatchQty + Convert.ToDecimal(sourceList[i].SelectQty); } else { leaveCount = leaveCount - (decimal)sourceList[i].EnableQty; AlreadyMatchQty += (decimal)sourceList[i].EnableQty; } } OtherCanMatchQty = OtherCanMatchQty - AlreadyMatchQty; if (OtherCanMatchQty < 0) { OtherCanMatchQty = 0; AlreadyMatchQty = preOtherCanMatchQty; } #region 是否隐藏提示信息 IsVisibility_NeedMatchQty = Visibility.Collapsed; if (sourceList != null && sourceList.Any() && sourceList.Count() > 0) { if (OtherCanMatchQty > 0) { IsVisibility_NeedMatchQty = Visibility.Visible; ErrorMessage = string.Format(Client_Resource.DeliveryMatchView_ErrorMessage_NeedToChoseLot, OtherCanMatchQty);//string.Format("还需选择商品数量{0},申报数量需一次选完",OtherCanMatchQty); } } #endregion #endregion #region 屏蔽剩余勾选框 var sourceList_False = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == false); if (OtherCanMatchQty == 0) { for (int i = 0; i < sourceList_False.Count(); i++) { sourceList_False[i].IsEnabled = false; //sourceList[i].SelectQty = string.Empty; } } else { for (int i = 0; i < sourceList_False.Count(); i++) { sourceList_False[i].IsEnabled = true; } } #endregion IsEnableButtonEvent(); ReCheckData(); PreViewDataHandle(); } catch (Exception ex) { _action = false; } finally { _action = false; } } /// /// 获取已经填写的数量 /// private decimal GetAlreadyWriteNum(List sourceList, decimal leaveCount) { sourceList = sourceList.Where(x => x.SelectQty != "").ToList(); for (int i = 0; i < sourceList.Count(); i++) { //文本事件处理 if (Convert.ToDecimal(sourceList[i].SelectQty) > 0) CurrentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WrId), DeliveryQty = Convert.ToDecimal(sourceList[i].SelectQty), DeliverySellOrderId = sourceList[i].DeliverySellOrderId }); TotalDeliveryPriceMove += (decimal)sourceList[i].DeliveryPriceMove * Convert.ToDecimal(sourceList[i].SelectQty); //文本事件处理 leaveCount = leaveCount - Convert.ToDecimal(sourceList[i].SelectQty); AlreadyMatchQty += Convert.ToDecimal(sourceList[i].SelectQty); } OtherCanMatchQty = OtherCanMatchQty - AlreadyMatchQty; return leaveCount; } /// /// 预览数据转换 /// private void PreViewDataHandle() { var sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true); ChooseMatchOrderList.Clear(); foreach (var item in sourceList) { if (!ChooseMatchOrderList.Any(x => x.WrId == item.WrId)) { ChooseMatchOrderList.Add(item); } } } /// /// 回滚数据 /// private void ResetData() { for (int i = 0; i < DeliveryMatchOrderList.Where(x=>x.IsSelected !=true).Count(); i++) { DeliveryMatchOrderList[i].SelectQty = string.Empty; } } /// /// 复查数据 /// private void ReCheckData() { var sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true); #region 如果没有勾选则没有错误显示 if (sourceList.Count() == 0) { for (int i = 0; i < DeliveryMatchOrderList.Count(); i++) { DeliveryMatchOrderList[i].IsError = "0"; DeliveryMatchOrderList[i].SelectQty = ""; } } #endregion totalQty = decimal.Zero; AllCanUseQty = decimal.Zero; for (int i = 0; i < sourceList.Count(); i++) { totalQty += Convert.ToDecimal(sourceList[i].SelectQty); AllCanUseQty += Convert.ToDecimal(sourceList[i].EnableQty); } if (totalQty == DiscountNum && AllCanUseQty >= totalQty) { for (int i = 0; i < DeliveryMatchOrderList.Count(); i++) { DeliveryMatchOrderList[i].IsError = "0"; } } if (totalQty > DiscountNum || AllCanUseQty < totalQty) { OKButtonEnabled = false; IsVisibility_NeedMatchQty = Visibility.Visible; ErrorMessage = Client_Resource.DeliveryMatchView_ErrorMessage_ChoseLotBiggerThanLeave;//"选择数量大于可选数量"; } } /// /// 初始化数据 /// private void InitData() { if (_deliveryEntrustOrder.DeliveryGoodsId != 0) { IsBusy = true; //加载-仓单配对-数据 _deliveryService.SearchMatchWarehouseReq(BuildEntrustOrder(), SearchSuccessCallBack, SearchErrorCallBack); } //手动添加默认选择数据 TempDeliveryMatchOrderList.Add(new WrPairDetailModel() { StorePlace = Client_Resource.DeliveryMatchView_AllWareHouse, Brand = Client_Resource.DeliveryMatchView_AllBrand, Rank = Client_Resource.DeliveryMatchView_AllRank }); #region 测试数据 //for (int i = 0; i < 5; i++) //{ // TempDeliveryMatchOrderList.Add(new WrPairDetailModel() { StorePlace = "仓库" + i.ToString(), DeliveryGoodsName = "商品" + i.ToString(), Brand = i.ToString(), Rank = i.ToString(), WrId = i + 1003, WrCode = (i + 1).ToString(), EnableQty = i + 1 }); // DeliveryMatchOrderList.Add(new WrPairDetailModel() { StorePlace = "仓库" + i.ToString(), DeliveryGoodsName = "商品" + i.ToString(), Brand = i.ToString(), Rank = i.ToString(), WrId = i + 1003, WrCode = (i + 1).ToString(), EnableQty = i + 1 }); //} //FilteMatchOrderListByCombox(); #endregion IsEnableButtonEvent(); } /// /// 交割商品关系配置成功返回 /// /// protected void DeliveryGoodsRelationConfigSuccess(List itemList) { if (itemList != null && itemList.Count() > 0) { tempDeliveryConfigList = itemList; CurrentDeliveryGoodsConfig = itemList.FirstOrDefault(); if (CurrentDeliveryGoodsConfig != null) { DiscountNum = _deliveryEntrustOrder.DeliveryQty; //关联交割商品-单位 AgreeUnitString = CacheManager.TradeGoodsUnit.Where(x => x.UNITID == CurrentDeliveryGoodsConfig.GoodsUnitId).Select(x => x.GOODSUNITNAME).FirstOrDefault(); OtherCanMatchQty = (decimal)DiscountNum; tempOtherCanMatchQty = (decimal)DiscountNum; } } } /// /// 查询成功返回 /// /// protected void MarketOrderSuccess(List orders) { UpdateItemSource(orders); IsBusy = false; } /// /// 更新数据源 /// /// private void UpdateItemSource(List orders) { if (orders != null) { //foreach (var item in orders) //{ // #region 合约单位转换 // var goodsUnit = CacheManager.TradeGoodsUnit.FirstOrDefault((x) => x.GOODSUNITID == item.GoodsUnitId); // if (goodsUnit != null) // { // item.GoodsUnitIdDisplay = goodsUnit.NAME; // } // #endregion // #region 是否可提货 // if (item.Status == eWRStatus.Normal && (item.Qty - item.FreezeQty - item.PayQty) > 0) // { // item.IsVisibility = Visibility.Visible; // } // #endregion //} AllWarehouseOrders = orders; //所有单据 } } /// /// 交割商品关系配置失败返回 /// /// private void DeliveryGoodsCallBack(ErrorEntity errorEntity) { IsBusy = false; } /// /// 查询配对仓单实体 /// /// private WrPairReqModel BuildEntrustOrder() { var newOrder = new WrPairReqModel(); //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() && // UserManager.CurrentTradeAccount.FundsAccounts[0] != null) //{ // newOrder.OperatorId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} //else //{ // newOrder.OperatorId = UserManager.CurrentTradeAccount.AccountId; //} return newOrder; } /// /// 过滤仓单数据BY下拉列表 /// private void FilteMatchOrderListByCombox() { #region 重置勾选单据 _currentSelectedOrderMatchDetail = null; var sourceList = DeliveryMatchOrderList.ToList(); for (int i = 0; i < sourceList.Count(); i++) { sourceList[i].IsSelected = false; sourceList[i].IsEnabled = true; } OtherCanMatchQty = tempOtherCanMatchQty; AlreadyMatchQty = 0; TotalDeliveryPriceMove = 0; #endregion #region 数据过滤条件 DeliveryMatchOrderList = new List(TempDeliveryMatchOrderList);//数据回归 DeliveryWarehouseList = DeliveryMatchOrderList.Where(x => x.StorePlace != "").Select(x => x.StorePlace).Distinct().ToList(); if (CurrentWarehouse != null && CurrentWarehouse != Client_Resource.DeliveryMatchView_AllWareHouse)//全部仓库 { DeliveryMatchOrderList = DeliveryMatchOrderList.Where(x => x.StorePlace == CurrentWarehouse || x.StorePlace == Client_Resource.DeliveryMatchView_AllWareHouse).ToList(); DeliveryBrandList = new ObservableCollection(DeliveryMatchOrderList.Where(x => x.Brand != "").Select(x => x.Brand).Distinct()); } else { DeliveryBrandList = new ObservableCollection(DeliveryMatchOrderList.Where(x => x.Brand != "").Select(x => x.Brand).Distinct()); ; } if (CurrentBrand != null && CurrentBrand != Client_Resource.DeliveryMatchView_AllBrand)//全部品牌 { DeliveryMatchOrderList = DeliveryMatchOrderList.Where(x => x.Brand == CurrentBrand || x.Brand == Client_Resource.DeliveryMatchView_AllBrand).ToList(); DeliveryLevelList = new ObservableCollection(DeliveryMatchOrderList.Where(x => x.Rank != "").Select(x => x.Rank).Distinct()); } else { DeliveryLevelList = new ObservableCollection(DeliveryMatchOrderList.Where(x => x.Rank != "").Select(x => x.Rank).Distinct()); } if (CurrentLevel != null && CurrentLevel != Client_Resource.DeliveryMatchView_AllRank)//全部等级 { DeliveryMatchOrderList = DeliveryMatchOrderList.Where(x => x.Rank == CurrentLevel || x.Rank == Client_Resource.DeliveryMatchView_AllRank).ToList(); } #endregion #region 默认选择 DeliveryMatchOrderList = DeliveryMatchOrderList.FindAll(x => x.StorePlace != Client_Resource.DeliveryMatchView_AllWareHouse);//过滤手动添加数据 if (CurrentWarehouse == null) { CurrentWarehouse = DeliveryWarehouseList.FirstOrDefault(x => x == Client_Resource.DeliveryMatchView_AllWareHouse);//默认选择 } if (CurrentLevel == null) { CurrentLevel = DeliveryLevelList.FirstOrDefault(x => x == Client_Resource.DeliveryMatchView_AllRank);//默认选择 } if (CurrentBrand == null) { CurrentBrand = DeliveryBrandList.FirstOrDefault(x => x == Client_Resource.DeliveryMatchView_AllBrand);//默认选择 } #endregion IsEnableButtonEvent(); } /// /// 查询成功返回,绑定数据源 /// /// The item list. protected void SearchSuccessCallBack(WrPairRspModel itemList) { if (itemList.WrPairDetails != null && itemList.WrPairDetails.Any() && itemList.WrPairDetails.Count() > 0) { foreach (var item in itemList.WrPairDetails) { #region 合约单位转换 var goodsUnit = CacheManager.TradeGoodsUnit.FirstOrDefault((x) => x.UNITID == item.GoodsUnitId); if (goodsUnit != null) { item.GoodsUnitIdDisplay = goodsUnit.GOODSUNITNAME; } #endregion #region 当前仓单WrCode列表 if (WrCodeListStr == string.Empty) { WrCodeListStr = "'" + item.WrCode + "'"; } else { WrCodeListStr += "," + "'" + item.WrCode + "'"; } #endregion } TempDeliveryMatchOrderList = itemList.WrPairDetails.Where(x => x.EnableQty != 0).ToList(); SearchMatchOrderList = itemList.WrPairDetails.Where(x => x.EnableQty != 0).ToList(); //手动添加默认选择数据 TempDeliveryMatchOrderList.Add(new WrPairDetailModel() { StorePlace = Client_Resource.DeliveryMatchView_AllWareHouse, Brand = Client_Resource.DeliveryMatchView_AllBrand, Rank = Client_Resource.DeliveryMatchView_AllRank }); DeliveryMatchOrderList = TempDeliveryMatchOrderList; FilteMatchOrderListByCombox(); } IsBusy = false; #region 仓单查询 var accountid = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) //{ // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} if (WrCodeListStr != string.Empty) { _deliveryService.QueryDeliveryWarehouseOrders(SearchWarehouseOrdersType.WRCode, WrCodeListStr, accountid, DateTime.MinValue, DateTime.Now.AddDays(1), MarketOrderSuccess, DeliveryGoodsCallBack); } #endregion } /// /// 查询失败返回 /// /// The item list. protected void SearchErrorCallBack(ErrorEntity errorEntity) { IsBusy = false; //Application.Current.Dispatcher.BeginInvoke(new Action(() => //{ // ErrorManager.ShowReturnError(errorEntity, Client_Resource.APP_Tips, false); //})); } /// /// 提交配对成功返回 /// /// private void EntrurstSuccessCallBack(DeliveryOrderMatchRspModel order) { IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { OKButtonEnabled = true; MessageBoxHelper.ShowSuccess(Client_Resource.OrderMatch_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(); this.Cleanup(); } })); } #endregion "Private Methods" #region "=========其它方法/Other Methods" /// /// 数据验证 /// /// /// public bool Validated(ref string msg) { ////申报数量 > 持仓数量 if (AlreadyMatchQty > preOtherCanMatchQty) { msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_OpenLotGreatThanMaxLot, preOtherCanMatchQty); return false; } return true; } #endregion "Other Methods" } }