반응형
public static class GridrCopyHelper
{
private static string RegPath = $"Software\\CHA_MES\\GridrCopy";
public static string DataTableToJsonReg(this DataTable dataTable)
{
string json = JsonConvert.SerializeObject(dataTable);
SaveGridToRegistry(json);
return json;
}
public static DataTable JsonToDataTableReg(this string json)
{
DataTable dataTable = JsonConvert.DeserializeObject<DataTable>(json);
return dataTable;
}
private static void SaveGridToRegistry(string json)
{
try
{
RegistryKey key = Registry.CurrentUser.CreateSubKey(RegPath);
key.SetValue(Environment.MachineName, json);
key.Close();
}
catch (Exception ex)
{
}
}
public static DataTable LoadGridFromRegistry()
{
try
{
// 레지스트리에서 값 읽기
RegistryKey key = Registry.CurrentUser.OpenSubKey(RegPath);
if (key != null)
{
string jsonString = key.GetValue(Environment.MachineName) as string;
key.Close();
return JsonToDataTableReg(jsonString);
}
return null;
}
catch (Exception ex)
{
return null;
}
finally
{
}
}
}