@ -7,43 +7,34 @@ import java.sql.ResultSet;
import java.sql.SQLException ;
import java.sql.Statement ;
import java.util.ArrayList ;
import com.jFxKasse.application.Main ;
import com.jFxKasse.datatypes.tableDataJob ;
import com.jFxKasse.datatypes.tableDataPositionen ;
import java.io.File ;
public class DBController
{
private Connection connection ;
private String DB_PATH_Linux = System . getProperty ( "user.home" )
+ "/bin/jFxKasse/" ;
private String DB_PATH ;
private String dbname ;
@SuppressWarnings ( "unused" )
private Main main ;
public void main ( )
{
try {
connection = DriverManager
. getConnection ( "jdbc:sqlite:" + DB_PATH_Linux + dbname + ".db" ) ;
. getConnection ( "jdbc:sqlite:" + DB_PATH + dbname + ".db" ) ;
} catch ( SQLException e ) {
// TODO Auto-generated catch block
e . printStackTrace ( ) ;
}
}
public DBController ( Main main )
public DBController ( String path )
{
this . main = main ;
this . DB_PATH = path ;
}
public void setDbname ( String dbname )
{
this . dbname = dbname ;
@ -51,14 +42,14 @@ public class DBController
public void connectDatabase ( )
{ // connect to database
System . out . println ( "Verbinde ... DB name: " + dbname ) ;
System . out . println ( "Connecting ... DB name: " + dbname ) ;
try {
if ( connection ! = null )
return ;
connection = DriverManager
. getConnection ( "jdbc:sqlite:" + DB_PATH_Linux + dbname + ".db" ) ;
. getConnection ( "jdbc:sqlite:" + DB_PATH + dbname + ".db" ) ;
if ( ! connection . isClosed ( ) )
System . out . println ( "DB Datei-Verbindung erstellt " ) ;
System . out . println ( "DB connection established " ) ;
} catch ( SQLException e ) {
throw new RuntimeException ( e ) ;
}
@ -78,8 +69,8 @@ public class DBController
} ) ;
}
public boolean existiertDatenbank ( String pPfad )
{ // Prüft ob die Datenbank existiert
public boolean existDB ( String pPfad )
{ // does the DB exists?
File varTmpDir = new File ( pPfad ) ;
if ( ! varTmpDir . exists ( ) ) {
return false ;
@ -90,10 +81,7 @@ public class DBController
public String getCategoryNameFromPositionen ( int pID )
{
// System.out.println("getCategoryName: " + pID);
int catInPos = 0 ;
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery ( "SELECT posid, cat FROM positionen "
@ -104,11 +92,9 @@ public class DBController
e . printStackTrace ( ) ;
}
if ( catInPos = = 6 ) {
return "Standard" ;
}
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery ( "SELECT catid, catname FROM category "
@ -125,7 +111,7 @@ public class DBController
// table Position section //
public void createTablePositionen ( )
{ // create table position
System . out . println ( "Erstelle Tabel le Positionen" ) ;
System . out . println ( "Creating tab le Positionen" ) ;
try {
Statement stmt = connection . createStatement ( ) ;
stmt . executeUpdate ( "DROP TABLE IF EXISTS positionen;" ) ;
@ -146,7 +132,7 @@ public class DBController
public void fillPositionen_Positionen ( int pID , String pName , float pValue ,
int pCat , String pColor )
{ // create new data in table
System . out . println ( "Erstelle neuen positionen eintrag " ) ;
System . out . println ( "Creating new positionen entry " ) ;
try {
PreparedStatement ps = connection . prepareStatement (
"INSERT INTO positionen VALUES (?, ?, ?, ?, ?);" ) ;
@ -167,7 +153,7 @@ public class DBController
}
public String getName_Positionen ( int pID )
{ // Gibt das Datum zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -181,7 +167,7 @@ public class DBController
}
public String getValue_Positionen ( int pID )
{ // Gibt das Konto zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -196,7 +182,7 @@ public class DBController
}
public int getCat_Positionen ( int pID )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -211,7 +197,7 @@ public class DBController
}
public String getColor_Positionen ( int pID )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -226,7 +212,7 @@ public class DBController
}
public void setName_Positionen ( int pID , String pName )
{ // Setzt das Datum
{
try {
Statement stmt = connection . createStatement ( ) ;
stmt . executeUpdate ( "UPDATE positionen SET name = '" + pName
@ -238,7 +224,7 @@ public class DBController
}
public void setValue_Positionen ( int pID , String pValue )
{ // Setzt das Konto
{
try {
Statement stmt = connection . createStatement ( ) ;
stmt . executeUpdate ( "UPDATE positionen SET value = '" + pValue
@ -250,7 +236,7 @@ public class DBController
}
public void setCat_Positionen ( int pID , int pCat )
{ // Setzt den Nutzername
{
try {
Statement stmt = connection . createStatement ( ) ;
stmt . executeUpdate ( "UPDATE positionen SET cat = '" + pCat
@ -262,7 +248,7 @@ public class DBController
}
public void setColor_Positionen ( int pID , String pColor )
{ // Setzt den Nutzername
{
try {
Statement stmt = connection . createStatement ( ) ;
stmt . executeUpdate ( "UPDATE positionen SET color = '" + pColor
@ -274,14 +260,13 @@ public class DBController
}
public ArrayList < tableDataPositionen > ladeTabellePositionen ( )
{ // Gibt ein Objekt daten mit allen Einträgen der DB zurück
{
ArrayList < tableDataPositionen > daten = new ArrayList < > ( ) ;
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery ( "SELECT * FROM positionen;" ) ;
while ( rs . next ( ) ) {
try {
// Entschlüsselte Daten werden als Datenobjekt gespeichert
daten . add ( new tableDataPositionen ( rs . getInt ( "posid" ) ,
rs . getString ( "name" ) , rs . getString ( "value" ) ,
rs . getString ( "cat" ) , rs . getString ( "color" ) ) ) ;
@ -298,7 +283,7 @@ public class DBController
}
public void ausgebenSysoPositionen ( )
{ // Debugging Ausgabe der kompletten Tabelle
{
System . out . println ( "Print positionen" ) ;
try {
Statement stmt = connection . createStatement ( ) ;
@ -339,7 +324,7 @@ public class DBController
}
public void setName_Category ( int pID , String pName )
{ // Setzte den Namen
{
try {
Statement stmt = connection . createStatement ( ) ;
stmt . executeUpdate ( "UPDATE category SET catname = '" + pName
@ -371,7 +356,7 @@ public class DBController
}
public String getName_Category ( int pID )
{ // Gibt das Datum zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -387,8 +372,8 @@ public class DBController
// table Jobs section //
public void erstelleTabelleJobs ( )
{ // Erstelle Tabelle mit Reihen
System . out . println ( "Erstelle Tabel le Jobs" ) ;
{ // create table jobs
System . out . println ( "Creating tab le Jobs" ) ;
try {
Statement stmt = connection . createStatement ( ) ;
stmt . executeUpdate ( "DROP TABLE IF EXISTS jobs;" ) ;
@ -402,7 +387,6 @@ public class DBController
public int getLatestJobNumber_Job ( )
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -414,11 +398,10 @@ public class DBController
}
return 0 ;
}
public String getTime_Job ( int pID )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -432,7 +415,7 @@ public class DBController
}
public String getQuantity_Job ( int pID )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -447,7 +430,7 @@ public class DBController
}
public String getName_Job ( int pID )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -462,7 +445,7 @@ public class DBController
}
public String getValue_Job ( int pID )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -477,7 +460,7 @@ public class DBController
}
public String getCategory_Job ( int pID )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -492,7 +475,7 @@ public class DBController
}
public String getState_Job ( int pID )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -506,7 +489,7 @@ public class DBController
}
public String getJobValue_Job ( int pID )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -520,7 +503,7 @@ public class DBController
}
public String getAllJobValue_Job ( )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
@ -533,14 +516,14 @@ public class DBController
return "0" ;
}
}
public String getJobCount ( )
{ // Gibt den Nutzernamen zurück
{
try {
Statement stmt = connection . createStatement ( ) ;
ResultSet rs = stmt . executeQuery (
"SELECT count(*) AS JOBCOUNT FROM jobs WHERE state = "
+ '"' + "verbucht" + '"' + ";" ) ;
"SELECT count(*) AS JOBCOUNT FROM jobs WHERE state = " + '"'
+ "verbucht" + '"' + ";" ) ;
return rs . getString ( "JOBCOUNT" ) ;
} catch ( SQLException e ) {
System . err . println ( "Couldn't handle DB-Query" ) ;
@ -548,12 +531,9 @@ public class DBController
return "0" ;
}
}
public void setStatus_Jobs ( int pID , String pStatus )
{ // Setzt das Konto
{
try {
Statement stmt = connection . createStatement ( ) ;
stmt . executeUpdate ( "UPDATE jobs SET state = '" + pStatus
@ -565,7 +545,7 @@ public class DBController
}
public ArrayList < tableDataJob > loadTableJobs_Job ( )
{ // Gibt den Nutzernamen zurück
{
ArrayList < tableDataJob > tmp = new ArrayList < tableDataJob > ( ) ;
try {
@ -575,8 +555,6 @@ public class DBController
while ( rs . next ( ) ) {
try {
// return rs.getString("jobvalue");
String tablePosition = rs . getString ( "positionen_name" ) ;
tableDataJob data = new tableDataJob ( rs . getInt ( "jobid" ) ,
@ -600,7 +578,6 @@ public class DBController
String pPositionen_name , String pPositionen_value ,
String pPositionen_cat , String pState , String pJobvalue )
{
System . out . println ( "Create new Job Entry" ) ;
try {
PreparedStatement ps = connection . prepareStatement (
@ -621,7 +598,5 @@ public class DBController
System . err . println ( "Couldn't handle DB-Query" ) ;
e . printStackTrace ( ) ;
}
}
}