From: Harishankar Date: Tue, 31 Mar 2020 07:10:18 +0000 (+0530) Subject: Manage Legal Notices - Bill Details X-Git-Url: https://harishankar.org/repos/?p=habeas.git;a=commitdiff_plain;h=d70d1fecd85b5f5b7a6eea4ac59fd8926bb5fe8f Manage Legal Notices - Bill Details Created the screen for updating bill details --- diff --git a/src/habeas/BillDetailsDialog.form b/src/habeas/BillDetailsDialog.form new file mode 100644 index 0000000..c82d47a --- /dev/null +++ b/src/habeas/BillDetailsDialog.form @@ -0,0 +1,143 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/habeas/BillDetailsDialog.java b/src/habeas/BillDetailsDialog.java new file mode 100644 index 0000000..a8eb6d1 --- /dev/null +++ b/src/habeas/BillDetailsDialog.java @@ -0,0 +1,209 @@ +/* + * 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 java.util.Date; +import javax.swing.JOptionPane; + +/** + * + * @author hari + */ +public class BillDetailsDialog extends javax.swing.JDialog { + + private int selected_id; + + /** + * Creates new form BillDetailsDialog + */ + public BillDetailsDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + } + + /** + * 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() { + + jLabel1 = new javax.swing.JLabel(); + comboBillStatus = new javax.swing.JComboBox<>(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + dateBill = new org.jdesktop.swingx.JXDatePicker(); + valBillAmount = new javax.swing.JFormattedTextField(); + buttonApply = new javax.swing.JButton(); + buttonCancel = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Bill Details"); + setLocationByPlatform(true); + + jLabel1.setText("Bill Status"); + + comboBillStatus.setEditable(true); + comboBillStatus.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "PENDING", "RAISED", "AWAITING PAYMENT", "PAID" })); + + jLabel2.setText("Bill Date"); + + jLabel3.setText("Bill Amount"); + + valBillAmount.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance()))); + + buttonApply.setMnemonic('A'); + buttonApply.setText("Apply"); + buttonApply.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonApplyActionPerformed(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) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(comboBillStatus, 0, 301, Short.MAX_VALUE) + .addComponent(dateBill, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(valBillAmount))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(comboBillStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(dateBill, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(valBillAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonApply) + .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 buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed + // TODO add your handling code here: + String bill_status = (String)comboBillStatus.getSelectedItem(); + if (! "PENDING".equals(bill_status) && (dateBill.getDate() == null || + valBillAmount.getValue() == null)) { + JOptionPane.showMessageDialog(this, MANDATORY_FIELDS_MISSING); + return; + } + + boolean rt = Utility.updateNoticeBillDetails (selected_id, bill_status, + dateBill.getDate(), (int)valBillAmount.getValue()); + if (rt == false) + JOptionPane.showMessageDialog(this, ERROR_UPDATING); + else + dispose (); + }//GEN-LAST:event_buttonApplyActionPerformed + private static final String MANDATORY_FIELDS_MISSING = "Mandatory fields missing"; + private static final String ERROR_UPDATING = "Error in 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(BillDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(BillDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(BillDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(BillDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + BillDetailsDialog dialog = new BillDetailsDialog(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 buttonApply; + private javax.swing.JButton buttonCancel; + private javax.swing.JComboBox comboBillStatus; + private org.jdesktop.swingx.JXDatePicker dateBill; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JFormattedTextField valBillAmount; + // End of variables declaration//GEN-END:variables + + void setFields(int selid, String bill_status, int bill_amount, Date bill_date) { + selected_id = selid; + comboBillStatus.setSelectedItem(bill_status); + dateBill.setDate(bill_date); + valBillAmount.setValue(bill_amount); + + } +} diff --git a/src/habeas/ManageNoticesDialog.form b/src/habeas/ManageNoticesDialog.form index db94879..c537409 100644 --- a/src/habeas/ManageNoticesDialog.form +++ b/src/habeas/ManageNoticesDialog.form @@ -10,6 +10,7 @@ + @@ -35,6 +36,15 @@ + + + + + + + + + diff --git a/src/habeas/ManageNoticesDialog.java b/src/habeas/ManageNoticesDialog.java index 60a9125..b1b5c47 100644 --- a/src/habeas/ManageNoticesDialog.java +++ b/src/habeas/ManageNoticesDialog.java @@ -49,9 +49,11 @@ public class ManageNoticesDialog extends javax.swing.JDialog { menuDescription = new javax.swing.JMenuItem(); menuDraftStatus = new javax.swing.JMenuItem(); menuDispatchDetails = new javax.swing.JMenuItem(); + menuBillDetails = new javax.swing.JMenuItem(); jScrollPane1 = new javax.swing.JScrollPane(); tableNotices = new javax.swing.JTable(); + menuDescription.setMnemonic('e'); menuDescription.setText("Description..."); menuDescription.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -79,6 +81,15 @@ public class ManageNoticesDialog extends javax.swing.JDialog { }); popMenu.add(menuDispatchDetails); + menuBillDetails.setMnemonic('B'); + menuBillDetails.setText("Bill Details..."); + menuBillDetails.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + menuBillDetailsActionPerformed(evt); + } + }); + popMenu.add(menuBillDetails); + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Manage Notices"); setLocationByPlatform(true); @@ -164,6 +175,18 @@ public class ManageNoticesDialog extends javax.swing.JDialog { frm.setVisible(true); }//GEN-LAST:event_menuDispatchDetailsActionPerformed + private void menuBillDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuBillDetailsActionPerformed + // TODO add your handling code here: + int selid = getSelectedNotice(); + if (selid == -1) return; + ArrayList notice = Utility.getNoticeDetails(selid); + if (notice == null) return; + + BillDetailsDialog frm = new BillDetailsDialog((Frame) this.getParent(),true); + frm.setFields (selid, (String)notice.get(11), (int)notice.get(12), (Date)notice.get(13)); + frm.setVisible(true); + }//GEN-LAST:event_menuBillDetailsActionPerformed + /** * @param args the command line arguments */ @@ -208,6 +231,7 @@ public class ManageNoticesDialog extends javax.swing.JDialog { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JMenuItem menuBillDetails; private javax.swing.JMenuItem menuDescription; private javax.swing.JMenuItem menuDispatchDetails; private javax.swing.JMenuItem menuDraftStatus; diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java index 4a4042c..2d2caca 100644 --- a/src/habeas/Utility.java +++ b/src/habeas/Utility.java @@ -272,6 +272,26 @@ public class Utility { Date sqldate = new Date (date.getTime()/1000); return sqldate; } + + static boolean updateNoticeBillDetails(int selid, String bill_status, + java.util.Date bill_date, int 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.setInt(4, selid); + st.execute(); + conn.close(); + return true; + } catch (SQLException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + + } public Utility () { }