diff --git a/Classes/ApiClient.cs b/Classes/ApiClient.cs index 1434d9d..593c958 100644 --- a/Classes/ApiClient.cs +++ b/Classes/ApiClient.cs @@ -28,6 +28,8 @@ public class ApiClient : IDisposable private string? _currentRefreshToken; private readonly object _tokenLock = new object(); + private string DominioEFC = Helpers.DominioExpedienteElectronico(); + public ApiClient(TimeSpan? timeout = null, int maxRetries = 3, TimeSpan? retryDelay = null) { @@ -57,6 +59,10 @@ public class ApiClient : IDisposable return @"/api/v1/token/refresh/"; } + public string EndpointStatusTask() + { + return @"/api/v1/tasks/status/"; + } private void SetAuthorizationBearer(string token, string refresh_token) { @@ -277,6 +283,13 @@ public class ApiClient : IDisposable return await SendWithRetriesAsync(() => new HttpRequestMessage(HttpMethod.Get, url)); } + public async Task GetStatusTaskAsync(string taskId) + { + var apiClient = Globales.ApiClient; + string url = DominioEFC + EndpointStatusTask() + $"{taskId}/"; + return await SendWithRetriesAsync(() => new HttpRequestMessage(HttpMethod.Get, url)); + } + public async Task PostJsonAsync(string url, string jsonContent) { using var content = new StringContent(jsonContent, System.Text.Encoding.UTF8, "application/json"); diff --git a/Classes/SQLiteHelper.cs b/Classes/SQLiteHelper.cs index 912d7ec..6bb88be 100644 --- a/Classes/SQLiteHelper.cs +++ b/Classes/SQLiteHelper.cs @@ -498,7 +498,7 @@ namespace EFCDesk.Classes Console.WriteLine($"Error: {ex.Message}"); } } - public void MarcarCarpetaProcesada(string ruta, string estado) + public void MarcarCarpetaProcesada(string expediente, string estado) { try { @@ -510,7 +510,7 @@ namespace EFCDesk.Classes using (var command = new SQLiteCommand(updateQuery, connection)) { - command.Parameters.AddWithValue("@r", ruta); + command.Parameters.AddWithValue("@r", expediente); command.Parameters.AddWithValue("@e", estado); command.ExecuteNonQuery(); } @@ -545,6 +545,30 @@ namespace EFCDesk.Classes } } + public void ActaulizarStatusCarpeta(string expediente, string estado) + { + try + { + using (var connection = new SQLiteConnection(_connectionString)) + { + connection.Open(); + + string updateQuery = "UPDATE Carpetas SET Estado=@e WHERE Ruta=@r OR Nombre=@r"; + + using (var command = new SQLiteCommand(updateQuery, connection)) + { + command.Parameters.AddWithValue("@r", expediente); + command.Parameters.AddWithValue("@e", estado); + command.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + public bool EstaArchivoProcesado(string rutaArchivo) { diff --git a/Forms/FormExpedientes.cs b/Forms/FormExpedientes.cs index f58a29d..886cda0 100644 --- a/Forms/FormExpedientes.cs +++ b/Forms/FormExpedientes.cs @@ -70,7 +70,7 @@ namespace EFCDesk.Forms }; // Columna de acciones - //table.Columns.Add("Acciones", typeof(Image)); + table.Columns.Add("Acciones", typeof(Image)); // Crear el icono UNA sola vez Bitmap iconoVer = IconChar.Eye.ToBitmap( @@ -87,7 +87,7 @@ namespace EFCDesk.Forms row["Estatus"] = exp.Estado; row["Fecha Registro"] = exp.FechaCreacion; row["TaskId"] = exp.TaskId; - //row["Acciones"] = iconoVer; + row["Acciones"] = iconoVer; table.Rows.Add(row); } return table; @@ -115,9 +115,9 @@ namespace EFCDesk.Forms dgwExpedientes.Columns["Fecha Registro"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; dgwExpedientes.Columns["Fecha Registro"].Width = 180; - //dgwExpedientes.Columns["Acciones"].Width = 40; - //dgwExpedientes.Columns["Acciones"].HeaderText = ""; - //((DataGridViewImageColumn)dgwExpedientes.Columns["Acciones"]).ImageLayout = DataGridViewImageCellLayout.Zoom; + dgwExpedientes.Columns["Acciones"].Width = 40; + dgwExpedientes.Columns["Acciones"].HeaderText = ""; + ((DataGridViewImageColumn)dgwExpedientes.Columns["Acciones"]).ImageLayout = DataGridViewImageCellLayout.Zoom; _ = Task.Run(() => { @@ -152,8 +152,8 @@ namespace EFCDesk.Forms try { var apiClient = Globales.ApiClient; - string url = DominioEFC + $"/api/v1/tasks/status/?task_id={taskId}"; - return await apiClient.GetAsync(url); + //string url = DominioEFC + $"/api/v1/tasks/status/{taskId}/"; + return await apiClient.GetStatusTaskAsync(taskId); } catch (Exception ex) { @@ -209,7 +209,7 @@ namespace EFCDesk.Forms } // Actualizar en SQLite - _sqliteHelper.MarcarCarpetaProcesada(rutaExpediente, nuevoEstado); + _sqliteHelper.ActaulizarStatusCarpeta(rutaExpediente, nuevoEstado); // Mostrar resultado MessageBox.Show(mensaje, "Estado de Tarea", MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -384,6 +384,9 @@ namespace EFCDesk.Forms if (string.IsNullOrEmpty(taskId)) return; + if (string.IsNullOrEmpty(expediente)) + return; + //// Ejecutar trabajo pesado en segundo plano //var resultado = await Task.Run(() => //{ @@ -394,7 +397,7 @@ namespace EFCDesk.Forms //MessageBox.Show(resultado); - string responseJson = await ConsultarEstadoTareaAsync(taskId); + string responseJson = await ConsultarEstadoTareaAsync(taskId); await ProcesarRespuestaTareaAsync(responseJson, expediente); diff --git a/Forms/FormMain.cs b/Forms/FormMain.cs index 4c5e844..6d79de1 100644 --- a/Forms/FormMain.cs +++ b/Forms/FormMain.cs @@ -1902,8 +1902,19 @@ namespace EFCDesk.Forms private void btn_VisorExpedientes_Click(object sender, EventArgs e) { - FormExpedientes winExpedientes = new FormExpedientes(); - winExpedientes.Show(); + var form = Application.OpenForms.OfType().FirstOrDefault(); + + if (form != null) + { + form.BringToFront(); + form.WindowState = FormWindowState.Normal; + } + else + { + FormExpedientes winExpedientes = new FormExpedientes(); + winExpedientes.Show(); + } + } } }