Example #1
0
 private static void cargarDatos(Empleados_logs log, MySqlDataReader reader)
 {
     log.fecha       = Convert.ToDateTime(reader["fecha"].ToString()).ToShortDateString();
     log.hora        = Convert.ToDateTime(reader["hora"].ToString()).ToShortTimeString();
     log.modulo      = reader["modulo"].ToString();
     log.accion      = reader["accion"].ToString();
     log.usuario     = reader["usuario"].ToString();
     log.empleado_id = reader["empleado_id"].ToString();
 }
Example #2
0
        public List <Empleados_logs> obtenerFiltrado(ItemFiltro[] itemFiltro,
                                                     ItemOrden[] orden, bool busquedaAnd, double inicio, double fin, out double totalRegistros)
        {
            List <Empleados_logs> ret = new List <Empleados_logs>();

            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 empleados_logs " + 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 empleados_logs " + where + " "
                                      + cadenaOrden
                                      + " LIMIT " + (inicio - 1) + ", " + rowcount;

                MySqlDataReader dr = comando.ExecuteReader();

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