From 988965ad5c97f63eeb48b8e44a82cccb032bf591 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Mon, 30 Mar 2020 18:01:27 +0530 Subject: [PATCH] Manage Legal Notices - Draft Status Created the screen for updating draft status --- src/habeas/DraftStatusDialog.form | 92 +++++++++++++++ src/habeas/DraftStatusDialog.java | 173 ++++++++++++++++++++++++++++ src/habeas/ManageNoticesDialog.java | 12 +- src/habeas/Utility.java | 77 +++++++++++-- 4 files changed, 343 insertions(+), 11 deletions(-) create mode 100644 src/habeas/DraftStatusDialog.form create mode 100644 src/habeas/DraftStatusDialog.java diff --git a/src/habeas/DraftStatusDialog.form b/src/habeas/DraftStatusDialog.form new file mode 100644 index 0000000..cd6f65f --- /dev/null +++ b/src/habeas/DraftStatusDialog.form @@ -0,0 +1,92 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/habeas/DraftStatusDialog.java b/src/habeas/DraftStatusDialog.java new file mode 100644 index 0000000..0154d47 --- /dev/null +++ b/src/habeas/DraftStatusDialog.java @@ -0,0 +1,173 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package habeas; + +import javax.swing.JOptionPane; + +/** + * + * @author hari + */ +public class DraftStatusDialog extends javax.swing.JDialog { + + private int selectednotice_id; + + /** + * Creates new form DraftStatusDialog + */ + + public DraftStatusDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + } + + public void setDraftStatus (boolean created, boolean approved) { + checkDraftCreated.setSelected(created); + checkDraftApproved.setSelected(approved); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + checkDraftCreated = new javax.swing.JCheckBox(); + checkDraftApproved = new javax.swing.JCheckBox(); + buttonUpdate = new javax.swing.JButton(); + buttonCancel = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Draft Status"); + setLocationByPlatform(true); + + checkDraftCreated.setText("Draft Created"); + + checkDraftApproved.setText("Draft Approved"); + + buttonUpdate.setMnemonic('U'); + buttonUpdate.setText("Update"); + buttonUpdate.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonUpdateActionPerformed(evt); + } + }); + + buttonCancel.setMnemonic('c'); + buttonCancel.setText("Cancel"); + buttonCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonCancelActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(checkDraftCreated, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(checkDraftApproved, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(195, Short.MAX_VALUE) + .addComponent(buttonUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(checkDraftCreated) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(checkDraftApproved) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonUpdate) + .addComponent(buttonCancel)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed + // TODO add your handling code here: + dispose (); + }//GEN-LAST:event_buttonCancelActionPerformed + + private void buttonUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUpdateActionPerformed + // TODO add your handling code here: + boolean rt = Utility.updateLegalNoticeDraftStatus (selectednotice_id, + checkDraftCreated.isSelected(), checkDraftApproved.isSelected()); + + if (rt == false) + JOptionPane.showMessageDialog(this, ERROR_UPDATING); + else + dispose (); + }//GEN-LAST:event_buttonUpdateActionPerformed + private static final String ERROR_UPDATING = "Error updating"; + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(DraftStatusDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(DraftStatusDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(DraftStatusDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(DraftStatusDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + DraftStatusDialog dialog = new DraftStatusDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonCancel; + private javax.swing.JButton buttonUpdate; + private javax.swing.JCheckBox checkDraftApproved; + private javax.swing.JCheckBox checkDraftCreated; + // End of variables declaration//GEN-END:variables + + void setSelectedNotice(int selid) { + selectednotice_id = selid; + } +} diff --git a/src/habeas/ManageNoticesDialog.java b/src/habeas/ManageNoticesDialog.java index c23923e..611f02d 100644 --- a/src/habeas/ManageNoticesDialog.java +++ b/src/habeas/ManageNoticesDialog.java @@ -5,12 +5,10 @@ */ package habeas; +import java.awt.Frame; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.util.ArrayList; -import javax.swing.JMenuItem; -import javax.swing.JPopupMenu; import javax.swing.table.DefaultTableModel; /** @@ -112,7 +110,13 @@ public class ManageNoticesDialog extends javax.swing.JDialog { int selid = getSelectedNotice (); if (selid == -1) return; - System.out.println (selid); + DraftStatusDialog frm = new DraftStatusDialog((Frame) this.getParent(), true); + ArrayList notice = Utility.getNoticeDetails (selid); + if (notice == null) return; + + frm.setDraftStatus((boolean)notice.get(4), (boolean)notice.get(5)); + frm.setSelectedNotice (selid); + frm.setVisible(true); }//GEN-LAST:event_menuDraftStatusActionPerformed diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java index a1148a2..dd83144 100644 --- a/src/habeas/Utility.java +++ b/src/habeas/Utility.java @@ -25,7 +25,7 @@ public class Utility { static ArrayList getClientDetails(int r) { ArrayList res = new ArrayList <>(); try { - Connection conn = DriverManager.getConnection("jdbc:sqlite:"+connectionURL); + Connection conn = DriverManager.getConnection(JDBC+connectionURL); PreparedStatement st = conn.prepareStatement("SELECT * FROM clients WHERE id=?;"); st.setInt(1, r); ResultSet rs = st.executeQuery(); @@ -51,7 +51,7 @@ public class Utility { if ("".equals(client_name)) return false; try { - Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + Connection conn = DriverManager.getConnection(JDBC + connectionURL); PreparedStatement st = conn.prepareStatement("INSERT INTO clients (ClientName," + "ClientAddress, ContactPerson, MailID, ContactNumber) VALUES (?, ?, ?, ?, ?);"); st.setString(1, client_name); @@ -73,7 +73,7 @@ public class Utility { static boolean deleteClient(int r) { try { - Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + Connection conn = DriverManager.getConnection(JDBC + connectionURL); PreparedStatement st = conn.prepareStatement("DELETE FROM clients WHERE id=?;"); PreparedStatement st2 = conn.prepareStatement("DELETE FROM legalnotices WHERE ClientId=?;"); st.setInt(1, r); @@ -94,7 +94,7 @@ public class Utility { if ("".equals(client_name)) return false; try { - Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + Connection conn = DriverManager.getConnection(JDBC + connectionURL); PreparedStatement st = conn.prepareStatement("UPDATE clients SET " + "ClientName=?, ClientAddress=?," + "ContactPerson=?, MailID=?, ContactNumber=? WHERE id=?;"); @@ -121,7 +121,7 @@ public class Utility { entrustment_date == null || client == null) return false; try { - Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + Connection conn = DriverManager.getConnection(JDBC + connectionURL); PreparedStatement st = conn.prepareStatement("INSERT INTO legalnotices" + " (ReferenceNumber, Description, EntrustmentDate, ClientId) " + "VALUES (?, ?, ?, ?);"); @@ -143,7 +143,7 @@ public class Utility { static ArrayList getNotices() { ArrayList notices = new ArrayList<>(); try { - Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + Connection conn = DriverManager.getConnection(JDBC + connectionURL); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT id, ReferenceNumber, Description " + "FROM legalnotices;"); @@ -159,6 +159,69 @@ public class Utility { return null; } + } + static java.util.Date getValidDate (ResultSet rs, String datefield) throws SQLException { + // Since resultset.getDate returns a java.sql.Date, we need a way to get + // the date in java.util.Date which is usable in our application. Hence + // this helper function. Since we don't want a valid Date object if the + // field is null, we are using this if clause + if (rs.getDate(datefield) == null) + return null; + else + return (new java.util.Date(rs.getLong(datefield)*1000)); + } + + static ArrayList getNoticeDetails(int selid) { + ArrayList notice = new ArrayList<>(); + try { + Connection conn = DriverManager.getConnection(JDBC + connectionURL); + PreparedStatement st = conn.prepareStatement("SELECT * FROM legalnotices WHERE id=?;"); + st.setInt(1, selid); + ResultSet rs = st.executeQuery(); + while (rs.next()) { + notice.add(rs.getString("ReferenceNumber")); + notice.add(rs.getString("Description")); + notice.add(getValidDate(rs, "EntrustmentDate")); + notice.add (rs.getInt ("ClientId")); + notice.add (rs.getBoolean("DraftCreated")); + notice.add (rs.getBoolean("DraftApproved")); + notice.add (rs.getBoolean("NoticeSent")); + notice.add (getValidDate(rs, "SentDate")); + notice.add (rs.getString("RPADReference")); + notice.add (rs.getBoolean("NoticeDelivered")); + notice.add (getValidDate(rs, "DeliveryDate")); + notice.add (rs.getString("BillStatus")); + notice.add (rs.getInt ("BillAmount")); + notice.add (getValidDate (rs, "BillDate")); + notice.add (rs.getBoolean ("ClarificationPending")); + notice.add (rs.getString("ClarificationRemarks")); + } + return notice; + } catch (SQLException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return null; + } + + + } + private static final String JDBC = "jdbc:sqlite:"; + + static boolean updateLegalNoticeDraftStatus(int selectednotice_id, boolean created, boolean approved) { + try { + Connection conn = DriverManager.getConnection(JDBC + connectionURL); + PreparedStatement st = conn.prepareStatement("UPDATE legalnotices " + + "SET DraftCreated=?, DraftApproved=? WHERE id=?;"); + st.setBoolean(1, created); + st.setBoolean(2, approved); + st.setInt (3, selectednotice_id); + st.execute(); + conn.close(); + return true; + } catch (SQLException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + } public Utility () { @@ -172,7 +235,7 @@ public class Utility { public static ArrayList getClientsNameAndId () { ArrayList data = new ArrayList<>(); try { - Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + Connection conn = DriverManager.getConnection(JDBC + connectionURL); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT id, ClientName from clients;"); while (rs.next()) { -- 2.20.1