generated from javiertuya/samples-test-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from uo287568/HU08-DescargaDeEnvios
HU de descarga de envíos realizada
- Loading branch information
Showing
5 changed files
with
268 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package giis.demo.tkrun; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import javax.swing.JOptionPane; | ||
|
||
import giis.demo.util.SwingUtil; | ||
|
||
public class DescargaController { | ||
private DescargaModel model; | ||
private DescargaView view; | ||
|
||
public DescargaController(DescargaModel descargaModel, DescargaView descargaView) { | ||
this.model = descargaModel; | ||
this.view = descargaView; | ||
//no hay inicializacion especifica del modelo, solo de la vista | ||
this.initView(); | ||
} | ||
|
||
public void initController() { | ||
view.getBtCancelar().addActionListener(e -> SwingUtil.exceptionWrapper(() -> salir())); | ||
view.getBtRegistrar().addActionListener(e -> realizarDescarga()); | ||
} | ||
|
||
private void realizarDescarga() { | ||
if (comprobarCampos()) { | ||
int id = Integer.parseInt(view.getTfID().getText()); | ||
int nref = Integer.parseInt(view.getTfNRef().getText()); | ||
if (comprobarEnvio(id, nref)) { | ||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
LocalDateTime now = LocalDateTime.now(); | ||
String fechaHoraActual = dtf.format(now); | ||
model.registrarDescarga(id, nref, "Descarga", view.getTfUbicacion().getText(), fechaHoraActual); | ||
JOptionPane.showMessageDialog(null, "REGISTRO DE DESCARGA REALIZADO CORRECTAMENTE"); | ||
view.reset(); | ||
} | ||
} | ||
} | ||
|
||
private boolean comprobarEnvio(int id, int nref) { | ||
PedidosTransportistaDisplayDTO envio = model.getEnvio(id, nref); | ||
if (envio==null) { | ||
JOptionPane.showMessageDialog(null, "No existe un pedido con el número: " + nref + "\nasignado al repartidor con ID: " + id); | ||
return false; | ||
} else { | ||
MovimientosDisplayDTO movimiento = model.getLastMov(id, nref); | ||
if (movimiento != null) { | ||
if (movimiento.getMovimiento().equals("Descarga")) { | ||
JOptionPane.showMessageDialog(null, "No puede haber un movimiento de descarga seguido de otro de descarga. \nEl último movimiento debe ser de carga"); | ||
return false; | ||
} else if (movimiento.getUbicacion().equals(view.getTfUbicacion().getText())) { | ||
JOptionPane.showMessageDialog(null, "La ubicación de la descarga coincide con la de la última carga"); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
private boolean comprobarCampos() { | ||
try { | ||
if(view.getTfID().getText().isBlank() || view.getTfNRef().getText().isBlank() || view.getTfUbicacion().getText().isBlank()) { | ||
JOptionPane.showMessageDialog(null, "Rellena todos los campos"); | ||
return false; | ||
} else if(Integer.parseInt(view.getTfID().getText()) <= 0 || Integer.parseInt(view.getTfNRef().getText()) <= 0) { | ||
JOptionPane.showMessageDialog(null, "Formato de ID o Número de referencia inválido"); | ||
return false; | ||
} else return true; | ||
} catch (NumberFormatException e) { | ||
JOptionPane.showMessageDialog(null, "Formato de ID o Número de referencia inválido"); | ||
return false; | ||
} | ||
} | ||
|
||
private void salir() { | ||
int eleccion=JOptionPane.showConfirmDialog(null, "¿Está segur@ de cancelar la descarga del envío?"); | ||
if(eleccion==JOptionPane.YES_OPTION) | ||
view.reset(); | ||
} | ||
|
||
public void initView() { | ||
view.getFrame().setVisible(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package giis.demo.tkrun; | ||
|
||
import java.util.List; | ||
|
||
import giis.demo.util.Database; | ||
/** | ||
* Acceso a los datos de carreras e inscripciones, | ||
* utilizado como modelo para el ejemplo de swing y para las pruebas unitarias y de interfaz de usuario. | ||
* | ||
* <br/>En los metodos de este ejemplo toda la logica de negocio se realiza mediante una unica query sql por lo que siempre | ||
* se utilizan los metodos de utilidad en la clase Database que usan apache commons-dbutils y controlan la conexion. | ||
* En caso de que en un mismo metodo se realicen diferentes queries se deberia controlar la conexion desde esta clase | ||
* (ver como ejemplo la implementacion en Database). | ||
* | ||
* <br/>Si utilizase algún otro framework para manejar la persistencia, la funcionalidad proporcionada por esta clase sería la asignada | ||
* a los Servicios, Repositorios y DAOs. | ||
*/ | ||
public class DescargaModel { | ||
|
||
private Database db=new Database(); | ||
|
||
public PedidosTransportistaDisplayDTO getEnvio(int id, int nref) { | ||
String sql = "select * from pedidosTransportista where id=? and nref=?"; | ||
List<PedidosTransportistaDisplayDTO> envios = db.executeQueryPojo(PedidosTransportistaDisplayDTO.class, sql, id, nref); | ||
if(envios.isEmpty()) { | ||
return null; | ||
} | ||
return envios.get(0); | ||
} | ||
|
||
public MovimientosDisplayDTO getLastMov(int id, int nref) { | ||
String sql = "select * from movimientos where id=? and nref=? order by fechamov desc"; | ||
List<MovimientosDisplayDTO> movimientos = db.executeQueryPojo(MovimientosDisplayDTO.class, sql, id, nref); | ||
if(movimientos.isEmpty()) { | ||
return null; | ||
} | ||
return movimientos.get(0); | ||
} | ||
|
||
public void registrarDescarga(int id, int nref, String mov, String ubi, String fechaHoraActual) { | ||
String sql="insert into movimientos (id,nref,movimiento,ubicacion,fechaMov) values (?,?,?,?,?)"; | ||
db.executeUpdate(sql,id,nref,mov,ubi,fechaHoraActual); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package giis.demo.tkrun; | ||
|
||
import javax.swing.JFrame; | ||
import net.miginfocom.swing.MigLayout; | ||
import javax.swing.JLabel; | ||
import javax.swing.JTextField; | ||
import javax.swing.JButton; | ||
|
||
import javax.swing.JPanel; | ||
import java.awt.Font; | ||
import java.awt.FlowLayout; | ||
import java.awt.Color; | ||
|
||
public class DescargaView { | ||
|
||
private JFrame frmDescargaEnvios; | ||
private JLabel lbTítulo; | ||
private JButton btnCancelar; | ||
private JButton btRegistro; | ||
private JLabel lbID; | ||
private JTextField tfID; | ||
private JLabel lbNRef; | ||
private JTextField tfNRef; | ||
private JLabel lbUbicacion; | ||
private JTextField tfUbicacion; | ||
private JLabel lbFecha; | ||
|
||
/** | ||
* Create the application. | ||
*/ | ||
public DescargaView() { | ||
initialize(); | ||
} | ||
|
||
/** | ||
* Initialize the contents of the frame. | ||
*/ | ||
private void initialize() { | ||
frmDescargaEnvios = new JFrame(); | ||
frmDescargaEnvios.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 13)); | ||
frmDescargaEnvios.setTitle("DescargaEnvíos"); | ||
frmDescargaEnvios.setName("DescargaEnvíos"); | ||
frmDescargaEnvios.setBounds(0, 0, 374, 231); | ||
frmDescargaEnvios.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | ||
frmDescargaEnvios.getContentPane().setLayout(new MigLayout("", "[grow]", "[][10.00][][][][][16.00][]")); | ||
|
||
lbTítulo = new JLabel("Registro de descarga de envíos:"); | ||
lbTítulo.setFont(new Font("Tahoma", Font.BOLD, 15)); | ||
frmDescargaEnvios.getContentPane().add(lbTítulo, "cell 0 0"); | ||
|
||
lbID = new JLabel("ID del transportista: "); | ||
lbID.setFont(new Font("Tahoma", Font.PLAIN, 13)); | ||
frmDescargaEnvios.getContentPane().add(lbID, "flowx,cell 0 2"); | ||
|
||
lbNRef = new JLabel("Número de referencia del envío: "); | ||
lbNRef.setFont(new Font("Tahoma", Font.PLAIN, 13)); | ||
frmDescargaEnvios.getContentPane().add(lbNRef, "flowx,cell 0 3"); | ||
|
||
lbUbicacion = new JLabel("Ubicación de la descarga:"); | ||
lbUbicacion.setFont(new Font("Tahoma", Font.PLAIN, 13)); | ||
frmDescargaEnvios.getContentPane().add(lbUbicacion, "flowx,cell 0 4"); | ||
|
||
lbFecha = new JLabel("Se registrará la fecha y hora de la descarga (hora actual)"); | ||
lbFecha.setFont(new Font("Tahoma", Font.PLAIN, 13)); | ||
frmDescargaEnvios.getContentPane().add(lbFecha, "cell 0 5"); | ||
|
||
tfID = new JTextField(); | ||
frmDescargaEnvios.getContentPane().add(tfID, "cell 0 2"); | ||
tfID.setColumns(10); | ||
|
||
tfNRef = new JTextField(); | ||
frmDescargaEnvios.getContentPane().add(tfNRef, "cell 0 3"); | ||
tfNRef.setColumns(10); | ||
|
||
tfUbicacion = new JTextField(); | ||
frmDescargaEnvios.getContentPane().add(tfUbicacion, "cell 0 4"); | ||
tfUbicacion.setColumns(10); | ||
|
||
JPanel pnBotones = new JPanel(); | ||
FlowLayout fl_pnBotones = (FlowLayout) pnBotones.getLayout(); | ||
fl_pnBotones.setAlignment(FlowLayout.RIGHT); | ||
frmDescargaEnvios.getContentPane().add(pnBotones, "cell 0 7,grow"); | ||
|
||
btnCancelar = new JButton("Cancelar"); | ||
btnCancelar.setForeground(Color.WHITE); | ||
btnCancelar.setBackground(Color.RED); | ||
btnCancelar.setFont(new Font("Tahoma", Font.BOLD, 12)); | ||
pnBotones.add(btnCancelar); | ||
|
||
btRegistro = new JButton("Registrar descarga"); | ||
btRegistro.setBackground(Color.GREEN); | ||
btRegistro.setFont(new Font("Tahoma", Font.BOLD, 12)); | ||
pnBotones.add(btRegistro); | ||
} | ||
|
||
public void reset() { | ||
this.tfID.setText(""); | ||
this.tfNRef.setText(""); | ||
this.tfUbicacion.setText(""); | ||
this.getFrame().setVisible(false); | ||
} | ||
|
||
//Getters y Setters anyadidos para acceso desde el controlador (repersentacion compacta) | ||
public JFrame getFrame() { return this.frmDescargaEnvios; } | ||
public JButton getBtCancelar() { return this.btnCancelar; } | ||
public JButton getBtRegistrar() { return this.btRegistro; } | ||
public JTextField getTfID() { return tfID; } | ||
public JTextField getTfNRef() { return tfNRef; } | ||
public JTextField getTfUbicacion() { return tfUbicacion; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters