Ejemplo n.º 1
0
        public List <Gastos> obtener(string id)
        {
            string where = "";
            if (fecha != "")
            {
                where += " where id=@id";
            }

            List <Gastos> ret = new List <Gastos>();

            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 gastos" + where;
            cmd.Parameters.AddWithValue("@fecha", fecha);

            try
            {
                if (Database.obtenerTransaccion() == null)
                {
                    conexion.Open();
                }
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Gastos bar = new Gastos();
                    cargarDatos(bar, reader);
                    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);
        }
Ejemplo n.º 2
0
        private List <Gastos> crear_lista_gastos(string desde, string hasta)
        {
            List <Gastos> ret = new List <Gastos>();

            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 (SELECT empleados_grupos.*, gastos.fecha, gastos.detalles, gastos.importe from empleados_grupos LEFT JOIN gastos on gastos.grupo = empleados_grupos.id) as base 
                                where (fecha BETWEEN @fecha1 AND @fecha2) or fecha IS NULL";
            cmd.Parameters.AddWithValue("@fecha1", Convert.ToDateTime(desde));
            cmd.Parameters.AddWithValue("@fecha2", Convert.ToDateTime(hasta));

            try
            {
                if (Database.obtenerTransaccion() == null)
                {
                    conexion.Open();
                }
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Gastos bar = new Gastos();
                    bar.fecha        = Convert.ToDateTime(reader["fecha"].ToString()).ToShortDateString();
                    bar.grupo_nombre = reader["nombre"].ToString();
                    bar.importe      = Convert.ToDecimal(reader["importe"].ToString());
                    bar.detalles     = reader["detalles"].ToString();
                    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);
        }
Ejemplo n.º 3
0
        public Gastos obtener_gastos(string id)
        {
            Gastos tmp = new Gastos();

            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 gastos where id=@id";
            cmd.Parameters.AddWithValue("@id", id);

            try
            {
                if (Database.obtenerTransaccion() == null)
                {
                    conexion.Open();
                }
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    tmp.fecha        = Convert.ToDateTime(reader["fecha"].ToString()).ToShortDateString();
                    tmp.grupo_id     = reader["grupo"].ToString();
                    tmp.importe      = Convert.ToDecimal(reader["importe"].ToString());
                    tmp.detalles     = reader["detalles"].ToString();
                    tmp.asignado_por = reader["asignado_por"].ToString();
                }

                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(tmp);
        }
Ejemplo n.º 4
0
 private static void cargarDatos(Gastos gasto, MySqlDataReader dr)
 {
     gasto.id                    = dr["id"].ToString();
     gasto.fecha                 = Convert.ToDateTime(dr["fecha"].ToString()).ToShortDateString();
     gasto.grupo_id              = dr["grupo"].ToString();
     gasto.grupo_nombre          = dr["nombre"].ToString();
     gasto.importe               = Convert.ToDecimal(dr["importe"].ToString());
     gasto.detalles              = dr["detalles"].ToString();
     gasto.asignado_por          = dr["asignado_por"].ToString();
     gasto.asignado_por_empleado = dr["asignado_por_empleado"].ToString();
 }
Ejemplo n.º 5
0
        public List <Gastos> obtenerFiltrado(ItemFiltro[] itemFiltro,
                                             ItemOrden[] orden, bool busquedaAnd, double inicio, double fin, out double totalRegistros)
        {
            List <Gastos> ret = new List <Gastos>();

            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 (select base.*, concat(empleados.apellido, ', ', empleados.nombre) as asignado_por_empleado 
            from (select gastos.*, empleados_grupos.nombre from gastos 
            left join empleados_grupos on gastos.grupo = empleados_grupos.id) as base left join empleados on base.asignado_por = empleados.id) as base2 " + 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, "fecha");

                //TODO: Hacer Paginacion

                double rowcount = fin - (inicio - 1);

                comando.CommandText = @"SELECT * FROM (select base.*, concat(empleados.apellido, ', ', empleados.nombre) as asignado_por_empleado 
                from (select gastos.*, empleados_grupos.nombre from gastos 
                left join empleados_grupos on gastos.grupo = empleados_grupos.id) as base left join empleados on base.asignado_por = empleados.id) as base2 " + where + " "
                                      + cadenaOrden
                                      + " LIMIT " + (inicio - 1) + ", " + rowcount;

                MySqlDataReader dr = comando.ExecuteReader();

                while (dr.Read())
                {
                    Gastos bar = new Gastos();
                    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);
        }