Example #1
0
 private static void cargarDatos(TareasEstados objeto, MySqlDataReader dr)
 {
     objeto.Id     = dr[dbCampoCodigo].ToString();
     objeto.Nombre = dr[dbCampoNombre].ToString();
     objeto.Tipo   = dr[dbCampoTipo].ToString();
 }
Example #2
0
        } // Unsubscribe

        #endregion

        public List <TareasEstados> obtenerFiltrado(ItemFiltro[] itemFiltro,
                                                    ItemOrden[] orden, bool busquedaAnd, double inicio, double fin, out double totalRegistros)
        {
            List <TareasEstados> ret = new List <TareasEstados>();

            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, dbCampoNombre);

                //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())
                {
                    TareasEstados bar = new TareasEstados();
                    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);
        }
Example #3
0
        public List <TareasEstados> obtener(string codigo = "", string tipo = "")
        {
            string where = "";
            if (codigo != "")
            {
                where += " where tarea_estado_codigo=@codigo ";
            }
            if (tipo != "")
            {
                where += " where tarea_estado_tipo=@tipo";
            }

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

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

            try
            {
                if (Database.obtenerTransaccion() == null)
                {
                    conexion.Open();
                }
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    TareasEstados bar = new TareasEstados();
                    bar.Id     = reader[dbCampoCodigo].ToString();
                    bar.Nombre = reader[dbCampoNombre].ToString();
                    bar.Tipo   = reader[dbCampoTipo].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);
        }