using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//----------------------------------------------------------------
//Module Name: $safeprojectname$
//Purpose:
//CopyRight: Muchinfo
//History:
//----------------------------------------------------------------
//DateTime 2016/10/25 15:25:09
//Author
//Description Create
//----------------------------------------------------------------
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Ioc;
using Muchinfo.MTPClient.Data;
using Muchinfo.MTPClient.Data.Enums;
using Muchinfo.MTPClient.Data.Model.Account;
using Muchinfo.MTPClient.Infrastructure.MessageBox;
using Muchinfo.MTPClient.Infrastructure.Helpers;
using Muchinfo.MTPClient.Infrastructure.Utilities;
using Muchinfo.MTPClient.IService;
using Muchinfo.MTPClient.Resources;
namespace Muchinfo.MTPClient.Account.ViewModels
{
public class TaAmountLogViewModel : RegisterMessageBase
{
public bool IsQueryHistory
{
get;set;
}
/// 查询开始时间
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 _amountLogList;
public List AmountLogList
{
get { return _amountLogList; }
set { Set(() => AmountLogList, ref _amountLogList, value); }
}
public TaAmountLogViewModel()
{
_orderService = SimpleIoc.Default.GetInstance();
DateTime time = ApplicationParameter.ServerTimeNow;
//this.StartDateTime = time.AddDays(1 - time.Day);
this.StartDateTime = time.AddDays(-7);
this.EndDateTime = time;
MessengerHelper.DefaultUnregister(this, MessengerTokens.ShowTaAmountLogByCapitalAccount);
MessengerHelper.DefaultRegister(this, MessengerTokens.ShowTaAmountLogByCapitalAccount, (e) =>
{
//显示对应资金账户的数据信息
QueryAmountLog(e);
});
}
public RelayCommand QueryCommand
{
get
{
return new RelayCommand(() =>
{
if (Vailed())
{
QueryAmountLog(UserManager.CurrentTradeAccount.FundsAccountId, IsQueryHistory);
}
});
}
}
///
/// Queries the amount log.
///
/// The accountid.
/// if set to true [is history].
public void QueryAmountLog(ulong accountid, bool isHistory = false)
{
if (IsBusy) return;
IsBusy = true;
var queryCommons = new List();
queryCommons.Add(new QueryCommonParam()
{
ParamKey = "accountId",
ParamValue = accountid + string.Empty
});
if (isHistory)
{
queryCommons.Add(new QueryCommonParam()
{
ParamKey = "startDate",
ParamValue = StartDateTime.ToString("yyyy-MM-dd")
});
queryCommons.Add(new QueryCommonParam()
{
ParamKey = "endDate",
ParamValue = EndDateTime.ToString("yyyy-MM-dd HH:mm:ss")
});
}
queryCommons.Add(new QueryCommonParam() // 90926 2.资金流水记录中,仅保留出入金记录,其他类型的流水都不显示;
{
ParamKey = "operatetype",
ParamValue = "101,103",
});
_orderService.QueryTaAmountLog(isHistory, queryCommons, QueryAmountLogCallBack,
QueryErrorCallback);
}
private void QueryAmountLogCallBack(List amountQueryList)
{
IsBusy = false;
this.AmountLogList = amountQueryList;
}
public override 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()
{
RefreshContent();
}
public override void RefreshContent()
{
QueryCommand.Execute(null);
}
///
/// 数据验证
///
///
private bool Vailed()
{
if (StartDateTime > EndDateTime)
{
MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_StartEnd, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
return false;
}
else if ((EndDateTime - StartDateTime).Days > 30)
{
MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_Over30days, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
return false;
}
return true;
}
}
}