using System.Windows;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Ioc;
using Muchinfo.MTPClient.Bank.Views;
using Muchinfo.MTPClient.Data;
using Muchinfo.MTPClient.Data.Enums;
using Muchinfo.MTPClient.Data.Model.Bank;
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.WPF.Controls.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Muchinfo.MTPClient.Bank.ViewModels
{
public class AmountQueryViewModel : QueryPanelModelBase
{
private bool _isBusy;
///
/// 是否忙,显示等待控件
///
//public bool IsBusy
//{
// get { return _isBusy; }
// set { Set(() => IsBusy, ref _isBusy, value); }
//}
/// 查询开始时间
private DateTime _startDateTime;
///
/// 查询开始时间
///
public DateTime StartDateTime
{
get { return _startDateTime; }
set
{
Set(() => StartDateTime, ref _startDateTime, new DateTime(value.Year, value.Month, value.Day, 0, 0, 0));
}
}
/// 查询结束时间
private DateTime _endDateTime;
///
/// 查询结束时间
///
public DateTime EndDateTime
{
get { return _endDateTime; }
set
{
Set(() => EndDateTime, ref _endDateTime, new DateTime(value.Year, value.Month, value.Day, 23, 59, 59));
}
}
private List _amountQueryList;
public List AmountQueryList
{
get { return _amountQueryList; }
set { Set(() => AmountQueryList, ref _amountQueryList, value); }
}
private IBankService _bankService;
public AmountQueryViewModel()
{
_bankService = SimpleIoc.Default.GetInstance();
DateTime time = ApplicationParameter.ServerTimeNow;
//this.StartDateTime = time.AddDays(1 - time.Day);
this.StartDateTime = time.AddDays(-7);
this.EndDateTime = time;
SelectBankOutIn();
}
public RelayCommand QuetyCommand
{
get
{
return new RelayCommand(() =>
{
if (this.EndDateTime < this.StartDateTime)
{
MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Models_EndDateLessBegin, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
return;
}
int number = (StartDateTime.Year - EndDateTime.Year) * 12 + StartDateTime.Month - EndDateTime.Month;
if (number < -3)
{
MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Models_CanNotGreatThan3Month, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
return;
}
SelectBankOutIn();
});
}
}
public RelayCommand OutCommand
{
get
{
return new RelayCommand(() =>
{
var amount = new AmountManagerView(FundsApplyType.Withdraw){Owner = System.Windows.Application.Current.MainWindow,WindowStartupLocation = WindowStartupLocation.CenterOwner};
amount.ShowDialog();
});
}
}
public RelayCommand InCommand
{
get
{
return new RelayCommand(() =>
{
var amount = new AmountManagerView(FundsApplyType.Deposit) { Owner = System.Windows.Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner };
amount.ShowDialog();
});
}
}
public void SelectBankOutIn()
{
var queryCommons = new List();
var accountid = UserManager.CurrentTradeAccount.AccountId;
//if (UserManager.CurrentTradeAccount.FundsAccounts!=null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
//{
// accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
//}
queryCommons.Add(new QueryCommonParam()
{
ParamKey = "accountId",
ParamValue = accountid + string.Empty
});
queryCommons.Add(new QueryCommonParam()
{
ParamKey = "beginDate",
ParamValue = StartDateTime.ToString("yyyy-MM-dd")
});
queryCommons.Add(new QueryCommonParam()
{
ParamKey = "endDate",
ParamValue = EndDateTime.Date.AddHours(24).ToString("yyyy-MM-dd HH:mm:ss")
});
//
IsBusy = true;
//this.AmountQueryList = _bankService.QueryBankOutIn(this.StartDateTime, this.EndDateTime, UserManager.CurrentTradeAccount);
_bankService.QueryBankOutIn(QueryStatement.SearchClientMoneyOutIn, queryCommons, QueryBankOutInCallBack,
QueryErrorCallback);
}
private void QueryBankOutInCallBack(List amountQueryList)
{
IsBusy = false;
this.AmountQueryList = amountQueryList.OrderByDescending((item)=>item.CreateTime).ToList();
}
public virtual void QueryErrorCallback(ErrorEntity errorEntity)
{
IsBusy = false;
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
ErrorManager.ShowReturnError(errorEntity, Client_Resource.APP_Tips, false);
}));
}
//注册消息
public override void RegisterMessage()
{
SelectBankOutIn();
}
public override void RefreshContent()
{
QuetyCommand.Execute(null);
}
}
}