ConfigSettingClass.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Media;
  10. namespace HistoryDLL
  11. {
  12. public class WindowsResolution
  13. {
  14. public CyclicScroller.MonitorFlag ncm;
  15. public WindowsResolution()
  16. {
  17. int Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
  18. int Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
  19. //判斷是否為多螢幕~由 width 判斷
  20. double value = Math.Ceiling((double)Width / 1920);
  21. if (value == 1)
  22. {
  23. ncm = CyclicScroller.MonitorFlag.Monitor1_1;
  24. ConfigSettingClass.MainBackCollect.ScreenSetting = 1;
  25. }
  26. else if (value == 2)
  27. {
  28. ncm = CyclicScroller.MonitorFlag.Monitor2_1;
  29. ConfigSettingClass.MainBackCollect.ScreenSetting = 2;
  30. }
  31. else if (value == 3)
  32. {
  33. ncm = CyclicScroller.MonitorFlag.Monitor3_1;
  34. ConfigSettingClass.MainBackCollect.ScreenSetting = 3;
  35. }
  36. else if (value == 4)
  37. {
  38. ncm = CyclicScroller.MonitorFlag.Monitor4_1;
  39. ConfigSettingClass.MainBackCollect.ScreenSetting = 4;
  40. }
  41. else if (value == 5)
  42. {
  43. ncm = CyclicScroller.MonitorFlag.Monitor5_1;
  44. ConfigSettingClass.MainBackCollect.ScreenSetting = 5;
  45. }
  46. else if (value == 6)
  47. {
  48. ncm = CyclicScroller.MonitorFlag.Monitor6_1;
  49. ConfigSettingClass.MainBackCollect.ScreenSetting = 6;
  50. }
  51. }
  52. }
  53. public class ConfigSettingClass
  54. {
  55. #region Static Members
  56. public static MainBackground MainBackCollect = new MainBackground()
  57. {
  58. BackgroundColor = Color.FromArgb(255, 255, 255, 255),
  59. BackgroundColorPoint = new Point(0, 0),
  60. ImgBackground = String.Empty,
  61. ImgLogo = String.Empty,
  62. DefaultLangIndex = 0,
  63. BackHomeMillisecond = 20,
  64. ScreenSetting = 1,
  65. LangText = new string[] { "中文", "English", "", "" },
  66. LangFlowDir = new FlowDirection[] { FlowDirection.LeftToRight, FlowDirection.LeftToRight, FlowDirection.LeftToRight, FlowDirection.LeftToRight },
  67. IsUsing4kResolution = false
  68. };
  69. public static Event EventCollect = new Event()
  70. {
  71. BackgroundColor = Color.FromArgb(230, 3, 115, 185),
  72. BackgroundColorPoint = new Point(0, 0),
  73. TextColor = Color.FromArgb(255, 232, 238, 255),
  74. TextColorPoint = new Point(0, 0),
  75. ThicknessColor = Color.FromArgb(255, 177, 232, 255),
  76. ThicknessColorPoint = new Point(0, 0)
  77. };
  78. public static EventContent EventContentCollect = new EventContent()
  79. {
  80. BackgroundColor = Color.FromArgb(233, 115, 217, 255),
  81. BackgroundColorPoint = new Point(0, 0),
  82. TextColor = Color.FromArgb(198, 0, 6, 9),
  83. TextColorPoint = new Point(0, 0),
  84. ThicknessColor = Color.FromArgb(255, 198, 255, 255),
  85. ThicknessColorPoint = new Point(0, 0)
  86. };
  87. public static Timeline TimelineCollect = new Timeline()
  88. {
  89. BackgroundColor = Color.FromArgb(177, 168, 197, 255),
  90. BackgroundColorPoint = new Point(0, 0),
  91. TextColor = Color.FromArgb(176, 255, 255, 255),
  92. TextColorPoint = new Point(0, 0),
  93. ThicknessColor = Color.FromArgb(255, 0, 87, 154),
  94. ThicknessColorPoint = new Point(0, 0)
  95. };
  96. public static TimelineExtent TimelineExtentCollect = new TimelineExtent()
  97. {
  98. BackgroundColor = Color.FromArgb(204, 0, 41, 104),
  99. BackgroundColorPoint = new Point(0, 0),
  100. TextColor = Color.FromArgb(255, 162, 220, 255),
  101. TextColorPoint = new Point(0, 0),
  102. ThicknessColor = Color.FromArgb(255, 76, 49, 0),
  103. ThicknessColorPoint = new Point(0, 0)
  104. };
  105. public static ButtonSelect BtnSelectCollect = new ButtonSelect()
  106. {
  107. BackgroundColor = Color.FromArgb(168, 12, 0, 0),
  108. BackgroundColorPoint = new Point(0, 0),
  109. TextColor = Color.FromArgb(255, 222, 241, 255),
  110. TextColorPoint = new Point(0, 0),
  111. BackgroundColorUnselect = Color.FromArgb(168, 0, 129, 181),
  112. BackgroundColorUnselectPoint = new Point(0, 0),
  113. TextColorUnselect = Color.FromArgb(120, 255, 255, 255),
  114. TextColorUnselectPoint = new Point(0, 0)
  115. };
  116. #endregion
  117. public ConfigSettingClass(string ConfigPath, WindowsResolution windowsresolution)
  118. {
  119. if (File.Exists(ConfigPath))
  120. {
  121. string jsonResult;
  122. using (StreamReader sr = new StreamReader(ConfigPath))
  123. {
  124. jsonResult = sr.ReadToEnd();
  125. }
  126. var container = DeserializeFromJson<DataCollect>(jsonResult);
  127. if (container != null)
  128. {
  129. MainBackCollect = container.MainBackgroundCollect;
  130. EventCollect = container.EventCollect;
  131. EventContentCollect = container.EventContentCollect;
  132. TimelineCollect = container.TimelineCollect;
  133. TimelineExtentCollect = container.TimelineExtentCollect;
  134. BtnSelectCollect = container.ButtonSelectCollect;
  135. }
  136. try
  137. {
  138. if (ConfigSettingClass.MainBackCollect.LangFlowDir == null || ConfigSettingClass.MainBackCollect.LangFlowDir.Length < 4 ||
  139. ConfigSettingClass.MainBackCollect.LangText == null || ConfigSettingClass.MainBackCollect.LangText.Length < 4)
  140. {
  141. MainBackCollect = null;
  142. return;
  143. }
  144. }
  145. catch (Exception ex)
  146. {
  147. MainBackCollect = null;
  148. return;
  149. }
  150. }
  151. else
  152. {
  153. SetDefaultBgAndLogo(windowsresolution);
  154. }
  155. if (ConfigSettingClass.MainBackCollect.BackHomeMillisecond <= 5)
  156. {
  157. ConfigSettingClass.MainBackCollect.BackHomeMillisecond = 5;
  158. }
  159. }
  160. private void SetDefaultBgAndLogo(WindowsResolution windowsresolution)
  161. {
  162. MainBackCollect.ImgLogo = "logo.png";
  163. switch (windowsresolution.ncm)
  164. {
  165. case CyclicScroller.MonitorFlag.Monitor1_1:
  166. {
  167. //MainBackCollect.ImgBackground = "1x1.jpg";
  168. break;
  169. }
  170. case CyclicScroller.MonitorFlag.Monitor2_1:
  171. {
  172. MainBackCollect.ImgBackground = "2x1.jpg";
  173. break;
  174. }
  175. case CyclicScroller.MonitorFlag.Monitor3_1:
  176. {
  177. MainBackCollect.ImgBackground = "3x1.jpg";
  178. break;
  179. }
  180. }
  181. }
  182. public static T DeserializeFromJson<T>(string json)
  183. {
  184. T deserializedProduct = JsonConvert.DeserializeObject<T>(json);
  185. return deserializedProduct;
  186. }
  187. }
  188. }