iniSetClass.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Configuration;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace Uninpho.Railway.Waveform
  10. {
  11. public class iniSetClass
  12. {
  13. public static Dictionary<string, string> PZflash = new Dictionary<string, string>();
  14. static string path = Application.StartupPath + "//pzConfig.ini";
  15. public static void loadAllPZ(string path_)
  16. {
  17. //先检查有没有配置文件
  18. if (File.Exists(path_))
  19. {
  20. //有,则读
  21. path = path_;
  22. }
  23. else
  24. {
  25. //无,则建
  26. SaveAppConfig("pzConfig", path);
  27. File.WriteAllText(path, "");
  28. }
  29. StreamReader sr = new StreamReader(path);
  30. while (!sr.EndOfStream)
  31. {
  32. try
  33. {
  34. //id name scale offset linewidth r,g,b,a visible
  35. string str = sr.ReadLine();
  36. var strarr = str.Split(' ')[0];
  37. if (!PZflash.ContainsKey(strarr))
  38. {
  39. PZflash.Add(strarr, str);
  40. }
  41. }
  42. catch (Exception ex)
  43. {
  44. continue;
  45. }
  46. }
  47. sr.Close();
  48. }
  49. public static void updataPZflash(CoorListClass wavedata)
  50. {
  51. string sql = wavedata.ListId + " " + wavedata.ListName + " " + wavedata.Scale + " " +
  52. wavedata.Offset + " " + wavedata.Width + " " + wavedata.RGBA[0].ToString()
  53. + "," + wavedata.RGBA[1].ToString() + "," + wavedata.RGBA[2].ToString() + "," +
  54. wavedata.RGBA[3].ToString() + " " + wavedata.Visible;
  55. if (PZflash.ContainsKey(wavedata.ListId))
  56. {
  57. PZflash[wavedata.ListId] = sql;
  58. }
  59. else
  60. {
  61. PZflash.Add(wavedata.ListId, sql);
  62. }
  63. }
  64. public static void updataPZflash1(CoorListClass wavedata)
  65. {
  66. if (!PZflash.ContainsKey(wavedata.ListId))
  67. {
  68. string sql = wavedata.ListId + " " + wavedata.ListName + " " + wavedata.Scale + " " +
  69. wavedata.Offset + " " + wavedata.Width + " " + wavedata.RGBA[0].ToString()
  70. + "," + wavedata.RGBA[1].ToString() + "," + wavedata.RGBA[2].ToString() + "," +
  71. wavedata.RGBA[3].ToString() + " " + wavedata.Visible;
  72. PZflash.Add(wavedata.ListId, sql);
  73. }
  74. }
  75. /// <summary>
  76. /// 保存
  77. /// </summary>
  78. public static void savePZFun()
  79. {
  80. StreamWriter sw = new StreamWriter(path);
  81. foreach (var item in PZflash)
  82. {
  83. sw.WriteLine(item.Value);
  84. }
  85. sw.Close();
  86. }
  87. /// <summary>
  88. /// 保存配置文件的设定
  89. /// </summary>
  90. /// <param name="Key"></param>
  91. /// <param name="Value"></param>
  92. public static void SaveAppConfig(string Key, string Value)
  93. {
  94. string strFilePath = System.Windows.Forms.Application.ExecutablePath;
  95. Configuration objConfig = ConfigurationManager.OpenExeConfiguration(strFilePath);
  96. bool bolExist = false;
  97. foreach (string Item in objConfig.AppSettings.Settings.AllKeys)
  98. {
  99. if (Item == Key)
  100. {
  101. bolExist = true;
  102. break;
  103. }
  104. }
  105. if (bolExist)
  106. {
  107. objConfig.AppSettings.Settings.Remove(Key);
  108. }
  109. objConfig.AppSettings.Settings.Add(Key, Value);
  110. objConfig.Save(ConfigurationSaveMode.Modified);
  111. ConfigurationManager.RefreshSection("appSettings");
  112. }
  113. }
  114. }