using System; using System.Collections.Generic; using System.IO; using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Uninpho.Railway.Waveform { public class iniSetClass { public static Dictionary PZflash = new Dictionary(); static string path = Application.StartupPath + "//pzConfig.ini"; public static void loadAllPZ(string path_) { //先检查有没有配置文件 if (File.Exists(path_)) { //有,则读 path = path_; } else { //无,则建 SaveAppConfig("pzConfig", path); File.WriteAllText(path, ""); } StreamReader sr = new StreamReader(path); while (!sr.EndOfStream) { try { //id name scale offset linewidth r,g,b,a visible string str = sr.ReadLine(); var strarr = str.Split(' ')[0]; if (!PZflash.ContainsKey(strarr)) { PZflash.Add(strarr, str); } } catch (Exception ex) { continue; } } sr.Close(); } public static void updataPZflash(CoorListClass wavedata) { string sql = wavedata.ListId + " " + wavedata.ListName + " " + wavedata.Scale + " " + wavedata.Offset + " " + wavedata.Width + " " + wavedata.RGBA[0].ToString() + "," + wavedata.RGBA[1].ToString() + "," + wavedata.RGBA[2].ToString() + "," + wavedata.RGBA[3].ToString() + " " + wavedata.Visible; if (PZflash.ContainsKey(wavedata.ListId)) { PZflash[wavedata.ListId] = sql; } else { PZflash.Add(wavedata.ListId, sql); } } public static void updataPZflash1(CoorListClass wavedata) { if (!PZflash.ContainsKey(wavedata.ListId)) { string sql = wavedata.ListId + " " + wavedata.ListName + " " + wavedata.Scale + " " + wavedata.Offset + " " + wavedata.Width + " " + wavedata.RGBA[0].ToString() + "," + wavedata.RGBA[1].ToString() + "," + wavedata.RGBA[2].ToString() + "," + wavedata.RGBA[3].ToString() + " " + wavedata.Visible; PZflash.Add(wavedata.ListId, sql); } } /// /// 保存 /// public static void savePZFun() { StreamWriter sw = new StreamWriter(path); foreach (var item in PZflash) { sw.WriteLine(item.Value); } sw.Close(); } /// /// 保存配置文件的设定 /// /// /// public static void SaveAppConfig(string Key, string Value) { string strFilePath = System.Windows.Forms.Application.ExecutablePath; Configuration objConfig = ConfigurationManager.OpenExeConfiguration(strFilePath); bool bolExist = false; foreach (string Item in objConfig.AppSettings.Settings.AllKeys) { if (Item == Key) { bolExist = true; break; } } if (bolExist) { objConfig.AppSettings.Settings.Remove(Key); } objConfig.AppSettings.Settings.Add(Key, Value); objConfig.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); } } }