//----------------------------------------------------------------
//Module Name: WindowMessengerRegister
//Purpose:
//CopyRight: Muchinfo
//History:
//----------------------------------------------------------------
//DateTime Author Description
//----------------------------------------------------------------
//2014-04-03 deng.yinping Create
//----------------------------------------------------------------
using GalaSoft.MvvmLight.Ioc;
using GalaSoft.MvvmLight.Threading;
using Muchinfo.MTPClient.Account.ViewModels;
using Muchinfo.MTPClient.Account.ViewModels.Notices;
using Muchinfo.MTPClient.Account.Views;
using Muchinfo.MTPClient.Account.Views.Notices;
using Muchinfo.MTPClient.Data;
using Muchinfo.MTPClient.Data.Enums;
using Muchinfo.MTPClient.Data.Helper;
using Muchinfo.MTPClient.Data.Model;
using Muchinfo.MTPClient.Data.Model.Account;
using Muchinfo.MTPClient.Data.Model.Delivery;
using Muchinfo.MTPClient.Data.Model.GoodRules;
//using Muchinfo.MTPClient.Data.Model.Listing;
using Muchinfo.MTPClient.Data.Quote;
using Muchinfo.MTPClient.Delivery.ViewModels;
using Muchinfo.MTPClient.Data.Model.Message;
using Muchinfo.MTPClient.Delivery.Views;
using Muchinfo.MTPClient.Infrastructure.Cache;
using Muchinfo.MTPClient.Infrastructure.Helpers;
using Muchinfo.MTPClient.Infrastructure.LinkProxy;
using Muchinfo.MTPClient.Infrastructure.MessageBox;
using Muchinfo.MTPClient.Infrastructure.MessengerArgs;
using Muchinfo.MTPClient.Infrastructure.Utilities;
using Muchinfo.MTPClient.IService;
using Muchinfo.MTPClient.Listing.ViewModel;
using Muchinfo.MTPClient.Listing.Views;
using Muchinfo.MTPClient.Report;
using Muchinfo.MTPClient.Resources;
using Muchinfo.MTPClient.Trade.ViewModels;
using Muchinfo.MTPClient.Trade.Views;
using Muchinfo.MTPClient.UI.ViewModels;
using Muchinfo.MTPClient.UI.Views;
using Muchinfo.PC.Common.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Muchinfo.MTPClient.Account.Views.AllOrderView;
using Muchinfo.MTPClient.Sale.Views;
using Muchinfo.MTPClient.Data.Model.Sale;
namespace Muchinfo.MTPClient.UI.Utilities
{
public class MessageRegister
{
private static MainPage _homePage;
// private static Muchinfo.MTPClient.FinancingAndInvestment.ViewModels
///
/// 消息注册
///
/// The home page.
public static void Register(MainPage homePage)
{
_homePage = homePage;
#region 图表
////打开图表窗口
//MessengerHelper.DefaultRegister(homePage, MessengerTokens.OpenQuoteChartWindow, WindowHelper.OpenQuoteChartWindow);
////打开自定义周期窗口
//MessengerHelper.DefaultRegister(homePage, MessengerTokens.OpenEditCustomCycleWindow, (e) => WindowHelper.OpenEditCustomCycleWindow());
////更新图表周期
//MessengerHelper.DefaultRegister(homePage, MessengerTokens.UpateChartCycleType, UpateChartCycleType);
#endregion
#region 行情
//打开行情窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.OpenQuoteWindow, WindowHelper.OpenWindow);
//注册行情订阅消息
// MessengerHelper.DefaultRegister(homePage, MessengerTokens.QuoteSubscribe, (s) => QuoteSubscribeHelper.QuoteSubscribe());
#endregion
#region 帐户、查询
//用户离线通知
MessengerHelper.DefaultRegister(homePage, MessengerTokens.UserOfflineNoticeToken, UserOfflineNotice);
//用户离线通知(结算)
MessengerHelper.DefaultRegister(homePage, MessengerTokens.UserOfflineNoticesSttle, UserOfflineNotice);
//链路检查失败处理
MessengerHelper.DefaultRegister(homePage, MessengerTokens.UserOfflineNoticeToken, LogoutFail);
//链路检查失败处理
MessengerHelper.DefaultRegister(homePage, MessengerTokens.ConnectCheckedToken, CheckTokenFail);
//公告和风控
// MessengerHelper.DefaultRegister(homePage, MessengerTokens.AnnouncementMessage, MessageNotice);
//账户报表
MessengerHelper.DefaultRegister(homePage, MessengerTokens.AccountReport, AccountReportQuety);
#endregion
#region 银行
//签约申请
MessengerHelper.DefaultRegister(homePage, MessengerTokens.BankSign, BankSignMessage);
//解约申请
MessengerHelper.DefaultRegister(homePage, MessengerTokens.BankCancelSign, BankBrokenSign);
//银行变更
MessengerHelper.DefaultRegister(homePage, MessengerTokens.BankUpdate, ChanageBankMessage);
//打开出入金申请窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.FundsApply, WindowHelper.ShowAmountManager);
#endregion
#region 交易单据
//建仓消息
MessengerHelper.DefaultRegister(homePage, MessengerTokens.OrderMessageToken, ShowOrderDialog);
//挂牌申报消息
//MessengerHelper.DefaultRegister(homePage, MessengerTokens.OrderListingToken, ShowListingOrderDialog);
//单据变动 (成交通知更新委托单)
MessengerHelper.DefaultRegister(homePage, MessengerTokens.OrderNoticeToken, OrderNotice);
//挂牌通知
// MessengerHelper.DefaultRegister(homePage, MessengerTokens.ListingNotice, ListingNotice);
//预埋单更新
//MessengerHelper.DefaultRegister(homePage, MessengerTokens.PreOrderUpdate,PreOrderNotice);
//交收申报
//MessengerHelper.DefaultRegister(homePage, MessengerTokens.DeliveryDeclare, DeliveryMessage);
//交收申报-带参数
//MessengerHelper.DefaultRegister(homePage, MessengerTokens.DeliveryDeclareParameter, DeliveryMessageParameter);
//写单据成交日志
// MessengerHelper.DefaultRegister(homePage, MessengerTokens.WriteOrderCompleteLog, LogManager.WriteOrderCompleteLog);
//止盈止损下单
MessengerHelper.DefaultRegister(homePage, MessengerTokens.ShowSPSLToken, ShowSPSLDialog);
#endregion
//重新登录
MessengerHelper.DefaultRegister(homePage, MessengerTokens.RerunApplication, (s) =>
{
////保存布局及列表行情抬头
MessengerHelper.DefaultSend(string.Empty, MessengerTokens.SaveLayout);
WindowHelper.RerunApplication();
});
//风控通知
MessengerHelper.DefaultRegister(homePage, MessengerTokens.RiskControl, RiskControl);
//账户信息改变通知
MessengerHelper.DefaultRegister(homePage, MessengerTokens.AccountInfoChange, AccountRaiseChange);
////市场开始通知(已修改,未使用)
// MessengerHelper.DefaultRegister(homePage, MessengerTokens.Market_OpenToken, MarketOpenNotice);
//开休市计划通知
AppMessengerHelper.MarketStatusChangeNotifyMessage.Register(homePage, MarketStatusChangeNotifyAction);
////收到修改商品信息的通知
MessengerHelper.DefaultRegister(homePage, MessengerTokens.UpdateCacheGoodsToken, UpdateTradeGoods);
////收到修改账号参数信息的通知
MessengerHelper.DefaultRegister(homePage, MessengerTokens.AccountParamChangeToken, QueryAccountParam);
//提货申请-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.TakeDeliveryGoodsApply, TakeDeliveryGoodsApplyEvent);
//交收申报配对-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.DeliveryMatchDeclare, DeliveryMatchMessage);
//交割单详情-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.DeliveryOrderDetail, DeliveryOrderDetailMessage);
//申报单详情-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.DeliveryEntructOrderDetail, DeliveryEntructOrderDetailMessage);
//持仓单详情-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.HoldOrderDetail, HoldOrderDetailMessage);
//持仓汇总下的持仓明细
MessengerHelper.DefaultRegister(homePage, MessengerTokens.HoldOrderLst, HoldOrderLstMessage);
//委托单详情-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.LimitOrderDetail, LimitOrderDetailMessage);
//预埋单详情-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.PreLimitOrderDetail, PreLimitOrderDetailMessage);
//成交明细详情-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.TransactionOrderDetail, TransactionOrderDetailMessage);
//配号中签详情-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.DistributeBallotDetail, DistributeBallotDetailMessage);
//提货详情-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.TakeGoodsMoreDetail, TakeGoodsMoreDetailMessage);
//确认货票-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.ComfirmGoodsTickets, ComfirmGoodsTicketsMessage);
//仓单提货信息填写-弹出窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.WarehouseRecieveInfo, WarehouseRecieveInfoMessage);
////公告小窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.AnnouncementMessage, ShowNotice);
////显示公告详情
MessengerHelper.DefaultRegister(homePage, MessengerTokens.AnnouncementDetail, ShowAnnouncement);
////菜单显示窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.AnnouncementDetail, ShowNoticeWin);
////打开风控信息
MessengerHelper.DefaultRegister(homePage, MessengerTokens.AnnouncementMessage, RiskControlMsg);
////弹出公告或风控信息
MessengerHelper.DefaultRegister(homePage, MessengerTokens.AnnouncementMessage, ShowNoticeWindow);
////提货通知
MessengerHelper.DefaultRegister < OutStoreAuditNtfModel>(homePage, MessengerTokens.OutStoreAuditToken,
(model) =>
{
var messge = new NoticeMsg();
{
messge.TITLE = model.Content;
}
messge.IsClicked = true;
messge.SmallWinTitle = Client_Resource.Text_OutStoreAuditNotice;
ShowNotice(messge);
});
////交割商品到期提货通知
MessengerHelper.DefaultRegister(homePage, MessengerTokens.GoodsCloseDateToken,
(model) =>
{
var messge = new NoticeMsg();
{
messge.TITLE = model.MsgContent;
}
messge.IsClicked = true;
messge.SmallWinTitle = Client_Resource.Text_GoodsCloseDateTokenNotice;
ShowNotice(messge);
});
////会员风控通知
MessengerHelper.DefaultRegister(homePage, MessengerTokens.RiskControlMemberToken,
(model) =>
{
var messge = new NoticeMsg();
{
messge.TITLE = model.MsgContent;
}
messge.IsClicked = true;
messge.RiskLevel = model.RiskLevel;
messge.SmallWinTitle = Client_Resource.Moduels_Notify;
ShowNotice(messge);
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
if ((eAccountStatus)model.AccountStatus != UserManager.CurrentTradeAccount.AccountStatus)
{
//更新 用户状态
UserManager.CurrentTradeAccount.AccountStatus = (eAccountStatus)model.AccountStatus;
MessengerHelper.DefaultSend((eAccountStatus)model.AccountStatus, MessengerTokens.AccountStautsChange);
}
}));
});
////投资者风控通知
MessengerHelper.DefaultRegister(homePage, MessengerTokens.RiskControlInvestorToken,
(model) =>
{
/*if (isShowF)// 因为服务端一直推送斩仓通知的消息。这个只是测试代码,一定要记得去掉,要不有2次斩仓通知的话,那就完犊子了。
{
return;
}
isShowF = true;*/
RiskControlMsg msg = Newtonsoft.Json.JsonConvert.DeserializeObject(model.MsgContent);
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var messge = new NoticeMsg();
{
messge.TITLE = msg.Content;
}
messge.IsClicked = true;
messge.RiskLevel = msg.SendType;
messge.SmallWinTitle = Client_Resource.Moduels_Notify;
ShowNotice(messge);
if ((eAccountStatus)model.AccountStatus != UserManager.CurrentTradeAccount.AccountStatus)
{
//更新 用户状态
UserManager.CurrentTradeAccount.AccountStatus = (eAccountStatus)model.AccountStatus;
MessengerHelper.DefaultSend((AccountStatus)model.AccountStatus, MessengerTokens.AccountStautsChange);
}
}));
});
////通用通知
MessengerHelper.DefaultRegister(homePage, MessengerTokens.CommonMessageToken,
(model) =>
{
var messge = new NoticeMsg();
{
messge.TITLE = model.Content;
messge.SmallWinTitle = model.Title;
}
messge.IsClicked = true;
ShowNotice(messge);
});
////弹出修改密码窗口
MessengerHelper.DefaultRegister(homePage, MessengerTokens.ShowModifyPwd, ShowModifyPwdDialog);
}
private static bool isShowF = false;
///
/// Shows the modify password dialog.
///
/// if set to true [is unforce update].
private static void ShowModifyPwdDialog(bool isUnforceUpdate)
{
// 风管云平台不需要修改密码
//Application.Current.Dispatcher.BeginInvoke(new Action(() =>
//{
// var view = new TradePWDModifyView(isUnforceUpdate)
// {
// Owner = Application.Current.MainWindow,
// WindowStartupLocation = WindowStartupLocation.CenterOwner
// };
// view.ShowDialog();
//}));
}
///
/// 提货申请-弹出窗口
///
/// 交易账号
private static void TakeDeliveryGoodsApplyEvent(TradeAccount tradeAccount)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var deliveryDeclareView = new TakaDeliveryGoodsApplyView
{
Owner = Application.Current.MainWindow
};
deliveryDeclareView.ShowDialog();
}));
}
///
/// 取消消息注册
///
public static void Cleanup()
{
if (_homePage == null) return;
MessengerHelper.DefaultUnregister(_homePage);
}
///
/// 市场开始通知
///
///
private static void MarketOpenNotice(string[] goodsCodes)
{
//实时行情断后重新订阅商品
QuoteProxyHelper.QuoteSubscribe(GoodsFromScr.All);
//var goodReadTimeService = SimpleIoc.Default.GetInstance();
//goodReadTimeService.MarketOpenUpdateDayQuote(goodsCodes);
}
///
/// 开休市计划通知【行为】
///
/// MarketStatusChangeModel
private static void MarketStatusChangeNotifyAction(List marketstatus)
{
var models = marketstatus.Select((item) => item.Type);
string signals = string.Empty;
foreach (var model in models)
{
signals += "," + model;
}
LogInfoHelper.WriteInfo("开休市计划通知" + signals);
if (models.Contains((uint)SignalTypeEnum.SystemSettlement))
{
//切断链路
LinkManager.Instance.Dispose();
//当控制信号类型为系统结算时
//提示框:系统结算,重新连接
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
////保存布局及列表行情抬头
MessengerHelper.DefaultSend(string.Empty, MessengerTokens.SaveLayout);
MessageBoxHelper.ShowInfo(Client_Resource.SystemMessage_SystemSettlement_Relink, Client_Resource.Warning_Tips);
//重新启动应用程序
WindowHelper.RerunApplication();
}));
}
else if (models.Contains((uint) SignalTypeEnum.QuoteGoodClear) ||
models.Contains((uint) SignalTypeEnum.MarketOpen))
{
//当控制信号类型为市场开市时
//实时行情断后重新订阅商品
Task.Factory.TryStartNew(() =>
{
QuoteProxyHelper.QuoteClear(GoodsFromScr.All);
//LinkManager.Instance.QuoteTcpLinkProxy.ClearQuote();
var random = new Random();
var second = random.Next(1000, 3000);
Thread.Sleep(second);
QuoteProxyHelper.QuoteSubscribe(GoodsFromScr.All);
CacheManager.TradeDayPlan.Clear(); ////清除开休市时间
MessengerHelper.DefaultSend(string.Empty, MessengerTokens.Market_OpenToken); ////图表更新
});
}
CheckMarketStatusChange(marketstatus);
}
///
/// 市场开收市
///
///
private static void CheckMarketStatusChange(List marketstatus)
{
if (marketstatus != null && marketstatus.Any())
{
foreach (var marketChange in marketstatus)
{
if (CacheManager.MarketStatus.ContainsKey(marketChange.Id))
{
switch ((SignalTypeEnum)marketChange.Type)
{
case SignalTypeEnum.MarketOpen:
CacheManager.MarketStatus[marketChange.Id] =(int) MarketStatus.MarketOpen;
break;
case SignalTypeEnum.MarketClose:
CacheManager.MarketStatus[marketChange.Id] =(int) MarketStatus.MarketClose;
break;
default:
break;
}
}
}
}
if (UserManager.CurrentTradeAccount.AccountType != eUserType.USERTYPE_INVESTOR)
{
var allMarketType = CacheManager.MarketStatus.Values.Any((status) => status == (int)MarketStatus.MarketOpen);
MessengerHelper.DefaultSend(allMarketType, MessengerTokens.MemberTraderUpdate);
}
}
///
/// 修改商品信息时更新缓存商品
///
private static void UpdateTradeGoods(string message)
{
var loginService = SimpleIoc.Default.GetInstance();
if (UserManager.CurrentTradeAccount != null)
{
loginService.AccountBaseInfoInit(UserManager.CurrentTradeAccount.AccountId, QueryGoodsSuccess, null);
}
}
///
/// 更新商品信息后取盘面,订阅行情
///
///
private static void QueryGoodsSuccess(AccountInfoEntity accountInfo)
{
//实时行情断后重新订阅商品
QuoteProxyHelper.QuoteSubscribe(GoodsFromScr.All);
//todo:基本信息的账号资金不正确
var accountid = UserManager.CurrentTradeAccount.AccountId;
//if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
//{
// accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
//}
var loginService = SimpleIoc.Default.GetInstance();
// loginService.QueryTaAccount(accountid, null, null);
////更新资金信息
MessengerHelper.DefaultSend(accountid+string.Empty, MessengerTokens.MoneyNoticeToken);
loginService.QueryAccountGoodsParams(accountid, QueryGoodsParamsUpdate, null);
}
///
/// /更新参数
///
///
private static void QueryGoodsParamsUpdate(Dictionary dictionary)
{
MessengerHelper.DefaultSend(string.Empty, MessengerTokens.RefreshGoodsToken);
}
///
/// 修改账号参数时更新账号信息
///
///
private static void QueryAccountParam(string message)
{
var accountid = UserManager.CurrentTradeAccount.AccountId;
//if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
//{
// accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
//}
var loginService = SimpleIoc.Default.GetInstance();
if (UserManager.CurrentTradeAccount != null)
{
loginService.QueryAccountGoodsParams(accountid, QueryGoodsParamsUpdate, null);
}
MessengerHelper.DefaultSend( string.Empty, MessengerTokens.MoneyNoticeToken);
}
#region 消息方法
///
/// 更新图表周期消息
///
private static void UpateChartCycleType(UpateChartCycleTypeArgs arg)
{
//粤国际:取消此功能
//if (_homePage == null) return;
//var activeChartView = _homePage.MainPanel.Children[0] as QuoteChartView;
//if (activeChartView == null) return;
//activeChartView.SetCycleType(arg.CycleType, arg.TimSpan);
}
///
/// 成交通知
///
private static void OrderNotice(TradeAccount completeArg)
{
UserManager.InitializeTradeCacheData(completeArg);
//按单据类型发通知
MessengerHelper.DefaultSend(completeArg, MessengerTokens.OrderNotify);
}
///
/// 预埋单更新通知
///
///
private static void PreOrderNotice(bool IsCompleteNotice)
{
if (IsCompleteNotice)
{
UserManager.InitializeTradeCacheData(UserManager.CurrentTradeAccount);
//按单据类型发通知
MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNotify);
}
else
{
var cacheData = UserManager.GetTradeCacheData(UserManager.CurrentTradeAccount.AccountId);
cacheData.OpenPrePostOrderFlag = false;
MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.PreOrderNoticeToken);
}
}
private static void LogoutFail(ErrorEntity error)
{
//切断链路
LinkManager.Instance.Dispose();
////有弹出信息窗口,需要跳到UI线程
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
////保存布局及列表行情抬头
MessengerHelper.DefaultSend(string.Empty, MessengerTokens.SaveLayout);
ErrorManager.ShowReturnError(error, Client_Resource.UI2014_Tips);
////重新运行
WindowHelper.RerunApplication();
}));
}
private static void CheckTokenFail(ErrorEntity error)
{
//切断链路
LinkManager.Instance.Dispose();
////有弹出信息窗口,需要跳到UI线程
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
////保存布局及列表行情抬头
MessengerHelper.DefaultSend(string.Empty, MessengerTokens.SaveLayout);
MessageBoxHelper.ShowInfo(Client_Resource.CheckToken_Error_ReStart, Client_Resource.UI2014_Tips);
// ErrorManager.ShowReturnError(Client_Resource.CheckToken_Error_ReStart, Client_Resource.UI2014_Tips);
////重新运行
WindowHelper.RerunApplication();
}));
}
///
/// 用户离线通知
///
private static void UserOfflineNotice(RestartType flag)
{
//切断链路
LinkManager.Instance.Dispose();
//重新运行
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
string logoutMsg = string.Empty;
switch (flag)
{
case RestartType.LoginOut:
logoutMsg = Client_Resource.Mes_Logout;
break;
case RestartType.TradeCheckedFail:
logoutMsg = Client_Resource.Message_TradeCheckFail;
break;
case RestartType.QuoteCheckedFail:
logoutMsg = Client_Resource.Message_QuoteCheckFail;
break;
case RestartType.LinkFail:
logoutMsg = Client_Resource.Link_Fail;
break;
case RestartType.SttleLoginOut:
logoutMsg = Client_Resource.Sttle_LoginOut;
break;
default:
logoutMsg = Client_Resource.Mes_LogoutCommon;
break;
}
////保存布局及列表行情抬头
MessengerHelper.DefaultSend(string.Empty, MessengerTokens.SaveLayout);
MessageBoxHelper.ShowInfo(logoutMsg, Client_Resource.Warning_Tips);
////重新运行
WindowHelper.RerunApplication();
}));
}
private static void ShowOrderDialog(OrderMessage orderMessage)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
TradeOrderViewModel viewModel;
if (orderMessage.OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN)
{
var homeViewModel = SimpleIoc.Default.GetInstance();
QuoteGoods quoteGoods;
if (CacheManager.FromType == eOrderFormType.Listting)//是否挂牌模式
{
quoteGoods = homeViewModel.SelectedCommissionQuoteGoods;
quoteGoods.formType = eOrderFormType.Listting;
quoteGoods.OrderId_Listing = orderMessage.OrderId;
quoteGoods.OrderPrice_Listing = orderMessage.OrderPrice;
}
else
{
quoteGoods = homeViewModel.SelectedQuoteGoods;
quoteGoods.formType = eOrderFormType.Commom;
quoteGoods.OrderId_Listing = orderMessage.OrderId;
}
if (quoteGoods == null)
{
MessageBoxHelper.ShowInfo(Client_Resource.Select_Goods_Error, Client_Resource.APP_Tips);
return;
}
if ((quoteGoods.ContainsGoodsSrc & (int)GoodsFromScr.Trade) != (int)GoodsFromScr.Trade) ////浏览的商品
{
var errorMsg = string.Format(Client_Resource.Goods_WithOutTrade_Power, quoteGoods.Name);
MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.APP_Tips);
return ;
}
if (CacheManager.CacheGoodsBaseInfos == null || !CacheManager.CacheGoodsBaseInfos.Any())
{
MessageBoxHelper.ShowInfo(Client_Resource.Trade_WidthoutTradeGoods, Client_Resource.APP_Tips);
return;
}
//j是否是
if (orderMessage.Direction == Direction.Ask && quoteGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY)
{
var holdingOrders = UserManager.GetCacheOrders();
if (holdingOrders == null || !holdingOrders.Any())
{
MessageBoxHelper.ShowInfo(Client_Resource.Quick_OrderHasNoHolds, Client_Resource.MessageBox_Error_Title);
return;
}
var holds =
holdingOrders.Where(
(item) =>
item.GoodsId == quoteGoods.GoodsParameters.GoodsId && item.Direction == Direction.Bid)
.ToList();
if (!holds.Any())
{
MessageBoxHelper.ShowInfo(Client_Resource.Quick_OrderHasNoHolds, Client_Resource.MessageBox_Error_Title);
return;
}
}
if (ApplicationParameter._LockType == LockType.Lock &&
UserManager.GetCurrentLayoutStyle() == LayoutStyle.Tradition)
{
return;
}
viewModel = new TradeOrderViewModel(quoteGoods, orderMessage.Direction);
}
else
{
CacheManager.FundsAccountId = orderMessage.AccountID;
viewModel = new TradeOrderViewModel(orderMessage.Order, orderMessage.OrderPriceMode);
}
if (UserManager.GetCurrentLayoutStyle() == LayoutStyle.Tradition)
{
//这种布局不弹出下单窗口
MessengerHelper.DefaultSend(viewModel, MessengerTokens.OrderMessage);
}
else
{
var openWindow = new EntrustOrderView(viewModel)
{
Owner = Application.Current.MainWindow,
WindowStartupLocation = WindowStartupLocation.CenterOwner
};
openWindow.ShowDialog();
}
}));
}
///
/// Shows the SPSL dialog.
///
/// The order message.
private static void ShowSPSLDialog(OrderMessage orderMessage)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
CacheManager.FundsAccountId = orderMessage.AccountID;
var viewModel = new TradeOrderViewModel(orderMessage.Order, orderMessage.OrderPriceMode, OrderModel.SPSL);
var openWindow = new EntrustOrderView(viewModel)
{
Owner = Application.Current.MainWindow,
WindowStartupLocation = WindowStartupLocation.CenterOwner
};
openWindow.ShowDialog();
}));
}
///
/// 交收申请消息
///
/// 交易账号
private static void DeliveryMessage(TradeAccount tradeAccount)
{
//todo:uncomment
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var deliveryDeclareView = new NDeliveryOrderView//DeliveryOrderView
{
Owner = Application.Current.MainWindow
};
deliveryDeclareView.ShowDialog();
}));
}
///
/// 交收申请消息-带参数
///
/// 交易账号
private static void DeliveryMessageParameter(DeliveryOrderMessage parameter)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var deliveryDeclareView = new NDeliveryOrderView(parameter)
{
Owner = Application.Current.MainWindow
};
deliveryDeclareView.ShowDialog();
}));
}
///
/// 仓单提货人信息填写窗口
///
///
private static void WarehouseRecieveInfoMessage(Muchinfo.MTPClient.Data.Model.Delivery.DeliveryWarehouse item)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var declareView = new RecieveInfoView(item)
{
Owner = Application.Current.MainWindow
};
declareView.ShowDialog();
}));
}
///
/// 确认货票消息
///
/// 交割查询实体
private static void ComfirmGoodsTicketsMessage(Muchinfo.MTPClient.Data.Model.Delivery.DryHoldDetail itemOrder)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var newView = new ComfirmGoodsTicketsView(itemOrder)
{
Owner = Application.Current.MainWindow
};
newView.ShowDialog();
}));
}
///
/// 提货详情消息
///
/// 交割提货查询
private static void TakeGoodsMoreDetailMessage(Muchinfo.MTPClient.Data.Model.Delivery.TakaDeliveryGoodsQueryModel itemOrder)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var newView = new TakeGoodsMoreDetailView(itemOrder)
{
Owner = Application.Current.MainWindow
};
newView.ShowDialog();
}));
}
///
/// 交割单详情消息
///
/// 交割查询实体
private static void DeliveryOrderDetailMessage(Muchinfo.MTPClient.Data.Model.Delivery.DryHoldDetail itemOrder)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var newView = new DryHoldMoreDetailView(itemOrder)
{
Owner = Application.Current.MainWindow
};
newView.ShowDialog();
}));
}
///
/// 申报单详情消息
///
/// 交割查询实体
private static void DeliveryEntructOrderDetailMessage(Muchinfo.MTPClient.Data.Model.Delivery.DeliveryEntrustOrder itemOrder)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var newView = new DeliveryEntructOrderDetail(itemOrder)
{
Owner = Application.Current.MainWindow
};
newView.ShowDialog();
}));
}
///
/// 持仓单详情消息
///
/// HoldingOrder
private static void HoldOrderDetailMessage(HoldingOrder itemOrder)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var newView = new MOHoldMoreDetailView(itemOrder)
{
Owner = Application.Current.MainWindow
};
newView.ShowDialog();
}));
}
private static void HoldOrderLstMessage(HoldingSummary summary)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var newView = new MOHoldLstBySummary(summary)
{
Owner = Application.Current.MainWindow
};
newView.ShowDialog();
}));
}
///
/// 委托单详情消息
///
/// OrderDetail
private static void LimitOrderDetailMessage(OrderDetail itemOrder)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var newView = new MOOrderMoreDetailView(itemOrder)
{
Owner = Application.Current.MainWindow
};
newView.ShowDialog();
}));
}
///
/// 预埋单详情消息
///
/// PreLimitOrderDetail
private static void PreLimitOrderDetailMessage(PrePostDetail itemOrder)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var newView = new MOPrePostMoreDetailView(itemOrder)
{
Owner = Application.Current.MainWindow
};
newView.ShowDialog();
}));
}
///
/// 成交明细详情消息
///
/// PreLimitOrderDetail
private static void TransactionOrderDetailMessage(CloseOrder itemOrder)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var newView = new MOTransactionMoreDetailView(itemOrder)
{
Owner = Application.Current.MainWindow
};
newView.ShowDialog();
}));
}
///
/// 配号中签详情
///
/// HoldingOrder
private static void DistributeBallotDetailMessage(DistributeBallot itemOrder)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var newView = new DistributeBallotDetailView(itemOrder)
{
Owner = Application.Current.MainWindow
};
newView.ShowDialog();
}));
}
///
/// 交收配对消息
///
/// 交易账号
private static void DeliveryMatchMessage(Muchinfo.MTPClient.Data.Model.Delivery.DeliveryEntrustOrder itemOrder)
{
//todo:uncomment
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
var deliveryDeclareView = new DeliveryMatchView(itemOrder)
{
Owner = Application.Current.MainWindow
};
// DeliveryMatchView matchWindow = new DeliveryMatchView(viewModel);
deliveryDeclareView.ShowDialog();
}));
}
///
/// 报表查询
///
/// 交易账号
private static void AccountReportQuety(TradeAccount tradeAccount)
{
DispatcherHelper.RunAsync(() =>
{
var reportView = new InvestorReportView()
{
Owner = Application.Current.MainWindow
};
reportView.ShowDialog();
});
}
///
/// 银行变更
///
/// 交易账号
private static void ChanageBankMessage(TradeAccount tradeAccount)
{
//todo:uncomment
return;
//DispatcherHelper.RunAsync(() =>
//{
// var view = new Bank.Views.BankUpdateView { Owner = Application.Current.MainWindow };
// var viewModel = new Muchinfo.MTPClient.Bank.ViewModels.BankUpdateViewModel(view);
// view.DataContext = viewModel;
// //if (viewModel.CurrentSigningBank != null)
// view.ShowDialog();
//});
}
///
/// 解约申请
///
/// 交易账号
private static void BankBrokenSign(TradeAccount tradeAccount)
{
//todo:uncomment
return;
//DispatcherHelper.RunAsync(() =>
//{
// var view = new Bank.Views.BankTerminationView { Owner = Application.Current.MainWindow };
// var viewModel = new Muchinfo.MTPClient.Bank.ViewModels.BankTerminationViewModel(view);
// view.DataContext = viewModel;
// //if (viewModel.CurrentSigningBank != null)
// view.ShowDialog();
//});
}
///
/// 签约申请
///
/// 交易账号
private static void BankSignMessage(TradeAccount tradeAccount)
{
//todo:uncomment
return;
//DispatcherHelper.RunAsync(() =>
//{
// var view = new Bank.Views.BankSigningView { Owner = Application.Current.MainWindow };
// view.ShowDialog();
//});
}
private static NoticesView _notices;
///
/// 查询未读公告,通知
///
///
private static void ShowNoticeWindow(MsgTypeEnum MsgType)
{
NoticesBase noticebase;
if (MsgType == MsgTypeEnum.Bulletin)
{
noticebase = new NoticesViewModel();
}
else
{
noticebase = new TradeMessageViewModel();
}
//var window = new NoticesView();
//window.DataContext = noticebase;
//window.Owner = Application.Current.MainWindow;
//window.ShowInTaskbar = false;
//window.ShowDialog();
ShowNoticeWin(noticebase);
}
///
/// 显示窗口
///
///
private static void ShowNoticeWin(NoticesBase noticebase)
{
if (_notices != null)
{
if (_notices.IsVisible)
{
_notices.Close();
}
}
_notices = new NoticesView()
{
Owner = Application.Current.MainWindow,
WindowStartupLocation = WindowStartupLocation.CenterOwner
};
_notices.DataContext = noticebase;
_notices.Show();
}
///
/// 处理风控信息
///
///
private static void RiskControlMsg(RiskControl risk)
{
//NoticeMsg noticeMsg=new NoticeMsg()
//{
//};
//DateTime dateTime;
//DateTime.TryParse(risk.Date, out dateTime);
//noticeMsg.SCHEDULE_TIME = dateTime;
// noticeMsg.CONTENT= string.Format(Client_Resource.Msg_TotalContent);
//var window = new NoticesView();
//window.DataContext = new TradeMessageViewModel();
//window.Owner = Application.Current.MainWindow;
//window.ShowInTaskbar = false;
//window.ShowDialog();
var noticebase= new TradeMessageViewModel();
ShowNoticeWin(noticebase);
}
///
/// 会员交易员风控通知提示
///
///
private static void RiskControl(RiskControl riskControl)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
riskControl.MsgRate = riskControl.MsgRate * 100; //推过来的是百分比
riskControl.RealRate = riskControl.RealRate * 100;
//if (Application.Current.Properties["RiskControlNoticeView"] == null)
//{
ShowRiskControl(riskControl);
//}
//else
//{
//RiskControlNoticeView riskControlNoticeView =
// (RiskControlNoticeView)Application.Current.Properties["RiskControlNoticeView"];
//if (riskControlNoticeView != null)
//{
//if (riskControlNoticeView.Opacity != 0)
//{
// MessengerHelper.DefaultSend(TradeTreeMenu.Ntf, MessengerTokens.AccountFunction);
//}
//else
//{
// ShowRiskControl(riskControl);
//}
//}
// }
if (riskControl.AccountStatus != UserManager.CurrentTradeAccount.AccountStatus)
{
//更新 用户状态
UserManager.CurrentTradeAccount.AccountStatus = riskControl.AccountStatus;
MessengerHelper.DefaultSend(riskControl.AccountStatus, MessengerTokens.AccountStautsChange);
}
}));
}
private static void ShowRiskControl(RiskControl riskControl)
{
if (Application.Current.Properties["RiskControlView"] == null)
{
RiskControlView riskControlView = new RiskControlView() { Owner = Application.Current.MainWindow };
riskControlView.DataContext = riskControl;
Application.Current.Properties["RiskControlView"] = riskControlView;
riskControlView.Show();
}
else
{
RiskControlView riskControlView = (RiskControlView)Application.Current.Properties["RiskControlView"];
if (riskControlView != null)
{
riskControlView.Owner = Application.Current.MainWindow;
riskControlView.DataContext = riskControl;
riskControlView.Shows();
}
}
}
///
/// 公告通知提示
///
///
private static void ShowNotice(NoticeMsg notice)
{
// NoticeViewModel noticeViewModel = new NoticeViewModel(notice);
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
if (Application.Current.Properties["NoticeView"] == null)
{
NoticeView noticeView = new NoticeView() { Owner = Application.Current.MainWindow };
noticeView.DataContext = notice;
if (string.IsNullOrWhiteSpace(notice.SmallWinTitle))
{
noticeView.Title = Client_Resource.NoticeView_Title;
}
else
{
noticeView.Title = notice.SmallWinTitle;
}
Application.Current.Properties["NoticeView"] = noticeView;
noticeView.SetWindow();
noticeView.Show();
}
else
{
NoticeView noticeView = (NoticeView)Application.Current.Properties["NoticeView"];
if (noticeView != null)
{
if (string.IsNullOrWhiteSpace(notice.SmallWinTitle))
{
noticeView.Title = Client_Resource.NoticeView_Title;
}
else
{
noticeView.Title = notice.SmallWinTitle;
}
noticeView.Owner = Application.Current.MainWindow;
noticeView.DataContext = notice;
noticeView.SetWindow();
noticeView.Shows();
}
}
}));
}
///
/// 投资者风控提示
///
private static void ShowRisk(Announcement riskMessage)
{
RiskViewModel riskViewModel = new RiskViewModel(riskMessage);
DispatcherHelper.RunAsync(() =>
{
if (Application.Current.Properties["RiskView"] == null)
{
RiskView riskView = new RiskView() { Owner = Application.Current.MainWindow };
riskView.DataContext = riskViewModel;
Application.Current.Properties["RiskView"] = riskView;
riskView.SetWindow();
riskView.Show();
}
else
{
RiskView riskView = (RiskView)Application.Current.Properties["RiskView"];
if (riskView != null)
{
riskView.Owner = Application.Current.MainWindow;
riskView.DataContext = riskViewModel;
riskView.SetWindow();
riskView.Shows();
}
}
});
}
///
///用户状态改变通知
///
private static void AccountRaiseChange(AccountMessage account)
{
if (account.AccountStatus != UserManager.CurrentTradeAccount.AccountStatus)
{
UserManager.CurrentTradeAccount.AccountStatus = account.AccountStatus;
MessengerHelper.DefaultSend(account.AccountStatus, MessengerTokens.AccountStautsChange);
}
if (account.RiskRateID != UserManager.CurrentTradeAccount.RiskRateId)
{
//todo:查询风险率类型
Task.Factory.TryStartNew(() =>
{
var loginService = SimpleIoc.Default.GetInstance();
if (UserManager.CurrentTradeAccount != null)
{
}
}, () => { });
}
}
///
/// 显示公告窗口
///
///
protected static void ShowAnnouncement(NoticeMsg notice)
{
//var window = new NoticesView();
//window.DataContext = new NoticesViewModel(notice);
//window.Owner = Application.Current.MainWindow;
//window.ShowInTaskbar = false;
//window.ShowDialog();
var noticebase = new NoticesViewModel(notice);
ShowNoticeWin(noticebase);
}
#endregion
///
/// 显示挂牌委托界面
///
/// 挂牌窗口
private static void ShowListingOrderDialog(Direction parameter)
{
var deliveryGoodsView = SimpleIoc.Default.GetInstance();
var entrust = new ListingEntrustView(deliveryGoodsView.ListingGoodsess, deliveryGoodsView.CurrentGoods,parameter)
{
Owner = Application.Current.MainWindow,
ShowInTaskbar = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
entrust.ShowDialog();
}
}
}