Skip to content

Commit

Permalink
Add excel export
Browse files Browse the repository at this point in the history
Added Excel export option
Refactored code
Changed default operation for database creation
  • Loading branch information
shreyask21 committed Apr 15, 2020
1 parent 88c5532 commit 37c6231
Show file tree
Hide file tree
Showing 18 changed files with 931 additions and 169 deletions.
8 changes: 7 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/mysql-connector-java-8.0.19.jar"/>
<classpathentry kind="lib" path="lib/myqsl_connector/mysql-connector-java-8.0.19.jar"/>
<classpathentry kind="lib" path="lib/apache_poi/poi-4.1.2.jar"/>
<classpathentry kind="lib" path="lib/apache_poi/poi-ooxml-4.1.2.jar"/>
<classpathentry kind="lib" path="lib/apache_poi/commons-collections4-4.4.jar"/>
<classpathentry kind="lib" path="lib/apache_poi/xmlbeans-3.1.0.jar"/>
<classpathentry kind="lib" path="lib/apache_poi/commons-compress-1.20.jar"/>
<classpathentry kind="lib" path="lib/apache_poi/poi-ooxml-schemas-4.1.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file modified bin/db_driver/assetdb.class
Binary file not shown.
Binary file modified export/asset_management.jar
Binary file not shown.
537 changes: 537 additions & 0 deletions lib/apache_poi/LICENSE

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
23 changes: 17 additions & 6 deletions src/GUI/about.java → src/GUI/About_Dialog.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package GUI;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

public class about extends JDialog {
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;

public class About_Dialog extends JDialog {
private static final long serialVersionUID = 5381052862136001506L;

public about() {
public About_Dialog() {
setModal(true);
setResizable(false);
setTitle("About Project");
Expand All @@ -19,7 +29,7 @@ public about() {
int y = (int) ((dimension.getHeight() - getHeight()) / 2);
setBounds(x, y, 516, 600);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
getContentPane().setLayout(null);
JLabel L = new JLabel(new ImageIcon(this.getClass().getClassLoader().getResource("about.png")));
Expand All @@ -32,6 +42,7 @@ public about() {
gitbtn.setBounds(208, 511, 100, 40);
getContentPane().add(gitbtn);
gitbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
Expand Down
71 changes: 39 additions & 32 deletions src/GUI/createdb_dialog.java → src/GUI/Createdb_Dialog.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
package GUI;

import db_driver.assetdb;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.ButtonGroup;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;

import db_driver.Assetdb;

/*Shows the database creation option dialog*/
public class createdb_dialog extends JDialog implements ActionListener {
public class Createdb_Dialog extends JDialog implements ActionListener {

private static final long serialVersionUID = 718615945910521098L;
private boolean action = false; // Default: existing database
private final JPanel contentPanel = new JPanel();
private JTextField tbox_dbname;
private JTextField tbox_tablename;
private boolean action = true; // Default: create new database
private String username, password;

/* Generates layout */
public createdb_dialog() {
assetdb db = new assetdb();
public Createdb_Dialog() {
Assetdb db = new Assetdb();
/* Create layout */
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
this.setModal(true);
this.setTitle("Choose What To Do...");
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
setModal(true);
setAlwaysOnTop(true);
setTitle("Choose What To Do...");
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - getWidth()) / 2);
int y = (int) ((dimension.getHeight() - getHeight()) / 2);
Expand All @@ -52,18 +56,18 @@ public createdb_dialog() {
radio_newdb.setBounds(35, 20, 153, 21);
contentPanel.add(radio_newdb);
radio_newdb.setActionCommand("new");
radio_newdb.setSelected(true);

JRadioButton radio_olddb = new JRadioButton("Use Existing database");
radio_olddb.setFont(new Font("Tahoma", Font.PLAIN, 13));
radio_olddb.setBounds(210, 20, 168, 21);
contentPanel.add(radio_olddb);
radio_olddb.setActionCommand("old");
radio_olddb.setSelected(true);

/* Group radio buttons so only one can be pushed */
ButtonGroup group = new ButtonGroup();
group.add(radio_newdb);
group.add(radio_olddb);
group.add(radio_newdb);

/* Add action listeners to both radio buttons. Calls actionPerformed() */
radio_newdb.addActionListener(this);
Expand Down Expand Up @@ -101,6 +105,7 @@ public createdb_dialog() {
exitbtn.setBounds(135, 193, 130, 25);
contentPanel.add(exitbtn);
exitbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
System.exit(0);
Expand All @@ -112,21 +117,22 @@ public void actionPerformed(ActionEvent e) {
okbtn.setBounds(135, 158, 130, 25);
contentPanel.add(okbtn);
okbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (action) {
if (!db.checkDBexisting(createdb_dialog.this.username, createdb_dialog.this.password, getDBName(),
if (!db.checkDBexisting(Createdb_Dialog.this.username, Createdb_Dialog.this.password, getDBName(),
getTableName())) {
dispose();
} else {
JOptionPane.showMessageDialog(createdb_dialog.this, "Database already exists", "Error",
JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(Createdb_Dialog.this, "Database and table already exists",
"Error", JOptionPane.ERROR_MESSAGE);
}
} else {
if (db.checkDBexisting(createdb_dialog.this.username, createdb_dialog.this.password, getDBName(),
if (db.checkDBexisting(Createdb_Dialog.this.username, Createdb_Dialog.this.password, getDBName(),
getTableName())) {
dispose();
} else {
JOptionPane.showMessageDialog(createdb_dialog.this, "Invalid database or table", "Error",
JOptionPane.showMessageDialog(Createdb_Dialog.this, "Invalid database or table", "Error",
JOptionPane.ERROR_MESSAGE);
}
}
Expand All @@ -136,6 +142,7 @@ public void actionPerformed(ActionEvent e) {
}

/* Setter for radio buttons */
@Override
public void actionPerformed(ActionEvent e) {
if ("new".equals(e.getActionCommand())) {
this.action = true;
Expand All @@ -145,13 +152,6 @@ public void actionPerformed(ActionEvent e) {

}

/* Displays the GUI to user */
public void showDialog(String usrn, String psw) {
this.username = usrn;
this.password = psw;
this.setVisible(true);
}

/* Returns the action type. true-> new database, false -> existing */
public boolean getAction() {
return action;
Expand All @@ -165,4 +165,11 @@ public String getDBName() {
public String getTableName() {
return tbox_tablename.getText().trim();
}

/* Displays the GUI to user */
public void showDialog(String usrn, String psw) {
this.username = usrn;
this.password = psw;
this.setVisible(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.ResultSet;

import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.WindowConstants;

public class display_dialog extends JDialog {
public class Display_Table_Dialog extends JDialog {
private static final long serialVersionUID = 70344042872926412L;
private String[] columnNames = { "Sr.", "Asset ID", "Purchase Date", "Asset Type", "Asset Price", "Asset Status" };
private String[][] rows;
Expand All @@ -17,7 +19,7 @@ public void display_table(ResultSet rs, int RowCount) {
this.storeData(rs);
this.setTitle("Asset Database Entries");
this.setModalityType(ModalityType.APPLICATION_MODAL);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
this.setAlwaysOnTop(false);
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
Expand All @@ -27,14 +29,15 @@ public void display_table(ResultSet rs, int RowCount) {
this.setLocation(x, y);
this.setLocationRelativeTo(null);
this.getContentPane().setLayout(null);

JTable table = new JTable(this.rows, this.columnNames);
table.setBounds(30, 40, 200, 300);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(10, 11, 564, 339);
this.getContentPane().add(scrollPane);
this.setVisible(true);
}

private void storeData(ResultSet rs) {
int currentRowIndex = 0;
try {
Expand All @@ -49,7 +52,7 @@ private void storeData(ResultSet rs) {
}
} catch (Exception e) {
e.printStackTrace();
error_dialog.showError(e.getMessage());
Error_Dialog.showError(e.getMessage());
}
}
}
24 changes: 24 additions & 0 deletions src/GUI/Error_Dialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package GUI;

import java.io.PrintWriter;
import java.io.StringWriter;

import javax.swing.JOptionPane;

public class Error_Dialog {
public static void showError(Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
JOptionPane.showMessageDialog(null, "The Stack Trace:\n" + sw.toString(), "Something went wrong :(",
JOptionPane.ERROR_MESSAGE);
System.exit(0);
}

public static void showError(String error) {
JOptionPane.showMessageDialog(null, error, "Something went wrong :(", JOptionPane.ERROR_MESSAGE);
}

public static void showInfo(String info) {
JOptionPane.showMessageDialog(null, info, "Information", JOptionPane.INFORMATION_MESSAGE);
}
}
49 changes: 27 additions & 22 deletions src/GUI/login_dialog.java → src/GUI/Login_Dialog.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
package GUI;

import db_driver.assetdb;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.WindowConstants;

import db_driver.Assetdb;

/*Shows the login dialog*/
public class login_dialog extends JDialog {
public class Login_Dialog extends JDialog {

private static final long serialVersionUID = 1L;
private JTextField textbox_username;
private JPasswordField textbox_password;
private JLabel lblNewLabel;
private JLabel lblNewLabel_1;
private JLabel lblNewLabel_2;
private JPasswordField textbox_password;
private JTextField textbox_username;

/* Generates layout */
public login_dialog() {
public Login_Dialog() {
/* Create layout */
setModalityType(ModalityType.APPLICATION_MODAL);
setResizable(false);
setTitle("Please Login");
setAlwaysOnTop(false);
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
assetdb db = new assetdb();
setAlwaysOnTop(true);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
Assetdb db = new Assetdb();
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - getWidth()) / 2);
int y = (int) ((dimension.getHeight() - getHeight()) / 2);
Expand All @@ -57,9 +60,10 @@ public login_dialog() {
submitbtn.setMnemonic(KeyEvent.VK_ENTER);
getContentPane().add(submitbtn);
submitbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!db.checkCreds(getUsername(), getPassword())) {
JOptionPane.showMessageDialog(login_dialog.this, "Invalid username or password", "Login",
JOptionPane.showMessageDialog(Login_Dialog.this, "Invalid username or password", "Login",
JOptionPane.ERROR_MESSAGE);
} else {
dispose();
Expand All @@ -84,6 +88,7 @@ public void actionPerformed(ActionEvent e) {
JButton exitbtn = new JButton("EXIT");
exitbtn.setForeground(new Color(255, 0, 0));
exitbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
System.exit(ABORT);
Expand All @@ -94,14 +99,14 @@ public void actionPerformed(ActionEvent e) {

}

public String getUsername() {
return textbox_username.getText().trim();
}

public String getPassword() {
return new String(textbox_password.getPassword());
}

public String getUsername() {
return textbox_username.getText().trim();
}

/* Displays the GUI to user */
public void showDialog() {
this.setVisible(true);
Expand Down
Loading

0 comments on commit 37c6231

Please sign in to comment.