BLL.Presupuesto.Buscar C# (CSharp) Method

Buscar() public method

public Buscar ( int IdBuscado ) : bool
IdBuscado int
return bool
        public override bool Buscar(int IdBuscado)
        {
            ConexionDb conexion = new ConexionDb();
            DataTable dt = new DataTable();
            DataTable detalleDt = new DataTable();

            try
            {
                dt = conexion.ObtenerDatos(String.Format("Select * From Presupuestos Where PresupuestoId = {0} --", IdBuscado));
                if (dt.Rows.Count > 0)
                {
                    this.PresupuestoId = (int)dt.Rows[0]["PresupuestoId"];
                    this.UsuarioId = (int)dt.Rows[0]["UsuarioId"];
                    this.Descripcion = dt.Rows[0]["Descripcion"].ToString();
                }
                detalleDt = conexion.ObtenerDatos(String.Format("Select * From PresupuestoDetalle Where PresupuestoId = {0} --", IdBuscado));
                if (detalleDt.Rows.Count > 0)
                {
                    foreach (DataRow dr in detalleDt.Rows)
                        this.AgregarDetalle((int)dr["TipoEgresoId"], Convert.ToSingle(dr["Monto"]));
                }
            }
            catch
            {
                return false;
            }
            return dt.Rows.Count > 0;
        }

Usage Example

 protected void BuscarButton_Click(object sender, EventArgs e)
 {
     Presupuesto presupuesto = new Presupuesto();
     if (presupuesto.Buscar(Convert.ToInt16(PresupuestoTextBox.Text)))
     {
         LlenarRegistro(presupuesto);
         Utilitarios.ShowToastr(this, "Busqueda exitosa", "Exito");
         PresupuestoTextBox.Enabled = false;
     }
     else
     {
         Limpiar();
         Utilitarios.ShowToastr(this, "No se pudo encontrar el presupuesto especificado", "Error", "error");
     }
 }
All Usage Examples Of BLL.Presupuesto::Buscar