| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- using System.Linq;
- using System.Windows;
- using System.Windows.Input;
- using GalaSoft.MvvmLight;
- using System.Collections.Generic;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Data.Model.Delivery;
- using System;
- using Muchinfo.MTPClient.Delivery.Views;
- 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 Muchinfo.MTPClient.Infrastructure.Cache;
- namespace Muchinfo.MTPClient.Delivery.ViewModels
- {
- /// <summary>
- /// This class contains properties that a View can data bind to.
- /// <para>
- /// See http://www.galasoft.ch/mvvm
- /// </para>
- /// </summary>
- public class DeliveryWarehouseOrderViewModel : QueryPanelModelBase
- {
- #region "=========私有成员/Private Data Members"
- protected IDeliveryService _deliveryService;
- #endregion "Private Data Members"
- #region "=========构造函数/Constructor/Initialization"
- public DeliveryWarehouseOrderViewModel()
- {
- _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
- }
- #endregion "Constructor/Initialization"
- #region "=========接口重写/Interface implementation Or override"
- /// <summary>
- /// 初始化注册消息
- /// </summary>
- public override void RegisterMessage()
- {
- EndTime = DateTime.Now;
- StartTime = DateTime.Now.AddDays(-30);
- RefreshCommand.Execute(null);
- MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.OrderNotify);
- MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.OrderNotify, (e) =>
- {
- //接收通知时,防止时间设置错误,弹出错误提示
- EndTime = ApplicationParameter.ServerTimeNow;
- StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
- RefreshCommand.Execute(null);
- });
- }
- public override void UnRegisterMessage()
- {
- MessengerHelper.DefaultUnregister(this);
- }
- /// <summary>
- /// 查询交收申报单
- /// </summary>
- 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.QueryDeliveryWarehouseOrders(SearchWarehouseOrdersType.AccountId,string.Empty,accountid, StartTime.Date, EndTime.Date.AddHours(24), MarketOrderSuccess, QueryErrorCallback);
- }
- #endregion "Interface implementation Or override"
- #region "=========公共属性/Public Properties To Get/Set "
- #region 开始时间
- private DateTime startTime;
- /// <summary>
- /// 开始时间
- /// </summary>
- public DateTime StartTime
- {
- get { return startTime; }
- set { Set(() => StartTime, ref startTime, value); }
- }
- #endregion
- #region 结束时间
- private DateTime _endTime;
- /// <summary>
- /// 结束时间
- /// </summary>
- public DateTime EndTime
- {
- get { return _endTime; }
- set { Set(() => EndTime, ref _endTime, value); }
- }
- #endregion
- #region 所有ListSource
- private List<DeliveryWarehouse> _allAduitOrders;
- /// <summary>
- /// 所有ListSource
- /// </summary>
- public List<DeliveryWarehouse> AllAduitOrders
- {
- get { return _allAduitOrders; }
- set { Set(() => AllAduitOrders, ref _allAduitOrders, value); }
- }
- #endregion
- #region 当前选择单据转换
- private List<OutStoreReqDetailModel> _currentSelectedOutStore = null;
- /// <summary>
- /// 当前勾选的提货单据LIST
- /// </summary>
- public List<OutStoreReqDetailModel> CurrentSelectedOutStore
- {
- get
- {
- return _currentSelectedOutStore;
- }
- set
- {
- Set(() => CurrentSelectedOutStore, ref _currentSelectedOutStore, value);
- }
- }
- #endregion
- #region 选择当前行【实体】
- private DeliveryWarehouse _selectEntrustOrder;
- /// <summary>
- /// 选择 行
- /// </summary>
- public DeliveryWarehouse SelectEntrustOrder
- {
- get { return _selectEntrustOrder; }
- set { Set(() => SelectEntrustOrder, ref _selectEntrustOrder, value); }
- }
- #endregion
- #endregion "Public Properties To Get/Set "
- #region "=========公共命令/Public Commands"
- #region 交割申报下单命令Command
- private RelayCommand _deliveryCommand;
- /// <summary>
- /// Gets the DeliveryCommand.
- /// </summary>
- public RelayCommand DeliveryCommand
- {
- get
- {
- return _deliveryCommand
- ?? (_deliveryCommand = new RelayCommand(
- () =>
- {
- MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.DeliveryDeclare);
- }));
- }
- }
- #endregion
- #region 重置查询时间命令Command
- private RelayCommand _resetCommand;
- /// <summary>
- /// Gets the ResetCommand.
- /// </summary>
- public RelayCommand ResetCommand
- {
- get
- {
- return _resetCommand
- ?? (_resetCommand = new RelayCommand(
- () =>
- {
- EndTime = DateTime.Now;
- StartTime = DateTime.Now.AddDays(-30);
- }));
- }
- }
- #endregion
- #region 弹出窗口填写个人信息Command
- private RelayCommand _popUpRecieveInfoCommand;
- /// <summary>
- /// 弹出窗口填写个人信息Command
- /// </summary>
- public RelayCommand PopUpRecieveInfoCommand
- {
- get
- {
- return _popUpRecieveInfoCommand
- ?? (_popUpRecieveInfoCommand = new RelayCommand(
- () =>
- {
- MessengerHelper.DefaultSend(SelectEntrustOrder, MessengerTokens.WarehouseRecieveInfo);
- }));
- }
- }
- #endregion
- #region 提货命令Command
- public ICommand TakeGoodsCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- CurrentSelectedOutStore = new List<OutStoreReqDetailModel>();
- CurrentSelectedOutStore.Add(new OutStoreReqDetailModel() { WRId = (SelectEntrustOrder.WRID), StoreOutQty = (SelectEntrustOrder.Qty) });
- if (SelectEntrustOrder != null && CurrentSelectedOutStore.Count()>0)
- {
- var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToTakeGoods,
- Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips);
- if (boxResult == MessageBoxResult.Yes)
- {
- IsBusy = true;
- var newOrder = new OutStoreReqModel()
- {
- //申请
- OperateType = (int)TakaGoodsOperateType.Apply,
- OutStoreDetail = CurrentSelectedOutStore
- };
- 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;
- }
- try
- {
- _deliveryService.SubmitOutStoreReq(newOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack);
- }
- finally
- {
- }
- }
- }
- });
- }
- }
- #endregion
- #region 仓单详情Command
- private RelayCommand<DeliveryWarehouse> _popDetailCommand;
- /// <summary>
- /// 信息Command
- /// </summary>
- public RelayCommand<DeliveryWarehouse> PopDetailCommand
- {
- get
- {
- return _popDetailCommand
- ?? (_popDetailCommand = new RelayCommand<DeliveryWarehouse>(
- (wareHouse) =>
- {
- var wareHouseView = new WareHouseOrderDetailView()
- {
- Owner = Application.Current.MainWindow,
- WindowStartupLocation = WindowStartupLocation.CenterOwner,
- DataContext = wareHouse,
- ShowInTaskbar = false
- };
- wareHouseView.ShowDialog();
- }));
- }
- }
- #endregion
- #endregion "Public Commands"
- #region "=========私有方法/Private Methods"
- /// <summary>
- /// 提交提货成功返回
- /// </summary>
- /// <param name="order"></param>
- private void EntrurstSuccessCallBack(OutStoreRspModel order)
- {
- IsBusy = false;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- //OKButtonEnabled = true;
- //提货成功
- MessageBoxHelper.ShowSuccess(Client_Resource.Order_TakaDeliveryGoods_Success_Result,
- Client_Resource.UI2014_Tips);
-
- }));
- //刷新正常单
- MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
- }
- /// <summary>
- /// 提货委托失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void EntrurstErrorCallBack(ErrorEntity errorEntity)
- {
- IsBusy = false;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- //OKButtonEnabled = true;
- ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
-
- }));
- }
- /// <summary>
- /// 查询成功返回
- /// </summary>
- /// <param name="orders"></param>
- protected void MarketOrderSuccess(List<DeliveryWarehouse> orders)
- {
- UpdateItemSource(orders);
- IsBusy = false;
- }
- /// <summary>
- /// 查询失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- public override void QueryErrorCallback(ErrorEntity errorEntity)
- {
- IsBusy = false;
- var errorMsg = string.Format("{0}:{1}", errorEntity.RequestFunc, ErrorManager.FormatErrorMsg(errorEntity)); //错误信息显示到状态
- MessengerHelper.DefaultSend(errorMsg, MessengerTokens.ErrorMessage);
- }
- /// <summary>
- /// 更新数据源
- /// </summary>
- /// <param name="orders"></param>
- private void UpdateItemSource(List<DeliveryWarehouse> orders)
- {
- if (orders != null)
- {
- foreach (var item in orders)
- {
- #region 合约单位转换
- var goodsUnit = CacheManager.TradeGoodsUnit.FirstOrDefault((x) => x.UNITID == item.GoodsUnitId);
- if (goodsUnit != null)
- {
- item.GoodsUnitIdDisplay = goodsUnit.GOODSUNITNAME;
- }
- #endregion
- #region 是否可提货
- if (item.Status == eWRStatus.Normal && (item.Qty - item.FreezeQty - item.PayQty) > 0)
- {
- item.IsVisibility = Visibility.Visible;
- }
- #endregion
- try
- {
- var helper = new EncryptHelper();
- item.WarehouseAddress = item.AreaAddress +
- (string.IsNullOrWhiteSpace(item.DetailAddress)
- ? string.Empty
- : helper.AesDecrypt(item.DetailAddress));
- }
- catch (Exception)
- {
- }
- #region 存货货显本人
- item.WRSAVER = UserManager.CurrentTradeAccount.CustomerName;
- #endregion
- }
- AllAduitOrders = orders; //所有单据
- }
- }
- #endregion "Private Methods"
- #region "=========其它方法/Other Methods"
- /// <summary>
- /// 数据验证
- /// </summary>
- /// <returns></returns>
- 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"
-
-
- }
- }
|