| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using System.Windows;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Messaging;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.WPF.Controls.Windows;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- namespace Muchinfo.MTPClient.Account.ViewModels
- {
- public class CompleteOrderViewModel : RegisterMessageBase
- {
- private const int historyMaxDays = 90;
- private bool _radioNow = true;
- /// <summary>
- /// 当前查询
- /// </summary>
- public bool RadioNow
- {
- get { return _radioNow; }
- set
- {
- Set(() => RadioNow, ref _radioNow, value);
- if (_radioNow)
- {
- _radioCustom = false;
- QueryOrders();
- }
- }
- }
- private bool _radioCustom;
- /// <summary>
- /// 自定义是否选中
- /// </summary>
- public bool RadioCustom
- {
- get { return _radioCustom; }
- set
- {
- Set(() => RadioCustom, ref _radioCustom, value);
- EndDateTime = DateTime.Now.AddDays(-1); //查询历史为当前的前一天
- StartDateTime = EndDateTime.AddDays(1 - EndDateTime.Day); //结束当月的第一天
- if (_radioCustom)
- {
- _radioNow = false;
- QueryOrders();
- }
- }
- }
- /// 查询开始时间
- private DateTime _startDateTime;
- /// <summary>
- /// 查询开始时间
- /// </summary>
- public DateTime StartDateTime
- {
- get { return _startDateTime; }
- set
- {
- Set(() => StartDateTime, ref _startDateTime, new DateTime(value.Year, value.Month, value.Day));
- }
- }
- /// 查询结束时间
- private DateTime _endDateTime;
- /// <summary>
- /// 查询结束时间
- /// </summary>
- public DateTime EndDateTime
- {
- get { return _endDateTime; }
- set
- {
- Set(() => EndDateTime, ref _endDateTime, new DateTime(value.Year, value.Month, value.Day));
- }
- }
- private ObservableCollection<CompleteOrder> _completeOrders = new ObservableCollection<CompleteOrder>();
- /// <summary>
- /// 成交单
- /// </summary>
- public ObservableCollection<CompleteOrder> CompleteOrders
- {
- get { return _completeOrders; }
- set { Set(() => CompleteOrders, ref _completeOrders, value); }
- }
- /// <summary>
- /// 刷新
- /// </summary>
- public RelayCommand RefreshCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- QueryOrders();
- });
- }
- }
- /// <summary>
- /// 刷新账户信息
- /// </summary>
- public override void RefreshContent()
- {
- RefreshCommand.Execute(null);
- }
- public CompleteOrderViewModel()
- {
-
- }
- /// <summary>
- /// 单据注册消息
- /// </summary>
- public override void RegisterMessage()
- {
- //当选择时刷新
- var cacheData = UserManager.GetTradeCacheData(UserManager.CurrentTradeAccount.AccountId);
- if (!cacheData.CompleteOrderFlag)
- {
- RefreshCommand.Execute(null);
- }
- else
- {
- UpdateOrders();
- }
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- Messenger.Default.Unregister<TradeAccount>(this, MessengerTokens.OrderNotify);
- Messenger.Default.Register<TradeAccount>(this, MessengerTokens.OrderNotify, (e) =>
- {
- if (RadioNow)
- {
- UpdateOrders();
- }
- });
- }));
- }
- /// <summary>
- /// 更新当前单据
- /// </summary>
- private void UpdateOrders()
- {
- CompleteOrders = UserManager.GetCacheOrders<CompleteOrder>();
- }
- private void QueryOrders()
- {
- if (validate())
- {
- IsBusy = true;
- var queryCommons = new List<QueryCommonParam>();
- if (RadioNow) ////查询当前
- {
- queryCommons.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = UserManager.CurrentTradeAccount.AccountId + string.Empty });
- }
- else ////查询历史
- {
- //todo:查询历史参数
- queryCommons.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = UserManager.CurrentTradeAccount.AccountId + string.Empty });
- }
- _orderService.QueryComplateOrders(QueryStatement.QueryComplateOrder, queryCommons, QueryComplateOrderSuccessCallback, QueryErrorCallback);
- }
- }
- public void QueryComplateOrderSuccessCallback(List<CompleteOrder> completeOrders)
- {
- IsBusy = false;
- UpdateOrders();
- }
- /// <summary>
- /// 验证输入有效性
- /// </summary>
- /// <returns></returns>
- private bool validate()
- {
- if (RadioCustom)
- {
- if (StartDateTime.AddHours(-StartDateTime.Hour) > EndDateTime)
- {
- MessageBoxHelper.ShowInfo(
- Muchinfo.MTPClient.Resources.Muchinfo_Resource.Models_EndDateLessBegin,
- Muchinfo.MTPClient.Resources.Muchinfo_Resource.APP_Tips);
- return false;
- }
- else if ((EndDateTime - StartDateTime).TotalDays > historyMaxDays)
- {
- MessageBoxHelper.ShowInfo(
- string.Format(Muchinfo.MTPClient.Resources.Muchinfo_Resource.QueryDaysMustblow, historyMaxDays),
- Muchinfo.MTPClient.Resources.Muchinfo_Resource.APP_Tips);
- return false;
- }
- }
- return true;
- }
- public override void UnRegisterMessage()
- {
- Messenger.Default.Unregister<TradeAccount>(this, MessengerTokens.OrderNotify);
- base.UnRegisterMessage();
- }
- }
- }
|