From 3d2f6cfab3becbf7ad69924e63b91fa7e2745fc7 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Sun, 29 Mar 2020 22:13:18 +0530 Subject: [PATCH 1/1] Initial Commit First Commit. Implemented the Client Master form - add, delete and update. --- src/habeas/ClientMasterDialog.form | 239 +++++++++++++++ src/habeas/ClientMasterDialog.java | 402 +++++++++++++++++++++++++ src/habeas/DatabaseSettingsDialog.form | 105 +++++++ src/habeas/DatabaseSettingsDialog.java | 177 +++++++++++ src/habeas/Habeas.java | 43 +++ src/habeas/MainFrame.form | 77 +++++ src/habeas/MainFrame.java | 137 +++++++++ src/habeas/Utility.java | 152 ++++++++++ 8 files changed, 1332 insertions(+) create mode 100644 src/habeas/ClientMasterDialog.form create mode 100644 src/habeas/ClientMasterDialog.java create mode 100644 src/habeas/DatabaseSettingsDialog.form create mode 100644 src/habeas/DatabaseSettingsDialog.java create mode 100644 src/habeas/Habeas.java create mode 100644 src/habeas/MainFrame.form create mode 100644 src/habeas/MainFrame.java create mode 100644 src/habeas/Utility.java diff --git a/src/habeas/ClientMasterDialog.form b/src/habeas/ClientMasterDialog.form new file mode 100644 index 0000000..e7d0b7c --- /dev/null +++ b/src/habeas/ClientMasterDialog.form @@ -0,0 +1,239 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true"> + <Title/> + <Editor/> + <Renderer/> + </Column> + </TableColumnModel> + </Property> + <Property name="selectionMode" type="int" value="0"/> + <Property name="showGrid" type="boolean" value="true"/> + <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor"> + <TableHeader reorderingAllowed="true" resizingAllowed="true"/> + </Property> + </Properties> + </Component> + </SubComponents> + </Container> + <Component class="javax.swing.JButton" name="buttonAdd"> + <Properties> + <Property name="mnemonic" type="int" value="65"/> + <Property name="text" type="java.lang.String" value="Add"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonAddActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JButton" name="buttonDelete"> + <Properties> + <Property name="mnemonic" type="int" value="68"/> + <Property name="text" type="java.lang.String" value="Delete"/> + <Property name="enabled" type="boolean" value="false"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonDeleteActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JButton" name="buttonUpdate"> + <Properties> + <Property name="mnemonic" type="int" value="85"/> + <Property name="text" type="java.lang.String" value="Update"/> + <Property name="enabled" type="boolean" value="false"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonUpdateActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JLabel" name="jLabel1"> + <Properties> + <Property name="text" type="java.lang.String" value="Client Name"/> + </Properties> + </Component> + <Component class="javax.swing.JTextField" name="textClientName"> + </Component> + <Component class="javax.swing.JLabel" name="jLabel2"> + <Properties> + <Property name="text" type="java.lang.String" value="Client Address"/> + </Properties> + </Component> + <Container class="javax.swing.JScrollPane" name="jScrollPane2"> + <AuxValues> + <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> + </AuxValues> + + <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> + <SubComponents> + <Component class="javax.swing.JTextArea" name="textClientAddress"> + <Properties> + <Property name="columns" type="int" value="20"/> + <Property name="rows" type="int" value="5"/> + </Properties> + </Component> + </SubComponents> + </Container> + <Component class="javax.swing.JLabel" name="jLabel3"> + <Properties> + <Property name="text" type="java.lang.String" value="Contact Person"/> + </Properties> + </Component> + <Component class="javax.swing.JTextField" name="textContactPerson"> + </Component> + <Component class="javax.swing.JLabel" name="jLabel4"> + <Properties> + <Property name="text" type="java.lang.String" value="Phone Number"/> + </Properties> + </Component> + <Component class="javax.swing.JTextField" name="textPhoneNumber"> + </Component> + <Component class="javax.swing.JLabel" name="jLabel5"> + <Properties> + <Property name="text" type="java.lang.String" value="Mail ID"/> + </Properties> + </Component> + <Component class="javax.swing.JTextField" name="textMailID"> + </Component> + <Component class="javax.swing.JButton" name="buttonClose"> + <Properties> + <Property name="mnemonic" type="int" value="67"/> + <Property name="text" type="java.lang.String" value="Close"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonCloseActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JButton" name="buttonClearSelection"> + <Properties> + <Property name="mnemonic" type="int" value="83"/> + <Property name="text" type="java.lang.String" value="Clear Selection"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonClearSelectionActionPerformed"/> + </Events> + </Component> + </SubComponents> +</Form> diff --git a/src/habeas/ClientMasterDialog.java b/src/habeas/ClientMasterDialog.java new file mode 100644 index 0000000..a17d2a1 --- /dev/null +++ b/src/habeas/ClientMasterDialog.java @@ -0,0 +1,402 @@ +/* + * 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.ArrayList; +import javax.swing.JOptionPane; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import javax.swing.plaf.basic.BasicListUI; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; + +/** + * + * @author hari + */ +public class ClientMasterDialog extends javax.swing.JDialog { + + /** + * Creates new form ClientMasterDialog + * @param parent + * @param modal + */ + public ClientMasterDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + populateTable (); + tableClients.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent lse) { + int r = getSelectedClient (); + if (r == -1) { + buttonAdd.setEnabled(true); + buttonUpdate.setEnabled(false); + buttonDelete.setEnabled(false); + return; + } + + ArrayList<Object> clients = Utility.getClientDetails (r); + for (int q = 0; q < clients.size(); q += 5) { + textClientName.setText (clients.get(q).toString()); + textClientAddress.setText(clients.get(q+1).toString()); + textContactPerson.setText(clients.get(q+2).toString()); + textMailID.setText(clients.get(q+3).toString()); + textPhoneNumber.setText(clients.get(q+4).toString()); + } + buttonAdd.setEnabled(false); + buttonUpdate.setEnabled(true); + buttonDelete.setEnabled(true); + } + }); + } + + private int getSelectedClient () { + int i = tableClients.getSelectedRow(); + if (i == -1) + return -1; + + DefaultTableModel mdl = (DefaultTableModel)tableClients.getModel(); + int r = (int)mdl.getValueAt(i, 0); + return r; + } + + private void populateTable () { + DefaultTableModel mdl = (DefaultTableModel)tableClients.getModel(); + mdl.setRowCount(0); + ArrayList<Object> clientsdata = Utility.getClientsNameAndId(); + if (clientsdata == null) return; + for (int i = 0 ; i < clientsdata.size(); i +=2) { + mdl.addRow(new Object[] { + clientsdata.get(i), clientsdata.get(i+1)}); + } + } + + /** + * 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") + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + tableClients = new javax.swing.JTable(); + buttonAdd = new javax.swing.JButton(); + buttonDelete = new javax.swing.JButton(); + buttonUpdate = new javax.swing.JButton(); + jLabel1 = new javax.swing.JLabel(); + textClientName = new javax.swing.JTextField(); + jLabel2 = new javax.swing.JLabel(); + jScrollPane2 = new javax.swing.JScrollPane(); + textClientAddress = new javax.swing.JTextArea(); + jLabel3 = new javax.swing.JLabel(); + textContactPerson = new javax.swing.JTextField(); + jLabel4 = new javax.swing.JLabel(); + textPhoneNumber = new javax.swing.JTextField(); + jLabel5 = new javax.swing.JLabel(); + textMailID = new javax.swing.JTextField(); + buttonClose = new javax.swing.JButton(); + buttonClearSelection = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Clients Master"); + + tableClients.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "id", "Client Name" + } + ) { + Class[] types = new Class [] { + java.lang.Integer.class, java.lang.String.class + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + @Override + public boolean isCellEditable (int row, int col) { + return false; + } + }); + tableClients.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + tableClients.setShowGrid(true); + jScrollPane1.setViewportView(tableClients); + tableClients.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + + buttonAdd.setMnemonic('A'); + buttonAdd.setText("Add"); + buttonAdd.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAddActionPerformed(evt); + } + }); + + buttonDelete.setMnemonic('D'); + buttonDelete.setText("Delete"); + buttonDelete.setEnabled(false); + buttonDelete.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonDeleteActionPerformed(evt); + } + }); + + buttonUpdate.setMnemonic('U'); + buttonUpdate.setText("Update"); + buttonUpdate.setEnabled(false); + buttonUpdate.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonUpdateActionPerformed(evt); + } + }); + + jLabel1.setText("Client Name"); + + jLabel2.setText("Client Address"); + + textClientAddress.setColumns(20); + textClientAddress.setRows(5); + jScrollPane2.setViewportView(textClientAddress); + + jLabel3.setText("Contact Person"); + + jLabel4.setText("Phone Number"); + + jLabel5.setText("Mail ID"); + + buttonClose.setMnemonic('C'); + buttonClose.setText("Close"); + buttonClose.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonCloseActionPerformed(evt); + } + }); + + buttonClearSelection.setMnemonic('S'); + buttonClearSelection.setText("Clear Selection"); + buttonClearSelection.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonClearSelectionActionPerformed(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) + .addComponent(jScrollPane1) + .addGroup(layout.createSequentialGroup() + .addComponent(buttonAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE) + .addComponent(buttonClearSelection) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonClose, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE) + .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(textClientName) + .addComponent(jScrollPane2) + .addComponent(textContactPerson) + .addComponent(textPhoneNumber) + .addComponent(textMailID)))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonAdd) + .addComponent(buttonUpdate) + .addComponent(buttonDelete) + .addComponent(buttonClose) + .addComponent(buttonClearSelection)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(textClientName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(10, 10, 10) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(textContactPerson, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel3)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel4) + .addComponent(textPhoneNumber, 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(jLabel5) + .addComponent(textMailID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + private void buttonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCloseActionPerformed + // TODO add your handling code here: + dispose (); + }//GEN-LAST:event_buttonCloseActionPerformed + + private void buttonClearSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClearSelectionActionPerformed + clearFields(); + }//GEN-LAST:event_buttonClearSelectionActionPerformed + + private void buttonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddActionPerformed + // TODO add your handling code here: + boolean rt = Utility.addClient (textClientName.getText(), textClientAddress.getText(), + textContactPerson.getText(), textMailID.getText(), + textPhoneNumber.getText()); + + if (rt == true) { + JOptionPane.showMessageDialog(this, SUCCESSFULLY_ADDED); + clearFields(); + populateTable(); + } + else + JOptionPane.showMessageDialog (this, ERROR_IN_ADDING); + }//GEN-LAST:event_buttonAddActionPerformed + private static final String SUCCESSFULLY_ADDED = "Successfully added"; + private static final String ERROR_IN_ADDING = "Error in adding"; + + private void buttonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDeleteActionPerformed + // TODO add your handling code here: + int r = getSelectedClient(); + if (r == -1) return; + int conf = JOptionPane.showConfirmDialog(this, CONFIRM_DELETE_CLIENT); + if (conf == JOptionPane.YES_OPTION) { + boolean rt = Utility.deleteClient (r); + if (rt == true) { + JOptionPane.showMessageDialog(this, SUCCESSFULLY_DELETED); + clearFields(); + populateTable(); + } + else + JOptionPane.showMessageDialog(this, ERROR_IN_DELETING); + } + }//GEN-LAST:event_buttonDeleteActionPerformed + private static final String ERROR_IN_DELETING = "Error in deleting"; + + private void buttonUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUpdateActionPerformed + // TODO add your handling code here: + int r = getSelectedClient(); + if (r == -1 ) return; + boolean rt = Utility.updateClient (r, textClientName.getText(), + textClientAddress.getText(), textContactPerson.getText(), + textMailID.getText(), textPhoneNumber.getText()); + if (rt == true) { + JOptionPane.showMessageDialog(this, SUCCESSFULLY_UPDATED); + clearFields(); + populateTable(); + } else { + JOptionPane.showMessageDialog(this, ERROR_IN_UPDATING); + } + + }//GEN-LAST:event_buttonUpdateActionPerformed + private static final String ERROR_IN_UPDATING = "Error in updating"; + private static final String SUCCESSFULLY_UPDATED = "Successfully updated"; + private static final String SUCCESSFULLY_DELETED = "Successfully deleted"; + private static final String CONFIRM_DELETE_CLIENT = "Are you sure? This will" + + " also delete all other data associated with this client"; + + private void clearFields() { + // TODO add your handling code here: + tableClients.clearSelection(); + textClientAddress.setText (""); + textClientName.setText (""); + textContactPerson.setText(""); + textMailID.setText(""); + textPhoneNumber.setText(""); + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> + /* 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(ClientMasterDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(ClientMasterDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(ClientMasterDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(ClientMasterDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + //</editor-fold> + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + ClientMasterDialog dialog = new ClientMasterDialog(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 buttonAdd; + private javax.swing.JButton buttonClearSelection; + private javax.swing.JButton buttonClose; + private javax.swing.JButton buttonDelete; + private javax.swing.JButton buttonUpdate; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTable tableClients; + private javax.swing.JTextArea textClientAddress; + private javax.swing.JTextField textClientName; + private javax.swing.JTextField textContactPerson; + private javax.swing.JTextField textMailID; + private javax.swing.JTextField textPhoneNumber; + // End of variables declaration//GEN-END:variables +} diff --git a/src/habeas/DatabaseSettingsDialog.form b/src/habeas/DatabaseSettingsDialog.form new file mode 100644 index 0000000..a9ebf5e --- /dev/null +++ b/src/habeas/DatabaseSettingsDialog.form @@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo"> + <Properties> + <Property name="defaultCloseOperation" type="int" value="2"/> + <Property name="title" type="java.lang.String" value="Connection"/> + <Property name="locationByPlatform" type="boolean" value="true"/> + <Property name="resizable" type="boolean" value="false"/> + </Properties> + <SyntheticProperties> + <SyntheticProperty name="formSizePolicy" type="int" value="1"/> + <SyntheticProperty name="generateCenter" type="boolean" value="false"/> + </SyntheticProperties> + <AuxValues> + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + </AuxValues> + + <Layout> + <DimensionLayout dim="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <EmptySpace max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <Component id="jLabel1" min="-2" pref="139" max="-2" attributes="0"/> + <EmptySpace min="0" pref="0" max="32767" attributes="0"/> + </Group> + <Group type="102" alignment="0" attributes="0"> + <Group type="103" groupAlignment="1" attributes="0"> + <Component id="txtDatabaseURL" min="-2" pref="231" max="-2" attributes="0"/> + <Component id="buttonApply" min="-2" pref="92" max="-2" attributes="0"/> + </Group> + <EmptySpace max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="buttonClose" max="32767" attributes="0"/> + <Component id="buttonChooseFile" pref="93" max="32767" attributes="0"/> + </Group> + </Group> + </Group> + <EmptySpace max="-2" attributes="0"/> + </Group> + </Group> + </DimensionLayout> + <DimensionLayout dim="1"> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace max="-2" attributes="0"/> + <Component id="jLabel1" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="txtDatabaseURL" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="buttonChooseFile" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace pref="29" max="32767" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="buttonClose" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="buttonApply" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace max="-2" attributes="0"/> + </Group> + </Group> + </DimensionLayout> + </Layout> + <SubComponents> + <Component class="javax.swing.JLabel" name="jLabel1"> + <Properties> + <Property name="text" type="java.lang.String" value="Path to Database"/> + </Properties> + </Component> + <Component class="javax.swing.JTextField" name="txtDatabaseURL"> + </Component> + <Component class="javax.swing.JButton" name="buttonChooseFile"> + <Properties> + <Property name="text" type="java.lang.String" value="Choose..."/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonChooseFileActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JButton" name="buttonClose"> + <Properties> + <Property name="text" type="java.lang.String" value="Close"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonCloseActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JButton" name="buttonApply"> + <Properties> + <Property name="text" type="java.lang.String" value="Apply"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonApplyActionPerformed"/> + </Events> + </Component> + </SubComponents> +</Form> diff --git a/src/habeas/DatabaseSettingsDialog.java b/src/habeas/DatabaseSettingsDialog.java new file mode 100644 index 0000000..5a9ce9b --- /dev/null +++ b/src/habeas/DatabaseSettingsDialog.java @@ -0,0 +1,177 @@ +/* + * 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.prefs.Preferences; +import javax.swing.JFileChooser; + +/** + * + * @author hari + */ +public class DatabaseSettingsDialog extends javax.swing.JDialog { + + /** + * Creates new form DatabaseSettings + */ + public DatabaseSettingsDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + txtDatabaseURL.setText(Utility.connectionURL); + } + + /** + * 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") + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + txtDatabaseURL = new javax.swing.JTextField(); + buttonChooseFile = new javax.swing.JButton(); + buttonClose = new javax.swing.JButton(); + buttonApply = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Connection"); + setLocationByPlatform(true); + setResizable(false); + + jLabel1.setText("Path to Database"); + + buttonChooseFile.setText("Choose..."); + buttonChooseFile.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonChooseFileActionPerformed(evt); + } + }); + + buttonClose.setText("Close"); + buttonClose.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonCloseActionPerformed(evt); + } + }); + + buttonApply.setText("Apply"); + buttonApply.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonApplyActionPerformed(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() + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(txtDatabaseURL, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(buttonClose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonChooseFile, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(txtDatabaseURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonChooseFile)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonClose) + .addComponent(buttonApply)) + .addContainerGap()) + ); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed + // TODO add your handling code here + Utility.setConnectionURL (txtDatabaseURL.getText()); + }//GEN-LAST:event_buttonApplyActionPerformed + + private void buttonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCloseActionPerformed + // TODO add your handling code here: + dispose(); + }//GEN-LAST:event_buttonCloseActionPerformed + + private void buttonChooseFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonChooseFileActionPerformed + // TODO add your handling code here: + JFileChooser chooser = new JFileChooser (); + int i = chooser.showOpenDialog(this); + if (i == JFileChooser.APPROVE_OPTION) { + txtDatabaseURL.setText(chooser.getSelectedFile().getAbsolutePath()); + } + }//GEN-LAST:event_buttonChooseFileActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> + /* 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(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(DatabaseSettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + //</editor-fold> + //</editor-fold> + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + DatabaseSettingsDialog dialog = new DatabaseSettingsDialog(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 buttonChooseFile; + private javax.swing.JButton buttonClose; + private javax.swing.JLabel jLabel1; + private javax.swing.JTextField txtDatabaseURL; + // End of variables declaration//GEN-END:variables +} diff --git a/src/habeas/Habeas.java b/src/habeas/Habeas.java new file mode 100644 index 0000000..5932034 --- /dev/null +++ b/src/habeas/Habeas.java @@ -0,0 +1,43 @@ +/* + * 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.sql.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; + +/** + * + * @author hari + */ +public class Habeas { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + Utility.getConnectionURL(); + + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException ex) { + Logger.getLogger(Habeas.class.getName()).log(Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + Logger.getLogger(Habeas.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(Habeas.class.getName()).log(Level.SEVERE, null, ex); + } catch (UnsupportedLookAndFeelException ex) { + Logger.getLogger(Habeas.class.getName()).log(Level.SEVERE, null, ex); + } + + MainFrame frame = new MainFrame (); + frame.setVisible(true); + } + +} diff --git a/src/habeas/MainFrame.form b/src/habeas/MainFrame.form new file mode 100644 index 0000000..ee56f86 --- /dev/null +++ b/src/habeas/MainFrame.form @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> + <NonVisualComponents> + <Menu class="javax.swing.JMenuBar" name="jMenuBar1"> + <SubComponents> + <Menu class="javax.swing.JMenu" name="menuMaster"> + <Properties> + <Property name="mnemonic" type="int" value="77"/> + <Property name="text" type="java.lang.String" value="Master"/> + </Properties> + <SubComponents> + <MenuItem class="javax.swing.JMenuItem" name="menuClientMaster"> + <Properties> + <Property name="text" type="java.lang.String" value="Client Master..."/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuClientMasterActionPerformed"/> + </Events> + </MenuItem> + </SubComponents> + </Menu> + <Menu class="javax.swing.JMenu" name="menuSettings"> + <Properties> + <Property name="mnemonic" type="int" value="83"/> + <Property name="text" type="java.lang.String" value="Settings"/> + </Properties> + <SubComponents> + <MenuItem class="javax.swing.JMenuItem" name="menuDatabaseSettings"> + <Properties> + <Property name="mnemonic" type="int" value="68"/> + <Property name="text" type="java.lang.String" value="Database..."/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuDatabaseSettingsActionPerformed"/> + </Events> + </MenuItem> + </SubComponents> + </Menu> + </SubComponents> + </Menu> + </NonVisualComponents> + <Properties> + <Property name="defaultCloseOperation" type="int" value="3"/> + <Property name="title" type="java.lang.String" value="Habeas - Law Office Manager"/> + <Property name="locationByPlatform" type="boolean" value="true"/> + </Properties> + <SyntheticProperties> + <SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/> + <SyntheticProperty name="formSizePolicy" type="int" value="1"/> + <SyntheticProperty name="generateCenter" type="boolean" value="false"/> + </SyntheticProperties> + <AuxValues> + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + </AuxValues> + + <Layout> + <DimensionLayout dim="0"> + <Group type="103" groupAlignment="0" attributes="0"> + <EmptySpace min="0" pref="586" max="32767" attributes="0"/> + </Group> + </DimensionLayout> + <DimensionLayout dim="1"> + <Group type="103" groupAlignment="0" attributes="0"> + <EmptySpace min="0" pref="292" max="32767" attributes="0"/> + </Group> + </DimensionLayout> + </Layout> +</Form> diff --git a/src/habeas/MainFrame.java b/src/habeas/MainFrame.java new file mode 100644 index 0000000..28477ad --- /dev/null +++ b/src/habeas/MainFrame.java @@ -0,0 +1,137 @@ +/* + * 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; + +/** + * + * @author hari + */ +public class MainFrame extends javax.swing.JFrame { + + /** + * Creates new form MainFrame + */ + public MainFrame() { + 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") + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + jMenuBar1 = new javax.swing.JMenuBar(); + menuMaster = new javax.swing.JMenu(); + menuClientMaster = new javax.swing.JMenuItem(); + menuSettings = new javax.swing.JMenu(); + menuDatabaseSettings = new javax.swing.JMenuItem(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Habeas - Law Office Manager"); + setLocationByPlatform(true); + + menuMaster.setMnemonic('M'); + menuMaster.setText("Master"); + + menuClientMaster.setText("Client Master..."); + menuClientMaster.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + menuClientMasterActionPerformed(evt); + } + }); + menuMaster.add(menuClientMaster); + + jMenuBar1.add(menuMaster); + + menuSettings.setMnemonic('S'); + menuSettings.setText("Settings"); + + menuDatabaseSettings.setMnemonic('D'); + menuDatabaseSettings.setText("Database..."); + menuDatabaseSettings.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + menuDatabaseSettingsActionPerformed(evt); + } + }); + menuSettings.add(menuDatabaseSettings); + + jMenuBar1.add(menuSettings); + + setJMenuBar(jMenuBar1); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 586, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 292, Short.MAX_VALUE) + ); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + private void menuDatabaseSettingsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDatabaseSettingsActionPerformed + // TODO add your handling code here: + DatabaseSettingsDialog frm = new DatabaseSettingsDialog (this, true); + frm.setVisible(true); + }//GEN-LAST:event_menuDatabaseSettingsActionPerformed + + private void menuClientMasterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuClientMasterActionPerformed + // TODO add your handling code here: + ClientMasterDialog frm = new ClientMasterDialog (this, true); + frm.setVisible(true); + }//GEN-LAST:event_menuClientMasterActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> + /* 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(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + //</editor-fold> + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new MainFrame().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JMenuBar jMenuBar1; + private javax.swing.JMenuItem menuClientMaster; + private javax.swing.JMenuItem menuDatabaseSettings; + private javax.swing.JMenu menuMaster; + private javax.swing.JMenu menuSettings; + // End of variables declaration//GEN-END:variables +} diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java new file mode 100644 index 0000000..3eabd87 --- /dev/null +++ b/src/habeas/Utility.java @@ -0,0 +1,152 @@ +/* + * 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.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; + +/** + * + * @author hari + */ +public class Utility { + + static void setConnectionURL(String text) { + connectionURL = text; + Preferences.userRoot().put("ConnectionURL", text); + } + + static ArrayList<Object> getClientDetails(int r) { + ArrayList<Object> res = new ArrayList <>(); + try { + Connection conn = DriverManager.getConnection("jdbc:sqlite:"+connectionURL); + PreparedStatement st = conn.prepareStatement("SELECT * FROM clients WHERE id=?;"); + st.setInt(1, r); + ResultSet rs = st.executeQuery(); + while (rs.next()) { + res.add (rs.getString("ClientName")); + res.add(rs.getString("ClientAddress")); + res.add (rs.getString("ContactPerson")); + res.add (rs.getString("MailID")); + res.add (rs.getString("ContactNumber")); + } + conn.close (); + return res; + + } catch (SQLException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return null; + } + + } + + static boolean addClient(String client_name, String client_address, + String contact_person, String email_id, String phone_number) { + if ("".equals(client_name)) + return false; + try { + Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + PreparedStatement st = conn.prepareStatement("INSERT INTO clients (ClientName," + + "ClientAddress, ContactPerson, MailID, ContactNumber) VALUES (?, ?, ?, ?, ?);"); + st.setString(1, client_name); + st.setString(2, client_address); + st.setString(3, contact_person); + st.setString (4, email_id); + st.setString (5, phone_number); + st.execute(); + conn.close(); + return true; + + } catch (SQLException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + + + } + + static boolean deleteClient(int r) { + try { + Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + PreparedStatement st = conn.prepareStatement("DELETE FROM clients WHERE id=?;"); + PreparedStatement st2 = conn.prepareStatement("DELETE FROM legalnotices WHERE ClientId=?;"); + st.setInt(1, r); + st2.setInt (1, r); + st.execute(); + st2.execute(); + conn.close(); + return true; + } catch (SQLException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + + } + + static boolean updateClient(int r, String client_name, String client_address, + String contact_person, String mail_id, String phone_number) { + if ("".equals(client_name)) + return false; + try { + Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + PreparedStatement st = conn.prepareStatement("UPDATE clients SET " + + "ClientName=?, ClientAddress=?," + + "ContactPerson=?, MailID=?, ContactNumber=? WHERE id=?;"); + st.setString(1, client_name); + st.setString(2, client_address); + st.setString(3, contact_person); + st.setString(4, mail_id); + st.setString(5, phone_number); + st.setInt (6, r); + st.execute(); + conn.close(); + return true; + } catch (SQLException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + + + } + public Utility () { + + } + public static String connectionURL ; + + /** + * + * @return + */ + public static ArrayList<Object> getClientsNameAndId () { + ArrayList<Object> data = new ArrayList<>(); + try { + Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + Statement st = conn.createStatement(); + ResultSet rs = st.executeQuery("SELECT id, ClientName from clients;"); + while (rs.next()) { + data.add(rs.getInt("id")); + data.add(rs.getString("ClientName")); + } + conn.close(); + return data; + } catch (SQLException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return null; + } + + } + + public static void getConnectionURL () { + connectionURL = Preferences.userRoot().get("ConnectionURL", "legaldb"); + } + +} -- 2.20.1