Envio de Email y interfaz de Admin

This commit is contained in:
Soka_jplr 2024-03-17 21:00:44 -06:00
parent c8ebca08e3
commit 40a708ec48
16 changed files with 354 additions and 68 deletions

Binary file not shown.

View File

@ -40,6 +40,7 @@ public class ControladorBoleto implements ActionListener{
ventana.revalidate();
ventana.repaint();
pintarZona();
admin();
}
private void cambiarPanel(JPanel panelB) {
@ -136,4 +137,42 @@ public class ControladorBoleto implements ActionListener{
}
}
private void validar() {
double precio = consulta.getPrecioPorZona(ventana.getZona());
ventana.getTxtPrecio().setText(""+precio);
if("admin".equals(ventana.getUser().getTipo())){
ventana.getTxtPrecio().setVisible(true);
ventana.getLbPrecio().setVisible(true);
ventana.getBtnCambiarP().setVisible(true);
}else{
ventana.getTxtPrecio().setVisible(false);
ventana.getLbPrecio().setVisible(false);
ventana.getBtnCambiarP().setVisible(false);
}
}
private void admin() {
validar();
ventana.getBtnCambiarP().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(ventana.getTxtPrecio().getText()==""){
JOptionPane.showMessageDialog(null, "Error. LLena el campo");
}else{
double precio = Double.parseDouble(ventana.getTxtPrecio().getText());
if(consulta.cambiarP(ventana.getZona(),precio)){
JOptionPane.showMessageDialog(null, "Precio de la zona cambiado a: " + precio);
SalaPrincipal ven = new SalaPrincipal(ventana.getUser());
ven.setLocationRelativeTo(null);
ven.setVisible(true);
ventana.dispose();
}else{
JOptionPane.showMessageDialog(null, "Error. fallo en la BD");
}
}
}
});
}
}

View File

@ -20,6 +20,9 @@ public class ControladorCP implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(e.getSource()==ventana.getBtnMenu()){
SalaPrincipal vent = new SalaPrincipal(ventana.getUser());
vent.setLocationRelativeTo(null);
vent.setVisible(true);
ventana.dispose();
}
}

View File

@ -152,4 +152,14 @@ public final class ControladorEcenario implements MouseListener{
public void mouseExited(MouseEvent e) {
}
public void validarUsuario() {
double montoR = consulta.montoR();
ventanaSala.getLbMontoR().setText("Monto Recaudado: " + "$"+montoR);
if(ventanaSala.getUser().getTipo()=="admin"){
ventanaSala.getLbMontoR().setVisible(false);
}else{
ventanaSala.getLbMontoR().setVisible(true);
}
}
}

View File

@ -204,4 +204,56 @@ public class Consulta {
return verificar;
}
public double montoR() {
double montoR =0;
try {
conexion = cn.conectar();
Statement stm;
String sql ="select sum(Z.precio) as monto from compra C, zona Z where zona_id = Z.id;";
stm = conexion.createStatement();
ResultSet resultado = stm.executeQuery(sql);
while(resultado.next()){
montoR = resultado.getDouble(1);
}
cn.cerrarconexion();
} catch (SQLException e) {
System.out.println(e.toString());
}
return montoR;
}
public double getPrecioPorZona(Zona zona) {
double precio = 0;
try {
conexion = cn.conectar();
Statement stm;
String sql ="select precio from zona where id = "+zona.getId()+";";
stm = conexion.createStatement();
ResultSet resultado = stm.executeQuery(sql);
while(resultado.next()){
precio = resultado.getDouble(1);
}
cn.cerrarconexion();
} catch (SQLException e) {
System.out.println(e.toString());
}
return precio;
}
public boolean cambiarP(Zona zona, double precio) {
boolean verificar = false;
try {
PreparedStatement ps;
conexion = cn.conectar();
ps= conexion.prepareStatement("UPDATE `zona` SET `precio`= " +precio
+ "where id= '"+ zona.getId()+"';");
ps.executeUpdate();
verificar = true;
cn.cerrarconexion();
} catch (Exception e) {
System.out.println(e.toString());
}
return verificar;
}
}

View File

@ -1,33 +1,92 @@
package Modelo;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
*
* @author Daniel
*/
public class EnviarCorreo {
public class EnviarCorreo implements Runnable{
private static String emailFrom= "drannet9@gmail.com";
private static String passwordFrom="qnjkswqvuonuporj";
private static String emailTo;
private static String Subject;
private static String content;
private String emailTo;
private String subject;
private String content;
private Properties mProperties;
private Session mSession;
private MimeMessage mCorreo;
public EnviarCorreo(){
public EnviarCorreo(String emailTo, String Subject, String content) {
this.emailTo = emailTo;
this.subject = Subject;
this.content = content;
mProperties = new Properties();
}
private void createEmail(){
public void createEmail() throws MessagingException{
// Simple mail transfer protocol
mProperties.put("mail.smtp.host", "smtp.gmail.com");
mProperties.put("mail.smtp.ssl.trust", "smtp.gmail.com");
mProperties.setProperty("mail.smtp.starttls.enable", "true");
mProperties.setProperty("mail.smtp.port", "587");
mProperties.setProperty("mail.smtp.user",emailFrom);
mProperties.setProperty("mail.smtp.ssl.protocols", "TLSv1.2");
mProperties.setProperty("mail.smtp.auth", "true");
mSession = Session.getDefaultInstance(mProperties);
try {
mCorreo = new MimeMessage(mSession);
mCorreo.setFrom(new InternetAddress(emailFrom));
mCorreo.setRecipient(Message.RecipientType.TO, new InternetAddress(emailTo));
mCorreo.setSubject(subject);
mCorreo.setText(content, "ISO-8859-1", "html");
} catch (AddressException ex) {
System.out.println(ex.toString());
} catch (MessagingException ex) {
System.out.println(ex.toString());
}
}
private void sendEmail(){
public void sendEmail(){
try {
Transport mTransport = mSession.getTransport("smtp");
mTransport.connect(emailFrom, passwordFrom);
mTransport.sendMessage(mCorreo, mCorreo.getRecipients(Message.RecipientType.TO));
mTransport.close();
} catch (NoSuchProviderException ex) {
System.out.println(ex.toString());
} catch (MessagingException ex) {
System.out.println(ex.toString());
}
}
@Override
public void run() {
try {
createEmail();
sendEmail();
} catch (MessagingException ex) {
Logger.getLogger(EnviarCorreo.class.getName()).log(Level.SEVERE, null, ex);
}
}

View File

@ -4,10 +4,15 @@
*/
package Vista;
import Controlador.ControladorCP;
import Modelo.Asiento;
import Modelo.EnviarCorreo;
import Modelo.Tarjeta;
import Modelo.Usuario;
import Modelo.Zona;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.MessagingException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
@ -37,7 +42,10 @@ public class ConfirmacionPago extends javax.swing.JFrame {
this.tarjeta = tarjeta;
this.user = user;
lbCorreo.setText(user.getCorreoelectronico());
ControladorCP controlador = new ControladorCP(this);
btnMenu.addActionListener(controlador);
Thread hilo = new Thread(new EnviarCorreo(user.getCorreoelectronico(), "Compra de Boletos Dran.net", enviarC()));
hilo.run();
}
public void slogan() {
@ -188,4 +196,32 @@ public class ConfirmacionPago extends javax.swing.JFrame {
private javax.swing.JLabel lbCorreo;
private javax.swing.JLabel logo2;
// End of variables declaration//GEN-END:variables
private String enviarC() {
String zo = null;
switch (zona.getId()) {
case 1:
zo = "Zona B";
break;
case 2:
zo = "Zona General";
break;
case 3:
zo = "Zona VIP";
break;
case 4:
zo = "Zona C";
break;
default:
}
String contenido = "<h1>Hola "+user.getNombre()+" </h1>\n" +
"<div>\n" +
" Gracias por comprar tus boletos en Dran.net!!\n" +
" Compraste en la Zona: " + zo+ "\n" +
" precio: "+zona.getPrecio()+" \n" +
" asiento: "+ asiento.getNombre()+ " \n" +
"</div>\n" +
"<h3>Favor de no responder a este Correo</h3>";
return contenido;
}
}

View File

@ -43,6 +43,8 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
@ -67,7 +69,14 @@
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="30" max="32767" attributes="0"/>
<EmptySpace min="0" pref="24" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="lbMontoR" min="-2" pref="295" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -84,18 +93,13 @@
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace pref="45" max="32767" attributes="0"/>
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="22" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel13" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="lbMontoR" pref="23" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -385,6 +389,8 @@
<Property name="text" type="java.lang.String" value=" cada una con sus propios asientos y precios."/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lbMontoR">
</Component>
</SubComponents>
</Container>
</SubComponents>

View File

@ -9,6 +9,7 @@ import Modelo.Usuario;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
@ -37,6 +38,7 @@ public class SalaPrincipal extends javax.swing.JFrame {
panelGeneral.addMouseListener(controlador);
panelVip.addMouseListener(controlador);
btnCerrar.addMouseListener(controlador);
controlador.validarUsuario();
}
public void setBtnCerrar(JButton btnCerrar) {
@ -70,6 +72,10 @@ public class SalaPrincipal extends javax.swing.JFrame {
this.user = user;
}
public JLabel getLbMontoR() {
return lbMontoR;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
@ -97,6 +103,7 @@ public class SalaPrincipal extends javax.swing.JFrame {
jLabel11 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
lbMontoR = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
@ -274,6 +281,8 @@ public class SalaPrincipal extends javax.swing.JFrame {
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
@ -292,7 +301,11 @@ public class SalaPrincipal extends javax.swing.JFrame {
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(236, 236, 236)
.addComponent(jLabel2)))
.addContainerGap(30, Short.MAX_VALUE))
.addGap(0, 24, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(lbMontoR, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -307,15 +320,13 @@ public class SalaPrincipal extends javax.swing.JFrame {
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel4)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(22, 22, 22))
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel13)
.addGap(0, 0, Short.MAX_VALUE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbMontoR, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
@ -351,9 +362,11 @@ public class SalaPrincipal extends javax.swing.JFrame {
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel4;
private javax.swing.JLabel lbMontoR;
private javax.swing.JPanel panelB;
private javax.swing.JPanel panelC;
private javax.swing.JPanel panelGeneral;
private javax.swing.JPanel panelVip;
// End of variables declaration//GEN-END:variables
}

View File

@ -69,7 +69,7 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace pref="24" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -134,6 +134,14 @@
<EmptySpace min="-2" pref="30" max="-2" attributes="0"/>
</Group>
<Component id="jPanel3" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="lbPrecio" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtPrecio" min="-2" pref="78" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCambiarP" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -142,7 +150,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel3" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" alignment="0" groupAlignment="3" attributes="0">
@ -175,7 +183,13 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="35" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtPrecio" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lbPrecio" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnCambiarP" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</Group>
@ -322,6 +336,18 @@
<Property name="text" type="java.lang.String" value="Comprar"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnCambiarP">
<Properties>
<Property name="text" type="java.lang.String" value="Cambiar Precio"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtPrecio">
</Component>
<Component class="javax.swing.JLabel" name="lbPrecio">
<Properties>
<Property name="text" type="java.lang.String" value="$"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>

View File

@ -85,6 +85,26 @@ public class seleccionarBoleto extends javax.swing.JFrame {
return labelZona;
}
public JButton getBtnCambiarP() {
return btnCambiarP;
}
public JLabel getLbPrecio() {
return lbPrecio;
}
public JTextField getTxtPrecio() {
return txtPrecio;
}
public void setLbPrecio(JLabel lbPrecio) {
this.lbPrecio = lbPrecio;
}
public void setTxtPrecio(JTextField txtPrecio) {
this.txtPrecio = txtPrecio;
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@ -109,6 +129,9 @@ public class seleccionarBoleto extends javax.swing.JFrame {
logoimagen = new javax.swing.JLabel();
BtnRegreso = new javax.swing.JButton();
btnSeleccionarAsiento = new javax.swing.JButton();
btnCambiarP = new javax.swing.JButton();
txtPrecio = new javax.swing.JTextField();
lbPrecio = new javax.swing.JLabel();
logo1.setBackground(new java.awt.Color(0, 0, 204));
logo1.setFont(new java.awt.Font("Sitka Text", 1, 18)); // NOI18N
@ -193,6 +216,10 @@ public class seleccionarBoleto extends javax.swing.JFrame {
btnSeleccionarAsiento.setForeground(new java.awt.Color(255, 255, 255));
btnSeleccionarAsiento.setText("Comprar");
btnCambiarP.setText("Cambiar Precio");
lbPrecio.setText("$");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
@ -234,6 +261,13 @@ public class seleccionarBoleto extends javax.swing.JFrame {
.addGap(0, 0, Short.MAX_VALUE)))
.addGap(30, 30, 30))
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(lbPrecio)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCambiarP)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -268,7 +302,12 @@ public class seleccionarBoleto extends javax.swing.JFrame {
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35))))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbPrecio)
.addComponent(btnCambiarP))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
@ -285,7 +324,7 @@ public class seleccionarBoleto extends javax.swing.JFrame {
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(24, Short.MAX_VALUE))
);
pack();
@ -294,6 +333,7 @@ public class seleccionarBoleto extends javax.swing.JFrame {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton BtnRegreso;
private javax.swing.JButton btnCambiarP;
private javax.swing.JButton btnSeleccionarAsiento;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel11;
@ -309,9 +349,11 @@ public class seleccionarBoleto extends javax.swing.JFrame {
private javax.swing.JLabel labelNumeroAsiento;
private javax.swing.JLabel labelOcupado;
private javax.swing.JLabel labelZona;
private javax.swing.JLabel lbPrecio;
private javax.swing.JLabel logo1;
private javax.swing.JLabel logo2;
private javax.swing.JLabel logoimagen;
private javax.swing.JTextField txtPrecio;
// End of variables declaration//GEN-END:variables
}