| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2017/1/12 16:24:30
- //Author
- //Description Create
- //----------------------------------------------------------------
- using System.Windows;
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Infrastructure.MessageBox;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.MTPClient.Resources;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Data.Enums;
- namespace Muchinfo.MTPClient.Sale.ViewModels
- {
- public class DepositApplyViewModel:ViewModelBase
- {
- private IDepositService _iDepositService;
- private DepositPlan _curDepositPlan;
- private Window _openWindow;
- /// <summary>
- /// 当前托管计划
- /// </summary>
- public DepositPlan CurDepositPlan
- {
- get { return _curDepositPlan; }
- set
- {
- if (value != null && _curDepositPlan != value)
- {
- _iDepositService.QueryDepositWareHouse(value.ExAreaId,DepositWareHouseSuccess, ErrorQueryWareHouse); ///查询仓库
- MaxLot = value.MaxDepositNumber;
- }
- Set(() => CurDepositPlan, ref _curDepositPlan, value);
- Lot = 0;
- }
- }
-
-
- private List<DepositPlan> _depositPlans;
- /// <summary>
- /// 托管计划列表
- /// </summary>
- public List<DepositPlan> DepositPlans
- {
- get { return _depositPlans; }
- set { Set(() => DepositPlans, ref _depositPlans, value); }
- }
- private bool _isBusy;
- /// <summary>
- /// 是否正在加载
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
-
- public DepositApplyViewModel(DepositPlan deposit,List<DepositPlan>list)
- {
- _iDepositService = SimpleIoc.Default.GetInstance<IDepositService>();
- CurDepositPlan = deposit;
- DepositPlans = list.Where((item)=>item.IsDepositApply).ToList();
-
- IsBusy = true;
-
- }
-
- private decimal _lot;
- /// <summary>
- /// 数量
- /// </summary>
- public decimal Lot
- {
- get { return _lot; }
- set
- {
- Set(() => Lot, ref _lot, value);
-
- RaisePropertyChanged(() => FeeTips);
- RaisePropertyChanged(() => ErrorTips);
- RaisePropertyChanged(() => FreezeFee);
- }
- }
- public string ErrorTips
- {
- get
- {
- var error = string.Empty;
- if (Lot == 0)
- {
- return Client_Resource.Content_DepositApplyErrorTips;
- }
- if (MaxLot < Lot)
- {
- return Muchinfo.MTPClient.Resources.Client_Resource.Resources_DepositOrder_MaxLotError;
- }
- var usefunds = UserManager.CurrentAccountUsableFunds();
- if (usefunds < FreezeFee) ////资金不足
- {
- return Client_Resource.Content_DepositApplyMonenyErrorTips;
- }
-
-
- return error;
- }
- }
- private List<DepositWareHouse> _storelist;
- /// <summary>
- /// 仓库列表
- /// </summary>
- public List<DepositWareHouse> Storelist
- {
- get { return _storelist; }
- set { Set(() => Storelist, ref _storelist, value); }
- }
- private DepositWareHouse _curWareHouse;
- /// <summary>
- /// 当前的选择仓库
- /// </summary>
- public DepositWareHouse CurWareHouse
- {
- get { return _curWareHouse; }
- set { Set(() => CurWareHouse, ref _curWareHouse, value); }
- }
- private decimal _maxLot=long.MaxValue;
- /// <summary>
- /// 最大托管数量
- /// </summary>
- public decimal MaxLot
- {
- get { return _maxLot; }
- set { Set(() => MaxLot, ref _maxLot, value); }
- }
-
- public string FeeTips
- {
- get
- {
- if (CurDepositPlan != null)
- {
- var tip = string.Format(Client_Resource.AResources_DepositApplyFee, FreezeFee,
- CurDepositPlan.DepositReferPrice, Lot, CurDepositPlan.ListingRate);
- return tip;
- }
- return string.Empty;
- }
- }
-
- public decimal FreezeFee
- {
- get
- {
- if (CurDepositPlan != null)
- {
- return Math.Round(CurDepositPlan.DepositReferPrice*Lot*CurDepositPlan.ListingRate, 2,
- MidpointRounding.AwayFromZero);
- }
- return 0m ;
- }
- }
- /// <summary>
- /// 快速下单窗口取消
- /// </summary>
- public RelayCommand<Window> CancelCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- dialog.DialogResult = false;
- });
- }
- }
- /// <summary>
- /// 下单确定
- /// </summary>
- public RelayCommand<Window> OKCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- _openWindow = dialog;
-
-
- bool validateBool = Vailed();
- if (validateBool)
- {
- IsBusy = true;
- var accountId = UserManager.CurrentTradeAccount.AccountId;
- //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
- // UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
- //{
- // accountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
- //}
- var depositOrder = new DepositOrder()
- {
- DepositNum = Lot,
- Accountid = accountId,
- BuildType = eBuildType.BUILDTYPE_OPEN,
- DepositId = CurDepositPlan.DepositId,
- WarehouseId = CurWareHouse.WareHouseId,
- };
- _iDepositService.DepositApply(depositOrder, DepositApplySuccess, ErrorDeosit);
- }
-
- }, IsOKEnable);
- }
- }
- private void DepositWareHouseSuccess(List<DepositWareHouse> list)
- {
- IsBusy = false;
- Storelist = list;
- if (Storelist != null)
- {
- CurWareHouse = null;
- CurWareHouse = Storelist.FirstOrDefault();
- }
- }
- private void ErrorQueryWareHouse(ErrorEntity errorEntity)
- {
- IsBusy = false;
- //todo:写错误日志
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="depositOrder"></param>
- private void DepositApplySuccess(DepositOrder depositOrder)
- {
- IsBusy = false;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- MessageBoxHelper.ShowSuccess(Client_Resource.Content_DepositApplySuccess,
- Client_Resource.Open_MessageBox_Title);
- if (_openWindow != null)
- {
- _openWindow.Close();
- this.Cleanup();
- }
- }));
- //刷新正常单
- MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.DepositOrderToken);
- }
- private void ErrorDeosit(ErrorEntity errorEntity)
- {
- IsBusy = false;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
- if (_openWindow != null)
- {
- _openWindow.Close();
- this.Cleanup();
- }
- // IsBusy = false;
- }));
- }
- private bool IsOKEnable(Window item)
- {
- if (CurDepositPlan==null)
- {
- return false;
- }
- else if(CurWareHouse==null)
- {
- return false;
- }
- var usefunds = UserManager.CurrentAccountUsableFunds();
- if (usefunds < FreezeFee) ////资金不足
- {
- return false;
- }
- if (CurDepositPlan.MaxDepositNumber < Lot)
- {
-
- return false;
- }
- return Lot > 0;
- }
- private bool Vailed()
- {
- if (CurDepositPlan == null)
- {
- MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Content_DepositUnSelect, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
- return false;
- }
- if (CurDepositPlan.MaxDepositNumber < Lot)
- {
- MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Resources_DepositOrder_MaxLotError, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
- return false;
- }
- DateTime deTime = DateTime.Now;
- if (!DateTime.TryParse(CurDepositPlan.DepositStartTime, out deTime)||deTime.Date>ApplicationParameter.ServerTimeNow.Date)
- {
- MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Content_DepositUnStarting, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
- return false;
- }
- else if (!DateTime.TryParse(CurDepositPlan.DepositEndTime, out deTime)||deTime.Date<ApplicationParameter.ServerTimeNow.Date)
- {
- MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Content_DepositEnd, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
- return false;
- }
- return true;
- }
-
- }
- }
|