You are on page 1of 10

SUPERMARKET

MANAGEMENT

SUBMITTED TO: - SUBMITTED BY:


Dr. Mithilesh Kumar Dubey Name: - KHEMRAJ MEGHWAL
Section: - D1605
Reg. no.: - 11616760
Introduction about the project
The project titled as “SUPERMARKET MANAGEMENT SYSTEM “is a standalone application to manage a
Supermarket. It is Point of Sale Software for managing the inventory, employees and billing. This system is
developed using NetBeans jForms.

This system is designed for the ease of shopkeeper and owner of the shop. So, we designed a very easy interface
which can user learn that what the buttons will perform when they are clicked. This interface can be used by
both the illiterate to computing and expert user.

Modules

 LOGIN
 MAINE
 STOCK
 SALE
 DATABASE CONNECTION

SPLASH SCREEN
This is the first module to be
loaded and run. The purpose of
the module is to check the
connection with the database and
to use as an advertisement.

This module will terminate if the


connection throws any exception.

In future will be utilized for messaging for the users.

Snippet Code
for(int i=0;i<=100;i++)
{
try {
Thread.sleep(50);
} catch (InterruptedException ex) {
Logger.getLogger(splash.class.getName()).log(Level.SEVERE, null, ex);
}
Splash.loadingnum.setText(Integer.toString(i)+"%");
Splash.loadingbar.setValue(i);
switch(i){
case 10:
Splash.process.setText("loading dll...");
break;
case 20:
Splash.process.setText("connecting database...");
break;
case 30:
Splash.process.setText("Finalizing...");
break;
case 80:
Splash.process.setText("Opening Main Page...");
break;
}
if(i==100)
{
Login lg=new Login();
Splash.setVisible(false);
lg.setVisible(true);
}
}

LOGIN
This module is opened if the database connection is established else it will not be loaded. This
module is the access control to the
system. Basically, there are 2 types of
users in this system.

1. Admin users - Has full access to all


the modules of this system.

2. Sales/Others – Has restricted access.


i.e., Normal users has access to some
of the modules only.
 First a login screen should be
displayed to get the user details.
The user has to enter the user-id
and the password. The password
has to be masked with character
‘*’.
 The user details should be verified against the details in the user tables and if he / she is
valid user, they should be entered into the system. Once entered, based on the user type
access to the different modules to be enabled / disabled.
Snippet Code
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Login lg = new Login();
String sql = "Select *From login where UserName= ? and Password= ? and Type =?";
String user;
try {
int count = 0;
pst = conn.prepareStatement(sql);
pst.setString(1, Log_txt.getText());
pst.setString(2, Log_Pass.getText());
pst.setString(3, txt_combo.getSelectedItem().toString());
rs = pst.executeQuery();

while (rs.next()) {
int id = rs.getInt(1);
Emp.empId = id;
String user1 = rs.getString(2);
Usern.username = user1;
count = count + 1;
}
String access = (txt_combo.getSelectedItem().toString());

if (access == "Admin") {

if (count == 1) {
JOptionPane.showMessageDialog(null, "Success");
MainForm j = new MainForm();
j.setVisible(true);
j.info_name.setText("Welcome Admin " + (Usern.username));
// j.user_info.setText("Welcome " + (Usern.username));
this.dispose();

Date currentDate = GregorianCalendar.getInstance().getTime();


DateFormat df = DateFormat.getDateInstance();
String dateString = df.format(currentDate);

Date d = new Date();


SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String timeString = sdf.format(d);

String value0 = timeString;


String values = dateString;
int value = Emp.empId;
String reg = "insert into Audit (emp_id,date,status) values ('" + value + "','" + value0
+ " / " + values + "','Logged in')";
pst = conn.prepareStatement(reg);
pst.execute();
this.dispose();

} else if (count > 1) {


JOptionPane.showMessageDialog(null, "Duplicate Username or Password Access
denied");
} else {
JOptionPane.showMessageDialog(null, "Username and Password is not correct");

Log_txt.setText("");
Log_Pass.setText("");
}
} else if (access == "Sales") {
if (count == 1) {

JOptionPane.showMessageDialog(null, "Sucess");

MainForm j = new MainForm();


j.setVisible(true);

j.info_name.setText("Welcome " + (Usern.username));

this.dispose();
} else if (count > 1) {
JOptionPane.showMessageDialog(null, "Duplicate Username or Password Access
denied");
} else {
JOptionPane.showMessageDialog(null, "Username and Password is not correct");
}

}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Connection Lost");
this.dispose();
} finally {

try {
rs.close();
pst.close();

} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Connection Lost");
}

}
}

MAIN INTERFACE

This is the main interface module where all the other modules reside. This is a mdi form which act
as a container for the jinternal forms for stock, sale and settings.

STOCK MODULE
This form is used to enter items and search through the item and can be edited.
Snippet Code:
public ArrayList<Item> findItem(String ValToSearch)
{
ArrayList<Item> Itemlist=new ArrayList<Item>();

Statement st;
ResultSet rs;
try {
conn=Connect.connectDB();
st=conn.createStatement();
String searchQuery = "SELECT * FROM `item_details` WHERE CONCAT(`it_ID`,
`itName`) LIKE '%"+ValToSearch+"%'";
rs=st.executeQuery(searchQuery);
Item item;
while(rs.next())
{
item=new Item(
rs.getInt("it_ID"),
rs.getString("itName"),
rs.getString("descrip"),
rs.getInt("qty"),
rs.getString("exp_Date"),
Float.parseFloat(rs.getString("cost")),
Float.parseFloat(rs.getString("price")));
Itemlist.add(item);
}
} catch (SQLException ex) {
Logger.getLogger(Item_Recieve.class.getName()).log(Level.SEVERE, null, ex);
}
return Itemlist;
}
public void findItem()
{

ArrayList<Item> Items=findItem(txt_search.getText());

DefaultTableModel model=new DefaultTableModel();


model.setColumnIdentifiers(new
Object[]{"ID","Name","Description","Qty","ExpDate","Cost","Price"});
Object [] row=new Object[7];

for(int i=0;i<Items.size();i++)
{
row[0]=Items.get(i).getID();
row[1]=Items.get(i).getName();
row[2]=Items.get(i).getDes();
row[3]=Items.get(i).getQty();
row[4]=Items.get(i).getExp();
row[5]=Items.get(i).getCost();
row[6]=Items.get(i).getPrice();
model.addRow(row);
}

Item_table1.setModel(model);
}
public void price()
{
float a=Float.parseFloat(txt_cost.getText());
int b=Integer.parseInt(txt_qty.getText());
txt_total.setText(String.valueOf(a*b));

SALES MODULE

This module will sell item(s) and balance can be calculated depending on the amount given by the
customer. Once Cash button is pressed the item id, and price will be saved in a Sales table in MySql
server.
Snippet Code:
int rowsc=tbl_sales.getRowCount();
try{
conn=Connect.connectDB();

PreparedStatement ps=conn.prepareStatement("Insert into Sales(it_id,price)"


+ "values(?,?)");
for(int row = 0; row<rowsc; row++)
{
int itid = (int) tbl_sales.getValueAt(row, 0);
float price = (float) tbl_sales.getValueAt(row, 6);

//String price = (String)tbl_sales.getValueAt(row, 6);


// pst.setString(1, itid);
pst.setInt(1, itid);
pst.setFloat(2, price);
pst.executeQuery();
}
JOptionPane.showMessageDialog(null,"Added successfully");
}catch(Exception e){
JOptionPane.showMessageDialog(this,e.getMessage());
e.printStackTrace();

}
}

CONNECTION MODULE

This module connects to MySql database in WAMP server. We have used jdbc to connect.
Code:
import java.sql.*;

public class Connect extends JFrame{

Connection Conn = null;


PreparedStatement pst=null;
ResultSet rs=null;

public static Connection connectDB() {

Connection con = null;


String url = "jdbc:mysql://localhost:3306/";
String db = "supermarket";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "123";
try {
Class.forName(driver);
con = DriverManager.getConnection(url + db, user, pass);
if (con == null) {
System.out.println("Connection cannot be established");
}
// JOptionPane.showMessageDialog(null,"Welcome User");
return con;
} catch (ClassNotFoundException | SQLException e) {
//System.out.println(e);
JOptionPane.showMessageDialog(null,"Connection failed");
JOptionPane.showMessageDialog(null,"Exiting");
System.exit(0);
}
return null;
}

Conclusion:

This program in java can be further refined using validation module and fixing some of the bugs,
making it more user friendly and adding other modules for accounting and report generation.

You might also like