agregar un libro con herencias y linq en proceso.
C sharp
1.682 visualizaciones desde el 27 de Junio del 2018
permite agregar un libro con sus datos el cual podrá ser ordenado según necesidad del usuario.(incompleto)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Libros
{
public enum EnumTipoLibro
{
Impreso,
Digital
}
}
/////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Libros
{
public interface ITipoLibroParticular
{
bool EsRenovable { get; }
bool EsReproducible { get; }
}
}
/////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Libros
{
public class LibroColleccion: List<TipoLibro>
{
public int MayorAnnos()
{
return this.Max(r => r.Annos);
}
public int MenorAnnos()
{
return this.Min(r => r.Annos);
}
public int CantImpresoReproducibles()
{
return this.Where(r => (r is TipoLibroImpreso)).Count(r => ((TipoLibroImpreso)r).EsReproducible == true);
}
public int CantLibrosReproducible()
{
}
}
}
////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Libros
{
public class TipoDigital : TipoLibro, ITipoLibroParticular
{
public int CantMegas { get; set; }
public TipoDigital()
{
base.Tipo = EnumTipoLibro.Digital;
}
public bool EsRenovable
{
get
{
return (Annos > 5) ;
}
}
public bool EsReproducible
{
get
{
return (CantMegas < 8) ;
}
}
}
}
////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Libros
{
public class TipoLibro
{
private int _annos;
private string _titulo;
private string _autor;
public string Titulo
{
get { return _titulo; }
set
{
if (string.IsNullOrEmpty(value))
{
throw new Exception("El titulo no puede ser vacio");
}
_titulo = value;
}
}
public string Autor
{
get { return _autor; }
set { _autor = value; }
}
public int Annos
{
get { return _annos; }
set { _annos = value; }
}
public EnumTipoLibro Tipo { get; set; }
}
}
////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Libros
{
public class TipoLibroImpreso :TipoLibro, ITipoLibroParticular
{
public int CantPaginas{ get;set; }
public TipoLibroImpreso()
{
base.Tipo = EnumTipoLibro.Impreso;
}
public bool EsRenovable
{
get
{
return (Annos > 3);
}
}
public bool EsReproducible
{
get
{
return (CantPaginas < 500) ;
}
}
}
}
//////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Libros;
namespace Libreria
{
/// <summary>
/// Lógica de interacción para MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
LibroColleccion ListaLibros = new LibroColleccion();
public MainWindow()
{
InitializeComponent();
}
private void btnAgregar_Click(object sender, RoutedEventArgs e)
{
//try
//{
TipoLibro lib = new TipoLibro();
if (rdImpreso.IsChecked.Value)
{
lib = new TipoLibroImpreso();
((TipoLibroImpreso)lib).CantPaginas = int.Parse(txtPaginas.Text.Trim());
}
if (rdDigital.IsChecked.Value)
{
lib = new TipoDigital();
((TipoDigital)lib).CantMegas = int.Parse(txtMegas.Text.Trim());
}
lib.Titulo = txtTitulo.Text.Trim();
lib.Autor = txtAutor.Text.Trim();
lib.Annos = int.Parse(txtAnnos.Text.Trim());
ListaLibros.Add(lib);
Datos.ItemsSource = ListaLibros;
Datos.Items.Refresh();
int mayor = ListaLibros.MayorAnnos();
int menor = ListaLibros.MenorAnnos();
int reproducible = ListaLibros.CantImpresoReproducibles();
txtReproducible.Text = reproducible.ToString();
txtMayor.Text = mayor.ToString();
txtMenor.Text = menor.ToString();
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
}
private void rdImpreso_Checked(object sender, RoutedEventArgs e)
{
txtMegas.Text = "";
txtMegas.IsEnabled = false;
txtPaginas.IsEnabled = true;
}
private void rdDigital_Checked(object sender, RoutedEventArgs e)
{
txtPaginas.Text = "";
txtPaginas.IsEnabled = false;
txtMegas.IsEnabled = true;
}
}
}
No hay comentarios