refactoring-dipasquale-code #4

Merged
f.disciascio merged 1 commits from refactoring-dipasquale-code into dev 2025-05-21 09:52:00 +00:00
2 changed files with 637 additions and 578 deletions

View File

@ -184,7 +184,7 @@
<EmptySpace min="-2" pref="48" max="-2" attributes="0"/> <EmptySpace min="-2" pref="48" max="-2" attributes="0"/>
<Component id="jBtnReadCard" min="-2" pref="154" max="-2" attributes="0"/> <Component id="jBtnReadCard" min="-2" pref="154" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/> <EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jcmbSC" min="-2" pref="32" max="-2" attributes="0"/> <Component id="jcmbSmartCard" min="-2" pref="32" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
@ -195,7 +195,7 @@
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0"> <Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jcmbSC" min="-2" pref="3" max="-2" attributes="0"/> <Component id="jcmbSmartCard" min="-2" pref="3" max="-2" attributes="0"/>
<Component id="jBtnReadCard" pref="0" max="32767" attributes="0"/> <Component id="jBtnReadCard" pref="0" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
@ -299,7 +299,7 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jBtnReadCardActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jBtnReadCardActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JComboBox" name="jcmbSC"> <Component class="javax.swing.JComboBox" name="jcmbSmartCard">
<Properties> <Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4"> <StringArray count="4">

View File

@ -44,13 +44,13 @@ import javax.xml.parsers.DocumentBuilderFactory;
import jssc.SerialPort; import jssc.SerialPort;
import jssc.SerialPortException; import jssc.SerialPortException;
import org.apache.log4j.LogManager; import org.apache.log4j.LogManager;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import puntocassa.utils.Utils; import puntocassa.utils.Utils;
//****************************************************************************** //******************************************************************************
// * // *
// * @author Master // * @author Master
@ -146,7 +146,6 @@ public class PuntoCassa extends JFrame implements ActionListener {
private int deltaWidth = 14; private int deltaWidth = 14;
private int deltaHeight = 7; private int deltaHeight = 7;
// ========================================================================== // ==========================================================================
// *** Constructor della classe PuntoCassa // *** Constructor della classe PuntoCassa
// ========================================================================== // ==========================================================================
@ -161,6 +160,7 @@ public class PuntoCassa extends JFrame implements ActionListener {
// *** Legge la configurazione dal file XML // *** Legge la configurazione dal file XML
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
try { try {
MyApplication myApp = new MyApplication();
DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentFactory.newDocumentBuilder(); DocumentBuilder builder = documentFactory.newDocumentBuilder();
String startDir = System.getProperty("user.dir"); String startDir = System.getProperty("user.dir");
@ -172,71 +172,17 @@ public class PuntoCassa extends JFrame implements ActionListener {
ImageIcon icon = new ImageIcon(startDir + "/risorse/logo.png"); ImageIcon icon = new ImageIcon(startDir + "/risorse/logo.png");
this.setIconImage(icon.getImage()); this.setIconImage(icon.getImage());
} }
// --------------------------------------------------------------------
// ** Accesso al database
// --------------------------------------------------------------------
NodeList database = document.getElementsByTagName("database");
for (int i = 0; i < database.getLength(); i++) {
Node nodo = database.item(i);
if (nodo.getNodeType() == Node.ELEMENT_NODE) { leggiNodoDatabase(document);
Element db = (Element) nodo;
String attivo = db.getElementsByTagName("attivo").item(0).getFirstChild().getNodeValue();
String tipo = db.getElementsByTagName("tipo").item(0).getFirstChild().getNodeValue();
String driver = db.getElementsByTagName("driver").item(0).getFirstChild().getNodeValue();
String server = db.getElementsByTagName("server").item(0).getFirstChild().getNodeValue();
String porta = db.getElementsByTagName("porta").item(0).getFirstChild().getNodeValue();
String istanza = db.getElementsByTagName("istanza").item(0).getFirstChild().getNodeValue();
String username = db.getElementsByTagName("username").item(0).getFirstChild().getNodeValue();
String password = db.getElementsByTagName("password").item(0).getFirstChild().getNodeValue();
if (attivo.equals("SI")) { NodeList paths = leggiNodoPath(document, startDir);
//Encoding en = new Encoding();
dbUsername = username;
dbPassword = Encoding.decodeString(password);
dbTipo = tipo;
dbDriver = driver;
if (tipo.equals("MySQL")) {
dbStringa = "jdbc:mysql://" + server + ":" + porta + "/" + istanza;
} else if (tipo.equals("Oracle")) {
dbStringa = "jdbc:oracle:thin:@" + server + ":" + porta + ":" + istanza;
}
}
}
}
// --------------------------------------------------------------------
// ** Path
// --------------------------------------------------------------------
NodeList paths = document.getElementsByTagName("path");
for (int i = 0; i < paths.getLength(); i++) {
Node path = paths.item(i);
if (path.getNodeType() == Node.ELEMENT_NODE) {
Element p = (Element) path;
imgPath = p.getElementsByTagName("img_path").item(0).getFirstChild().getNodeValue();
if (imgPath.equalsIgnoreCase("..\\risorse\\")) {
imgPath = startDir + "/risorse/";
}
}
}
// --------------------------------------------------------------------
// ** Etichette
// --------------------------------------------------------------------
NodeList etichette = document.getElementsByTagName("etichette");
//String titolo = "";
MyApplication myApp = new MyApplication();
for (int i = 0; i < paths.getLength(); i++) {
Node etichetta = etichette.item(i);
if (etichetta.getNodeType() == Node.ELEMENT_NODE) {
Element p = (Element) etichetta;
String titolo = p.getElementsByTagName("titolo").item(0).getFirstChild().getNodeValue();
//idPuntoCassa = Long.valueOf(myApp.mySelect(this, "SELECT valore FROM parametri WHERE chiave = 'IdPuntoCassa'", "valore"));
idPuntoCassa = Long.valueOf(Utils.mySelect("SELECT valore FROM parametri WHERE chiave = 'IdPuntoCassa'", idPuntoCassa = Long.valueOf(Utils.mySelect("SELECT valore FROM parametri WHERE chiave = 'IdPuntoCassa'",
"valore", "valore",
this)); this));
//String credito = myApp.mySelect(this, "SELECT valore FROM parametri WHERE chiave = 'FlagIgnoraSaldoStop'", "valore"); leggiNodoEtichette(document, paths, idPuntoCassa);
String credito = Utils.mySelect("SELECT valore FROM parametri WHERE chiave = 'FlagIgnoraSaldoStop'", String credito = Utils.mySelect("SELECT valore FROM parametri WHERE chiave = 'FlagIgnoraSaldoStop'",
"valore", "valore",
this); this);
@ -244,10 +190,7 @@ public class PuntoCassa extends JFrame implements ActionListener {
consentiCredito = true; consentiCredito = true;
} }
titolo = titolo + " " + idPuntoCassa;
this.setTitle(titolo);
//Aggiornamento 14-01-2019 //Aggiornamento 14-01-2019
//String stringDatiPagamento = myApp.mySelect(this, "select tp.id || '|' || tp.nome || '|' || pd.flag_bonus || '|' || "
String stringDatiPagamento = Utils.mySelect("select tp.id || '|' || tp.nome || '|' || pd.flag_bonus || '|' || " String stringDatiPagamento = Utils.mySelect("select tp.id || '|' || tp.nome || '|' || pd.flag_bonus || '|' || "
+ "pd.flag_extra as valore from punti_cassa pc " + "pd.flag_extra as valore from punti_cassa pc "
+ "inner join punti_distribuzione pd on pc.id_punto_distribuzione = pd.id " + "inner join punti_distribuzione pd on pc.id_punto_distribuzione = pd.id "
@ -269,69 +212,26 @@ public class PuntoCassa extends JFrame implements ActionListener {
} }
pulsantiModoPagamento(); pulsantiModoPagamento();
} }
}
}
// -------------------------------------------------------------------- leggiNodoDisplay(document, myApp);
// ** display
// --------------------------------------------------------------------
NodeList disp = document.getElementsByTagName("display");
for (int i = 0; i < disp.getLength(); i++) {
Node display = disp.item(i);
if (display.getNodeType() == Node.ELEMENT_NODE) {
Element p = (Element) display;
displayWidth = Integer.parseInt(p.getElementsByTagName("larghezza").item(0).getFirstChild().getNodeValue());
displayHeight = Integer.parseInt(p.getElementsByTagName("altezza").item(0).getFirstChild().getNodeValue());
altezzaBarraApplicazioni = Integer.parseInt(p.getElementsByTagName("altBarraApplicazioni").item(0).getFirstChild().getNodeValue());
hFont = Integer.parseInt(p.getElementsByTagName("fontSize").item(0).getFirstChild().getNodeValue());
altControlli = Integer.parseInt(p.getElementsByTagName("altezzaControlli").item(0).getFirstChild().getNodeValue());
largControlli = Integer.parseInt(p.getElementsByTagName("larghezzaControlli").item(0).getFirstChild().getNodeValue());
String tastiera = p.getElementsByTagName("TastieraVideo").item(0).getFirstChild().getNodeValue();
myApp.tastieraVideo = !tastiera.equals("NO");
}
}
//adatto panel login //adatto panel login
Font f = new Font("Tahoma", 0, hFont);
UIManager.put("OptionPane.messageFont",
new FontUIResource(new Font("Tahoma", Font.BOLD, hFont))
);
UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("Tahoma", Font.BOLD, 25)));
btnLogin.setFont(f);
pnlLogin.setSize(calcolaLarghezzaAltezza(pnlLogin.getWidth(), largControlli), calcolaLarghezzaAltezza(pnlLogin.getHeight(), altControlli)); pnlLogin.setSize(calcolaLarghezzaAltezza(pnlLogin.getWidth(), largControlli), calcolaLarghezzaAltezza(pnlLogin.getHeight(), altControlli));
lblPassword.setFont(f);
lblUsername.setFont(f);
txtUsername.setFont(f);
txtPassword.setFont(f);
jTxtTessera.setFont(f);
jChLogin.setFont(f);
jBtnReadCard.setVisible(false); jBtnReadCard.setVisible(false);
Font newFontBtnAnnulla = new Font(jbtnAnnulla.getFont().getName(), jbtnAnnulla.getFont().getStyle(), hFont); settingFontsInterfaccia();
jbtnAnnulla.setFont(newFontBtnAnnulla);
Font newFontBtnDuplica = new Font(jbtnDuplica.getFont().getName(), jbtnDuplica.getFont().getStyle(), hFont);
jbtnDuplica.setFont(newFontBtnDuplica);
Font newFontBtnElimina = new Font(jbtnElimina.getFont().getName(), jbtnElimina.getFont().getStyle(), hFont);
jbtnElimina.setFont(newFontBtnElimina);
Font newFontBtnChiudi = new Font(jbtnChiudi.getFont().getName(), jbtnChiudi.getFont().getStyle(), hFont);
jbtnChiudi.setFont(newFontBtnChiudi);
Font newFontTxtTotaleCassa = new Font(txtTotaleCassa.getFont().getName(), txtTotaleCassa.getFont().getStyle(), (hFont + (hFont / 10 * 3)));
txtTotaleCassa.setFont(newFontTxtTotaleCassa);
Font newFontTxtTotalePunti = new Font(txtTotalePunti.getFont().getName(), txtTotalePunti.getFont().getStyle(), (hFont + (hFont / 10 * 3)));
txtTotalePunti.setFont(newFontTxtTotalePunti);
// --------------------------------------------------------------------
// ** ID_PUNTO_CASSA
// --------------------------------------------------------------------
jcmbSC.setVisible(false);
String VMD = document.getElementsByTagName("Visualizza_Messaggi_Display").item(0).getFirstChild().getNodeValue();
visualizzaMessaggiDisplay = VMD.equalsIgnoreCase("SI"); jcmbSmartCard.setVisible(false);
visualizzaMessaggiDisplay = document.getElementsByTagName("Visualizza_Messaggi_Display").item(0).getFirstChild().getNodeValue()
.equalsIgnoreCase("SI");
//visualizzaMessaggiDisplay = VMD.equalsIgnoreCase("SI");
messageDisplay = document.getElementsByTagName("Messaggio_Display").item(0).getFirstChild().getNodeValue(); messageDisplay = document.getElementsByTagName("Messaggio_Display").item(0).getFirstChild().getNodeValue();
updateReaderCombo(); aggiornaSmartCardReaderCombo(myApp);
//String ultimiMovimenti = myApp.mySelect(this, "SELECT valore FROM parametri WHERE chiave = 'FlagVisualizzaUltimiPassaggi'", "valore");
String ultimiMovimenti = Utils.mySelect("SELECT valore FROM parametri WHERE chiave = 'FlagVisualizzaUltimiPassaggi'", String ultimiMovimenti = Utils.mySelect("SELECT valore FROM parametri WHERE chiave = 'FlagVisualizzaUltimiPassaggi'",
"valore", "valore",
this); this);
@ -392,6 +292,156 @@ public class PuntoCassa extends JFrame implements ActionListener {
} }
/**
* Definizione e settaggio dei fonts sull'interfaccia grafica
*/
private void settingFontsInterfaccia() {
Font f = new Font("Tahoma", 0, hFont);
UIManager.put("OptionPane.messageFont",
new FontUIResource(new Font("Tahoma", Font.BOLD, hFont))
);
UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("Tahoma", Font.BOLD, 25)));
btnLogin.setFont(f);
lblPassword.setFont(f);
lblUsername.setFont(f);
txtUsername.setFont(f);
txtPassword.setFont(f);
jTxtTessera.setFont(f);
jChLogin.setFont(f);
Font newFontBtnAnnulla = new Font(jbtnAnnulla.getFont().getName(), jbtnAnnulla.getFont().getStyle(), hFont);
jbtnAnnulla.setFont(newFontBtnAnnulla);
Font newFontBtnDuplica = new Font(jbtnDuplica.getFont().getName(), jbtnDuplica.getFont().getStyle(), hFont);
jbtnDuplica.setFont(newFontBtnDuplica);
Font newFontBtnElimina = new Font(jbtnElimina.getFont().getName(), jbtnElimina.getFont().getStyle(), hFont);
jbtnElimina.setFont(newFontBtnElimina);
Font newFontBtnChiudi = new Font(jbtnChiudi.getFont().getName(), jbtnChiudi.getFont().getStyle(), hFont);
jbtnChiudi.setFont(newFontBtnChiudi);
Font newFontTxtTotaleCassa = new Font(txtTotaleCassa.getFont().getName(), txtTotaleCassa.getFont().getStyle(), (hFont + (hFont / 10 * 3)));
txtTotaleCassa.setFont(newFontTxtTotaleCassa);
Font newFontTxtTotalePunti = new Font(txtTotalePunti.getFont().getName(), txtTotalePunti.getFont().getStyle(), (hFont + (hFont / 10 * 3)));
txtTotalePunti.setFont(newFontTxtTotalePunti);
}
/**
* Lettura del nodo 'display' del file di configurazione
* @param document
* @param myApp
* @throws NumberFormatException
* @throws DOMException
*/
private void leggiNodoDisplay(Document document, MyApplication myApp) throws NumberFormatException, DOMException {
// --------------------------------------------------------------------
// ** display
// --------------------------------------------------------------------
NodeList disp = document.getElementsByTagName("display");
for (int i = 0; i < disp.getLength(); i++) {
Node display = disp.item(i);
if (display.getNodeType() == Node.ELEMENT_NODE) {
Element p = (Element) display;
displayWidth = Integer.parseInt(p.getElementsByTagName("larghezza").item(0).getFirstChild().getNodeValue());
displayHeight = Integer.parseInt(p.getElementsByTagName("altezza").item(0).getFirstChild().getNodeValue());
altezzaBarraApplicazioni = Integer.parseInt(p.getElementsByTagName("altBarraApplicazioni").item(0).getFirstChild().getNodeValue());
hFont = Integer.parseInt(p.getElementsByTagName("fontSize").item(0).getFirstChild().getNodeValue());
altControlli = Integer.parseInt(p.getElementsByTagName("altezzaControlli").item(0).getFirstChild().getNodeValue());
largControlli = Integer.parseInt(p.getElementsByTagName("larghezzaControlli").item(0).getFirstChild().getNodeValue());
String tastiera = p.getElementsByTagName("TastieraVideo").item(0).getFirstChild().getNodeValue();
myApp.tastieraVideo = !tastiera.equals("NO");
}
}
}
/**
* Lettura del noto 'etichette' del file di configurazione
*
* @param document
* @param paths
* @throws DOMException
* @throws NumberFormatException
*/
private void leggiNodoEtichette(Document document, NodeList paths, Long idPuntoCassa) throws DOMException, NumberFormatException {
NodeList etichette = document.getElementsByTagName("etichette");
for (int i = 0; i < paths.getLength(); i++) {
Node etichetta = etichette.item(i);
if (etichetta.getNodeType() == Node.ELEMENT_NODE) {
Element p = (Element) etichetta;
String titolo = p.getElementsByTagName("titolo").item(0).getFirstChild().getNodeValue();
titolo = titolo + " " + idPuntoCassa;
this.setTitle(titolo);
}
}
}
/**
* Lettura del nodo 'path' del file di configurazione
*
* @param document
* @param startDir
* @return
* @throws DOMException
*/
private NodeList leggiNodoPath(Document document, String startDir) throws DOMException {
NodeList paths = document.getElementsByTagName("path");
for (int i = 0; i < paths.getLength(); i++) {
Node path = paths.item(i);
if (path.getNodeType() == Node.ELEMENT_NODE) {
Element p = (Element) path;
imgPath = p.getElementsByTagName("img_path").item(0).getFirstChild().getNodeValue();
if (imgPath.equalsIgnoreCase("..\\risorse\\")) {
imgPath = startDir + "/risorse/";
}
}
}
return paths;
}
/**
* Lettura del nodo 'database' del file di configurazione
*
* @param document
* @throws DOMException
*/
private void leggiNodoDatabase(Document document) throws DOMException {
NodeList database = document.getElementsByTagName("database");
for (int i = 0; i < database.getLength(); i++) {
Node nodo = database.item(i);
if (nodo.getNodeType() == Node.ELEMENT_NODE) {
Element db = (Element) nodo;
String attivo = db.getElementsByTagName("attivo").item(0).getFirstChild().getNodeValue();
if (attivo.equals("SI")) {
dbTipo = db.getElementsByTagName("tipo").item(0).getFirstChild().getNodeValue();
dbDriver = db.getElementsByTagName("driver").item(0).getFirstChild().getNodeValue();
String server = db.getElementsByTagName("server").item(0).getFirstChild().getNodeValue();
String porta = db.getElementsByTagName("porta").item(0).getFirstChild().getNodeValue();
String istanza = db.getElementsByTagName("istanza").item(0).getFirstChild().getNodeValue();
dbUsername = db.getElementsByTagName("username").item(0).getFirstChild().getNodeValue();
dbPassword = Encoding.decodeString(db.getElementsByTagName("password").item(0).getFirstChild().getNodeValue());
//dbUsername = username;
//dbPassword = Encoding.decodeString(password);
//dbTipo = tipo;
//dbDriver = driver;
switch (dbTipo) {
case "MySQL" ->
dbStringa = "jdbc:mysql://" + server + ":" + porta + "/" + istanza;
case "Oracle" ->
dbStringa = "jdbc:oracle:thin:@" + server + ":" + porta + ":" + istanza;
}
/*if (dbTipo.equals("MySQL")) {
dbStringa = "jdbc:mysql://" + server + ":" + porta + "/" + istanza;
} else if (dbTipo.equals("Oracle")) {
dbStringa = "jdbc:oracle:thin:@" + server + ":" + porta + ":" + istanza;
}*/
}
}
}
}
public KeyEventDispatcher creaKeyEventDispatcher() { public KeyEventDispatcher creaKeyEventDispatcher() {
return new KeyEventDispatcher() { return new KeyEventDispatcher() {
Boolean swip = false; Boolean swip = false;
@ -567,13 +617,13 @@ public class PuntoCassa extends JFrame implements ActionListener {
}; };
} }
/**
* *
/*** * FlagProponiAggiornamentoDB ha 3 possibili valori: AUTO vuol dire che, se
* FlagProponiAggiornamentoDB ha 3 possibili valori: * il db locale è da aggiornare (DB_locale_aggiornato = 0), lo deve fare e
* AUTO vuol dire che, se il db locale è da aggiornare (DB_locale_aggiornato = 0), lo deve fare e basta senza chiedere conferma * basta senza chiedere conferma SI vuol dire che, se il db locale è da
* SI vuol dire che, se il db locale è da aggiornare (DB_locale_aggiornato = 0), lo deve fare chiedendo conferma * aggiornare (DB_locale_aggiornato = 0), lo deve fare chiedendo conferma NO
* NO vuol dire che non lo deve fare nemmeno se è da aggiornare * vuol dire che non lo deve fare nemmeno se è da aggiornare
*/ */
private void verificaAggiornamentoDB() { private void verificaAggiornamentoDB() {
Long dbAggiornato = Utils.mySelectInteger("Select DB_locale_aggiornato as Agg from dual", "Agg", Long dbAggiornato = Utils.mySelectInteger("Select DB_locale_aggiornato as Agg from dual", "Agg",
@ -583,8 +633,7 @@ public class PuntoCassa extends JFrame implements ActionListener {
if (dbAggiornato == 0) { if (dbAggiornato == 0) {
if (flagProponiAggiornamentoDB.equals("SI")) { if (flagProponiAggiornamentoDB.equals("SI")) {
aggiornaDB(true); aggiornaDB(true);
} } else if (flagProponiAggiornamentoDB.equals("AUTO")) {
else if(flagProponiAggiornamentoDB.equals("AUTO")){
aggiornaDB(false); aggiornaDB(false);
} }
} }
@ -645,17 +694,20 @@ public class PuntoCassa extends JFrame implements ActionListener {
} }
} }
private void updateReaderCombo() { /**
* Aggiorna la lista di lettori smartcard disponibili
* @param myApp
*/
private void aggiornaSmartCardReaderCombo(MyApplication myApp) {
try { try {
MyApplication myApp = new MyApplication(); //MyApplication myApp = new MyApplication();
jcmbSC.setModel(new DefaultComboBoxModel(myApp.smartCard.listReaders())); jcmbSmartCard.setModel(new DefaultComboBoxModel(myApp.smartCard.listReaders()));
} catch (Exception ex) { } catch (Exception ex) {
LogManager.getLogger(PuntoCassa.class.getName()).error(ex); LogManager.getLogger(PuntoCassa.class.getName()).error(ex);
} }
} }
private Integer calcolaLarghezzaAltezza(Integer larControllo, Integer percentuale) { private Integer calcolaLarghezzaAltezza(Integer larControllo, Integer percentuale) {
Integer d = percentuale - 100; Integer d = percentuale - 100;
if (d == 0) { if (d == 0) {
@ -687,7 +739,7 @@ public class PuntoCassa extends JFrame implements ActionListener {
jTxtTessera = new javax.swing.JTextField(); jTxtTessera = new javax.swing.JTextField();
btnImpostaCliente = new javax.swing.JButton(); btnImpostaCliente = new javax.swing.JButton();
jBtnReadCard = new javax.swing.JButton(); jBtnReadCard = new javax.swing.JButton();
jcmbSC = new javax.swing.JComboBox(); jcmbSmartCard = new javax.swing.JComboBox();
lblCodice3 = new javax.swing.JLabel(); lblCodice3 = new javax.swing.JLabel();
lblTipoPagamento = new javax.swing.JLabel(); lblTipoPagamento = new javax.swing.JLabel();
lblCodice4 = new javax.swing.JLabel(); lblCodice4 = new javax.swing.JLabel();
@ -833,7 +885,7 @@ public class PuntoCassa extends JFrame implements ActionListener {
} }
}); });
jcmbSC.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jcmbSmartCard.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
lblCodice3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N lblCodice3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
lblCodice3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblCodice3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
@ -889,14 +941,14 @@ public class PuntoCassa extends JFrame implements ActionListener {
.addGap(48, 48, 48) .addGap(48, 48, 48)
.addComponent(jBtnReadCard, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jBtnReadCard, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jcmbSC, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jcmbSmartCard, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap()) .addContainerGap())
); );
subPnlTesseraLayout.setVerticalGroup( subPnlTesseraLayout.setVerticalGroup(
subPnlTesseraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) subPnlTesseraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(subPnlTesseraLayout.createSequentialGroup() .addGroup(subPnlTesseraLayout.createSequentialGroup()
.addGroup(subPnlTesseraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(subPnlTesseraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jcmbSC, javax.swing.GroupLayout.PREFERRED_SIZE, 3, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jcmbSmartCard, javax.swing.GroupLayout.PREFERRED_SIZE, 3, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jBtnReadCard, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) .addComponent(jBtnReadCard, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTxtTessera, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jTxtTessera, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -1755,7 +1807,8 @@ public class PuntoCassa extends JFrame implements ActionListener {
tipo = cmd.substring(0, i); tipo = cmd.substring(0, i);
switch (tipo) { switch (tipo) {
case "CATEGORIA" -> pulsantiCategoria(id, cmd); case "CATEGORIA" ->
pulsantiCategoria(id, cmd);
case "PRODOTTO" -> { case "PRODOTTO" -> {
if (isCassaAperta) { if (isCassaAperta) {
@ -1917,8 +1970,9 @@ public class PuntoCassa extends JFrame implements ActionListener {
} }
/** /**
* funzione che calcola i prezzi dei prodotti e il totale in base alla fascia dello studente * funzione che calcola i prezzi dei prodotti e il totale in base alla
* oppure utilizza la fascia di default * fascia dello studente oppure utilizza la fascia di default
*
* @param model * @param model
*/ */
private void sommaColonne(MyTableModel model) { private void sommaColonne(MyTableModel model) {
@ -2192,11 +2246,11 @@ public class PuntoCassa extends JFrame implements ActionListener {
//JPanel pnl = this.pnlProdotti; //JPanel pnl = this.pnlProdotti;
var listaBottoni = new ArrayList<JToggleButton>(); var listaBottoni = new ArrayList<JToggleButton>();
for (Integer r = 0; r < 6; r++) { for (Integer r = 0; r < 6; r++) {
Color c2 = new Color(255, 153, 255); Color c2 = new Color(255, 153, 255);
switch (r) { switch (r) {
case 0 -> where = " and upper(cat.CODICE)='PRIM' "; case 0 ->
where = " and upper(cat.CODICE)='PRIM' ";
case 1 -> { case 1 -> {
where = " and upper(cat.CODICE)='SECO' "; where = " and upper(cat.CODICE)='SECO' ";
c2 = Color.CYAN; c2 = Color.CYAN;
@ -2646,12 +2700,12 @@ public class PuntoCassa extends JFrame implements ActionListener {
lblInfo.setText("Passaggi: Tot. [" + prog + "], giorno [" + progGG + "], turno [" + progTurno + "]"); lblInfo.setText("Passaggi: Tot. [" + prog + "], giorno [" + progGG + "], turno [" + progTurno + "]");
DecimalFormat df2 = new DecimalFormat("#,###,###,##0.00"); DecimalFormat df2 = new DecimalFormat("#,###,###,##0.00");
lblInfo2.setText("Incassi [" + nomeTurno + "]: Tot. [" + lblInfo2.setText("Incassi [" + nomeTurno + "]: Tot. ["
df2.format(progressivoScalare + progressivoContanti + progressivoTicket + progressivoDifferito) + "] SC [" + + df2.format(progressivoScalare + progressivoContanti + progressivoTicket + progressivoDifferito) + "] SC ["
df2.format(progressivoScalare) + "], CO [" + + df2.format(progressivoScalare) + "], CO ["
df2.format(progressivoContanti) + "], TI [" + + df2.format(progressivoContanti) + "], TI ["
df2.format(progressivoTicket) + "], DI [" + + df2.format(progressivoTicket) + "], DI ["
df2.format(progressivoDifferito) + "]"); + df2.format(progressivoDifferito) + "]");
} }
public void addRemoveKeyDispatcher(Boolean aggiungi) { public void addRemoveKeyDispatcher(Boolean aggiungi) {
@ -3207,7 +3261,6 @@ public class PuntoCassa extends JFrame implements ActionListener {
//pwd = new String(); //pwd = new String();
//sql = new String(); //sql = new String();
// ======================================================================= // =======================================================================
// *** Verifica la correttezza delle credenziali inserite - Account // *** Verifica la correttezza delle credenziali inserite - Account
// ======================================================================= // =======================================================================
@ -3468,12 +3521,10 @@ public class PuntoCassa extends JFrame implements ActionListener {
return testo; return testo;
} }
/*** /**
* Metodo che gestisce la pressione dei bottoni relativi alle modalita di pagamento * *
* 0 -> a scalare * Metodo che gestisce la pressione dei bottoni relativi alle modalita di
* 1 -> contanti * pagamento 0 -> a scalare 1 -> contanti 2 -> ticket 3 -> differito
* 2 -> ticket
* 3 -> differito
*/ */
private void pulsantiModoPagamento() { private void pulsantiModoPagamento() {
switch (Integer.parseInt(idModoPagamento.toString())) { switch (Integer.parseInt(idModoPagamento.toString())) {
@ -3683,11 +3734,11 @@ public class PuntoCassa extends JFrame implements ActionListener {
Utils.myInsert("Insert into Acquisti " Utils.myInsert("Insert into Acquisti "
+ "(id,id_Tessera,id_Prodotto,id_Punto_Cassa,Data,Importo,Punti,Num_Progressivo,id_Tipo_Pagamento," + "(id,id_Tessera,id_Prodotto,id_Punto_Cassa,Data,Importo,Punti,Num_Progressivo,id_Tipo_Pagamento,"
+ "id_Turno,flag_gratuita,flag_bonus,flag_asporto,flag_passaggio_tessera)" + "id_Turno,flag_gratuita,flag_bonus,flag_asporto,flag_passaggio_tessera)"
+ "values(-1," + tessera + "," + model2.getValueAt(i, 2) + "," + idPuntoCassa + "," + + "values(-1," + tessera + "," + model2.getValueAt(i, 2) + "," + idPuntoCassa + ","
//formattaDataOra(adesso) + "," + model2.getValueAt(i, 1) + ",0," + progressivo + "," + + //formattaDataOra(adesso) + "," + model2.getValueAt(i, 1) + ",0," + progressivo + "," +
formatLocalDateTime(adesso) + "," + model2.getValueAt(i, 1) + ",0," + progressivo + "," + formatLocalDateTime(adesso) + "," + model2.getValueAt(i, 1) + ",0," + progressivo + ","
idModoPagamento + "," + idTurno + "," + flagGratuita + "," + flagBonus + "," + + idModoPagamento + "," + idTurno + "," + flagGratuita + "," + flagBonus + ","
flagAsporto + "," + flagPassaggioTessera + ")", + flagAsporto + "," + flagPassaggioTessera + ")",
this); this);
aggiornaProgressivoPagamentiTurno(Double.valueOf(model2.getValueAt(i, 1).toString())); aggiornaProgressivoPagamentiTurno(Double.valueOf(model2.getValueAt(i, 1).toString()));
model2.deleteRow(i); model2.deleteRow(i);
@ -3964,7 +4015,6 @@ public class PuntoCassa extends JFrame implements ActionListener {
//lblFascia.setText(""); //lblFascia.setText("");
//if (isCassaAperta == false) { //if (isCassaAperta == false) {
turnoAttuale(); turnoAttuale();
if ((idTurnoAttuale - idTurno) != 0) { if ((idTurnoAttuale - idTurno) != 0) {
@ -3999,7 +4049,6 @@ public class PuntoCassa extends JFrame implements ActionListener {
idProfiloTariffario = idProfiloTariffarioDefault;//0L idProfiloTariffario = idProfiloTariffarioDefault;//0L
//setModoPagamento(modoPagamentoDefault); //setModoPagamento(modoPagamentoDefault);
this.caricaPannello(); this.caricaPannello();
//abilitaPulsanti(pnlCategorie, true, true); //abilitaPulsanti(pnlCategorie, true, true);
jbtnChiudi.setEnabled(false); jbtnChiudi.setEnabled(false);
@ -4049,13 +4098,15 @@ public class PuntoCassa extends JFrame implements ActionListener {
logTessera(); logTessera();
try { try {
if (!controlloAbilitazioneTessera(numeroTessera)) if (!controlloAbilitazioneTessera(numeroTessera)) {
return; return;
}
String controlloPassaggi = "Select controlla_passaggi('" + numeroTessera + "'," + idPuntoCassa + ") as T from dual"; String controlloPassaggi = "Select controlla_passaggi('" + numeroTessera + "'," + idPuntoCassa + ") as T from dual";
Long abilitatoPassaggi = Utils.mySelectInteger(controlloPassaggi, "T", this); Long abilitatoPassaggi = Utils.mySelectInteger(controlloPassaggi, "T", this);
if (!controlloPassaggi(abilitatoPassaggi, numeroTessera)) if (!controlloPassaggi(abilitatoPassaggi, numeroTessera)) {
return; return;
}
//aggiungo un giorno altrimenti in caso di scadenza nello stesso giorno //aggiungo un giorno altrimenti in caso di scadenza nello stesso giorno
//considera le ore //considera le ore
@ -4132,7 +4183,6 @@ public class PuntoCassa extends JFrame implements ActionListener {
lblTipoPagamento.setText(tipo); lblTipoPagamento.setText(tipo);
} }
//28-09-2016 quando c'è una sola categoria faccio click //28-09-2016 quando c'è una sola categoria faccio click
if (numeroCategorie == 1) { if (numeroCategorie == 1) {
Component[] components = pnlCategorie.getComponents(); Component[] components = pnlCategorie.getComponents();
@ -4469,13 +4519,6 @@ public class PuntoCassa extends JFrame implements ActionListener {
} }
public void getImage(String idProdotto) { public void getImage(String idProdotto) {
String fullName = null; String fullName = null;
InputStream gifData = null; InputStream gifData = null;
@ -4545,7 +4588,6 @@ public class PuntoCassa extends JFrame implements ActionListener {
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
return "to_date('" + formatter.format(data) + "','dd/mm/yyyy HH24:MI:SS')"; return "to_date('" + formatter.format(data) + "','dd/mm/yyyy HH24:MI:SS')";
}*/ }*/
private String formatLocalDateTime(LocalDateTime data) { private String formatLocalDateTime(LocalDateTime data) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
return "to_date('" + data.format(formatter) + "','dd/mm/yyyy HH24:MI:SS')"; return "to_date('" + data.format(formatter) + "','dd/mm/yyyy HH24:MI:SS')";
@ -4726,31 +4768,52 @@ public class PuntoCassa extends JFrame implements ActionListener {
} }
} }
/**
* Metodo che stampa un messaggio sul POS
private void statoAttivoNonLoggato() { * Se il POS è chiuso, stampa a prescindere, altrimenti stampa solo se non è stata letta una tessera
String PC = idPuntoCassa.toString(); * @param flagAperto
if (PC.length() >= 5) { */
PC = PC.substring(PC.length() - 5, PC.length()); private void stampaSuPos(boolean flagAperto){
String idPuntoCassaString = idPuntoCassa.toString();
if (idPuntoCassaString.length() >= 5) {
idPuntoCassaString = idPuntoCassaString.substring(idPuntoCassaString.length() - 5, idPuntoCassaString.length());
} else { } else {
PC = Utils.spaziBianchi(PC, 5, false); idPuntoCassaString = Utils.spaziBianchi(idPuntoCassaString, 5, false);
} }
String Riga = Utils.spaziBianchi(messageDisplay, 20, true) + "POS " + PC + " CHIUSO"; if(flagAperto && jTxtTessera.getText().trim().length() <= 0){
display(Riga, null); String riga = Utils.spaziBianchi(messageDisplay, 20, true) + "POS " + idPuntoCassaString + " APERTO";
display(riga, null);
}
else if (!flagAperto){
String riga = Utils.spaziBianchi(messageDisplay, 20, true) + "POS " + idPuntoCassaString + " CHIUSO";
display(riga, null);
}
}
private void statoAttivoNonLoggato() {
String idPuntoCassaString = idPuntoCassa.toString();
if (idPuntoCassaString.length() >= 5) {
idPuntoCassaString = idPuntoCassaString.substring(idPuntoCassaString.length() - 5, idPuntoCassaString.length());
} else {
idPuntoCassaString = Utils.spaziBianchi(idPuntoCassaString, 5, false);
}
String riga = Utils.spaziBianchi(messageDisplay, 20, true) + "POS " + idPuntoCassaString + " CHIUSO";
display(riga, null);
} }
private void statoAttivoLoggato() { private void statoAttivoLoggato() {
//per evitare che inserendo la tessera successiva mi cancelli il num tessera //per evitare che inserendo la tessera successiva mi cancelli il num tessera
if (jTxtTessera.getText().trim().length() <= 0) { if (jTxtTessera.getText().trim().length() <= 0) {
String PC = idPuntoCassa.toString(); String idPuntoCassaString = idPuntoCassa.toString();
if (PC.length() >= 5) { if (idPuntoCassaString.length() >= 5) {
PC = PC.substring(PC.length() - 5, PC.length()); idPuntoCassaString = idPuntoCassaString.substring(idPuntoCassaString.length() - 5, idPuntoCassaString.length());
} else { } else {
PC = Utils.spaziBianchi(PC, 5, false); idPuntoCassaString = Utils.spaziBianchi(idPuntoCassaString, 5, false);
} }
String riga = Utils.spaziBianchi(messageDisplay, 20, true) + "POS " + PC + " APERTO"; String riga = Utils.spaziBianchi(messageDisplay, 20, true) + "POS " + idPuntoCassaString + " APERTO";
display(riga, null); display(riga, null);
} }
} }
@ -4772,8 +4835,6 @@ public class PuntoCassa extends JFrame implements ActionListener {
} }
}*/ }*/
class CardTask extends TimerTask { class CardTask extends TimerTask {
PuntoCassa frmA; PuntoCassa frmA;
@ -4785,7 +4846,7 @@ public class PuntoCassa extends JFrame implements ActionListener {
public void run() { public void run() {
MyApplication myApp = new MyApplication(); MyApplication myApp = new MyApplication();
try { try {
myApp.smartCard.setReader(jcmbSC.getSelectedItem()); myApp.smartCard.setReader(jcmbSmartCard.getSelectedItem());
myApp.smartCard.connect("T=1"); myApp.smartCard.connect("T=1");
statoCarta = StatiCarta.INSERITA; statoCarta = StatiCarta.INSERITA;
if (pnlLogin.isVisible() == false && cartaLetta == false) { if (pnlLogin.isVisible() == false && cartaLetta == false) {
@ -4900,8 +4961,6 @@ public class PuntoCassa extends JFrame implements ActionListener {
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
public javax.swing.JButton btnImpostaCliente; public javax.swing.JButton btnImpostaCliente;
private javax.swing.JButton btnLogin; private javax.swing.JButton btnLogin;
@ -4927,7 +4986,7 @@ public class PuntoCassa extends JFrame implements ActionListener {
private javax.swing.JButton jbtnGiu; private javax.swing.JButton jbtnGiu;
private javax.swing.JButton jbtnStampa; private javax.swing.JButton jbtnStampa;
private javax.swing.JButton jbtnSu; private javax.swing.JButton jbtnSu;
private javax.swing.JComboBox jcmbSC; private javax.swing.JComboBox jcmbSmartCard;
private javax.swing.JLabel lblAzienda; private javax.swing.JLabel lblAzienda;
private javax.swing.JLabel lblCategoria; private javax.swing.JLabel lblCategoria;
private javax.swing.JLabel lblCodice; private javax.swing.JLabel lblCodice;