using System; using System.Collections.Generic; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/12/27 20:05:44 //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.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; namespace Muchinfo.MTPClient.Delivery.ViewModels { public class DeliveryCompleteViewModel : QueryPanelModelBase { private IDeliveryService _deliveryService; public DeliveryCompleteViewModel() { _deliveryService = SimpleIoc.Default.GetInstance(); } #region "接口重写/Interface implementation Or override" /// /// 初始化注册消息 /// public override void RegisterMessage() { EndTime = ApplicationParameter.ServerTimeNow; StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30); RefreshCommand.Execute(null); } public override void UnRegisterMessage() { MessengerHelper.DefaultUnregister(this); } /// /// 查询交收申报单 /// public override void RefreshContent() { if (!Vailed()) { return; } IsBusy = true; var accountid = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) //{ // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} _deliveryService.QueryDeliveryComplete(accountid, StartTime.Date, EndTime.Date.AddHours(24), MarketOrderSuccess, QueryErrorCallback); } #endregion "Interface implementation Or override" #region "Public Properties To Get/Set " #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 private List _deliveryCompleteModels; public List DeliveryCompleteModels { get { return _deliveryCompleteModels; } set { Set(() => DeliveryCompleteModels, ref _deliveryCompleteModels, value); } } #endregion "Public Properties To Get/Set " #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 #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" /// /// 查询成功返回 /// /// protected void MarketOrderSuccess(List orders) { DeliveryCompleteModels = orders; IsBusy = false; } /// /// 查询失败返回 /// /// 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(); } } }