OOSE Word
OOSE Word
AIM:
The aim is to create a robust Java application for managing orders in a retail system,
facilitating efficient customer and product management that is Stock Maintenance System
in NetBeans IDE using SQLite database.
PROBLEM STATEMENT:
Develop a Java application for managing orders in a retail system, allowing users to add
customers, view products, add products to a cart, and save order details. The application
should feature customer and product management functionalities, along with cart
management for adding products with quantity. Admin tasks include setting up the
database schema, implementing error handling, ensuring a user-friendly UI/UX design, and
conducting thorough testing to ensure reliability.
CLASS DIAGRAM:
ACTIVITY DIAGRAM:
SEQUENCE DIAGRAM:
COLLABORATION DIAGRAM:
STATE DIAGRAM:
SOURCE CODE:
Connection Provider.java:
package dao;
import java.sql.*;
public class ConnectionProvider {
public static Connection getCon(){
try{
Class.forName("org.sqlite.JDBC");
Connection con = DriverManager.getConnection("jdbc:sqlite:F:\\SQLite\\stock.db");
return con;
}
catch(Exception e){
System.out.println(e);
return null;
}
}
}
Login.java:
import dao.ConnectionProvider;
import javax.swing.JOptionPane;
import java.sql.*;
public class Login extends javax.swing.JFrame {
public Login() {
initComponents();
setLocationRelativeTo(null);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/login-
background.PNG"))); // NOI18N
getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -
1));
pack();
}// </editor-fold>
int temp = 0;
try{
Connection con = ConnectionProvider.getCon();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from appUser where email='"+e+"' and
password='"+pass+"' and status='Active'");
while(rs.next()){
temp = 1;
setVisible(false);
new Home(rs.getString("userRole")).setVisible(true);
}
if(temp == 0){
JOptionPane.showMessageDialog(null, "Incorrect email or oassword");
}
}
catch(Exception e1){
JOptionPane.showMessageDialog(null ,e1);
}
}
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
}
//</editor-fold>
Tables.java:
package dao;
import java.sql.*;
import javax.swing.JOptionPane;
public class tables {
public static void main(String args[]){
Connection con = null;
Statement st = null;
try{
con = ConnectionProvider.getCon();
st = con.createStatement();
st.executeUpdate("CREATE TABLE User(appuser_pk INTEGER primary key
AUTOINCREMENT, userRole varchar(50), name varchar(100), mobileNumber varchar(50),
email varchar(200), password varchar(50), address varchar(200), status varchar(50)");
st.executeUpdate("INSERT INTO User VALUES (1,'SuperAdmin', 'Super Admin',
'12345', 'superadmin@testemail.com', '123', 'India', 'Active')");
st.executeUpdate("CREATE TABLE category (category_pk INTEGER primary key
AUTOINCREMENT, name varchar(200))");
st.executeUpdate("CREATE TABLE products (product_pk INTEGER primary key
AUTOINCREMENT, name varchar(200), quantity int, price int, description varchar(200),
category_fk int)");
st.executeUpdate("CREATE TABLE customer (customer_pk INTEGER primary key
AUTOINCREMENT, name varchar(200), mobileNumber varchar(50), email varchar(200))");
JOptionPane.showMessageDialog(null,"Table created successfully");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
finally{
try{
con.close();
st.close();
}
catch(Exception e){}
}
}
}
Home.java:
import javax.swing.JOptionPane;
public class Home extends javax.swing.JFrame {
public Home() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);
}
//</editor-fold>
ManageUser.java:
import dao.ConnectionProvider;
import java.awt.Color;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.JOptionPane;
import java.sql.*;
public class ManageUser extends javax.swing.JFrame {
private int appuserPK = 0;
public ManageUser() {
initComponents();
setLocationRelativeTo(null);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
label.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/images/All_page_Background.png"))); //
NOI18N
getContentPane().add(label, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, -20, -1,
640));
pack();
}// </editor-fold>
if(validateFields("new")){
JOptionPane.showMessageDialog(null, "All fields are required");
}
else{
try{
Connection con = ConnectionProvider.getCon();
PreparedStatement pt = con.prepareStatement("insert into User
(userRole,name,mobileNumber,email,password,address,status) values('Admin',?,?,?,?,?,?)");
pt.setString(1, name);
pt.setString(2, mobilenumber);
pt.setString(3, email);
pt.setString(4, password);
pt.setString(5, address);
pt.setString(6, status);
pt.executeUpdate();
JOptionPane.showMessageDialog(null, "User added successfully");
setVisible(false);
new ManageUser().setVisible(true);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
txtpassword.setEditable(false);
txtpassword.setBackground(Color.DARK_GRAY);
btnsave.setEnabled(false);
btnupdate.setEnabled(true);
}
if(validateFields("edit")){
JOptionPane.showMessageDialog(null, "All fields are required");
}
else{
try{
Connection con = ConnectionProvider.getCon();
PreparedStatement pt = con.prepareStatement("update user set name=?,
mobileNumber=?, email=?, address=?, status=? where appuser_pk=?");
pt.setString(1, name);
pt.setString(2, mobilenumber);
pt.setString(3, email);
pt.setString(4, address);
pt.setString(5, status);
pt.setInt(6, appuserPK);
pt.executeUpdate();
JOptionPane.showMessageDialog(null, "User updated successfully");
setVisible(false);
new ManageUser().setVisible(true);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
/**
* @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(ManageUser.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ManageUser.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ManageUser.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ManageUser.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
}
//</editor-fold>
import dao.ConnectionProvider;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.sql.*;
public class ManageCategory extends javax.swing.JFrame {
private int categoryPK = 0;
public ManageCategory() {
initComponents();
setLocationRelativeTo(null);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentShown(java.awt.event.ComponentEvent evt) {
formComponentShown(evt);
}
});
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
tablecategory.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
}
});
getContentPane().add(btnclose, new org.netbeans.lib.awtextra.AbsoluteConstraints(770,
260, -1, 30));
jLabel3.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/images/All_page_Background.png"))); //
NOI18N
getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, -30,
960, 660));
pack();
}// </editor-fold>
/**
* @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()) {
}
ManageProduct.java:
import dao.ConnectionProvider;
import javax.swing.JOptionPane;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
jLabel3.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/images/All_page_Background.png"))); //
NOI18N
getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -
1));
pack();
}// </editor-fold>
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
btnupdate.setEnabled(false);
}
if(validateFields("new")){
JOptionPane.showMessageDialog(null, "All fields are required");
}
else{
try{
Connection con = ConnectionProvider.getCon();
PreparedStatement pt = con.prepareStatement("insert into products
(name,quantity,price,description,category_fk) values(?,?,?,?,?)");
pt.setString(1,name);
pt.setString(2, quantity);
pt.setString(3, price);
pt.setString(4, description);
pt.setString(5, categoryid[0]);
pt.executeUpdate();
JOptionPane.showMessageDialog(null, "Product added successfully");
setVisible(false);
new ManageProduct().setVisible(true);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
try{
Connection con = ConnectionProvider.getCon();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from category");
while(rs.next()){
if(Integer.parseInt(categoryid) != rs.getInt(1))
comboboxcategory.addItem(rs.getString("category_pk")+"-"+rs.getString("name"));
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
btnsave.setEnabled(false);
btnupdate.setEnabled(true);
}
if(validateFields("edit")){
JOptionPane.showMessageDialog(null, "All fields are required");
}
else{
try{
if(!quantity.equals(" ")){
totalquantity = totalquantity + Integer.parseInt(quantity);
}
Connection con = ConnectionProvider.getCon();
PreparedStatement pt = con.prepareStatement("update products set name=?,
quantity=?, price=?, description=?, category_fk=? where product_pk=?");
pt.setString(1,name);
pt.setInt(2, totalquantity);
pt.setString(3, price);
pt.setString(4, description);
pt.setString(5, categoryid[0]);
pt.setInt(6, productPK);
pt.executeUpdate();
JOptionPane.showMessageDialog(null, "Product updated successfully");
setVisible(false);
new ManageProduct().setVisible(true);
}
catch(Exception e){
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblquantity;
private javax.swing.JTable tableproduct;
private javax.swing.JTextField txtdescription;
private javax.swing.JTextField txtname;
private javax.swing.JTextField txtprice;
private javax.swing.JTextField txtquantity;
// End of variables declaration
}
ManageCustomer.java:
import dao.ConnectionProvider;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.JOptionPane;
public class ManageCustomer extends javax.swing.JFrame {
private int customerPK = 0;
public ManageCustomer() {
initComponents();
setLocationRelativeTo(null);
}
// TODO add your handling code here:
DefaultTableModel model = (DefaultTableModel) tablecustomer.getModel();
try{
Connection con = ConnectionProvider.getCon();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from customer");
while(rs.next()){
model.addRow(new Object[]{rs.getString("customer_pk"), rs.getString("name"),
rs.getString("mobileNumber"), rs.getString("email")});
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
btnupdate.setEnabled(false);
}
if(validateFields()){
JOptionPane.showMessageDialog(null, "All fields are required");
}
else{
try{
Connection con = ConnectionProvider.getCon();
PreparedStatement pt = con.prepareStatement("insert into customer
(name,mobileNumber,email) values(?,?,?)");
pt.setString(1, name);
pt.setString(2, mobileNumber);
pt.setString(3, email);
pt.executeUpdate();
JOptionPane.showMessageDialog(null, "Customer added successfully");
setVisible(false);
new ManageCustomer().setVisible(true);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
private void tablecustomerMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
int index = tablecustomer.getSelectedRow();
TableModel model = tablecustomer.getModel();
btnsave.setEnabled(false);
btnupdate.setEnabled(true);
}
if(validateFields()){
JOptionPane.showMessageDialog(null, "All fields are required");
}
else{
try{
Connection con = ConnectionProvider.getCon();
PreparedStatement pt = con.prepareStatement("update customer set name=?,
mobileNumber=?, email=? where customer_pk=?");
pt.setString(1, name);
pt.setString(2, mobileNumber);
pt.setString(3, email);
pt.setInt(4, customerPK);
pt.executeUpdate();
JOptionPane.showMessageDialog(null, "Customer updated
successfully");
setVisible(false);
new ManageCustomer().setVisible(true);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import commonFinish.openPdf;
import static commonFinish.openPdf.openbyid;
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import dao.ConnectionProvider;
import dao.StockUtils;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
public class ManageOrder extends javax.swing.JFrame {
private int customerPK = 0;
private int productPK = 0;
private int finaltotalprice = 0;
private String orderid = "";
public ManageOrder() {
initComponents();
setLocationRelativeTo(null);
}
/**
* 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">
private void initComponents() {
pack();
}// </editor-fold>
txtproductname.setEditable(false);
txtproductprice.setEditable(false);
txtproductdescription.setEditable(false);
try{
Connection con = ConnectionProvider.getCon();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from customer");
while(rs.next()){
model.addRow(new Object[]{rs.getString("customer_pk"), rs.getString("name"),
rs.getString("mobileNumber"), rs.getString("email")});
}
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
tb1.addCell(namecell);
tb1.addCell(descriptioncell);
tb1.addCell(pricecell);
tb1.addCell(quantitycell);
tb1.addCell(subtotalpricecell);
doc.add(tb1);
doc.add(starline);
Paragraph thanksmessage = new Paragraph("Thank you. Please visit again.");
doc.add(thanksmessage);
openPdf.openbyid(orderid);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
doc.close();
setVisible(false);
new ManageOrder().setVisible(true);
}
else{
JOptionPane.showMessageDialog(null, "Please add some product to the cart or select
customer");
}
}
int checkstock = 0;
int checkincart = 0;
try{
Connection con = ConnectionProvider.getCon();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from products where
product_pk="+productPK+"");
while(rs.next()){
if(rs.getInt("quantity") >= Integer.parseInt(noOfunits)){
checkstock = 1;
}
else{
JOptionPane.showMessageDialog(null, "Product out of stock. Only
"+rs.getInt("quantity")+" left");
}
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
if(checkstock == 1){
DefaultTableModel model = (DefaultTableModel) tablecart.getModel();
if(tablecart.getRowCount() != 0){
for(int i=0; i<tablecart.getRowCount(); i++){
if(Integer.parseInt(model.getValueAt(i, 0).toString()) == productPK){
checkincart = 1;
JOptionPane.showMessageDialog(null, "Product already exists in cart");
}
}
}
if(checkincart == 0){
model.addRow(new Object[]{productPK, productname, noOfunits, productprice,
productdescription, totalprice});
finaltotalprice = finaltotalprice + totalprice;
lblfinaltotalprice.setText(String.valueOf(finaltotalprice));
JOptionPane.showMessageDialog(null, "Product added successfully");
}
clearProductFields();
}
}
else{
JOptionPane.showMessageDialog(null, "No of quantity and product field is required");
}
}
/**
* @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(ManageOrder.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (InstantiationException ex) {