Documente Academic
Documente Profesional
Documente Cultură
Page 1 of 114
CONTENTS
TOPIC ABOUT THE PROJECT OBJECTIVE SYSTEM ANALYSIS FEASIBILITY STUDY HARDWARE AND SOFTWARE SPECIFICATIONS VALIDATION CHECKS TESTING CODING BIBLIOGRAPHY
Page 2 of 114
The project has become a powerful tool for the exchange of information between the Administrator, Railway reservation centers, government offices and of late the common people.
The project RAILWAY RESERVATION SYSTEM is developed not only to maintain records but also to provide security to them, 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 deleting trains and even stations. Administrator can access to all the users he can add more users and even delete anyone of them.
Page 3 of 114
OBJECTIVE
THE BASIC AND MOST FUNDAMENTAL OBJECTIVE OF THIS PROJECT IS TO DEVELOP AND MAINTAIN A PROPER DATABASE OF RECORDS OF A RAILWAY RESERVATION SYSTEM WITH TRAIN NUMBER,TRAIN NAME,TRAIN SOURCE,TRAIN DESTINATION,TRAIN TIME,TRAIN TYPE,NUMBER OF SEATS(IN A.C. ,SLEEPER CLASS),TRAIN ROOT,TRAIN DATE & DAY.THIS PROJECT INTERACTS WITH MOUSE TOO,ONE CAN USE EITHER MOUSE OR NUMBERPAD TO CHOOSE A OPTION WHILE MENU IS SHOWN.
PROPER ENTRY SYSTEM OF THIS PROJECT GIVES THE CORRECT INFORMATION REGARDING TRAINS TO ANY USER.
Page 4 of 114
SYSTEM ANALYSIS
The working of RAILWAY RESERVATION SYSTEM is that all the TRAIN NUMBER,TRAIN NAME,TRAIN SOURCE,TRAIN DESTINATION,TRAIN TIME,TRAIN TYPE,NUMBER OF SEATS(IN A.C. ,SLEEPER CLASS) etc. are maintained manually. Due to the peer pressure of working it becomes difficult to maintain security and integrity of those data. Thus, to put a check on unauthorized access we made users and their password to do any transaction with records.
In order to sort out the problems described above Train Reservation system felt the need for a system that not only work efficiently and secure but also be cost effective. Thinking all this and other, they decide to go fully and truly computerized. Therefore, they give us permission for developing system, which could enhance their work culture.
Page 5 of 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 be created too.
4. Henceforth security of record is maintained, and as the database is computerized their integrity is also maintained. 5. Any transaction cant be made until it is being made by the user.
Page 6 of 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 to know that what the users demonstrable needs are. We find that we can be able to satisfy their most of the requirement. We can maintain their database automated, we can reduce their operating cost time at a considerable 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 us drastically reduces the working effort. Therefore, they supported us very well. There was also sufficient support from the railway Administration too because the new system enhances the efficiency of the employees.
Page 7 of 114
TECHNICAL FEASIBILITY:
There was not any technology in School so there was need for new system. The system available in School has PIII processor & more than 10 GB HDD. This capacity is sufficient for storage of data and smooth running of software.
Page 8 of 114
Page 9 of 114
HARDWARE PLATEFORM:
Processor
Pentium IV 3.0GHZ
RAM
256MB
Monitor
LG Color Monitor
Mouse
Keyboard
Samsung Keyboard
HDD
80GB
Printer
Page 10 of 114
SOFTWARE PLATFORM
Operating System
Windows XP
Front End
Back End
Page 11 of 114
VALIDATION CHECKS
T h i s p h a s e i s e s s e n t i a l b e fo r e s y s t e m t e s t i n g. I t i n cl u d es t he c h e c k i n g o f v a l i d i t y wh e t h e r t h e en t r y t o t he s ys t e m i s va l i d or not. W e t o o k s o m e d u m m y d a t a t o ch ec k t he val i d i t y of t he s ys t e m . It wa s wo r k i n g we l l a n d a s ex pe c t e d.
A l l t h e m o d u l e s a n d fo r ms , s u b mo du l e s ar e co nt a i n i n g va l i d features.
Page 12 of 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 mind the probable user of the system, the effort spent in learning the new system, so that they can comfortable with it. This is in itself a he factor since it modifies the design, the tools used and the utilities provided with the system. The new system can not be even assumed that the persons interacting with system are computer illitrates, the interface should be designed so that they can easily familiarize and master the system. In short, the system should be that the effort spent in learning it should spell outs its worth. The learning curve should not have a steep slope but a gradual one.
AVAILABILTY OF INFRASTRUCTURE:
Availability of infrastructure is another factor that plays an important role in the deciding of the resulting model. A design that fixes varied level of security, reliability and flexibility naturally demands a processing power. This can be easily understood in the height of concurrent accessing of the database. The number of user accessing the database concurrently naturally depends upon the processing power.
Page 13 of 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
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 tested for 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 was individually tested, without keeping in mind the inherent interaction between the units. 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 validity check that conjointly these units giving the expected result or not. Basically this testing was done to test the design of the system.
Page 15 of 114
SYSTEM TESTING:
After the integration testing the system testing was done. It was done to test the requirement specification of the system. In this testing the whole system was tested at once against some parameters.
ACCEPTANCE TESTING:
More finally the acceptance testing was done. This testing was done with the actual data by the user for their kind acceptance. This testing has done for the users satisfaction.
Page 16 of 114
Page 17 of 114
// admininfo.java
public class admininfo extends JFrame implements ActionListener, FocusListener,MouseListener { JFrame frmainfo; JPanel pnlainfo,pnlitrain,pnlcancelt,pnlmem; JLabel lblahinfo,lbltno,lbltname,lbltsource,lbltdest,lblttime,lblttype,lblsleeper,lblseat,lblvia,lbldays; JTextField txttno,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; String strtno,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
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
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
pnlmem.setLayout(null);
Page 21 of 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.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
lblsleeper=new JLabel("No. of Seat in AC"); lblseat=new JLabel("No. of Seat in Sleeper"); lblvia=new JLabel("Root"); lbldays=new JLabel("Days");
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");
Page 23 of 114
btnclear=new JButton("Clear");
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);
Page 24 of 114
txtvia2.setBounds(350,240,140,25); txtttype.setBounds(380,170,110,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
Page 26 of 114
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
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
}); 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
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(); } } });
txtvia2.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 30 of 114
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
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
if(clickcount==2) { chooser = new JColorChooser(current != null ?current :Color.WHITE); JDialog dialog = JColorChooser.createDialog(this,"Choose a Colour",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 {
Page 33 of 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
} 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) {
Page 35 of 114
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
} }
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 where tno='"+strtno+"'"); if(rs.next()) { JOptionPane.showMessageDialog(null,"Train no. already exist!!!","Note",2); } else {
Page 37 of 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,day 6,day7) "+" VALUES ('"+strtno+"','"+strtname+"','"+strtsource+"','"+strtdest+"','"+strttime+"','"+strfareac+"','"+strfaresleeper+"','"+str ttype+"','"+strsac+"','"+strssleeper+"','"+strvia1+"','"+strvia2+"','"+intd1+"','"+intd2+"','"+intd3+"','"+intd4+"','"+i ntd5+"','"+intd6+"','"+intd7+"')"; System.out.println("!"); stmt.executeUpdate(sqli); System.out.println("2"); rs=stmt.executeQuery("Select * from location where source='"+strtsource+"'"); rs=stmt.executeQuery("Select * from location where dest='"+strtdest+"'"); if(rs.next()){} if(rs.next()){}
clearfields(); } } } catch(Exception e) {
Page 38 of 114
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+"'"+"Wh ere tno ='"+strtno+"'" ; stmt.executeUpdate(sqlu); clearfields(); disablefields(); } catch(Exception e) { JOptionPane.showMessageDialog(null,e,"Note 6",2); } }
Page 39 of 114
try { connection(); takememdata(); rs=stmt.executeQuery("Select * from Users where name='"+strmemname+"'"); if(rs.next()) { JOptionPane.showMessageDialog(null,"Member Already Exist!!!","Note",2); } else {
stmt.executeUpdate(sqli);
Page 40 of 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
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 where tno='"+txttno.getText()+"'"); if(rs.next()) { enablefields(); strtno=rs.getString("tno");txttno.setText(strtno);
strtname=rs.getString("tname");txttname.setText(strtname);
Page 42 of 114
strsac=rs.getString("sleeper"); txtsleeper.setText(strsac);
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. is Incorrect","Note",2); clearfields(); } } catch(Exception e) { JOptionPane.showMessageDialog(null,e,"Note",2);
Page 43 of 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
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");
Page 45 of 114
{} catch(ClassNotFoundException clsnotfndExcep) { System.out.println("ERROR " + clsnotfndExcep); } } public static void main(String args[]) { try {
// RReservation.java
Page 46 of 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; JMenuItem mnutaval,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"; String strseatpn,gender,strtype,dateb,strdeboard,strboard,strname,stradd,strage,strphone,strtno,strno,strnos,strse atnop,data,stramount,strtime; int pseat1,pseat2,amount;
Page 47 of 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
////////////////// JLabel lblhbook,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
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
cbdest=new JComboBox();
for(int i=1;i<=12;i++) { cbmonth.addItem(""+i); } cbyear=new JComboBox(); cbyear.addItem("2009"); cbyear.addItem("2010"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection(url); stmt = conn.createStatement(); rs=stmt.executeQuery("SELECT * FROM location"); while(rs.next()) { cbsource.addItem(rs.getString("source")); cbdest.addItem(rs.getString("dest")); } } catch(Exception e)
Page 51 of 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
/////////////////////////////////////////////////////////////// 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
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
cbm.setBounds(370,110,80,25); cbf.setBounds(450,110,80,25); cbsleeper.setBounds(370,170,80,25); cbac.setBounds(450,170,80,25); cbboarding.setBounds(250,200,130,25); cbdeboarding.setBounds(250,230,130,25); btnbook.setBounds(410,260,100,25); btnbcancel.setBounds(410,290,100,25); pnltbook.add(lblhbook); pnltbook.add(lblname); pnltbook.add(lbladd); pnltbook.add(lblage); pnltbook.add(lblgender); pnltbook.add(lblphone); pnltbook.add(lblboarding); pnltbook.add(lbltrainno); pnltbook.add(lblseattype); pnltbook.add(lblnos); pnltbook.add(lbldate); pnltbook.add(txtname); pnltbook.add(txtadd); pnltbook.add(txtage); pnltbook.add(txtphone); pnltbook.add(txttrainno); pnltbook.add(txtnos); pnltbook.add(txtdayb); pnltbook.add(txtmonthb); pnltbook.add(txtyearb);
Page 55 of 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(); } } });
Page 56 of 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(); } } });
Page 57 of 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(); } } });
Page 58 of 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
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
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
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
{ 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
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
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 a Colour",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
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 Trains where tno ='"+txttrainno.getText()+"'"); if(rs.next()) {
Page 66 of 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 a Valid Train No.","Note 3",2); } } catch(Exception e) { System.out.println(e); } } }
Page 67 of 114
{ if(txtname.getText().length()==0) { JOptionPane.showMessageDialog(null,"Please give your name !!!","Note 4",2); return; } if(txtadd.getText().length()==0) { JOptionPane.showMessageDialog(null,"Add Field may be blank!!!","Note 5",2); return; } if(txtage.getText().length()==0) { JOptionPane.showMessageDialog(null,"Not a Valid Age !!!","Note 6",2); return; } if(txtphone.getText().length()==0) { JOptionPane.showMessageDialog(null,"Contact No. must be privided !!!","Note 7",2); return; } if(txttrainno.getText().length()==0) { JOptionPane.showMessageDialog(null,"Please give a valid train no. !!!","Note 8",2); return;
Page 68 of 114
if(txtdayb.getText().length()==0) { JOptionPane.showMessageDialog(null,"Provide a valid Day!!!","Note 10",2); return; } if(txtmonthb.getText().length()==0) { JOptionPane.showMessageDialog(null,"Your Month is not valid in date Field !!!","Note 11",2); return; } if(txtyearb.getText().length()==0) { JOptionPane.showMessageDialog(null,"Not a valid year !!!","Note 12",2); return; } if(txtage.getText().length()>2) { JOptionPane.showMessageDialog(null,"Your age Not more than 99 !!!","Note 13",2);
Page 69 of 114
return; } if(txtphone.getText().substring(0,1).equalsIgnoreCase("0")) { if(txtphone.getText().length()>11) { JOptionPane.showMessageDialog(null,"Please give a valid Contact no !!!","Note 14",2); return; } } if(txtphone.getText().length()>10) {
JOptionPane.showMessageDialog(null,"Please give a valid Contact no !!!","Note 15",2); return; } else { { reservTicket(); } catch(Exception e) { JOptionPane.showMessageDialog(null,e,"Note 2",2); } } } try
Page 70 of 114
Page 71 of 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
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
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 Trains where tsource='" + sourcen + "' and tdest= '" + destn + "' and day7='Y'"); System.out.println("Error"); coln=rs.getMetaData().getColumnCount(); while(rs.next())
Page 74 of 114
rowData[1]=rs.getString("tname");
dataRows.addElement(rowData); ctr++; }System.out.println("Error1"); } if(din==4) { rs=stmt.executeQuery("select * from Trains where 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");
Page 75 of 114
dataRows.addElement(rowData); ctr++; }System.out.println("Error1"); } if(din==5) { rs=stmt.executeQuery("select * from Trains where 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");
dataRows.addElement(rowData); ctr++; }System.out.println("Error1"); } if(din==6) { rs=stmt.executeQuery("select * from Trains where tsource='" + sourcen + "' and tdest= '" + destn + "' and day3='Y'");
Page 76 of 114
rowData[1]=rs.getString("tname");
dataRows.addElement(rowData); ctr++; }System.out.println("Error1"); } if(din==0) { rs=stmt.executeQuery("select * from Trains where tsource='" + sourcen + "' and tdest= '" + destn + "' and day4='Y'"); System.out.println("Error"); coln=rs.getMetaData().getColumnCount(); while(rs.next()) { rowData=new String[coln];
rowData[0]=rs.getString("tno");
Page 77 of 114
rowData[1]=rs.getString("tname");
dataRows.addElement(rowData); ctr++; }System.out.println("Error1"); } if(din==1) { rs=stmt.executeQuery("select * from Trains where 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");
dataRows.addElement(rowData); ctr++;
Page 78 of 114
}System.out.println("Error1"); } if(din==2) {
rs=stmt.executeQuery("select * from Trains where 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");
Page 79 of 114
else { for (i=0;i<ctr-1;i++) { n=0; while (n<6) { System.out.println("Error2"); avaltrain[i][n]= ((String []) (dataRows.elementAt (i))) [n]; avaltrain[i][n]= ((String []) (dataRows.elementAt (i))) [n]; avaltrain[i][n]= ((String []) (dataRows.elementAt (i))) [n]; avaltrain[i][n]= ((String []) (dataRows.elementAt (i))) [n]; avaltrain[i][n]= ((String []) (dataRows.elementAt (i))) [n]; avaltrain[i][5]= Integer.toString(day)+"/"+Integer.toString(month)+"/"+Integer.toString(year); n++; } System.out.print("\n"); } for (i=0;i<ctr-1;i++) { n=0; while (n<6) { System.out.println("rows in the vector" + " " + ((String [])(dataRows.elementAt (i))) [n]);
Page 80 of 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); } }
Page 81 of 114
try { ResultSet rs=stmt.executeQuery("Select * from Reservation where PTno='"+txtno.getText()+"' and PTDay='"+txtday.getText()+"' and PTMonth='"+txtmonth.getText()+"' and PTYear='"+txtyear.getText()+"'"); int i=0; while(rs.next()) { i++; } rs=stmt.executeQuery("Select * from Trains where tno='"+txtno.getText()+"'"); rs.next(); JOptionPane.showMessageDialog(null,"Total Seats in Sleeper "+rs.getString("sleeper")+"\nReserved Seats "+i+"","Note",2); rs=stmt.executeQuery("Select * from Reservationac where PTno='"+txtno.getText()+"' and PTDay='"+txtday.getText()+"' and PTMonth='"+txtmonth.getText()+"' and PTYear='"+txtyear.getText()+"'"); int aci=0; while(rs.next()) { aci++; } rs=stmt.executeQuery("Select * from Trains where tno='"+txtno.getText()+"'"); rs.next(); JOptionPane.showMessageDialog(null,"Total "+aci+"","Note",2);
Page 82 of 114
catch(Exception e) { JOptionPane.showMessageDialog(null,e,"Note 21",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
} catch(Exception e) { JOptionPane.showMessageDialog(null,e,"Note1",2); }
Page 84 of 114
int s=0; String status="A";String quantity="1";String pscost="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 Trains where 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
} else if(FromIndex==1 && ToIndex==2) { int INTTTime=Integer.parseInt(TTime.substring(11,13))+2; pstime=INTTTime+" : 00"; INTTCost=Integer.parseInt(TCost)*40/100; pscost="Rs. "+INTTCost;
Page 86 of 114
Page 87 of 114
String passangergender=JOptionPane.showInputDialog(null,"Gender ?","Information",JOptionPane.QUESTION_ MESSAGE); String passangerage=JOptionPane.showInputDialog(null,"Age?","Information",JOptionPane.QUESTION_MESSA GE); rs=stmt.executeQuery("Select * from Reservation where PTno='"+txttrainno.getText()+"' and PTDay='"+jday+"' and PTMonth='"+jmonth+"' and PTYear='"+jyear+"'"); while(rs.next()){s++;} int LimitDiff=Integer.parseInt(TSLimit)-s; if(LimitDiff>0) { pseatn=s+1; }else if(LimitDiff<0||LimitDiff==0) { pseatn=-1*LimitDiff+1; status="W"; } String sqlr="insert into Reservation(PNR,PassengerName,PTno,PTDay,PTMonth,PTYear,PFrom,PTo,PSStatus,PSQ,PSNo,PTTi me,PCost,PGender,PAge) "+" values('"+pnr+"','"+pssangername+"','"+strtno+"','"+jday+"','"+jmonth+"','"+jyear+"','"+strboard+"','"+strdeboar d+"','"+status+"','"+quantity+"','"+pseatn+"','"+pstime+"','"+pscost+"','"+passangergender+"','"+passangerage +"')"; stmt.executeUpdate(sqlr); s=0;
Page 88 of 114
msg += "__________________________________________\n\n"; msg += "PNR No. "+pnr+" "+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 Rs."+Integer.parseInt(strnos)*INTTCost+"\n\n"; msg += "***************HAPPY JOURNEY**************\n\n"; "+strnos+" Grand Total Train No.
int s=0; String status="A";String quantity="1";String pscost="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
long lpnr=Math.round(dpnr); String strpnr="",pnr=strpnr.valueOf(lpnr).toString(); ResultSet rs=stmt.executeQuery("select * from Trains where 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;
Page 90 of 114
} else if(FromIndex==1 && ToIndex==2) { int INTTTime=Integer.parseInt(TTime.substring(11,13))+2; pstime=INTTTime+" : 00"; INTTCost=Integer.parseInt(TCost)*40/100; pscost="Rs. "+INTTCost;
Page 91 of 114
for(int i=0;i<Integer.parseInt(strnos);i++) { String pssangername=JOptionPane.showInputDialog(null,"Passenger Name ?","Information",JOptionPane.QUESTION_MESSAGE); String passangergender=JOptionPane.showInputDialog(null,"Gender ?","Information",JOptionPane.QUESTION_ MESSAGE); String passangerage=JOptionPane.showInputDialog(null,"Age?","Information",JOptionPane.QUESTION_MESSA GE);
rs=stmt.executeQuery("Select * from Reservationac where PTno='"+txttrainno.getText()+"' and PTDay='"+jday+"' and PTMonth='"+jmonth+"' and PTYear='"+jyear+"'"); while(rs.next()){s++;} int LimitDiff=Integer.parseInt(TSLimit)-s; if(LimitDiff>0) {
Page 92 of 114
pseatn=s+1; }else if(LimitDiff<0||LimitDiff==0) { pseatn=-1*LimitDiff+1; status="W"; } String sqlr="insert into Reservationac(PNR,PassengerName,PTno,PTDay,PTMonth,PTYear,PFrom,PTo,PSStatus,PSQ,PSNo,PT Time,PCost,PGender,PAge) "+" values('"+pnr+"','"+pssangername+"','"+strtno+"','"+jday+"','"+jmonth+"','"+jyear+"','"+strboard+"','"+strdeboar d+"','"+status+"','"+quantity+"','"+pseatn+"','"+pstime+"','"+pscost+"','"+passangergender+"','"+passangerage +"')"; stmt.executeUpdate(sqlr); s=0;
} String msg = "Railway Reservation \n"; msg += "__________________________________________\n\n"; msg += "PNR No. "+pnr+" "+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 Rs."+Integer.parseInt(strnos)*INTTCost+"\n\n"; "+strnos+" Grand Total Train No.
Page 93 of 114
JOptionPane.showMessageDialog(null,e,"Book",2); }
public void cancelTicket() { try { String passangerpnr=JOptionPane.showInputDialog(null,"Please Enter PNR No. ?","Information",JOptionPane.QUESTION_MESSAGE); ResultSet rs=stmt.executeQuery("Select * from Reservation where PNR='"+passangerpnr+"'"); rs.next(); String status=rs.getString("PSStatus"); String pseatn=rs.getString("PSNo");
Page 94 of 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 Reservation where PTno='"+ptrainno+"' and PTDay='"+jday+"' and PTMonth='"+jmonth+"' and PTYear='"+jyear+"' and PFrom='"+pjfrom+"' and PSStatus='W'"); while(rs.next()) {
rs=stmt.executeQuery("Delete from Reservation where PNR='"+passangerpnr+"'"); rs=stmt.executeQuery("Select PSNo from Reservation where PSStatus='W'"); while(rs.next()) {
Page 95 of 114
String sqluw="update Reservation " +"set PSNo='"+intpseatn+"'"+" where PSStatus='W'"; stmt.executeUpdate(sqluw); System.out.println("5"); } rs=stmt.executeQuery("Delete from Reservation where PNR='"+passangerpnr+"'"); JOptionPane.showMessageDialog(null,"OPeration Successfull !!!","Info",2); } if(status.equals("W")) { rs=stmt.executeQuery("Select PSNo from Reservation where PSStatus='W'"); while(rs.next()) {
Page 96 of 114
} catch(Exception e) { //JOptionPane.showMessageDialog(null,e,"Cancel",2); } }
public void cancelAcTicket() { try { String passangerpnr=JOptionPane.showInputDialog(null,"Please Enter PNR No. ?","Information",JOptionPane.QUESTION_MESSAGE); ResultSet rs=stmt.executeQuery("Select * from Reservationac where 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
if(status.equals("A")) { rs=stmt.executeQuery("Select PNR from Reservationac where 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");
String sqlu="update Reservationac " +"set PSStatus='"+status+"',PSNo='"+tsno[u]+"'"+" where PNR='"+upnr+"'"; stmt.executeUpdate(sqlu); u++;
rs=stmt.executeQuery("Delete from Reservationac where PNR='"+passangerpnr+"'"); rs=stmt.executeQuery("Select PSNo from Reservationac where PSStatus='W'"); while(rs.next()) {
Page 98 of 114
String sqluw="update Reservationac " +"set PSNo='"+intpseatn+"'"+" where PSStatus='W'"; stmt.executeUpdate(sqluw); System.out.println("5"); } rs=stmt.executeQuery("Delete from Reservationac where PNR='"+passangerpnr+"'"); JOptionPane.showMessageDialog(null,"OPeration Successfull !!!","Info",2); } if(status.equals("W")) { rs=stmt.executeQuery("Select PSNo from Reservationac where PSStatus='W'"); while(rs.next()) {
Page 99 of 114
} 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 Reservation where PNR='"+printpnr+"'");
rs.next(); String ptno=rs.getString("PTno"); rs=stmt.executeQuery("Select * from Trains where tno='"+ptno+"'"); rs.next(); String ptname=rs.getString("tname"); rs=stmt.executeQuery("Select * from Reservation where PNR='"+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++; }
Reservation
\n";
Indian Railway
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 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"; " + rs.getString("PFrom") + "
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); }
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 Reservationac where PNR='"+printpnr+"'"); rs.next(); String ptno=rs.getString("PTno"); rs=stmt.executeQuery("Select * from Trains where tno='"+ptno+"'"); rs.next(); String ptname=rs.getString("tname"); rs=stmt.executeQuery("Select * from Reservationac where PNR='"+printpnr+"'"); while(rs.next()) { passangers[i]=rs.getString("PassengerName"); passangerg[i]=rs.getString("PGender");
pecost=pecost+Integer.parseInt(tttcost.substring(4,tttcost.length()));
i++; }
Reservation
\n";
Indian Railway
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 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"; " + rs.getString("PFrom") + "
String data6 = " ******************Happy Journey***************"; //Page Footer. String sep0 = " -----------------------------------------------------------\n"; String sep1 = " -----------------------------------------------------------\n"; String sep2 = " -----------------------------------------------------------\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); } }
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 Balance Report", p);
if (pJob != null) {
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;
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 {
rs = stmt.executeQuery(sql); colnid=rs.getMetaData().getColumnCount();
String chktrainno=txttrainno.getText(); try { rs=stmt.executeQuery("Select * from Trains where tno='"+chktrainno+"'"); if(rs.next()) { System.out.println("submit 1");
chkseatorgac=Integer.parseInt(rs.getString("sleeper"));
chkseatorgsleeper=Integer.parseInt(rs.getString("seat"));
if(rs1.next()) {
String chkseattype=rs1.getString("cstype");
if(chkseattype.equalsIgnoreCase("AC")) {
System.out.println("submit 2");
if(chkseattype.equalsIgnoreCase("Sleeper")) { System.out.println("track");
chkavalseatsleeper=chkseatorgsleeper; } }
if(strtype.equalsIgnoreCase("Sleeper")) {
if(chkavalseatsleeper<0) {
/*pseat1=chkseatorgslee per-chkavalseatsleeper;
pseat2=chkseatorgsleeper-chkavalseatsleeper-Integer.parseInt(strnos);*/
pseat1=chkavalseatsleeper*1+1;
pseat2=chkavalseatsleeper-Integer.parseInt(strnos);
} if(chkavalseatsleeper>0) {
pseat1=chkseatorgsleeper-chkavalseatsleeper+1;
pseat2=chkseatorgsleeper-chkavalseatsleeper+1+Integer.parseInt(strnos);
} if(strtype.equalsIgnoreCase("AC")) {
} catch(Exception e)
{ JOptionPane.showMessageDialog(null,e,"Note 25",2); }
public static void main(String args[]) { try { //javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.pl af.windows.WindowsLookAndFeel"); } catch (Exception e) {} PReservation ti=new PReservation(); }
REFERENCE
JSP Buzz :
Casey Kochmer