protected void comprar_Click(object sender, EventArgs e) { if (comprar.Text == "Volver") { Response.Redirect("home.aspx"); } else { if (Session[Session.SessionID + "usuario"] == null) { Response.Redirect("login.aspx"); } usuario = (Usuario)Session[Session.SessionID + "usuario"]; if (usuario.direccion.id == 1) { Response.Redirect("agregardomicilio.aspx"); } else { SmtpClient smtp = (SmtpClient)Session[Session.SessionID + "smtp"]; MailMessage email = (MailMessage)Session[Session.SessionID + "email"]; bool compro = true; venta.idUsuario = usuario.id; venta.precioTotal = carrito.precioTotal; venta.fecha = DateTime.Now.Date; ventaNegocio.Agregar(venta); venta.idVenta = ventaNegocio.BuscarVenta(); foreach (var item in carrito.carro) { ventaArticulo.idArticulo = item.id; ventaArticulo.idVenta = venta.idVenta; ventaArticulo.cantidad = item.cantidad; ventaArticulo.money = item.precio / item.cantidad; ventaArticuloNegocio.Agregar(ventaArticulo); negocio.Venta(item.id, item.cantidad); } carrito.carro.Clear(); carrito.cantArt = 0; carrito.precioTotal = 0; Session.Add(Session.SessionID + "articulo", carrito); Session.Add(Session.SessionID + "compro", compro); email.To.Add(new MailAddress("*****@*****.**")); email.Body = "El usuario <b>" + usuario.userName + "</b> realizo una compra"; email.Subject = "NUEVA COMPRA"; smtp.Send(email); email.To.Add(new MailAddress(usuario.email)); email.Subject = "EN CASA - Compra realizada el" + DateTime.Now.ToString("dd / MMM / yyy hh: mm: ss"); email.Body = "Envio el Link de Pago por la compra realizada <b>link de pago</b>"; smtp.Send(email); email.Dispose(); Response.Redirect("Carrito.aspx"); } } }
private void BtnMod_Click(object sender, EventArgs e) { VentaNegocio negV = new VentaNegocio(); ProductoVendidoNegocio negPV = new ProductoVendidoNegocio(); try { if (v.IdVenta == 0) { v.Cliente = new Cliente(); v.Empleado = new Empleado(); } v.Cliente = (Cliente)BoxCliente.SelectedItem; v.Empleado = (Empleado)BoxEmpleado.SelectedItem; v.FechaVenta = DateFecha.Value; v.Monto = (float)Convert.ToDouble(TxtTotal.Text); if (v.IdVenta != 0) { negV.Modificar(v); negPV.EliminarProductosDeVenta(v.IdVenta); } else { v.IdVenta = Convert.ToInt32(negV.Agregar(v)); } foreach (ProductoVendido pv in v.LstProductosVendidos) { pv.IdVenta = v.IdVenta; pv.IdPxv = negPV.Agregar(pv); negPV.DescontarStock(pv); } Invoicer i = new Invoicer(); i.Go(v); Mensaje m = new Mensaje("PDF Generado."); m.ShowDialog(); this.Close(); } catch (Exception ex) { Mensaje m = new Mensaje(ex.ToString()); m.ShowDialog(); } }