using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/6/21 13:38:33 //Author //Description Create //---------------------------------------------------------------- using GalaSoft.MvvmLight.Messaging; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Data.Model.Sale; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.Infrastructure.Windows; using Muchinfo.MTPClient.IService; using System.Collections.Generic; using System.Linq; using System.Windows; namespace Muchinfo.MTPClient.Sale.ViewModels { /// /// 配号中签 /// public class DistributeBallotViewModel : QueryPanelModelBase { #region "=========私有成员/Private Data Members" protected ISaleService _saleService; #endregion "Private Data Members" #region "=========构造函数/Constructor/Initialization" public DistributeBallotViewModel() { this._saleService = SimpleIoc.Default.GetInstance(); } #endregion "Constructor/Initialization" #region "=========接口重写/Interface implementation Or override" public override void RegisterMessage() { RefreshCommand.Execute(null); MessengerHelper.DefaultUnregister(this, MessengerTokens.OrderNotify); MessengerHelper.DefaultRegister(this, MessengerTokens.OrderNotify, (e) => { RefreshCommand.Execute(null); }); } public override void UnRegisterMessage() { MessengerHelper.DefaultUnregister(this, MessengerTokens.OrderNotify); } public override void RefreshContent() { IsBusy = true; var queryCommonParams = new List(); var accountid = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) //{ // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} queryCommonParams.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = accountid + string.Empty }); queryCommonParams.Add(new QueryCommonParam() { ParamKey = "Status", ParamValue = (int)eCommonResult.COMMONRESULT_OK + string.Empty }); _saleService.QueryAccountDistributeBallot(queryCommonParams, MarketOrderSuccess, QueryErrorCallback); } #endregion "Interface implementation Or override" #region "=========公共属性/Public Properties To Get/Set " #region 数据源 private List _itemSource; public List ItemSource { get { return _itemSource; } set { Set(() => ItemSource, ref _itemSource, value); } } #endregion #region 当前选择配号中签 private DistributeBallot _currentDistributeBallotItem; /// /// 当前选择配号中签 /// public DistributeBallot CurrentDistributeBallotItem { get { return _currentDistributeBallotItem; } set { Set(() => CurrentDistributeBallotItem, ref _currentDistributeBallotItem, value); } } #endregion #region 是否显示查看详细 private Visibility _isVisibility_CheckSeeMoreDetail = Visibility.Collapsed; /// /// 是否显示查看详细 /// public Visibility IsVisibility_CheckSeeMoreDetail { get { return _isVisibility_CheckSeeMoreDetail; } set { Set(() => IsVisibility_CheckSeeMoreDetail, ref _isVisibility_CheckSeeMoreDetail, value); } } #endregion #endregion "Public Properties To Get/Set " #region "=========公共命令/Public Commands" #region 查看详情 private RelayCommand _seeMoreDetailCommand; /// /// 查看详情 /// public RelayCommand SeeMoreDetailCommand { get { return _seeMoreDetailCommand ?? (_seeMoreDetailCommand = new RelayCommand( p => { MessengerHelper.DefaultSend(CurrentDistributeBallotItem, MessengerTokens.DistributeBallotDetail); }, CheckSeeMoreDetail)); } } #endregion #endregion "Public Commands" #region "=========私有方法/Private Methods" protected void MarketOrderSuccess(List orders) { #region 重构数据源 //多个中签尾号,相同委托单号,只显示一个,中签尾号以逗号隔开 Dictionary dicList = new Dictionary(); List FilterDistributeBallotList = new List(); if (orders != null && orders.Any()) { string orderid = string.Empty; string winTailNo = string.Empty; foreach (var item in orders.OrderBy(x => x.OrderId)) { if (orderid == string.Empty) { orderid = item.OrderId.ToString(); winTailNo = item.WINTAILNO; dicList.Add(item.OrderId.ToString(), item); } else if (orderid == item.OrderId.ToString()) { item.WINTAILNO = winTailNo = item.WINTAILNO + "," + winTailNo; dicList.Remove(item.OrderId.ToString()); dicList.Add(item.OrderId.ToString(), item); } else if (orderid != item.OrderId.ToString()) { orderid = item.OrderId.ToString(); winTailNo = item.WINTAILNO; dicList.Add(item.OrderId.ToString(), item); } } } if (dicList != null && dicList.Any()) { foreach (var item in dicList) { FilterDistributeBallotList.Add(item.Value); } } #endregion ItemSource = FilterDistributeBallotList.OrderByDescending((item) => item.OrderTime).ToList(); IsBusy = false; } #endregion "Private Methods" #region "=========其它方法/Other Methods" /// /// 检查是否可查看详细 /// /// private bool CheckSeeMoreDetail(DistributeBallot order) { bool result = false; IsVisibility_CheckSeeMoreDetail = Visibility.Collapsed; if (this.CurrentDistributeBallotItem != null) { IsVisibility_CheckSeeMoreDetail = Visibility.Visible; result = true; } return result; } #endregion "Other Methods" } }