QuoteFieldMapHelper.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using Muchinfo.PC.Common.Helpers;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. namespace Muchinfo.MTPClient.Infrastructure.Helpers
  5. {
  6. /// <summary>
  7. /// 抬头字段匹配类
  8. /// </summary>
  9. public static class QuoteFieldMapHelper
  10. {
  11. #region Fields
  12. private static readonly List<string> DefaultColorFields;
  13. private static readonly List<string> DirectDisplayFields;
  14. private static readonly Dictionary<string, string> FieldMap;
  15. private static readonly List<string> RightAlignFields;
  16. private static readonly List<string> ChanageBorderFields;
  17. #endregion Fields
  18. #region Constructors
  19. static QuoteFieldMapHelper()
  20. {
  21. FieldMap = new Dictionary<string, string>(FormatHelper.StringEqualityComparer)
  22. {
  23. {"MarketCode", "GoodsCode"},
  24. {"SName", "Name"},
  25. {"Time", "Date"},
  26. {"Buy", "BidPrice"},
  27. {"Sell", "AskPrice"},
  28. {"Pr", "CurrentPrice"},
  29. {"ChgRt", "IncreasePercent"},
  30. {"OpenPr", "Open"},
  31. {"HighPr", "High"},
  32. {"LowPr", "Low"},
  33. {"ClosePrLast", "LastClose"},
  34. {"YClear", "LastSettlement"},
  35. {"Chg", "IncreaseValue"},
  36. {"Amplitude", "Amplitude"},
  37. {"position", "Positions"},
  38. {"Addp", "DayAddPositions"},
  39. {"Volume", "CurrentVolume"},
  40. {"TVolume", "TotalVolume"},
  41. {"BidVolume", "BidVolume"},
  42. {"AskVolume", "AskVolume"},
  43. {"WtUnit", "QuoteUnit"},
  44. {"BoardLot", "LotUnit"},
  45. {"Currency", "QuoteCurrency"},
  46. {"Exchange", "ExchangeName"},
  47. {"Sort", "SortName"},
  48. {"APr", "AveragePrice"},
  49. {"TrdSum", "TradeTurnover"},
  50. {"Vratio", "QuantityRelativeRatio"},
  51. {"OverturnRt", "TurnoverRate"},
  52. {"PE", "PriceEarningRatio"},
  53. {"Insite", "InSize"},
  54. {"outsite", "OutSize"},
  55. {"ORatio", "WeiBi"},
  56. {"Ospread", "WeiCha"},
  57. {"LShares", "NegotiableShares"},
  58. {"LMktVal", "MarketCapitalizations"},
  59. {"TShares", "TotalEquity"}
  60. };
  61. //默认颜色的字段集合
  62. DefaultColorFields = new List<string>()
  63. {
  64. "Amplitude", "GoodsCode", "Date", "SortName", "LastClose", "LotUnit", "CurrentVolume",
  65. "AskVolume", "BidVolume", "QuoteCurrency","TotalVolume","LastSettlement",
  66. "Positions","DayAddPositions","QuoteUnit","TradeTurnover","TotalTurnover","TurnoverRate",
  67. "PriceEarningRatio","NegotiableShares","MarketCapitalizations","TotalEquity", "ExchangeName",
  68. };
  69. //直接显示的字段集合
  70. DirectDisplayFields = new List<string>
  71. {
  72. "GoodsCode", "Name", "LotUnit", "QuoteUnit", "SortName", "ExchangeName", "QuoteCurrency"
  73. };
  74. RightAlignFields = new List<string>()
  75. {
  76. //"GoodsCode", "Name" ,"Date","SortName","ExchangeName","DeliveryDate","QuoteCurrency","QuoteUnit"
  77. };
  78. //当行情价格改变时,显示边框的字段
  79. ChanageBorderFields = new List<string>()
  80. {
  81. "BidPrice", "AskPrice", "CurrentPrice"
  82. };
  83. }
  84. #endregion Constructors
  85. #region Methods
  86. #region Public Static Methods
  87. /// <summary>
  88. /// 设置字段对齐方式
  89. /// </summary>
  90. /// <param name="fieldName">Name of the field.</param>
  91. /// <returns>TextAlignment.</returns>
  92. public static TextAlignment GetFieldAlign(string fieldName)
  93. {
  94. return RightAlignFields.Contains(fieldName) ? TextAlignment.Right : TextAlignment.Center;
  95. }
  96. /// <summary>
  97. /// 是否是格式化的显示字段
  98. /// </summary>
  99. /// <param name="fieldName">Name of the field.</param>
  100. /// <returns><c>true</c> if [is display field] [the specified field name]; otherwise, <c>false</c>.</returns>
  101. public static bool IsDisplayField(string fieldName)
  102. {
  103. return !DirectDisplayFields.Contains(fieldName);
  104. }
  105. /// <summary>
  106. /// 获取映射后的字段颜色名称
  107. /// </summary>
  108. /// <param name="fieldName">映射字段名称</param>
  109. /// <returns>字段颜色名称</returns>
  110. public static string MapColorField(string fieldName)
  111. {
  112. if (DefaultColorFields.Contains(fieldName))
  113. return "DefaultColor";
  114. else
  115. return fieldName + "Color";
  116. }
  117. /// <summary>
  118. /// 获取映射后的字段名称
  119. /// </summary>
  120. /// <param name="fieldName">字段名称</param>
  121. /// <returns>映射字段名称</returns>
  122. public static string MapField(string fieldName)
  123. {
  124. if (FieldMap.ContainsKey(fieldName))
  125. return FieldMap[fieldName];
  126. else
  127. return fieldName;
  128. }
  129. /// <summary>
  130. /// 是否为显示边框的字段
  131. /// </summary>
  132. /// <param name="fieldName">映射字段名称</param>
  133. /// <returns>true为显示边框的字段,否则为false</returns>
  134. public static bool IsShowBorderField(string fieldName)
  135. {
  136. if (string.IsNullOrWhiteSpace(fieldName)) return false;
  137. return ChanageBorderFields.Contains(fieldName);
  138. }
  139. /// <summary>
  140. /// 获取映射显示变化的边框的字段
  141. /// </summary>
  142. /// <param name="fieldName">字段名称</param>
  143. /// <returns>行情绑定的字段名</returns>
  144. public static string MapShowBorderField(string fieldName)
  145. {
  146. return "Is" + fieldName + "Border";
  147. }
  148. #endregion Public Static Methods
  149. #endregion Methods
  150. }
  151. }