109 lines
3.8 KiB
C#
109 lines
3.8 KiB
C#
using Dapper;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Shared.DTO.Integracion_DGA;
|
|
using Shared.DTO.VariablesEntorno;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DAL
|
|
{
|
|
public class JobsDgaVilosRepository
|
|
{
|
|
|
|
public async Task<bool> InsertarDgaMacroResultadoVilos(List<DgaMacroResultadoVilos> dgaMacroResultadoVilos)
|
|
{
|
|
try
|
|
{
|
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
|
{
|
|
await connection.OpenAsync();
|
|
|
|
// 1. Truncar la tabla antes de insertar
|
|
await connection.ExecuteAsync("TRUNCATE TABLE DGA_MACRO_RESULTADO_VILOS");
|
|
|
|
// 2. Llamar al stored procedure
|
|
await connection.ExecuteAsync("SP_CALCULO_DGA_VILOS", commandType: System.Data.CommandType.StoredProcedure);
|
|
|
|
// 3. Insertar todos los datos de la lista usando Dapper
|
|
string sql = "INSERT INTO DGA_MACRO_RESULTADO_VILOS (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
|
|
await connection.ExecuteAsync(sql, dgaMacroResultadoVilos);
|
|
|
|
return true; // Éxito
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception($"Error: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
public async Task<bool> InsertarDgaSensorResultadoVilos(List<DgaSensorResultadoVilos> dgaSensorResultadoVilos)
|
|
{
|
|
try
|
|
{
|
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
|
{
|
|
await connection.OpenAsync();
|
|
|
|
// 1. Truncar la tabla antes de insertar
|
|
await connection.ExecuteAsync("TRUNCATE TABLE DGA_SENSOR_RESULTADO_VILOS");
|
|
|
|
// 2. Insertar todos los datos de la lista usando Dapper
|
|
string sql = "INSERT INTO DGA_SENSOR_RESULTADO_VILOS (TagName, TimeStamp, Value, Quality) VALUES (@TagName, @TimeStamp, @Value, @Quality)";
|
|
await connection.ExecuteAsync(sql, dgaSensorResultadoVilos);
|
|
|
|
return true; // Éxito
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception($"Error: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
public async Task<bool> SpCalculoDgaVilos()
|
|
{
|
|
try
|
|
{
|
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
|
{
|
|
await connection.OpenAsync();
|
|
await connection.ExecuteAsync(
|
|
"SP_CALCULO_DGA_VILOS",
|
|
commandType: CommandType.StoredProcedure
|
|
);
|
|
}
|
|
return true; // Éxito
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception($"Error: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
public async Task<bool> SpTraspasoDatosAchirdVilos()
|
|
{
|
|
try
|
|
{
|
|
using (var connection = new SqlConnection(BdConexion.StringConnection))
|
|
{
|
|
await connection.OpenAsync();
|
|
await connection.ExecuteAsync(
|
|
"SP_TRASPASO_DATOS_ACHIRD_VILOS",
|
|
commandType: CommandType.StoredProcedure
|
|
);
|
|
}
|
|
return true; // Éxito
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception($"Error: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|