Anda di halaman 1dari 31

National Academy

Class Xll

Informative Practices Project on School Book Shop


Submitted to:
Mrs. Rekha arora

Submitted By: Lavish Yadav Roll.No.1613725

Acknowledgement
From the depth of my heart I express my deep sincere gratitude to the Almighty for the Blessings that had bestowed upon me to do this work. Having a successful project is really a great pleasure to us. Yet all these will not have been possible if not for hard work, persistence and cooperation among the researchers. I would like to extend my sincerest appreciation to the following people who helped accomplish the project. They are the people who contributed much for the success of this endeavor. First of all, I would like to thank my parents and benefactors who have shown their unending support and provided us with necessary materials I needed. Second, I would like to thank my I.P. teacher, Mrs. Rekha Arora for teaching us the fundamental research and investigatory writing and for showing a great deal of patience through the time. Above all, I would like to thank God for giving us the gift of wisdom and understanding and for answering my prayers.

TEACHERS REMARK:-

CERTIFICATE:This is hereby to certify that the original and genuine project work has been carried out to investigate about the subject matter and the related data collection and work done has been completely solely, sincerely and satisfactorily by LAVISH YADAV of class-XII(A), NATIONAL ACADEMY, regarding his project titled Book

Shop.

Teachers Signature:-

Coding behind AllItem.java


import java.sql.*; import javax.swing.table.DefaultTableModel; import javax.swing.JOptionPane;/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * AllItem.java * * Created on Nov 29, 2011, 8:27:12 AM */ /** * * @author student58 */ public class AllItem extends javax.swing.JFrame { Connection con = null; Statement stmt = null; ResultSet rs = null; /** Creates new form AllItem */ public AllItem() { 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") Generated Code private void abtnActionPerformed(java.awt.event.ActionEvent evt) { DefaultTableModel model = (DefaultTableModel)bookTbl.getModel(); try{ Class.forName("java.sql.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Lavish","root","root"); stmt = con.createStatement(); String query = "Select * from book;"; rs = stmt.executeQuery(query); while(rs.next()){ String bcode = rs.getString("bcode"); String bname = rs.getString("bname"); String amt = rs.getString("amt"); String QtyA = rs.getString("QtyA");

model.addRow(new Object[]{bcode,bname,amt,QtyA});} }catch(Exception e){ JOptionPane.showMessageDialog(null,e.getMessage()); } // TODO add your handling code here: } private void lbtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); new Main().setVisible(true);// TODO add your handling code here: } private void bbtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); new SaleBook().setVisible(true); // TODO add your handling code here: } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new AllItem().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton abtn; private javax.swing.JButton bbtn; private javax.swing.JTable bookTbl; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JButton lbtn; // End of variables declaration }

Coding behind ENDING.java


/* * ENDING.java /** * * @author student */ public class ENDING extends javax.swing.JFrame { /** Creates new form ENDING */ public ENDING() { 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") Generated Code private void ebtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ENDING().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton ebtn; private javax.swing.JLabel jLabel1; // End of variables declaration }

Coding behind front.java


/* * Front.java /** * * @author Lavish */ public class Front extends javax.swing.JFrame { /** Creates new form Front */ public Front() { 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") Generated Code private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.setVisible(false); new Main().setVisible(true); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Front().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; // End of variables declaration }

Coding behind Main.java


import javax.swing.JOptionPane;/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * Main.java * * Created on Nov 22, 2011, 11:46:32 AM */ /** * * @author Lavish */ public class Main extends javax.swing.JFrame { /** Creates new form Main */ public Main() { 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") Generated Code private void backbtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.setVisible(false); new Front().setVisible(true); } private void libtnActionPerformed(java.awt.event.ActionEvent evt) { String pwd = new String(pwdFld.getPassword()); if (pwd.equals("ip")){ this.setVisible(false); new Menu().setVisible(true); }else { JOptionPane.showMessageDialog(null,"Access Denied.Please enter correct password"); } }

private void ebtnActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.setVisible(false); new ENDING().setVisible(true); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Main().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton backbtn; private javax.swing.JButton ebtn; private javax.swing.JLabel jLabel1; private javax.swing.JButton libtn; private javax.swing.JPasswordField pwdFld; // End of variables declaration }

Coding behind Menu.java


import java.sql.*; import javax.swing.table.DefaultTableModel; import javax.swing.JOptionPane; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * Menu.java * * Created on Nov 21, 2011, 11:44:55 AM */ /** * * @author Lavish */ public class Menu extends javax.swing.JFrame { /** Creates new form Menu */ public Menu() { 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") Generated Code private void lobtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); new Main().setVisible(true);// TODO add your handling code here: } private void allitmbtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); new AllItem().setVisible(true); // TODO add your handling code here: } private void salebtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false);

new SaleBook().setVisible(true); }

// TODO add your handling code here:

private void adminbtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); new adminpswd().setVisible(true); // TODO add your handling code here: } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Menu().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton adminbtn; private javax.swing.JButton allitmbtn; private javax.swing.JButton lobtn; private javax.swing.JButton salebtn; // End of variables declaration }

Coding behind salebook.java


import java.sql.*; import javax.swing.JOptionPane; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * SaleBook.java * * Created on Nov 29, 2011, 8:10:17 AM */ /** * * @author student58 */ public class SaleBook extends javax.swing.JFrame { Connection con = null; Statement stmt = null; ResultSet rs = null; /** Creates new form SaleBook */ public SaleBook() { 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") Generated Code private void salebtnActionPerformed(java.awt.event.ActionEvent evt) { loadBtn.doClick(); int b=Integer.parseInt(bcodeTF.getText()); if(QtyOTF.getText().isEmpty()){JOptionPane.showMessageDialog(null,"Please enter quantity ");} int qtya = Integer.parseInt(QtyATF.getText()); int qtyo = Integer.parseInt(QtyOTF.getText()); if (qtyo>qtya) JOptionPane.showMessageDialog(rootPane,"Only "+qtya+" items of "+bcodeTF.getText()+" are in stock! \n Sorry, Cannot take your order."); else {

float amt1= Float.parseFloat(amtTF.getText()); float amt = qtyo*amt1; int ans1=JOptionPane.showConfirmDialog(rootPane,"surely wanna purchase?"); TotAmtTF.setText(""+amt); int qty = qtya-qtyo;{ if(ans1 == JOptionPane.YES_OPTION) JOptionPane.showMessageDialog(rootPane,"Book sold.Thankyou for purchasing"); } try { Class.forName("java.sql.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost/Lavish","root","root"); Statement qry = con.createStatement(); String query = "UPDATE book SET QtyA =QtyA-"+qtyo+" where bcode="+b; qry.executeUpdate(query); } catch(Exception e) { JOptionPane.showMessageDialog(null,e.getMessage()); } } // TODO add your handling code here: } private void loadBtnActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName("java.sql.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost/Lavish","root","root"); //JOptionPane.showMessageDialog(this, "ok"); stmt = con.createStatement(); String query = "Select * from book where bcode ="+bcodeTF.getText()+";"; rs = stmt.executeQuery(query); if (rs.next()) { String bcode = rs.getString("bcode"); String bname = rs.getString("bname"); String amt = rs.getString("amt"); String QtyA = rs.getString("QtyA"); bcodeTF.setText(bcode); bnameTF.setText(bname); amtTF.setText(amt); QtyATF.setText(QtyA); } else { JOptionPane.showMessageDialog(null,"No such record found"); bnameTF.setText(""); QtyATF.setText("");

amtTF.setText(""); } } catch(Exception e) { JOptionPane.showMessageDialog(null,e.getMessage()); }

// TODO add your handling code here: } private void lobtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); new Main().setVisible(true);// TODO add your handling code here: } private void clearbtnActionPerformed(java.awt.event.ActionEvent evt) { bcodeTF.setText(""); bnameTF.setText(""); amtTF.setText(""); QtyATF.setText(""); QtyOTF.setText(""); TotAmtTF.setText(""); // TODO add your handling code here: } private void backbtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); new Menu().setVisible(true);// TODO add your handling code here: } private void QtyATFActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void QtyOTFCaretUpdate(javax.swing.event.CaretEvent evt) { //loadBtn.doClick();

// TODO add your handling code here: } private void TotAmtTFActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } /** * @param args the command line arguments

*/ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SaleBook().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JTextField QtyATF; private javax.swing.JTextField QtyOTF; private javax.swing.JTextField TotAmtTF; private javax.swing.JTextField amtTF; private javax.swing.JButton backbtn; private javax.swing.JTextField bcodeTF; private javax.swing.JTextField bnameTF; private javax.swing.JButton clearbtn; 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.JLabel jLabel6; private javax.swing.JButton loadBtn; private javax.swing.JButton lobtn; private javax.swing.JButton salebtn; // End of variables declaration }

Coding behind admin.java


import java.sql.*; import javax.swing.table.DefaultTableModel; import javax.swing.JOptionPane;/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * admin.java * * Created on Jul 30, 2007, 12:59:55 AM */ /** * * @author student */ public class admin extends javax.swing.JFrame { Connection con = null; Statement stmt = null; ResultSet rs = null; /** Creates new form admin */ public admin() { 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") Generated Code private void lobtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); new Main().setVisible(true);// TODO add your handling code here: } private void clearbtnActionPerformed(java.awt.event.ActionEvent evt) { bcodeTF.setText(""); bnameTF.setText(""); amtTF.setText(""); QtyATF.setText("");

// TODO add your handling code here: } private void updatebtnActionPerformed(java.awt.event.ActionEvent evt) { int ans = JOptionPane.showConfirmDialog(null,"Surely wanna update the record?"); if(ans == JOptionPane.YES_OPTION){ try{ stmt = con.createStatement(); String query ="Update book set bname ='"+ bnameTF.getText() +"',amt ='"+amtTF.getText()+"',QtyA ='"+QtyATF.getText()+"'WHERE bcode = "+bcodeTF.getText()+";"; stmt.executeUpdate(query); JOptionPane.showMessageDialog(null,"Record successfully updated."); } catch(Exception e) { JOptionPane.showMessageDialog(null,"Error in table updation!"); } }// TODO add your handling code here: } private void addbtnActionPerformed(java.awt.event.ActionEvent evt) { int ans = JOptionPane.showConfirmDialog(null,"Surely want to add record"); if (ans == JOptionPane.YES_OPTION) { try { Class.forName("java.sql.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost/Lavish","root","root"); stmt = con.createStatement(); String bcode = bcodeTF.getText(); String bname = bnameTF.getText(); String amt = amtTF.getText(); String QtyA = QtyATF.getText(); String strSQL = "Insert into book(bcode,bname,amt,QtyA) values('"+(bcode)+"','"+(bname)+"','"+(amt)+"','"+(QtyA)+"');"; stmt.executeUpdate(strSQL); JOptionPane.showMessageDialog(null,"Record Added!"); bcodeTF.setText(""); bnameTF.setText(""); amtTF.setText(""); QtyATF.setText(""); } catch(Exception e) { JOptionPane.showMessageDialog(null,e.getMessage()); } } // TODO add your handling code here: } private void delbtnActionPerformed(java.awt.event.ActionEvent evt) { int res = JOptionPane.showConfirmDialog(null,"wanna delete the record for sure?");

if (res == JOptionPane.YES_OPTION) { try { stmt = con.createStatement(); String query = "Delete from book where bcode ='"+bcodeTF.getText()+"';"; stmt.executeUpdate(query); JOptionPane.showMessageDialog(null,"Record Deleted!"); } catch(Exception e) { JOptionPane.showMessageDialog(null,"Error in deletion!"); } }// end of if bcodeTF.setText(""); bnameTF.setText(""); amtTF.setText(""); QtyATF.setText("");

// TODO add your handling code here: } private void loadBtnActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName("java.sql.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost/Lavish","root","root"); //JOptionPane.showMessageDialog(this, "ok"); stmt = con.createStatement(); String query = "Select * from book where bcode ="+bcodeTF.getText()+";"; rs = stmt.executeQuery(query); if (rs.next()) { String bcode = rs.getString("bcode"); String bname = rs.getString("bname"); String amt = rs.getString("amt"); String QtyA = rs.getString("QtyA"); bcodeTF.setText(bcode); bnameTF.setText(bname); amtTF.setText(amt); QtyATF.setText(QtyA); } else { JOptionPane.showMessageDialog(null,"No such record found"); bnameTF.setText(""); QtyATF.setText(""); amtTF.setText(""); } } catch(Exception e) { JOptionPane.showMessageDialog(null,e.getMessage()); }

// TODO add your handling code here: }

/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new admin().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JTextField QtyATF; private javax.swing.JButton addbtn; private javax.swing.JTextField amtTF; private javax.swing.JTextField bcodeTF; private javax.swing.JTextField bnameTF; private javax.swing.JButton clearbtn; private javax.swing.JButton delbtn; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JButton loadBtn; private javax.swing.JButton lobtn; private javax.swing.JButton updatebtn; // End of variables declaration }

Coding behind adminpswd.java


import javax.swing.JOptionPane;/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * adminpswd.java * * Created on Jul 30, 2007, 1:02:29 AM */ /** * * @author student */ public class adminpswd extends javax.swing.JFrame { /** Creates new form adminpswd */ public adminpswd() { 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") Generated Code private void libtnActionPerformed(java.awt.event.ActionEvent evt) { String pwd = new String(pwdFld.getPassword()); if (pwd.equals("ip")){ this.setVisible(false); new Menu().setVisible(true); } else { JOptionPane.showMessageDialog(null,"Access Denied.Please enter correct password"); }{ this.setVisible(false); new adminpswd().setVisible(true);} this.setVisible(false); new admin().setVisible(true); // TODO add your handling code here: } private void backbtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false);

new Menu().setVisible(true); }

// TODO add your handling code here:

/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new adminpswd().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton backbtn; private javax.swing.JLabel jLabel1; private javax.swing.JButton libtn; private javax.swing.JPasswordField pwdFld; // End of variables declaration }

Coding behind coverpage.java


* coverpage.java * * Created on Jan 10, 2012, 8:51:01 PM */ /** * * @author BASE COMPUTERS */ public class coverpage extends javax.swing.JFrame { /** Creates new form coverpage */ public coverpage() { 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") Generated Code private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); new Front().setVisible(true);// TODO add your handling code here: } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new coverpage().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; // End of variables declaration }

Screen Shots of program:


1.

2.

3.

4.

5.

6.

7.

8.

9.

Coding for Making Table in MySql:

create database Lavish; use Lavish; create Table book ( bcode char(5) unique, bname char(30), amt char(5), QtyA char(5) ); insert into book values(101,"bbc","120","25"); insert into book values(102,"oxford","130","30"); insert into book values(103.,"ip","150","35"); insert into book values(104,"chem","190","40"); insert into book values(105,"phy","200","45"); insert into book values(106,"phe","220","50"); insert into book values(107,"maths","180","55");

Anda mungkin juga menyukai