<%@page language="java" import="java.text.*,java.util.*,java.sql.*" contentType="text/html"%>

<%
		 Number sno=Integer.parseInt(request.getParameter("serial"));
          String lettertype="";
		  String serial="";
	 String entrydate="";
String entrytime="";
String subject="";
String sendto="";
String lettername="";
String letterno="";
 String  letterdate="";
String receivedfrom="";
String markedto="";
String action="";
String demiofficial="";	  
			  SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
		   try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:letter");
            PreparedStatement pstmt = con.prepareStatement("select lettertype  from tappal_number where sno="+sno+"");
                      
              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="+sno+"");

 ResultSet rs1= pstmt1.executeQuery();
	 	   while(rs1.next())
            {
serial=rs1.getString(1);
letterno=rs1.getString(2);
 Timestamp tsp2=rs1.getTimestamp(3);
 java.util.Date d2=new java.util.Date(tsp2.getTime());
  letterdate=sdf.format(d2);
 receivedfrom=rs1.getString(4);
 subject=rs1.getString(5);
markedto=rs1.getString(6);
 action=rs1.getString(7);
 demiofficial=rs1.getString(8);
 lettername=rs1.getString(9);
 Timestamp tsp3=rs1.getTimestamp(10);
 java.util.Date d3=new java.util.Date(tsp3.getTime());
 entrydate=sdf.format(d3);
 entrytime=rs1.getString(11);

			 
			 }
	
	 
	          
			  }		   
		   
		   
		   
		else   if(lettertype.equals("outgoing"))
			   {
				             PreparedStatement pstmt2= con.prepareStatement("select * from o_tappals where serial="+sno+"");

 ResultSet rs2= pstmt2.executeQuery();

		   while(rs2.next())
            {
       

 serial=rs2.getString(1);
 letterno=rs2.getString(2);
Timestamp tsp4=rs2.getTimestamp(3);
 java.util.Date d4=new java.util.Date(tsp4.getTime());
 entrydate=sdf.format(d4);
 entrytime=rs2.getString(4);
 subject=rs2.getString(5);
 sendto=rs2.getString(6);
 lettername=rs2.getString(7);
demiofficial=rs2.getString(8);

			
			}
  
			   }	   
		   
		   
else
			   {
		    request.setAttribute("error","Not Found,may be no letter is present with this number ");
                   RequestDispatcher rd=request.getRequestDispatcher("update.jsp");
                rd.forward(request, response);
			
                
			   }
		   con.close();
		   }

catch(ClassNotFoundException s)
        { 
	out.println("loaderror");
   	}
		catch(SQLException e)
        { 
	out.println("sqlerror");
   }


%>





<html>
    <head>
        <link href="css/sty.css" rel="stylesheet" type="text/css"></link>        
 <script src="js/timer.js">  </script>
<script src="js/datepicker.js">  </script>
<script>

  function showform()
{
  var let='<%=lettertype%>' ;

if(let=="incoming")
document.getElementById("f1").style.display="block"
if(let=="outgoing")
document.getElementById("f2").style.display="block"

}
			  function validate1()
			  {
            	
         var a=incomingform.letterno.value;
         var b=incomingform.letterdate.value;
         var c=incomingform.receivedfrom.value;
         var d=incomingform.subject.value;
         var e=incomingform.markedto.value;
     
		if(document.incomingform.action[0].checked)
        var f=document.incomingform.action[0].value;
		 if(document.incomingform.action[1].checked)
        var f=document.incomingform.action[1].value;
	 if(document.incomingform.lettername[0].checked)
        var h=document.incomingform.lettername[0].value;
     if(document.incomingform.lettername[1].checked)
        var h=document.incomingform.lettername[1].value;
   if(document.incomingform.lettername[2].checked)
        var h=document.incomingform.lettername[2].value;

	 if(h=="" || h==null)
		window.alert("please select lettername");
 	else if(a=="" || a==null)
	window.alert("please enter letternumber");
        else  if(b=="" || b==null)
	window.alert("please pick letterdate");
        else if(c=="" || c==null)
	window.alert("please enter received from");
         else if(d=="" || d==null)
	window.alert("please enter subject");
         else if(e=="" || e==null)
	window.alert("please enter marked to");
		 else if(f=="" || f==null)
		window.alert("please select action taken");

      
     else
                   incomingform.submit();
				  
   
  }
   
   
   
   function show(z)
{

document.getElementById("f"+z).style.display="block"
}
function hide(z)
{
document.getElementById("f"+z).style.display="none"
}

 
 
 function validate2()
			  {
            	
         var a=outgoingform.letterno.value;
         var b=outgoingform.subject.value;
         var c=outgoingform.sendto.value;
     if(document.outgoingform.lettername[0].checked)
        var h=document.outgoingform.lettername[0].value;
     if(document.outgoingform.lettername[1].checked)
        var h=document.outgoingform.lettername[1].value;
   if(document.outgoingform.lettername[2].checked)
        var h=document.outgoingform.lettername[2].value;

       if(h=="" || h==null)
		window.alert("please select lettername");
        else	if(a=="" || a==null)
	window.alert("please enter letternumber");
        else  if(b=="" || b==null)
	window.alert("please enter subject");
        else if(c=="" || c==null)
window.alert("please enter sendto");
		else
				
                   outgoingform.submit();

				  
			  }
  
		  
		  
		  
		  
		  
	
</script>

</head>

<body onload="showform(),ftime()">
<center>







<FORM METHOD=POST style="display:none" name="incomingform" id="f1" ACTION="UpdatingProcess">
<h1>Incoming <%=lettername%> Tappal</h1>
<hr>
<TABLE  cellspacing=5 cellpadding=5>
<TR>
	<TD>LetterName:</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="local">Local</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="headquarters">HeadQuarters</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="others">Others</TD>
</TR>
<tr>
<TD><INPUT TYPE="checkbox" NAME="demiofficial" value="yes">Demiofficial</TD>
</tr>
</table>

<TABLE cellspacing=5 cellpadding=5 >
<TR>
	<TD>SNO</TD>
	<TD><INPUT TYPE="text" value='<%=serial%>' NAME="serial" id="serial" readonly></TD>
</TR>
<TR>
	<TD>LETTER NO</TD>
	<TD><INPUT TYPE="text" NAME="letterno" value='<%=letterno%>'></TD>
</TR>
<TR>
	<TD>LETTER DATE</TD>
	<TD><input type="TEXT" name='letterdate' readonly value='<%=letterdate%>'>
        <img alt="pickdate"src="images/cal.gif" onclick="displayDatePicker('letterdate')"></td>
</TR>

<TR>
	<TD>RECEIVED FROM</TD>
	<TD><INPUT TYPE="text" NAME="receivedfrom" value='<%=receivedfrom%>'>
		</TD>
</TR>

<TR>
	<TD>SUBJECT</TD>
	<TD><TEXTAREA NAME="subject" ROWS="3" COLS="25"><%=subject%></TEXTAREA></TD>
</TR>

<TR>
	<TD>MARKED TO</TD>
	<TD><INPUT TYPE="text" NAME="markedto" value='<%=markedto%>'></TD>
</TR>
<tr>
<td style="display:none">
<input type="text" name="lettertype" VALUE="incoming" readonly>
<input type="text" name="entrydate" id="t2" readonly>
<input type="text" name="entrytime" id="t3" readonly>
</td>
</tr>
</table>
<hr>
 <table cellspacing=5 cellpadding=5>

<TR>
 <td><INPUT TYPE="radio" NAME="action" value="closed">CLOSED
<td> <INPUT TYPE="radio"NAME="action" value="pending">PENDING</td>			
</tr>
<tr>
<TD><INPUT TYPE="button" VALUE="submit" onclick="validate1()"></TD>
<TD align="center"><INPUT TYPE="RESET" VALUE="RESET"></TD>
</TR>
</TABLE>
  </FORM>
 
 
  <FORM METHOD=POST style="display:none" name="outgoingform" id="f2" ACTION="UpdatingProcess">
<h1>Outgoing <%=lettername%> Tappal</h1>
<hr>

	<TABLE  cellspacing=5 cellpadding=5>
<TR>
	<TD>LetterName:</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="local">Local</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="headquarters">HeadQuarters</TD>
	<TD><INPUT TYPE="radio" NAME="lettername" value="others">Others</TD>
</TR>
<tr>
<TD><INPUT TYPE="checkbox" NAME="demiofficial" value="yes">Demiofficial</TD>
</tr>
</table>

<TABLE cellspacing=5 cellpadding=5>
<TR>
	<TD>SNO</TD>
	<TD><INPUT TYPE="text" NAME="serial" value='<%=serial%>'  readonly></TD>
</TR>
<TR>
	<TD>LETTER NO</TD>
	<TD><INPUT TYPE="text" NAME="letterno" value='<%=letterno%>'></TD>
</TR>
<TR>
	<TD>DATE</TD>
	<TD><input type="text" name="entrydate" id="t2" readonly ></TD>
	
</TR>
<TR>
	<TD>TIME</TD>
	<TD><input type="text" name="entrytime" id="t3" readonly></TD>
</TR>

<TR>
	<TD>SUBJECT</TD>
	<TD><TEXTAREA NAME="subject" ROWS="3" COLS="25"><%=subject%></TEXTAREA></TD>
</TR>
<TR>
	<TD>SEND TO</TD>
	<TD><INPUT TYPE="text" NAME="sendto" value='<%=sendto%>' ></TD>
</TR>


<TR>
	<TD><INPUT TYPE="button" VALUE="submit" onclick="validate2()"></TD>
	<TD align="center"><INPUT TYPE="RESET"></TD>
</TR>
	<tr><td><input type="hidden" name="lettertype"  VALUE="outgoing" readonly></td></tr>
	

</TABLE>
  
</FORM>













</center>
</body>
</html>