private static void cargarDatos(Viaticos objeto, MySqlDataReader dr) { objeto.Id = dr[dbCampoCodigo].ToString(); objeto.Descripcion = dr[dbCampoDescripcion].ToString(); objeto.Importe = Convert.ToDecimal(dr[dbCampoImporte].ToString()).ToString("F2"); objeto.DescripcionImporte = objeto.Descripcion + " - $ " + objeto.Importe; }
public List <Viaticos> obtener(string codigo = "") { string where = ""; if (codigo != "") { where += " where viatico_codigo=@codigo "; } List <Viaticos> ret = new List <Viaticos>(); UltimoMensaje = null; DAL.Database db = new Database(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = "select * from viaticos" + where; cmd.Parameters.AddWithValue("@codigo", codigo); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Viaticos bar = new Viaticos(); bar.Id = reader[dbCampoCodigo].ToString(); bar.Descripcion = reader[dbCampoDescripcion].ToString(); bar.Importe = reader[dbCampoImporte].ToString(); bar.DescripcionImporte = bar.Descripcion + " - $ " + bar.Importe; ret.Add(bar); } reader.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }
} // Unsubscribe #endregion public List <Viaticos> obtenerFiltrado(ItemFiltro[] itemFiltro, ItemOrden[] orden, bool busquedaAnd, double inicio, double fin, out double totalRegistros) { List <Viaticos> ret = new List <Viaticos>(); UltimoMensaje = null; MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand(); comando.Connection = conexion; comando.Transaction = Database.obtenerTransaccion(); totalRegistros = 0; int parameterCount = 0; string where = ""; string tipoBusqueda = " AND "; if (!busquedaAnd) { tipoBusqueda = " OR "; } Varios.armarConsultaFiltros(itemFiltro, comando, ref parameterCount, ref where, tipoBusqueda); string cadenaOrden = ""; comando.CommandText = "SELECT count(*) FROM " + dbTabla + " " + where; try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } double.TryParse(comando.ExecuteScalar().ToString(), out totalRegistros); if (inicio < 0) { inicio = 0; } if (inicio > totalRegistros) { inicio = totalRegistros - 1; } if (fin > totalRegistros || fin == -1) { fin = totalRegistros; } if (inicio < 1) { inicio = 1; } if (fin < 1) { fin = 1; } cadenaOrden = Varios.armarCadenaOrden(orden, cadenaOrden, dbCampoDescripcion); //TODO: Hacer Paginacion double rowcount = fin - (inicio - 1); comando.CommandText = " SELECT * FROM " + dbTabla + " " + where + " " + cadenaOrden + " LIMIT " + (inicio - 1) + ", " + rowcount; MySqlDataReader dr = comando.ExecuteReader(); while (dr.Read()) { Viaticos bar = new Viaticos(); bar.Subscribe(this); cargarDatos(bar, dr); ret.Add(bar); } dr.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }