7/31/2019 Railway Servation System
1/114
SUMMER TRAINING PROJECT
ON
RAILWAYS RESERVATION SYSTEM
AMITY UNIVERSITY, LUCKNOW
UNDER GUIDANCE OF:
Mrs. Nidhi Srivastava
DEPARTMENT OF A.I.I.T.
SUBMITTED BY:
JATIN SAXENA
RAGHUNATH SINGH
ADITYA PRATAP SINGH
Page 1 of 114
7/31/2019 Railway Servation System
2/114
CONTENTS
TOPIC
ABOUT THE PROJECT
OBJECTIVE
SYSTEM ANALYSIS
FEASIBILITY STUDY
HARDWARE AND SOFTWARE SPECIFICATIONS
VALIDATION CHECKS
TESTING
CODING
BIBLIOGRAPHY
Page 2 of 114
7/31/2019 Railway Servation System
3/114
ABOUT THE PROJECT
INTRODUCTION TO THE PROJECT:
The project has become a powerful tool for the exchange of information between the Administrator, Railway reservation centers, governmentoffices and of late the common people.
The project RAILWAY RESERVATION SYSTEM isdeveloped not only to maintain records but also to provide security tothem, which is being done by creating users and password. One cant do
any work in this project if he/she is not a user or they dont know the password.
The databases consist of adding, updating, searching and deletingtrains and even stations. Administrator can access to all the users he canadd more users and even delete anyone of them .
Page 3 of 114
7/31/2019 Railway Servation System
4/114
OBJECTIVE
THE BASIC AND MOST FUNDAMENTAL OBJECTIVE OF THIS PROJECTIS TO DEVELOP AND MAINTAIN A PROPER DATABASE OF RECORDSOF A RAILWAY RESERVATION SYSTEM WITH TRAIN NUMBER,TRAIN
NAME,TRAIN SOURCE,TRAIN DESTINATION,TRAIN TIME,TRAINTYPE,NUMBER OF SEATS(IN A.C. ,SLEEPER CLASS),TRAIN ROOT,TRAINDATE & DAY.THIS PROJECT INTERACTS WITH MOUSE TOO,ONE CAN
USE EITHER MOUSE OR NUMBERPAD TO CHOOSE A OPTION WHILEMENU IS SHOWN.
PROPER ENTRY SYSTEM OF THIS PROJECT GIVES THE CORRECTINFORMATION REGARDING TRAINS TO ANY USER.
Page 4 of 114
7/31/2019 Railway Servation System
5/114
SYSTEM ANALYSIS
The working of RAILWAY RESERVATION SYSTEM is that all the TRAIN NUMBER,TRAIN NAME,TRAIN SOURCE,TRAIN DESTINATION,TRAINTIME,TRAIN TYPE,NUMBER OF SEATS(IN A.C. ,SLEEPER CLASS) etc. aremaintained manually. Due to the peer pressure of working it becomes difficult tomaintain security and integrity of those data. Thus, to put a check on unauthorizedaccess we made users and their password to do any transaction with records.
NEEDS FOR COMPUTERIZED SYSTEM:
In order to sort out the problems described above Train Reservation system felt theneed for a system that not only work efficiently and secure but also be costeffective. Thinking all this and other, they decide to go fully and trulycomputerized. Therefore, they give us permission for developing system, whichcould enhance their work culture.
Page 5 of 114
7/31/2019 Railway Servation System
6/114
WORK HANDLED:
1. Maintained different users.
2. Administrator can access to any of the user.
3. Any user can be deleted by administrator; similarly any new user can becreated too.
4. Henceforth security of record is maintained, and as the database iscomputerized their integrity is also maintained.
5. Any transaction cant be made until it is being made by the user.
Page 6 of 114
7/31/2019 Railway Servation System
7/114
FEASIBILITY STUDY
After analyzing their requirement we conduct a feasibility study to know that
their requirements are feasible are not. Under feasibility study, we have tried toknow that what the users demonstrable needs are.
We find that we can be able to satisfy their most of the requirement. We canmaintain their database automated, we can reduce their operating cost time at aconsiderable instance. We concentrate our attention on these two primary areas of interest:
OPERATIONAL FEASIBILITY:
We have developed software for railway reservation system database. The
employee on the counter has very tedious work of maintaining the records of the trains available & the passenger too. The new system developed by usdrastically reduces the working effort. Therefore, they supported us very well.There was also sufficient support from the railway Administration too becausethe new system enhances the efficiency of the employees .
Page 7 of 114
7/31/2019 Railway Servation System
8/114
TECHNICAL FEASIBILITY:
There was not any technology in School so there was need for new system. Thesystem available in School has PIII processor & more than 10 GB HDD. Thiscapacity is sufficient for storage of data and smooth running of software.
Page 8 of 114
7/31/2019 Railway Servation System
9/114
Page 9 of 114
7/31/2019 Railway Servation System
10/114
HARDWARE PLATEFORM:
The following hardware components are used in developing the system: -
Processor : Pentium IV 3.0GHZ
RAM : 256MB
Monitor : LG Color Monitor
Mouse : Samsung Optical Muse
Keyboard : Samsung Keyboard
HDD : 80GB
Printer : Any (Preferred Laser Jet)
Page 10 of 114
7/31/2019 Railway Servation System
11/114
7/31/2019 Railway Servation System
12/114
VALIDATION CHECKS
This phase i s e s sen t i a l be fo re sys tem tes t ing . I t i nc ludes thecheck ing o f va l id i ty whe the r the en t ry to the sys tem i s va l id o r not .
We took some dummy da ta to check the va l id i ty o f the sys tem. I twas work ing we l l and as expec ted .
However, some log ica l e r ro r s were found ou t a f t e r runn ing thedummy da ta .
Al l the modules and fo rms , sub modules a re con ta in ing va l idfea tu res .
Page 12 of 114
7/31/2019 Railway Servation System
13/114
LEARNING CURVE:
Each project, when put into practice, demands some learning on the part of the user. Any project should be designed keeping in mindthe probable user of the system, the effort spent in learning the newsystem, so that they can comfortable with i t. This is in i tself a hefactor since it modifies the design, the tools used and the utili t ies
provided with the system. The new system can not be eve n assumedthat the persons interacting with system are computer il l i trates, theinterface should be designed so that they can easily familiarize andmaster the system. In short , the system should be that the effortspent in learning it should spell outs its worth. The learning curveshould not have a steep slope but a gradual one.
AVAILABILTY OF INFRASTRUCTURE:
Availab il ity o f inf rast ructure i s ano ther f ac to r tha t p lays animportant role in the deciding of the resulting model. A design thatfixes varied level of security, reliability and flexibility naturallydemands a processing power. This can be easily understood in theheight of concurrent accessing of the database. The number of user
accessing the database concurrently natural ly depends upon the processing power.
Page 13 of 114
7/31/2019 Railway Servation System
14/114
TESTING:
Testing of program consists of providing the program with a set of test slip I/p (or
test Cases) & opening if the program behaves expected. It means we set the
parameters After Making a system & see that it behaves as expected. If it is not the
condition Under which a failure accurse are noted for debugging & correction.
So the software testing is a critical element of software quality assurance &
Represents the ultimate review of specification, design and coding. During the
making of This project we have passed through some testing methods to be
assuring the result are as expected or not.
Page 14 of 114
7/31/2019 Railway Servation System
15/114
The methods are given below:
A)Unit testing B)Integration testing
C)System testing D)Acceptance testing
UNIT TESTING:
In the particular testing the individual units were tested individually with raw data.The result obtained was checked. The validation of the data entered was also testedfor all the data elements. In this testing we have discovered the syntactical errors or semantics errors. One thing is important in that testing is that each unit wasindividually tested, without keeping in mind the inherent interaction between theunits. Each unit was tested at the time of coding itself.
INTEGARTION TESTING:
After the individual tests of each unit, these are integrated & the tested for validitycheck that conjointly these units giving the expected result or not. Basically thistesting was done to test the design of the system.
Page 15 of 114
7/31/2019 Railway Servation System
16/114
SYSTEM TESTING:
After the integration testing the system testing was done. It was done to test therequirement specification of the system. In this testing the whole system was testedat once against some parameters.
ACCEPTANCE TESTING:
More finally the acceptance testing was done. This testing was done with the actualdata by the user for their kind acceptance. This testing has done for the userssatisfaction.
Page 16 of 114
7/31/2019 Railway Servation System
17/114
Page 17 of 114
7/31/2019 Railway Servation System
18/114
// admininfo.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class admininfo extends JFrame implements ActionListener, FocusListener,MouseListener
{
JFrame frmainfo;
JPanel pnlainfo,pnlitrain,pnlcancelt,pnlmem;
JLabellblahinfo,lbltno,lbltname,lbltsource,lbltdest,lblttime,lblttype,lblsleeper,lblseat,lblvia,lbldays;
JTextFieldtxttno,txttname,txttsource,txttdest,txtttime,txtsleeper,txtseat,txtvia1,txtvia2,txtttype;
Checkbox day1,day2,day3,day4,day5,day6,day7;
JButton btncreate,btncancel,btnclear;
JMenu menuadmin;
JMenuItem mnuctrain,mnuutrain,mnucmem,mnubook;
JMenuBar mb;
int flag;
Stringstrtno,strtname,strtsource,strtdest,strttime,strfareac,strfaresleeper,strttype,strsac,strssleeper,strvia1,strvia2,strd1,strd2,strd3,strd4,strd5,strd6,strd7;
String intd1,intd2,intd3,intd4,intd5,intd6,intd7;
String strmemname,strmempass,strmememail,strmemadd,strmemmo;
Connection conn;
Page 18 of 114
7/31/2019 Railway Servation System
19/114
Statement stmt;
ResultSet rs;
JLabellblmemhead,lblmemname,lblmempass,lblmememail,lblmemadd,lblmemmo;
JTextField txtmemname,txtmememail,txtmemadd,txtmemmo;
JPasswordField txtmempass;
JButton btncmem,btnmemclear,btnmemcancel;
Color current,chosen;
JColorChooser chooser;
ActionListener okListener;
int toglebf=0;
public admininfo()
{
frmainfo=new JFrame("Adminstrator");
pnlainfo=new JPanel();
pnlitrain=new JPanel();
pnlcancelt=new JPanel();
pnlmem=new JPanel();
menuadmin=new JMenu("Admin");
mnuctrain=new JMenuItem("Create Train");
mnuutrain=new JMenuItem("Update Train");
mnucmem=new JMenuItem("Create Member");
mnubook=new JMenuItem("Book Ticket");
menuadmin.add(mnuctrain);
Page 19 of 114
7/31/2019 Railway Servation System
20/114
menuadmin.add(mnuutrain);
menuadmin.add(mnucmem);
menuadmin.add(mnubook);
mb=new JMenuBar();
mb.add(menuadmin);
frmainfo.setJMenuBar(mb);
mnuctrain.addActionListener(this);
mnuutrain.addActionListener(this);
mnucmem.addActionListener(this);
mnubook.addActionListener(this);
lblmemhead=new JLabel("Welcome",JLabel.CENTER);
lblmemhead.setFont(new Font("Times new roman",Font.ITALIC,30));
lblmemname=new JLabel(" User Name");
lblmempass=new JLabel("Password");
lblmememail=new JLabel("Email");
lblmemadd=new JLabel("Address");
lblmemmo=new JLabel("Contact No");
txtmemname=new JTextField(20);
txtmempass=new JPasswordField(20);
txtmememail=new JTextField(20);
txtmemadd=new JTextField(20);
txtmemmo=new JTextField(20);
btncmem=new JButton("Submit");
Page 20 of 114
7/31/2019 Railway Servation System
21/114
btnmemclear=new JButton("Clear");
btnmemcancel=new JButton("Cancel");
btncmem.addActionListener(this);btnmemclear.addActionListener(this);
btnmemcancel.addActionListener(this);
pnlmem.setLayout(null);
lblmemhead.setBounds(5,5,590,30);
lblmemname.setBounds(150,100,100,25);
lblmempass.setBounds(150,135,100,25);
lblmememail.setBounds(150,170,100,25);
lblmemadd.setBounds(150,205,100,25);
lblmemmo.setBounds(150,240,100,25);
txtmemname.setBounds(300,100,150,25);
txtmempass.setBounds(300,135,150,25);
txtmememail.setBounds(300,170,150,25);
txtmemadd.setBounds(300,205,150,25);
txtmemmo.setBounds(300,240,150,25);
btncmem.setBounds(155,275,80,25);
btnmemclear.setBounds(250,275,80,25);
btnmemcancel.setBounds(345,275,80,25);
Page 21 of 114
7/31/2019 Railway Servation System
22/114
pnlmem.add(lblmemhead);
pnlmem.add(lblmemname);
pnlmem.add(lblmempass);
pnlmem.add(lblmememail);pnlmem.add(lblmemadd);
pnlmem.add(lblmemmo);
pnlmem.add(txtmemname);
pnlmem.add(txtmempass);
pnlmem.add(txtmememail);
pnlmem.add(txtmemadd);
pnlmem.add(txtmemmo);
pnlmem.add(btncmem);
pnlmem.add(btnmemclear);
pnlmem.add(btnmemcancel);
pnlmem.setBounds(5,5,590,390);
pnlmem.setVisible(false);
lblahinfo=new JLabel("Welcome Administrator",JLabel.CENTER);
lbltno=new JLabel("Train no");
lbltname=new JLabel("Train Name");
lbltsource=new JLabel("Train Source");
lbltdest=new JLabel("Train Destination");
lblttime=new JLabel("Train Time");
lblttype=new JLabel("Train Type");
Page 22 of 114
7/31/2019 Railway Servation System
23/114
lblsleeper=new JLabel("No. of Seat in AC");
lblseat=new JLabel("No. of Seat in Sleeper");
lblvia=new JLabel("Root");
lbldays=new JLabel("Days");
lblahinfo.setFont(new Font("Times new roman",Font.ITALIC,30));
txttno=new JTextField(5);
txttname=new JTextField(20);
txttsource=new JTextField(20);
txttdest=new JTextField(20);
txtttime=new JTextField(5);
txtsleeper=new JTextField(3);
txtseat=new JTextField(3);
txtvia1=new JTextField(15);
txtvia2=new JTextField(15);
txtttype=new JTextField(10);
day1=new Checkbox("Sun");
day2=new Checkbox("Mon");
day3=new Checkbox("Tue");
day4=new Checkbox("Wed");
day5=new Checkbox("Thu");
day6=new Checkbox("Fri");
day7=new Checkbox("Sat");
btncreate=new JButton("Submit");
btncancel=new JButton("Cancel");
Page 23 of 114
7/31/2019 Railway Servation System
24/114
btnclear=new JButton("Clear");
btncreate.addActionListener(this);
btncancel.addActionListener(this);btnclear.addActionListener(this);
pnlitrain.setLayout(null);
lblahinfo.setBounds(5,5,590,30);
lbltno.setBounds(80,100,100,25);
lbltname.setBounds(280,100,100,25);
lbltsource.setBounds(80,135,100,25);
lbltdest.setBounds(290,135,100,25);
lblttime.setBounds(80,170,100,25);
lblttype.setBounds(280,170,100,25);
lblsleeper.setBounds(80,205,130,25);
lblseat.setBounds(290,205,130,25);
lblvia.setBounds(80,240,100,25);
lbldays.setBounds(80,275,60,25);
txttno.setBounds(190,100,80,25);
txttname.setBounds(390,100,100,25);
txttsource.setBounds(190,135,90,25);
txttdest.setBounds(400,135,90,25);
txtttime.setBounds(190,170,80,25);
txtsleeper.setBounds(220,205,40,25);
txtseat.setBounds(440,205,40,25);
txtvia1.setBounds(190,240,140,25);
Page 24 of 114
7/31/2019 Railway Servation System
25/114
txtvia2.setBounds(350,240,140,25);
txtttype.setBounds(380,170,110,25);
day1.setBounds(145,275,50,25);day2.setBounds(190,275,50,25);
day3.setBounds(245,275,50,25);
day4.setBounds(300,275,50,25);
day5.setBounds(355,275,50,25);
day6.setBounds(410,275,50,25);
day7.setBounds(465,275,50,25);
btncreate.setBounds(140,310,80,25);
btncancel.setBounds(360,310,80,25);
btnclear.setBounds(250,310,80,25);
pnlitrain.add(lblahinfo);
pnlitrain.add(lbltno);
pnlitrain.add(lbltname);
pnlitrain.add(lbltsource);
pnlitrain.add(lbltdest);
pnlitrain.add(lblttime);
pnlitrain.add(lblttype);
pnlitrain.add(lblsleeper);
pnlitrain.add(lblseat);
pnlitrain.add(lblvia);
pnlitrain.add(lbldays);
pnlitrain.add(txttno);
Page 25 of 114
7/31/2019 Railway Servation System
26/114
pnlitrain.add(txttname);
pnlitrain.add(txttsource);
pnlitrain.add(txttdest);
pnlitrain.add(txtttime);pnlitrain.add(txtsleeper);
pnlitrain.add(txtseat);
pnlitrain.add(txtvia1);
pnlitrain.add(txtvia2);
pnlitrain.add(txtttype);
pnlitrain.add(day1);
pnlitrain.add(day2);
pnlitrain.add(day3);
pnlitrain.add(day4);
pnlitrain.add(day5);
pnlitrain.add(day6);
pnlitrain.add(day7);
pnlitrain.add(btncreate);
pnlitrain.add(btncancel);
pnlitrain.add(btnclear);
pnlitrain.setBounds(5,5,590,390);
pnlainfo.setLayout(null);
pnlainfo.add(pnlitrain);
pnlainfo.add(pnlmem);
Page 26 of 114
7/31/2019 Railway Servation System
27/114
frmainfo.getContentPane().add(pnlainfo);
frmainfo.setSize(600,400);
frmainfo.setLocation(200,150);
frmainfo.setVisible(true);
txttno.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txttname.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
Page 27 of 114
7/31/2019 Railway Servation System
28/114
e.consume();
}
}
});txttsource.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txttdest.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
Page 28 of 114
7/31/2019 Railway Servation System
29/114
});
txtsleeper.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e){
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txtseat.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txtvia1.addKeyListener(new KeyAdapter()
{
Page 29 of 114
7/31/2019 Railway Servation System
30/114
7/31/2019 Railway Servation System
31/114
chosen = chooser.getColor();
current=chosen;
}
}; //********************************************************************
frmainfo.addMouseListener(this);
pnlainfo.addMouseListener(this);
pnlitrain.addMouseListener(this);
pnlcancelt.addMouseListener(this);
pnlmem.addMouseListener(this);
lblahinfo.addMouseListener(this);
lbltno.addMouseListener(this);
lbltname.addMouseListener(this);
lbltsource.addMouseListener(this);
lbltdest.addMouseListener(this);
lblttime.addMouseListener(this);
lblttype.addMouseListener(this);
lblsleeper.addMouseListener(this);
lblseat.addMouseListener(this);
lblvia.addMouseListener(this);
lbldays.addMouseListener(this);
txttno.addMouseListener(this);
txttname.addMouseListener(this);
txttsource.addMouseListener(this);
txttdest.addMouseListener(this);
txtttime.addMouseListener(this);
txtsleeper.addMouseListener(this);
txtseat.addMouseListener(this);
Page 31 of 114
7/31/2019 Railway Servation System
32/114
txtvia1.addMouseListener(this);
txtvia2.addMouseListener(this);
txtttype.addMouseListener(this);
day1.addMouseListener(this);day2.addMouseListener(this);
day3.addMouseListener(this);
day4.addMouseListener(this);
day5.addMouseListener(this);
day6.addMouseListener(this);
day7.addMouseListener(this);
btncreate.addMouseListener(this);
btncancel.addMouseListener(this);
btnclear.addMouseListener(this);
lblmemhead.addMouseListener(this);
lblmemname.addMouseListener(this);
lblmempass.addMouseListener(this);
lblmememail.addMouseListener(this);
lblmemadd.addMouseListener(this);
lblmemmo.addMouseListener(this);
txtmemname.addMouseListener(this);
txtmememail.addMouseListener(this);
txtmemadd.addMouseListener(this);
txtmemmo.addMouseListener(this);
txtmempass.addMouseListener(this);
btncmem.addMouseListener(this);
btnmemclear.addMouseListener(this);
btnmemcancel.addMouseListener(this);
Page 32 of 114
7/31/2019 Railway Servation System
33/114
//*********************************************************************
}
public void mouseClicked(MouseEvent e){
int clickcount=e.getClickCount();
if(clickcount==2)
{
chooser = new JColorChooser(current != null ?current:Color.WHITE);
JDialog dialog = JColorChooser.createDialog(this,"Choose aColour",true,chooser,okListener,null);
dialog.setVisible(true);
Component obj=e.getComponent();
if(obj==pnlainfo||obj==pnlitrain||obj==pnlcancelt||obj==pnlmem||obj==frmainfo)
{
obj.setBackground(chosen);
}
else
{
obj.setForeground(chosen);
}
}
}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
Page 33 of 114
7/31/2019 Railway Servation System
34/114
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void actionPerformed(ActionEvent ae)
{if(ae.getSource()==mnuctrain)
{
flag=0;
pnlainfo.setVisible(true);
btncreate.setText("Submit");
pnlitrain.setVisible(true);
pnlmem.setVisible(false);
enablefields();
}
if(ae.getSource()==mnuutrain)
{
flag=1;
pnlainfo.setVisible(true);
disablefields();
txttno.addFocusListener(this);
btncreate.setText("UpDate");
pnlitrain.setVisible(true);
pnlmem.setVisible(false);
}
if(ae.getSource()==mnucmem)
{
pnlainfo.setVisible(true);
pnlmem.setVisible(true);
pnlitrain.setVisible(false);
Page 34 of 114
7/31/2019 Railway Servation System
35/114
}
if(ae.getSource()==mnubook)
{
new PReservation();}
if(ae.getSource()==btncreate)
{
createtrain();
}
if(ae.getSource()==btncancel)
{
pnlainfo.setVisible(false);
}
if(ae.getSource()==btnclear)
{
clearfields();
}
if(ae.getSource()==btncmem)
{
try
{
createmem();
clearmemdata();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Note",2);
Page 35 of 114
7/31/2019 Railway Servation System
36/114
}
}
if(ae.getSource()==btnmemcancel)
{pnlainfo.setVisible(false);
}
if(ae.getSource()==btnmemclear)
{
clearmemdata();
}
}
public void focusGained (FocusEvent fe)
{
}
public void focusLost (FocusEvent fe)
{
if(fe.getSource()==txttno)
{
try
{
focustno();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Note",2);
}
Page 36 of 114
7/31/2019 Railway Servation System
37/114
}
}
public void createtrain(){
if(flag==0)
{
try
{
enablefields();
txttno.removeFocusListener(this);
connection();
intd1=intd2=intd3=intd4=intd5=intd6=intd7="N";
taketraininfo();
rs=stmt.executeQuery("Select * from Trains wheretno='"+strtno+"'");
if(rs.next())
{
JOptionPane.showMessageDialog(null,"Train no.already exist!!!","Note",2);
}
else
{
strfareac=JOptionPane.showInputDialog(null,"Get Fare of the AC Seats inTrain","Fare",2);
strfaresleeper=JOptionPane.showInputDialog(null,"Get Fare of the Sleeper Seats inTrain","Fare",2);
Page 37 of 114
7/31/2019 Railway Servation System
38/114
if(strfareac.length()==0||strfaresleeper.length()==0)
{
return;
}
else
{
String sqli = "INSERT INTO Trains(tno,tname,tsource,tdest,ttime,fareac,faresleeper,ttype,ac,sleeper,via1,via2,day1,day2,day3,day4,day5,day6,day7) "+" VALUES('"+strtno+"','"+strtname+"','"+strtsource+"','"+strtdest+"','"+strttime+"','"+strfareac+"','"+strfaresleeper+"','"+str ttype+"','"+strsac+"','"+strssleeper+"','"+strvia1+"','"+strvia2+"','"+intd1+"','"+intd2+"','"+intd3+"','"+intd4+"','"+intd5+"','"+intd6+"','"+intd7+"')";
System.out.println("!");
stmt.executeUpdate(sqli);
System.out.println("2");
rs=stmt.executeQuery("Select * fromlocation where source='"+strtsource+"'");
rs=stmt.executeQuery("Select * fromlocation where dest='"+strtdest+"'");
if(rs.next()){}
if(rs.next()){}
stmt.executeUpdate("INSERT INTOlocation (source,dest) "+" VALUES ('"+strtsource+"','"+strtdest+"')");
clearfields();
}
}
}
catch(Exception e)
{
Page 38 of 114
7/31/2019 Railway Servation System
39/114
JOptionPane.showMessageDialog(null,e,"Note 5",2);
}
}
if(flag==1){
try
{
connection();
intd1=intd2=intd3=intd4=intd5=intd6=intd7="N";
taketraininfo();
String sqlu = "UPDATE Trains " + "SET tname ='"+strtname+"', tsource = '"+strtsource+"', tdest = '"+strtdest+"', ttime = '"+strttime+"', ttype ='"+strttype+"',ac='"+strsac+"',sleeper='"+strssleeper+"',via1='"+strvia1+"',via2='"+strvia2+"',day1='"+intd1+"',day2='"+intd2+"',day3='"+intd3+"',day4='"+intd4+"',day5='"+intd5+"',day6='"+intd6+"',day7='"+intd7+"'"+"Where tno ='"+strtno+"'" ;
stmt.executeUpdate(sqlu);
clearfields();
disablefields();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Note 6",2);
}
}
}
public void createmem()
{
Page 39 of 114
7/31/2019 Railway Servation System
40/114
try
{
connection();
takememdata();rs=stmt.executeQuery("Select * from Users where
name='"+strmemname+"'");
if(rs.next())
{
JOptionPane.showMessageDialog(null,"Member AlreadyExist!!!","Note",2); }
else
{
String sqli="INSERT INTO Users(name,pass,email,add,mo) "+" VALUES('"+strmemname+"','"+strmempass+"','"+strmememail+"','"+strmemadd+"','"+strmemmo+"')";
stmt.executeUpdate(sqli);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Note",2);
}
}
public void taketraininfo()
{
strtno=txttno.getText();
Page 40 of 114
7/31/2019 Railway Servation System
41/114
strtname=txttname.getText();
strtsource=txttsource.getText();
strtdest=txttdest.getText();
strttime=txtttime.getText();strttype=txtttype.getText();
strsac=txtsleeper.getText();
strssleeper=txtseat.getText();
strvia1=txtvia1.getText();
strvia2=txtvia2.getText();
strd1=day1.getLabel();if(day1.getState()){intd1="Y";}
strd2=day2.getLabel();if(day2.getState()){intd2="Y";}
strd3=day3.getLabel();if(day3.getState()){intd3="Y";}
strd4=day4.getLabel();if(day4.getState()){intd4="Y";}
strd5=day5.getLabel();if(day5.getState()){intd5="Y";}
strd6=day6.getLabel();if(day6.getState()){intd6="Y";}
strd7=day7.getLabel();if(day7.getState()){intd7="Y";}
System.out.println("Day1 "+intd1+"\nDay2 "+intd2+"\nDay3"+intd3+"\nDay4 "+intd4+"\nDay 5"+intd5+"\nDay 6"+intd6+"\n Day 7"+intd7);
}
public void clearfields()
{
txttno.setText("");
txttname.setText("");
txttsource.setText("");
txttdest.setText("");
txtttime.setText("");
txtttype.setText("");
txtsleeper.setText("");
Page 41 of 114
7/31/2019 Railway Servation System
42/114
txtseat.setText("");
txtvia1.setText("");
txtvia2.setText("");
day1.setState(false);day2.setState(false);
day3.setState(false);
day4.setState(false);
day5.setState(false);
day6.setState(false);
day7.setState(false);
}
public void focustno()
{
try
{
connection();
rs=stmt.executeQuery("select * from Trains wheretno='"+txttno.getText()+"'");
if(rs.next())
{
enablefields();
strtno=rs.getString("tno");txttno.setText(strtno);
strtname=rs.getString("tname");txttname.setText(strtname);
strtsource=rs.getString("tsource");txttsource.setText(strtsource);
strtdest=rs.getString("tdest");txttdest.setText(strtdest);
strttime=rs.getString("ttime"); txtttime.setText(strttime);
strttype=rs.getString("ttype"); txtttype.setText(strttype);
Page 42 of 114
7/31/2019 Railway Servation System
43/114
strsac=rs.getString("sleeper");txtsleeper.setText(strsac);
strssleeper=rs.getString("seat");txtseat.setText(strssleeper);
strvia1=rs.getString("via1"); txtvia1.setText(strvia1);
strvia2=rs.getString("via2"); txtvia2.setText(strvia2);
intd1=rs.getString("day1");if(intd1.equals("Y")){day1.setState(true);}
intd2=rs.getString("day2");if(intd2.equals("Y")){day2.setState(true);}
intd3=rs.getString("day3");if(intd3.equals("Y")){day3.setState(true);}
intd4=rs.getString("day4");if(intd4.equals("Y")){day4.setState(true);}
intd5=rs.getString("day5");if(intd5.equals("Y")){day5.setState(true);}
intd6=rs.getString("day6");if(intd6.equals("Y")){day6.setState(true);}
intd7=rs.getString("day7");if(intd7.equals("Y")){day7.setState(true);}
enablefields();
}
else
{
JOptionPane.showMessageDialog(null,"Train No. isIncorrect","Note",2);
clearfields();
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Note",2);
Page 43 of 114
7/31/2019 Railway Servation System
44/114
}
}
public void disablefields()
{txttno.setEditable(true);
txttname.setEditable(false);
txttsource.setEditable(false);
txttdest.setEditable(false);
txtttime.setEditable(false);
txtttype.setEditable(false);
txtsleeper.setEditable(false);
txtseat.setEditable(false);
txtvia1.setEditable(false);
txtvia2.setEditable(false);
}
public void enablefields()
{
txttno.setEditable(true);
txttname.setEditable(true);
txttsource.setEditable(true);
txttdest.setEditable(true);
txtttime.setEditable(true);
txtttype.setEditable(true);
txtsleeper.setEditable(true);
txtseat.setEditable(true);
txtvia1.setEditable(true);
txtvia2.setEditable(true);
}
Page 44 of 114
7/31/2019 Railway Servation System
45/114
public void takememdata()
{
strmemname=txtmemname.getText();
strmempass=txtmempass.getText();strmememail=txtmememail.getText();
strmemadd=txtmemadd.getText();
strmemmo=txtmemmo.getText();
}
public void clearmemdata()
{
txtmemname.setText("");
txtmempass.setText("");
txtmememail.setText("");
txtmemadd.setText("");
txtmemmo.setText("");
}
public void connection()
{
String url = "jdbc:odbc:RR";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
System.out.println("Databse Connected!!!");
}
catch(SQLException sqlExcep)
Page 45 of 114
7/31/2019 Railway Servation System
46/114
{}
catch(ClassNotFoundException clsnotfndExcep)
{
System.out.println("ERROR " + clsnotfndExcep);}
}
public static void main(String args[])
{
try
{
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception e)
{}
admininfo adminif=new admininfo();
}
}
// RReservation.javaPage 46 of 114
7/31/2019 Railway Servation System
47/114
import java.awt.*;
import java.sql.*;
import java.util.*;
import java.util.Vector;import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.awt.PrintJob.*;
import javax.swing.border.*;
import java.sql.SQLException;
public class PReservation extends JFrame implements ActionListener,FocusListener,MouseListener
{
JFrame frmtinfo;
JPanel pnltinfo,pnltaval,pnltbook,pnlinfo;
JMenu menutaval;
JMenuItemmnutaval,mnutbook,mnutfind,mnucticket,mnucacticket,mnuprint,mnuprintac;
JMenuBar mb;
JLabel lbltinfo,lbltsource,lbltdest,lbltdate;
JComboBox cbsource,cbdest,cbday,cbmonth,cbyear;
JButton btnsearcht;
Connection conn,conn1;
Statement stmt,stmt1;
ResultSet rs;
String url = "jdbc:odbc:RR";
Stringstrseatpn,gender,strtype,dateb,strdeboard,strboard,strname,stradd,strage,strphone,strtno,strno,strnos,strseatnop,data,stramount,strtime;
int pseat1,pseat2,amount;
Page 47 of 114
7/31/2019 Railway Servation System
48/114
String Billid="";
Vector dataRows=new Vector();
Vector dataRowsid=new Vector();
int columns = 0;int rowcount = 0;
int rowsLoaded = 0;
int chkavalseatac=0;
int chkavalseatsleeper=0;
int chkseatorgac=0;
int chkseatorgsleeper=0;
int ctr = 1;
int ctrid=1;
int n=1;
int coln=0;
int colnid=0;
int vectNum=0;
int rec=0;
int recid=0;
int flag=0;
int i=0;
String [][]avaltrain;
String[] rowData;String[] rowDataid;
JTable tbltrain;
//////////////
JLabel lbltno,lbljdate;
JTextField txtno,txtday,txtmonth,txtyear;
JButton btnsubmit;
JScrollPane scrollpane;
Page 48 of 114
7/31/2019 Railway Servation System
49/114
//////////////////
JLabellblhbook,lblname,lbladd,lblage,lblgender,lblphone,lblboarding,lbltrainno,lblseattype,lblnos,lbldate;
JTextField
txtname,txtage,txtphone,txttrainno,txtnos,txtdayb,txtmonthb,txtyearb;
JTextArea txtadd;
Checkbox cbm,cbf,cbsleeper,cbac;
JComboBox cbboarding,cbdeboarding;
CheckboxGroup cbg,cbg1;
JButton btnbook,btnbcancel;
////////////////////////////
Color current,chosen;
JColorChooser chooser;
ActionListener okListener;
public PReservation()
{
frmtinfo=new JFrame("Trains Informaion");
pnltinfo=new JPanel();
pnlinfo=new JPanel();
menutaval=new JMenu("Train");
mnutaval=new JMenuItem("Seat Availablity");
mnutbook=new JMenuItem("Seat Booking");
mnutfind=new JMenuItem("Find Train");
mnucticket=new JMenuItem("Cancel Ticket");
mnucacticket=new JMenuItem("Cancel AC Ticket");
mnuprint=new JMenuItem("Print Ticket");
mnuprintac=new JMenuItem("Print AC Ticket");
menutaval.add(mnutfind);
Page 49 of 114
7/31/2019 Railway Servation System
50/114
menutaval.add(mnutaval);
menutaval.add(mnutbook);
menutaval.add(mnucticket);
menutaval.add(mnucacticket);menutaval.add(mnuprint);
menutaval.add(mnuprintac);
mb=new JMenuBar();
mb.add(menutaval);
frmtinfo.setJMenuBar(mb);
mnutfind.addActionListener(this);
mnutaval.addActionListener(this);
mnutbook.addActionListener(this);
mnucticket.addActionListener(this);
mnucacticket.addActionListener(this);
mnuprint.addActionListener(this);
mnuprintac.addActionListener(this);
lbltinfo=new JLabel("Trains Information",JLabel.CENTER);
lbltinfo.setFont(new Font("Times new roman",Font.ITALIC,30));
lbltsource=new JLabel("Train Source");
lbltdest=new JLabel("Train Destination");
lbltdate=new JLabel("Date(dd|mm|yyyy)");
lbltsource.setFont(new Font("Times new roman",0,14));
lbltdest.setFont(new Font("Times new roman",0,14));
lbltdate.setFont(new Font("Times new roman",0,14));
//btnsearcht.setFont(new Font("Times new roman",Font.BOLD,12));
avaltrain=new String[100][6];
cbday=new JComboBox();
cbsource=new JComboBox();
Page 50 of 114
7/31/2019 Railway Servation System
51/114
cbdest=new JComboBox();
for(int i=1;i
7/31/2019 Railway Servation System
52/114
{
System.out.println("Error:"+e);
}
btnsearcht=new JButton("Search Train");pnltinfo.setLayout(null);
lbltinfo.setBounds(10,10,580,35);
lbltsource.setBounds(175,100,100,25);
lbltdest.setBounds(175,135,100,25);
lbltdate.setBounds(175,170,110,25);
cbsource.setBounds(325,100,120,25);
cbdest.setBounds(325,135,120,25);
cbday.setBounds(325,170,35,25);
cbmonth.setBounds(360,170,35,25);
cbyear.setBounds(395,170,50,25);
btnsearcht.setBounds(260,205,120,25);
pnlinfo.setLayout(null);
pnlinfo.add(lbltinfo);
pnlinfo.add(lbltsource);
pnlinfo.add(lbltdest);
pnlinfo.add(lbltdate);
pnlinfo.add(cbsource);
pnlinfo.add(cbdest);
pnlinfo.add(cbday);
pnlinfo.add(cbmonth);
pnlinfo.add(cbyear);
pnlinfo.add(btnsearcht);
btnsearcht.addActionListener(this);
Page 52 of 114
7/31/2019 Railway Servation System
53/114
///////////////////////////////////////////////////////////////
pnltbook=new JPanel();
lblhbook=new JLabel("Seat Booking Form",JLabel.CENTER);
lblhbook.setFont(new Font("Times new roman",Font.ITALIC,30));lblname=new JLabel("Full Name");
lbladd=new JLabel("Address");
lblage=new JLabel("Age");
lblgender=new JLabel("Gender");
lblphone=new JLabel("Contact No,");
lblboarding=new JLabel("Boarding At");
lbltrainno=new JLabel("Train no");
lblseattype=new JLabel("Destination");
lblnos=new JLabel("How much Seat?");
lbldate=new JLabel("Journey Date");
txtname=new JTextField(20);
txtadd=new JTextArea(20,90);
txtage=new JTextField(2);
txtphone=new JTextField(10);
txttrainno=new JTextField(5);
txtnos=new JTextField(2);
txtdayb=new JTextField(2);
txtmonthb=new JTextField(2);
txtyearb=new JTextField(5);
cbg=new CheckboxGroup();
cbg1=new CheckboxGroup();
cbm=new Checkbox("Male",cbg,true);
Page 53 of 114
7/31/2019 Railway Servation System
54/114
cbf=new Checkbox("FeMale",cbg,false);
cbsleeper=new Checkbox("Sleeper",cbg1,false);
cbac=new Checkbox("AC",cbg1,true);
cbboarding=new JComboBox();cbdeboarding=new JComboBox();
btnbook=new JButton("Book Seat");
btnbcancel=new JButton("Cancel");
pnltbook.setLayout(null);
lblhbook.setBounds(50,5,550,30);
lblname.setBounds(150,50,100,25);
lbladd.setBounds(150,80,100,25);
lblage.setBounds(150,110,50,25);
lblgender.setBounds(290,110,80,25);
lblphone.setBounds(150,140,100,25);
lbltrainno.setBounds(150,170,100,25);
lblboarding.setBounds(150,200,100,25);
lblseattype.setBounds(150,230,100,25);
lblnos.setBounds(150,260,100,25);
lbldate.setBounds(150,290,100,25);
txtname.setBounds(250,50,150,25);
txtadd.setBounds(250,80,150,25);
txtage.setBounds(250,110,25,25);
txtphone.setBounds(250,140,100,25);
txttrainno.setBounds(250,170,50,25);
txtnos.setBounds(250,260,30,25);
txtdayb.setBounds(250,290,25,25);
txtmonthb.setBounds(280,290,25,25);
txtyearb.setBounds(310,290,50,25);
Page 54 of 114
7/31/2019 Railway Servation System
55/114
7/31/2019 Railway Servation System
56/114
pnltbook.add(cbm);
pnltbook.add(cbf);
pnltbook.add(cbsleeper);
pnltbook.add(cbac);pnltbook.add(cbboarding);
pnltbook.add(cbdeboarding);
pnltbook.add(btnbook);
pnltbook.add(btnbcancel);
btnbook.addActionListener(this);
btnbcancel.addActionListener(this);
pnltbook.setBounds(5,0,590,480);
txtname.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txtage.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
Page 56 of 114
7/31/2019 Railway Servation System
57/114
{
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txtphone.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txttrainno.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
Page 57 of 114
7/31/2019 Railway Servation System
58/114
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txtnos.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txtdayb.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
Page 58 of 114
7/31/2019 Railway Servation System
59/114
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txtmonthb.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
}
}
});
txtyearb.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
Page 59 of 114
7/31/2019 Railway Servation System
60/114
getToolkit().beep();
e.consume();
}}});
txttrainno.addFocusListener(this);/////////////////////////////////
pnltaval=new JPanel();
lbltno=new JLabel("Train no:");
lbljdate=new JLabel("Journey Date");
txtno=new JTextField(5);
txtday=new JTextField(2);
txtmonth=new JTextField(2);
txtyear=new JTextField(4);
lbltno.setFont(new Font("Tahoma",0,13));
lbljdate.setFont(new Font("Tahoma",0,13));
txtno.setFont(new Font("Tahoma",0,13));
txtday.setFont(new Font("Tahoma",0,13));
txtmonth.setFont(new Font("Tahoma",0,13));
txtyear.setFont(new Font("Tahoma",0,13));
btnsubmit=new JButton("Submit");
pnltaval.setLayout(null);
lbltno.setBounds(40,50,100,25);
lbljdate.setBounds(40,80,100,25);
txtno.setBounds(150,50,50,25);
txtday.setBounds(150,80,25,25);
txtmonth.setBounds(180,80,25,25);
txtyear.setBounds(210,80,50,25);
btnsubmit.setBounds(170,110,75,25);
Page 60 of 114
7/31/2019 Railway Servation System
61/114
pnltaval.setBorder(new TitledBorder("Seat Availablity Information"));
pnltaval.setBounds(170,90,250,150);
pnltaval.add(lbltno);
pnltaval.add(lbljdate);pnltaval.add(txtno);
pnltaval.add(txtday);
pnltaval.add(txtmonth);
pnltaval.add(txtyear);
pnltaval.add(btnsubmit);
btnsubmit.addActionListener(this);
pnltinfo.setLayout(null);
pnlinfo.setBounds(5,5,590,380);
pnltbook.setBounds(5,5,590,380);
pnltinfo.add(pnltaval);
pnltinfo.add(pnltbook);
pnltinfo.add(pnlinfo);
frmtinfo.getContentPane().add(pnltinfo);
pnltaval.setVisible(false);
pnltbook.setVisible(false);
pnlinfo.setVisible(true);
frmtinfo.setSize(600,400);
frmtinfo.setLocation(200,150);
frmtinfo.setVisible(true);
txtno.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
Page 61 of 114
7/31/2019 Railway Servation System
62/114
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
} } });
txtday.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
} } });
txtmonth.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!((Character.isDigit(c) ||(c ==KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
} } });
txtyear.addKeyListener(new KeyAdapter()
Page 62 of 114
7/31/2019 Railway Servation System
63/114
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();if (!((Character.isDigit(c) ||(c ==
KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))))
{
getToolkit().beep();
e.consume();
} } });
okListener=new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
chosen = chooser.getColor();
current=chosen;
} };
//**********************************************
frmtinfo.addMouseListener(this);
pnltinfo.addMouseListener(this);
pnltaval.addMouseListener(this);
pnltbook.addMouseListener(this);
pnlinfo.addMouseListener(this);
lbltinfo.addMouseListener(this);
lbltsource.addMouseListener(this);
lbltdest.addMouseListener(this);
lbltdate.addMouseListener(this);
cbsource.addMouseListener(this);
Page 63 of 114
7/31/2019 Railway Servation System
64/114
cbdest.addMouseListener(this);
cbday.addMouseListener(this);
cbmonth.addMouseListener(this);
cbyear.addMouseListener(this);btnsearcht.addMouseListener(this);
//tbltrain.addMouseListener(this);
lbltno.addMouseListener(this);
lbljdate.addMouseListener(this);
txtno.addMouseListener(this);
txtday.addMouseListener(this);
txtmonth.addMouseListener(this);
txtyear.addMouseListener(this);
btnsubmit.addMouseListener(this);
lblhbook.addMouseListener(this);
lblname.addMouseListener(this);
lbladd.addMouseListener(this);
lblage.addMouseListener(this);
lblgender.addMouseListener(this);
lblphone.addMouseListener(this);
lblboarding.addMouseListener(this);
lbltrainno.addMouseListener(this);
lblseattype.addMouseListener(this);
lblnos.addMouseListener(this);
lbldate.addMouseListener(this);
txtname.addMouseListener(this);
txtage.addMouseListener(this);
txtphone.addMouseListener(this);
txttrainno.addMouseListener(this);
Page 64 of 114
7/31/2019 Railway Servation System
65/114
txtnos.addMouseListener(this);
txtdayb.addMouseListener(this);
txtmonthb.addMouseListener(this);
txtyearb.addMouseListener(this);txtadd.addMouseListener(this);
cbm.addMouseListener(this);
cbf.addMouseListener(this);
cbsleeper.addMouseListener(this);
cbac.addMouseListener(this);
cbboarding.addMouseListener(this);
cbdeboarding.addMouseListener(this);
btnbook.addMouseListener(this);
//***********************************************
}
public void mouseClicked(MouseEvent e)
{
int clickcount=e.getClickCount();
if(clickcount==2)
{
chooser = new JColorChooser(current != null ?current:Color.WHITE);
JDialog dialog = JColorChooser.createDialog(this,"Choose aColour",true,chooser,okListener,null);
dialog.setVisible(true);
Component obj=e.getComponent();
if(obj==pnltinfo||obj==pnltaval||obj==pnltbook||obj==pnlinfo)
{
obj.setBackground(chosen);
}
Page 65 of 114
7/31/2019 Railway Servation System
66/114
else
{
obj.setForeground(chosen);
}}
}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void focusGained (FocusEvent fe)
{
if(fe.getSource()==txttrainno)
{
cbboarding.removeAllItems();
cbdeboarding.removeAllItems();
}
}
public void focusLost (FocusEvent fe)
{
if(fe.getSource()==txttrainno)
{
try
{
ResultSet rs=stmt.executeQuery("select * from Trainswhere tno ='"+txttrainno.getText()+"'");
if(rs.next())
{
Page 66 of 114
7/31/2019 Railway Servation System
67/114
String booksource=rs.getString("tsource");
String bookvia1=rs.getString("via1");
String bookvia2=rs.getString("via2");
String bookdest=rs.getString("tdest");cbboarding.addItem(booksource);
cbboarding.addItem(bookvia1);
cbboarding.addItem(bookvia2);
cbboarding.addItem(bookdest);
cbdeboarding.addItem(booksource);
cbdeboarding.addItem(bookvia1);
cbdeboarding.addItem(bookvia2);
cbdeboarding.addItem(bookdest);
}
else
{
JOptionPane.showMessageDialog(null,"Not aValid Train No.","Note 3",2);
}
}
catch(Exception e)
{
System.out.println(e);
} } }
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btnbook)
Page 67 of 114
7/31/2019 Railway Servation System
68/114
7/31/2019 Railway Servation System
69/114
}
if(txtnos.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"Please give avalid no.!!!","Note 9",2);
return;
}
if(txtdayb.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"Provide a validDay!!!","Note 10",2);
return;
}
if(txtmonthb.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"Your Month is notvalid in date Field !!!","Note 11",2);
return;
}
if(txtyearb.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"Not a validyear !!!","Note 12",2);
return;
}
if(txtage.getText().length()>2)
{
JOptionPane.showMessageDialog(null,"Your age Notmore than 99 !!!","Note 13",2);
Page 69 of 114
7/31/2019 Railway Servation System
70/114
return;
}
if(txtphone.getText().substring(0,1).equalsIgnoreCase("0"))
{if(txtphone.getText().length()>11)
{
JOptionPane.showMessageDialog(null,"Pleasegive a valid Contact no !!!","Note 14",2);
return;
}
}
if(txtphone.getText().length()>10)
{
JOptionPane.showMessageDialog(null,"Please give avalid Contact no !!!","Note 15",2);
return;
}
else
{ try
{
reservTicket();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Note2",2);
} } }
Page 70 of 114
7/31/2019 Railway Servation System
71/114
if(ae.getSource()==btnsubmit)
{
trainavalstatus();
}if(ae.getSource()==btnbcancel)
{
}
if(ae.getSource()==mnutfind)
{
pnltaval.setVisible(false);
pnltbook.setVisible(false);
pnlinfo.setVisible(true);
}
if(ae.getSource()==mnucticket)
{
try
{
cancelTicket();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Cancel1",2);
}
}
if(ae.getSource()==mnucacticket)
{
try
Page 71 of 114
7/31/2019 Railway Servation System
72/114
{
cancelAcTicket();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e,"Cancel1",2);
}
}
if(ae.getSource()==mnuprint)
{
try
{
printTicket();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Print 1",2);
}
}
if(ae.getSource()==mnuprintac)
{
try
{
printAcTicket();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Print 1",2);
Page 72 of 114
7/31/2019 Railway Servation System
73/114
} }
if(ae.getSource()==mnutaval)
{
pnltaval.setVisible(true);pnltbook.setVisible(false);
pnlinfo.setVisible(false);
}
if(ae.getSource()==mnutbook)
{
pnltaval.setVisible(false);
pnltbook.setVisible(true);
pnlinfo.setVisible(false);
}
if(ae.getSource()==btnsearcht)
{
try
{
searchtrain();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Note",2);
}
}
}
public void searchtrain()
{
int nrows=0;
Page 73 of 114
7/31/2019 Railway Servation System
74/114
String q,sourcen,destn;
try
{
System.out.println(cbday.getSelectedItem());sourcen=cbsource.getSelectedItem().toString();
destn=cbdest.getSelectedItem().toString();
int day=cbday.getSelectedIndex()+1;
int month=cbmonth.getSelectedIndex()+1;
int year=1990;
if(cbyear.getSelectedIndex()==0)
{
year=2009;
}else
if(cbyear.getSelectedIndex()==1)
{
year=2010;
}
System.out.println(day+" "+month+" "+year+" ");
java.util.Date dt=new java.util.Date(year,month,day);
int din=dt.getDay();
System.out.println(dt.getDay());
if(din==3)
{
rs=stmt.executeQuery("select * from Trainswhere tsource='" + sourcen + "' and tdest= '" + destn + "' and day7='Y'");
System.out.println("Error");
coln=rs.getMetaData().getColumnCount();
while(rs.next())
Page 74 of 114
7/31/2019 Railway Servation System
75/114
{
rowData=new String[coln];
rowData[0]=rs.getString("tno");
rowData[1]=rs.getString("tname");
rowData[2]=rs.getString("tsource");
rowData[3]=rs.getString("tdest");
rowData[4]=rs.getString("ttime");
dataRows.addElement(rowData);
ctr++;
}System.out.println("Error1");
}
if(din==4)
{
rs=stmt.executeQuery("select * from Trainswhere tsource='" + sourcen + "' and tdest= '" + destn + "' and day1='Y'");
System.out.println("Error");
coln=rs.getMetaData().getColumnCount();
while(rs.next())
{
rowData=new String[coln];
rowData[0]=rs.getString("tno");
rowData[1]=rs.getString("tname");
rowData[2]=rs.getString("tsource");
rowData[3]=rs.getString("tdest");
rowData[4]=rs.getString("ttime");
Page 75 of 114
7/31/2019 Railway Servation System
76/114
dataRows.addElement(rowData);
ctr++;
}System.out.println("Error1");}
if(din==5)
{
rs=stmt.executeQuery("select * from Trainswhere tsource='" + sourcen + "' and tdest= '" + destn + "' and day2='Y'");
System.out.println("Error");
coln=rs.getMetaData().getColumnCount();
while(rs.next())
{
rowData=new String[coln];
rowData[0]=rs.getString("tno");
rowData[1]=rs.getString("tname");
rowData[2]=rs.getString("tsource");
rowData[3]=rs.getString("tdest");
rowData[4]=rs.getString("ttime");
dataRows.addElement(rowData);
ctr++;
}System.out.println("Error1");
}
if(din==6)
{
rs=stmt.executeQuery("select * from Trainswhere tsource='" + sourcen + "' and tdest= '" + destn + "' and day3='Y'");
Page 76 of 114
7/31/2019 Railway Servation System
77/114
7/31/2019 Railway Servation System
78/114
rowData[1]=rs.getString("tname");
rowData[2]=rs.getString("tsource");
rowData[3]=rs.getString("tdest");
rowData[4]=rs.getString("ttime");
dataRows.addElement(rowData);
ctr++;
}System.out.println("Error1");
}
if(din==1)
{
rs=stmt.executeQuery("select * from Trainswhere tsource='" + sourcen + "' and tdest= '" + destn + "' and day5='Y'");
System.out.println("Error");
coln=rs.getMetaData().getColumnCount();
while(rs.next())
{
rowData=new String[coln];
rowData[0]=rs.getString("tno");
rowData[1]=rs.getString("tname");
rowData[2]=rs.getString("tsource");
rowData[3]=rs.getString("tdest");
rowData[4]=rs.getString("ttime");
dataRows.addElement(rowData);
ctr++;
Page 78 of 114
7/31/2019 Railway Servation System
79/114
}System.out.println("Error1");
}
if(din==2)
{
rs=stmt.executeQuery("select * from Trainswhere tsource='" + sourcen + "' and tdest= '" + destn + "' and day6='Y'");
System.out.println("Error");
coln=rs.getMetaData().getColumnCount();
while(rs.next())
{
rowData=new String[coln];
rowData[0]=rs.getString("tno");
rowData[1]=rs.getString("tname");
rowData[2]=rs.getString("tsource");
rowData[3]=rs.getString("tdest");
rowData[4]=rs.getString("ttime");
dataRows.addElement(rowData);
ctr++;
}System.out.println("Error1");
}
if(dataRows.size()==0)
{
JOptionPane.showMessageDialog(null,"No TrainHere !!!","Note 22",2);
}
Page 79 of 114
7/31/2019 Railway Servation System
80/114
else
{
for (i=0;i
7/31/2019 Railway Servation System
81/114
n++;
}
System.out.print("\n");
}String columnNames[] = {"Train no.", "Name Of
Train","Source","Destination","Arrival Time","Date"} ;
tbltrain=new JTable(avaltrain,columnNames);
scrollpane =JTable.createScrollPaneForTable( tbltrain ) ;
JPanel pnlsearch=new JPanel();
pnlsearch.add( scrollpane ) ;
JFrame frmsearch=new JFrame("Search Train");
frmsearch.getContentPane().add(pnlsearch);
frmsearch.setSize(520,140);
frmsearch.setVisible(true);
frmsearch.setLocation(250,150);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public void trainavalstatus()
{
Page 81 of 114
7/31/2019 Railway Servation System
82/114
try
{
ResultSet rs=stmt.executeQuery("Select * fromReservation where PTno='"+txtno.getText()+"' and PTDay='"+txtday.getText()+"' andPTMonth='"+txtmonth.getText()+"' and PTYear='"+txtyear.getText()+"'");
int i=0;
while(rs.next())
{
i++;
}
rs=stmt.executeQuery("Select * from Trainswhere tno='"+txtno.getText()+"'");
rs.next();
JOptionPane.showMessageDialog(null,"TotalSeats in Sleeper "+rs.getString("sleeper")+"\nReserved Seats "+i+"","Note",2);
rs=stmt.executeQuery("Select * fromReservationac where PTno='"+txtno.getText()+"' and PTDay='"+txtday.getText()+"' andPTMonth='"+txtmonth.getText()+"' and PTYear='"+txtyear.getText()+"'");
int aci=0;
while(rs.next())
{
aci++;
}
rs=stmt.executeQuery("Select * from Trainswhere tno='"+txtno.getText()+"'");
rs.next();
JOptionPane.showMessageDialog(null,"TotalSeats in AC "+rs.getString("ac")+"\nReserved Seats "+aci+"","Note",2);
}
Page 82 of 114
7/31/2019 Railway Servation System
83/114
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Note21",2);
}
}
public void getcustomerinfo()
{
try
{
strdeboard=cbdeboarding.getSelectedItem().toString();
strboard=cbboarding.getSelectedItem().toString();
strname=txtname.getText();
stradd=txtadd.getText();
strage=txtage.getText();
strphone=txtphone.getText();
strtno=txttrainno.getText();
strnos=txtnos.getText();
if(cbm.getState())
{
gender=cbm.getLabel().toString();
}
else
if(cbf.getState())
{
gender=cbf.getLabel().toString();
}
Page 83 of 114
7/31/2019 Railway Servation System
84/114
if(cbsleeper.getState())
{
strtype=cbsleeper.getLabel().toString();
}else
if(cbac.getState())
{
strtype=cbac.getLabel().toString();
}
dateb=txtdayb.getText()+"/"+txtmonthb.getText()+"/"+txtyearb.getText();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Note1",2);
}
}
public void reservTicket()
{
try
{
getcustomerinfo();
if(strtype.equalsIgnoreCase("Sleeper"))
Page 84 of 114
7/31/2019 Railway Servation System
85/114
{
int s=0;
String status="A";String quantity="1";Stringpscost="f";String pstime="d";
int pseatn=0;
int INTTCost=0;
String jday=txtdayb.getText();String jmonth=txtmonthb.getText();String jyear=txtyearb.getText();
double dpnr=Math.random();
dpnr=dpnr*100000;
long lpnr=Math.round(dpnr);
String strpnr="",pnr=strpnr.valueOf(lpnr).toString();
ResultSet rs=stmt.executeQuery("select * from Trainswhere tno ='"+txttrainno.getText()+"'");
rs.next();
String TSLimit=rs.getString("sleeper");
String TTime=rs.getString("ttime");
String TCost=rs.getString("faresleeper");
int FromIndex=cbboarding.getSelectedIndex();
int ToIndex=cbdeboarding.getSelectedIndex();
if(FromIndex==0&&ToIndex==1)
{
pstime=TTime;
INTTCost=Integer.parseInt(TCost)*30/100;
pscost="Rs. "+INTTCost;
}
else
Page 85 of 114
7/31/2019 Railway Servation System
86/114
if(FromIndex==0 && ToIndex==2)
{
pstime=TTime;
INTTCost=Integer.parseInt(TCost)*70/100;pscost="Rs. "+INTTCost;
}
else
if(FromIndex==0 && ToIndex==3)
{
pstime=TTime;
INTTCost=Integer.parseInt(TCost);
pscost="Rs. "+INTTCost;
}
else
if(FromIndex==1 && ToIndex==2)
{
intINTTTime=Integer.parseInt(TTime.substring(11,13))+2;
pstime=INTTTime+" : 00";
INTTCost=Integer.parseInt(TCost)*40/100;
pscost="Rs. "+INTTCost;
}
else
if(FromIndex==1 && ToIndex==3)
Page 86 of 114
7/31/2019 Railway Servation System
87/114
{
intINTTTime=Integer.parseInt(TTime.substring(11,13))+4;
pstime=INTTTime+" : 00";
INTTCost=Integer.parseInt(TCost)*65/100;
pscost="Rs. "+INTTCost;
}
else
if(FromIndex==2 && ToIndex==3)
{
intINTTTime=Integer.parseInt(TTime.substring(11,13))+6;
pstime=INTTTime+" : 00";
INTTCost=Integer.parseInt(TCost)*35/100;
pscost="Rs. "+INTTCost;
}
for(int i=0;i
7/31/2019 Railway Servation System
88/114
Stringpassangergender=JOptionPane.showInputDialog(null,"Gender ?","Information",JOptionPane.QUESTION_ MESSAGE);
Stringpassangerage=JOptionPane.showInputDialog(null,"Age?","Information",JOptionPane.QUESTION_MESSA
GE);
rs=stmt.executeQuery("Select * from Reservationwhere PTno='"+txttrainno.getText()+"' and PTDay='"+jday+"' and PTMonth='"+jmonth+"' andPTYear='"+jyear+"'");
while(rs.next()){s++;}
int LimitDiff=Integer.parseInt(TSLimit)-s;
if(LimitDiff>0)
{
pseatn=s+1;
}else
if(LimitDiff
7/31/2019 Railway Servation System
89/114
msg +="__________________________________________\n\n";
msg += "PNR No. "+pnr+" Train No."+strtno+" Time : "+pstime+"\n\n";
msg += "Journey Date"+jday+"-"+jmonth+"-"+jyear+" Cost "+pscost+"\n";
msg += "Journey From : "+strboard+"To :"+strdeboard+"\n";
msg += "Reserved By "+strname+"\n";
msg +="*******************Ticket********************\n\n";
msg += "No of Tickets "+strnos+" Grand TotalRs."+Integer.parseInt(strnos)*INTTCost+"\n\n";
msg += "***************HAPPYJOURNEY**************\n\n";
JOptionPane.showMessageDialog(null, msg,"Ticket Information", JOptionPane.INFORMATION_MESSAGE );
}
else
if(strtype.equalsIgnoreCase("AC"))
{
int s=0;
String status="A";String quantity="1";Stringpscost="f";String pstime="d";
int pseatn=0;
int INTTCost=0;
String jday=txtdayb.getText();String jmonth=txtmonthb.getText();String jyear=txtyearb.getText();
double dpnr=Math.random();
dpnr=dpnr*100000;
Page 89 of 114
7/31/2019 Railway Servation System
90/114
long lpnr=Math.round(dpnr);
String strpnr="",pnr=strpnr.valueOf(lpnr).toString();
ResultSet rs=stmt.executeQuery("select * from Trainswhere tno ='"+txttrainno.getText()+"'");
rs.next();
String TSLimit=rs.getString("ac");
String TTime=rs.getString("ttime");
String TCost=rs.getString("fareac");
int FromIndex=cbboarding.getSelectedIndex();
int ToIndex=cbdeboarding.getSelectedIndex();
if(FromIndex==0 && ToIndex==1)
{
pstime=TTime;
INTTCost=Integer.parseInt(TCost)*30/100;
pscost="Rs. "+INTTCost;
}
else
if(FromIndex==0 && ToIndex==2)
{
pstime=TTime;
INTTCost=Integer.parseInt(TCost)*70/100;
pscost="Rs. "+INTTCost;
}
else
if(FromIndex==0 && ToIndex==3)
{
Page 90 of 114
7/31/2019 Railway Servation System
91/114
pstime=TTime;
INTTCost=Integer.parseInt(TCost);
pscost="Rs. "+INTTCost;
}
else
if(FromIndex==1 && ToIndex==2)
{
intINTTTime=Integer.parseInt(TTime.substring(11,13))+2;
pstime=INTTTime+" : 00";
INTTCost=Integer.parseInt(TCost)*40/100;
pscost="Rs. "+INTTCost;
}
else
if(FromIndex==1 && ToIndex==3)
{
intINTTTime=Integer.parseInt(TTime.substring(11,13))+4;
pstime=INTTTime+" : 00";
INTTCost=Integer.parseInt(TCost)*65/100;
pscost="Rs. "+INTTCost;
}
else
if(FromIndex==2 && ToIndex==3)
Page 91 of 114
7/31/2019 Railway Servation System
92/114
7/31/2019 Railway Servation System
93/114
pseatn=s+1;
}else
if(LimitDiff
7/31/2019 Railway Servation System
94/114
msg += "***************HAPPYJOURNEY**************\n\n";
JOptionPane.showMessageDialog(null, msg,
"Ticket Information", JOptionPane.INFORMATION_MESSAGE );
}
}
catch(SQLException e)
{
System.out.println("Error code "+e.getErrorCode());
System.out.println("Sql State "+e.getSQLState());
JOptionPane.showMessageDialog(null,e,"Book",2);
}
}
public void cancelTicket()
{
try
{
String passangerpnr=JOptionPane.showInputDialog(null,"PleaseEnter PNR No. ?","Information",JOptionPane.QUESTION_MESSAGE);
ResultSet rs=stmt.executeQuery("Select * from Reservationwhere PNR='"+passangerpnr+"'");
rs.next();
String status=rs.getString("PSStatus");
String pseatn=rs.getString("PSNo");
Page 94 of 114
7/31/2019 Railway Servation System
95/114
String jday=rs.getString("PTDay");String jmonth=rs.getString("PTMonth");String jyear=rs.getString("PTYear");
String ptrainno=rs.getString("PTno");
String pjfrom=rs.getString("PFrom");
int s=0;int u=0;
while(rs.next()){s++;}
if(status.equals("A"))
{
rs=stmt.executeQuery("Select PNR from Reservationwhere PTno='"+ptrainno+"' and PTDay='"+jday+"' and PTMonth='"+jmonth+"' and PTYear='"+jyear+"' and
PFrom='"+pjfrom+"' and PSStatus='W'");
while(rs.next())
{
String upnr=rs.getString("PNR");
u++;
String sqlu="update Reservation " +"setPSStatus='"+status+"',PSNo='"+pseatn+"'"+" where PNR='"+upnr+"'";
stmt.executeUpdate(sqlu);
}
rs=stmt.executeQuery("Delete from Reservation wherePNR='"+passangerpnr+"'");
rs=stmt.executeQuery("Select PSNo from Reservationwhere PSStatus='W'");
while(rs.next())
{
Page 95 of 114
7/31/2019 Railway Servation System
96/114
System.out.println("2");
String strn=rs.getString("PSNo");
System.out.println("3");int intpseatn=Integer.parseInt(strn)-u;
System.out.println("4");
String sqluw="update Reservation " +"setPSNo='"+intpseatn+"'"+" where PSStatus='W'";
stmt.executeUpdate(sqluw);
System.out.println("5");
}
rs=stmt.executeQuery("Delete from Reservation wherePNR='"+passangerpnr+"'");
JOptionPane.showMessageDialog(null,"OPerationSuccessfull !!!","Info",2);
}
if(status.equals("W"))
{
rs=stmt.executeQuery("Select PSNo from Reservationwhere PSStatus='W'");
while(rs.next())
{
String strn=rs.getString("PSNo");
int intpseatn=Integer.parseInt(strn)-u;
String sqluw="update Reservation " +"setPSNo='"+intpseatn+"'"+" where PSStatus='W'";
stmt.executeUpdate(sqluw);
Page 96 of 114
7/31/2019 Railway Servation System
97/114
}
rs=stmt.executeQuery("Delete from Reservation wherePNR='"+passangerpnr+"'");
JOptionPane.showMessageDialog(null,"OPeration
Successfull !!!","Info",2);
}
}
catch(Exception e)
{
//JOptionPane.showMessageDialog(null,e,"Cancel",2);
}
}
public void cancelAcTicket()
{
try
{
String passangerpnr=JOptionPane.showInputDialog(null,"PleaseEnter PNR No. ?","Information",JOptionPane.QUESTION_MESSAGE);
ResultSet rs=stmt.executeQuery("Select * from Reservationacwhere PNR='"+passangerpnr+"'");
rs.next();
String status=rs.getString("PSStatus");
String pseatn=rs.getString("PSNo");
String jday=rs.getString("PTDay");String jmonth=rs.getString("PTMonth");String jyear=rs.getString("PTYear");
String ptrainno=rs.getString("PTno");
String pjfrom=rs.getString("PFrom");
String [] tsno=new String[3];
Page 97 of 114
7/31/2019 Railway Servation System
98/114
int s=0;int u=0;
while(rs.next()){tsno[s]=rs.getString("PSNo");s++;}
if(status.equals("A"))
{
rs=stmt.executeQuery("Select PNR from Reservationacwhere PTno='"+ptrainno+"' and PTDay='"+jday+"' and PTMonth='"+jmonth+"' and PTYear='"+jyear+"' andPFrom='"+pjfrom+"' and PSStatus='W'");
while(rs.next())
{
String upnr=rs.getString("PNR");
String sqlu="update Reservationac "+"set PSStatus='"+status+"',PSNo='"+tsno[u]+"'"+" where PNR='"+upnr+"'";
stmt.executeUpdate(sqlu);
u++;
}
rs=stmt.executeQuery("Delete from Reservationac wherePNR='"+passangerpnr+"'");
rs=stmt.executeQuery("Select PSNo from Reservationacwhere PSStatus='W'");
while(rs.next())
{
Page 98 of 114
7/31/2019 Railway Servation System
99/114
System.out.println("2");
String strn=rs.getString("PSNo");
System.out.println("3");int intpseatn=Integer.parseInt(strn)-u;
System.out.println("4");
String sqluw="update Reservationac " +"setPSNo='"+intpseatn+"'"+" where PSStatus='W'";
stmt.executeUpdate(sqluw);
System.out.println("5");
}
rs=stmt.executeQuery("Delete from Reservationac wherePNR='"+passangerpnr+"'");
JOptionPane.showMessageDialog(null,"OPerationSuccessfull !!!","Info",2);
}
if(status.equals("W"))
{
rs=stmt.executeQuery("Select PSNo from Reservationacwhere PSStatus='W'");
while(rs.next())
{
String strn=rs.getString("PSNo");
int intpseatn=Integer.parseInt(strn)-u;
String sqluw="update Reservationac " +"setPSNo='"+intpseatn+"'"+" where PSStatus='W'";
stmt.executeUpdate(sqluw);
Page 99 of 114
7/31/2019 Railway Servation System
100/114
}
rs=stmt.executeQuery("Delete from Reservationac wherePNR='"+passangerpnr+"'");
JOptionPane.showMessageDialog(null,"OPeration
Successfull !!!","Info",2);
}
}
catch(Exception e)
{
//JOptionPane.showMessageDialog(null,e,"Cancel",2);
}
}
public void printTicket()
{
try
{
String [] passangers=new String[3];
String [] passangerg=new String[3];
String [] passangera=new String[3];
String [] psstatus=new String[3];
String [] pseatn=new String[3];
int pecost=0;
int i=0;
String printpnr=JOptionPane.showInputDialog(null,"Please Enter PNR No. ?","Information",JOptionPane.QUESTION_MESSAGE);
ResultSet rs=stmt.executeQuery("Select * from Reservationwhere PNR='"+printpnr+"'");
Page 100 of 114
7/31/2019 Railway Servation System
101/114
rs.next();
String ptno=rs.getString("PTno");
rs=stmt.executeQuery("Select * from Trains wheretno='"+ptno+"'");
rs.next();
String ptname=rs.getString("tname");
rs=stmt.executeQuery("Select * from Reservation wherePNR='"+printpnr+"'");
System.out.println("1");
while(rs.next())
{
passangers[i]=rs.getString("PassengerName");
passangerg[i]=rs.getString("PGender");
passangera[i]=rs.getString("PAge");
psstatus[i]=rs.getString("PSStatus");
pseatn[i]=rs.getString("PSNo");
System.out.println("2");
String tttcost=rs.getString("PCost");
pecost=pecost+Integer.parseInt(tttcost.substring(4,tttcost.length()));
System.out.println("3");
i++;
}
rs=stmt.executeQuery("Select * from Reservation wherePNR='"+printpnr+"'");
rs.next();
System.out.println("4");
Page 101 of 114
7/31/2019 Railway Servation System
102/114
String data0 = " Indian RailwayReservation \n"; //Page Title.
String data1 = " PNR NO. "+rs.getString("PNR")+ " Train Name."+ptname+ " Train no: "+ptno+ " \n\n"; //Page Header.
String data2 = " Journey Date " + rs.getString("PTDay")+"-"+rs.getString("PTMonth")+"-"+rs.getString("PTYear") +" Ticket Cost "+ pecost+ "\n";
String data3 = " Journey From " + rs.getString("PFrom") + "To "+rs.getString("PTo")+"\n";
String data4 = " Passangers \n" +passangers[0] + " "+passangerg[0] +" "+passangera[0]+" Seat No "+psstatus[0]+""+pseatn[0]+"\n" + passangers[1] + " "+passangerg[1]+" "+passangera[1]+" Seat No"+psstatus[1]+" "+pseatn[1]+"\n" + passangers[2] + " "+passangerg[2]+" "+passangera[2]+"Seat No "+psstatus[2]+" "+pseatn[2]+"\n";
String data5 = " Train Time "+rs.getString("PTTime")+"\n\n";
String data6 = " ******************Happy Journey***************";//Page Footer.
String sep0 = " -----------------------------------------------------------\n";
String sep1 = " -----------------------------------------------------------\n";
String sep2 = " -----------------------------------------------------------\n";
String sep3 = " -----------------------------------------------------------\n";
String sep4 = " -----------------------------------------------------------\n\n";
data = data0 + sep0 + data1 + data2 + sep1 + data3 + sep2 +data4 + sep3 + data5 + sep4 + data6;
printRecord (data);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Print",2);
}
Page 102 of 114
7/31/2019 Railway Servation System
103/114
}
public void printAcTicket()
{try
{
String [] passangers=new String[3];
String [] passangerg=new String[3];
String [] passangera=new String[3];
String [] psstatus=new String[3];
String [] pseatn=new String[3];
int pecost=0;
int i=0;
String printpnr=JOptionPane.showInputDialog(null,"Please Enter PNR No. ?","Information",JOptionPane.QUESTION_MESSAGE);
ResultSet rs=stmt.executeQuery("Select * from Reservationacwhere PNR='"+printpnr+"'");
rs.next();
String ptno=rs.getString("PTno");
rs=stmt.executeQuery("Select * from Trains wheretno='"+ptno+"'");
rs.next();
String ptname=rs.getString("tname");
rs=stmt.executeQuery("Select * from Reservationac wherePNR='"+printpnr+"'");
while(rs.next())
{
passangers[i]=rs.getString("PassengerName");
passangerg[i]=rs.getString("PGender");
Page 103 of 114
7/31/2019 Railway Servation System
104/114
passangera[i]=rs.getString("PAge");
psstatus[i]=rs.getString("PSStatus");
pseatn[i]=rs.getString("PSNo");
String tttcost=rs.getString("PCost");
pecost=pecost+Integer.parseInt(tttcost.substring(4,tttcost.length()));
i++;
}
rs=stmt.executeQuery("Select * from Reservationac wherePNR='"+printpnr+"'");
rs.next();
String data0 = " Indian RailwayReservation \n"; //Page Title.
String data1 = " PNR NO. "+rs.getString("PNR")+ " Train Name."+ptname+ " Train no: "+ptno+ " \n\n"; //Page Header.
String data2 = " Journey Date " + rs.getString("PTDay")+"-"+rs.getString("PTMonth")+"-"+rs.getString("PTYear") +" Ticket Cost "+ pecost+ "\n";
String data3 = " Journey From " + rs.getString("PFrom") + "To "+rs.getString("PTo")+"\n";
String data4 = " Passangers \n" +passangers[0] + " "+passangerg[0] +" "+passangera[0]+" Seat No "+psstatus[0]+""+pseatn[0]+"\n" + passangers[1] + " "+passangerg[1]+" "+passangera[1]+" Seat No"+psstatus[1]+" "+pseatn[1]+"\n" + passangers[2] + " "+passangerg[2]+" "+passangera[2]+"Seat No "+psstatus[2]+" "+pseatn[2]+"\n";
String data5 = " Train Time "+rs.getString("PTTime")+"\n\n";
String data6 = " ******************Happy Journey***************";//Page Footer.
String sep0 = " -----------------------------------------------------------\n";
String sep1 = " -----------------------------------------------------------\n";
String sep2 = " -----------------------------------------------------------\n";
Page 104 of 114
7/31/2019 Railway Servation System
105/114
String sep3 = " -----------------------------------------------------------\n";
String sep4 = " -----------------------------------------------------------\n\n";
data = data0 + sep0 + data1 + data2 + sep1 + data3 + sep2 +data4 + sep3 + data5 + sep4 + data6;
printRecord (data);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Print",2);
}
}
void printRecord (String rec)
{
StringReader sr = new StringReader (rec);
LineNumberReader lnr = new LineNumberReader (sr);
Font typeface = new Font ("Times New Roman", Font.PLAIN, 12);
Properties p = new Properties ();
PrintJob pJob = getToolkit().getPrintJob (this, "Print Customer BalanceReport", p);
if (pJob != null)
{
Page 105 of 114
7/31/2019 Railway Servation System
106/114
Graphics gr = pJob.getGraphics ();
if (gr != null)
{
FontMetrics fm = gr.getFontMetrics (typeface);int margin = 20;
int pageHeight = pJob.getPageDimension().height -margin;
int fontHeight = fm.getHeight();
int fontDescent = fm.getDescent();
int curHeight = margin;
String nextLine;
gr.setFont (typeface);
try
{
do
{
nextLine = lnr.readLine ();
if (nextLine != null)
{
if ((curHeight + fontHeight) >pageHeight)
{ //New Page.
gr.dispose();
gr = pJob.getGraphics();
curHeight = margin;
}
curHeight += fontHeight;
Page 106 of 114
7/31/2019 Railway Servation System
107/114
if (gr != null)
{
gr.setFont (typeface);
gr.drawString (nextLine,margin, curHeight - fontDescent);
}
}
}
while (nextLine != null);
}
catch (EOFException eof) { }
catch (Throwable t) { }
}
gr.dispose();
}
if (pJob != null)
pJob.end ();
}
public String findBillid()
{
dataRowsid.removeAllElements();
recid=0;
String sql = "select * from customer";
ctrid=1;
try
{
Page 107 of 114
7/31/2019 Railway Servation System
108/114
rs = stmt.executeQuery(sql);
colnid=rs.getMetaData().getColumnCount();
while(rs.next()) // For each row...{
rowDataid=new String[colnid];
for (int i=0; i
7/31/2019 Railway Servation System
109/114
public void seatnosstr()
{
String chktrainno=txttrainno.getText();try
{
rs=stmt.executeQuery("Select * from Trainswhere tno='"+chktrainno+"'");
if(rs.next())
{
System.out.println("submit 1");
chkseatorgac=Integer.parseInt(rs.getString("sleeper"));
chkseatorgsleeper=Integer.parseInt(rs.getString("seat"));
ResultSet
rs1=stmt.executeQuery("Select * from customer where ctno='"+chktrainno+"'");
if(rs1.next())
{
Stringchkseattype=rs1.getString("cstype");
if(chkseattype.equalsIgnoreCase("AC"))
{
System.out.println("submit 2");
Page 109 of 114
7/31/2019 Railway Servation System
110/114
chkavalseatac=chkseatorgac-Integer.parseInt(rs1.getString("cnos"));
//chkavalseatsleeper=chkseatorgsleeper;
}
if(chkseattype.equalsIgnoreCase("Sleeper"))
{
System.out.println("track");
chkavalseatsleeper=chkseatorgsleeper-Integer.parseInt(rs1.getString("cnos"));
//chkavalseatac=chkseatorgac;
System.out.println("submit 3");
}
System.out.println("submit 4");
}
else
{
chkavalseatac=chkseatorgac;
chkavalseatsleeper=chkseatorgsleeper;
}
}
if(strtype.equalsIgnoreCase("Sleeper"))
{
if(chkavalseatsleeper
7/31/2019 Railway Servation System
111/114
/*pseat1=chkseatorgsleeper-chkavalseatsleeper;
pseat2=chkseatorgsleeper-chkavalseatsleeper-Integer.parseInt(strnos);*/
pseat1=chkavalseatsleeper*1+1;
pseat2=chkavalseatsleeper-Integer.parseInt(strnos);
strseatnop="WSL"+pseat1+"-"+pseat2*1+"";
System.out.println("Seat20102"+strseatnop);
System.out.println("Seat"+chkavalseatsleeper);
}
if(chkavalseatsleeper>0)
{
pseat1=chkseatorgsleeper-chkavalseatsleeper+1;
pseat2=chkseatorgsleeper-chkavalseatsleeper+1+Integer.parseInt(strnos);
strseatnop="SL"+pseat1+1+"-"+pseat2+"";
System.out.println("Seat"+strseatnop);
}
}
if(strtype.equalsIgnoreCase("AC"))
{
Page 111 of 114
7/31/2019 Railway Servation System
112/114
if(chkavalseatac0)
{
pseat1=chkseatorgac-chkavalseatac+1;
pseat2=chkseatorgac-chkavalseatac+1+Integer.parseInt(strnos);
strseatnop="AC"+pseat1+"-"+pseat2+"";
System.out.println("Seatl"+strseatnop);
}
}
}
catch(Exception e)
Page 112 of 114
7/31/2019 Railway Servation System
113/114
{
JOptionPane.showMessageDialog(null,e,"Note25",2);
}
}
public static void main(String args[])
{
try
{
//javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception e)
{}
PReservation ti=new PReservation();
}
}
REFERENCE
Page 113 of 114
7/31/2019 Railway Servation System
114/114
Professional JSP : Wrox press Inc.
More Servelets & JSP : Marty Hall
JSP Tag Libraries : Gal Shachor &Magnus Rydin
JSP Buzz : Casey Kochmer
JSP The Complete Refrence : Hanna, Phil
Java Servlet & JSP Cookbook : Bruce W Perry