<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link href="css/sty.css" rel="stylesheet" type="text/css"></link>        
</head>
<body>
<%@page language="java" import="java.text.*,java.util.*,java.sql.*" contentType="text/html"%>

<%
		 
		   try {
                       Number serial=Integer.parseInt(request.getParameter("serial"));
          String lettertype="";
		      SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:letter");
            
			PreparedStatement pstmt = con.prepareStatement("select lettertype  from tappal_number where sno="+serial+"");
                      
              ResultSet rs= pstmt.executeQuery();

		   while(rs.next())
            {
                lettertype=rs.getString(1);
			}
           
			 
			 
			 if(lettertype.equals("incoming"))
			   { 
				 
			
				             PreparedStatement pstmt1 = con.prepareStatement("select * from i_tappals where serial="+serial+"");

 ResultSet rs1= pstmt1.executeQuery();
	 out.println("<center><table cellspacing=10 cellpadding=5>");
		   while(rs1.next())
            {

out.println("<tr><td>SerialNo</td><td>"+rs1.getString(1)+"</td></tr>");
out.println("<tr><td>LetterNo</td><td>"+rs1.getString(2)+"</td></tr>");

 Timestamp tsp2=rs1.getTimestamp(3);
        java.util.Date d2=new java.util.Date(tsp2.getTime());
	 String d11=sdf.format(d2);

out.println("<tr><td>LetterDate</td><td>"+d11+"</td></tr>");

out.println("<tr><td>ReceivedFrom</td><td>"+rs1.getString(4)+"</td></tr>");
out.println("<tr><td>Subject</td><td>"+rs1.getString(5)+"</td></tr>");
out.println("<tr><td>MarkedTo</td><td>"+rs1.getString(6)+"</td></tr>");
String choose=rs1.getString(7);
if(choose.equals("pending"))
		out.println("<tr><td>ActionTaken</td><td><font color=red>"+choose+"</font></td></tr>");
else
out.println("<tr><td>ActionTaken</td><td><font color=magenta>"+choose+"</font></td></tr>");
				
out.println("<tr><td>Demiofficial</td><td>"+rs1.getString(8)+"</td></tr>");
out.println("<tr><td>LetterName</td><td>"+rs1.getString(9)+"</td></tr>");
 Timestamp tsp3=rs1.getTimestamp(10);
        java.util.Date d3=new java.util.Date(tsp3.getTime());
	 String d12=sdf.format(d3);
out.println("<tr><td>EntryDate</td><td>"+d12+"</td></tr>");
out.println("<tr><td>EntryTime</td><td>"+rs1.getString(11)+"</td></tr>");
			 
			 }
  out.println("</table></center>");
	
	 
	          
			  }		   
		   
		   
		   
		else   if(lettertype.equals("outgoing"))
			   {
				             PreparedStatement pstmt2= con.prepareStatement("select * from o_tappals where serial="+serial+"");

 ResultSet rs2= pstmt2.executeQuery();
	 out.println("<center><table cellspacing=10 cellpadding=5>");

		   while(rs2.next())
            {
       

out.println("<tr><td>SerialNo</td><td>"+rs2.getString(1)+"</td></tr>");
out.println("<tr><td>LetterNo</td><td>"+rs2.getString(2)+"</td></tr>");
Timestamp tsp4=rs2.getTimestamp(3);
        java.util.Date d4=new java.util.Date(tsp4.getTime());
	 String d13=sdf.format(d4);
out.println("<tr><td>EntryDate</td><td>"+d13+"</td></tr>");

out.println("<tr><td>EntryTime</td><td>"+rs2.getString(4)+"</td></tr>");
out.println("<tr><td>Subject</td><td>"+rs2.getString(5)+"</td></tr>");
out.println("<tr><td>SendTo</td><td>"+rs2.getString(6)+"</td></tr>");
out.println("<tr><td>LetterName</td><td>"+rs2.getString(7)+"</td></tr>");
out.println("<tr><td>Demiofficial</td><td>"+rs2.getString(8)+"</td></tr>");
			
			
			}
out.println("</table></center>");
  
			   }	   
		   
		   
else
			   {
	  request.setAttribute("error","Not Found,may be no letter is present with this number ");
                   RequestDispatcher rd=request.getRequestDispatcher("rserial.jsp");
                rd.forward(request, response);
		
		
                
			   }
		   
		   
		   
		   
		   
		   
		 con.close();  
		   
		   
		   
		   
		   
		   }

catch(ClassNotFoundException s)
        {
	out.println("loaderror");
   	}
catch(NumberFormatException n)
        {
	  request.setAttribute("error","please enter digits only ");
                   RequestDispatcher rd=request.getRequestDispatcher("rserial.jsp");
                rd.forward(request, response);

   	}

		catch(SQLException e)
        { 
	out.println("sqlerror");
   }
%>
</body>
</html>