Manage Legal Notices functionality
[habeas.git] / src / habeas / Utility.java
index 3eabd87..a1148a2 100644 (file)
@@ -8,11 +8,8 @@ package habeas;
 import java.util.ArrayList;
 import java.util.prefs.Preferences;
 import java.sql.*;
-import java.util.Dictionary;
-import java.util.HashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import javax.swing.JOptionPane;
 
 /**
  *
@@ -116,6 +113,52 @@ public class Utility {
         }
         
         
+    }
+
+    static boolean addLegalNotice(String reference_number, 
+            String description, java.util.Date entrustment_date, DBItem client) {
+        if ("".equals(reference_number) || "".equals(description) ||
+                entrustment_date == null || client == null)
+            return false;
+        try {
+            Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL);
+            PreparedStatement st = conn.prepareStatement("INSERT INTO legalnotices"
+                    + " (ReferenceNumber, Description, EntrustmentDate, ClientId) "
+                    + "VALUES (?, ?, ?, ?);");
+            st.setString(1, reference_number);
+            st.setString(2, description);
+            st.setLong(3, entrustment_date.getTime()/1000);
+            st.setInt (4, client.getKey());
+            st.execute();
+            conn.close();
+            return true;
+            
+        } catch (SQLException ex) {
+            Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
+            return false;
+        }
+        
+    }
+
+    static ArrayList<Object> getNotices() {
+        ArrayList<Object> notices = new ArrayList<>();
+        try {
+            Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL);
+            Statement st = conn.createStatement();
+            ResultSet rs = st.executeQuery("SELECT id, ReferenceNumber, Description "
+                    + "FROM legalnotices;");
+            while (rs.next()) {
+                notices.add(rs.getInt("id"));
+                notices.add(rs.getString("ReferenceNumber"));
+                notices.add(rs.getString("Description"));
+            }
+            conn.close();
+            return notices;
+        } catch (SQLException ex) {
+            Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
+            return null;
+        }
+        
     }
     public Utility () {