<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;
		SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
         String  demiofficial=request.getParameter("demiofficial");
         String action=request.getParameter("action");
		   
		  String date1=request.getParameter("t1");
         java.util.Date d1=sdf.parse(date1,new ParsePosition(0));
            Timestamp tsp1=new Timestamp(d1.getTime());
        
		 String date2=request.getParameter("t2");
           java.util.Date d2=sdf.parse(date2,new ParsePosition(0));
            Timestamp tsp2=new Timestamp(d2.getTime());
        
		
		
		try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:letter");
          PreparedStatement pstmt1=null,pstmt2=null;
	
	if(demiofficial==null&&action==null)
			{	
		pstmt1 = con.prepareStatement("select * from i_tappals where letterdate between ? and ?");
pstmt1.setTimestamp(1,tsp1 ); 
 pstmt1.setTimestamp(2,tsp2 );
    		}


	if(demiofficial!=null&&action==null)
			{
	pstmt1 = con.prepareStatement("select * from i_tappals where letterdate between ? and ? and demiofficial='"+demiofficial+"'");
pstmt1.setTimestamp(1,tsp1 ); 
 pstmt1.setTimestamp(2,tsp2 );
			}
if(demiofficial==null&&action!=null)
			{
pstmt1 = con.prepareStatement("select * from i_tappals where letterdate between ? and ? and action='"+action+"'");
pstmt1.setTimestamp(1,tsp1 ); 
 pstmt1.setTimestamp(2,tsp2 );
			}
if(demiofficial!=null&&action!=null)
			{
		pstmt1 = con.prepareStatement("select * from i_tappals where letterdate between ? and ?   and demiofficial='"+demiofficial+"' and action='"+action+"'");
	pstmt1.setTimestamp(1,tsp1 );         
 pstmt1.setTimestamp(2,tsp2 );
		}	
	
	
 ResultSet rs1= pstmt1.executeQuery();
	 
		   while(rs1.next())
            {
	 out.println("<center><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 tsp3=rs1.getTimestamp(3);
        java.util.Date d3=new java.util.Date(tsp3.getTime());
	 String d11=sdf.format(d3);

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 tsp4=rs1.getTimestamp(10);
   java.util.Date d4=new java.util.Date(tsp4.getTime());
   String d12=sdf.format(d4);
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(action==null)
			{
			
			
			
			if(demiofficial==null)
			{	
		pstmt2 = con.prepareStatement("select * from o_tappals where entrydate between ? and ?");
pstmt2.setTimestamp(1,tsp1 ); 
 pstmt2.setTimestamp(2,tsp2 );
    		}


	if(demiofficial!=null)
			{
	pstmt2 = con.prepareStatement("select * from o_tappals where entrydate between ? and ? and demiofficial='"+demiofficial+"'");
pstmt2.setTimestamp(1,tsp1 ); 
 pstmt2.setTimestamp(2,tsp2 );
			}
	
			
	
	ResultSet rs2= pstmt2.executeQuery();

		   while(rs2.next())
            {
       
	 out.println("<center><table cellspacing=10 cellpadding=5>");

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 tsp5=rs2.getTimestamp(3);
        java.util.Date d5=new java.util.Date(tsp5.getTime());
	 String d13=sdf.format(d5);
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>");
out.println("<hr>");  



 i++;
			
			}
			   	   
		   
		}   



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

		   	   }

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