115 lines
3.0 KiB
C#
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
|
|
}
|
|
}
|