using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.MessageBox; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.Infrastructure.Windows; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.Resources; using System; using System.Collections.Generic; using System.Windows; using System.Linq; using Muchinfo.MTPClient.Data.Model.Delivery; using GalaSoft.MvvmLight.Command; using System.Windows.Input; namespace Muchinfo.MTPClient.Delivery.ViewModels { /// /// 提货查询 /// public class TakaDeliveryGoodsQueryViewModel : QueryPanelModelBase { #region "=========私有成员/Private Data Members" protected IDeliveryService _deliveryService; #endregion "Private Data Members" #region "=========构造函数/Constructor/Initialization" public TakaDeliveryGoodsQueryViewModel() { _deliveryService = SimpleIoc.Default.GetInstance(); } #endregion "Constructor/Initialization" #region "=========接口重写/Interface implementation Or override" /// /// 初始化注册消息 /// public override void RegisterMessage() { EndTime = DateTime.Now; StartTime = DateTime.Now.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); }); } 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.QueryTakaDeliveryGoodsOrders(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 #region 所有提货仓单ListSource private List _allTakaDeliveryGoodsOrderList; /// /// 所有提货仓单ListSource /// public List AllTakaDeliveryGoodsOrderList { get { return _allTakaDeliveryGoodsOrderList; } set { Set(() => AllTakaDeliveryGoodsOrderList, ref _allTakaDeliveryGoodsOrderList, value); } } #endregion #region 选择当前行【实体】 private TakaDeliveryGoodsQueryModel _selectEntrustOrder; /// /// 选择 行 /// public TakaDeliveryGoodsQueryModel SelectEntrustOrder { get { return _selectEntrustOrder; } set { Set(() => SelectEntrustOrder, ref _selectEntrustOrder, value); } } #endregion #endregion "Public Properties To Get/Set " #region "=========公共命令/Public Commands" #region 提货申请命令Command private RelayCommand _takeDeliveryGoodsCommand; /// /// Gets the TakeDeliveryGoodsCommand. /// public RelayCommand TakeDeliveryGoodsCommand { get { return _takeDeliveryGoodsCommand ?? (_takeDeliveryGoodsCommand = new RelayCommand( () => { MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.TakeDeliveryGoodsApply); })); } } #endregion #region 重置查询时间命令Command private RelayCommand _resetCommand; /// /// Gets the ResetCommand. /// public RelayCommand ResetCommand { get { return _resetCommand ?? (_resetCommand = new RelayCommand( () => { EndTime = DateTime.Now; StartTime = DateTime.Now.AddDays(-30); })); } } #endregion #region 撤销命令Command public ICommand CancelCommand { get { return new RelayCommand(() => { PostCancelOrder(); }); } } #endregion /// /// 撤销命令 /// public RelayCommand CancelOrderCammand { get { return new RelayCommand(() => { if (SelectEntrustOrder == null) return; PostCancelOrder(); }, () => CanCancelOrderDetial()); } } /// /// 是否可撤单 /// /// public bool CanCancelOrderDetial() { var result = false; if (SelectEntrustOrder == null || SelectEntrustOrder.AuditStatus != eAuditStatus.AUDITSTATUS_CHECKING) { result = false; } else { result = true; } return result; } #region 查看详情Command private RelayCommand _seeMoreDetailCommand; /// /// 查看详情Command /// public RelayCommand SeeMoreDetailCommand { get { return _seeMoreDetailCommand ?? (_seeMoreDetailCommand = new RelayCommand( p => { MessengerHelper.DefaultSend(SelectEntrustOrder, MessengerTokens.TakeGoodsMoreDetail); })); } } #endregion #endregion "Public Commands" #region "=========私有方法/Private Methods" /// /// 撤销操作事务 /// private void PostCancelOrder() { if (SelectEntrustOrder != null) { var orderBuild = BuildEntrustOrder(); long orderNumber = orderBuild.StoreOutId; //var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureCancel + orderNumber + Muchinfo.MTPClient.Resources.Client_Resource.Models_Bill, // Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips); var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToCancel, Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips); if (boxResult == MessageBoxResult.Yes) { IsBusy = true; _deliveryService.SubmitOutStoreReq(orderBuild, EntrurstSuccessCallBack, EntrurstErrorCallBack); } } } /// 撤销成功返回 /// /// private void EntrurstSuccessCallBack(OutStoreRspModel order) { IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Account_CancelSuccess, Client_Resource.Cancel_MessageBox_Title); })); MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken); } /// /// 撤销失败返回 /// /// private void EntrurstErrorCallBack(ErrorEntity errorEntity) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true); IsBusy = false; })); } #region 创建下单委托对象 /// /// 创建下单委托对象 /// /// 下单委托对象 private OutStoreReqModel BuildEntrustOrder() { var newOrder = new OutStoreReqModel() { //申请 OperateType = (int)TakaGoodsOperateType.Canceled, PhoneNum="1", RecieveAddress="address", RecievePerson = "Person", StoreOutId=SelectEntrustOrder.StoreOutId }; if (UserManager.CurrentTradeAccount.FundsAccounts.Any() && UserManager.CurrentTradeAccount.FundsAccounts[0] != null) { newOrder.AccountID = newOrder.OperatorID = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; } else { newOrder.AccountID = newOrder.OperatorID = UserManager.CurrentTradeAccount.AccountId; } return newOrder; } #endregion /// /// 查询成功返回 /// /// protected void MarketOrderSuccess(List orders) { UpdateItemSource(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(); } /// /// 更新数据源-绑定数据源 /// /// private void UpdateItemSource(List orders) { if (orders != null) { AllTakaDeliveryGoodsOrderList = orders;//所有单据 } } #endregion "Private Methods" #region "=========其它方法/Other Methods" /// /// 数据验证 /// /// 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" } }