public static bool AltaDeProductoPorTipo(string nombre, float precioUnitario, int cantidad, string marca, string tipoDeProducto, List <Producto> listaAñadirProducto) { bool retValue = false; switch (tipoDeProducto) { case ("Kiosco"): ProductoKiosko nuevoProductoKiosko = new ProductoKiosko(nombre, precioUnitario, cantidad, marca); listaAñadirProducto.Add(nuevoProductoKiosko); retValue = true; break; case ("Perecedero"): ProductoPerecedero nuevoProductoPerecedero = new ProductoPerecedero(nombre, precioUnitario, cantidad, marca); listaAñadirProducto.Add(nuevoProductoPerecedero); retValue = true; break; case ("Viveres"): ProductoViveres nuevoProductoViveres = new ProductoViveres(nombre, precioUnitario, cantidad, marca); listaAñadirProducto.Add(nuevoProductoViveres); retValue = true; break; default: retValue = false; break; } return(retValue); }
public static void Harcodeos() { Cliente PrimerCliente = new Cliente("Homero", "simpson", 32425312); Cliente SegundoCliente = new Cliente("Ned", "flanders", 25789632); Cliente TercerCliente = new Cliente("March", "simpson", 14526325); listaDeClientes.Add(PrimerCliente); listaDeClientes.Add(SegundoCliente); listaDeClientes.Add(TercerCliente); Empleado PrimerEmpleado = new Empleado("Fineas", "Grant", 32456987, Empleado.EArea.Caja, "fagrant"); Empleado SegundoEmpleado = new Empleado("Lola", "Palooza", 25418745, Empleado.EArea.Ventas, "lpalooza"); Empleado TercerEmpleado = new Empleado("Nasha", "Yeloso", 32456987, Empleado.EArea.Gerencia, "Nyeloso"); listaDeEmpleados.Add(PrimerEmpleado); listaDeEmpleados.Add(SegundoEmpleado); listaDeEmpleados.Add(TercerEmpleado); Producto PrimerProducto = new ProductoPerecedero("Leche", 125, 0, "La veronica"); Producto SegundoProducto = new ProductoPerecedero("Manteca", 12, 12, "Girasol"); Producto TercerProducto = new ProductoPerecedero("Jamon", 125, 12, "El cerdito"); Producto CuartoProducto = new ProductoViveres("Arroz", 49.5f, 2, "3 hermanos"); Producto QuintoProducto = new ProductoViveres("Azucar", 35.5f, 2, "La dulsura"); Producto SextoProducto = new ProductoViveres("Harina", 49.5f, 5, "Salinas"); Producto SeptimoProducto = new ProductoKiosko("Dulce de Leche", 125.2f, 12, "Vauquita"); Producto OctavoProducto = new ProductoKiosko("Chocolate", 80, 12, "Cacao"); Producto NovenoProducto = new ProductoKiosko("Alfajor lalala", 45, 1, "Guaymayen"); listaDeProductos.Add(PrimerProducto); listaDeProductos.Add(SegundoProducto); listaDeProductos.Add(TercerProducto); listaDeProductos.Add(CuartoProducto); listaDeProductos.Add(QuintoProducto); listaDeProductos.Add(SextoProducto); listaDeProductos.Add(SeptimoProducto); listaDeProductos.Add(OctavoProducto); listaDeProductos.Add(NovenoProducto); Venta PrimeraVenta = new Venta(PrimerCliente, PrimerEmpleado, 1235); Venta SegundaVenta = new Venta(SegundoCliente, SegundoEmpleado, 1352); Venta TerceraVenta = new Venta(TercerCliente, TercerEmpleado, 1500); listaDeVentas.Add(PrimeraVenta); listaDeVentas.Add(SegundaVenta); listaDeVentas.Add(TerceraVenta); }
/// <summary> /// Trae un producto de la base de datos identificado con el ID /// </summary> /// <param name="id"></param> /// <returns>Objeto de tipo producto</returns> public Producto LeerPorID(int id) { Producto prod = null; try { comando.CommandText = "Select * from Productos where id = " + id.ToString(); conexion.Open(); SqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { string tipo = reader["tipoProducto"].ToString(); if (tipo == "perecedero") { prod = new ProductoPerecedero(reader["descripcion"].ToString(), id, double.Parse(reader["Precio"].ToString()), int.Parse(reader["cantidad"].ToString()), Producto.ETipo.perecedero); } else { prod = new ProductoNoPerecedero(reader["descripcion"].ToString(), id, double.Parse(reader["Precio"].ToString()), int.Parse(reader["cantidad"].ToString()), Producto.ETipo.noPerecedero); } } reader.Close(); } catch (Exception e) { throw new ArchivosException("Falla al intentar leer la base de datos", e); } finally { conexion.Close(); } return(prod); }