| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546 |
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using System.Windows;
- using System.Linq;
- using Muchinfo.MTPClient.Data.Model.Delivery;
- using Muchinfo.MTPClient.Infrastructure.MessageBox;
- using Muchinfo.MTPClient.Resources;
- using System.Collections.Generic;
- using System;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Data;
- using GalaSoft.MvvmLight.Ioc;
- namespace Muchinfo.MTPClient.Delivery.ViewModels
- {
- /// <summary>
- /// 仓单提货人信息
- /// <para>
- /// </para>
- /// </summary>
- public class RecieveInfoViewModel : ViewModelBase
- {
-
- #region "=========私有成员/Private Data Members"
- protected IDeliveryService _deliveryService;
- private Window _openWindow;
- private DeliveryWarehouse _itemWarehouse;
- #endregion "Private Data Members"
- #region "=========构造函数/Constructor/Initialization"
- public RecieveInfoViewModel(DeliveryWarehouse itemWarehouse)
- {
- this._itemWarehouse = itemWarehouse;
- GoodsName = itemWarehouse.DeliveryGoodsCodeNameDisplay;
- GoodsUnitIdDisplay = itemWarehouse.GoodsUnitIdDisplay;
- AvailableQty = itemWarehouse.Qty - itemWarehouse.FreezeQty - itemWarehouse.PayQty;
- //RecieveAddress = itemWarehouse.address;
- //RecievePerson = itemWarehouse.personname;
- //PhoneNum = itemWarehouse.telphone;
- _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
- CheckRecievePersonInfo();
- }
- #endregion "Constructor/Initialization"
- #region "=========接口重写/Interface implementation Or override"
- //To do interface implementation
- #endregion "Interface implementation Or override"
- #region "=========公共属性/Public Properties To Get/Set "
- #region 交易商品名称
- private string _goodsName = string.Empty;
- /// <summary>
- /// 交易商品名称
- /// </summary>
- public string GoodsName
- {
- get
- {
- return _goodsName;
- }
- set
- {
- Set(() => GoodsName, ref _goodsName, value);
- }
- }
- #endregion
- #region 可用数量
- private decimal _availableQty = decimal.Zero;
- /// <summary>
- /// Sets and gets the Qty property.
- /// </summary>
- public decimal AvailableQty
- {
- get
- {
- return _availableQty;
- }
- set
- {
- Set(() => AvailableQty, ref _availableQty, value);
- }
- }
- #endregion
- #region 商品单位
- private string _GoodsUnitIdDisplay = string.Empty;
- /// <summary>
- /// 商品单位
- /// </summary>
- public string GoodsUnitIdDisplay
- {
- get
- {
- return _GoodsUnitIdDisplay;
- }
- set
- {
- Set(() => GoodsUnitIdDisplay, ref _GoodsUnitIdDisplay, 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 bool _oKButtonEnabled = true;
- /// <summary>
- ///按钮是否可用
- /// </summary>
- public bool OKButtonEnabled
- {
- get
- {
- return _oKButtonEnabled;
- }
- set
- {
- Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
- }
- }
- #endregion
- #region 是否忙
- private bool _isBusy;
- /// <summary>
- /// 是否忙
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
- #endregion
- #region 收货人
- private string _RecievePerson = string.Empty;
- /// <summary>
- /// 收货人
- /// </summary>
- public string RecievePerson
- {
- get
- {
- return _RecievePerson;
- }
- set
- {
- Set(() => RecievePerson, ref _RecievePerson, value);
- }
- }
- #endregion
- #region 收货地址
- private string _RecieveAddress = string.Empty;
- /// <summary>
- /// 收货地址
- /// </summary>
- public string RecieveAddress
- {
- get
- {
- return _RecieveAddress;
- }
- set
- {
- Set(() => RecieveAddress, ref _RecieveAddress, value);
- }
- }
- #endregion
- #region 联系方式
- private string _PhoneNum = string.Empty;
- /// <summary>
- /// 联系方式
- /// </summary>
- public string PhoneNum
- {
- get
- {
- return _PhoneNum;
- }
- set
- {
- Set(() => PhoneNum, ref _PhoneNum, value);
- }
- }
- #endregion
- private string _IdCardNum;
- /// <summary>
- /// 證件號
- /// </summary>
- public string IdCardNum
- {
- get
- {
- return _IdCardNum;
- }
- set
- {
- Set(() => IdCardNum, ref _IdCardNum, value);
- }
- }
- private TakeGoodsWay _TakeGoodsWay;
- public TakeGoodsWay TakeGoodsWay
- {
- get
- {
- return _TakeGoodsWay;
- }
- set
- {
- Set(() => TakeGoodsWay, ref _TakeGoodsWay, value);
- }
- }
- #region 是否可以修改
- private bool _isEnableToWrite = false;
- /// <summary>
- /// 是否可以修改
- /// </summary>
- public bool IsEnableToWrite
- {
- get
- {
- return _isEnableToWrite;
- }
- set
- {
- Set(() => IsEnableToWrite, ref _isEnableToWrite, value);
- }
- }
- #endregion
- #region 当前账号提货人信息
- private DepositPersonalInfoRspModel _currentDepositPersonalInfo;
- /// <summary>
- /// 当前账号提货人信息
- /// </summary>
- public DepositPersonalInfoRspModel CurrentDepositPersonalInfo
- {
- get
- {
- return _currentDepositPersonalInfo;
- }
- set
- {
- Set(() => CurrentDepositPersonalInfo, ref _currentDepositPersonalInfo, value);
- }
- }
- #endregion
- #endregion "Public Properties To Get/Set "
- #region "=========公共命令/Public Commands"
- #region 取消选中Command
- /// <summary>
- /// 取消选中
- /// </summary>
- private RelayCommand unSelectCommand;
- public RelayCommand UnSelectCommand
- {
- get
- {
- return unSelectCommand ?? (unSelectCommand = new RelayCommand(
- () =>
- {
- //SettlementSelectedOutStore();
- }));
- }
- }
- #endregion
- #region 提交确定Command
- /// <summary>
- /// 提交确定
- /// </summary>
- public RelayCommand<Window> OKCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- CurrentSelectedOutStore = new List<OutStoreReqDetailModel>();
- CurrentSelectedOutStore.Add(new OutStoreReqDetailModel() { WRId = (_itemWarehouse.WRID), StoreOutQty = ((_itemWarehouse.Qty - _itemWarehouse.FreezeQty - _itemWarehouse.PayQty)) });
- OKButtonEnabled = false;
- string errorMsg = string.Empty;
- bool validateBool = Validated(ref errorMsg); ////内容验证
- if (validateBool)
- {
- IsBusy = true;
- _openWindow = dialog;
- var newOrder = new OutStoreReqModel()
- {
- //申请
- OperateType = (int)TakaGoodsOperateType.Apply,
- RecievePerson = RecievePerson,
- RecieveAddress = string.IsNullOrWhiteSpace(RecieveAddress) ? "--" : RecieveAddress.Trim(),
- PhoneNum = PhoneNum.Trim(),
- IdCardNum = IdCardNum.Trim(),
- TakeGoodsWay =TakeGoodsWay,
- 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
- {
- }
- }
- else
- {
- MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
- OKButtonEnabled = true;
- }
- });
- }
- }
- #endregion
- #region 窗口取消Command
- /// <summary>
- /// 窗口取消
- /// </summary>
- public RelayCommand<Window> CancelCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- dialog.DialogResult = false;
- });
- }
- }
- #endregion
- #endregion "Public Commands"
- #region "=========私有方法/Private Methods"
- /// <summary>
- /// 检查收货人信息
- /// </summary>
- private void CheckRecievePersonInfo()
- {
-
- if (_itemWarehouse != null)
- {
- RecieveAddress = _itemWarehouse.address;
- RecievePerson = _itemWarehouse.personname;
- PhoneNum = _itemWarehouse.telphone;
- IdCardNum = _itemWarehouse.IdCardNum;
- TakeGoodsWay = _itemWarehouse.TakeGoodsWay == TakeGoodsWay.Express?TakeGoodsWay.Express:TakeGoodsWay.Self;
- return;
- }
- IsEnableToWrite = false;
- if (string.IsNullOrEmpty(RecievePerson))
- {
- //读取登录人基本信息
- GetDepositPersonalInfo();
- IsEnableToWrite = true;
- }
- }
- /// <summary>
- /// 获取交割提货个人信息
- /// </summary>
- private void GetDepositPersonalInfo()
- {
- var accountid = UserManager.CurrentTradeAccount.AccountId;
- //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
- //{
- // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
- //}
- var ReqModel = new DepositPersonalInfoReqModel();
- ReqModel.accountId = (long)accountid;
- IsBusy = true;
- //交割提货个人信息查询
- _deliveryService.SearchDepositPersonalInfoReq(ReqModel, QueryDepositPersonalInfoSuccess, QueryDepositPersonalInfoCallBack);
- }
- /// <summary>
- /// 交割提货个人信息-成功返回
- /// </summary>
- /// <param name="orders"></param>
- protected void QueryDepositPersonalInfoSuccess(DepositPersonalInfoRspModel itemModel)
- {
- TakeGoodsWay = TakeGoodsWay.Self;
- if (itemModel != null)
- {
-
- CurrentDepositPersonalInfo = itemModel;
- if (CurrentDepositPersonalInfo != null)
- {
- RecieveAddress = CurrentDepositPersonalInfo.address;
- RecievePerson = CurrentDepositPersonalInfo.personName;
- PhoneNum = CurrentDepositPersonalInfo.telphone;
-
- }
- }
- IsBusy = false;
- }
- /// <summary>
- /// 获取交割提货个人信息失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void QueryDepositPersonalInfoCallBack(ErrorEntity errorEntity)
- {
- IsBusy = false;
- }
- /// <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);
- if (_openWindow != null)
- {
- _openWindow.Close();
- this.Cleanup();
- }
- }));
- //刷新正常单
- 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);
- if (_openWindow != null)
- {
- _openWindow.Close();
- this.Cleanup();
- }
- }));
- }
- #endregion "Private Methods"
- #region "=========其它方法/Other Methods"
- /// <summary>
- /// 数据验证
- /// </summary>
- /// <param name="msg"></param>
- /// <returns></returns>
- public bool Validated(ref string msg)
- {
- if (string.IsNullOrWhiteSpace(RecievePerson))
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecievePerson + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
- return false;
- }
- if (TakeGoodsWay == TakeGoodsWay.Express && string.IsNullOrWhiteSpace(RecieveAddress))
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecieveAddress + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
- return false;
- }
- if (string.IsNullOrWhiteSpace(PhoneNum))
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNum + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite;
- return false;
- }
- if (!string.IsNullOrWhiteSpace(PhoneNum) && !PhoneNum.StartsWith("1") || PhoneNum.Length != 11 || !ValidationHelper.IsMobile(PhoneNum))
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNumErrFormat;
- return false;
- }
- if (String.IsNullOrWhiteSpace(IdCardNum) || !ValidationHelper.IsIDcard(IdCardNum.Trim()))
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_IDCardNumErrFormat;
- return false;
- }
- return true;
- }
- #endregion "Other Methods"
-
- }
- }
|