X-Git-Url: https://harishankar.org/repos/?p=habeas.git;a=blobdiff_plain;f=src%2Fhabeas%2FUtility.java;h=14edb1f0e0ae635693b1e690eea8523ac631e8df;hp=8795204463730b08014ff741371333ca28b931c8;hb=HEAD;hpb=020bf95644b2f26d9c81d66d2a752e55bcd3ad5b diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java index 8795204..14edb1f 100644 --- a/src/habeas/Utility.java +++ b/src/habeas/Utility.java @@ -17,6 +17,7 @@ import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.logging.Level; import java.util.logging.Logger; +import org.sqlite.util.StringUtils; /** * @@ -30,7 +31,23 @@ public class Utility { "SELECT ReferenceNumber, Description, SentDate, RPADReference, " + "ClientName FROM legalnotices INNER JOIN clients ON ClientId=clients.id" - + " WHERE NoticeSent=1 AND NoticeDelivered=0;" + + " WHERE NoticeSent=1 AND NoticeDelivered=0;", + + "SELECT ReferenceNumber, Description, EntrustmentDate, ClientName FROM legalnotices" + + " INNER JOIN clients ON ClientId=clients.id" + + " WHERE DraftCreated=1 AND DraftApproved=0;", + + "SELECT ReferenceNumber, Description, EntrustmentDate, " + + "ClarificationRemarks, ClientName FROM legalnotices INNER JOIN clients ON" + + " ClientId=clients.id WHERE ClarificationPending=1;", + + "SELECT ReferenceNumber, Description, EntrustmentDate, ClarificationRemarks" + + ", ClientName from legalnotices INNER JOIN clients ON ClientId=clients.id " + + "WHERE DraftCreated=0;", + + "SELECT ReferenceNumber, Description, EntrustmentDate, ClientName FROM" + + " legalnotices INNER JOIN clients ON ClientId=clients.id WHERE " + + " DraftApproved=1 AND NoticeSent=0;" } ; private static final String[] REPORTS_FILTERED = { "SELECT ReferenceNumber, Description" @@ -40,7 +57,23 @@ public class Utility { "SELECT ReferenceNumber, Description, SentDate, RPADReference, " + "ClientName FROM legalnotices INNER JOIN clients ON ClientId=clients.id" - + " WHERE NoticeSent=1 AND NoticeDelivered=0 AND ClientId=?;" + + " WHERE NoticeSent=1 AND NoticeDelivered=0 AND ClientId=?;", + + "SELECT ReferenceNumber, Description, EntrustmentDate, ClientName FROM legalnotices" + + " INNER JOIN clients ON ClientId=clients.id" + + " WHERE DraftCreated=1 AND DraftApproved=0 AND ClientId=?;", + + "SELECT ReferenceNumber, Description, EntrustmentDate, " + + "ClarificationRemarks, ClientName FROM legalnotices INNER JOIN clients ON" + + " ClientId=clients.id WHERE ClarificationPending=1 AND ClientId=?;", + + "SELECT ReferenceNumber, Description, EntrustmentDate, ClarificationRemarks" + + ", ClientName from legalnotices INNER JOIN clients ON ClientId=clients.id " + + "WHERE DraftCreated=0 AND ClientId=?;", + + "SELECT ReferenceNumber, Description, EntrustmentDate, ClientName FROM" + + " legalnotices INNER JOIN clients ON ClientId=clients.id WHERE " + + " DraftApproved=1 AND NoticeSent=0 AND ClientId=?;" } ; static void saveStationerySettings (String left_header, @@ -322,14 +355,14 @@ public class Utility { } static boolean updateNoticeBillDetails(int selid, String bill_status, - java.util.Date bill_date, int bill_amount) { + java.util.Date bill_date, long bill_amount) { try { Connection conn = DriverManager.getConnection(JDBC + connectionURL); PreparedStatement st = conn.prepareStatement("UPDATE legalnotices" + " SET BillStatus=?,BillDate=?,BillAmount=? WHERE id=?;"); st.setString (1, bill_status); st.setDate(2, toSqlDate(bill_date)); - st.setInt(3, bill_amount); + st.setLong(3, bill_amount); st.setInt(4, selid); st.execute(); conn.close(); @@ -560,13 +593,13 @@ public class Utility { try { FileWriter f = new FileWriter (filePath); for (int i = 0; i < reportCols.length; i ++) { - f.append (escapeQuote(reportCols[i])); + f.append (escapeQuoteCSV(reportCols[i])); f.append (","); } f.append("\n"); for (int i = 0; i < reportData.size(); i += reportCols.length) { for (int j = 0; j < reportCols.length; j ++) { - f.append (escapeQuote(reportData.get(i+j))); + f.append (escapeQuoteCSV(reportData.get(i+j))); f.append (","); } f.append ("\n"); @@ -581,8 +614,10 @@ public class Utility { } - private static String escapeQuote(Object bareStr) { - if (bareStr.getClass() == String.class) { + private static String escapeQuoteCSV(Object bareStr) { + if (bareStr == null) + return ""; + else if (bareStr.getClass() == String.class) { String str = (String)bareStr; String escapedStr = str.replace ("\"", "\"\""); System.out.println(escapedStr); @@ -593,6 +628,60 @@ public class Utility { return String.format("\"%s\"", bareStr.toString()); } + static boolean saveReportHTML(String filepath, String report_title, + String[] report_cols, ArrayList report_data) { + FileWriter htmlFile; + try { + htmlFile = new FileWriter(filepath); + htmlFile.append("\n\n\n"); + htmlFile.append(htmlEscape(report_title)); + htmlFile.append("\n\n"); + htmlFile.append ("\n"); + htmlFile.append("

"); + htmlFile.append(htmlEscape(report_title)); + htmlFile.append("

\n"); + htmlFile.append ("\n"); + htmlFile.append ("\t\n"); + for (int i = 0; i < report_cols.length; i ++) { + htmlFile.append ("\t\t\n"); + } + htmlFile.append ("\t\n"); + for (int r = 0; r < report_data.size(); r += report_cols.length) { + htmlFile.append("\t\n"); + for (int c = 0; c < report_cols.length; c ++) { + htmlFile.append("\t\t\n"); + } + htmlFile.append ("\t\n"); + } + htmlFile.append("
"); + htmlFile.append (htmlEscape(report_cols[i])); + htmlFile.append("
"); + htmlFile.append(htmlEscape(report_data.get(r+c))); + htmlFile.append("
\n"); + htmlFile.append("\n"); + htmlFile.append(""); + htmlFile.flush(); + htmlFile.close(); + return true; + } catch (IOException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + } + + private static String htmlEscape(Object barestr) { + if (barestr == null) + return ""; + else if (barestr.getClass() == String.class) { + String barestrs = (String)barestr; + String str = barestrs.replace("&", "&").replace("<", "<"). + replace(">", ">").replace("\"", """).replace("\n", "
"); + return str; + } + else + return barestr.toString(); + } + public Utility () {