123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- 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<string, string> PZflash = new Dictionary<string, string>();
- 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);
- }
- }
- /// <summary>
- /// 保存
- /// </summary>
- public static void savePZFun()
- {
- StreamWriter sw = new StreamWriter(path);
- foreach (var item in PZflash)
- {
- sw.WriteLine(item.Value);
- }
- sw.Close();
- }
- /// <summary>
- /// 保存配置文件的设定
- /// </summary>
- /// <param name="Key"></param>
- /// <param name="Value"></param>
- 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");
- }
- }
- }
|