using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model.Delivery; using Muchinfo.MTPClient.Infrastructure.MessageBox; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using System.Windows; using System.Linq; using Muchinfo.MTPClient.Resources; using System; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Data; namespace Muchinfo.MTPClient.Delivery.ViewModels { /// /// 确认货票窗口 /// public class ComfirmGoodsTicketsViewModel : ViewModelBase { #region "=========私有成员/Private Data Members" private DryHoldDetail _itemModel; private IDeliveryService _deliveryService; private Window _openWindow; private ePerformanceType _currentePerformanceType; private bool _isCheckGoods = false; private bool _isCheckTickets = false; #endregion "Private Data Members" #region "=========构造函数/Constructor/Initialization" public ComfirmGoodsTicketsViewModel(DryHoldDetail itemOrder) { this._itemModel = itemOrder; _deliveryService = SimpleIoc.Default.GetInstance(); InitData(); } #endregion "Constructor/Initialization" #region "=========接口重写/Interface implementation Or override" //To do interface implementation #endregion "Interface implementation Or override" #region "=========公共属性/Public Properties To Get/Set " public int countNum { get; set; } public string pValue_hValue_countNum { get; set; } public eDeliveryStatus DeliveryStatus { get; set; } private bool _isBusy; /// /// 是否在忙 /// public bool IsBusy { get { return _isBusy; } set { Set(() => IsBusy, ref _isBusy, value); } } #endregion "Public Properties To Get/Set " #region "=========公共命令/Public Commands" #region 窗口取消Command /// /// 下单窗口取消 /// public RelayCommand CancelCommand { get { return new RelayCommand((dialog) => { dialog.DialogResult = false; }); } } #endregion #region 确认付款Command private RelayCommand _confirmPayCommand; /// /// Gets the ConfirmPayCommand. /// public RelayCommand ConfirmPayCommand { get { return _confirmPayCommand ?? (_confirmPayCommand = new RelayCommand( (dialog) => { #region 待审核处理 if (_itemModel != null) { var orderBuild = BuildEntrustOrder(); _openWindow = dialog; if (_isCheckGoods == false && _isCheckTickets == false) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DeliveryHolderViewModel_MustCheckOneGoodsOrTicket, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true); return; } ////勾选货 //if (_isCheckGoods== true) //{ // orderBuild.ConfirmType = (int)ePerformanceType.Confirm_Goods; // _currentePerformanceType = ePerformanceType.Confirm_Goods; //} ////勾选票 //if (_isCheckTickets == true) //{ // orderBuild.ConfirmType = (int)ePerformanceType.PERFORMANCETYPE_DELIVERY; // _currentePerformanceType = ePerformanceType.PERFORMANCETYPE_DELIVERY; //} ////同时勾选 //if (_isCheckGoods == true && _isCheckTickets == true) //{ // _currentePerformanceType = ePerformanceType.PERFORMANCETYPE_DELIVERY; //} long orderNumber = orderBuild.DeliveryId; var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToCommit, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips); if (boxResult == MessageBoxResult.Yes && orderBuild!=null) { IsBusy = true; _deliveryService.SubmitReceiveConfirmReq(orderBuild, EntrurstSuccessCallBack, EntrurstErrorCallBack); } } #endregion })); } } #endregion #region 选中GoodsCommand /// /// 选中 /// private RelayCommand selectGoodsCommand; public RelayCommand SelectGoodsCommand { get { return selectGoodsCommand ?? (selectGoodsCommand = new RelayCommand( () => { _isCheckGoods = true; })); } } #endregion #region 取消选中GoodsCommand /// /// 取消选中 /// private RelayCommand unSelectGoodsCommand; public RelayCommand UnSelectGoodsCommand { get { return unSelectGoodsCommand ?? (unSelectGoodsCommand = new RelayCommand( () => { _isCheckGoods = false; })); } } #endregion #region 选中TicketCommand /// /// 选中 /// private RelayCommand selectTicketCommand; public RelayCommand SelectTicketCommand { get { return selectTicketCommand ?? (selectTicketCommand = new RelayCommand( () => { _isCheckTickets = true; })); } } #endregion #region 取消选中TicketCommand /// /// 取消选中 /// private RelayCommand unSelectTicketCommand; public RelayCommand UnSelectTicketCommand { get { return unSelectTicketCommand ?? (unSelectTicketCommand = new RelayCommand( () => { _isCheckTickets = false; })); } } #endregion #endregion "Public Commands" #region "=========私有方法/Private Methods" /// /// 数据初始化 /// private void InitData() { if (_itemModel != null) { countNum = this._itemModel.countNum; pValue_hValue_countNum = this._itemModel.pValue_hValue_countNum; DeliveryStatus = this._itemModel.DeliveryStatus; } } #region 创建下单委托对象 /// /// 创建下单委托对象 /// /// 下单委托对象 private ReceiveConfirmReqModel BuildEntrustOrder() { if (_itemModel != null) { var newOrder = new ReceiveConfirmReqModel() { DeliveryId = _itemModel.DeliveryId, //ConfirmType=(int)ePerformanceType.Confirm_Goods, GoodsId = (uint)_itemModel.DeliveryGoodsId, OperatorID = UserManager.CurrentTradeAccount.AccountId, AccountType = UserManager.CurrentTradeAccount.AccountType, //BuildType = eBuildType.BUILDTYPE_CANCEL, EntrurstTime = ApplicationParameter.ServerTimeNow, //OrderQty = SelectEntrustOrder.DeliveryQty, ValidType = ExpirationType.AlwaysValid, //RelateOrderID = SelectEntrustOrder.DeliveryOrderId, AccountId = UserManager.CurrentTradeAccount.AccountId, }; //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() && // UserManager.CurrentTradeAccount.FundsAccounts[0] != null) //{ // newOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} //else //{ // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId; //} return newOrder; } return null; } #endregion /// 确认收货、票成功返回 /// /// private void EntrurstSuccessCallBack(ReceiveConfirmRspModel order) { IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { // var orderBuild = BuildEntrustOrder(); if (_currentePerformanceType == ePerformanceType.PERFORMANCETYPE_DELIVERY) { MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_ReceiveConfirmGoods_Success_Result, Client_Resource.Models_Tips); } else if (_currentePerformanceType == ePerformanceType.PERFORMANCETYPE_DELIVERY) { MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_ReceiveConfirmTicket_Success_Result, Client_Resource.Models_Tips); } else if (_currentePerformanceType == ePerformanceType.PERFORMANCETYPE_DELIVERY) { MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_ReceiveConfirmTicketAndGoods_Success_Result1, Client_Resource.Models_Tips); } if (_openWindow != null) { _openWindow.Close(); this.Cleanup(); } })); 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; if (_openWindow != null) { _openWindow.Close(); this.Cleanup(); } })); } #endregion "Private Methods" #region "=========其它方法/Other Methods" //To to something #endregion "Other Methods" } }