using System.Collections; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Data.Model.Config; using Muchinfo.MTPClient.Data.Model.Delivery; using Muchinfo.MTPClient.Data.Model.Listing; using Muchinfo.MTPClient.Data.Model.Sale; using Muchinfo.MTPClient.Infrastructure.Enums; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.IService; using Muchinfo.PC.Common.Bosn; using Muchinfo.PC.Common.Helpers; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Threading; using System.Windows; using Muchinfo.MTPClient.Data.DTO; using Muchinfo.MTPClient.Infrastructure.Cache; namespace Muchinfo.MTPClient.Infrastructure.Utilities { /// /// UserManager类 /// public class UserManager { #region 字段 private static object _lockObject = new object(); /// /// 本地数据文件后缀名 /// public const string LocalDataExtensionName = ".dll"; #endregion #region 公有属性 /// /// 当前列表显示的商品 /// /// The current goods i ds. public static List CurrentGoodsIds { get; set; } /// /// 交易面板选中的当前Id /// public static int CurrentGoodsId { get; set; } #region 当前商品是否有商品 private static bool _currentGroupHasGoods=false; /// /// 当前商品是否有商品 /// public static bool CurrentGroupHasGoods { get { return _currentGroupHasGoods; } set { _currentGroupHasGoods = value; } } #endregion /// /// 主界面是否被解锁 //todo:什么用? /// public static bool MainPanelIsUnLock { get; set; } /// /// 行情窗口类型-List/Board /// /// The type of the quotation. public static TabContetMode QuotationWindowType { get; set; } /// /// 当前用户 /// public static UserInfo CurrentInfo; #endregion #region 用户缓存信息 private static List _tradeAccounts = new List(); /// /// 登录的交易账号集合 /// public static List TradeAccounts { get { return _tradeAccounts; } } private static TradeAccount _currentTradeAccount; /// /// 当前选中的交易账号 /// public static TradeAccount CurrentTradeAccount { get { return _currentTradeAccount; } set { _currentTradeAccount = value; //当时账号更新的交易Header需更新 MessengerHelper.DefaultSend(_currentTradeAccount, MessengerTokens.UpdateTradeAccount); } } /// /// 是否为游客登录 /// public static bool IsAccountLogin { get; set; } /// /// 关注商品列表 /// private static List _foucusGoodsList; /// /// 游客登录查询的商品 /// public static List BrownSaleGoodses { get; set; } /// /// 用户名可操作的菜单 /// public static List AccessFuncMenus { get; set; } /// /// 本地固定菜单 /// public static List FixedFuncMenus { get; set; } /// /// 缓冲本地菜单 /// public static Dictionary LocalFuncMenus { get; set; } /// /// 获取菜单类型 /// /// /// public static MenuCommandType GetMenuCommandType(string FuncMenuCode) { return UserManager.LocalFuncMenus.Where(x => x.Value == FuncMenuCode).Select(x => x.Key).FirstOrDefault(); } /// /// 获取菜单对应ResourceCode /// /// public static string GetMenuCommandValue(MenuCommandType typeKey) { return UserManager.LocalFuncMenus.Where(x => x.Key == typeKey).Select(x => x.Value).FirstOrDefault(); } private static List _tradeMenuItems=new List(); /// /// 交易菜单 /// public static List TradeFuncMenus { get { return _tradeMenuItems; } set { _tradeMenuItems=value; } } /// /// Gets or sets the trade rate temporary configuration. /// /// The trade rate temporary configuration. public static List TradeRateTmpConfigs { get; set; } /// /// 外部汇率模版配置表 /// /// The trade rate temporary configuration. public static List ExtenalTradeRateTmpConfigs { get; set; } /// /// 资金账户汇率模版配置 /// /// The trade rate temporary configuration. public static List TaAccountExchangeRateConfigs { get; set; } #endregion #region 用户数据路径 /// /// 系统配置路径 /// public static string SysConfigFolderPath { get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config"); } } /// /// 获取登录用户或游客配置的文件夹 /// /// The user settings folder. public static string UserSettingsFolder { get { var usersFolder = UsersSettingsFolder; var folder = CurrentTradeAccount == null || CurrentTradeAccount.LoginID==uint.MaxValue ? Path.Combine(usersFolder, "Guest") : Path.Combine(usersFolder, CurrentTradeAccount.LoginID.ToString()); if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); return folder; } } /// /// 获取程序目录的"Users"文件夹 /// public static string UsersSettingsFolder { get { var userConfigRoot = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Users"); if (!Directory.Exists(userConfigRoot)) Directory.CreateDirectory(userConfigRoot); return userConfigRoot; } } /// /// 用户基本数据文件夹 /// public static string UserDataFolder { get { var usersFolder = UserSettingsFolder; var folder = Path.Combine(usersFolder, "Data"); if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); return folder; } } #endregion #region 登录账号读写 - BSON存储 /// /// 获取登录的交易账号集合 /// /// List{LoginAccount}. public static List GetTradeAccounts() { var filePath = Path.Combine(UsersSettingsFolder, "LoginAccounts" + LocalDataExtensionName); if (!File.Exists(filePath)) return null; try { var result = BsonHelper.LoadData(filePath); if (result == null||!result.Any()) return null; return result.OrderByDescending(z => z.LoginTime).ToList(); } catch (Exception ex) { LogHelper.WriteError(typeof(UserManager), "get LoginAccount Error:" + ex.ToString()); File.Delete(filePath); return null; } } /// /// 获取用户保存的配置 /// /// /// public static UserInfo GetTradeAccount(string userName) { var filePath = Path.Combine(UsersSettingsFolder, "LoginAccounts" + LocalDataExtensionName); if (!File.Exists(filePath)) return null; try { var result = BsonHelper.LoadData(filePath); if (result == null || !result.Any()) return null; var dicResult = result.ToDictionary((item) => item.UserName); if (dicResult.ContainsKey(userName)) { return dicResult[userName]; } } catch (Exception) { File.Delete(filePath); return null; } return null; } /// /// 获取当前用户名 /// /// public static UserInfo GetCurrentUserInfo() { if (CurrentInfo != null) return CurrentInfo; else { return GetTradeAccount(UserManager.CurrentTradeAccount.LoginID.ToString()); } } /// /// 保存交易账号 /// /// List{LoginAccount}. public static void SaveTradeAccount(UserInfo tradeAccount) { if (tradeAccount == null) return; var filePath = Path.Combine(UsersSettingsFolder, "LoginAccounts" + LocalDataExtensionName); var accountHash = new Dictionary(); try { if (File.Exists(filePath)) { var listHash = BsonHelper.LoadData(filePath) as List; if (listHash != null && listHash.Any()) { accountHash = listHash.ToDictionary((item)=>item.UserName); } } accountHash[tradeAccount.UserName] = tradeAccount; BsonHelper.SaveData(filePath, accountHash.Values.ToList(), null, true); CurrentInfo = tradeAccount; } catch (Exception ex) { LogHelper.WriteError(typeof(UserManager), "Save LoginAccount Error:" + ex.ToString()); } } /// /// 登录成功保存内容 /// public static void LoginedSave(UserInfo tradeAccount, bool IsSaveAccount) { UserInfo info = tradeAccount; info.LoginTime = DateTime.Now; info.RememberAccount = IsSaveAccount; info.LoginType = 0; info.MemberId = UserManager.CurrentTradeAccount.MemberAreaId; SaveTradeAccount(info); //记住本次登录用户 var lastLoginUser = new LastLoginUser(); lastLoginUser.MemberId = info.MemberId + string.Empty; lastLoginUser.MemberPath = Path.Combine(UserManager.SysConfigFolderPath, info.MemberId + string.Empty); SaveLastLoginUser(lastLoginUser); //CurrentUser = info; } /// /// 读取最一个用户登录的账号所属会员 /// /// public static LastLoginUser GetLastLoginUser() { string filePath = Path.Combine(UsersSettingsFolder, "AppDefault" + LocalDataExtensionName); var result = BsonHelper.LoadData(filePath); if (result == null || !result.Any()) return null; return result.FirstOrDefault(); } /// /// /保存最后一个用户的所属会员 /// /// 会员代码 public static void SaveLastLoginUser(LastLoginUser lastLoginUser) { string filePath = Path.Combine(UsersSettingsFolder, "AppDefault" + LocalDataExtensionName); BsonHelper.SaveData(filePath, lastLoginUser, null, true); } #endregion #region 用户单据 private static List _tradeCacheDataList = new List(); /// /// 初始化缓存数据标志 /// /// The trade account. public static void InitializeTradeCacheData(TradeAccount tradeAccount) { if (tradeAccount == null) return; var tradeCacheData = GetTradeCacheData(tradeAccount.AccountId); if (tradeCacheData == null) return; tradeCacheData.HoldOrderFlag = false; tradeCacheData.CloseOrderFlag = false; tradeCacheData.OpenCompleteFlag = false; tradeCacheData.CompleteOrderFlag = false; tradeCacheData.LimitOrderFlag = false; tradeCacheData.HoldingSummaryFlag = false; tradeCacheData.DeliveryOrderFlag = false; tradeCacheData.OpenPrePostOrderFlag = false; } public static Dictionary> GetMarketHoldOrders(TradeAccount account) { if (CurrentTradeAccount == null) { return new Dictionary>(); } var tradeCacheData = GetTradeCacheData(CurrentTradeAccount.AccountId); return tradeCacheData.MarketHoldDetails; } public static Dictionary> GetMarketHoldSummaries(TradeAccount account) { if (CurrentTradeAccount == null) { return new Dictionary>(); } var tradeCacheData = GetTradeCacheData(CurrentTradeAccount.AccountId); return tradeCacheData.MarketHoldSummaries; } /// /// Determines whether [has goods hold summary] [the specified account identifier]. /// /// The account identifier. /// The buy or sell. /// The goods identifier. /// true if [has goods hold summary] [the specified account identifier]; otherwise, false. public static bool HasGoodsHoldSummary(ulong accountId, Direction buyOrSell, uint goodsId ) { if (CurrentTradeAccount == null) { return false; } var tradeCacheData = GetTradeCacheData(accountId); if (tradeCacheData == null || tradeCacheData.HoldingSummaries == null || !tradeCacheData.HoldingSummaries.Any()) return false; return tradeCacheData.HoldingSummaries.Any(z => z.GoodsId == goodsId && z.Direction == buyOrSell); } public static List GetHoldSummaries(ulong accountId) { var tradeCacheData = GetTradeCacheData(accountId); return tradeCacheData.HoldingSummaries == null ? null : tradeCacheData.HoldingSummaries.ToList(); } /// /// 按市场区分单据数据 /// /// /// public static void UpdateMarketHoldOrders(Dictionary> orders) { if (CurrentTradeAccount == null) return; var tradeCacheData = GetTradeCacheData(CurrentTradeAccount.AccountId); if (typeof(T).Equals(typeof(HoldingOrder))) { tradeCacheData.MarketHoldDetails = orders as Dictionary>; tradeCacheData.HoldOrderFlag = true; } else if (typeof(T).Equals(typeof(HoldingSummary))) { tradeCacheData.MarketHoldSummaries = orders as Dictionary>; tradeCacheData.HoldingSummaryFlag = true; } } /// /// 按市场类型更新单据信息 /// /// 单据类型 /// 市场类型 /// 单据列表 public static void UpdateMarketOrders(eTradeMode marketType, List orders) { if (CurrentTradeAccount == null) return; var tradeCacheData = GetTradeCacheData(CurrentTradeAccount.AccountId); if (typeof(T).Equals(typeof(CloseOrder))) { if (tradeCacheData.MarketCloseOrders == null) { tradeCacheData.MarketCloseOrders = new Dictionary>(); } tradeCacheData.MarketCloseOrders[marketType] = orders as List; tradeCacheData.CloseOrderFlag = true; } else if (typeof(T).Equals(typeof(CompleteOrder))) { if (tradeCacheData.MarketOpenCompletes == null) { tradeCacheData.MarketOpenCompletes = new Dictionary>(); } tradeCacheData.MarketOpenCompletes[marketType] = orders as List; tradeCacheData.OpenCompleteFlag = true; } else if (typeof(T).Equals(typeof(PrePostDetail)))//预埋单 { if (tradeCacheData.MarketOpenPrePostOrder == null) { tradeCacheData.MarketOpenPrePostOrder = new Dictionary>(); } tradeCacheData.MarketOpenPrePostOrder[marketType] = orders as List; tradeCacheData.OpenPrePostOrderFlag = true; } else if (typeof(T).Equals(typeof(OrderDetail))) { if (tradeCacheData.MarketOrderDetails == null) { tradeCacheData.MarketOrderDetails = new Dictionary>(); } tradeCacheData.MarketOrderDetails[marketType] = orders as List; tradeCacheData.LimitOrderFlag = true; } } /// /// 从缓存中取相应的单据 /// /// 单据类型 /// /// public static Dictionary> GetMarketCommonOrder(TradeAccount account) { if (CurrentTradeAccount == null) return null; var tradeCacheData = GetTradeCacheData(account.AccountId); if (typeof(T).Equals(typeof(CloseOrder))) { return tradeCacheData.MarketCloseOrders as Dictionary>; } else if (typeof(T).Equals(typeof(OrderDetail))) { return tradeCacheData.MarketOrderDetails as Dictionary>; } else if (typeof(T).Equals(typeof(CompleteOrder))) { return tradeCacheData.MarketOpenCompletes as Dictionary>; } else if (typeof(T).Equals(typeof(PrePostDetail))) { return tradeCacheData.MarketOpenPrePostOrder as Dictionary>; } return null; } /// /// 更新缓存的单据 /// /// 类型 /// 账号 /// public static void UpdateCacheOrder(List orders) { if (CurrentTradeAccount == null) return; var tradeCacheData = GetTradeCacheData(CurrentTradeAccount.FundsAccountId); if (orders is List) { tradeCacheData.OpenOrders = new ObservableCollection(orders as List); tradeCacheData.HoldOrderFlag = true; } else if (orders is List) { tradeCacheData.LimitOrders = new ObservableCollection(orders as List); tradeCacheData.LimitOrderFlag = true; } else if (orders is List) { tradeCacheData.CloseOrders = new ObservableCollection(orders as List); tradeCacheData.CloseOrderFlag = true; } else if (orders is List) { tradeCacheData.HoldingSummaries = new ObservableCollection(orders as List); //配置参数赋值到头寸记录 foreach (var holdingSummary in tradeCacheData.HoldingSummaries) { holdingSummary.ShowCloseOrder = ApplicationParameter.ShowCloseOrder; } tradeCacheData.HoldingSummaryFlag = true; } else if (orders is List) { tradeCacheData.ComplateOrders = new ObservableCollection(orders as List); tradeCacheData.CompleteOrderFlag = true; } else if (orders is List) { tradeCacheData.DryEntrustOrders = new ObservableCollection(orders as List); tradeCacheData.DryEntrustOrdersFlag = true; } else if (orders is List) { tradeCacheData.DryHoldOrders = new ObservableCollection(orders as List); tradeCacheData.DryHoldFlag = true; } else if (orders is List) { tradeCacheData.DeliveryWarehouseOrders = new ObservableCollection(orders as List); tradeCacheData.DeliveryWarehouseFlag = true; } else if (orders is List) { tradeCacheData.DeliveryMatchOrders = new ObservableCollection(orders as List); tradeCacheData.DeliveryMatchFlag = true; } else if (orders is List) { tradeCacheData.TakaDeliveryGoodsOrder = new ObservableCollection(orders as List); tradeCacheData.TakaDeliveryGoodsFlag = true; } else if (orders is List) { tradeCacheData.TakaDeliveryGoodsApplyOrder = new ObservableCollection(orders as List); tradeCacheData.TakaDeliveryGoodsApplyFlag = true; } else if (orders is List) { tradeCacheData.DeliveryConfigInfo = new ObservableCollection(orders as List); tradeCacheData.DeliveryGoodsConfigFlag = true; } else if (orders is List) { tradeCacheData.DeliveryGoodsRuleValue = new ObservableCollection(orders as List); tradeCacheData.DeliveryGoodsRuleFlag = true; } else if (orders is List) { tradeCacheData.DelistingOrders = new ObservableCollection(orders as List); tradeCacheData.DelistingOrderFlag = true; } else if (orders is List) { tradeCacheData.RelationperformConfig = new ObservableCollection(orders as List); tradeCacheData.RelationperformConfigFlag = true; } } /// /// 获取缓存的单据内容 /// /// 单据类型 /// public static ObservableCollection GetCacheOrders() { var orders = new ObservableCollection(); if (CurrentTradeAccount == null) return orders; var tradeCacheData = GetTradeCacheData(CurrentTradeAccount.AccountId); if (orders is ObservableCollection) { return tradeCacheData.OpenOrders as ObservableCollection; } else if (orders is ObservableCollection) { return tradeCacheData.LimitOrders as ObservableCollection; } else if (orders is ObservableCollection) { return tradeCacheData.CloseOrders as ObservableCollection; } else if (orders is ObservableCollection) { return tradeCacheData.HoldingSummaries as ObservableCollection; } else if (orders is ObservableCollection) { return tradeCacheData.ComplateOrders as ObservableCollection; } else if (orders is ObservableCollection) { return tradeCacheData.DryEntrustOrders as ObservableCollection; } else if (orders is ObservableCollection) { return tradeCacheData.DryHoldOrders as ObservableCollection; } else if (orders is ObservableCollection) { return tradeCacheData.DelistingOrders as ObservableCollection;; } return orders; } /// /// 加载预警信息 /// /// public static void LoadWarningOrders(TradeAccount tradeAccount) { if (tradeAccount != null) { var tradeCacheData = GetTradeCacheData(tradeAccount.AccountId); if (tradeCacheData != null) { var warningService = SimpleIoc.Default.GetInstance(); try { tradeCacheData.WarningOrders = warningService.GetWarnings(tradeAccount); } catch (Exception ex) { LogHelper.WriteError(typeof(UserManager), ex.Message); } } } } /// /// 保存预警信息 /// /// /// public static void SaveWarningOrders(TradeAccount tradeAccount, ObservableCollection warningOrders) { if (tradeAccount != null) { var tradeCacheData = GetTradeCacheData(tradeAccount.AccountId); if (tradeCacheData != null) { tradeCacheData.WarningOrders = warningOrders; } } } public static ObservableCollection GetWarningOrders(TradeAccount tradeAccount) { if (tradeAccount != null) { var tradeCacheData = GetTradeCacheData(tradeAccount.AccountId); if (tradeCacheData != null) return tradeCacheData.WarningOrders; } return null; } /// /// Gets the trade data. /// /// The trade code. /// TradeData. public static TradeCacheData GetTradeCacheData(ulong accountId) { var tradeCacheData = _tradeCacheDataList.FirstOrDefault(z => z.AccountId == accountId); if (tradeCacheData == null) { tradeCacheData = new TradeCacheData(accountId); _tradeCacheDataList.Add(tradeCacheData); } return tradeCacheData; } /// /// 从缓存中读取持仓单信息 /// /// 信息 /// public static ObservableCollection CacheOpenOrders(TradeAccount tradeAccount) { if (tradeAccount == null) return null; var tradeCacheData = GetTradeCacheData(tradeAccount.AccountId); if (tradeCacheData == null) return null; return tradeCacheData.OpenOrders; } #endregion #region 用户配置(行情列表抬头\布局) - 采用JSON存储 private static string _userConfigFile { get { return Path.Combine(UserDataFolder, "UserConfig"+ LocalDataExtensionName); } } /// /// 获取默认布局 /// /// UserLayout. private static UserLayout GetDefaultLayout() { ////返回布局默认值 return new UserLayout() { QuoteGridRowLengthUnitType = GridUnitType.Star, QuoteGridRowLengthValue = 3, QuoteGridRowMinHeight = 300, QueryGridRowLengthUnitType = GridUnitType.Pixel, QueryGridRowLengthValue = 280, // QueryGridRowMinHeight = 200 }; } /// /// 获取当前主题 /// /// ColorStyle. public static ColorStyle GetCurrentColorStyle() { var userConfigs = JsonHelper.LoadData(_userConfigFile); var userConfig = userConfigs.FirstOrDefault(); ////本地配置文件为空或是当前主题为None,则返回服务端默认配置 if (null == userConfig || userConfig.CurrentColorStyle == ColorStyle.None) { var defaultColor = 1; if (!int.TryParse(string.IsNullOrWhiteSpace(ApplicationParameter.ColorStyle) ? "4" : ApplicationParameter.ColorStyle, out defaultColor)) defaultColor = 4; ////目前实现1,4,5三种主题 if (Enum.IsDefined(typeof(ColorStyle), defaultColor)) return (ColorStyle)defaultColor; return ColorStyle.CoolBlack; }; return userConfig.CurrentColorStyle; } /// /// 保存当前主题 /// /// The style. public static void SaveCurrentColorStyle(ColorStyle style) { var userConfigs = JsonHelper.LoadData(_userConfigFile); var userConfig = userConfigs.FirstOrDefault() ?? new UserConfig(); userConfig.CurrentColorStyle = style; //只存一个集合,每次覆盖 JsonHelper.SaveData(_userConfigFile, new List() { userConfig }, null, true); } /// /// 获取当前布局 /// /// List{QuoteListHeader}. public static LayoutStyle GetCurrentLayoutStyle() { if (!UserManager.IsAccountLogin) ////游客登录 { return LayoutStyle.Horizontal; } var userConfigs = JsonHelper.LoadData(_userConfigFile); var userConfig = userConfigs.FirstOrDefault(); ////本地配置文件为空或是当前布局为None,则返回服务端默认配置 if (null == userConfig || userConfig.CurrentLayoutStyle == LayoutStyle.None) { var defaultLayout = 1; if (!int.TryParse(string.IsNullOrWhiteSpace(ApplicationParameter.LayoutStyle) ? "1" : ApplicationParameter.LayoutStyle, out defaultLayout)) defaultLayout = 1; ////目前实现1,2两种布局 if (Enum.IsDefined(typeof(LayoutStyle), defaultLayout)) return (LayoutStyle)defaultLayout; return LayoutStyle.Vertical; }; return userConfig.CurrentLayoutStyle; } /// /// 保存当前布局 /// /// The style. public static void SaveCurrentLayoutStyle(LayoutStyle style) { var userConfigs = JsonHelper.LoadData(_userConfigFile); var userConfig = userConfigs.FirstOrDefault() ?? new UserConfig(); userConfig.CurrentLayoutStyle = style; //只存一个集合,每次覆盖 JsonHelper.SaveData(_userConfigFile, new List() { userConfig }, null, true); } /// /// 获取布局 /// /// The style. /// List{QuoteListHeader}. public static UserLayout GetLayoutStyle(LayoutStyle style) { if (style == LayoutStyle.None) return null; var userConfigs = JsonHelper.LoadData(_userConfigFile); var userConfig = userConfigs.FirstOrDefault(); if (null == userConfig || null == userConfig.UserLayouts || !userConfig.UserLayouts.ContainsKey(style) || null == userConfig.UserLayouts[style]) { var defaultLayout = GetDefaultLayout(); return defaultLayout; }; return userConfig.UserLayouts[style]; } /// /// 保存布局 /// /// The style. /// The user layout. public static void SaveLayoutStyle(LayoutStyle style, UserLayout userLayout) { var userConfigs = JsonHelper.LoadData(_userConfigFile); var userConfig = userConfigs.FirstOrDefault() ?? new UserConfig(); if (userConfig.UserLayouts == null) userConfig.UserLayouts = new Dictionary(); userConfig.UserLayouts[style] = userLayout; //只存一个集合,每次覆盖 JsonHelper.SaveData(_userConfigFile, new List() { userConfig }, null, true); } /// /// 获取抬头 /// /// The type. /// List{QuoteListHeader}. public static List GetQuoteListHeaders(QuoteListHeaderType type) { var userConfigs = JsonHelper.LoadData(_userConfigFile); var userConfig = userConfigs.FirstOrDefault(); if (null == userConfig || null == userConfig.QuoteGridHeaders || !userConfig.QuoteGridHeaders.ContainsKey(type) || null == userConfig.QuoteGridHeaders[type]) return null; if (IsUpdateHeaderVer(type, userConfig.ConfigHeadersVer)) ////保存的版本是否要更新 { return null; ////返回空则更新 } return userConfig.QuoteGridHeaders[type]; } /// /// 保存抬头 /// /// The type. /// The headers. public static void SaveQuoteListHeaders(QuoteListHeaderType type, List headers) { object lockObject = new object(); bool lockToken = false; try { Monitor.Enter(lockObject, ref lockToken); var userConfigs = JsonHelper.LoadData(_userConfigFile); var userConfig = userConfigs.FirstOrDefault() ?? new UserConfig(); if (userConfig.QuoteGridHeaders == null) userConfig.QuoteGridHeaders = new Dictionary>(); userConfig.QuoteGridHeaders[type] = headers; userConfig.ConfigHeadersVer = SaveHeaderVer(type, userConfig.ConfigHeadersVer); ////保存版本号 //只存一个集合,每次覆盖 JsonHelper.SaveData(_userConfigFile, new List() {userConfig}, null, true); } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { if (lockToken) { Monitor.Exit(lockObject); } } } /// /// 是否更新抬头 /// /// /// /// private static bool IsUpdateHeaderVer(QuoteListHeaderType type, string localVerString) { if (string.IsNullOrWhiteSpace(ApplicationParameter.ConfigHeadersVer)) { return false; ////没有版本更新 } var updateVer = new Version(ApplicationParameter.ConfigHeadersVer); if (string.IsNullOrWhiteSpace(localVerString)) { return true; ////版本号全是0则不更新 } var locolVer = new Version(localVerString); switch (type) { case QuoteListHeaderType.OTC: case QuoteListHeaderType.Channel: return updateVer.Minor > locolVer.Minor; case QuoteListHeaderType.Bid: return updateVer.Build > locolVer.Build; case QuoteListHeaderType.BidMarket: return updateVer.Revision > locolVer.Revision; ////混合版 case QuoteListHeaderType.MySelected: return updateVer.Major > locolVer.Major; ////自选版本 } return false; } /// private static string SaveHeaderVer(QuoteListHeaderType type, string localVerString) { if (string.IsNullOrWhiteSpace(ApplicationParameter.ConfigHeadersVer)) { return string.Empty; ////没有版本更新 } var updateVer = new Version(ApplicationParameter.ConfigHeadersVer); if (string.IsNullOrWhiteSpace(localVerString)) { localVerString = "0.0.0.0"; } var locolVer = new Version(localVerString); switch (type) { case QuoteListHeaderType.OTC: case QuoteListHeaderType.Channel: return string.Format("{0}.{1}.{2}.{3}", locolVer.Major, updateVer.Minor, locolVer.Build, locolVer.Revision); break; case QuoteListHeaderType.Bid: return string.Format("{0}.{1}.{2}.{3}", locolVer.Major, locolVer.Minor, updateVer.Build, locolVer.Revision); break; case QuoteListHeaderType.BidMarket: return string.Format("{0}.{1}.{2}.{3}", locolVer.Major, locolVer.Minor, locolVer.Build, updateVer.Revision); break; case QuoteListHeaderType.MySelected: return string.Format("{0}.{1}.{2}.{3}", updateVer.Major, locolVer.Minor, locolVer.Build, locolVer.Revision); break; } return string.Empty; } #endregion #region 是否为监控会员 /// /// 是否为监控会员//如果返回false 角色按投资者处理 /// /// public static bool IsMonitorMember() { if (UserManager.CurrentTradeAccount != null)// && UserManager.CurrentTradeAccount.FundsAccounts != null) { #region MTP2.0 注销 //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() && UserManager.CurrentTradeAccount.FundsAccounts[0].AreaRoles != 0) //{ // return UserManager.CurrentTradeAccount.AccountType == eLoginUserType.LOGINUSERTYPE_TRADER && // (UserManager.CurrentTradeAccount.FundsAccounts[0].AreaRoles & // ((int)eAreaRole.AREAROLE_MAKEMEMBER + (int)eAreaRole.AREAROLE_TOPMAKEMEMBER + (int)eAreaRole.AREAROLE_INDUSTRYMEMBER)) > 0; ////产业会员,二级做市会员,做市会员ww风控取信息 //} #endregion return UserManager.CurrentTradeAccount.AccountType != eUserType.USERTYPE_INVESTOR; } else { return false; } } #endregion /// /// 当前账号的可用资金 /// /// public static decimal CurrentAccountUsableFunds() { var usableFunds = 0m; if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) { usableFunds = UserManager.CurrentTradeAccount.FundsAccounts[0].AvailMargin; ////默认使用可用数量 } if (UserManager.IsMonitorMember()) { if (UserManager.CurrentTradeAccount.MemberAccountInfo != null) ////监控会员取风控的资金信息 { usableFunds = UserManager.CurrentTradeAccount.MemberAccountInfo.AvailMargin; } } return usableFunds; } /// /// 获取可用资金BY AccountId /// /// public static decimal GetCurrentUsableFundsByAccountId(ulong AccountId) { var usableFunds = 0m; if (CacheManager.CacheTAAcountList !=null && CacheManager.CacheTAAcountList.Count > 0) { usableFunds = CacheManager.CacheTAAcountList.Where(x => x.FundsAccounts.AccountId == AccountId).Select(x=>x.FundsAccounts.AvailMargin).FirstOrDefault(); ////默认使用可用数量 } return usableFunds; } } }