using Exferia_Aplicacion.General; using Exferia_EntityFramework; using Exferia_KairosPRO._1_Modelos; using Exferia_KairosPRO._1_Modelos.Herencia.Capas; using Exferia_KairosPRO_EF; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading; using static Exferia_Aplicacion.General.Enumerados; namespace Exferia_KairosPRO._2_Datos { public class KRS_PerfilesLinea_Datos : ABS_Datos { #region Listado public override List Obtener_Listado(List _lst_CamposConRelacionABuscar, List _lst_INTERNO_Filtro_OpcionPadre_Modelo, List _lst_INTERNO_Filtro_Modelo) { return null; } public override dynamic Obtener_RegistroListado(List _lst_CamposConRelacionABuscar, List _lst_INTERNO_Filtro_OpcionPadre_Modelo, List _lst_INTERNO_Filtro_Modelo, long _lng_id, List _lst_id) { return null; } protected override void ConsultaRellenar_Listado(KairosProEntities _dbcontext, List _lst_CamposConRelacionABuscar, long _lng_id, List _lst_id, List _lst_INTERNO_Filtro_OpcionPadre_Modelo, List _lst_INTERNO_Filtro_Modelo) { } #endregion #region Listado Secundario public override List Obtener_Listado_Secundario(List _lst_CamposConRelacionABuscar, List _lst_INTERNO_Filtro_OpcionPadre_Modelo, List _lst_INTERNO_Filtro_Modelo) { return null; } public override dynamic Obtener_RegistroListado_Secundario(List _lst_CamposConRelacionABuscar, List _lst_INTERNO_Filtro_OpcionPadre_Modelo, List _lst_INTERNO_Filtro_Modelo, long _lng_id, List _lst_id) { return null; } protected override void ConsultaRellenar_Listado_Secundario(KairosProEntities _dbcontext, List _lst_CamposConRelacionABuscar, long _lng_id, List _lst_id, List _lst_INTERNO_Filtro_OpcionPadre_Modelo, List _lst_INTERNO_Filtro_Modelo) { } #endregion #region F3 public override dynamic Obtener_F3(string _str_filtro, string _str_CampoBusqueda, List _lst_INTERNO_Filtro_OpcionPadre_Modelo, List _lst_INTERNO_Filtro_Modelo) { return null; } public override dynamic Obtener_F3_PorId(long _lng_id, List _lst_INTERNO_Filtro_OpcionPadre_Modelo, List _lst_INTERNO_Filtro_Modelo) { return null; } protected override void ConsultaRellenar_F3(KairosProEntities _dbcontext, string _str_CampoBusqueda, string _str_Filtro, long _lng_id, List _lst_INTERNO_Filtro_OpcionPadre_Modelo, List _lst_INTERNO_Filtro_Modelo) { } #endregion #region Obtener private dynamic g_dnm_Modelo_Obtener = null; public override dynamic Obtener(long _lng_id) { KairosProEntities obj_KairosProEntities = null; try { obj_KairosProEntities = new KairosProEntities(); obj_KairosProEntities.Configuration.LazyLoadingEnabled = false; string str_SQL = " SELECT " + nameof(KRS_PerfilesLinea.id) + "," + nameof(KRS_PerfilesLinea.idPerfilCabecera) + "," + nameof(KRS_PerfilesLinea.codigoCliente) + "," + nameof(KRS_PerfilesLinea.idJornadaCabecera) + "," + nameof(KRS_PerfilesLinea.fechaDesde) + "," + nameof(KRS_PerfilesLinea.fechaHasta) + " FROM " + nameof(KRS_PerfilesLinea) + " WHERE " + nameof(KRS_PerfilesLinea.id) + "=@id and " + nameof(KRS_PerfilesLinea.codigoCliente) + "=@codigoCliente "; //Parametros object[] arr_Parametros = new object[] { new SqlParameter("@id", _lng_id), new SqlParameter("@codigoCliente", Variables.G_LNG_IDCLIENTE_LICENCIAVALIDADO) }; //Rellenar el Modelo g_dnm_Modelo_Obtener = obj_KairosProEntities.Database.SqlQuery(str_SQL, arr_Parametros).FirstOrDefault(); } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Obtener), true); } finally { obj_KairosProEntities.Database.Connection.Close(); obj_KairosProEntities.Dispose(); } return g_dnm_Modelo_Obtener; } public override dynamic Obtener_Registro_PorCampo(string _str_CampoBusqueda, string _str_Filtro) { throw new NotImplementedException(); } public List Obtener_Para_SolicitudesAusencias(long _lng_CodigoCliente,List _lst_idEmpleado,DateTime _dtt_FechaDesde,DateTime _dtt_FechaHasta) { KairosProEntities obj_KairosProEntities = null; List lst_INTERNO_AUX_PerfilesLineaSolicitudesAsucencias_Modelo = null; try { obj_KairosProEntities = new KairosProEntities(); obj_KairosProEntities.Configuration.LazyLoadingEnabled = false; if (_lst_idEmpleado != null && _lst_idEmpleado.Count > 0) { List lst_Parametros = new List(); string str_Filtros_IDS = Funciones.Formar_ContenidoIN_ParaConsultaWhere(nameof(KRS_Ejercicios_PerfilesCabecera), nameof(KRS_Ejercicios_PerfilesCabecera.idEmpleado), G_ENUM_FORMARCONTENIDOIN_CONDICIONANTES.NADA, _lst_idEmpleado); string str_SQL = " SELECT distinct " + nameof(INTERNO_AUX_PerfilesLineaSolicitudesAusencias_Modelo.IdEmpleado) + "=" + nameof(KRS_Ejercicios_PerfilesCabecera) + "." + nameof(KRS_Ejercicios_PerfilesCabecera.idEmpleado) + ", " + nameof(INTERNO_AUX_PerfilesLineaSolicitudesAusencias_Modelo.FechaDesde) + "=" + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaDesde) + ", " + nameof(INTERNO_AUX_PerfilesLineaSolicitudesAusencias_Modelo.FechaHasta) + "=" + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaHasta) + ", " + nameof(INTERNO_AUX_PerfilesLineaSolicitudesAusencias_Modelo.FechaBajaEmpleado) + "=" + nameof(KRS_Empleados) + "." + nameof(KRS_Empleados.fechaBaja) + " FROM " + nameof(KRS_PerfilesLinea) + " INNER JOIN " + nameof(KRS_PerfilesCabecera) + " on " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.idPerfilCabecera) + " = " + nameof(KRS_PerfilesCabecera) + "." + nameof(KRS_PerfilesCabecera.id) + " INNER JOIN " + nameof(KRS_Ejercicios_PerfilesCabecera) + " ON " + nameof(KRS_Ejercicios_PerfilesCabecera) + "." + nameof(KRS_Ejercicios_PerfilesCabecera.idPerfilCabecera) + " = " + nameof(KRS_PerfilesCabecera) + "." + nameof(KRS_PerfilesCabecera.id) + " AND " + nameof(KRS_Ejercicios_PerfilesCabecera) + "." + nameof(KRS_Ejercicios_PerfilesCabecera.codigoCliente) + " = " + nameof(KRS_PerfilesCabecera) + "." + nameof(KRS_PerfilesCabecera.codigoCliente) + " INNER JOIN " + nameof(KRS_Empleados) + " on " + nameof(KRS_Ejercicios_PerfilesCabecera) + "." + nameof(KRS_Ejercicios_PerfilesCabecera.idEmpleado) + " = " + nameof(KRS_Empleados) + "." + nameof(KRS_Empleados.id) + " WHERE " + nameof(KRS_PerfilesCabecera) + "." + nameof(KRS_PerfilesCabecera.fechaBorrado) + " is null and " + nameof(KRS_Empleados) + "." + nameof(KRS_Empleados.fechaBorrado) + " is null and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.codigoCliente) + " =@codigoCliente and " + " ( " + " ( " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaDesde) + ">=@fechaDesde and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaDesde) + "<=@fechaHasta " + " ) or " + " ( " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaHasta) + "<=@fechaHasta and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaHasta) + ">=@fechaDesde " + " ) " + " ) and " + str_Filtros_IDS; //Parametros lst_Parametros.Add(new SqlParameter("@codigoCliente", _lng_CodigoCliente)); lst_Parametros.Add(new SqlParameter("@fechaDesde", _dtt_FechaDesde)); lst_Parametros.Add(new SqlParameter("@fechaHasta", _dtt_FechaHasta)); object[] arr_Parametros = lst_Parametros.ToArray(); //Rellenar listado principal lst_INTERNO_AUX_PerfilesLineaSolicitudesAsucencias_Modelo = obj_KairosProEntities.Database.SqlQuery(str_SQL, arr_Parametros).ToList(); } } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Obtener_Para_SolicitudesAusencias), true); } finally { obj_KairosProEntities.Database.Connection.Close(); obj_KairosProEntities.Dispose(); } return lst_INTERNO_AUX_PerfilesLineaSolicitudesAsucencias_Modelo; } #endregion #region MODELOS #region Modelo Simple private KRS_PerfilesLinea g_mdl_KRS_PerfilesLinea = null; public KRS_PerfilesLinea Obtener_Modelo_Por_Id(long _lng_id,long _lng_CodigoCliente) { try { string str_SQL = Obtener_Consulta_Modelo() + //WHERE " WHERE " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.id) + "=@id and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.codigoCliente) + "=@codigoCliente"; //Parametros object[] arr_Parametros = new object[] { new SqlParameter("@id", _lng_id), new SqlParameter("@codigoCliente", _lng_CodigoCliente) }; Ejecutar_Consulta_Modelo(str_SQL, arr_Parametros); } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Obtener_Modelo_Por_Id), true); } return g_mdl_KRS_PerfilesLinea; } public KRS_PerfilesLinea Obtener_Modelo_Por_FechaEmpleado(long _lng_idEmpleado, long _lng_CodigoCliente,DateTime _dtt_Fecha) { try { string str_SQL = Obtener_Consulta_Modelo() + " INNER JOIN " + nameof(KRS_PerfilesCabecera) + " ON " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.idPerfilCabecera) + "=" + nameof(KRS_PerfilesCabecera) + "." + nameof(KRS_PerfilesCabecera.id) + " and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.codigoCliente) + "=" + nameof(KRS_PerfilesCabecera) + "." + nameof(KRS_PerfilesCabecera.codigoCliente) + " INNER JOIN " + nameof(KRS_Ejercicios_PerfilesCabecera) + " ON " + nameof(KRS_PerfilesCabecera) + "." + nameof(KRS_PerfilesCabecera.id) + "=" + nameof(KRS_Ejercicios_PerfilesCabecera) + "." + nameof(KRS_Ejercicios_PerfilesCabecera.idPerfilCabecera) + " and " + nameof(KRS_PerfilesCabecera) + "." + nameof(KRS_PerfilesCabecera.codigoCliente) + "=" + nameof(KRS_Ejercicios_PerfilesCabecera) + "." + nameof(KRS_Ejercicios_PerfilesCabecera.codigoCliente) + //WHERE " WHERE " + nameof(KRS_Ejercicios_PerfilesCabecera) + "." + nameof(KRS_Ejercicios_PerfilesCabecera.idEmpleado) + "=@idEmpleado and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.codigoCliente) + "=@codigoCliente and " + //Fechas nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaDesde) + " <=@Fecha and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaHasta) + " >=@Fecha "; //Parametros object[] arr_Parametros = new object[] { new SqlParameter("@idEmpleado", _lng_idEmpleado), new SqlParameter("@codigoCliente", _lng_CodigoCliente), new SqlParameter("@Fecha", _dtt_Fecha), }; Ejecutar_Consulta_Modelo(str_SQL, arr_Parametros); } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Obtener_Modelo_Por_FechaEmpleado), true); } return g_mdl_KRS_PerfilesLinea; } private void Ejecutar_Consulta_Modelo(string _str_SQL, object[] _arr_Parametros) { KairosProEntities obj_KairosProEntities = null; try { //Conexion obj_KairosProEntities = new KairosProEntities(); obj_KairosProEntities.Configuration.LazyLoadingEnabled = false; //Rellenar el Modelo g_mdl_KRS_PerfilesLinea = obj_KairosProEntities.Database.SqlQuery(_str_SQL, _arr_Parametros).FirstOrDefault(); } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Ejecutar_Consulta_Modelo), true); } finally { obj_KairosProEntities.Database.Connection.Close(); obj_KairosProEntities.Dispose(); } } #endregion #region Modelo Listado private List g_lst_KRS_PerfilesLinea = null; public List Obtener_ModeloListado_Por_Ids(List _lst_ids) { try { if (_lst_ids != null && _lst_ids.Count > 0) { //pasar el listado de Ids a un string List lst_Parametros = new List(); string str_Filtros_IDS = Funciones.Formar_ContenidoIN_ParaConsultaWhere(nameof(KRS_PerfilesLinea), nameof(KRS_PerfilesLinea.id), G_ENUM_FORMARCONTENIDOIN_CONDICIONANTES.NADA, _lst_ids); string str_SQL = Obtener_Consulta_Modelo() + //WHERE " WHERE " + str_Filtros_IDS; //Parametros object[] arr_Parametros = lst_Parametros.ToArray(); //Ejecutar y rellenar el listado Ejecutar_Consulta_Modelo_Listado(str_SQL, arr_Parametros, false); } } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Obtener_ModeloListado_Por_Ids), true); } return g_lst_KRS_PerfilesLinea; } public List Obtener_ModeloListado_Por_PerfilCabeceraEjercicio(long _lng_idPerfilCabecera, GEN_EjerciciosActivos_Empresa _mdl_GEN_EjerciciosActivos_Empresa, bool _bol_Cargar_JornadasCabecera) { try { string str_SQL = Obtener_Consulta_Modelo() + //WHERE " WHERE " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.idPerfilCabecera) + "=@idPerfilCabecera and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.codigoCliente) + "=@codigoCliente and " + //Fechas nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaDesde) + " >=@FechaInicio and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaDesde) + " <=@FechaFin and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaHasta) + " >=@FechaInicio and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaHasta) + " <=@FechaFin "; //Parametros object[] arr_Parametros = new object[] { new SqlParameter("@idPerfilCabecera", _lng_idPerfilCabecera), new SqlParameter("@codigoCliente", Variables.G_LNG_IDCLIENTE_LICENCIAVALIDADO), new SqlParameter("@FechaInicio", _mdl_GEN_EjerciciosActivos_Empresa.temporadaFechaInicio), new SqlParameter("@FechaFin", _mdl_GEN_EjerciciosActivos_Empresa.temporadaFechaFin) }; Ejecutar_Consulta_Modelo_Listado(str_SQL, arr_Parametros, _bol_Cargar_JornadasCabecera); } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Obtener_ModeloListado_Por_PerfilCabeceraEjercicio), true); } return g_lst_KRS_PerfilesLinea; } public List Obtener_ModeloListado_Por_PerfilesCabecerasEjercicio(List _lst_idPerfilCabecera, GEN_EjerciciosActivos_Empresa _mdl_GEN_EjerciciosActivos_Empresa, bool _bol_Cargar_JornadasCabecera) { try { if (_mdl_GEN_EjerciciosActivos_Empresa != null) { List lst_Parametros = new List(); string str_Filtros_IDS = Funciones.Formar_ContenidoIN_ParaConsultaWhere(nameof(KRS_PerfilesLinea), nameof(KRS_PerfilesLinea.idPerfilCabecera), G_ENUM_FORMARCONTENIDOIN_CONDICIONANTES.AND_FIN, _lst_idPerfilCabecera); string str_SQL = Obtener_Consulta_Modelo() + //WHERE " WHERE " + str_Filtros_IDS + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.codigoCliente) + "=@codigoCliente and " + //Fechas nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaDesde) + " >=@FechaInicio and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaDesde) + " <=@FechaFin and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaHasta) + " >=@FechaInicio and " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaHasta) + " <=@FechaFin "; //Parametros lst_Parametros.Add(new SqlParameter("@codigoCliente", Variables.G_LNG_IDCLIENTE_LICENCIAVALIDADO)); lst_Parametros.Add(new SqlParameter("@FechaInicio", _mdl_GEN_EjerciciosActivos_Empresa.temporadaFechaInicio)); lst_Parametros.Add(new SqlParameter("@FechaFin", _mdl_GEN_EjerciciosActivos_Empresa.temporadaFechaFin)); object[] arr_Parametros = lst_Parametros.ToArray(); Ejecutar_Consulta_Modelo_Listado(str_SQL, arr_Parametros, _bol_Cargar_JornadasCabecera); } } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Obtener_ModeloListado_Por_PerfilesCabecerasEjercicio), true); } return g_lst_KRS_PerfilesLinea; } #region Ejecutar Consulta //Listado de modelos Relacionados private List g_lst_KRS_JornadasCabecera = null; //Hilos private static int g_int_TotalHilos_Modelo_Listado = 1; private bool[] g_bol_Hilos_Terminados_Modelo_Listado = new bool[g_int_TotalHilos_Modelo_Listado]; private void Ejecutar_Consulta_Modelo_Listado(string _str_SQL, object[] _arr_Parametros, bool _bol_Cargar_JornadasCabecera) { KairosProEntities obj_KairosProEntities = null; try { //Conexion obj_KairosProEntities = new KairosProEntities(); obj_KairosProEntities.Configuration.LazyLoadingEnabled = false; //Rellenar el listado g_lst_KRS_PerfilesLinea = obj_KairosProEntities.Database.SqlQuery(_str_SQL, _arr_Parametros).ToList(); #region Rellenar Tablas Relacionadas if (g_lst_KRS_PerfilesLinea != null && g_lst_KRS_PerfilesLinea.Count > 0) { //Si tiene que buscar alguna tabla relacionada if (_bol_Cargar_JornadasCabecera) { #region PRIMERO BUSCO LOS DATOS DE LAS TABLAS RELACIONADAS //reiniciar Valores de los hilos for (int int_Contador = 0; int_Contador < g_int_TotalHilos_Modelo_Listado; int_Contador++) { g_bol_Hilos_Terminados_Modelo_Listado[int_Contador] = false; } //KRS_JornadasCabecera ############################################# if (_bol_Cargar_JornadasCabecera) { ThreadStart obj_ThreadStart_JORNADACABECERA = new ThreadStart(Obtener_JornadasCabecera_Modelo_Listado); Thread obj_Thread_JORNADACABECERA = new Thread(obj_ThreadStart_JORNADACABECERA); obj_Thread_JORNADACABECERA.Start(); } else { g_bol_Hilos_Terminados_Modelo_Listado[0] = true; } //Esperando a que terminen todos los hilos ......................................... bool bol_Termino = false; while (bol_Termino == false) { bol_Termino = true; foreach (bool bol_Termino_Hilo in g_bol_Hilos_Terminados_Modelo_Listado) { if (bol_Termino_Hilo == false) { bol_Termino = false; break; } } Thread.Sleep(10); } //................................................................................. #endregion #region DESPUES SE LO VOY ASIGNANDO A LOS REGISTRO UNO A UNO foreach (KRS_PerfilesLinea mdl_KRS_PerfilesLinea in g_lst_KRS_PerfilesLinea) { //KRS_JornadasCabecera ############################################# if (_bol_Cargar_JornadasCabecera && g_lst_KRS_JornadasCabecera != null && g_lst_KRS_JornadasCabecera.Count > 0) { mdl_KRS_PerfilesLinea.KRS_JornadasCabecera = g_lst_KRS_JornadasCabecera.Where(m => m.id == mdl_KRS_PerfilesLinea.idJornadaCabecera).FirstOrDefault(); } } #endregion } } #endregion } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Ejecutar_Consulta_Modelo_Listado), true); } finally { obj_KairosProEntities.Database.Connection.Close(); obj_KairosProEntities.Dispose(); } } #region Tablas Relacionadas private void Obtener_JornadasCabecera_Modelo_Listado() { try { KRS_JornadasCabecera_Datos obj_KRS_JornadasCabecera_Datos = new KRS_JornadasCabecera_Datos(); g_lst_KRS_JornadasCabecera = obj_KRS_JornadasCabecera_Datos.Obtener_ModeloListado_Por_Ids(g_lst_KRS_PerfilesLinea.Select(m=>m.idJornadaCabecera).ToList(),true,true); } catch (Control_Errores) { } finally { g_bol_Hilos_Terminados_Modelo_Listado[0] = true; } } #endregion #endregion #endregion private string Obtener_Consulta_Modelo() { return " SELECT " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.id) + " , " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.idPerfilCabecera) + " , " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.codigoCliente) + " , " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.idJornadaCabecera) + " , " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaDesde) + " , " + nameof(KRS_PerfilesLinea) + "." + nameof(KRS_PerfilesLinea.fechaHasta) + " FROM " + nameof(KRS_PerfilesLinea); } #endregion #region Grabar public override INTERNO_ValorDevuelto_Modelo Grabar(object _mdl_obj) { KairosProEntities obj_KairosProEntities = null; INTERNO_ValorDevuelto_Modelo mdl_INTERNO_ValorDevuelto_Modelo = new INTERNO_ValorDevuelto_Modelo(); mdl_INTERNO_ValorDevuelto_Modelo.TodoCorrecto = true; try { obj_KairosProEntities = new KairosProEntities(); obj_KairosProEntities.Configuration.LazyLoadingEnabled = false; KRS_PerfilesLinea mdl_KRS_PerfilesLinea_AGrabar = (KRS_PerfilesLinea)_mdl_obj; KRS_PerfilesLinea mdl_KRS_PerfilesLinea_DatosViejos = new KRS_PerfilesLinea(); KRS_PerfilesLinea mdl_KRS_PerfilesLinea_Final = new KRS_PerfilesLinea(); //Tipo de Accion que se va a realizar mdl_INTERNO_ValorDevuelto_Modelo.TipoAccion = G_ENUM_TIPOACCION.INT_INSERTAR; //Validado el codigo del cliente, se lo asignamos antes de grabar mdl_KRS_PerfilesLinea_AGrabar.codigoCliente = Variables.G_LNG_IDCLIENTE_LICENCIAVALIDADO; //Cargar los Datos del modelo Funciones.CopiarPropiedadesObjetos(mdl_KRS_PerfilesLinea_AGrabar, mdl_KRS_PerfilesLinea_Final, false, false); #region INSERT string str_SQL_Insert = " INSERT INTO " + nameof(KRS_PerfilesLinea) + " (" + nameof(KRS_PerfilesLinea.idPerfilCabecera) + "," + nameof(KRS_PerfilesLinea.codigoCliente) + "," + nameof(KRS_PerfilesLinea.idJornadaCabecera) + "," + nameof(KRS_PerfilesLinea.fechaDesde) + "," + nameof(KRS_PerfilesLinea.fechaHasta) + " ) " + " OUTPUT INSERTED." + nameof(KRS_PerfilesLinea.id) + " VALUES " + " ( " + "@idPerfilCabecera," + "@codigoCliente," + "@idJornadaCabecera," + "@fechaDesde," + "@fechaHasta" + " ) "; //Parametros object[] arr_Parametros_Insert = new object[] { new SqlParameter("@idPerfilCabecera", mdl_KRS_PerfilesLinea_Final.idPerfilCabecera), new SqlParameter("@codigoCliente", mdl_KRS_PerfilesLinea_Final.codigoCliente), new SqlParameter("@idJornadaCabecera", mdl_KRS_PerfilesLinea_Final.idJornadaCabecera), new SqlParameter("@fechaDesde", mdl_KRS_PerfilesLinea_Final.fechaDesde), new SqlParameter("@fechaHasta", mdl_KRS_PerfilesLinea_Final.fechaHasta) }; #endregion //Id de la tabla mdl_INTERNO_ValorDevuelto_Modelo.Id = obj_KairosProEntities.Database.SqlQuery(str_SQL_Insert, arr_Parametros_Insert).Single(); } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Grabar), true); } finally { //Finalizar transaccion obj_KairosProEntities.Database.Connection.Close(); obj_KairosProEntities.Dispose(); } return mdl_INTERNO_ValorDevuelto_Modelo; } #endregion #region Borrar public override INTERNO_ValorDevuelto_Modelo Borrar(long _lng_id) { KairosProEntities obj_KairosProEntities = null; INTERNO_ValorDevuelto_Modelo mdl_INTERNO_ValorDevuelto_Modelo = new INTERNO_ValorDevuelto_Modelo(); mdl_INTERNO_ValorDevuelto_Modelo.TodoCorrecto = true; //Tipo de Accion que se va a realizar mdl_INTERNO_ValorDevuelto_Modelo.TipoAccion = G_ENUM_TIPOACCION.INT_ELIMINAR; try { obj_KairosProEntities = new KairosProEntities(); obj_KairosProEntities.Configuration.LazyLoadingEnabled = false; // Ver si existe ###################################################################### KRS_PerfilesLinea mdl_KRS_PerfilesLinea = Obtener_Modelo_Por_Id(_lng_id, Variables.G_LNG_IDCLIENTE_LICENCIAVALIDADO); //###################################################################################### if (mdl_KRS_PerfilesLinea != null ) { #region Delete string str_SQL_Delete = " DELETE FROM " + nameof(KRS_PerfilesLinea) + " WHERE " + nameof(KRS_PerfilesLinea.id) + "=@id and " + nameof(KRS_PerfilesLinea.codigoCliente) + "=@codigoCliente" ; //Parametros object[] arr_Parametros_Delete = new object[] { new SqlParameter("@id", _lng_id), new SqlParameter("@codigoCliente", Variables.G_LNG_IDCLIENTE_LICENCIAVALIDADO) }; #endregion //Delete obj_KairosProEntities.Database.ExecuteSqlCommand(str_SQL_Delete, arr_Parametros_Delete); // Grabar un registro de trazabilidad con los datos de la transaccion realizada. USR_Trazabilidad_Datos.Grabar_Trazabilidad(typeof(KRS_PerfilesLinea), null, mdl_KRS_PerfilesLinea, G_ENUM_TIPOACCION.INT_ELIMINAR, obj_KairosProEntities); } //Devolver tambien el objeto mdl_INTERNO_ValorDevuelto_Modelo.Id = _lng_id; } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Borrar), true); } finally { obj_KairosProEntities.Database.Connection.Close(); obj_KairosProEntities.Dispose(); } return mdl_INTERNO_ValorDevuelto_Modelo; } public override INTERNO_ValorDevuelto_Modelo Borrar(object _mdl_obj) { return null; } public override INTERNO_ValorDevuelto_Modelo Borrar(long _lng_id, long _lng_idAuxiliar) { KairosProEntities obj_KairosProEntities = null; INTERNO_ValorDevuelto_Modelo mdl_ValorDevuelto_Modelo = new INTERNO_ValorDevuelto_Modelo(); mdl_ValorDevuelto_Modelo.TodoCorrecto = true; try { obj_KairosProEntities = new KairosProEntities(); obj_KairosProEntities.Configuration.LazyLoadingEnabled = false; if (_lng_idAuxiliar>-1) { string str_SQL = " DELETE FROM " + nameof(KRS_PerfilesLinea) + " WHERE " + nameof(KRS_PerfilesLinea.idPerfilCabecera) + " =" + _lng_idAuxiliar + " AND " + nameof(KRS_PerfilesLinea.codigoCliente) + "=" + Variables.G_LNG_IDCLIENTE_LICENCIAVALIDADO; obj_KairosProEntities.Database.ExecuteSqlCommand(str_SQL); } } catch (Control_Errores) { throw; } catch (Exception ex) { throw new Control_Errores("", ex, nameof(KRS_PerfilesLinea_Datos) + "/" + nameof(Borrar), true); } finally { obj_KairosProEntities.Database.Connection.Close(); obj_KairosProEntities.Dispose(); } return mdl_ValorDevuelto_Modelo; } #endregion } }