From a86a84bd9f46c7e26e93546fc89c2024758296d7 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 14 Apr 2024 09:47:56 +0200 Subject: [PATCH] Luego de AgregarDirectorio de trabajo --- EstadoTrabajo.cs | 42 +++++++ DatabaseManagerList.cs => ListaPersistente.cs | 8 +- MainWindow.xaml | 65 +++++++--- MainWindow.xaml.cs | 116 ++++++++++++++---- ROIEditor.csproj | 1 + 5 files changed, 181 insertions(+), 51 deletions(-) create mode 100644 EstadoTrabajo.cs rename DatabaseManagerList.cs => ListaPersistente.cs (96%) diff --git a/EstadoTrabajo.cs b/EstadoTrabajo.cs new file mode 100644 index 0000000..72c9887 --- /dev/null +++ b/EstadoTrabajo.cs @@ -0,0 +1,42 @@ +using Newtonsoft.Json; +using System.IO; +using Path = System.IO.Path; + +namespace ROIEditor +{ + public class EstadoTrabajo + { + public string strDirectorioTrabajo; + public string NombreImagenEditando; + + private static string _filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EstadoTrabajo.json"); + + public EstadoTrabajo() + { + strDirectorioTrabajo = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + NombreImagenEditando = null; + } + // Método para guardar el estado en un archivo JSON + public void GuardarEstado() + { + string json = JsonConvert.SerializeObject(this); + File.WriteAllText(_filePath, json); + } + + // Método para cargar el estado desde un archivo JSON + public static EstadoTrabajo CargarEstado() + { + if (File.Exists(_filePath)) + { + string json = File.ReadAllText(_filePath); + return JsonConvert.DeserializeObject(json); + } + return new EstadoTrabajo(); // Devuelve una nueva instancia si no existe el archivo + } + + public string CarpetaDB() + { + return Path.Combine(strDirectorioTrabajo, "roieditor.db"); + } + } +} diff --git a/DatabaseManagerList.cs b/ListaPersistente.cs similarity index 96% rename from DatabaseManagerList.cs rename to ListaPersistente.cs index d1669d1..0c42acb 100644 --- a/DatabaseManagerList.cs +++ b/ListaPersistente.cs @@ -11,7 +11,7 @@ using System.ComponentModel; namespace ROIEditor { - public class DatabaseManagerList + public class ListaPersistente { private readonly string connectionString; private readonly string tableName; @@ -46,7 +46,7 @@ namespace ROIEditor public int Count => data.Count; - public DatabaseManagerList(string dbPath, string tableName) + public ListaPersistente(string dbPath, string tableName) { connectionString = $"Data Source={dbPath}"; this.tableName = tableName; @@ -130,14 +130,14 @@ namespace ROIEditor } } - public class DatabaseManagerItem where T : new() + public class ItemPersistente where T : new() { private readonly string connectionString; private readonly string tableName; private T data; // Ahora 'data' es un objeto de tipo T public string Clave; - public DatabaseManagerItem(string dbPath, string tableName) + public ItemPersistente(string dbPath, string tableName) { connectionString = $"Data Source={dbPath}"; this.tableName = tableName; diff --git a/MainWindow.xaml b/MainWindow.xaml index 130232b..4c70983 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -21,57 +21,85 @@ - - - - + + + + + + + + + + +