diff --git a/src/puntocassa/PuntoCassa.form b/src/puntocassa/PuntoCassa.form index 18588c7..cbc47b6 100644 --- a/src/puntocassa/PuntoCassa.form +++ b/src/puntocassa/PuntoCassa.form @@ -184,7 +184,7 @@ - + @@ -195,7 +195,7 @@ - + @@ -299,7 +299,7 @@ - + diff --git a/src/puntocassa/PuntoCassa.java b/src/puntocassa/PuntoCassa.java index f23c86b..7542c9a 100644 --- a/src/puntocassa/PuntoCassa.java +++ b/src/puntocassa/PuntoCassa.java @@ -44,13 +44,13 @@ import javax.xml.parsers.DocumentBuilderFactory; import jssc.SerialPort; import jssc.SerialPortException; import org.apache.log4j.LogManager; +import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import puntocassa.utils.Utils; - //****************************************************************************** // * // * @author Master @@ -69,7 +69,7 @@ public class PuntoCassa extends JFrame implements ActionListener { public static String dbPassword = ""; private String utenteLoggato = ""; private String imgPath = "";// "L:\\Lavoro\\Goffredo\\risorse\\"; - private int displayWidth = 1024; + private int displayWidth = 1024; private int displayHeight = 768; private int altezzaBarraApplicazioni = 0; private Long progressivo = 0L; @@ -141,12 +141,11 @@ public class PuntoCassa extends JFrame implements ActionListener { private static Boolean bottoneImposta = true; private static Boolean asporto = false; private static Boolean flagPrecaricaLista = false; - + //delta per la grafica (in px) private int deltaWidth = 14; private int deltaHeight = 7; - - + // ========================================================================== // *** Constructor della classe PuntoCassa // ========================================================================== @@ -161,6 +160,7 @@ public class PuntoCassa extends JFrame implements ActionListener { // *** Legge la configurazione dal file XML // ----------------------------------------------------------------------- try { + MyApplication myApp = new MyApplication(); DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = documentFactory.newDocumentBuilder(); String startDir = System.getProperty("user.dir"); @@ -172,167 +172,67 @@ public class PuntoCassa extends JFrame implements ActionListener { ImageIcon icon = new ImageIcon(startDir + "/risorse/logo.png"); 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) { - 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(); + leggiNodoDatabase(document); - if (attivo.equals("SI")) { - //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; - } - } - } + NodeList paths = leggiNodoPath(document, startDir); + + idPuntoCassa = Long.valueOf(Utils.mySelect("SELECT valore FROM parametri WHERE chiave = 'IdPuntoCassa'", + "valore", + this)); + + leggiNodoEtichette(document, paths, idPuntoCassa); + + String credito = Utils.mySelect("SELECT valore FROM parametri WHERE chiave = 'FlagIgnoraSaldoStop'", + "valore", + this); + if (credito.equalsIgnoreCase("SI")) { + consentiCredito = true; } - // -------------------------------------------------------------------- - // ** 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/"; - } + //Aggiornamento 14-01-2019 + String stringDatiPagamento = Utils.mySelect("select tp.id || '|' || tp.nome || '|' || pd.flag_bonus || '|' || " + + "pd.flag_extra as valore from punti_cassa pc " + + "inner join punti_distribuzione pd on pc.id_punto_distribuzione = pd.id " + + "inner join tipi_pagamenti tp on pd.id_tipo_paga_default = tp.id " + + "where pc.id=" + idPuntoCassa, + "valore", + this); + + String[] arrayDatiPagamento = stringDatiPagamento.split("\\|", -1); + if (arrayDatiPagamento.length >= 2) { + idModoPagamento = Long.valueOf(arrayDatiPagamento[0]); + modoPagamentoDefault = arrayDatiPagamento[1]; + lblTipoPagamento.setText(arrayDatiPagamento[1]); + //Aggiornamento 14-01-2019 + flagBonus = Integer.valueOf(arrayDatiPagamento[2]); + flagExtra = false; + if (arrayDatiPagamento[3].equalsIgnoreCase("1")) { + flagExtra = true; } + pulsantiModoPagamento(); } - // -------------------------------------------------------------------- - // ** 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'", - "valore", - this)); - - //String credito = myApp.mySelect(this, "SELECT valore FROM parametri WHERE chiave = 'FlagIgnoraSaldoStop'", "valore"); - String credito = Utils.mySelect("SELECT valore FROM parametri WHERE chiave = 'FlagIgnoraSaldoStop'", - "valore", - this); - if (credito.equalsIgnoreCase("SI")) { - consentiCredito = true; - } - - titolo = titolo + " " + idPuntoCassa; - this.setTitle(titolo); - //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 || '|' || " - + "pd.flag_extra as valore from punti_cassa pc " - + "inner join punti_distribuzione pd on pc.id_punto_distribuzione = pd.id " - + "inner join tipi_pagamenti tp on pd.id_tipo_paga_default = tp.id " - + "where pc.id=" + idPuntoCassa, - "valore", - this); - - String[] arrayDatiPagamento = stringDatiPagamento.split("\\|", -1); - if (arrayDatiPagamento.length >= 2) { - idModoPagamento = Long.valueOf(arrayDatiPagamento[0]); - modoPagamentoDefault = arrayDatiPagamento[1]; - lblTipoPagamento.setText(arrayDatiPagamento[1]); - //Aggiornamento 14-01-2019 - flagBonus = Integer.valueOf(arrayDatiPagamento[2]); - flagExtra = false; - if (arrayDatiPagamento[3].equalsIgnoreCase("1")) { - flagExtra = true; - } - pulsantiModoPagamento(); - } - } - } - - // -------------------------------------------------------------------- - // ** 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"); - - } - } + leggiNodoDisplay(document, myApp); //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)); - lblPassword.setFont(f); - lblUsername.setFont(f); - txtUsername.setFont(f); - txtPassword.setFont(f); - jTxtTessera.setFont(f); - jChLogin.setFont(f); jBtnReadCard.setVisible(false); - - 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); - // -------------------------------------------------------------------- - // ** ID_PUNTO_CASSA - // -------------------------------------------------------------------- - jcmbSC.setVisible(false); + + settingFontsInterfaccia(); + - 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(); - 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", this); if (ultimiMovimenti.equalsIgnoreCase("NO")) { @@ -344,7 +244,7 @@ public class PuntoCassa extends JFrame implements ActionListener { statoAttivoNonLoggato(); - String flagRicevutaValue = Utils.mySelect("Select Valore from Parametri where Chiave='FlagRicevuta'", "Valore",this); + String flagRicevutaValue = Utils.mySelect("Select Valore from Parametri where Chiave='FlagRicevuta'", "Valore", this); PuntoCassa.flagRicevuta = !flagRicevutaValue.equalsIgnoreCase("NO"); String flagDataNascita = Utils.mySelect("Select Valore from Parametri where Chiave='FlagMostraDataDiNascita'", "Valore", this); @@ -353,7 +253,7 @@ public class PuntoCassa extends JFrame implements ActionListener { String flagEsegueStorniValue = Utils.mySelect("Select Valore from Parametri where Chiave='FlagEsegueStorni'", "Valore", this); this.flagEsegueStorni = !flagEsegueStorniValue.equalsIgnoreCase("NO"); - String timeoutSwipCard = Utils.mySelect("Select Valore from Parametri where Chiave='TimeoutSwipCard'", "Valore",this); + String timeoutSwipCard = Utils.mySelect("Select Valore from Parametri where Chiave='TimeoutSwipCard'", "Valore", this); //if (myApp.isNumeric(timeoutSwipCard)) { if (Utils.isNumeric(timeoutSwipCard)) { delaySwipCard = Integer.valueOf(timeoutSwipCard); @@ -366,7 +266,7 @@ public class PuntoCassa extends JFrame implements ActionListener { asporto = true; } - String flagPrecarica = Utils.mySelect("Select Valore from Parametri where Chiave='FlagPrecaricaLista'", "Valore", this); + String flagPrecarica = Utils.mySelect("Select Valore from Parametri where Chiave='FlagPrecaricaLista'", "Valore", this); flagPrecaricaLista = !flagPrecarica.equalsIgnoreCase("NO"); keyDispatcher = creaKeyEventDispatcher(); @@ -391,206 +291,355 @@ public class PuntoCassa extends JFrame implements ActionListener { verificaAggiornamentiJAR(); } - - public KeyEventDispatcher creaKeyEventDispatcher(){ - return new KeyEventDispatcher() { - Boolean swip = false; - Boolean spiaAltreCarte = false; - Boolean timerUnaVolta = false; - MyApplication myApp = new MyApplication(); - public boolean dispatchKeyEvent(KeyEvent e) { - int id = e.getID(); - - if (jbtnChiudi.isEnabled() && pnlLogin.isVisible() == false && jTxtTessera.getText().length() > 0) { - e.consume(); - if (myApp.unaVolta == false) { - myApp.unaVolta = true; - } - return false; - } - myApp.unaVolta = false; - int keyCode = e.getKeyCode(); - if (id == KeyEvent.KEY_RELEASED) { - String tasto = "" + e.getKeyChar(); - System.out.println(keyCode + " - " + tasto); - - logTestoTessera.append(e.getKeyChar()); - - if (tasto.equalsIgnoreCase("ò")) { //144 - swip = true; - } - //05-12-2017 - if (keyCode == 16 || keyCode == 45 || tasto.equalsIgnoreCase("ò")) { - spiaAltreCarte = true; - } - - if (tasto.equalsIgnoreCase("ò") == false && keyCode != 16 && keyCode != 45 && swip) { //keyCode != 144 && keyCode != 17 - - testoSwipCard.append(tasto); - System.out.println(testoSwipCard.toString()); - - } - if (keyCode == 45 && swip) { //keyCode != 144 - swip = false; - System.out.println(testoSwipCard.toString()); - - warn(); - } - - //30-11-2017 modifica per rfid - if (keyCode != 16) { - testoRFIDCard.append(tasto); - } - if (keyCode == 10 && swip == false && spiaAltreCarte == false) { //keyCode != 144 - - System.out.println(testoRFIDCard.toString()); - testoSwipCard = testoRFIDCard; - testoRFIDCard = new StringBuilder(); - warn(); - } - - //29-10-18------------------------------------------------------ - if (timerUnaVolta == false) { - timerUnaVolta = true; - final Timer timer = new Timer(); - final TimerTask task = new TimerTask() { - @Override - public void run() { - - if (testoRFIDCard.toString().length() > 2) { - System.out.println("Timer: " + testoRFIDCard.toString()); - testoSwipCard = testoRFIDCard; - testoRFIDCard = new StringBuilder(); - warn(); - } - - timer.cancel(); - timer.purge(); - timerUnaVolta = false; - } - }; - - timer.schedule(task, 5000); - } - //fine 29-10-18------------------------------------------------------ - - } - - return true; - } - - public void warn() { - if (statoCardLettore) { - return; - } - - //29-10-2018 - testoRFIDCard = new StringBuilder(); - //fine 29-10-2018 - - if (testoSwipCard.toString().length() > 0) { - statoCardLettore = true; - - final Timer timer = new Timer(); - - final TimerTask task = new TimerTask() { - @Override - public void run() { - String tessera = ""; - //per tessere tipo 8 e 9 - if (testoSwipCard.toString().contains("ì")) { - String[] txt = testoSwipCard.toString().split("ì"); - - // per tessera MASTERCARD CARDHOLDER - if (testoSwipCard.toString().length() > 30) { - - tessera = txt[0].trim().replace("_", ""); - } else { - tessera = txt[1].trim().replace("_", ""); - } - } else if (testoSwipCard.toString().contains("&")) { - // per tessera MASTERCARD CARDHOLDER - String[] txt = testoSwipCard.toString().split("&"); - - tessera = txt[0].trim().replace("%B", ""); - - } else { - tessera = testoSwipCard.toString().trim().replace("_", ""); - } - - //per tessera tipo 3 - if (tessera.length() >= 17 && tessera.length() <= 19) { - tessera = tessera.substring(0, 7); - } - - //per tessere tipo 6 e 7 - if (tessera.length() == 21) { - tessera = tessera.substring(0, 10); - int posI = 0; - for (int i = 0; i <= tessera.length(); i++) { - if (tessera.substring(i, i + 1).equalsIgnoreCase("0") == false) { - posI = i; - break; - } - } - - tessera = tessera.substring(posI); - } - - spiaAltreCarte = false; - swip = false; - if (pnlLogin.isVisible()) { - controllaLogInCarta(tessera); - } else { - //05/11/2018 le nuove tessere con CF a volte leggono solo la matricola - jTxtTessera.setText(tessera); - passaggioTessera = true; - logNumeroTessera = tessera; - cercaTessera(); - } - - testoSwipCard = new StringBuilder(); - - timer.cancel(); - timer.purge(); - statoCardLettore = false; - - } - }; - - timer.schedule(task, delaySwipCard); - - } - } - - }; - } - - - - /*** - * FlagProponiAggiornamentoDB ha 3 possibili valori: - * AUTO vuol dire che, se il db locale è da aggiornare (DB_locale_aggiornato = 0), lo deve fare e basta senza chiedere conferma - * SI vuol dire che, se il db locale è da aggiornare (DB_locale_aggiornato = 0), lo deve fare chiedendo conferma - * NO vuol dire che non lo deve fare nemmeno se è da aggiornare + /** + * Definizione e settaggio dei fonts sull'interfaccia grafica */ - private void verificaAggiornamentoDB() { - Long dbAggiornato = Utils.mySelectInteger("Select DB_locale_aggiornato as Agg from dual", "Agg", - this); - String flagProponiAggiornamentoDB = Utils.mySelect("Select Valore from Parametri where chiave='FlagProponiAggiornamentoDB' ", "Valore", - this); - if(dbAggiornato == 0){ - if (flagProponiAggiornamentoDB.equals("SI")) { - aggiornaDB(true); + 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"); + } - else if(flagProponiAggiornamentoDB.equals("AUTO")){ - aggiornaDB(false); - } } } - private void verificaModoPagamento() { + /** + * 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() { + return new KeyEventDispatcher() { + Boolean swip = false; + Boolean spiaAltreCarte = false; + Boolean timerUnaVolta = false; + MyApplication myApp = new MyApplication(); + + public boolean dispatchKeyEvent(KeyEvent e) { + int id = e.getID(); + + if (jbtnChiudi.isEnabled() && pnlLogin.isVisible() == false && jTxtTessera.getText().length() > 0) { + e.consume(); + if (myApp.unaVolta == false) { + myApp.unaVolta = true; + } + return false; + } + myApp.unaVolta = false; + int keyCode = e.getKeyCode(); + if (id == KeyEvent.KEY_RELEASED) { + String tasto = "" + e.getKeyChar(); + System.out.println(keyCode + " - " + tasto); + + logTestoTessera.append(e.getKeyChar()); + + if (tasto.equalsIgnoreCase("ò")) { //144 + swip = true; + } + //05-12-2017 + if (keyCode == 16 || keyCode == 45 || tasto.equalsIgnoreCase("ò")) { + spiaAltreCarte = true; + } + + if (tasto.equalsIgnoreCase("ò") == false && keyCode != 16 && keyCode != 45 && swip) { //keyCode != 144 && keyCode != 17 + + testoSwipCard.append(tasto); + System.out.println(testoSwipCard.toString()); + + } + if (keyCode == 45 && swip) { //keyCode != 144 + swip = false; + System.out.println(testoSwipCard.toString()); + + warn(); + } + + //30-11-2017 modifica per rfid + if (keyCode != 16) { + testoRFIDCard.append(tasto); + } + if (keyCode == 10 && swip == false && spiaAltreCarte == false) { //keyCode != 144 + + System.out.println(testoRFIDCard.toString()); + testoSwipCard = testoRFIDCard; + testoRFIDCard = new StringBuilder(); + warn(); + } + + //29-10-18------------------------------------------------------ + if (timerUnaVolta == false) { + timerUnaVolta = true; + final Timer timer = new Timer(); + final TimerTask task = new TimerTask() { + @Override + public void run() { + + if (testoRFIDCard.toString().length() > 2) { + System.out.println("Timer: " + testoRFIDCard.toString()); + testoSwipCard = testoRFIDCard; + testoRFIDCard = new StringBuilder(); + warn(); + } + + timer.cancel(); + timer.purge(); + timerUnaVolta = false; + } + }; + + timer.schedule(task, 5000); + } + //fine 29-10-18------------------------------------------------------ + + } + + return true; + } + + public void warn() { + if (statoCardLettore) { + return; + } + + //29-10-2018 + testoRFIDCard = new StringBuilder(); + //fine 29-10-2018 + + if (testoSwipCard.toString().length() > 0) { + statoCardLettore = true; + + final Timer timer = new Timer(); + + final TimerTask task = new TimerTask() { + @Override + public void run() { + String tessera = ""; + //per tessere tipo 8 e 9 + if (testoSwipCard.toString().contains("ì")) { + String[] txt = testoSwipCard.toString().split("ì"); + + // per tessera MASTERCARD CARDHOLDER + if (testoSwipCard.toString().length() > 30) { + + tessera = txt[0].trim().replace("_", ""); + } else { + tessera = txt[1].trim().replace("_", ""); + } + } else if (testoSwipCard.toString().contains("&")) { + // per tessera MASTERCARD CARDHOLDER + String[] txt = testoSwipCard.toString().split("&"); + + tessera = txt[0].trim().replace("%B", ""); + + } else { + tessera = testoSwipCard.toString().trim().replace("_", ""); + } + + //per tessera tipo 3 + if (tessera.length() >= 17 && tessera.length() <= 19) { + tessera = tessera.substring(0, 7); + } + + //per tessere tipo 6 e 7 + if (tessera.length() == 21) { + tessera = tessera.substring(0, 10); + int posI = 0; + for (int i = 0; i <= tessera.length(); i++) { + if (tessera.substring(i, i + 1).equalsIgnoreCase("0") == false) { + posI = i; + break; + } + } + + tessera = tessera.substring(posI); + } + + spiaAltreCarte = false; + swip = false; + if (pnlLogin.isVisible()) { + controllaLogInCarta(tessera); + } else { + //05/11/2018 le nuove tessere con CF a volte leggono solo la matricola + jTxtTessera.setText(tessera); + passaggioTessera = true; + logNumeroTessera = tessera; + cercaTessera(); + } + + testoSwipCard = new StringBuilder(); + + timer.cancel(); + timer.purge(); + statoCardLettore = false; + + } + }; + + timer.schedule(task, delaySwipCard); + + } + } + + }; + } + + /** + * * + * FlagProponiAggiornamentoDB ha 3 possibili valori: AUTO vuol dire che, se + * il db locale è da aggiornare (DB_locale_aggiornato = 0), lo deve fare e + * basta senza chiedere conferma SI vuol dire che, se il db locale è da + * aggiornare (DB_locale_aggiornato = 0), lo deve fare chiedendo conferma NO + * vuol dire che non lo deve fare nemmeno se è da aggiornare + */ + private void verificaAggiornamentoDB() { + Long dbAggiornato = Utils.mySelectInteger("Select DB_locale_aggiornato as Agg from dual", "Agg", + this); + String flagProponiAggiornamentoDB = Utils.mySelect("Select Valore from Parametri where chiave='FlagProponiAggiornamentoDB' ", "Valore", + this); + if (dbAggiornato == 0) { + if (flagProponiAggiornamentoDB.equals("SI")) { + aggiornaDB(true); + } else if (flagProponiAggiornamentoDB.equals("AUTO")) { + aggiornaDB(false); + } + } + } + + private void verificaModoPagamento() { flagImpostaTipoPagamento = Utils.mySelect("Select Valore from Parametri where chiave='FlagImpostaTipoPagamento' ", "Valore", this).equals("NO"); } @@ -601,10 +650,10 @@ public class PuntoCassa extends JFrame implements ActionListener { || !logNumeroTessera.isEmpty() || logTestoTessera.length() > 0) { Utils.myInsert("Insert into LETTURE_TESSERE (STRINGA_LETTA,NUMERO_TESSERA,ID_TESSERA,ERRORE) values " - + "('" + logTestoTessera.toString().replace("'", "''") - + "','" + logNumeroTessera - + "','" + logIDTessera - + "','" + logTesseraErrore.replace("'", "''") + + "('" + logTestoTessera.toString().replace("'", "''") + + "','" + logNumeroTessera + + "','" + logIDTessera + + "','" + logTesseraErrore.replace("'", "''") + "')", this); logIDTessera = ""; logNumeroTessera = ""; @@ -613,11 +662,11 @@ public class PuntoCassa extends JFrame implements ActionListener { } catch (Exception ex) { LogManager.getLogger(PuntoCassa.class).error(ex); } - } + } private void verificaAggiornamentiJAR() { try { - String pathURLAggiornamento = Utils.mySelect("Select Valore from Parametri where chiave='UrlJAR' ", "Valore", + String pathURLAggiornamento = Utils.mySelect("Select Valore from Parametri where chiave='UrlJAR' ", "Valore", this); if (pathURLAggiornamento.length() > 0) { @@ -645,16 +694,19 @@ 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 { - MyApplication myApp = new MyApplication(); - jcmbSC.setModel(new DefaultComboBoxModel(myApp.smartCard.listReaders())); + //MyApplication myApp = new MyApplication(); + jcmbSmartCard.setModel(new DefaultComboBoxModel(myApp.smartCard.listReaders())); } catch (Exception ex) { - LogManager.getLogger(PuntoCassa.class.getName()).error(ex); + LogManager.getLogger(PuntoCassa.class.getName()).error(ex); } } - private Integer calcolaLarghezzaAltezza(Integer larControllo, Integer percentuale) { Integer d = percentuale - 100; @@ -687,7 +739,7 @@ public class PuntoCassa extends JFrame implements ActionListener { jTxtTessera = new javax.swing.JTextField(); btnImpostaCliente = new javax.swing.JButton(); jBtnReadCard = new javax.swing.JButton(); - jcmbSC = new javax.swing.JComboBox(); + jcmbSmartCard = new javax.swing.JComboBox(); lblCodice3 = new javax.swing.JLabel(); lblTipoPagamento = 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.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); @@ -889,14 +941,14 @@ public class PuntoCassa extends JFrame implements ActionListener { .addGap(48, 48, 48) .addComponent(jBtnReadCard, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE) .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()) ); subPnlTesseraLayout.setVerticalGroup( subPnlTesseraLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(subPnlTesseraLayout.createSequentialGroup() .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)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTxtTessera, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -1516,18 +1568,18 @@ public class PuntoCassa extends JFrame implements ActionListener { y = th - 60; w = (tw / 8); h = 60; - + int part = (displayWidth - lblDB.getWidth()) / 9; - + lblUtenteLoggato.setLocation(x, y); //lblUtenteLoggato.setSize(w, h); lblUtenteLoggato.setSize(part, h); - + //lblInfo.setLocation(w, y); lblInfo.setLocation(lblUtenteLoggato.getLocation().x + lblUtenteLoggato.getSize().width, y); //lblInfo.setSize(w * 2 + 60 - lblDB.getWidth(), h); //lblInfo.setSize(296, h); - lblInfo.setSize((int)(part * 2.5), h); + lblInfo.setSize((int) (part * 2.5), h); //lblInfo2.setLocation(w * 3 + 60 - lblDB.getWidth(), y); lblInfo2.setLocation(lblInfo.getLocation().x + lblInfo.getSize().width, y); @@ -1535,13 +1587,13 @@ public class PuntoCassa extends JFrame implements ActionListener { int larg = tw - (w * 2 + 10) - 359; //lblInfo2.setSize(larg, h); //lblInfo2.setSize(444, h); - lblInfo2.setSize((int)(part * 4), h); + lblInfo2.setSize((int) (part * 4), h); //lblStatoConnessione.setLocation(tw - 181 - lblDB.getWidth(), y); lblStatoConnessione.setLocation(lblInfo2.getLocation().x + lblInfo2.getSize().width, y); //lblStatoConnessione.setSize(175, h); //lblStatoConnessione.setSize(116, h); - lblStatoConnessione.setSize((int)(part * 1.5), h); + lblStatoConnessione.setSize((int) (part * 1.5), h); //lblDB.setLocation(tw - 181 - lblDB.getWidth() + lblStatoConnessione.getWidth(), y); lblDB.setLocation(lblStatoConnessione.getLocation().x + lblStatoConnessione.getSize().width, y); @@ -1642,7 +1694,7 @@ public class PuntoCassa extends JFrame implements ActionListener { // ----------------------------------------------------------------------- y = h; pnlLista1.setBorder(javax.swing.BorderFactory.createTitledBorder("Composizione")); - pnlLista1.setLocation(x, y); + pnlLista1.setLocation(x, y); //pnlLista1.setSize(w, 70); pnlLista1.setSize(w, pnlProdotti.getHeight() / 6); scpLista1.setLocation(0, 0); @@ -1755,7 +1807,8 @@ public class PuntoCassa extends JFrame implements ActionListener { tipo = cmd.substring(0, i); switch (tipo) { - case "CATEGORIA" -> pulsantiCategoria(id, cmd); + case "CATEGORIA" -> + pulsantiCategoria(id, cmd); case "PRODOTTO" -> { if (isCassaAperta) { @@ -1846,7 +1899,7 @@ public class PuntoCassa extends JFrame implements ActionListener { } } //fine 21-12-18<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - + rs.close(); st.close(); dbConnection.close(); @@ -1917,9 +1970,10 @@ public class PuntoCassa extends JFrame implements ActionListener { } /** - * funzione che calcola i prezzi dei prodotti e il totale in base alla fascia dello studente - * oppure utilizza la fascia di default - * @param model + * funzione che calcola i prezzi dei prodotti e il totale in base alla + * fascia dello studente oppure utilizza la fascia di default + * + * @param model */ private void sommaColonne(MyTableModel model) { Double t = model.somma(colImporto); @@ -2029,7 +2083,7 @@ public class PuntoCassa extends JFrame implements ActionListener { "idCompleto", this); if (Long.parseLong(idVassoio) != -1) { - String nomeVassoio = Utils.mySelect("Select nome from vassoi where id=" + idVassoio, "nome", + String nomeVassoio = Utils.mySelect("Select nome from vassoi where id=" + idVassoio, "nome", this); String prezzo = Utils.mySelect("Select prezzo from tariffe where id_fascia=" + idProfiloTariffario + " " + "and id_prodotto=" + idVassoio, "prezzo", @@ -2075,7 +2129,7 @@ public class PuntoCassa extends JFrame implements ActionListener { JPanel pnl = this.pnlCategorie; switch (tipo) { - case "CATEGORIE" -> { + case "CATEGORIE" -> { sql = "SELECT distinct c.id, c.nome, c.descrizione FROM categorie_prodotti c " + " INNER JOIN prodotti p ON p.id_categoria = c.ID " + " INNER JOIN catalogo_punti_cassa l ON l.id_prodotto = p.ID " @@ -2177,7 +2231,7 @@ public class PuntoCassa extends JFrame implements ActionListener { + " AND t.id_fascia = " + idProfiloTariffario + " AND c.id_prodotto = p.id AND c.id_punto_cassa =" + idPuntoCassa; //MyApplication myApp = new MyApplication(); - String nrec = Utils.mySelect("SELECT count(*) as nrec " + sql2, "nrec", + String nrec = Utils.mySelect("SELECT count(*) as nrec " + sql2, "nrec", this); if (Integer.parseInt(nrec) <= 0) { menuGiornoPresente = false; @@ -2192,11 +2246,11 @@ public class PuntoCassa extends JFrame implements ActionListener { //JPanel pnl = this.pnlProdotti; var listaBottoni = new ArrayList(); - for (Integer r = 0; r < 6; r++) { Color c2 = new Color(255, 153, 255); switch (r) { - case 0 -> where = " and upper(cat.CODICE)='PRIM' "; + case 0 -> + where = " and upper(cat.CODICE)='PRIM' "; case 1 -> { where = " and upper(cat.CODICE)='SECO' "; c2 = Color.CYAN; @@ -2292,10 +2346,10 @@ public class PuntoCassa extends JFrame implements ActionListener { } this.pnlProdotti.setLayout(new GridLayout(6, 5, 1, 1)); this.pnlProdotti.removeAll(); - for(JToggleButton bt : listaBottoni){ + for (JToggleButton bt : listaBottoni) { this.pnlProdotti.add(bt); } - + this.pnlProdotti.revalidate(); this.pnlProdotti.repaint(); //this.revalidate(); @@ -2570,30 +2624,30 @@ public class PuntoCassa extends JFrame implements ActionListener { // ** progressivo giorno turno scontrino // ----------------------------------------------------------- Date now = new Date(); - String progT = Utils.mySelect("select nvl(max(prog_turno),0) as Prog from Progressivi where id_Punto_cassa=" - + idPuntoCassa + " and id_Turno=" + idTurno + " and data=" + formattaData(now), + String progT = Utils.mySelect("select nvl(max(prog_turno),0) as Prog from Progressivi where id_Punto_cassa=" + + idPuntoCassa + " and id_Turno=" + idTurno + " and data=" + formattaData(now), "Prog", this); progressivoTurno = Long.valueOf(progT); - String progG = Utils.mySelect("select nvl(max(prog_giorno),0) as Prog from Progressivi where id_Punto_cassa=" + String progG = Utils.mySelect("select nvl(max(prog_giorno),0) as Prog from Progressivi where id_Punto_cassa=" + idPuntoCassa + " and data=" + formattaData(now), "Prog", this); progressivoGiorno = Long.valueOf(progG); - String controlloTurno = Utils.mySelect("select count(*) as Prog from Progressivi where id_Punto_cassa=" + String controlloTurno = Utils.mySelect("select count(*) as Prog from Progressivi where id_Punto_cassa=" + idPuntoCassa + " and data=" + formattaData(now) + " and id_Turno=" + idTurno, "Prog", this); if (Long.parseLong(controlloTurno) <= 0) { Utils.myInsert("Insert into Progressivi (data,id_Punto_cassa,id_Turno,prog_assoluto,prog_giorno,prog_turno) " - + " values (" + formattaData(now) + "," + idPuntoCassa + "," + idTurno + "," + progressivo + "," + progressivoGiorno + ",0)", - this); + + " values (" + formattaData(now) + "," + idPuntoCassa + "," + idTurno + "," + progressivo + "," + progressivoGiorno + ",0)", + this); } // ----------------------------------------------------------- // ** incassi turno pagamento a scalare // ----------------------------------------------------------- - String progPS = Utils.mySelect("select nvl(sum(incasso_turno_scalare),0) as Prog from Progressivi where id_Punto_cassa=" + String progPS = Utils.mySelect("select nvl(sum(incasso_turno_scalare),0) as Prog from Progressivi where id_Punto_cassa=" + idPuntoCassa + " and id_Turno=" + idTurno + " and data=" + formattaData(now), "Prog", this); progressivoScalare = Double.valueOf(progPS); @@ -2601,7 +2655,7 @@ public class PuntoCassa extends JFrame implements ActionListener { // ----------------------------------------------------------- // ** incassi turno pagamento a contanti // ----------------------------------------------------------- - String progPC = Utils.mySelect("select nvl(sum(incasso_turno_contanti),0) as Prog from Progressivi where id_Punto_cassa=" + String progPC = Utils.mySelect("select nvl(sum(incasso_turno_contanti),0) as Prog from Progressivi where id_Punto_cassa=" + idPuntoCassa + " and id_Turno=" + idTurno + " and data=" + formattaData(now), "Prog", this); progressivoContanti = Double.valueOf(progPC); @@ -2609,7 +2663,7 @@ public class PuntoCassa extends JFrame implements ActionListener { // ----------------------------------------------------------- // ** incassi turno pagamento ticket // ----------------------------------------------------------- - String progPT = Utils.mySelect("select nvl(sum(incasso_turno_ticket),0) as Prog from Progressivi where id_Punto_cassa=" + String progPT = Utils.mySelect("select nvl(sum(incasso_turno_ticket),0) as Prog from Progressivi where id_Punto_cassa=" + idPuntoCassa + " and id_Turno=" + idTurno + " and data=" + formattaData(now), "Prog", this); progressivoTicket = Double.valueOf(progPT); @@ -2617,7 +2671,7 @@ public class PuntoCassa extends JFrame implements ActionListener { // ----------------------------------------------------------- // ** incassi turno pagamento differito // ----------------------------------------------------------- - String progDI = Utils.mySelect("select nvl(sum(incasso_turno_differito),0) as Prog from Progressivi where id_Punto_cassa=" + String progDI = Utils.mySelect("select nvl(sum(incasso_turno_differito),0) as Prog from Progressivi where id_Punto_cassa=" + idPuntoCassa + " and id_Turno=" + idTurno + " and data=" + formattaData(now), "Prog", this); progressivoDifferito = Double.valueOf(progDI); @@ -2646,12 +2700,12 @@ public class PuntoCassa extends JFrame implements ActionListener { lblInfo.setText("Passaggi: Tot. [" + prog + "], giorno [" + progGG + "], turno [" + progTurno + "]"); DecimalFormat df2 = new DecimalFormat("#,###,###,##0.00"); - lblInfo2.setText("Incassi [" + nomeTurno + "]: Tot. [" + - df2.format(progressivoScalare + progressivoContanti + progressivoTicket + progressivoDifferito) + "] SC [" + - df2.format(progressivoScalare) + "], CO [" + - df2.format(progressivoContanti) + "], TI [" + - df2.format(progressivoTicket) + "], DI [" + - df2.format(progressivoDifferito) + "]"); + lblInfo2.setText("Incassi [" + nomeTurno + "]: Tot. [" + + df2.format(progressivoScalare + progressivoContanti + progressivoTicket + progressivoDifferito) + "] SC [" + + df2.format(progressivoScalare) + "], CO [" + + df2.format(progressivoContanti) + "], TI [" + + df2.format(progressivoTicket) + "], DI [" + + df2.format(progressivoDifferito) + "]"); } public void addRemoveKeyDispatcher(Boolean aggiungi) { @@ -2733,7 +2787,7 @@ public class PuntoCassa extends JFrame implements ActionListener { private void jbtnStampaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnStampaActionPerformed - Boolean ok = Utils.myInsert("UPDATE PARAMETRI set valore='NO' where chiave='FlagDownloadInCorso'", + Boolean ok = Utils.myInsert("UPDATE PARAMETRI set valore='NO' where chiave='FlagDownloadInCorso'", this); if (ok) { JOptionPane.showOptionDialog(this, "Operazione correttamente eseguita.", "Attenzione", @@ -2847,7 +2901,7 @@ public class PuntoCassa extends JFrame implements ActionListener { nTessera = nTess; } } catch (Exception ex) { - JOptionPane.showMessageDialog(this, "Card Reader non collegato o errore di lettura!", + JOptionPane.showMessageDialog(this, "Card Reader non collegato o errore di lettura!", "jBtnReadCardActionPerformed", JOptionPane.ERROR_MESSAGE); } finally { @@ -2862,12 +2916,12 @@ public class PuntoCassa extends JFrame implements ActionListener { }//GEN-LAST:event_formWindowDeiconified private void setTastiera(java.awt.event.MouseEvent evt) { setTastieraAfterEvent(evt); - } + } private void setTastiera(java.awt.event.FocusEvent evt) { setTastieraAfterEvent(evt); } - + private void setTastieraAfterEvent(ComponentEvent evt) { MyApplication myApp = new MyApplication(); if (jChLogin.isSelected() == false) { @@ -2883,13 +2937,13 @@ public class PuntoCassa extends JFrame implements ActionListener { } } } - - + + private void jbtnEsciActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnEsciActionPerformed Object[] options = {"Si", "No"}; Object selectedValue = JOptionPane.showOptionDialog(this, "Confermi chiusura sessione?", "Attenzione", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); - if (Integer.parseInt(selectedValue.toString()) == 0) { + if (Integer.parseInt(selectedValue.toString()) == 0) { pnlErrore.setVisible(false); pnlLogin.setVisible(true); pnlTop.setVisible(false); @@ -2908,7 +2962,7 @@ public class PuntoCassa extends JFrame implements ActionListener { jChLoginActionPerformed(null); azzera(); statoAttivoNonLoggato(); - } + } }//GEN-LAST:event_jbtnEsciActionPerformed private void jBtnStornoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnStornoActionPerformed @@ -2966,7 +3020,7 @@ public class PuntoCassa extends JFrame implements ActionListener { JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); return; } - + if (isCassaAperta == true) { lblResiduo.setText("[...]"); setModoPagamento("A scalare"); @@ -3087,7 +3141,7 @@ public class PuntoCassa extends JFrame implements ActionListener { if (Integer.parseInt(selectedValue.toString()) == 0) { annulla(); doLayout(); - } + } } }//GEN-LAST:event_jbtnAnnullaActionPerformed private void annulla() { @@ -3207,7 +3261,6 @@ public class PuntoCassa extends JFrame implements ActionListener { //pwd = new String(); //sql = new String(); - // ======================================================================= // *** Verifica la correttezza delle credenziali inserite - Account // ======================================================================= @@ -3224,7 +3277,7 @@ public class PuntoCassa extends JFrame implements ActionListener { sql = "SELECT id || '|' || id_Stato as res FROM accounts WHERE username = '" + this.txtUsername.getText() + "' " + "and password = '" + Encoding.encodeString(pwd) + "'"; //String[] el = myApp.mySelect(this, sql, "res").split("\\|"); - String[] el = Utils.mySelect(sql, "res",this).split("\\|"); + String[] el = Utils.mySelect(sql, "res", this).split("\\|"); //if (myApp.isNumeric(el[0])) { if (Utils.isNumeric(el[0])) { idAccount = Long.valueOf(el[0]); @@ -3400,29 +3453,29 @@ public class PuntoCassa extends JFrame implements ActionListener { //21/12/2016 if (gratuitaResidue <= 0) {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //11/06/24 rimozione controllo su gratuita e bonus //if (gratuitaResidue <= 0 && (flagBonus == 0 || bonusResidui <= 0)) { - if ((saldo - calcolaTotale()) <= saldoStop) { + if ((saldo - calcolaTotale()) <= saldoStop) { - //31-10-2019 se lista precaricata e saldo <0 devo chudere - //if (stoCalcolando == false) { - if (cercaTestoModoPagamento().equalsIgnoreCase("A scalare")) { - if ((saldo - calcolaTotale()) < 0) { - JOptionPane.showMessageDialog(this, "Saldo insufficiente!", "Saldo", JOptionPane.OK_OPTION); - logTessera(); - //azzera(); - return true; - } - } - //} - isSaldoOK = true; - } else if (saldo <= saldoAlert) { - JOptionPane.showMessageDialog(this, - "Saldo ridotto, potrebbero non essere disponibili tutti i prodotti!", - "Saldo Alert", JOptionPane.ERROR_MESSAGE); - isSaldoOK = true; - - } else { - isSaldoOK = true; + //31-10-2019 se lista precaricata e saldo <0 devo chudere + //if (stoCalcolando == false) { + if (cercaTestoModoPagamento().equalsIgnoreCase("A scalare")) { + if ((saldo - calcolaTotale()) < 0) { + JOptionPane.showMessageDialog(this, "Saldo insufficiente!", "Saldo", JOptionPane.OK_OPTION); + logTessera(); + //azzera(); + return true; + } } + //} + isSaldoOK = true; + } else if (saldo <= saldoAlert) { + JOptionPane.showMessageDialog(this, + "Saldo ridotto, potrebbero non essere disponibili tutti i prodotti!", + "Saldo Alert", JOptionPane.ERROR_MESSAGE); + isSaldoOK = true; + + } else { + isSaldoOK = true; + } //} return isSaldoOK; } @@ -3468,12 +3521,10 @@ public class PuntoCassa extends JFrame implements ActionListener { return testo; } - /*** - * Metodo che gestisce la pressione dei bottoni relativi alle modalita di pagamento - * 0 -> a scalare - * 1 -> contanti - * 2 -> ticket - * 3 -> differito + /** + * * + * Metodo che gestisce la pressione dei bottoni relativi alle modalita di + * pagamento 0 -> a scalare 1 -> contanti 2 -> ticket 3 -> differito */ private void pulsantiModoPagamento() { switch (Integer.parseInt(idModoPagamento.toString())) { @@ -3534,7 +3585,7 @@ public class PuntoCassa extends JFrame implements ActionListener { + " where t.numero = '" + numTessera + "' and t.id_utente = u.id" + " and u.id_categoria = c.id and cf.id_categoria_utenti = c.id"; - String[] saldoMinimo = Utils.mySelect(querySaldo, "saldi",this).split("\\|"); + String[] saldoMinimo = Utils.mySelect(querySaldo, "saldi", this).split("\\|"); Double saldo = 0.0; String residuo = lblResiduo.getText().trim().replace("€", ""); if (residuo.equalsIgnoreCase("[...]")) { @@ -3553,14 +3604,14 @@ public class PuntoCassa extends JFrame implements ActionListener { if (saldo <= saldoAlert) { if (consentiCredito == true) { if (messaggioSaldoUnaVolta == false) { - if (JOptionPane.showConfirmDialog(null, "Saldo insufficiente. Vuoi autorizzare comunque la transazione?", + if (JOptionPane.showConfirmDialog(null, "Saldo insufficiente. Vuoi autorizzare comunque la transazione?", "Saldo", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { messaggioSaldoUnaVolta = true; } else { return; } } - } + } } } //-------------------------------------------------------- @@ -3576,7 +3627,7 @@ public class PuntoCassa extends JFrame implements ActionListener { Double costoPasto = Double.valueOf(txtTotaleCassa.getText().replace("€", "").trim().replace(",", ".")); if (saldo > costoPasto) { Object[] options = {"A Scalare", "Contanti"}; - Object selectedValue = JOptionPane.showOptionDialog(this, + Object selectedValue = JOptionPane.showOptionDialog(this, "Attenzione, c'è saldo sufficiente sulla tessera,\nscegli la modalità di pagamento da utilizzare", "Modalità Pagamento", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, null); if (Integer.parseInt(selectedValue.toString()) == 0) { @@ -3593,7 +3644,7 @@ public class PuntoCassa extends JFrame implements ActionListener { } } Boolean spiaProgressivo = false; - + LocalDateTime adesso = LocalDateTime.now(); LocalDate oggi = LocalDate.now(); String flagPassaggioTessera = "0"; @@ -3629,14 +3680,14 @@ public class PuntoCassa extends JFrame implements ActionListener { + "INNER JOIN prodotti pr ON st.id_prodotto = pr.id " + "WHERE pr.id_categoria = 0 " + "AND trunc(st.data) = trunc(sysdate) " - + "AND st.id_tessera = " + idTessera + + "AND st.id_tessera = " + idTessera + " AND st.id_turno=" + idTurno; Long abilitatoPassaggi = Utils.mySelectInteger(controlloPassaggi, "passaggi", - this); + this); if (abilitatoPassaggi > 0) { abilitatoPassaggi = abilitatoPassaggi + 1; - if (JOptionPane.showConfirmDialog(null, - "Sei sicuro di voler registrare il passaggio n° " + abilitatoPassaggi + " sulla tessera " + jTxtTessera.getText() + "?", + if (JOptionPane.showConfirmDialog(null, + "Sei sicuro di voler registrare il passaggio n° " + abilitatoPassaggi + " sulla tessera " + jTxtTessera.getText() + "?", "Secondo Passaggio", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) { azzera(); aggiornaLabelInfo(); @@ -3655,11 +3706,11 @@ public class PuntoCassa extends JFrame implements ActionListener { Utils.myInsert("Insert into Acquisti " + "(id,id_Tessera,id_Prodotto,id_Punto_Cassa,Data,Importo,Punti," + "Num_Progressivo,id_Tipo_Pagamento,flag_in_vassoio,id_Turno,flag_asporto,flag_passaggio_tessera)" - + "values(-1," + tessera + "," + model.getValueAt(i, colIDProdotto) + "," + + "values(-1," + tessera + "," + model.getValueAt(i, colIDProdotto) + "," //+ idPuntoCassa + "," + formattaDataOra(adesso) + "," - + idPuntoCassa + "," + formatLocalDateTime(adesso) + "," - + model.getValueAt(i, colImporto) + "," + model.getValueAt(i, colPunti) + "," - + progressivo + "," + idModoPagamento + "," + vassoio + "," + idTurno + "," + + idPuntoCassa + "," + formatLocalDateTime(adesso) + "," + + model.getValueAt(i, colImporto) + "," + model.getValueAt(i, colPunti) + "," + + progressivo + "," + idModoPagamento + "," + vassoio + "," + idTurno + "," + flagAsporto + "," + flagPassaggioTessera + ")", this); @@ -3683,13 +3734,13 @@ public class PuntoCassa extends JFrame implements ActionListener { Utils.myInsert("Insert into Acquisti " + "(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)" - + "values(-1," + tessera + "," + model2.getValueAt(i, 2) + "," + idPuntoCassa + "," + - //formattaDataOra(adesso) + "," + model2.getValueAt(i, 1) + ",0," + progressivo + "," + - formatLocalDateTime(adesso) + "," + model2.getValueAt(i, 1) + ",0," + progressivo + "," + - idModoPagamento + "," + idTurno + "," + flagGratuita + "," + flagBonus + "," + - flagAsporto + "," + flagPassaggioTessera + ")", + + "values(-1," + tessera + "," + model2.getValueAt(i, 2) + "," + idPuntoCassa + "," + + //formattaDataOra(adesso) + "," + model2.getValueAt(i, 1) + ",0," + progressivo + "," + + formatLocalDateTime(adesso) + "," + model2.getValueAt(i, 1) + ",0," + progressivo + "," + + idModoPagamento + "," + idTurno + "," + flagGratuita + "," + flagBonus + "," + + flagAsporto + "," + flagPassaggioTessera + ")", this); - aggiornaProgressivoPagamentiTurno(Double.valueOf(model2.getValueAt(i, 1).toString())); + aggiornaProgressivoPagamentiTurno(Double.valueOf(model2.getValueAt(i, 1).toString())); model2.deleteRow(i); spiaProgressivo = true; } @@ -3702,18 +3753,18 @@ public class PuntoCassa extends JFrame implements ActionListener { //04/03/2022 non e possibile acquistare prodotti che non siano partedi una composizione String vassoio = "1"; Utils.myInsert("Insert into Acquisti (id,id_Prodotto,id_Punto_Cassa,Data,Importo,Punti,Num_Progressivo,id_Tipo_Pagamento," - + "flag_in_vassoio,id_Turno,flag_asporto,flag_passaggio_tessera)values(-1," + + "flag_in_vassoio,id_Turno,flag_asporto,flag_passaggio_tessera)values(-1," //+ model.getValueAt(i, colIDProdotto) + "," + idPuntoCassa + "," + formattaDataOra(adesso) + "," - + model.getValueAt(i, colIDProdotto) + "," + idPuntoCassa + "," + formatLocalDateTime(adesso) + "," - + model.getValueAt(i, colImporto) + "," + model.getValueAt(i, colPunti) - + "," + progressivo + "," + idModoPagamento + "," + vassoio + "," + idTurno + "," + + model.getValueAt(i, colIDProdotto) + "," + idPuntoCassa + "," + formatLocalDateTime(adesso) + "," + + model.getValueAt(i, colImporto) + "," + model.getValueAt(i, colPunti) + + "," + progressivo + "," + idModoPagamento + "," + vassoio + "," + idTurno + "," + flagAsporto + "," + flagPassaggioTessera + ")", this); aggiornaProgressivoPagamentiTurno(Double.valueOf(model.getValueAt(i, colImporto).toString())); elencoIdProdotti.append(model.getValueAt(i, colIDProdotto)); - elencoIdProdotti.append(","); + elencoIdProdotti.append(","); } model.deleteRow(i); spiaProgressivo = true; @@ -3730,10 +3781,10 @@ public class PuntoCassa extends JFrame implements ActionListener { } Utils.myInsert("Insert into Acquisti (id,id_Prodotto,id_Punto_Cassa,Data,Importo,Punti,Num_Progressivo,id_Tipo_Pagamento," - + "id_Turno,flag_gratuita,flag_bonus,flag_asporto,flag_passaggio_tessera)values(-1," + + "id_Turno,flag_gratuita,flag_bonus,flag_asporto,flag_passaggio_tessera)values(-1," //+ model2.getValueAt(i, 2) + "," + idPuntoCassa + "," + formattaDataOra(adesso) + "," - + model2.getValueAt(i, 2) + "," + idPuntoCassa + "," + formatLocalDateTime(adesso) + "," - + model2.getValueAt(i, 1) + ",0," + progressivo + "," + idModoPagamento + "," + idTurno + + model2.getValueAt(i, 2) + "," + idPuntoCassa + "," + formatLocalDateTime(adesso) + "," + + model2.getValueAt(i, 1) + ",0," + progressivo + "," + idModoPagamento + "," + idTurno + "," + flagGratuita + "," + flagBonusPerInsert + "," + flagAsporto + "," + flagPassaggioTessera + ")", this); aggiornaProgressivoPagamentiTurno(Double.valueOf(model2.getValueAt(i, 1).toString())); @@ -3749,10 +3800,10 @@ public class PuntoCassa extends JFrame implements ActionListener { progressivo++; progressivoGiorno++; progressivoTurno++; - Utils.myInsert("Update Progressivi set Prog_assoluto=" + progressivo + ",prog_giorno=" + progressivoGiorno - + ",prog_Turno=" + progressivoTurno + ",incasso_turno_contanti=" + progressivoContanti - + ",incasso_turno_ticket=" + progressivoTicket + ",incasso_turno_scalare=" + progressivoScalare - + ",incasso_turno_differito=" + progressivoDifferito + Utils.myInsert("Update Progressivi set Prog_assoluto=" + progressivo + ",prog_giorno=" + progressivoGiorno + + ",prog_Turno=" + progressivoTurno + ",incasso_turno_contanti=" + progressivoContanti + + ",incasso_turno_ticket=" + progressivoTicket + ",incasso_turno_scalare=" + progressivoScalare + + ",incasso_turno_differito=" + progressivoDifferito //+ " where id_Punto_cassa=" + idPuntoCassa + " and id_turno=" + idTurno + " and data=" + formattaData(adesso)); + " where id_Punto_cassa=" + idPuntoCassa + " and id_turno=" + idTurno + " and data=" + formatLocalDate(oggi), this); @@ -3802,8 +3853,8 @@ public class PuntoCassa extends JFrame implements ActionListener { String query = "SELECT count(*) as nr FROM VIEW_PRENOTAZIONI_TURNO " + "WHERE id_Modalita in (2,3) " + "and id_stato in (0,1) " - + "AND id_turno =" + idTurnoAttuale - + " AND id_tessera = " + idTessera + + "AND id_turno =" + idTurnoAttuale + + " AND id_tessera = " + idTessera + " and id_Prenotazione=" + idPrenotazione; int rowCount = Integer.parseInt(Utils.mySelect(query, "nr", this)); if (rowCount > 0) { @@ -3811,8 +3862,8 @@ public class PuntoCassa extends JFrame implements ActionListener { query = "SELECT count(*) as nr FROM VIEW_PRENOTAZIONI_TURNO " + "WHERE id_Modalita in (2,3) " + "and id_stato in (0,1) " - + "AND id_turno =" + idTurnoAttuale - + " AND id_tessera = " + idTessera + + "AND id_turno =" + idTurnoAttuale + + " AND id_tessera = " + idTessera + " AND id_Prodotto in (" + elencoIdProdotto + ") " + "and id_Prenotazione=" + idPrenotazione; rowCount = Integer.parseInt(Utils.mySelect(query, "nr", this)); @@ -3822,7 +3873,7 @@ public class PuntoCassa extends JFrame implements ActionListener { } Object[] options = {"Si", "No"}; - Object selectedValue = JOptionPane.showOptionDialog(this, + Object selectedValue = JOptionPane.showOptionDialog(this, "I prodotti selezionati sono diversi dai prenotati!\nVuoi proseguire?", "Prenotazione", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, null); if (Integer.parseInt(selectedValue.toString()) == 1) { @@ -3840,14 +3891,14 @@ public class PuntoCassa extends JFrame implements ActionListener { String query = "SELECT id FROM VIEW_PRENOTAZIONI_TURNO " + "WHERE id_Modalita in (2,3) " + "and id_stato in (0,1) " - + "AND id_turno =" + idTurnoAttuale - + " AND id_tessera = " + idTessera + + "AND id_turno =" + idTurnoAttuale + + " AND id_tessera = " + idTessera + " and id_Prenotazione=" + idPrenotazione; Connection dbConnection = DriverManager.getConnection(dbStringa, dbUsername, dbPassword); Statement st = dbConnection.createStatement(); ResultSet rs = st.executeQuery(query); while (rs.next()) { - Utils.myInsert("Update PRENOTAZIONI_PASTI set id_Stato=2 where id=" + rs.getString("id"), + Utils.myInsert("Update PRENOTAZIONI_PASTI set id_Stato=2 where id=" + rs.getString("id"), this); } rs.close(); @@ -3880,7 +3931,7 @@ public class PuntoCassa extends JFrame implements ActionListener { private void azzera() { try { MyTableModel model = (MyTableModel) tblLista.getModel(); - MyTableModel model1 = (MyTableModel) tblLista1.getModel(); + MyTableModel model1 = (MyTableModel) tblLista1.getModel(); model.clearTable(); model1.clearTable(); } catch (Exception e) { @@ -3896,7 +3947,7 @@ public class PuntoCassa extends JFrame implements ActionListener { pnlCategorie.setVisible(false); pnlProdotti.setVisible(false); - + if (flagPrecaricaLista == false) { abilitaPulsanti(pnlCategorie, false, false); abilitaPulsanti(pnlProdotti, false, false); @@ -3964,51 +4015,49 @@ public class PuntoCassa extends JFrame implements ActionListener { //lblFascia.setText(""); //if (isCassaAperta == false) { + turnoAttuale(); + if ((idTurnoAttuale - idTurno) != 0) { - turnoAttuale(); - if ((idTurnoAttuale - idTurno) != 0) { + progressivoTurno = 1L; + progressivoContanti = 0.00; + progressivoScalare = 0.00; + progressivoTicket = 0.00; + progressivoDifferito = 0.00; + if (nomeTurnoAttuale.equalsIgnoreCase("Pranzo")) { + progressivoGiorno = 1L; + } + idTurno = idTurnoAttuale; + nomeTurno = nomeTurnoAttuale; - progressivoTurno = 1L; - progressivoContanti = 0.00; - progressivoScalare = 0.00; - progressivoTicket = 0.00; - progressivoDifferito = 0.00; - if (nomeTurnoAttuale.equalsIgnoreCase("Pranzo")) { - progressivoGiorno = 1L; - } - idTurno = idTurnoAttuale; - nomeTurno = nomeTurnoAttuale; - - Date adesso = new Date(); - String controlloTurno = Utils.mySelect("select count(*) as Prog from Progressivi " - + "where id_Punto_cassa=" + idPuntoCassa - + " and data=" + formattaData(adesso) - + " and id_Turno=" + idTurno, "Prog", + Date adesso = new Date(); + String controlloTurno = Utils.mySelect("select count(*) as Prog from Progressivi " + + "where id_Punto_cassa=" + idPuntoCassa + + " and data=" + formattaData(adesso) + + " and id_Turno=" + idTurno, "Prog", + this); + if (Long.parseLong(controlloTurno) <= 0) { + Utils.myInsert("Insert into Progressivi (data,id_Punto_cassa,id_Turno,prog_assoluto,prog_giorno,prog_turno) " + + " values (" + formattaData(adesso) + "," + idPuntoCassa + "," + idTurno + "," + + progressivo + "," + progressivoGiorno + ",0)", this); - if (Long.parseLong(controlloTurno) <= 0) { - Utils.myInsert("Insert into Progressivi (data,id_Punto_cassa,id_Turno,prog_assoluto,prog_giorno,prog_turno) " - + " values (" + formattaData(adesso) + "," + idPuntoCassa + "," + idTurno + "," - + progressivo + "," + progressivoGiorno + ",0)", - this); - } - - aggiornaLabelInfo(); } - isCassaAperta = true; - idProfiloTariffario = idProfiloTariffarioDefault;//0L + aggiornaLabelInfo(); + } - //setModoPagamento(modoPagamentoDefault); + isCassaAperta = true; + idProfiloTariffario = idProfiloTariffarioDefault;//0L - this.caricaPannello(); - //abilitaPulsanti(pnlCategorie, true, true); - jbtnChiudi.setEnabled(false); + //setModoPagamento(modoPagamentoDefault); + this.caricaPannello(); + //abilitaPulsanti(pnlCategorie, true, true); + jbtnChiudi.setEnabled(false); //} } /** * funzione richiamata in seguito alla selezione di una tessera - * + * */ public void cercaTessera() {//String QueryCF) { MyApplication myApp = new MyApplication(); @@ -4034,7 +4083,7 @@ public class PuntoCassa extends JFrame implements ActionListener { String dati[] = res.split("\\|", -1); Date now = new Date(); - + SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); idProfiloTariffario = Long.valueOf(dati[12]); @@ -4049,13 +4098,15 @@ public class PuntoCassa extends JFrame implements ActionListener { logTessera(); try { - if (!controlloAbilitazioneTessera(numeroTessera)) + if (!controlloAbilitazioneTessera(numeroTessera)) { return; - + } + String controlloPassaggi = "Select controlla_passaggi('" + numeroTessera + "'," + idPuntoCassa + ") as T from dual"; Long abilitatoPassaggi = Utils.mySelectInteger(controlloPassaggi, "T", this); - if (!controlloPassaggi(abilitatoPassaggi, numeroTessera)) + if (!controlloPassaggi(abilitatoPassaggi, numeroTessera)) { return; + } //aggiungo un giorno altrimenti in caso di scadenza nello stesso giorno //considera le ore @@ -4066,7 +4117,7 @@ public class PuntoCassa extends JFrame implements ActionListener { scadenzaTessera = c.getTime(); if (scadenzaTessera.after(now) && idStato != 2) { - + MyTableModel model = (MyTableModel) tblLista.getModel(); String modoPagamento = cercaTestoModoPagamento(); @@ -4077,7 +4128,7 @@ public class PuntoCassa extends JFrame implements ActionListener { if (flagMostraDataDiNascita) { lblNascita.setText(dati[3]); } - + lblAzienda.setText(dati[5]); lblConvenzione.setText(dati[6]); lblFascia.setText(dati[7]); @@ -4085,7 +4136,7 @@ public class PuntoCassa extends JFrame implements ActionListener { jBtnAsporto.setEnabled(true); jbtnChiudi.setEnabled(true); - + if (btnImpostaCliente.isVisible()) { btnImpostaCliente.setEnabled(false); jBtnBuoni.setEnabled(false); @@ -4098,7 +4149,7 @@ public class PuntoCassa extends JFrame implements ActionListener { if (dati.length > 13) { if (dati[13].length() > 0) { gratuitaResidue = Integer.parseInt(dati[13]); - } + } lblGratuita.setText(dati[13]); } @@ -4124,14 +4175,13 @@ public class PuntoCassa extends JFrame implements ActionListener { pulsantiModoPagamento(); stoCalcolando = false; - if (!modoPagamento.equalsIgnoreCase("A scalare")) { + if (!modoPagamento.equalsIgnoreCase("A scalare")) { String punti = Utils.mySelect("Select Punti from Tessere where numero='" + numeroTessera + "'", "Punti", this); lblPunti.setText(punti); String tipo = cercaTestoModoPagamento(); lblTipoPagamento.setText(tipo); } - //28-09-2016 quando c'è una sola categoria faccio click if (numeroCategorie == 1) { @@ -4176,8 +4226,8 @@ public class PuntoCassa extends JFrame implements ActionListener { } - private boolean controlloPassaggi(Long abilitatoPassaggi, String numeroTessera) throws HeadlessException, NumberFormatException { - + private boolean controlloPassaggi(Long abilitatoPassaggi, String numeroTessera) throws HeadlessException, NumberFormatException { + if (abilitatoPassaggi == 0L) { //05/09/2022 String queryPassaggi = "select count(*) as NRec from st_acquisti a inner join prodotti p on a.id_prodotto=p.id inner join Tipi_Pagamenti tp on a.id_tipo_pagamento=tp.id where TRUNC(data) = TRUNC(SYSDATE) and id_tessera=" + idTessera + " and flag_in_vassoio=0 and id_punto_cassa=" + idPuntoCassa; @@ -4225,12 +4275,12 @@ public class PuntoCassa extends JFrame implements ActionListener { try { String query = "SELECT * FROM (SELECT id_Prenotazione as nr FROM VIEW_PRENOTAZIONI_TURNO " - + "WHERE id_modalita in (2,3) " - + "AND id_stato IN (0,1) " - + "AND id_turno = " + idTurnoAttuale + " " - + "AND id_tessera = " + idTessera + " " - + "order by id_prenotazione) " - + "where rownum = 1"; + + "WHERE id_modalita in (2,3) " + + "AND id_stato IN (0,1) " + + "AND id_turno = " + idTurnoAttuale + " " + + "AND id_tessera = " + idTessera + " " + + "order by id_prenotazione) " + + "where rownum = 1"; String idP = Utils.mySelect(query, "nr", this); if (idP.length() > 0) { Long rowCount = Long.valueOf(idP); @@ -4239,9 +4289,9 @@ public class PuntoCassa extends JFrame implements ActionListener { query = "SELECT Distinct Nome FROM VIEW_PRENOTAZIONI_TURNO v join prodotti p on v.ID_PRODOTTO=p.ID " + "WHERE id_Modalita in (2,3) " + "and id_stato in (0,1) " - + "AND id_turno =" + idTurnoAttuale - + " AND id_tessera = " + idTessera - + " and id_prenotazione=" + idPrenotazione + + "AND id_turno =" + idTurnoAttuale + + " AND id_tessera = " + idTessera + + " and id_prenotazione=" + idPrenotazione + " order by Nome"; Connection dbConnection = DriverManager.getConnection(dbStringa, dbUsername, dbPassword); Statement st = dbConnection.createStatement(); @@ -4273,7 +4323,7 @@ public class PuntoCassa extends JFrame implements ActionListener { try { MyTableModel model = (MyTableModel) tblLista.getModel(); - MyTableModel model1 = (MyTableModel) tblLista1.getModel(); + MyTableModel model1 = (MyTableModel) tblLista1.getModel(); model.clearTable(); model1.clearTable(); sommaColonne(model); @@ -4281,8 +4331,8 @@ public class PuntoCassa extends JFrame implements ActionListener { String query = "SELECT * FROM VIEW_PRENOTAZIONI_TURNO " + "WHERE id_Modalita in (2,3) " + "and id_stato in (0,1) " - + "AND id_turno =" + idTurnoAttuale - + " AND id_tessera = " + idTessera + + "AND id_turno =" + idTurnoAttuale + + " AND id_tessera = " + idTessera + " and id_prenotazione=" + idPrenotazione; Connection dbConnection = DriverManager.getConnection(dbStringa, dbUsername, dbPassword); @@ -4342,7 +4392,7 @@ public class PuntoCassa extends JFrame implements ActionListener { Object row[] = model.getRow(y); String idProdotto = row[3].toString(); String query = "SELECT Punti || '|' || prezzo as res FROM tariffe " - + "where id_Prodotto = " + idProdotto + + "where id_Prodotto = " + idProdotto + " and id_fascia=" + idProfiloTariffario; String res = Utils.mySelect(query, "res", this); if (res.length() > 0) { @@ -4398,7 +4448,7 @@ public class PuntoCassa extends JFrame implements ActionListener { } } - } + } public Object[][] rowData(String query, String[] cols, String[] colType, int rowCount) { Object[][] rows = null; @@ -4469,13 +4519,6 @@ public class PuntoCassa extends JFrame implements ActionListener { } - - - - - - - public void getImage(String idProdotto) { String fullName = null; InputStream gifData = null; @@ -4541,24 +4584,23 @@ public class PuntoCassa extends JFrame implements ActionListener { return imgData; }*/ - /*private String formattaDataOra(Date data) { + /*private String formattaDataOra(Date data) { SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm: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"); - return "to_date('" + data.format(formatter) + "','dd/mm/yyyy HH24:MI:SS')"; + return "to_date('" + data.format(formatter) + "','dd/mm/yyyy HH24:MI:SS')"; } - - private String formatLocalDate(LocalDate data){ + + private String formatLocalDate(LocalDate data) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); - return "to_date('" + data.format(formatter) + "','dd/mm/yyyy')"; + return "to_date('" + data.format(formatter) + "','dd/mm/yyyy')"; } private String formattaData(Date data) { SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); - return "to_date('" + formatter.format(data) + "','dd/mm/yyyy')"; + return "to_date('" + formatter.format(data) + "','dd/mm/yyyy')"; } private void aggiungiImmaginiPulsanti() { @@ -4616,7 +4658,7 @@ public class PuntoCassa extends JFrame implements ActionListener { // *** occupare tutto lo schermo utile // ================================================================= Toolkit toolkit = Toolkit.getDefaultToolkit(); - Dimension screenSize = toolkit.getScreenSize(); + Dimension screenSize = toolkit.getScreenSize(); //p.setSize(1024, 768); //p.setLocation((int) (screenSize.width - 1024) / 2, (int) (screenSize.height - 768) / 2); @@ -4675,7 +4717,7 @@ public class PuntoCassa extends JFrame implements ActionListener { idAccount = 0L; if (stato == 2) { //String messaggio = myApp.mySelect(this, "Select Descrizione from Stati_Accounts where id=" + stato, "descrizione"); - String messaggio = Utils.mySelect("Select Descrizione from Stati_Accounts where id=" + stato, "descrizione", + String messaggio = Utils.mySelect("Select Descrizione from Stati_Accounts where id=" + stato, "descrizione", this); JOptionPane.showMessageDialog(this, messaggio + "."); @@ -4725,32 +4767,53 @@ public class PuntoCassa extends JFrame implements ActionListener { } } } - - - private void statoAttivoNonLoggato() { - String PC = idPuntoCassa.toString(); - if (PC.length() >= 5) { - PC = PC.substring(PC.length() - 5, PC.length()); + /** + * Metodo che stampa un messaggio sul POS + * Se il POS è chiuso, stampa a prescindere, altrimenti stampa solo se non è stata letta una tessera + * @param flagAperto + */ + private void stampaSuPos(boolean flagAperto){ + String idPuntoCassaString = idPuntoCassa.toString(); + if (idPuntoCassaString.length() >= 5) { + idPuntoCassaString = idPuntoCassaString.substring(idPuntoCassaString.length() - 5, idPuntoCassaString.length()); } else { - PC = Utils.spaziBianchi(PC, 5, false); + idPuntoCassaString = Utils.spaziBianchi(idPuntoCassaString, 5, false); } - String Riga = Utils.spaziBianchi(messageDisplay, 20, true) + "POS " + PC + " CHIUSO"; - display(Riga, null); + if(flagAperto && jTxtTessera.getText().trim().length() <= 0){ + 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() { //per evitare che inserendo la tessera successiva mi cancelli il num tessera if (jTxtTessera.getText().trim().length() <= 0) { - String PC = idPuntoCassa.toString(); - if (PC.length() >= 5) { - PC = PC.substring(PC.length() - 5, PC.length()); + String idPuntoCassaString = idPuntoCassa.toString(); + if (idPuntoCassaString.length() >= 5) { + idPuntoCassaString = idPuntoCassaString.substring(idPuntoCassaString.length() - 5, idPuntoCassaString.length()); } 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); } } @@ -4772,8 +4835,6 @@ public class PuntoCassa extends JFrame implements ActionListener { } }*/ - - class CardTask extends TimerTask { PuntoCassa frmA; @@ -4785,7 +4846,7 @@ public class PuntoCassa extends JFrame implements ActionListener { public void run() { MyApplication myApp = new MyApplication(); try { - myApp.smartCard.setReader(jcmbSC.getSelectedItem()); + myApp.smartCard.setReader(jcmbSmartCard.getSelectedItem()); myApp.smartCard.connect("T=1"); statoCarta = StatiCarta.INSERITA; if (pnlLogin.isVisible() == false && cartaLetta == false) { @@ -4810,7 +4871,7 @@ public class PuntoCassa extends JFrame implements ActionListener { } } - + // ========================================================================== // *** Sottoclasse per la gestione degli eventi a timer // ========================================================================== @@ -4898,8 +4959,6 @@ public class PuntoCassa extends JFrame implements ActionListener { } } - - // Variables declaration - do not modify//GEN-BEGIN:variables @@ -4927,7 +4986,7 @@ public class PuntoCassa extends JFrame implements ActionListener { private javax.swing.JButton jbtnGiu; private javax.swing.JButton jbtnStampa; private javax.swing.JButton jbtnSu; - private javax.swing.JComboBox jcmbSC; + private javax.swing.JComboBox jcmbSmartCard; private javax.swing.JLabel lblAzienda; private javax.swing.JLabel lblCategoria; private javax.swing.JLabel lblCodice;