ConfigSettingClass.cs 7.5 KB

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