using System; using System.Collections.Generic; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/8/5 14:38:50 //Author //Description Create //---------------------------------------------------------------- using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Data.Model.Delivery; 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 System.Windows; using Muchinfo.MTPClient.Resources; namespace Muchinfo.MTPClient.Delivery.ViewModels { /// /// 交割单查询ViewModel /// public class DeliveryHolderViewModel : QueryPanelModelBase { #region "私有字段/Private Data Members" protected IDeliveryService _deliveryService; private ISystemService _systemService; private ePerformanceType _currentePerformanceType; private MTPSystemConfig _systemConfig; ////是否需要确认货票 当前配置0时表示不启动自支确认货,1表示启动自动确认货 private const int keyId = 304; //// 是否需要确认货票配置ID private Window _openWindow; #endregion "Private Data Members" #region "构造函数/Constructor/Initialization" public DeliveryHolderViewModel() { _deliveryService = SimpleIoc.Default.GetInstance(); _currentePerformanceType = ePerformanceType.PERFORMANCETYPE_DELIVERY; _systemService = SimpleIoc.Default.GetInstance(); } #endregion "Constructor/Initialization" #region "接口重写/Interface implementation Or override" /// /// 初始化注册消息 /// public override void RegisterMessage() { EndTime = ApplicationParameter.ServerTimeNow; StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30); RefreshCommand.Execute(null); //当选择时刷新 MessengerHelper.DefaultUnregister(this, MessengerTokens.UpdateDeliveryHolderOrder); MessengerHelper.DefaultRegister(this, MessengerTokens.UpdateDeliveryHolderOrder, (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 queryList = new List(); queryList.Add(new QueryCommonParam() { ParamKey = "userid", ParamValue = UserManager.CurrentTradeAccount.CustomerId + string.Empty }); queryList.Add(new QueryCommonParam() { ParamKey = "starttime", ParamValue = StartTime.ToString() + string.Empty }); queryList.Add(new QueryCommonParam() { ParamKey = "endtime", ParamValue = EndTime.ToString() + string.Empty }); _deliveryService.QueryDryOrdersByCapitalAccount(QueryStatement.QueryDeliveryHolder, queryList, QuerySuccessCallBackNew, QueryErrorCallbackNew); } private void QuerySuccessCallBackNew(List orders) { ItemOrders = orders; IsBusy = false; } private void QueryErrorCallbackNew(ErrorEntity error) { IsBusy = false; } /// /// 是否显示确认货 /// public bool IsComfrimVsb { get { if (_systemConfig == null) { return true; } return !"1".Equals(_systemConfig.systemconfigvalue); } } /// /// 成功返回 /// /// protected void MarketOrderSuccess(List orders) { //UserManager.CurrentTradeAccount.AccountId if (orders != null && orders.Count > 0) { ItemOrders = orders.OrderByDescending(x => x.DeliveryTime).ToList(); } IsBusy = false; } /// /// 是否确认货票参数查询 /// /// private void QuerySystemConfigSuccess(List configs) { IsBusy = false; if (configs != null && configs.Any()) { _systemConfig = configs[0]; RaisePropertyChanged(() => IsComfrimVsb); } } /// /// 失败返回 /// /// 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(); } #endregion "Interface implementation Or override" #region "Public Properties To Get/Set " #region 当前履约类型 private ePerformanceType _currentConfirmType; public ePerformanceType CurrentConfirmType { get { return _currentConfirmType; } set { _currentConfirmType = value; } } #endregion #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 _itemOrders; /// /// 未审核ListSource /// public List ItemOrders { get { return _itemOrders; } set { Set(() => ItemOrders, ref _itemOrders, value); } } #endregion #region 选择当前行【实体】 private DryHoldDetail _selectEntrustOrder; /// /// 选择 行 /// public DryHoldDetail SelectEntrustOrder { get { return _selectEntrustOrder; } set { Set(() => SelectEntrustOrder, ref _selectEntrustOrder, value); } } #endregion #endregion "Public Properties To Get/Set " #region "Public Commands" #region 重置查询时间命令Command private RelayCommand _resetCommand; /// /// Gets the ResetCommand. /// public RelayCommand ResetCommand { get { return _resetCommand ?? (_resetCommand = new RelayCommand( () => { EndTime = ApplicationParameter.ServerTimeNow; StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30); })); } } #endregion #region 选中GoodsCommand /// /// 选中 /// private RelayCommand selectGoodsCommand; public RelayCommand SelectGoodsCommand { get { return selectGoodsCommand ?? (selectGoodsCommand = new RelayCommand( () => { //CurrentConfirmType = ePerformanceType.Confirm_Goods; //var sourceList = ItemOrders.ToList().FindAll(p => p.IsGoodsSelected == true); //for (int i = 0; i < sourceList.Count(); i++) //{ // //_currentSelectedOrderMatchDetail.Add(new OrderMatchDetailModel() { WRId = (sourceList[i].WRID), DeliveryQty = (sourceList[i].Qty) }); //} })); } } #endregion #region 取消选中GoodsCommand /// /// 取消选中 /// private RelayCommand unSelectGoodsCommand; public RelayCommand UnSelectGoodsCommand { get { return unSelectGoodsCommand ?? (unSelectGoodsCommand = new RelayCommand( () => { CurrentConfirmType = ePerformanceType.PERFORMANCETYPE_DELIVERY; })); } } #endregion #region 选中TicketCommand /// /// 选中 /// private RelayCommand selectTicketCommand; public RelayCommand SelectTicketCommand { get { return selectTicketCommand ?? (selectTicketCommand = new RelayCommand( () => { CurrentConfirmType = ePerformanceType.PERFORMANCETYPE_DELIVERY; })); } } #endregion #region 取消选中TicketCommand /// /// 取消选中 /// private RelayCommand unSelectTicketCommand; public RelayCommand UnSelectTicketCommand { get { return unSelectTicketCommand ?? (unSelectTicketCommand = new RelayCommand( () => { CurrentConfirmType = ePerformanceType.PERFORMANCETYPE_WRTRADE; })); } } #endregion #region 确认付款Command private RelayCommand _confirmPayCommand; /// /// Gets the ConfirmPayCommand. /// public RelayCommand ConfirmPayCommand { get { return _confirmPayCommand ?? (_confirmPayCommand = new RelayCommand( () => { #region 待审核处理 if (SelectEntrustOrder != null) { var orderBuild = BuildEntrustOrder(); if (ItemOrders.ToList().Exists(p => p.DeliveryId == orderBuild.DeliveryId && p.IsGoodsSelected == false && p.IsTicketSelected == false)) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DeliveryHolderViewModel_MustCheckOneGoodsOrTicket, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true); return; } ////勾选货 //if (ItemOrders.ToList().Exists(p =>p.DeliveryId == orderBuild.DeliveryId && p.IsGoodsSelected == true)) //{ // orderBuild.ConfirmType = (int)ePerformanceType.Confirm_Goods; // _currentePerformanceType = ePerformanceType.Confirm_Goods; //} ////勾选票 //if (ItemOrders.ToList().Exists(p => p.DeliveryId == orderBuild.DeliveryId && p.IsTicketSelected == true)) //{ // orderBuild.ConfirmType = (int)ePerformanceType.Confirm_Ticket; // _currentePerformanceType = ePerformanceType.Confirm_Ticket; //} ////同时勾选 //if (ItemOrders.ToList().Exists(p => p.DeliveryId == orderBuild.DeliveryId && p.IsTicketSelected == true) && ItemOrders.ToList().Exists(p => p.DeliveryId == orderBuild.DeliveryId && p.IsGoodsSelected == true)) //{ // _currentePerformanceType = ePerformanceType.Confirm_Other; //} long orderNumber = orderBuild.DeliveryId; //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_MakesureToCommit, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips); if (boxResult == MessageBoxResult.Yes) { IsBusy = true; _deliveryService.SubmitReceiveConfirmReq(orderBuild, EntrurstSuccessCallBack, EntrurstErrorCallBack); } } #endregion })); } } #endregion #region 查看详情 private RelayCommand _seeMoreDetailCommand; /// /// Gets the SeeMoreDetailCommand. /// public RelayCommand SeeMoreDetailCommand { get { return _seeMoreDetailCommand ?? (_seeMoreDetailCommand = new RelayCommand( p => { MessengerHelper.DefaultSend(SelectEntrustOrder, MessengerTokens.DeliveryOrderDetail); })); } } #endregion #region 确认货票 private RelayCommand _comfirmGoodsTicketsCommand; /// /// Gets the ComfirmGoodsTicketsCommand. /// public RelayCommand ComfirmGoodsTicketsCommand { get { return _comfirmGoodsTicketsCommand ?? (_comfirmGoodsTicketsCommand = new RelayCommand( p => { if (p != null) { var orderBuild = BuildEntrustOrder(); orderBuild.DeliveryId = p.DeliveryId; orderBuild.PlanDetailID = p.PlanDetailId; var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToCommit, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips); if (boxResult == MessageBoxResult.Yes) { IsBusy = true; _deliveryService.SubmitReceiveConfirmReq(orderBuild, ComfirmSuccessCallBack, EntrurstErrorCallBack); } } //MessengerHelper.DefaultSend(SelectEntrustOrder, MessengerTokens.ComfirmGoodsTickets); })); } } #endregion #region 申诉命令 private RelayCommand _appealCommand; /// /// 申诉命令 /// public RelayCommand AppealCommand { get { return _appealCommand ?? (_appealCommand = new RelayCommand( p => { //var orderBuild = BuildEntrustOrder(); //orderBuild.ConfirmType = (int)ePerformanceType.Appeal; //var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureToAppeal, // Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips); //if (boxResult == MessageBoxResult.Yes && orderBuild != null) //{ // IsBusy = true; // _currentePerformanceType = ePerformanceType.Appeal; // _deliveryService.SubmitReceiveConfirmReq(orderBuild, EntrurstSuccessCallBack, EntrurstErrorCallBack); //} })); } } #endregion #endregion "Public Commands" #region "Private Methods" /// 确认收货、票成功返回 /// /// private void ComfirmSuccessCallBack(ReceiveConfirmRspModel order) { IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { // var orderBuild = BuildEntrustOrder(); MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_RecConfirm_Success_Result, Client_Resource.Models_Tips); })); RefreshCommand.Execute(null); // MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken); } /// 确认收货、票成功返回 /// /// private void EntrurstSuccessCallBack(ReceiveConfirmRspModel order) { IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { // var orderBuild = BuildEntrustOrder(); //if (_currentePerformanceType == ePerformanceType.Confirm_Goods ) //{ // MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_ReceiveConfirmGoods_Success_Result, // Client_Resource.Models_Tips); //} //else if (_currentePerformanceType == ePerformanceType.Appeal) //{ // MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_Appeal_Success_Result, // Client_Resource.Models_Tips); //} //else if (_currentePerformanceType == ePerformanceType.Confirm_Ticket) //{ // MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_ReceiveConfirmTicket_Success_Result, // Client_Resource.Models_Tips); //} //else if (_currentePerformanceType == ePerformanceType.Confirm_Other) //{ // MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Order_ReceiveConfirmTicketAndGoods_Success_Result1, // Client_Resource.Models_Tips); //} })); 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 ReceiveConfirmReqModel BuildEntrustOrder() { var newOrder = new ReceiveConfirmReqModel() { DeliveryId = SelectEntrustOrder.DeliveryId, //ConfirmType=(int)ePerformanceType.Confirm_Goods, GoodsId = (uint)SelectEntrustOrder.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; } #endregion /// /// 数据验证 /// /// 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 "Private Methods" } }