refactoring funzioni, metodi e variabili
creazione file Utils
This commit is contained in:
parent
f7f5a3975e
commit
086dc95e49
File diff suppressed because it is too large
Load Diff
103
src/puntocassa/utils/Utils.java
Normal file
103
src/puntocassa/utils/Utils.java
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package puntocassa.utils;
|
||||
|
||||
import java.sql.*;
|
||||
import javax.swing.JOptionPane;
|
||||
import puntocassa.PuntoCassa;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco DS
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
public static boolean isNumeric(String s) {
|
||||
return s.matches("[-+]?\\d*\\.?\\d+");
|
||||
}
|
||||
|
||||
|
||||
public static String mySelect(String query, String campo, String dbStringa, String dbUsername, String dbPassword, PuntoCassa puntoCassa) {
|
||||
String res = "";
|
||||
try {
|
||||
Connection dbConnection = DriverManager.getConnection(dbStringa, dbUsername, dbPassword);
|
||||
Statement st = dbConnection.createStatement();
|
||||
ResultSet rs = st.executeQuery(query);
|
||||
while (rs.next()) {
|
||||
|
||||
res = rs.getString(campo);
|
||||
}
|
||||
rs.close();
|
||||
st.close();
|
||||
dbConnection.close();
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(puntoCassa, "Errore MySelect ['" + e.getMessage() + " " + query + "']");
|
||||
|
||||
}
|
||||
if (res == null) {
|
||||
res = "";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Boolean myInsert(String query, String dbStringa, String dbUsername, String dbPassword, PuntoCassa puntoCassa) {
|
||||
//System.out.println(query);
|
||||
Boolean res = false;
|
||||
try {
|
||||
Connection dbConnection = DriverManager.getConnection(dbStringa, dbUsername, dbPassword);
|
||||
Statement st = dbConnection.createStatement();
|
||||
ResultSet rs = st.executeQuery(query);
|
||||
rs.close();
|
||||
st.close();
|
||||
dbConnection.close();
|
||||
res = true;
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(puntoCassa, "Errore MySelect ['" + e.getMessage() + " " + query + "']");
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Long mySelectInteger(String query, String campo, String dbStringa, String dbUsername, String dbPassword, PuntoCassa puntoCassa) {
|
||||
System.out.println(query);
|
||||
Long res = 0L;
|
||||
try {
|
||||
Connection dbConnection = DriverManager.getConnection(dbStringa, dbUsername, dbPassword);
|
||||
Statement st = dbConnection.createStatement();
|
||||
ResultSet rs = st.executeQuery(query);
|
||||
while (rs.next()) {
|
||||
|
||||
res = rs.getLong(campo);
|
||||
}
|
||||
rs.close();
|
||||
st.close();
|
||||
dbConnection.close();
|
||||
} catch (SQLException e) {
|
||||
JOptionPane.showMessageDialog(puntoCassa, "Errore MySelectInteger ['" + e.getMessage() + " " + query + "']");
|
||||
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public static String spaziBianchi(String testo, Integer Num, Boolean suffisso) {
|
||||
String res = testo;
|
||||
StringBuilder suff = new StringBuilder();
|
||||
if (testo.length() < Num) {
|
||||
Integer delta = Num - testo.length();
|
||||
for (Integer i = 0; i < delta; i++) {
|
||||
suff.append(" ");
|
||||
}
|
||||
if (suffisso == false) {
|
||||
res = suff.toString() + testo;
|
||||
} else {
|
||||
res = testo + suff.toString();
|
||||
}
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user