Skip to content

Commit

Permalink
Added remaining GUI
Browse files Browse the repository at this point in the history
Added delete GUI
Added modify GUI
Added new entry GUI
  • Loading branch information
shreyask21 committed Apr 17, 2020
1 parent 6836143 commit a8aeb1f
Show file tree
Hide file tree
Showing 17 changed files with 1,173 additions and 56 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ and design an accompanying software in Java to connect to it with easy to unders

## Screenshots

![1](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/1.png) ![2](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/2.png) ![3](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/3.png) ![4](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/4.png) ![5](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/5.png) ![6](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/6.png)
![1](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/1.png) ![2](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/2.png)
![3](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/3.png)
![4](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/4.png)
![5](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/5.png)
![6](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/6.png)
![7](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/7.png)
![8](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/8.png)
![9](https://raw.githubusercontent.com/shreyask21/assetmgmt/master/img/screenshots/9.png)
Binary file modified export/asset_management.jar
Binary file not shown.
Binary file modified img/screenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/screenshots/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/screenshots/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/screenshots/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/screenshots/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/screenshots/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/screenshots/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/screenshots/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/screenshots/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
282 changes: 282 additions & 0 deletions src/GUI/Delete_Dialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
package GUI;

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.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;

import db_driver.Assetdb;

public class Delete_Dialog extends JDialog {
private static final long serialVersionUID = 4738336405102830035L;

public static boolean checkValidDate(String value) {
Date date = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
date = sdf.parse(value);
if (!value.equals(sdf.format(date))) {
date = null;
}
} catch (Exception ex) {
}
return date != null;
}

private Assetdb db;
private JButton ExportBtn;
private JTextField IDTbox;
private JTextField pdateTbox;
private JTextField PriceTbox;
private JTextField SrTbox;
private JTextField StatusTbox;
private JTable table;

private JTextField TypeTbox;

public Delete_Dialog(Assetdb dbobj) {
this.db = dbobj;
this.setTitle("Delete Entries");
setModal(true);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setResizable(false);
this.setAlwaysOnTop(false);
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - getWidth()) / 2);
int y = (int) ((dimension.getHeight() - getHeight()) / 2);
this.setBounds(400, 300, 626, 458);
this.setLocationRelativeTo(null);
this.setLocation(x, y);
this.setLocationRelativeTo(null);
this.getContentPane().setLayout(null);

SrTbox = new JTextField();
SrTbox.setHorizontalAlignment(SwingConstants.TRAILING);
SrTbox.setBounds(10, 36, 90, 26);
getContentPane().add(SrTbox);
SrTbox.setColumns(10);

IDTbox = new JTextField();
IDTbox.setHorizontalAlignment(SwingConstants.TRAILING);
IDTbox.setColumns(10);
IDTbox.setBounds(110, 36, 90, 26);
getContentPane().add(IDTbox);

pdateTbox = new JTextField();
pdateTbox.setHorizontalAlignment(SwingConstants.TRAILING);
pdateTbox.setColumns(10);
pdateTbox.setBounds(210, 36, 90, 26);
getContentPane().add(pdateTbox);

TypeTbox = new JTextField();
TypeTbox.setHorizontalAlignment(SwingConstants.TRAILING);
TypeTbox.setColumns(10);
TypeTbox.setBounds(310, 36, 90, 26);
getContentPane().add(TypeTbox);

PriceTbox = new JTextField();
PriceTbox.setHorizontalAlignment(SwingConstants.TRAILING);
PriceTbox.setColumns(10);
PriceTbox.setBounds(410, 36, 90, 26);
getContentPane().add(PriceTbox);

StatusTbox = new JTextField();
StatusTbox.setHorizontalAlignment(SwingConstants.TRAILING);
StatusTbox.setColumns(10);
StatusTbox.setBounds(510, 36, 90, 26);
getContentPane().add(StatusTbox);

JLabel lblNewLabel = new JLabel("Sr.");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblNewLabel.setBounds(10, 12, 90, 20);
getContentPane().add(lblNewLabel);

JLabel lblId = new JLabel("ID");
lblId.setHorizontalAlignment(SwingConstants.CENTER);
lblId.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblId.setBounds(110, 12, 90, 20);
getContentPane().add(lblId);

JLabel lblPurchaseDate = new JLabel("Purchase Date");
lblPurchaseDate.setHorizontalAlignment(SwingConstants.CENTER);
lblPurchaseDate.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblPurchaseDate.setBounds(210, 12, 90, 20);
getContentPane().add(lblPurchaseDate);

JLabel lblType = new JLabel("Type");
lblType.setHorizontalAlignment(SwingConstants.CENTER);
lblType.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblType.setBounds(310, 12, 90, 20);
getContentPane().add(lblType);

JLabel lblPrice = new JLabel("Price");
lblPrice.setHorizontalAlignment(SwingConstants.CENTER);
lblPrice.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblPrice.setBounds(410, 12, 90, 20);
getContentPane().add(lblPrice);

JLabel lblStatus = new JLabel("Status");
lblStatus.setHorizontalAlignment(SwingConstants.CENTER);
lblStatus.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblStatus.setBounds(510, 12, 90, 20);
getContentPane().add(lblStatus);

JButton searchbtn = new JButton("Search");
searchbtn.setFont(new Font("Tahoma", Font.PLAIN, 13));
searchbtn.setBounds(10, 73, 190, 34);
getContentPane().add(searchbtn);

ExportBtn = new JButton("Delete Selected Rows");
ExportBtn.setFont(new Font("Tahoma", Font.PLAIN, 13));
ExportBtn.setBounds(410, 73, 190, 34);
getContentPane().add(ExportBtn);

table = new JTable();
table.setBounds(10, 118, 590, 292);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(10, 118, 590, 292);
getContentPane().add(scrollPane);
ExportBtn.setEnabled(false);

JButton helpbtn = new JButton("Help");
helpbtn.setFont(new Font("Tahoma", Font.PLAIN, 13));
helpbtn.setBounds(210, 73, 190, 34);
getContentPane().add(helpbtn);
FillTable();

searchbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Delete_Dialog.this.FillTable();
}
});
ExportBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Delete_Dialog.this.deleteValues();
}
});

table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me) {
if (me.getClickCount() == 1) {
JTable target = (JTable) me.getSource();
int[] rows = target.getSelectedRows(); // select a row
if (rows.length > 0) {
ExportBtn.setEnabled(true);
} else {
ExportBtn.setEnabled(false);
}
}
if (me.getClickCount() == 2) {
JTable target = (JTable) me.getSource();
int row = target.getSelectedRow(); // select a row
int choice = JOptionPane.showOptionDialog(null, "Do you want to delete selected row?",
"Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
new String[] { "Delete", "Go back" }, "default");
if (choice == JOptionPane.YES_OPTION) {
String Sr = table.getValueAt(row, 0).toString();
db.deleteEntrySr(Sr);
}
table.clearSelection();
FillTable();
table.clearSelection();
}
}
});

helpbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,
"Double click on the table row to delete it.\nOR\nDelete multiple rows by keeping 'Control' key pressed\n"
+ "and select rows by clicking on them and pressing the delete button.",
"Help", JOptionPane.INFORMATION_MESSAGE);
}
});
}

private void deleteValues() {
DefaultTableModel model = (DefaultTableModel) table.getModel();
int[] selectedRows = table.getSelectedRows();
if (selectedRows.length > 0) {
int choice = JOptionPane.showOptionDialog(null, "Do you want to delete selected rows?", "Confirmation",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Delete", "Go back" },
"default");
if (choice == JOptionPane.YES_OPTION) {
for (int currentRow : selectedRows) {
String Sr = model.getValueAt(currentRow, 0).toString();
db.deleteEntrySr(Sr);
}
}
table.clearSelection();
FillTable();
table.clearSelection();
}
}

public void FillTable() {
try {
table.clearSelection();
ResultSet rs = db.getResultSet(this.getSearchString());
DefaultTableModel tableModel = new DefaultTableModel();
ResultSetMetaData metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
tableModel.addColumn(metaData.getColumnLabel(columnIndex));
}
Object[] row = new Object[columnCount];
while (rs.next()) {
for (int i = 0; i < columnCount; i++) {
row[i] = rs.getObject(i + 1);
}
tableModel.addRow(row);
}
table.setModel(tableModel);
table.setDefaultEditor(Object.class, null);
table.getTableHeader().setReorderingAllowed(false);
ExportBtn.setEnabled(false);
} catch (Exception e) {
e.printStackTrace();
}
}

private String[] getSearchString() {
String[] searchString = new String[6];
searchString[0] = this.SrTbox.getText().trim();
searchString[1] = this.IDTbox.getText().trim();
if (checkValidDate(this.pdateTbox.getText().trim())) {
searchString[2] = this.pdateTbox.getText().trim();
} else {
searchString[2] = "";
}
searchString[3] = this.TypeTbox.getText().trim();
searchString[4] = this.PriceTbox.getText().trim();
searchString[5] = this.StatusTbox.getText().trim();
return searchString;
}

public void showDialog() {
this.setVisible(true);
}
}
Loading

0 comments on commit a8aeb1f

Please sign in to comment.