| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991 |
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Account.ViewModels;
- using Muchinfo.MTPClient.Account.ViewModels.AllOrderViewModel;
- using Muchinfo.MTPClient.Account.Views;
- using Muchinfo.MTPClient.CustomException;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.DTO;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Data.Model.GoodRules;
- using Muchinfo.MTPClient.Data.Model.Message;
- using Muchinfo.MTPClient.Infrastructure.Cache;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Infrastructure.LinkProxy;
- using Muchinfo.MTPClient.Infrastructure.MessageBox;
- using Muchinfo.MTPClient.Infrastructure.Users;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.Infrastructure.Windows;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.MTPClient.Resources;
- using Muchinfo.MTPClient.Service.Utilities;
- using Muchinfo.MTPClient.Trade.ViewModels;
- using Muchinfo.MTPClient.UI.Utilities;
- using Muchinfo.MTPClient.UI.Views;
- using Muchinfo.PC.Common.Extensions;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Threading;
- namespace Muchinfo.MTPClient.UI.ViewModels
- {
- /// <summary>
- /// HomePageViewModel类
- /// </summary>
- public class HomeViewModel : ViewModelBase
- {
- #region Fields
- private bool _isClosePower;//是否有平仓权限
- private ObservableCollection<SysMenuItem> _mainMenuItems;
- private Visibility _statusBarVisibility;
- private Visibility _toolBarVisibility;
- private IAnnouncementService _announcementService;
- private ILoginService _loginService;
- private int _oldTabIndex;
- private ISystemService _systemService;
- private IDeliveryService _deliveryService;//交割服务-》查询交割关系列表
- private Dictionary<ResxVerType, ResxVerInfo> _resxVerInfos; ////服务端资源版本
- private IOrderService _orderService;
- private ICommonQueryService _commonQueryService;
- #endregion Fields
- #region Constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="HomeViewModel" /> class.
- /// </summary>
- /// <param name="service">系统服务</param>
- public HomeViewModel(ISystemService service)
- {
- //初始化命令
- InitializeCommands();
- _toolBarVisibility = Visibility.Visible;
- _statusBarVisibility = Visibility.Visible;
- _announcementService = SimpleIoc.Default.GetInstance<IAnnouncementService>();
- _loginService = SimpleIoc.Default.GetInstance<ILoginService>();
- SystemName = ApplicationParameter.TradeSystemName;
- _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
- _systemService = service;
- _orderService = SimpleIoc.Default.GetInstance<IOrderService>();
- _commonQueryService = SimpleIoc.Default.GetInstance<ICommonQueryService>();
- ApplicationParameter.MakePublishNetIp();
- //消息注册
- RegisterMessenger();
- if (UserManager.IsAccountLogin) ////已交易登录
- {
- TradeDataInit();
- }
- else
- { ////游客没有交易菜单
- CreateLoaclMenu(new List<SysMenuItem>());
- }
- }
- #endregion Constructors
- #region Properties
- #region Public Properties
- private RelayCommand _ftenCommand;
- /// <summary>
- /// Gets the FtenCommand.
- /// </summary>
- public RelayCommand FtenCommand
- {
- get
- {
- return _ftenCommand
- ?? (_ftenCommand = new RelayCommand(
- () =>
- {
- var FtenAddress = ApplicationParameter.FtenAddress;
- if (!string.IsNullOrEmpty(FtenAddress))
- {
- MessengerHelper.DefaultSend<TabContetMode>(TabContetMode.QuoteGoodsInfo, MessengerTokens.ChangeGoodsInfo);
- }
- }));
- }
- }
- /// <summary>
- /// 当前使用的样式
- /// </summary>
- public Object CurrentStyle
- {
- get;
- set;
- }
- public string TradeTypeDisplay
- {
- get
- {
- return string.Empty;
- //var isConfigVersion = ConfigurationManager.AppSettings["IsMockTrade"];
- //return isConfigVersion == "0" ? " - 模拟盘" : " - 实盘";
- }
- }
- /// <summary>
- /// 系统名称
- /// </summary>
- public string SystemName { get; set; }
- /// <summary>
- /// 获取和设置the main menu items
- /// </summary>
- public ObservableCollection<SysMenuItem> MainMenuItems
- {
- get
- {
- return _mainMenuItems;
- }
- set
- {
- Set(() => MainMenuItems, ref _mainMenuItems, value);
- }
- }
- /// <summary>
- /// 获取和设置the menu command
- /// </summary>
- public RelayCommand<SysMenuItem> MenuCommand
- {
- get;
- private set;
- }
- /// <summary>
- /// Gets or sets the name of the user.
- /// </summary>
- public Visibility StatusbarVisibility
- {
- get { return _statusBarVisibility; }
- set
- {
- Set(() => StatusbarVisibility, ref _statusBarVisibility, value);
- }
- }
- /// <summary>
- /// Gets or sets the name of the user.
- /// </summary>
- public Visibility ToolbarVisibility
- {
- get { return _toolBarVisibility; }
- set
- {
- Set(() => ToolbarVisibility, ref _toolBarVisibility, value);
- }
- }
- /// <summary>
- /// 主窗体是否隐藏
- /// </summary>
- private Visibility _mainPanelVisibility = Visibility.Collapsed;
- public Visibility MainPanelVisibility
- {
- get { return _mainPanelVisibility; }
- set
- {
- Set(() => MainPanelVisibility, ref _mainPanelVisibility, value);
- }
- }
- #region 快速下单
- public RelayCommand<int> OrderTransactionCommand
- {
- get
- {
- return new RelayCommand<int>((commandParameter) => Task.Factory.TryStartNew(() =>
- {
- }));
- }
- }
- #endregion
- /// <summary>
- /// 是否为已使用交易账号登录
- /// </summary>
- public bool IsAccountLogin
- {
- get { return UserManager.IsAccountLogin; }
- }
- /// <summary>
- /// 是否顯示功能樹
- /// </summary>
- public bool IsTreeVbs
- {
- get { return UserManager.IsAccountLogin && IsTradeVisible; }
- }
- private bool _isBusy;
- /// <summary>
- /// 是否忙
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
- #endregion Public Properties
- private bool _isTradeVisible = true;
- /// <summary>
- /// 是否显示交易数据
- /// </summary>
- public bool IsTradeVisible
- {
- get { return _isTradeVisible; }
- set
- {
- Set(() => IsTradeVisible, ref _isTradeVisible, value);
- var defaultLayout = UserManager.GetCurrentLayoutStyle();
- MainLayoutUpdate(defaultLayout);
- }
- }
- /// <summary>
- /// 是否保存布局
- /// </summary>
- public bool IsSaveLayout
- {
- get;
- set;
- }
- #endregion Properties
- #region Methods
- #region Private Methods
- /// <summary>
- /// 构建本地菜单
- /// </summary>
- /// <param name="accessItems">交易菜单</param>
- private void CreateLoaclMenu(List<SysMenuItem> accessItems)
- {
- _systemService = SimpleIoc.Default.GetInstance<ISystemService>();
- _orderService = SimpleIoc.Default.GetInstance<IOrderService>();
- MainMenuItems = _systemService.GetSysMenuItems(accessItems, MenuCommand);
- var toolMenu = _mainMenuItems.FirstOrDefault(z => z.Title == MenuNames.Tools);
- if (toolMenu == null || toolMenu.Children == null || !toolMenu.Children.Any()) return;
- var toolBarItem = toolMenu.Children.FirstOrDefault(z => z.SysCommandType == MenuCommandType.Toolbar);
- if (toolBarItem != null) ToolbarVisibility = toolBarItem.IsChecked ? Visibility.Visible : Visibility.Collapsed;
- var statusBarItem = toolMenu.Children.FirstOrDefault(z => z.SysCommandType == MenuCommandType.Statusbar);
- if (statusBarItem != null) StatusbarVisibility = statusBarItem.IsChecked ? Visibility.Visible : Visibility.Collapsed;
- }
- /// <summary>
- /// 消息注册
- /// </summary>
- private void RegisterMessenger()
- {
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.MainPanelIsUnlock, MainPanelIsEnableMethod);
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.InitLockTimer, InitLockTimer);
- MessengerHelper.DefaultRegister<QuoteGoodsDTO>(this, MessengerTokens.SelectGoodsChange, SelectGoodsChange);
- MessengerHelper.DefaultRegister<QuoteGoodsForSelectOrder>(this, MessengerTokens.SelectGoodsOrderChange, SelectGoods);
- MessengerHelper.DefaultRegister<QuoteGoodsDTO>(this, MessengerTokens.SelectCommissionGoodsChange, SelectCommissionGoodsChange);
- //注册快捷下单消息
- MessengerHelper.DefaultRegister<FrameworkElement>(this, MessengerTokens.ShowQueryContet, (view) =>
- {
- QueryView = view;
- });
- MessengerHelper.DefaultRegister<string>(this, MessengerTokens.OrderRefresh, OrderViewRefresh);
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.SetHideExpandTradeToken, SetHideTradeMsg);
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.CancelOrderEnable, (isEnable) =>
- {
- //var tradeFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == UserManager.GetMenuCommandValue(MenuCommandType.Cancel));
- var tradeFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == MenuCommandType.Cancel.ToString());
- if (tradeFunc != null)
- {
- tradeFunc.IsEnabled = isEnable;
- }
- });
- MessengerHelper.DefaultRegister<TradeOrderViewModel>(this, MessengerTokens.OrderMessage, SetOrderView);
- }
- /// <summary>
- /// 选择某个商品
- /// </summary>
- /// <param name="goods"></param>
- private void SelectGoods(QuoteGoodsForSelectOrder goods)
- {
- if (goods == null)
- {
- return;
- }
- if (goods.IsSelect)
- {
- if (ApplicationParameter._LockType == LockType.Lock &&
- UserManager.GetCurrentLayoutStyle() == LayoutStyle.Tradition)
- {
- return;
- }
- }
-
- SelectedQuoteGoods = goods.QuoteGoods;
- if (IsAccountLogin && (SelectedQuoteGoods.ContainsGoodsSrc & (int)GoodsFromScr.Trade) > 0) //交易商品可下单
- {
- ////处理点击会卡的问题
- Task.Factory.TryStartNew(() =>
- {
- var viewModel = new TradeOrderViewModel(SelectedQuoteGoods, Direction.Bid);
- SetOrderView(viewModel);
- });
- }
- }
- /// <summary>
- /// 选择商品改变
- /// </summary>
- /// <param name="goods">The goods.</param>
- private void SelectGoodsChange(QuoteGoodsDTO goods)
- {
- var quoteGoods = CacheManager.CacheGoodsBaseInfos.FirstOrDefault((item) => item.Symbol == goods.Symbol);
- // bool showChart;
- if (quoteGoods != null)
- {
- //todo:
- //if (goods.GoodsParameters.TradeMode == TradeModeType.BidGoods)
- //{
- // showChart = ApplicationParameter.ShowChart == 2; //设置竞价商品才显示图表
- //}
- QuoteGoodsForSelectOrder orderGoods = new QuoteGoodsForSelectOrder
- {
- IsSelect = true,
- QuoteGoods = quoteGoods
- };
- SelectGoods(orderGoods);
-
- }
- //IsShowChart = ApplicationParameter.ShowChart == 1 || showChart;
- }
- /// <summary>
- /// 选择五档买卖商品改变
- /// </summary>
- /// <param name="goods">The goods.</param>
- private void SelectCommissionGoodsChange(QuoteGoodsDTO goods)
- {
- var quoteGoods = CacheManager.CacheGoodsBaseInfos.FirstOrDefault((item) => item.Symbol == goods.Symbol);
- if (quoteGoods != null)
- {
- SelectedCommissionQuoteGoods = quoteGoods;
- }
- }
- /// <summary>
- /// 设置是否展开交易信息
- /// </summary>
- /// <param name="result"></param>
- private void SetHideTradeMsg(bool result)
- {
- IsTradeVisible = result;
- }
- private FrameworkElement _queryView;
- /// <summary>
- /// 查询面板显示的内容
- /// </summary>
- public FrameworkElement QueryView
- {
- get { return _queryView; }
- set
- {
- if (_queryView != null && value.Equals(_queryView))
- {
- return;
- }
- else
- {
- if (_queryView != null)
- {
- var queryPanel = _queryView.DataContext as QueryPanelModelBase;
- if (queryPanel != null)
- {
- queryPanel.UnRegisterMessage();
- }
- }
- }
- Set(() => QueryView, ref _queryView, value);
- var newQueryPanel = value.DataContext as QueryPanelModelBase;
- if (newQueryPanel != null)
- {
- newQueryPanel.RegisterMessage();
- }
- }
- }
- private FrameworkElement _mainContent;
- /// <summary>
- /// 布局内容显示
- /// </summary>
- public FrameworkElement MainContent
- {
- get { return _mainContent; }
- set { Set(() => MainContent, ref _mainContent, value); }
- }
- /// <summary>
- /// 选择的商品
- /// </summary>
- public QuoteGoods SelectedQuoteGoods { get; set; }
- /// <summary>
- /// 选择的商品
- /// </summary>
- public QuoteGoods SelectedCommissionQuoteGoods { get; set; }
- /// <summary>
- /// 更新单据窗口的内容
- /// </summary>
- /// <param name="update"></param>
- private void OrderViewRefresh(string update)
- {
- //下方查询界面显示方式修改后此方法无效,要刷新单据须在各自界面注册消息OrderViewRefresh去实现 --dyp
- if (QueryView != null && QueryView.DataContext is IOrderRefresh)
- {
- (QueryView.DataContext as IOrderRefresh).Refresh();
- }
- ///刷新后-重新查询交割关系列表--pending by dk
- // _deliveryService.QueryRelationPAndXGoodsInfoList(QueryAllDeliveryRelationSuccess, null);
- }
- /// <summary>
- /// <summary>
- /// 设置撤单是否可用
- /// </summary>
- /// <param name="isEnable"></param>
- private void SetCancelItemEable(bool isEnable)
- {
- var menuItem = _mainMenuItems.FirstOrDefault((item) => item.Title == MenuNames.Trading);
- if (menuItem == null) return;
- var canelItem = menuItem.Children.FirstOrDefault((cItem) => cItem.Title == MenuNames.OrderCancel);
- if (canelItem == null) return;
- //var accountManager = SimpleIoc.Default.GetInstance<AccountManagerViewModel>();
- }
- /// <summary>
- /// Executes the command.
- /// </summary>
- /// <param name="item">The item.</param>
- private void ExecuteCommand(SysMenuItem item)
- {
- CacheManager.FromType = eOrderFormType.Commom; //顶部买卖按钮与挂牌无关
- var goods = this.SelectedQuoteGoods;
- switch (item.SysCommandType)
- {
- #region 系统
- case MenuCommandType.Reconnect:
- if (MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.UI2014_IsOrNotReconnect,
- Muchinfo.MTPClient.Resources.Client_Resource.UI2014_Tips) == MessageBoxResult.Yes)
- {
- if (UserManager.IsAccountLogin)
- {
- ////保存布局及列表行情抬头
- MessengerHelper.DefaultSend(string.Empty, MessengerTokens.SaveLayout);
- //手动发送登出消息
- var service = SimpleIoc.Default.GetInstance<ILoginService>();
- if (service != null) service.TradeAccountLogout(UserManager.CurrentTradeAccount);
- }
- WindowHelper.RerunApplication();
- }
- break;
- case MenuCommandType.ChangeTradePassword:
- //非强制修改密码
- MessengerHelper.DefaultSend(true, MessengerTokens.ShowModifyPwd);
- break;
- case MenuCommandType.Horizontal:
- SetInitializeCheck(item);
- MainLayoutUpdate(LayoutStyle.Horizontal);
- break;
- case MenuCommandType.Vertical:
- SetInitializeCheck(item);
- MainLayoutUpdate(LayoutStyle.Vertical);
- break;
- case MenuCommandType.Tradition:
- SetInitializeCheck(item);
- MainLayoutUpdate(LayoutStyle.Tradition);
- break;
- case MenuCommandType.Logout:
- OnClose();
- break;
- case MenuCommandType.CoolBlack:
- SetInitializeCheck(item);
- ThemesUpdate(ColorStyle.CoolBlack);
- break;
- //case MenuCommandType.White:
- // break;
- //case MenuCommandType.SkyBlue:
- // SetInitializeCheck(item);
- // ThemesUpdate(ColorStyle.SkyBlue);
- // break;
- //case MenuCommandType.DarkRed:
- // SetInitializeCheck(item);
- // ThemesUpdate(ColorStyle.DarkRed);
- // break;
- case MenuCommandType.DarkBlue:
- SetInitializeCheck(item);
- ThemesUpdate(ColorStyle.DarkBlue);
- break;
- case MenuCommandType.BlueWhite:
- SetInitializeCheck(item);
- ThemesUpdate(ColorStyle.BlueWhite);
- break;
- case MenuCommandType.LockScreen:
- this.IsLockScreen = true;
- break;
- #endregion
- #region 分析
- case MenuCommandType.CandleChart:
- if (goods == null) return;
- // WindowHelper.OpenQuoteChartWindow(new OpenQuoteChartWindowArg(goods, CycleType.Minute));
- break;
- case MenuCommandType.TimeSharingChart:
- if (goods == null) return;
- // WindowHelper.OpenQuoteChartWindow(new OpenQuoteChartWindowArg(goods, CycleType.TimeSharing));
- break;
- case MenuCommandType.TikChart:
- if (goods == null) return;
- // WindowHelper.OpenQuoteChartWindow(new OpenQuoteChartWindowArg(goods, CycleType.Tik));
- break;
- case MenuCommandType.TradeDetails:
- if (goods == null) return;
- //PriceCardHelper.OpenSubPenDetail(goods);
- break;
- case MenuCommandType.TikDetails:
- if (goods == null) return;
- //PriceCardHelper.OpenSubPriceDetail(goods);
- break;
- case MenuCommandType.F10:
- //todo:
- break;
- case MenuCommandType.MA:
- //todo:
- break;
- case MenuCommandType.BOLL:
- //todo:
- break;
- case MenuCommandType.MACD:
- //todo:
- break;
- case MenuCommandType.DMI:
- //todo:
- break;
- case MenuCommandType.OBV:
- //todo:
- break;
- case MenuCommandType.VOL:
- //todo:
- break;
- case MenuCommandType.RSI:
- //todo:
- break;
- case MenuCommandType.KDJ:
- //todo:
- break;
- case MenuCommandType.CCI:
- //todo:
- break;
- case MenuCommandType.BIAS:
- //todo:
- break;
- case MenuCommandType.PSY:
- //todo:
- break;
- case MenuCommandType.MTM:
- //todo:
- break;
- case MenuCommandType.WR:
- //todo:
- break;
- case MenuCommandType.MultiCycles:
- //todo:
- break;
- case MenuCommandType.MultiGoodses:
- //todo:
- break;
- case MenuCommandType.ComparisonGoodes:
- //todo:
- break;
- #endregion
- #region 交易
- case MenuCommandType.BuyIn:
- //建仓
- var openOrder = new OrderMessage() { Direction = Direction.Bid, OrderPriceMode = ePriceMode.PRICEMODE_MARKET };
- MessengerHelper.DefaultSend(openOrder, MessengerTokens.OrderMessageToken);
- break;
- case MenuCommandType.Sellout:
- //平仓
- var order = new OrderMessage() { Direction = Direction.Ask, OrderPriceMode = ePriceMode.PRICEMODE_MARKET };
- MessengerHelper.DefaultSend(order, MessengerTokens.OrderMessageToken);
- break;
- case MenuCommandType.Cancel:
- //撤单
- if (ViewModelLocator.MOrderDetails.CanCancelOrderDetial())
- {
- // ViewModelLocator.MOrderDetails.CancelAllHoldingCammand.Execute(null);
- ViewModelLocator.MOrderDetails.CancelHoldingCammand.Execute(null);
- }
- else
- {
- MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.UnSupportOrderTypes, Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips);
- }
- break;
- case MenuCommandType.SaleApply:
- var sale = new OrderMessage() { Direction = Direction.Bid, OrderPriceMode = ePriceMode.PRICEMODE_MARKET };
- MessengerHelper.DefaultSend(sale, MessengerTokens.OrderMessageToken);
- break;
- case MenuCommandType.DeliveryApply:
- //交收申请
- MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.DeliveryDeclare);
- break;
- case MenuCommandType.ReportQuery:
- //报表查询
- MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.AccountReport);
- break;
- case MenuCommandType.TradeLogin:
- var login = new TradeLoginView()
- {
- Owner = Application.Current.MainWindow,
- WindowStartupLocation = WindowStartupLocation.CenterOwner,
- ShowInTaskbar = false,
- };
- if (login.ShowDialog() == true)
- {
- TradeDataInit(); ////交易账号登录
- }
- break;
- //case MenuCommandType.TradeSettings:
- // MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.TraderingParamSet);
- // break;
- #endregion
- #region 帮助
- //case MenuCommandType.UserGuide:
- // break;
- case MenuCommandType.EscapeClause:
- var v = new AboutView(1);
- v.Owner = Application.Current.MainWindow;
- v.WindowStartupLocation = WindowStartupLocation.CenterOwner;
- v.ShowDialog();
- break;
- case MenuCommandType.OfficalWeb:
- if (string.IsNullOrWhiteSpace(ApplicationParameter.WebSite))
- {
- MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.UI2014_NoOfficialWebsitePleaseConfigurationFile, Muchinfo.MTPClient.Resources.Client_Resource.UI2014_ConfigurationError);
- }
- else
- {
- var proc = new Process { StartInfo = { FileName = ApplicationParameter.WebSite } };
- proc.Start();
- }
- break;
- //case MenuCommandType.OnlineCS:
- // break;
- case MenuCommandType.AboutUs:
- var t = new AboutView(2)
- {
- Owner = Application.Current.MainWindow,
- WindowStartupLocation = WindowStartupLocation.CenterOwner
- };
- t.ShowDialog();
- break;
- #endregion
- case MenuCommandType.MarketQuote:
- case MenuCommandType.SelectedGoodses:
- MessengerHelper.DefaultSend(item, MessengerTokens.ChangeMarket);
- break;
- default:
- if (item.Command != null) ////默认实现自带操作的命令
- {
- item.Command.Execute(null);
- }
- break;
- }
- }
- /// <summary>
- /// Initializes the commands.
- /// </summary>
- private void InitializeCommands()
- {
- MenuCommand = new RelayCommand<SysMenuItem>((item) =>
- {
- if (item == null || (item.Children != null && item.Children.Any())) return;
- ExecuteCommand(item);
- });
- }
- #region 快捷键
- private RelayCommand<CommandFunc> _keyCommand;
- /// <summary>
- /// 初始化命令
- /// </summary>
- public RelayCommand<CommandFunc> KeyCommand
- {
- get
- {
- if (_keyCommand != null)
- {
- return _keyCommand;
- }
- _keyCommand = new RelayCommand<CommandFunc>((command) =>
- {
- ExecuteKeyCommand(command);
- });
- return _keyCommand;
- }
- }
- /// <summary>
- /// 执行命令
- /// </summary>
- /// <param name="command"></param>
- private void ExecuteKeyCommand(CommandFunc command)
- {
- if (this.IsLockScreen) ////锁屏时不执行命令
- {
- return;
- }
- var curMode = ViewModelLocator.MainContent.TabContetMode;
- switch (command)
- {
- case CommandFunc.OpenOrder:
- if (CanCommandEnable(MenuCommandType.BuyIn) &&
- UserManager.QuotationWindowType == TabContetMode.QuoteList)
- {
- var order = new OrderMessage()
- {
- Direction = Direction.Bid,
- OrderPriceMode = ePriceMode.PRICEMODE_MARKET
- };
- MessengerHelper.DefaultSend(order, MessengerTokens.OrderMessageToken);
- }
- break;
- case CommandFunc.OpenChart:
- MessengerHelper.DefaultSend(TabContetMode.QuoteChart, MessengerTokens.MainContentChange);
- break;
- case CommandFunc.BrowserBack: ////返回行情列表,在行情列表则提示是否退出
- var mode = ViewModelLocator.MainContent.TabContetMode;
- if (mode == TabContetMode.QuoteList)
- {
- OnClose();
- }
- else
- {
- MessengerHelper.DefaultSend(TabContetMode.QuoteList, MessengerTokens.MainContentChange);
- }
- break;
- case CommandFunc.QuoteInsert:
- if ((curMode == TabContetMode.QuoteList || curMode == TabContetMode.QuoteBoard) &&
- SelectedQuoteGoods != null)
- {
- if (ApplicationParameter.ShowChart == 1 || !UserManager.IsAccountLogin) ////游客登录也可看图表
- {
- //如果是在内容行上双击, 打开分析图表窗口
- //MessengerHelper.DefaultSend(new OpenQuoteChartWindowArg(QuoteListDataGrid.SelectedItem as QuoteGoods, CycleType.Minutes1),
- // MessengerTokens.OpenQuoteChartWindow);
- MessengerHelper.DefaultSend(TabContetMode.QuoteChart, MessengerTokens.MainContentChange);
- }
- }
- break;
- case CommandFunc.QuotePageDown:
- case CommandFunc.QuotePageup:
- if (curMode == TabContetMode.QuoteList || curMode == TabContetMode.QuoteChart)
- {
- MessengerHelper.DefaultSend<CommandFunc>(command, MessengerTokens.QuoteGoodsListToken);
- }
- break;
- case CommandFunc.GoodsF10:
- var FtenAddress = ApplicationParameter.FtenAddress;
- if (!string.IsNullOrEmpty(FtenAddress))
- {
- MessengerHelper.DefaultSend<TabContetMode>(TabContetMode.QuoteGoodsInfo,
- MessengerTokens.ChangeGoodsInfo);
- }
- break;
- case CommandFunc.Tab:
- if (UserManager.GetCurrentLayoutStyle() == LayoutStyle.Tradition)
- {
- MessengerHelper.DefaultSend(true, MessengerTokens.SetOrderFoucsToken);
- }
- break;
- case CommandFunc.Amount:
- MessengerHelper.DefaultSend(MenuCommandType.AccountInfo, MessengerTokens.MenuSelectChange);
- break;
- case CommandFunc.HoldDetail:
- MessengerHelper.DefaultSend(MenuCommandType.Position, MessengerTokens.MenuSelectChange);
- break;
- case CommandFunc.CompleteOrder:
- MessengerHelper.DefaultSend(MenuCommandType.TransactionOrder, MessengerTokens.MenuSelectChange);
- break;
- case CommandFunc.QuoteTik:
- if (SelectedQuoteGoods != null &&
- (SelectedQuoteGoods.TradeMode == eTradeMode.TRADEMODE_BIDDING ||
- SelectedQuoteGoods.TradeMode == eTradeMode.TRADEMODE_MARKETMAKE ||
- SelectedQuoteGoods.TradeMode == eTradeMode.TRADEMODE_BIDDINGMARKETMAKE))
- {
- MessengerHelper.DefaultSend<QuoteGoods>(SelectedQuoteGoods, MessengerTokens.ShowTikDetail);
- }
- MessengerHelper.DefaultSend(MenuCommandType.AccountInfo, MessengerTokens.MenuSelectChange);
- break;
- case CommandFunc.Buy:
- var tradeView = SimpleIoc.Default.GetInstance<TradeHeaderViewModel>();
- if (tradeView.CanCommandEnable(MenuCommandType.BuyIn))
- {
- tradeView.BuyCommand.Execute(null);
- }
- break;
- case CommandFunc.Sell:
- var tradeViewsell = SimpleIoc.Default.GetInstance<TradeHeaderViewModel>();
- if (tradeViewsell.CanCommandEnable(MenuCommandType.Sellout))
- {
- tradeViewsell.SellCommand.Execute(null);
- }
- break;
- case CommandFunc.Cancel:
- var orderView = SimpleIoc.Default.GetInstance<MOOrderDetailViewModel>();
- orderView.SearchOrderStatus = SearchOrderStatus.OnMarket;
- MessengerHelper.DefaultSend(MenuCommandType.EntrustOrder, MessengerTokens.MenuSelectChange);
- break;
- case CommandFunc.OpenTradeBoard:
- IsTradeVisible = !IsTradeVisible;
- break;
- case CommandFunc.TranFloatOrder:
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// 命令类型
- /// </summary>
- /// <param name="commandType"></param>
- /// <returns></returns>
- public bool CanCommandEnable(MenuCommandType commandType)
- {
- if (UserManager.TradeFuncMenus != null && UserManager.TradeFuncMenus.Any())
- {
- var tradeFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == commandType.ToString());
- if (tradeFunc != null)
- {
- return tradeFunc.IsEnabled;
- }
- }
- return false;
- }
- /// <summary>
- /// 初始化键命令
- /// </summary>
- /// <returns></returns>
- public List<KeyBinding> InitKeysCommand()
- {
- return _systemService.GetHomeKeyBindings(KeyCommand);
- }
- #endregion
- /// <summary>
- /// 将菜单的同级结点选择状态设置为False
- /// </summary>
- /// <param name="item">设置选择状态的菜单</param>
- private void SetInitializeCheck(SysMenuItem item)
- {
- if (item.ParentItem != null)
- {
- foreach (var childItem in item.ParentItem.Children)
- {
- childItem.IsChecked = false;
- }
- }
- item.IsChecked = true;
- SaveUserConfig(item); //只有设置布局的方可使用该方法
- }
- /// <summary>
- /// 保存用户主题布局
- /// </summary>
- /// <param name="item">设置的菜单</param>
- private void SaveUserConfig(SysMenuItem item)
- {
- switch (item.SysCommandType)
- {
- case MenuCommandType.Vertical:
- ////保存配置
- UserManager.SaveCurrentLayoutStyle(LayoutStyle.Vertical);
- break;
- case MenuCommandType.Horizontal:
- ////保存配置
- UserManager.SaveCurrentLayoutStyle(LayoutStyle.Horizontal);
- break;
- case MenuCommandType.Tradition:
- ////保存配置
- UserManager.SaveCurrentLayoutStyle(LayoutStyle.Tradition);
- break;
- case MenuCommandType.CoolBlack:
- ////保存配置
- UserManager.SaveCurrentColorStyle(ColorStyle.CoolBlack);
- break;
- case MenuCommandType.BlueWhite:
- ////保存配置
- UserManager.SaveCurrentColorStyle(ColorStyle.BlueWhite);
- break;
- case MenuCommandType.DarkBlue:
- ////保存配置
- UserManager.SaveCurrentColorStyle(ColorStyle.DarkBlue);
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// 设置系统主题
- /// </summary>
- public void InitializeThemes()
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- var defaultLayout = UserManager.GetCurrentLayoutStyle();
- MainLayoutUpdate(defaultLayout);
- var defaultColor = UserManager.GetCurrentColorStyle();
- ThemesUpdate(defaultColor);
- }));
- }
- /// <summary>
- /// 切换主题加载资源
- /// </summary>
- /// <param name="colorStyle"></param>
- private void ThemesUpdate(ColorStyle colorStyle)
- {
- string themesType;
- switch (colorStyle)
- {
- case ColorStyle.CoolBlack:
- themesType = "CoolBlack";
- break;
- //case ColorStyle.SkyBlue:
- // themesType = "SkyBlue";
- // break;
- //case ColorStyle.DarkRed:
- // themesType = "DarkRed";
- // break;
- case ColorStyle.DarkBlue:
- themesType = "DarkBlue";
- break;
- case ColorStyle.BlueWhite:
- themesType = "BlueWhite";
- break;
- default:
- themesType = "DarkBlue";
- break;
- }
- string url = string.Format("/Client.Main;component/Themes/{0}/Style.xaml", themesType);
- var resource = (ResourceDictionary)Application.LoadComponent(new Uri(url, UriKind.Relative));
- if (CurrentStyle != null && Application.Current.Resources.MergedDictionaries.Contains(CurrentStyle))
- {
- Application.Current.Resources.MergedDictionaries.Remove(CurrentStyle as ResourceDictionary);
- }
- else
- {
- for (int i = 0; i < Application.Current.Resources.MergedDictionaries.Count; i++)
- {
- var resourceDic = Application.Current.Resources.MergedDictionaries[i];
- if (resourceDic != null)
- {
- resourceDic.Clear();
- }
- }
- // Application.Current.Resources.MergedDictionaries.Clear();
- }
- //if (ApplicationParameter.DataGridColor == "0") //显示纯色
- //{
- // resource.Add("MuchinfoBrush35", System.Windows.Media.Brushes.Transparent);
- // resource.Add("MuchinfoBrush36", System.Windows.Media.Brushes.Transparent);
- //}
- Application.Current.Resources.MergedDictionaries.Add(resource);
- CurrentStyle = resource;
- MessengerHelper.DefaultSend<string>(themesType, MessengerTokens.RegisterResourceChange);
- ////主題变化时强制通知商品颜色改变
- MessengerHelper.DefaultSend(true, MessengerTokens.NotifyQuoteGoodsColorChanged);
- }
- private void MainLayoutUpdate(LayoutStyle layout)
- {
- LogInfoHelper.WriteInfo("Starting MainLayoutUpdate......");
- try
- {
- switch (layout)
- {
- case LayoutStyle.Horizontal:
- MainContent = new HorizontalLayout();
- break;
- case LayoutStyle.Vertical:
- MainContent = new VerticalLayout();
- break;
- case LayoutStyle.Tradition:
- MainContent = new TraditionLayout();
- break;
- default:
- MainContent = new HorizontalLayout();
- break;
- }
- LogInfoHelper.WriteInfo("end MainLayoutUpdate,begin send Message MessengerTokens.UpdateLayoutChange");
- MessengerHelper.DefaultSend(layout, MessengerTokens.UpdateLayoutChange);
- }
- catch (Exception ex)
- {
- LogInfoHelper.WriteInfo("布局异常..." + ex.ToString());
- }
- }
- /// <summary>
- /// Called when [close].
- /// </summary>
- private void OnClose()
- {
- if (MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.UI2014_IsOrNotExit,
- Muchinfo.MTPClient.Resources.Client_Resource.UI2014_Tips) == MessageBoxResult.Yes)
- {
- if (UserManager.IsAccountLogin)
- {
- ////保存布局及列表行情抬头
- MessengerHelper.DefaultSend(string.Empty, MessengerTokens.SaveLayout);
- //手动发送登出消息
- var service = SimpleIoc.Default.GetInstance<ILoginService>();
- if (service != null) service.TradeAccountLogout(UserManager.CurrentTradeAccount);
- }
- WindowHelper.RerunApplication(false);
- }
- }
- private void MainPanelIsEnableMethod(bool mainPanelIsUnlock)
- {
- if (mainPanelIsUnlock == true)
- {
- WindowCollection list = Application.Current.Windows;
- foreach (Window w in list)
- {
- if (w.Owner == null)
- {
- MainPanelVisibility = Visibility.Collapsed;
- }
- else
- {
- w.WindowState = WindowState.Normal;
- w.Opacity = 1;
- }
- }
- }
- else
- {
- MainPanelVisibility = Visibility.Visible;
- }
- }
- #endregion Private Methods
- #region 公告处理
- /// <summary>
- /// 查询是否有未读公告
- /// </summary>
- /// <param name="itemList">数据列表</param>
- protected void NoticeCountSuccess(List<NoticeCount> itemList)
- {
- if (itemList != null && itemList.Any())
- {
- var notice = itemList.FirstOrDefault((item) => item.MsgType == MsgTypeEnum.Bulletin && item.MsgCount > 0);
- if (notice != null) //弹出公告
- {
- MessengerHelper.DefaultSend<MsgTypeEnum>(notice.MsgType, MessengerTokens.AnnouncementMessage);
- return; //不用两个都弹出来
- }
- var notify = itemList.FirstOrDefault((item) => item.MsgType == MsgTypeEnum.NTF && item.MsgCount > 0);
- if (notify != null) //弹出消息
- {
- MessengerHelper.DefaultSend<MsgTypeEnum>(notify.MsgType, MessengerTokens.AnnouncementMessage);
- }
- }
- }
- protected void QueryErrorCallback(ErrorEntity errorEntity)
- {
- //IsBusy = false;
- //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- //{
- // ErrorManager.ShowReturnError(errorEntity, Muchinfo.MTPClient.Resources.Client_Resource.APP_Tips, false);
- //}));
- }
- #endregion
- #region 下单
- /// <summary>
- /// 下单类型
- /// </summary>
- /// <param name="tradeViewModel">下单模型</param>
- private void SetOrderView(TradeOrderViewModel tradeViewModel)
- {
- IsOrderVisible = true;
- TradeViewModel = tradeViewModel;
- }
- //ViewLoadedCommand = new RelayCommand<Home>((MainPage) =>
- //{
- // view.MainPanel.Children.Clear();
- // UserManager.UserManagerCurrentMarketType = MenuCommandType.CustomQuote;
- // UserManager.QuotationWindowType = QuotationWindowType.Board;
- // _oldTabIndex = 9;
- // WindowHelper.OpenDefaultQuoteListView(false);
- //});
- private bool _isOrderVisible;
- /// <summary>
- /// 是否显示下单
- /// </summary>
- public bool IsOrderVisible
- {
- get { return _isOrderVisible; }
- set { Set(() => IsOrderVisible, ref _isOrderVisible, value); }
- }
- private TradeOrderViewModel _tradeViewModel;
- /// <summary>
- /// 下单逻辑
- /// </summary>
- public TradeOrderViewModel TradeViewModel
- {
- get { return _tradeViewModel; }
- set { Set(() => TradeViewModel, ref _tradeViewModel, value); }
- }
- #endregion
- #region 交易登录初始化
- /// <summary>
- /// 交易数据初始化
- /// </summary>
- private void TradeDataInit()
- {
- IsBusy = true;
- ////初始化我的自选
- FavoriteManager.InitializeFavorite(MenuNames.QuotationFavorite);
- //先查询市场信息,再查询商品信息
- ulong lastUpdateTimeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.MarketsUTime);
- if (MarketResxManager.MarketResx.ResourceHashtable == null || MarketResxManager.MarketResx.Version != lastUpdateTimeUTC)
- {
- _loginService.MarketsQuerySearch(lastUpdateTimeUTC, MarketsInfoCallBack, ErrorEntityCallBack);
- }
- else
- {
- MarketsInfoModel[] marketsArr = Newtonsoft.Json.JsonConvert.DeserializeObject<MarketsInfoModel[]>(Newtonsoft.Json.JsonConvert.SerializeObject(MarketResxManager.MarketResx.ResourceHashtable.Values));
- List<MarketsInfoModel> marketLst = marketsArr.ToList();
- CacheManager.LoadMarketInfoList(marketLst);
- MarketsInfoCallBack(marketLst, 0, false);
- }
- SearchDeliveryGoods();
- }
- /// <summary>
- /// ///查询交割关系列表-成功返回
- /// </summary>
- private void QueryAllDeliveryRelationSuccess(List<Muchinfo.MTPClient.Data.Model.Delivery.RelationPAndXGoodsInfoModel> itemList)
- {
- Muchinfo.MTPClient.Infrastructure.Cache.CacheManager.AllDeliveryRelationList = itemList;
- }
- private void SearchAllGoodsUnitCallBack(List<Muchinfo.MTPClient.Data.Model.DBTableMsg.GoodsUnit> goodUnit)
- {
- Muchinfo.MTPClient.Infrastructure.Cache.CacheManager.TradeGoodsUnit = goodUnit;
- foreach (var quoteGoods in CacheManager.CacheGoodsBaseInfos)
- {
- quoteGoods.AgreeUnitDisplay = quoteGoods.GoodsParameters.AgreeUnit.ToString() + CacheManager.TradeGoodsUnit.Where(x => x.UNITID == quoteGoods.GoodsParameters.AgreeUnitType).Select(x => x.GOODSUNITNAME).FirstOrDefault();
- }
- }
- /// <summary>
- /// 查询失败
- /// </summary>
- /// <param name="error"></param>
- private void ErrorEntityCallBack(ErrorEntity error)
- {
- LogInfoHelper.WriteInfo("MarketsQuerySearch or GoodsQuerySearch or GoodsGroup callback Failed");
- IsBusy = false;
- InitComplete();
- FuncMenusErrorFunc(error);
- }
- private void AccountBaseInfoInitError(ErrorEntity error)
- {
- var format = "查询账号基本信息:" + string.Format(ErrorManager.FormatErrorMsg(error));
- LogInfoHelper.WriteInfo(format);
- ////清除链路
- // LinkManager.Instance.Dispose();
- }
- /// <summary>
- /// 市场成功查询MTP2.0
- /// </summary>
- /// <param name="MarketsInfoList"></param>
- public void MarketsInfoCallBack(List<MarketsInfoModel> MarketsInfoList, ulong marketStamp = 0, bool bUpdate = true)
- {
- //登陆后基本数据查询
- _loginService.LoginQuerySearch(UserManager.CurrentTradeAccount.LoginID, LoginQueryType.All, LoadAccountBaseInfoCallback, AccountBaseInfoInitError);
- if (bUpdate)
- {
- //如果是调用接口更新的系统参数,需要更新对应的本地文件
- var hashtable = new Hashtable();
- foreach (var market in MarketsInfoList)
- {
- hashtable.Add(market.MarketID, market);
- }
- MarketResxManager.SaveMarketResx(hashtable, marketStamp, UserManager.UserDataFolder);
- }
- }
- /// <summary>
- /// 商品成功查询MTP2.0
- /// </summary>
- /// <param name="GoodsInfoList">The goods information list.</param>
- /// <param name="goodsStamp">The goods stamp.</param>
- /// <param name="bUpdate">if set to <c>true</c> [b update].</param>
- /// <param name="midParam">The mid parameter.</param>
- public void GoodsInfoCallBack(List<QuoteGoods> GoodsInfoList, ulong goodsStamp = 0, bool bUpdate = true, List<TradeGoodsFeeRule> midParam = null)
- {
- if (bUpdate)
- {
- //如果是调用接口更新的系统参数,需要更新对应的本地文件
- var hashtable = new Hashtable();
- foreach (var goods in GoodsInfoList)
- {
- hashtable.Add(goods.GoodsCode, goods);
- }
- GoodsResxManager.SaveGoodsResx(hashtable, goodsStamp, UserManager.UserDataFolder);
- }
- ////创建行情链路, 链路成功后订阅商品
- //LinkManager.Instance.CreateQuoteTcpLink();
- //查询交易端配置的菜单--菜单权限从服务端不使用缓存
- ulong menuUTime = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.MenuUTime);
- _loginService.QueryAccountFuncMenu(menuUTime, midParam, FuncMenusSuccess, FuncMenusErrorFunc);
-
- //改成串行下载数据
- /*
- ////查询商品组信息
- //_loginService.QueryGoodsGroup(null, ErrorEntityCallBack);
- ////外部交易所查询
- //_loginService.QueryExternalExchange(ExternalExchangeCallBack, ErrorEntityCallBack);
- ////查询持仓汇总
- //var queryList = new List<QueryCommonParam>
- //{
- // new QueryCommonParam() {ParamKey = "accountId", ParamValue = UserManager.CurrentTradeAccount.FundsAccountId + string.Empty}
- //};
- //_orderService.QueryHoldingPosistion(QueryStatement.TradePositionDetail, queryList, QuerySuccessCallBack, QueryErrorCallback);
- //_commonQueryService.QueryMarketRun(0, MarketRunQuerySuccessCallBack, QueryErrorCallback);
- */
- }
- /// <summary>
- /// Markets the run query success call back.
- /// </summary>
- /// <param name="models">The models.</param>
- private void MarketRunQuerySuccessCallBack(List<MarketRunModelNew> models)
- {
- // 这里需要把所属母账户也带上 <- 又不用带了……
- var fundsAccountIDs = string.Join(",", UserManager.CurrentTradeAccount.FundsAccountIds);
- //if (UserManager.CurrentTradeAccount.FundsAccounts.Count > 0 && UserManager.CurrentTradeAccount.FundsAccounts[0].ParentAccountID != 0)
- //{
- // fundsAccountIDs += string.Format(",{0}", UserManager.CurrentTradeAccount.FundsAccounts[0].ParentAccountID);
- //}
- // 查询账户汇率模板
- _commonQueryService.QueryTradeRateTmpConfig(fundsAccountIDs, null, QueryErrorCallback);
- // 查询外部汇率模版配置表
- //_commonQueryService.QueryExtenalTradeRateTmpConfig(fundsAccountIDs, DateTime.Now.ToString("yyyyMMdd"), null, QueryErrorCallback);
- // 查询资金账户汇率
- //_commonQueryService.QueryTaAccountExchangeRate(fundsAccountIDs, null, QueryErrorCallback);
- CacheManager.UpdateMarketRun(models);
- }
- /// <summary>
- /// 外部交易所查询成功调用
- /// </summary>
- /// <param name="externalExchages"></param>
- private void ExternalExchangeCallBack(List<ExternalExchangeModel> externalExchages)
- {
- ////查询交易端配置的菜单
- List<Exchange> exchangeLst = new List<Exchange>();
- foreach (var exchange in externalExchages)
- {
- var newExchanage = new Exchange
- {
- ExchangeId = exchange.AutoID,
- ExchangeCode = exchange.ExExchangeCode,
- ExchangeName = exchange.ExExchangeName,
- IsMarketPrice = exchange.IsMarketPrice
- };
- exchangeLst.Add(newExchanage);
- }
- //使用外部交易所做为交易所缓存
- CacheManager.LoadExchangeInfo(exchangeLst);
- //重新构建分类菜单
- MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.UpdateQuoteMarket);
- //查询持仓汇总
- var queryList = new List<QueryCommonParam>
- {
- new QueryCommonParam() {ParamKey = "accountId", ParamValue = UserManager.CurrentTradeAccount.FundsAccountId + string.Empty}
- };
- _orderService.QueryHoldingPosistion(QueryStatement.TradePositionDetail, queryList, QuerySuccessCallBack, ErrorEntityCallBack);
- CreateLoaclMenu(UserManager.AccessFuncMenus);
- }
- /// <summary>
- /// Queries the success call back.
- /// </summary>
- /// <param name="orders">The orders.</param>
- private void QuerySuccessCallBack(List<HoldingSummary> orders)
- {
- _commonQueryService.QueryMarketRun(0, MarketRunQuerySuccessCallBack, ErrorEntityCallBack);
- }
- /// <summary>
- /// 构建菜单
- /// </summary>
- /// <param name="funcs"></param>
- private void FuncMenusSuccess(List<SysMenuItem> funcs, ulong menuUTime, List<TradeGoodsFeeRule> GoodsRuleLst, bool update = true)
- {
- UserManager.LocalFuncMenus = eSystemMenuValue.CreateInstance().menu;//实例化本地菜单数据;
- UserManager.FixedFuncMenus = eSystemMenuValue.CreateInstance().fixedMenuList;
- List<SysMenuItem> menus;
- try
- {
- //可使用菜单为 本地固定菜单+服务端获取的且终端已实现的菜单 - dyp
- menus = UserManager.FixedFuncMenus.Union(funcs.Where(z => UserManager.LocalFuncMenus.Select(t => t.Value).Contains(z.FuncMenuCode))).ToList();
- //对菜单进行排序 - dyp
- menus.Sort((x, y) => { return x.SortId > y.SortId ? 1 : (x.SortId == y.SortId ? 0 : -1); });
- }
- catch
- {
- menus = new List<SysMenuItem>();
- }
- //更新交集的菜单
- if (update)
- {
- var hashtable = new Hashtable();
- foreach (var menu in menus)
- {
- hashtable.Add(menu.FuncMenuCode, menu);
- }
- MenuResxManager.SaveMenuResx(hashtable, menuUTime, UserManager.UserDataFolder);
- }
- UserManager.AccessFuncMenus = menus;
- // ////是否可看
- // GetDepositPlan();
- // ////更新市场菜单
- //// MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.UpdateQuoteMarket);
- CreateLoaclMenu(menus);
- if (menus != null && menus.Any())
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- ViewModelLocator.MenuTree.LoadMenus(menus);
- //缓存 -交易商品的费用计算方式,与交易规则
- CacheManager.TradeGoodsFeeRules = GoodsRuleLst.ToArray<TradeGoodsFeeRule>().ToDictionary(key => key.GoodsID, value => value);
- ///todo:保存在缓存中
- IsBusy = false;
- InitComplete();
- }));
- }
- //查询商品组信息
- _loginService.QueryGoodsGroup(null, ErrorEntityCallBack);
- //外部交易所查询
- _loginService.QueryExternalExchange(ExternalExchangeCallBack, ErrorEntityCallBack);
- }
- /// <summary>
- /// 错误处理
- /// </summary>
- /// <param name="error">错误内容</param>
- private void FuncMenusErrorFunc(ErrorEntity error)
- {
- var funcs = new List<SysMenuItem>();
- UserManager.LocalFuncMenus = eSystemMenuValue.CreateInstance().menu;//实例化本地菜单数据;
- UserManager.FixedFuncMenus = eSystemMenuValue.CreateInstance().fixedMenuList;
- funcs.AddRange(UserManager.FixedFuncMenus);
- UserManager.AccessFuncMenus = funcs;
- CreateLoaclMenu(funcs); ////查询不到菜单时显示默认
- if (funcs != null && funcs.Any())
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- ViewModelLocator.MenuTree.LoadMenus(funcs);
- }));
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 登录后初始化内容
- /// </summary>
- /// <param name="accountInfo">与账号相关基本信息</param>
- private void LoadAccountBaseInfoCallback(AccountBaseInfoModel accountInfo)
- {
- ulong lastUpdateTimeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.GoodsUTime);
- if (GoodsResxManager.GoodsResx.ResourceHashtable == null || GoodsResxManager.GoodsResx.Version != lastUpdateTimeUTC)
- {
- _loginService.GoodsInfoSearch(lastUpdateTimeUTC, accountInfo.GoodsRuleAndFeeList, GoodsInfoCallBack, ErrorEntityCallBack);
- }
- else
- {
- QuoteGoods[] quoteGoodsArr = Newtonsoft.Json.JsonConvert.DeserializeObject<QuoteGoods[]>(Newtonsoft.Json.JsonConvert.SerializeObject(GoodsResxManager.GoodsResx.ResourceHashtable.Values));
- var goodsLst =quoteGoodsArr == null? new List<QuoteGoods>(): quoteGoodsArr.OrderBy(z=>z.GoodsCode).ToList();
- CacheManager.LoadGoodsInfoList(goodsLst, GoodsFromScr.Trade);
- GoodsInfoCallBack(goodsLst, 0, false, accountInfo.GoodsRuleAndFeeList);
- }
- }
- private void InitComplete()
- {
- //创建行情链路, 链路成功后订阅商品
- // LinkManager.Instance.CreateQuoteTcpLink();
- //进入主界面后再开户断线重连机制
- LinkManager.Instance.StartReconnect();
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- //设置系统主题
- InitializeThemes();
- InitLockTimer();///启动锁屏
- ////公告查询处理(处理先显示公告时,样式不一致)--pendding dk
- // _announcementService.QueryNoticeCount(UserManager.CurrentTradeAccount.AccountId, NoticeCountSuccess, QueryErrorCallback);
- ////更新市场菜单
- MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.UpdateQuoteMarket);
- MessengerHelper.DefaultSend(true, MessengerTokens.CheckTokenMsg); ///同步时间
- SimpleIoc.Default.GetInstance<MainContentViewModel>().InitMainPanel(); ////主界面内容 更新
- RaisePropertyChanged(() => IsAccountLogin);
- Task.Factory.TryStartNew(() =>
- {
- //var random = new Random();
- //var seconds = random.Next(2000, 10000); ////随机时间再取资源信息
- //var seconds = random.Next(1, 10); ////随机时间再取资源信息
- //Thread.Sleep(seconds);
- //获取资源版本号
- //_systemService.QueryResxVer(ResxVerSuccess, QueryResxVerError);
- if (CacheManager.CacheLastUpdateTimeList != null)
- {
- SearchErrorResxAndConstResx();
- SearchRiskMsgResx();
- }
- });
- }));
- }
- /// <summary>
- /// 查询数据库错误资源和常量资源信息
- /// </summary>
- private void SearchErrorResxAndConstResx()
- {
- ulong errorCodeTimeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.ErrorcodeUTime);
- if (MuchinfoException.ErrorResx.ResourceHashtable == null || MuchinfoException.ErrorResx.Version != errorCodeTimeUTC)
- {
- //错误码字典查询 MTP2.0
- _loginService.ErrorCodeQuerySearch(errorCodeTimeUTC, ErrorCodeResxCallback, QueryResxVerError);
- }
- ulong constTimeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.DirctionaryUTime);
- if (ConstResxManager.ConstResx.ResourceHashtable == null || ConstResxManager.ConstResx.Version != constTimeUTC)
- {
- //枚举常量字典查询 MTP2.0
- _loginService.DictionaryQuerySearch(constTimeUTC, ConstCodeResxCallback, QueryResxVerError);
- }
- }
- private void SearchDeliveryGoods()
- {
- ulong DeliveryGoodsUTime = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.DvGoodsUTime);
- if (DeliveryResxManager.DeliveryResx.ResourceHashtable == null || DeliveryResxManager.DeliveryResx.Version != DeliveryGoodsUTime)
- {
- //错误码字典查询 MTP2.0
- _loginService.DeliveryGoodsQuerySearch(DeliveryGoodsUTime, DeliveryGoodsCallback, DeliveryGoodsError);
- }
- else
- {
- DeliveryGoodsInfoModel[] deliveryGoodsArr = Newtonsoft.Json.JsonConvert.DeserializeObject<DeliveryGoodsInfoModel[]>(Newtonsoft.Json.JsonConvert.SerializeObject(DeliveryResxManager.DeliveryResx.ResourceHashtable.Values));
- List<DeliveryGoodsInfoModel> retLst = deliveryGoodsArr.ToList();
- CacheManager.CacheDeliveryGoodsInfo = retLst;
- }
- }
- private void DeliveryGoodsCallback(List<DeliveryGoodsInfoModel> retLst, ulong DeliveryGoodsUTime = 0, bool bUpdate = true)
- {
- if (bUpdate)
- {
- //如果是调用接口更新的系统参数,需要更新对应的本地文件
- var hashtable = new Hashtable();
- foreach (var deliveryGoods in retLst)
- {
- hashtable.Add(deliveryGoods.DeliveryGoodsCode, deliveryGoods);
- }
- DeliveryResxManager.SaveDeliveryResx(hashtable, DeliveryGoodsUTime, UserManager.UserDataFolder);
- }
- CacheManager.CacheDeliveryGoodsInfo = retLst;
- }
- private void DeliveryGoodsError(ErrorEntity errorEntity)
- {
- var format = "交割商品查询" + string.Format(ErrorManager.FormatErrorMsg(errorEntity));
- LogInfoHelper.WriteInfo(format);
- }
- /// <summary>
- /// 错误资源成功回调
- /// </summary>
- /// <param name="descritions"></param>
- private void ErrorCodeResxCallback(List<ErrorCodeInfoModel> descritions, ulong errCodeStamp)
- {
- Task.Factory.TryStartNew(() =>
- {
- var hashtable = new Hashtable();
- foreach (var desc in descritions)
- {
- hashtable.Add(desc.ErrorCode, desc.ErrorMsg);
- }
- MuchinfoException.ErrorResxSaveRep(hashtable, errCodeStamp);
- });
- }
- /// <summary>
- /// 常量资源成功回调
- /// </summary>
- /// <param name="descritions"></param>
- private void ConstCodeResxCallback(List<DictionaryInfoModel> descritions, ulong constStamp)
- {
- Task.Factory.TryStartNew(() =>
- {
- var hashtable = new Hashtable();
- foreach (var desc in descritions)
- {
- hashtable.Add(desc.FieldCode + "_" + desc.Key, desc.Value);
- }
- ConstResxManager.ConstResxSaveRep(hashtable, constStamp, UserManager.UserDataFolder);
- });
- }
- private void ResxVerSuccess(List<ResxVerInfo> resxVer)
- {
- if (resxVer != null && resxVer.Any())
- {
- _resxVerInfos = resxVer.ToDictionary((item) => item.Versiontype);
- if (_resxVerInfos.ContainsKey(ResxVerType.errorCode))
- {
- if (MuchinfoException.ErrorResx == null || MuchinfoException.ErrorResx.Version < _resxVerInfos[ResxVerType.errorCode].Versionno)
- {
- _systemService.QueryResxDescrition(ResxVerType.errorCode, ResxCallback, QueryResxVerError);
- }
- }
- if (_resxVerInfos.ContainsKey(ResxVerType._const))
- {
- if (ConstResxManager.ConstResx == null || ConstResxManager.ConstResx.Version < _resxVerInfos[ResxVerType._const].Versionno)
- {
- _systemService.QueryResxDescrition(ResxVerType._const, ResxCallback, QueryResxVerError);
- }
- }
- }
- }
- /// <summary>
- /// 查询资源回调
- /// </summary>
- /// <param name="descrition"></param>
- private void ResxCallback(List<ResxDescrition> descritions, ResxVerType varType)
- {
- Task.Factory.TryStartNew(() =>
- {
- var hashtable = new Hashtable();
- foreach (var desc in descritions)
- {
- hashtable.Add(desc.ConstKey, desc.Remarks);
- }
- if (varType == ResxVerType._const)
- {
- ConstResxManager.ConstResxSaveRep(hashtable, _resxVerInfos[varType].Versionno, UserManager.UserDataFolder);
- }
- else if (varType == ResxVerType.errorCode)
- {
- MuchinfoException.ErrorResxSaveRep(hashtable, _resxVerInfos[varType].Versionno);
- }
- });
- }
- private void QueryResxVerError(ErrorEntity errorEntity)
- {
- var format = "资源" + string.Format(ErrorManager.FormatErrorMsg(errorEntity));
- LogInfoHelper.WriteInfo(format);
- }
- #region 风险协议书获取
- /// <summary>
- /// 封装获取风险协议书的方法,如有更新就调用接口重新获取
- /// </summary>
- private void SearchRiskMsgResx()
- {
- ulong riskMsgTimeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.RiskMsgUTime);
- if (RiskMsgResxManager.RiskMsgResx.ResourceHashtable == null || RiskMsgResxManager.RiskMsgResx.Version != riskMsgTimeUTC)
- {
- //错误码字典查询 MTP2.0
- _loginService.RiskTipQuerySearch(riskMsgTimeUTC, RiskMsgResxCallback, QueryResxVerError);
- }
- }
- private void RiskMsgResxCallback(RiskTipQueryRspModel risktip, ulong risktipStamp = 0)
- {
- Task.Factory.TryStartNew(() =>
- {
- var hashtable = new Hashtable();
- hashtable.Add(risktip.TipTitle, risktip);
- RiskMsgResxManager.SaveRiskMsgResx(hashtable, risktipStamp, UserManager.UserDataFolder);
- });
- }
- #endregion
- #endregion Methods
- #region 锁屏
- private bool _isLockScreen;
- /// <summary>
- /// 是否锁屏
- /// </summary>
- public bool IsLockScreen
- {
- get { return _isLockScreen; }
- set
- {
- Set(() => IsLockScreen, ref _isLockScreen, value);
- }
- }
- /// <summary>
- /// 锁屏方式
- /// </summary>
- public bool LockScreenType
- {
- get
- {
- return ApplicationParameter.IsShowBGLockSreen == 1;
- }
- }
- /// <summary>
- /// 锁屏定时器
- /// </summary>
- private DispatcherTimer _dispatcherTimer;
- private void InitLockTimer(bool result)
- {
- InitLockTimer();
- }
- /// <summary>
- /// 初始化锁屏
- /// </summary>
- private void InitLockTimer()
- {
- var userInfo = UserManager.GetCurrentUserInfo(); ////交易菜单设置
- int time = 0;
- if (userInfo.TradeParams == null)
- {
- time = ApplicationParameter.LockSreenTime;
- }
- else
- {
- time = userInfo.TradeParams.LockScreenTime;
- }
- if (_dispatcherTimer != null)
- {
- _dispatcherTimer.Stop();
- }
- if (time > 0 && UserManager.IsAccountLogin) ////配置了时间才进行锁屏
- {
- _dispatcherTimer = new DispatcherTimer();
- _dispatcherTimer.Tick += _dispatcherTimer_Tick;
- int i = 100;
- _dispatcherTimer.Interval = new TimeSpan(0, 0, i);
- _dispatcherTimer.Start();
- }
- }
- private string _password;
- /// <summary>
- /// 密码
- /// </summary>
- public string Password
- {
- get { return _password; }
- set { Set(() => Password, ref _password, value); }
- }
- private string _errorMsg;
- /// <summary>
- /// 错误消息
- /// </summary>
- public string ErrorMsg
- {
- get { return _errorMsg; }
- set { Set(() => ErrorMsg, ref _errorMsg, value); }
- }
- private void _dispatcherTimer_Tick(object sender, EventArgs e)
- {
- var userInfo = UserManager.GetCurrentUserInfo(); ////交易菜单设置
- int time = 0;
- if (userInfo.TradeParams == null)
- {
- time = ApplicationParameter.LockSreenTime;
- }
- else
- {
- time = userInfo.TradeParams.LockScreenTime;
- }
- var LastInputTime = GetLastInputInfoHelper.GetLastInputTime();
- if (LastInputTime >= time)
- {
- #if DEBUG
- Console.WriteLine("时间:" + LastInputTime);
- #endif
- WindowCollection list = Application.Current.Windows;
- foreach (Window w in list)
- {
- if (w == Application.Current.MainWindow) ////主窗口
- {
- ////切换到行情列表 , 其他浏览器控件
- MessengerHelper.DefaultSend(TabContetMode.QuoteList, MessengerTokens.MainContentChange);
- }
- else
- {
- w.Close(); ////关其他窗口
- }
- }
- _dispatcherTimer.Stop();
- IsLockScreen = true; ////显示锁屏
- MessengerHelper.DefaultSend(false, MessengerTokens.LockScreenSetHideExpandTradeToken);
- //var lockScreen=new LockScreenWin(){Owner = Application.Current.MainWindow,WindowStartupLocation =WindowStartupLocation.CenterOwner };
- //lockScreen.ShowDialog();
- }
- }
- public RelayCommand UnLockCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- if (Vailed())
- {
- ErrorMsg = string.Empty;
- var password = EncryptHelper.SHA256(UserManager.CurrentTradeAccount.LoginID.ToString() + Password).ToLower();
- if (password.Equals(UserManager.CurrentTradeAccount.Md5Password))
- {
- IsLockScreen = false;
- Password = string.Empty;
- if (_dispatcherTimer == null)
- {
- if (ApplicationParameter.LockSreenTime > 0 && UserManager.IsAccountLogin) ////配置了时间才进行锁屏
- {
- _dispatcherTimer = new DispatcherTimer();
- _dispatcherTimer.Tick += _dispatcherTimer_Tick;
- int i = 100;
- _dispatcherTimer.Interval = new TimeSpan(0, 0, i);
- _dispatcherTimer.Start();
- }
- }
- else
- {
- _dispatcherTimer.Start();
- }
- MessengerHelper.DefaultSend(true, MessengerTokens.LockScreenSetHideExpandTradeToken);
- }
- else
- {
- //ErrorMsg = Client_Resource.Lock_loginpasswordError;
- MessageBoxHelper.ShowInfo(Client_Resource.Lock_loginpasswordError, Client_Resource.UI2014_Tips, true);
- }
- }
- });
- }
- }
- public RelayCommand LoginOutCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- this.OnClose();
- });
- }
- }
- private bool Vailed()
- {
- if (string.IsNullOrWhiteSpace(Password) || Password.Length < 6)
- {
- MessageBoxHelper.ShowInfo(Client_Resource.UI2014_AccountNotLessThan6Characters, Client_Resource.UI2014_Tips, true);
- return false;
- }
- return true;
- }
- #endregion
- #endregion
- }
- }
|