public void ProductosIguales() { Congelado c1 = new Congelado(1, "c1", "marca1", 1, DateTime.Now); Congelado c2 = new Congelado(1, "c2", "marca2", 2, DateTime.Now); Assert.AreEqual(c1, c2); }
/// <summary> /// Chequea datos del formulario /// Genera el atributo venta con todos los datos y la lista de productos a partir de la grilla /// </summary> private void btnAceptar_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtFactura.Text) || string.IsNullOrWhiteSpace(txtCliente.Text) || cmbCajas.SelectedIndex == -1 || dtProductosVenta.Rows.Count == 0) { MessageBox.Show("Por favor complete todos los datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { this.venta = new Venta <Producto>(); venta.factura = int.Parse(txtFactura.Text); venta.cliente = txtCliente.Text; venta.caja = (ECaja)Enum.Parse(typeof(ECaja), cmbCajas.SelectedIndex.ToString()); foreach (DataRow item in dtProductosVenta.Rows) { int id = int.Parse(item["Id"].ToString()); string nombre = item["Nombre"].ToString(); string marca = item["Marca"].ToString(); double precio = double.Parse(item["PrecioUnitario"].ToString()); string tipo = item["Tipo"].ToString(); EMaterial material; DateTime vencimiento; if (tipo == "Congelado") { vencimiento = DateTime.Parse(item["FechaVencimiento"].ToString()); Congelado c = new Congelado(id, nombre, marca, precio, vencimiento); venta += c; } else { material = (EMaterial)Enum.Parse(typeof(EMaterial), item["Material"].ToString()); Bazar b = new Bazar(id, nombre, marca, precio, material); venta += b; } } this.Close(); } }
static void Main(string[] args) { Congelado c1 = new Congelado(1, "Espinaca", "Carrefour", 50, DateTime.Now.AddDays(30)); Congelado c2 = new Congelado(2, "Hamburguesas", "Paty", 150.50, DateTime.Now.AddDays(10)); Congelado c3 = new Congelado(3, "Espinaca", "Carrefour", 50, DateTime.Now.AddDays(20)); Bazar b1 = new Bazar(4, "Balde", "Colombraro", 300, EMaterial.Plastico); Bazar b2 = new Bazar(5, "Jarra", "Luxury", 122.35, EMaterial.Vidrio); Bazar b3 = new Bazar(6, "Silla", "Maderera San Juan", 1500, EMaterial.Madera); Comercio c = new Comercio(); try { Venta <Producto> v1 = new Venta <Producto>(1, "Juan Perez", ECaja.CajaUno); v1.CambioEstado += venta_EventoCambioEstado; v1 += c1; v1 += b1; Console.WriteLine("Nueva venta: \n{0}", v1.ToString()); c += v1; Venta <Producto> v2 = new Venta <Producto>(2, "Jorge Rojas", ECaja.CajaDos); v2.CambioEstado += venta_EventoCambioEstado; v2 += c2; v2 += c3; Console.WriteLine("Nueva venta: \n{0}", v2.ToString()); c += v2; Venta <Producto> v3 = new Venta <Producto>(1, "Pedro Gonzales", ECaja.CajaTres); v3.CambioEstado += venta_EventoCambioEstado; v3 += b2; v3 += b3; Console.WriteLine("Nueva venta: \n{0}", v3.ToString()); c += v3; } catch (FacturaRepetidaException ex) { Console.WriteLine(ex.Message); } System.Threading.Thread.Sleep(11000); Console.WriteLine("Presione una tecla para continuar ..."); Console.ReadKey(); Console.Clear(); Console.WriteLine(c.ToString()); Console.WriteLine("Presione una tecla para continuar ..."); Console.ReadKey(); Console.Clear(); Exportador <List <Venta <Producto> > > exp = new Exportador <List <Venta <Producto> > >(); string archivo = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\ventas.xml"; try { exp.Exportar(archivo, c.Ventas); Console.WriteLine("Se ha exportado los datos de ventas al archivo '{0}'", archivo); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Fin del test. Presione una tecla para terminar ..."); Console.ReadKey(); }