using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//----------------------------------------------------------------
//Module Name: $safeprojectname$
//Purpose:
//CopyRight: Muchinfo
//History:
//----------------------------------------------------------------
//DateTime 2016/8/5 9:23:51
//Author
//Description Create
//----------------------------------------------------------------
using System.Windows;
using System.Windows.Input;
using GalaSoft.MvvmLight;
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 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;
namespace Muchinfo.MTPClient.Delivery.ViewModels
{
///
/// 交割申报查询ViewModel
///
public class DeliveryEntructViewModel : QueryPanelModelBase//QueryPanelPageModelBase
{
#region "私有字段/Private Data Members"
protected IDeliveryService _deliveryService;
#endregion "Private Data Members"
#region "构造函数/Constructor/Initialization"
public DeliveryEntructViewModel()
{
_deliveryService = SimpleIoc.Default.GetInstance();
}
#endregion "Constructor/Initialization"
#region "接口重写/Interface implementation Or override"
///
/// 初始化注册消息
/// RefreshContent
public override void RegisterMessage()
{
EndTime = ApplicationParameter.ServerTimeNow;
StartTime = ApplicationParameter.ServerTimeNow.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 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.QueryDeliveryDeclareByCapitalAccount(QueryStatement.QueryDeliverEntrustOrder, queryList, QuerySuccessCallBackNew, QueryErrorCallbackNew);
}
private void QuerySuccessCallBackNew(List orders)
{
UpdateItemSource(orders);
IsBusy = false;
}
private void QueryErrorCallbackNew(ErrorEntity error)
{
IsBusy = false;
}
#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 _unAduitOrders;
///
/// 未审核ListSource
///
public List UnAduitOrders
{
get { return _unAduitOrders; }
set { Set(() => UnAduitOrders, ref _unAduitOrders, value); }
}
#endregion
#region 审核不通过的ListSource
private List _refuseOrders;
///
/// 审核不通过的ListSource
///
public List RefuseOrders
{
get { return _refuseOrders; }
set { Set(() => RefuseOrders, ref _refuseOrders, value); }
}
#endregion
#region 所有单据ListSource【“待审核”、“未通过”、“已通过”、“已配对”】
private List _allOrders;
///
/// 所有单据ListSource
///
public List AllOrders
{
get { return _allOrders; }
set { Set(() => AllOrders, ref _allOrders, value); }
}
#endregion
#region 选择当前行【实体】
private DeliveryEntrustOrder _selectEntrustOrder;
///
/// 选择 行
///
public DeliveryEntrustOrder 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;
///
/// Gets the DeliveryCommand.
///
public RelayCommand DeliveryCommand
{
get
{
return _deliveryCommand
?? (_deliveryCommand = new RelayCommand(
() =>
{
MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.DeliveryDeclare);
}));
}
}
#endregion
#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 撤销命令Command
public ICommand CancelCommand
{
get
{
return new RelayCommand(() =>
{
if (SelectEntrustOrder != null)
{
}
});
}
}
#endregion
#region 撤销或配对命令Command
private RelayCommand _cancelOrMatchCommand;
///
/// Gets the CancelOrMatchCommand.
///
public RelayCommand CancelOrMatchCommand
{
get
{
return _cancelOrMatchCommand
?? (_cancelOrMatchCommand = new RelayCommand(
() =>
{
switch (SelectEntrustOrder.OrderStatus)
{
default:
break;
}
}));
}
}
///
/// 撤销命令
///
public RelayCommand CancelCammand
{
get
{
return new RelayCommand(() =>
{
MessageBoxHelper.ShowInfo("功能开发中,敬请期待", Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
return;
//if (SelectEntrustOrder == null) return;
//PostCancelOrder();
}, () => CanCancelOrderDetial());
}
}
///
/// 撤销操作Event
///
private void PostCancelOrder()
{
if (SelectEntrustOrder != null)
{
//var orderBuild = BuildEntrustOrder();
//long orderNumber = orderBuild.RelateOrderID;
////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.DeliveryApplyOrder(orderBuild, EntrurstSuccessCallBack, EntrurstErrorCallBack);
//}
}
}
///
/// 是否可撤单
///
///
public bool CanCancelOrderDetial()
{
var result = false;
return result;
}
#endregion
#region 查看详情
private RelayCommand _seeMoreDetailCommand;
///
/// 查看详情
///
public RelayCommand SeeMoreDetailCommand
{
get
{
return _seeMoreDetailCommand
?? (_seeMoreDetailCommand = new RelayCommand(
p =>
{
MessengerHelper.DefaultSend(SelectEntrustOrder, MessengerTokens.DeliveryEntructOrderDetail);
}));
}
}
#endregion
#region 撤销命令
private RelayCommand _cancelsCommand;
///
/// 撤销命令
///
public RelayCommand CancelsCommand
{
get
{
return _cancelsCommand
?? (_cancelsCommand = new RelayCommand(
() =>
{
PostCancelOrder();
}));
}
}
#endregion
#region 点选仓单命令
private RelayCommand _matchCommand;
///
/// 点选仓单命令
///
public RelayCommand MatchCommand
{
get
{
return _matchCommand
?? (_matchCommand = new RelayCommand(
() =>
{
MessageBoxHelper.ShowInfo("功能开发中,敬请期待", Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
if (SelectEntrustOrder.accountid == 0)
{
SelectEntrustOrder.accountid = UserManager.CurrentTradeAccount.FundsAccountId;
}
//MessengerHelper.DefaultSend(SelectEntrustOrder, MessengerTokens.DeliveryMatchDeclare);
}));
}
}
#endregion
#endregion "Public Commands"
#region "Private Methods"
#region 创建下单委托对象
///
/// 创建下单委托对象
///
/// 下单委托对象
private DeliveryOrderReqModel BuildEntrustOrder()
{
//string loginCode, string tradeCode, long orderId, long entrustId, decimal quantity, string goodsCode
//var entrustId = CurrentLimitOrder.EntrustId;
var newOrder = new DeliveryOrderReqModel()
{
};
//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 void EntrurstSuccessCallBack(DeliveryOrderRspModel order)
{
IsBusy = false;
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Account_CancelSuccess,
Client_Resource.Cancel_MessageBox_Title);
//MessageBoxHelper.ShowSuccess(Client_Resource.Order_Success_Result,
// Client_Resource.Cancel_MessageBox_Title);
//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;
}));
}
///
/// 查询成功返回
///
///
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)
{
foreach (var orderitem in orders)
{
if (orderitem.PPriceMode == 1)
{
orderitem.IsVisibility_RelationModeP = Visibility.Visible;
}
else
{
orderitem.IsVisibility_RelationModeP = Visibility.Collapsed;
}
if (orderitem.P2PriceMode == 1)
{
orderitem.IsVisibility_RelationModeP2 = Visibility.Visible;
}
else
{
orderitem.IsVisibility_RelationModeP2 = Visibility.Collapsed;
}
}
AllOrders = orders.OrderByDescending(x => x.OrderTime).ToList();//所有单据
}
}
#endregion "Private Methods"
#region "Other Methods like Validated"
///
/// 数据验证
///
///
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 like Validated"
}
}