-->

Wednesday 26 June 2013

CS project work (Library Management System)






    WestSide Public     
    School  
    Library Management
    System

          [Project Report]

Particular of Student
Name : ABCD
Roll No . 25
Class :  XII 


         



         ACKNOWLEDGEMENT


It is with great pleasure that I find myself penning down these lines to express my sincere thanks to various people who helped me a long way in completing my project.

The harmonious climate in our School provided proper guide for preparing the project. It was a privilege to have guided by Mr. My CS Teacher.

Thanks to all my classmates who helped me during the development of this project with their constructive criticism and advice.


                                                                             ABCD
                                                                             Roll No. 25



                                         Certificate



This is to certify that the project entitled  Library Management System” .which deals with managing libarary activities and Database Updating is being submitted by ABCD . This Project is a genuine piece of work carried out with the consultation of supervisor




                                                               ABCD
                                                                Roll No.25
                                                                Class : XII 















♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥!

Database Design

Program uses 2 tables to store & modify data
1.   book_rec


Field Name
Field Type
Width
Ac_No
Authors
Year
Title
Publisher
Total_Copies
Genre
Pages
Copies_issued
Int
Varchar
Int
Varchar
Varchar
int
Varchar
Int
int
6
60
4
100
100
2
50
5
2







2.   issuer_details

Field Name
Field Type
Width
Description
Ac_No
Isr_type
Isr_name
Is_on
Isrtc_Degs
St_cls
St_sec
Stud_Roll
Int
Varchar
varchar
date
Varchar
int
char
Int
6
20
60

60
2
1
2
Accesion_No
Issuer Type
Issuer Name
Issued On
Teac. Designation
Student Class
Student Section
Student Roll No


♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥!




Source Code
Class : MainFrame.java




Source Code:
   private void formWindowActivated(java.awt.event.WindowEvent evt) {                                    
essen_obj.First_run
    }                                   
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                          
new BookIssueingForm().setVisible(true);       
    }                                         
    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                          
new submit_book().setVisible(true);        
    }                                         
    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
 new srch_books().setVisible(true);         
    }                                         
    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {                                          
new books_issued().setVisible(true);          
    }                                                                              
    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {                                          
new Book_Info().setVisible(true);       
    }                                         
    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {                                          
 new md_data().setVisible(true);         
    }                                          
    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {                                          
new Add_Book().setVisible(true);       
    }                                         
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
System.exit(0);       
    }

Class: Book_Info.java








S ource Code:
package library_manag;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import java.sql.*;
//Used Variables
ResultSet rs;
   private void formWindowOpened(java.awt.event.WindowEvent evt) {                                 
DefaultListModel lm = (DefaultListModel) jList1.getModel();
        try{
      String query ="SELECT Title From book_rec Order By Title desc;";
       rs=essen_obj.stmt.executeQuery(query);
       while(rs.next())
       {
       String tit  = rs.getString("Title");
       lm.add(0,tit);
       jList1.setModel(lm);
       }}
catch (Exception e)
     {
   JOptionPane.showMessageDialog(this, e.getMessage());
     }    } 
private void jList1MouseClicked(java.awt.event.MouseEvent evt) {                                   
String p=(String)jList1.getSelectedValue();
             try{
String query ="SELECT Ac_No,Title,Authors,publisher,Genre,year,Total_Copies-Copies_issued AS 'Cop_Left' From book_rec where Title='"+p+"' Order by Title asc;";
 rs=essen_obj.stmt.executeQuery(query);
       while(rs.next())  {
       String stat = rs.getString("Cop_Left");
       acL.setText(rs.getInt("Ac_No")+"");
       aL.setText(rs.getString("Authors"));
       bL.setText(rs.getString("Title"));
       pL.setText(rs.getString("publisher"));
       gL.setText(rs.getString("Genre"));
       yL.setText(rs.getInt("year")+"");
       if(stat.equals("0"))
       sL.setText("No Copies Left");
       else
       sL.setText(stat+" Copies Left");
}}
catch (Exception e) {
       JOptionPane.showMessageDialog(this, e.getMessage());
     }
eL.setText(null);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
if(sL.getText().equals("No Copies Left"))
eL.setText("<html> <font color=RED>No Copy Avlaible of this Book  ..Choose some other Book </font>");
else
{
       BookIssueingForm ps = new BookIssueingForm();
int ac = Integer.parseInt(acL.getText());
ps.setVisible(true);
ps.issfrm(ac);
} }

Class : srch_books.java
Source Code :
package library_manag;
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
private void RefBTNActionPerformed(java.awt.event.ActionEvent evt) {                                      
DefaultTableModel model =(DefaultTableModel)table.getModel();
String query=null;
if(tCB.isSelected() && sCB.isSelected())
query ="SELECT B.Ac_No,B.isr_type,B.Isr_Name,B.Is_on,B.Isrtc_Degs,B.St_cls,B.St_sec,B.Stud_Roll,A.Title,A.Publisher FROM book_rec A,Issuer_Details B where A.Ac_No = B.Ac_No;";
else
  if(sCB.isSelected())
query ="Select B.Ac_No,B.isr_type,B.Isr_Name,B.Is_on,B.Isrtc_Degs,B.St_cls,B.St_sec,B.Stud_Roll,A.Title,A.Publisher FROM book_rec A,Issuer_Details B where B.Isr_Type='Student' and A.Ac_No = B.Ac_No;";
    if(tCB.isSelected())
query ="Select B.Ac_No,B.isr_type,B.Isr_Name,B.Is_on,B.Isrtc_Degs,B.St_cls,B.St_sec,B.Stud_Roll,A.Title,A.Publisher FROM book_rec A,Issuer_Details B where B.Isr_Type='Teacher' and A.Ac_No = B.Ac_No;";
    }
tr{
 table.removeAll();
       ResultSet rs=essen_obj.stmt.executeQuery(query);
int x =table.getRowCount();
int p=0;
for(;x>p;++p)
{ model.removeRow(0); }
       while(rs.next())
       {
       int acNo  = rs.getInt("Ac_No");
       String tit = rs.getString("Title");
String pb = rs.getString("Publisher");
String it = rs.getString("Isr_Name");
Date g =rs.getDate("Is_on");
 String des = rs.getString("Isrtc_Degs");
int c = rs.getInt("St_cls");
       String sec = rs.getString("St_sec");
      
       model.addRow(new Object[] {acNo,tit,pb,it,g,des,c,sec});
       }}
catch (Exception e)
     {
       JOptionPane.showMessageDialog(this, e.getMessage());
     } 
    }

Class : Add_Book

package library_manag;
import javax.swing.JOptionPane;

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        try
{
     int acNo =Integer.parseInt(AcNTF.getText());
String tit =tTF.getText();
    String pub =puTF.getText();
   String auth =aTF.getText();
    int year = Integer.parseInt(yTF.getText());
   int pg = Integer.parseInt(pgTF.getText());
   int cop = Integer.parseInt(coTF.getText());
    int h = gnCB.getSelectedIndex();
    String genre = ckgenre.ckg(h);
        try{
String query="Insert into book_rec (`Ac_No`, `Title`, `Authors`, `Publisher`, `Genre`, `Pages`, `Total_Copies`, year)" +
        " values("+acNo+",'"+tit+"','"+auth+"','"+pub+"','"+genre+"',"+pg+","+cop+","+year+");";
   essen_obj.stmt.executeUpdate(query);
   JOptionPane.showMessageDialog (null,"Book Added");
}
     catch(Exception e)
      {
      JOptionPane.showMessageDialog (this, e.getMessage());
      }
    }
 catch(Exception ep)
      {
          JOptionPane.showMessageDialog (this,"Plz check the Data you Entered");
      }  }
Class : md_data.java

Source Code:

package library_manag;
import javax.swing.JOptionPane;
import java.sql.*;
//Used Variables and Methods
ResultSet rs;
void setData(Object x)
{
    AcNoTF.setText(x+"");
    jButton1.doClick();
    tTF.requestFocus();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
   try {
         String tag = AcNoTF.getText();
             String query = "Select * from book_rec where Ac_NO=" + tag + ";";
                 rs = essen_obj.stmt.executeQuery(query);
                while (rs.next()) {
                    acL.setText(rs.getInt("Ac_No") + "");
                    yL.setText(rs.getInt("year") + "");
                    nL.setText(rs.getString("Title"));
                    pL.setText(rs.getString("Publisher"));
                }
                 if(acL.getText().isEmpty())
                 {
                 jButton2.setEnabled(false);
                 jButton4.setEnabled(false);
                 }
                 else
                 {
                 jButton2.setEnabled(true);
                 jButton4.setEnabled(true);
                    
                 }
                 } catch (Exception ep) {
                JOptionPane.showMessageDialog(this, "The Accession No you entered is not valid");
                jButton2.setEnabled(false);
                 jButton4.setEnabled(false);
            }    }

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                            
   try
{
              int acNo =Integer.parseInt(acL.getText());
     String   tit =tTF.getText();
    String pub =puTF.getText();
    String auth =aTF.getText();
    int year = Integer.parseInt(yTF1.getText());
    int pg = Integer.parseInt(pgTF.getText());
    int cop = Integer.parseInt(yTF2.getText());
   int h = gnCB.getSelectedIndex();
     String genre = ckgenre.ckg(h);
        try{
String query="Update book_rec SET Title='"+tit+"',Authors='"+auth+"',Publisher='"+pub+"',Genre='"+genre+"',Pages="+pg+",Total_Copies="+cop+",year="+year+" Where Ac_No="+acNo+";";
   essen_obj.stmt.executeUpdate(query);
   JOptionPane.showMessageDialog (null,"Database Updated");
}
     catch(Exception e)
      {
          JOptionPane.showMessageDialog (this, e.getMessage());
      }}
 catch(Exception ep)
      {
          JOptionPane.showMessageDialog (this,"Plz check the Data you Entered");
      } }

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        try {
            String query = "Delete from book_rec where Ac_No=" + acL.getText() + ";";
            essen_obj.stmt.executeUpdate(query);
      JOptionPane.showMessageDialog (null,"Book Deleted");
      jButton3.doClick();
        }catch (SQLException ex) {
            Logger.getLogger(md_data.class.getName()).log(Level.SEVERE, null, ex);
        }}
Class : BookIssueingForm.java
Source Code:
package library_manag;
import javax.swing.JOptionPane;
import java.sql.*;
//Variables Used & Methods
Resultset Rs;
void issfrm(int x)
{
    AcNoTF.setText(x+"");
    jButton1.doClick();
    rTF.requestFocus();
}
void issfrm(Object x)
{
    AcNoTF.setText(x+"");
    jButton1.doClick();
    rTF.requestFocus();
}
try{
    int x = Integer.parseInt(AcNoTF.getText());
    try{
     String tag=AcNoTF.getText();
      String query="Select * from book_rec where Ac_NO="+tag+";";
      rs =essen_obj.stmt.executeQuery(query);
     
      int Cop1=8,cop2=9;
    while(rs.next())
       { 
           acL.setText(rs.getInt("Ac_No")+"");
yL.setText(rs.getInt("year")+"");
nL.setText(rs.getString("Title"));
        pL.setText(rs.getString("Publisher"));
        Cop1=rs.getInt("Total_Copies");
        cop2=rs.getInt("Copies_issued");}
      if(Cop1-cop2==0)
      { JOptionPane.showMessageDialog(this,"Ops !!! No Copy Of Book is left For Issueing");}
      else
      {
        nTF.setEnabled(true);
        rTF.setEnabled(true);
        cCB.setEnabled(true);
        sCB.setEnabled(true);
        Is.setEnabled(true);
        dTF.setEnabled(true);
        CB.setEnabled(true);
 }}
 catch(Exception ep)
 { JOptionPane.showMessageDialog (this,ep.getMessage());
 }}
catch(Exception e)
{ eL.setText(e.getMessage());}
   private void IsActionPerformed(java.awt.event.ActionEvent evt) {                                  
try{String rol = rTF.getText();
String clas =(String) cCB.getSelectedItem();
String sec = (String) sCB.getSelectedItem();
String name = nTF.getText();
String to = (String) CB.getSelectedItem();
Date dat = Date.valueOf(dTF.getText());
String dg = dTF1.getText();
try{String acN=AcNoTF.getText();
      String query,qry2;
      if(to.equals("Student"))
      { query="insert into issuer_details Values("+acN+",'Student','"+name+"','"+dat+"',NULL,"+clas+",'"+sec+"',"+rol+");";
     qry2 ="Update book_rec set Copies_issued = Copies_issued +1 Where Ac_No="+acN+";";
      }
      else
      {query="insert into issuer_details Values("+acN+",'Teacher','"+name+"','"+dat+"','"+dg+"',NULL,NULL,NULL);";
     qry2 ="Update book_rec set Copies_issued = Copies_issued +1 Where Ac_No="+acN+";";
      }
essen_obj.stmt.executeUpdate(query);
essen_obj.stmt.executeUpdate(qry2);
      JOptionPane.showMessageDialog (null,"Book Issued");
      jButton1.doClick();
}
catch(Exception e)
{JOptionPane.showMessageDialog(this, e.getMessage());
}}
catch(Exception ep)
{JOptionPane.showMessageDialog (this,"The Accession No you entered is not valid");}
Class : Submit_book.java
Source code:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
int ac = Integer.parseInt(acL.getText());
try{
String query="Update book_rec set Copies_issued = Copies_issued -1 Where Ac_No="+acL.getText()+";";
String qry2="Delete from issuer_details where Ac_No="+acL.getText()+" AND Is_on='"+pL4.getText()+"';";
 essen_obj.stmt.executeUpdate(query);
 essen_obj.stmt.executeUpdate(qry2);
   JOptionPane.showMessageDialog (null,"Book Submitted");
   dispose();
}
catch (Exception e)
{
JOptionPane.showMessageDialog (null,e.getMessage());
 } }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        try
{
int x = Integer.parseInt(AcNoTF.getText());
            try { String query;
                String tag = AcNoTF.getText();
                if(tRb.isSelected())
                query = "Select A.Title,A.Publisher,A.year,B.Ac_No,B.Isr_Name,B.Is_on,B.Isrtc_Degs,B.St_cls,B.st_sec,B.Stud_Roll from book_rec A,issuer_Details B where B.Ac_NO="+tag+" AND (A.Ac_No=B.Ac_No AND B.isr_type='Teacher');";
                else
query = "Select A.Title,A.Publisher,A.year,B.Ac_No,B.Isr_Name,B.Is_on,B.Isrtc_Degs,B.St_cls,B.st_sec,B.Stud_Roll from book_rec A,issuer_Details B where B.Ac_NO="+tag+" AND (A.Ac_No=B.Ac_No AND B.isr_type='Student' AND B.St_cls="+cTF.getText()+");";
ResultSet rs = essen_obj.stmt.executeQuery(query);
                while (rs.next()) {
                    acL.setText(rs.getInt("Ac_No") + "");
                    yL.setText(rs.getInt("year") + "");
                    nL.setText(rs.getString("Title"));
                    pL.setText(rs.getString("Publisher"));
                    pL1.setText(rs.getString("Isr_Name"));
                    pL5.setText(rs.getString("Isrtc_Degs"));
                    pL2.setText(rs.getString("St_cls"));
                    pL3.setText(rs.getString("St_sec"));
                    pL4.setText(rs.getString("Is_on"));
   }    if(pL1.getText().isEmpty())
else
                    jButton2.setEnabled(true);
            }
catch (Exception ep) {               JOptionPane.showMessageDialog(this,ep.getMessage()); }
        }
 catch (Exception e) {
            eL.setText("The Accession No you entered doesn't seems to be Right");}

Source code : essen_obj.java
package library_manag;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.*;
public class essen_obj {
    public static Connection con;
    public static Statement stmt;
    public static ResultSet rs;
    static void First_run() {
try {
        Class.forName("java.sql.Driver");
con = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","");
  stmt = (Statement) con.createStatement();
     } catch(Exception e){
 }}
 }
♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥!
The END
♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥! ♥!





3 comments: