private void guardarAsincrono(Object objBase) { PaqueteGuardado p = (PaqueteGuardado)objBase; try { AlmacenObjetos.GuardarObjeto(p.ObjetoBaseGuardar); p.ObjetoBaseGuardar.DBAccesoOBJ = this.dbAcceso; p.ObjetoBaseGuardar.SUsuarioResponsable = ObjetoBase.UsuarioLogueado; long idHilo = p.ObjetoBaseGuardar.Guardar(); //if (guardadoTerminado == null) // throw new Exception("Se requiere implementar el evento 'GuardadoTerminado'."); if (guardadoTerminado != null) { guardadoTerminado(p.Identificador, "Guardado exitoso.", idHilo); } } catch (Exception ex) { //throw new Exception(ex.Message); if (guardadoTerminado != null) { guardadoTerminado(p.Identificador, "Error: " + ex.Message, -1); } } }
public long Guardar(ObjetoBase objBase) { try { objBase.Manejador = this; AlmacenObjetos.GuardarObjeto(objBase); objBase.DBAccesoOBJ = this.dbAcceso; objBase.SUsuarioResponsable = ObjetoBase.UsuarioLogueado; return(objBase.Guardar()); } catch (Exception ex) { throw new Exception(ex.Message); } }
public List <ObjetoBase> Cargar(Type tipo, String consulta, List <Object> valores) { //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- //AQUI SE TIENE Q BUSCAR LA SEPARACION DE BUSQUEDAS ENTRE ALMACEN DE OBJETOS Y BASE DE DATOS //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- try { DataTable resultado = null; List <ObjetoBase> retorno = null; //la consulta se cambia, para q solamente traiga IDS de la base de datos. String consultaIDS = ModificarConsultaParaAlmacen(consulta); Boolean TrajoIDS = false; //UsarAlmacenObjetos = false; //deshabilitamos el almacen de objetos // se intenta usar la consulta modificada if (UsarAlmacenObjetos) { try { //se traen los ids de los objetos y se marca la variable de control resultado = this.dbAcceso.EjecutarConsulta(consultaIDS, valores); TrajoIDS = true; } catch { //si ocurrio un error, y se debio a que la consulta estaba mal modificada, entonces //se usa la consulta original. resultado = this.dbAcceso.EjecutarConsulta(consulta, valores); } } if (TrajoIDS) { retorno = new List <ObjetoBase>(); List <long> idsRestantes = new List <long>(); ObjetoBase objetoTemp = null; foreach (DataRow dr in resultado.Rows) { long idT = Convert.ToInt64(dr["id"]); objetoTemp = AlmacenObjetos.ObtenerObjeto(tipo, idT); if (objetoTemp != null) { retorno.Add(objetoTemp); //Log.EscribirLog("ALMACEN: RETORNADO [tipo: "+tipo.Name+", id: "+idT+"]."); } else { idsRestantes.Add(idT); retorno.Add(null); } } if (idsRestantes.Count > 0) { String stridsRestantes = ""; foreach (long idR in idsRestantes) { stridsRestantes += "(" + idR + "), "; } stridsRestantes = stridsRestantes.Substring(0, stridsRestantes.Length - 2); //String consultaIdStr = "select * from " + tipo.Name + " where id in " + stridsRestantes; String consultaIdStr = @"select tabla.* from " + tipo.Name + @" as tabla inner join (values " + stridsRestantes + @") as Valores(id) on tabla.id = Valores.id;"; DataTable resultado2 = dbAcceso.EjecutarConsulta(consultaIdStr); // id = @id", new List<object>() { idT }); if (resultado2.Rows.Count > 0) { IList retorTemp = dbAcceso.MapearDataTableAObjecto(tipo, resultado2); int i = 0; foreach (ObjetoBase o in retorTemp) { AlmacenObjetos.GuardarObjeto(o); for (; i < retorno.Count; i++) { if (retorno[i] == null) { retorno[i] = o; break; } } //retorno.Add(o); //Log.EscribirLog("ALMACEN: AGREGADO [tipo: " + tipo.Name + ", id: " + idT + "]."); } } } } else { resultado = this.dbAcceso.EjecutarConsulta(consulta, valores); //Log.EscribirLog("ALMACEN: ERROR Fallo al convertir la consulta."); if (resultado.Rows.Count > 0) { retorno = dbAcceso.MapearDataTableAObjecto(tipo, resultado).Cast <ObjetoBase>().ToList(); foreach (ObjetoBase o in retorno) { o.Manejador = this; AlmacenObjetos.GuardarObjeto(o); } } } if (retorno != null) { foreach (ObjetoBase objBase in retorno) { objBase.Manejador = this; objBase.DBAccesoOBJ = dbAcceso; } } //resultado = this.dbAcceso.EjecutarConsulta(consulta, valores); //if (resultado.Rows.Count > 0) //{ // retorno = dbAcceso.MapearDataTableAObjecto(tipo, resultado); // foreach (ObjetoBase o in retorno) // { // AlmacenObjetos.GuardarObjeto(o); // } //} if (retorno == null) { return(null); } return(retorno.Cast <ObjetoBase>().ToList()); } catch (Exception ex) { throw new Exception(ex.Message); } }