1. //***************CObjeto*******************
using System;
using System.Collections.Generic;
using System.Text;
namespace ClasesGenerales
{
public delegate bool Seleccionar(CObjeto Objeto);
public class CObjeto
{
#region *********************** ATRIBUTOS ************************
private string aId;
#endregion *********************** ATRIBUTOS ************************
#region *********************** METODOS ************************
#region ==================== CONSTRUCTORES =======================
public CObjeto()
{
aId = "";
}
public CObjeto(string pId)
{
aId = pId;
}
#endregion ==================== CONSTRUCTORES =======================
#region ==================== PROPIEDADES =======================
public string Id
{
get { return aId; }
set { aId = value; }
}
#endregion ==================== PROPIEDADES =======================
#region ==================== OTROS =======================
// ================================================================
public override string ToString()
{
return aId;
}
// ================================================================
public override bool Equals(object Objeto)
{
return (Objeto.ToString() == aId);
}
// ================================================================
public virtual void Leer()
{
Console.Write("Identificador: ");
aId = Console.ReadLine();
}
// ================================================================
public virtual void Escribir()
{
Console.WriteLine(aId);
}
// ================================================================
public virtual void Mostrar()
{
Console.WriteLine();
Console.WriteLine("DATOS DE OBJETO");
Console.WriteLine("================");
Console.WriteLine("Identificador: " + aId);
}
#endregion =================== OTROS =======================
#endregion *********************** METODOS ************************
}
}
//*************************CListaObjetos************
using System;
using System.Collections;
using System.Collections.Generic;
2. using System.Text;
namespace ClasesGenerales
{
public class CListaObjetos
{
#region *********************** ATRIBUTOS ************************
private ArrayList aListado;
#endregion *********************** ATRIBUTOS ************************
#region *********************** METODOS ************************
#region ==================== CONSTRUCTORES =======================
public CListaObjetos()
{
aListado = new ArrayList();
}
#endregion ==================== CONSTRUCTORES =======================
#region ==================== PROPIEDADES =======================
public ArrayList Listado
{
get { return aListado; }
set { aListado = value; }
}
#endregion ==================== PROPIEDADES =======================
#region ==================== OTROS =======================
// ==============================================================
public void Agregar(CObjeto Objeto)
{
// ----- Verificar que objeto no exista en la lista
if (Indice(Objeto) < 0)
Listado.Add(Objeto);
else
// ----- Objeto ya existe en el listado, por tanto poner mensaje de error
Console.WriteLine(Objeto.Id+" ya existe en la lista, por tanto, no será
agregado...");
}
// ==============================================================
public int Indice(Object Objeto)
{
return Listado.IndexOf(Objeto.ToString());
}
// ==============================================================
public void Consultar(object pId)
{
// ----- Determinar Indice o ubicacion del Identificador
int I = Indice(pId);
if (I >= 0)
{
CObjeto Objeto = (Listado[I] as CObjeto);
Objeto.Mostrar();
}
else
// ----- Objeto no existe en el listado, por tanto poner mensaje de error
Console.WriteLine(pId + " No existe en la lista...");
}
// ==============================================================
public virtual void ProcesarObjeto(Object O)
{
CObjeto Objeto = O as CObjeto;
Objeto.Escribir();
}
// ==============================================================
public void RecorrerListado(int N)
{
if (N > 0)
{
// ----- Procesar los N-1 primeros elementos
RecorrerListado(N - 1);
// ----- Procesar N-ésimo Objeto
ProcesarObjeto(Listado[N - 1]);
}
}
3. // ==============================================================
public void RecorrerListado()
{
// ----- Recorrer listado para procesar cada objeto de la lista
RecorrerListado(Listado.Count);
}
#endregion =================== OTROS =======================
#endregion *********************** METODOS ************************
}
}
//**************************CLibro***************
using System;
using System.Collections.Generic;
using System.Text;
using ClasesGenerales;
namespace AppLibros
{
public class CLibro : CObjeto
{
#region *********************** ATRIBUTOS ************************
// -- Hereda el atributo aId
private string aTitulo;
private string aAutor;
private int aAnio;
private string aEspecialidad;
#endregion *********************** ATRIBUTOS ************************
#region *********************** METODOS ************************
#region ==================== CONSTRUCTORES =======================
public CLibro() : base()
{
aTitulo = "";
aAutor = "";
aAnio = 0;
aEspecialidad = "";
}
public CLibro(string pId, string pTitulo, string pAutor, int pAnio, string pEspecialidad)
: base(pId)
{
aTitulo = pTitulo;
aAutor = pAutor;
aAnio = pAnio;
aEspecialidad = pEspecialidad;
}
#endregion ==================== CONSTRUCTORES =======================
#region ==================== PROPIEDADES =======================
public string Codigo
{
get { return Id; }
set { Id = value; }
}
public string Titulo
{
get { return aTitulo; }
set { aTitulo = value; }
}
public string Autor
{
get { return aAutor; }
set { aAutor = value; }
}
public int Anio
{
get { return aAnio; }
set { aAnio = value; }
}
public string Especialidad
{
4. get { return aEspecialidad; }
set { aEspecialidad = value; }
}
#endregion ==================== PROPIEDADES =======================
#region ==================== OTROS =======================
// ================================================================
public override void Leer()
{
Console.WriteLine();
Console.WriteLine("INGRESAR DATOS DE LIBROS");
Console.WriteLine("===========================");
Console.Write("Código Libro: ");
Id = Console.ReadLine();
Console.Write("Título: ");
Titulo = Console.ReadLine();
Console.Write("Autor: ");
Autor = Console.ReadLine();
Console.Write("Año: ");
Anio = int.Parse(Console.ReadLine());
Console.Write("Especialidad: ");
Especialidad = Console.ReadLine();
}
// ================================================================
public override void Escribir()
{
Console.WriteLine(Id.PadRight(10) + Titulo.PadRight(20) + Autor.PadRight(30)+
Anio.ToString().PadLeft(5)+" "+Especialidad.PadRight(15));
}
// ================================================================
public override void Mostrar()
{
Console.WriteLine();
Console.WriteLine("DATOS DE LIBRO");
Console.WriteLine("=================");
Console.WriteLine("Codigo: " + Id);
Console.WriteLine("Título: " + Titulo);
Console.WriteLine("Autor: " + Autor);
Console.WriteLine("Año: " + Anio.ToString());
Console.WriteLine("Especialidad: " + Especialidad);
}
#endregion =================== OTROS =======================
#endregion *********************** METODOS ************************
}
}
//*************************CListaLibros******************
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using ClasesGenerales;
namespace AppLibros
{
public class CListaLibros : CListaObjetos
{
#region *********************** METODOS ************************
#region ==================== CONSTRUCTORES =======================
public CListaLibros() : base()
{
}
#endregion ==================== CONSTRUCTORES =======================
5. #region ==================== OTROS =======================
// ==============================================================
public void AgregarLibro()
{
// ----- Crear objeto Libro y leer sus datos
CLibro OLibro = new CLibro();
OLibro.Leer();
// ----- Agregar objeto a la Lista de Libros
Agregar(OLibro);
}
// ==============================================================
public void ConsultarLibro()
{
// ----- Leer el identificador de libro que se desea buscar
Console.WriteLine();
Console.Write("Ingrese el identificador del Libro: ");
string Id = Console.ReadLine();
// ----- Determinar Indice o ubicacion del libro
int I = Indice(Id);
if (I >= 0)
{
CLibro OLibro = (Listado[I] as CLibro);
OLibro.Mostrar();
}
else
// ----- Objeto no existe en el listado, por tanto poner mensaje de error
Console.WriteLine(Id + " No existe en la lista...");
}
// ======================================================
public void ListarLibros()
{
// ----- Poner Titulo
Console.WriteLine();
Console.WriteLine("========================================================================");
Console.WriteLine(" RELACION DE LIBROS");
Console.WriteLine("========================================================================");
Console.WriteLine("Id".PadRight(10)+"Titulo".PadRight(30)+"Autor".PadRight(20)+"Año".PadLeft(5)+"
Especialidad".PadRight(15));
Console.WriteLine("-------------------------------------------------------------------
-----");
RecorrerListado();
}
#endregion =================== OTROS =======================
#endregion *********************** METODOS ************************
}
}
//***************************CCOntrolLibros***************
using System;
using System.Collections.Generic;
using System.Text;
namespace AppLibros
{
public class CControlLibros
{
#region *********************** ATRIBUTOS ************************
private CListaLibros aListaLibros;
#endregion *********************** ATRIBUTOS ************************
#region *********************** METODOS ************************
#region ==================== CONSTRUCTORES =======================
6. public CControlLibros()
{
aListaLibros = new CListaLibros();
}
#endregion ==================== CONSTRUCTORES =======================
#region ==================== PROPIEDADES =======================
public CListaLibros ListaLibros
{
get { return aListaLibros; }
set { aListaLibros = value; }
}
#endregion ==================== PROPIEDADES =======================
#region ==================== OTROS =======================
// ======================================================
public void Menu()
{
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("**************************************");
Console.WriteLine("* CONTROL DE LIBROS *");
Console.WriteLine("**************************************");
Console.WriteLine("1.- Registrar Libro");
Console.WriteLine("2.- Consultar Libro");
Console.WriteLine("3.- Listar Libros");
Console.WriteLine("4.- Salir");
}
// ======================================================
public void Ejecutar()
{
// ----- Procesar opciones y Menu
int Opcion;
do
{
Menu();
// ----- Leer Opcion
Console.Write("Ingresa Opcion: ");
Opcion = int.Parse(Console.ReadLine());
Console.WriteLine("");
switch (Opcion)
{
case 1: ListaLibros.AgregarLibro();
break;
case 2 : ListaLibros.ConsultarLibro();
break;
case 3 : ListaLibros.ListarLibros();
break;
} // -- fin de switch
} while (Opcion < 4);
}
#endregion =================== OTROS =======================
#endregion *********************** METODOS ************************
}
}
//******************AppLibros****************
using System;
using System.Collections.Generic;
using System.Text;
namespace AppLibros
{
class Program
{
static void Main(string[] args)
{
CControlLibros OControlLibros = new CControlLibros();
OControlLibros.Ejecutar();
}
}
}