diff --git a/it/unisa/info13d/Articoli/Global.java b/it/unisa/info13d/Articoli/Global.java index fb2b6cb..2b1bb70 100644 --- a/it/unisa/info13d/Articoli/Global.java +++ b/it/unisa/info13d/Articoli/Global.java @@ -24,11 +24,14 @@ public class Global { return general_counter; } + public static void setGeneral_counter(int general_counter) { + Global.general_counter = general_counter; + } /** * E' il contatore statico privato */ - private static int general_counter = 0; + private static int general_counter; } diff --git a/it/unisa/info13d/Main.java b/it/unisa/info13d/Main.java index 71857b7..d76b8ea 100644 --- a/it/unisa/info13d/Main.java +++ b/it/unisa/info13d/Main.java @@ -9,6 +9,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.text.ParseException; +import it.unisa.info13d.Utility.IdCounter; import it.unisa.info13d.Utility.ReShow; public class Main { @@ -18,12 +19,16 @@ public class Main { LoginData login = new LoginData(); login.getUserDataInfo(); + + IdCounter.restore_counter(); Catalogo load_catalogo = new Catalogo(); ReShow r = new ReShow(); for (;r.reshow;) load_catalogo.showMenu(login.getType(),r); + IdCounter.save_counter(); + } diff --git a/it/unisa/info13d/Utility/IdCounter.java b/it/unisa/info13d/Utility/IdCounter.java index 22a1064..a23cb85 100644 --- a/it/unisa/info13d/Utility/IdCounter.java +++ b/it/unisa/info13d/Utility/IdCounter.java @@ -23,7 +23,19 @@ public class IdCounter { } + public static void restore_counter() throws FileNotFoundException,IOException,ClassNotFoundException{ + File f_data = new File("id_counter"); + if ( (f_data.exists())){ + ObjectInputStream reader = new ObjectInputStream(new FileInputStream(f_data)); + Integer data = (Integer) reader.readObject(); + Global.setGeneral_counter(data.intValue()); + }else{ + Global.setGeneral_counter(0); + + } + + } }