using System; using System.Collections.Generic; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2017/1/12 22:16:38 //Author //Description Create //---------------------------------------------------------------- using System.Windows; using System.Windows.Input; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Delivery; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.MessageBox; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.Infrastructure.Windows; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.Resources; using Muchinfo.MTPClient.Data.Model.Account; namespace Muchinfo.MTPClient.Sale.ViewModels { public class QueryDepositApplyViewModel : QueryPanelModelBase { #region 开始时间 private DateTime startTime; /// /// 开始时间 /// public DateTime StartTime { get { return startTime; } set { Set(() => StartTime, ref startTime, value); } } #endregion #region 结束时间 private DateTime _endTime; /// /// 结束时间 /// public DateTime EndTime { get { return _endTime; } set { Set(() => EndTime, ref _endTime, value); } } private List _depositApplyList; /// /// 查询托管申请单据 /// public List DepositApplyList { get { return _depositApplyList; } set { Set(() => DepositApplyList, ref _depositApplyList, value); } } private DepositApplyModel _curApplyModel; /// /// 当前选择的单据 /// public DepositApplyModel CurApplyModel { get { return _curApplyModel; } set { Set(() => CurApplyModel, ref _curApplyModel, value); } } #endregion #region 重置查询时间命令Command private RelayCommand _resetCommand; /// /// Gets the ResetCommand. /// public RelayCommand ResetCommand { get { return _resetCommand ?? (_resetCommand = new RelayCommand( () => { EndTime = ApplicationParameter.ServerTimeNow.AddDays(1); StartTime = ApplicationParameter.ServerTimeNow.AddDays(-29); })); } } #endregion #region 撤销命令Command private RelayCommand _cancelCommand; public ICommand CancelCommand { get { if (_cancelCommand == null) { _cancelCommand = new RelayCommand(() => { CanceleOrder(); }); } return _cancelCommand; } } private void CanceleOrder() { if (CurApplyModel != null) { var accountId = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() && // UserManager.CurrentTradeAccount.FundsAccounts[0] != null) //{ // accountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} var orderBuild = new DepositOrder() { Accountid = accountId, BuildType = eBuildType.BUILDTYPE_CLOSE, StoreinId = CurApplyModel.StoreInId, }; var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToCancel, Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips); if (boxResult == MessageBoxResult.Yes) { IsBusy = true; _depositService.DepositApply(orderBuild, EntrurstSuccessCallBack, EntrurstErrorCallBack); } } } private RelayCommand _rightRelayCommand; public RelayCommand RightCancelCommand { get { if (_rightRelayCommand == null) { _rightRelayCommand = new RelayCommand(() => { CanceleOrder(); }, IsCanceledEnable); } return _rightRelayCommand; } } private bool IsCanceledEnable() { if (CurApplyModel == null) { return false; } else { return CurApplyModel.AuditStatus == eAuditStatus.AUDITSTATUS_CHECKING; } } #endregion private IDepositService _depositService; public QueryDepositApplyViewModel() { _depositService = SimpleIoc.Default.GetInstance(); } /// 撤销成功返回 /// /// private void EntrurstSuccessCallBack(DepositOrder order) { IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Account_CancelSuccess, Client_Resource.Cancel_MessageBox_Title); //MessageBoxHelper.ShowSuccess(Client_Resource.Order_Success_Result, // Client_Resource.Cancel_MessageBox_Title); //if (_openWindow != null) //{ // _openWindow.Close(); // this.Cleanup(); //} })); RefreshContent(); ////更新撤单状态 } /// /// 撤销失败返回 /// /// private void EntrurstErrorCallBack(ErrorEntity errorEntity) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true); IsBusy = false; })); } public override void RegisterMessage() { EndTime = ApplicationParameter.ServerTimeNow.AddDays(1); StartTime = ApplicationParameter.ServerTimeNow.AddDays(-29); //RefreshContent(); RefreshCommand.Execute(null); MessengerHelper.DefaultUnregister(this, MessengerTokens.DepositOrderToken); MessengerHelper.DefaultRegister(this, MessengerTokens.DepositOrderToken, (e) => { RefreshCommand.Execute(null); }); } public override void UnRegisterMessage() { this.Cleanup(); //base.UnRegisterMessage(); } public override void RefreshContent() { if (Vailed()) { var accountid = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts != null && // UserManager.CurrentTradeAccount.FundsAccounts.Any()) //{ // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} _depositService.QueryDepositApply(accountid, startTime, EndTime, QueryDepositApplySuccess, ErrorQuery); } } private void QueryDepositApplySuccess(List list) { IsBusy = false; DepositApplyList = list; } private void ErrorQuery(ErrorEntity errorEntity) { IsBusy = false; ////todo:查询失败 } #region "Other Methods like Validated" /// /// 数据验证 /// /// private bool Vailed() { if (StartTime > EndTime) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_StartEnd, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true); return false; } else if ((EndTime - StartTime).Days > 30) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_Over30days, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true); return false; } return true; } #endregion "Other Methods like Validated" } }