using System; using System.Collections.Generic; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.PC.Common.Extensions; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Infrastructure.Utilities; using System.Collections.ObjectModel; using Muchinfo.MTPClient.Infrastructure.Helpers; namespace Muchinfo.MTPClient.Account.ViewModels { public class OperateLogViewModel : RegisterMessageBase { ObservableCollection _logs = new ObservableCollection(); public ObservableCollection Logs { get { return _logs; } set { Set(() => Logs, ref _logs, value); } } #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); } } #endregion public OperateLogViewModel() { } public override void RegisterMessage() { EndTime = ApplicationParameter.ServerTimeNow; StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30); RefreshCommand.Execute(null); MessengerHelper.DefaultUnregister(this, MessengerTokens.OrderNotify); MessengerHelper.DefaultRegister(this, MessengerTokens.OrderNotify, (e) => { //接收通知时,防止时间设置错误,弹出错误提示 EndTime = ApplicationParameter.ServerTimeNow; StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30); RefreshCommand.Execute(null); }); } #region 重置查询时间命令Command private RelayCommand _resetCommand; /// /// Gets the ResetCommand. /// public RelayCommand ResetCommand { get { return _resetCommand ?? (_resetCommand = new RelayCommand( () => { EndTime = ApplicationParameter.ServerTimeNow; StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30); })); } } #endregion /// /// 查询持仓成功回调 /// /// 持仓内容 private void QueryHoldOrderCallBack(List userLogs) { ////获取当前的持仓 IsBusy = false; Logs = new ObservableCollection(userLogs); } /// /// /// /// public override void QueryErrorCallback(ErrorEntity errorEntity) { IsBusy = false; //var errorMsg = string.Format("{0}:{1}", errorEntity.RequestFunc, ErrorManager.FormatErrorMsg(errorEntity)); //错误信息显示到状态 //MessengerHelper.DefaultSend(errorMsg, MessengerTokens.ErrorMessage); // base.QueryErrorCallback(); } public override void RefreshContent() { IsBusy = true; var queryCommons = new List(); queryCommons.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = UserManager.CurrentTradeAccount.AccountId + string.Empty }); queryCommons.Add(new QueryCommonParam() { ParamKey = "startDate", ParamValue = StartTime.ToString("yyyy-MM-dd HH:mm:ss") }); queryCommons.Add(new QueryCommonParam() { ParamKey = "endDate", ParamValue = EndTime.ToString("yyyy-MM-dd HH:mm:ss") }); _orderService.QueryUserLogs(QueryStatement.SearchSysLog, queryCommons, QueryHoldOrderCallBack, QueryErrorCallback); } } }