Files
SSG_Automation_Solution/SSG_Automation_Solution/Data/Options.cs
2026-04-01 19:57:37 +09:00

115 lines
3.0 KiB
C#

using DevExpress.XtraEditors;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SSG_Automation_Solution.Data
{
public class Options
{
#region Singleton
private static Options uniqueInstance = null;
private static readonly Object mInstanceLocker = new Object();
public static Options getInstance()
{
lock (mInstanceLocker)
{
if (uniqueInstance == null)
{
uniqueInstance = new Options();
}
}
return uniqueInstance;
}
#endregion
#region
public List<gridColor> gridColors = new List<gridColor>();
public struct gridColor
{
public string ;
public Color ;
public gridColor(string , Color ) : this()
{
this. = ;
this. = ;
}
}
string gridColorPath = Environment.CurrentDirectory + @"\Data\gridColor.json";
public Color GetGridColor(LabelControl lbl)
{
Color color = gridColors.Find(x => x. == lbl.Name).;
return color;
}
public void ChangeGridColor(string , Color )
{
int index = gridColors.FindIndex(x => x. == );
if (index > -1) gridColors.RemoveAt(index);
gridColors.Add(new gridColor(, ));
}
public void SaveGridColor()
{
try
{
JObject json = new JObject();
foreach (gridColor g in gridColors)
{
json.Add(g., g..ToArgb());
}
File.WriteAllText(gridColorPath, json.ToString(), Encoding.UTF8);
}
catch (Exception ex)
{
Console.WriteLine("DatControl Err");
Console.WriteLine(ex.Message);
}
}
public void LoadGridCOlor()
{
try
{
if (File.Exists(gridColorPath))
{
using (StreamReader file = new StreamReader(gridColorPath))
{
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject json = (JObject)JToken.ReadFrom(reader);
foreach (var x in json)
{
ChangeGridColor(x.Key, Color.FromArgb((int)x.Value));
}
}
}
}
}
catch (Exception ex) { }
}
#endregion
}
}