<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"%>

<%
		int i=0;
		 String receivedfrom=request.getParameter("receivedfrom");
		String  demiofficial=request.getParameter("demiofficial");
         String action=request.getParameter("action");
		
		SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
                  try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:letter");
	        PreparedStatement pstmt1=null;

		if(demiofficial==null&&action==null)
			{	
		pstmt1 = con.prepareStatement("select * from i_tappals where receivedfrom=?");
pstmt1.setString(1,receivedfrom);         
    		}


	if(demiofficial!=null&&action==null)
			{
	pstmt1 = con.prepareStatement("select * from i_tappals where receivedfrom=? and demiofficial='"+demiofficial+"'");
pstmt1.setString(1,receivedfrom);         
         
			}
if(demiofficial==null&&action!=null)
			{
pstmt1 = con.prepareStatement("select * from i_tappals where receivedfrom=? and action='"+action+"'");
pstmt1.setString(1,receivedfrom);         
         
			}
if(demiofficial!=null&&action!=null)
			{
		pstmt1 = con.prepareStatement("select * from i_tappals where receivedfrom=?   and demiofficial='"+demiofficial+"' and action='"+action+"'");
pstmt1.setString(1,receivedfrom);         
         
		}	
	
		
		ResultSet rs1= pstmt1.executeQuery();
	 
		   while(rs1.next())
            {
	 out.println("<center><table table cellspacing=10 cellpadding=5>");
			 
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>");
out.println("<hr>");


 i++;
 }
			
		   
		   
if(i<=0)
			   {
	  request.setAttribute("error","Not Found ");
                   RequestDispatcher rd=request.getRequestDispatcher("rreceived.jsp");
                rd.forward(request, response);
		
		       
			   }
		   con.close();
		   	   }


		catch(Exception e)
        { 
	out.println(e);
        }
	

%>
</body>
</html>