package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.text.*;
import java.util.*;
import java.sql.*;

public final class dupdate_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");

		 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");
   }



      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("    <head>\r\n");
      out.write("        <link href=\"css/sty.css\" rel=\"stylesheet\" type=\"text/css\"></link>        \r\n");
      out.write(" <script src=\"js/timer.js\">  </script>\r\n");
      out.write("<script src=\"js/datepicker.js\">  </script>\r\n");
      out.write("<script>\r\n");
      out.write("\r\n");
      out.write("  function showform()\r\n");
      out.write("{\r\n");
      out.write("  var let='");
      out.print(lettertype);
      out.write("' ;\r\n");
      out.write("\r\n");
      out.write("if(let==\"incoming\")\r\n");
      out.write("document.getElementById(\"f1\").style.display=\"block\"\r\n");
      out.write("if(let==\"outgoing\")\r\n");
      out.write("document.getElementById(\"f2\").style.display=\"block\"\r\n");
      out.write("\r\n");
      out.write("}\r\n");
      out.write("\t\t\t  function validate1()\r\n");
      out.write("\t\t\t  {\r\n");
      out.write("            \t\r\n");
      out.write("         var a=incomingform.letterno.value;\r\n");
      out.write("         var b=incomingform.letterdate.value;\r\n");
      out.write("         var c=incomingform.receivedfrom.value;\r\n");
      out.write("         var d=incomingform.subject.value;\r\n");
      out.write("         var e=incomingform.markedto.value;\r\n");
      out.write("     \r\n");
      out.write("\t\tif(document.incomingform.action[0].checked)\r\n");
      out.write("        var f=document.incomingform.action[0].value;\r\n");
      out.write("\t\t if(document.incomingform.action[1].checked)\r\n");
      out.write("        var f=document.incomingform.action[1].value;\r\n");
      out.write("\t if(document.incomingform.lettername[0].checked)\r\n");
      out.write("        var h=document.incomingform.lettername[0].value;\r\n");
      out.write("     if(document.incomingform.lettername[1].checked)\r\n");
      out.write("        var h=document.incomingform.lettername[1].value;\r\n");
      out.write("   if(document.incomingform.lettername[2].checked)\r\n");
      out.write("        var h=document.incomingform.lettername[2].value;\r\n");
      out.write("\r\n");
      out.write("\t if(h==\"\" || h==null)\r\n");
      out.write("\t\twindow.alert(\"please select lettername\");\r\n");
      out.write(" \telse if(a==\"\" || a==null)\r\n");
      out.write("\twindow.alert(\"please enter letternumber\");\r\n");
      out.write("        else  if(b==\"\" || b==null)\r\n");
      out.write("\twindow.alert(\"please pick letterdate\");\r\n");
      out.write("        else if(c==\"\" || c==null)\r\n");
      out.write("\twindow.alert(\"please enter received from\");\r\n");
      out.write("         else if(d==\"\" || d==null)\r\n");
      out.write("\twindow.alert(\"please enter subject\");\r\n");
      out.write("         else if(e==\"\" || e==null)\r\n");
      out.write("\twindow.alert(\"please enter marked to\");\r\n");
      out.write("\t\t else if(f==\"\" || f==null)\r\n");
      out.write("\t\twindow.alert(\"please select action taken\");\r\n");
      out.write("\r\n");
      out.write("      \r\n");
      out.write("     else\r\n");
      out.write("                   incomingform.submit();\r\n");
      out.write("\t\t\t\t  \r\n");
      out.write("   \r\n");
      out.write("  }\r\n");
      out.write("   \r\n");
      out.write("   \r\n");
      out.write("   \r\n");
      out.write("   function show(z)\r\n");
      out.write("{\r\n");
      out.write("\r\n");
      out.write("document.getElementById(\"f\"+z).style.display=\"block\"\r\n");
      out.write("}\r\n");
      out.write("function hide(z)\r\n");
      out.write("{\r\n");
      out.write("document.getElementById(\"f\"+z).style.display=\"none\"\r\n");
      out.write("}\r\n");
      out.write("\r\n");
      out.write(" \r\n");
      out.write(" \r\n");
      out.write(" function validate2()\r\n");
      out.write("\t\t\t  {\r\n");
      out.write("            \t\r\n");
      out.write("         var a=outgoingform.letterno.value;\r\n");
      out.write("         var b=outgoingform.subject.value;\r\n");
      out.write("         var c=outgoingform.sendto.value;\r\n");
      out.write("     if(document.outgoingform.lettername[0].checked)\r\n");
      out.write("        var h=document.outgoingform.lettername[0].value;\r\n");
      out.write("     if(document.outgoingform.lettername[1].checked)\r\n");
      out.write("        var h=document.outgoingform.lettername[1].value;\r\n");
      out.write("   if(document.outgoingform.lettername[2].checked)\r\n");
      out.write("        var h=document.outgoingform.lettername[2].value;\r\n");
      out.write("\r\n");
      out.write("       if(h==\"\" || h==null)\r\n");
      out.write("\t\twindow.alert(\"please select lettername\");\r\n");
      out.write("        else\tif(a==\"\" || a==null)\r\n");
      out.write("\twindow.alert(\"please enter letternumber\");\r\n");
      out.write("        else  if(b==\"\" || b==null)\r\n");
      out.write("\twindow.alert(\"please enter subject\");\r\n");
      out.write("        else if(c==\"\" || c==null)\r\n");
      out.write("window.alert(\"please enter sendto\");\r\n");
      out.write("\t\telse\r\n");
      out.write("\t\t\t\t\r\n");
      out.write("                   outgoingform.submit();\r\n");
      out.write("\r\n");
      out.write("\t\t\t\t  \r\n");
      out.write("\t\t\t  }\r\n");
      out.write("  \r\n");
      out.write("\t\t  \r\n");
      out.write("\t\t  \r\n");
      out.write("\t\t  \r\n");
      out.write("\t\t  \r\n");
      out.write("\t\t  \r\n");
      out.write("\t\r\n");
      out.write("</script>\r\n");
      out.write("\r\n");
      out.write("</head>\r\n");
      out.write("\r\n");
      out.write("<body onload=\"showform(),ftime()\">\r\n");
      out.write("<center>\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("<FORM METHOD=POST style=\"display:none\" name=\"incomingform\" id=\"f1\" ACTION=\"UpdatingProcess\">\r\n");
      out.write("<h1>Incoming ");
      out.print(lettername);
      out.write(" Tappal</h1>\r\n");
      out.write("<hr>\r\n");
      out.write("<TABLE  cellspacing=5 cellpadding=5>\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>LetterName:</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"radio\" NAME=\"lettername\" value=\"local\">Local</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"radio\" NAME=\"lettername\" value=\"headquarters\">HeadQuarters</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"radio\" NAME=\"lettername\" value=\"others\">Others</TD>\r\n");
      out.write("</TR>\r\n");
      out.write("<tr>\r\n");
      out.write("<TD><INPUT TYPE=\"checkbox\" NAME=\"demiofficial\" value=\"yes\">Demiofficial</TD>\r\n");
      out.write("</tr>\r\n");
      out.write("</table>\r\n");
      out.write("\r\n");
      out.write("<TABLE cellspacing=5 cellpadding=5 >\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>SNO</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"text\" value='");
      out.print(serial);
      out.write("' NAME=\"serial\" id=\"serial\" readonly></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>LETTER NO</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"text\" NAME=\"letterno\" value='");
      out.print(letterno);
      out.write("'></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>LETTER DATE</TD>\r\n");
      out.write("\t<TD><input type=\"TEXT\" name='letterdate' readonly value='");
      out.print(letterdate);
      out.write("'>\r\n");
      out.write("        <img alt=\"pickdate\"src=\"images/cal.gif\" onclick=\"displayDatePicker('letterdate')\"></td>\r\n");
      out.write("</TR>\r\n");
      out.write("\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>RECEIVED FROM</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"text\" NAME=\"receivedfrom\" value='");
      out.print(receivedfrom);
      out.write("'>\r\n");
      out.write("\t\t</TD>\r\n");
      out.write("</TR>\r\n");
      out.write("\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>SUBJECT</TD>\r\n");
      out.write("\t<TD><TEXTAREA NAME=\"subject\" ROWS=\"3\" COLS=\"25\">");
      out.print(subject);
      out.write("</TEXTAREA></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>MARKED TO</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"text\" NAME=\"markedto\" value='");
      out.print(markedto);
      out.write("'></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("<tr>\r\n");
      out.write("<td style=\"display:none\">\r\n");
      out.write("<input type=\"text\" name=\"lettertype\" VALUE=\"incoming\" readonly>\r\n");
      out.write("<input type=\"text\" name=\"entrydate\" id=\"t2\" readonly>\r\n");
      out.write("<input type=\"text\" name=\"entrytime\" id=\"t3\" readonly>\r\n");
      out.write("</td>\r\n");
      out.write("</tr>\r\n");
      out.write("</table>\r\n");
      out.write("<hr>\r\n");
      out.write(" <table cellspacing=5 cellpadding=5>\r\n");
      out.write("\r\n");
      out.write("<TR>\r\n");
      out.write(" <td><INPUT TYPE=\"radio\" NAME=\"action\" value=\"closed\">CLOSED\r\n");
      out.write("<td> <INPUT TYPE=\"radio\"NAME=\"action\" value=\"pending\">PENDING</td>\t\t\t\r\n");
      out.write("</tr>\r\n");
      out.write("<tr>\r\n");
      out.write("<TD><INPUT TYPE=\"button\" VALUE=\"submit\" onclick=\"validate1()\"></TD>\r\n");
      out.write("<TD align=\"center\"><INPUT TYPE=\"RESET\" VALUE=\"RESET\"></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("</TABLE>\r\n");
      out.write("  </FORM>\r\n");
      out.write(" \r\n");
      out.write(" \r\n");
      out.write("  <FORM METHOD=POST style=\"display:none\" name=\"outgoingform\" id=\"f2\" ACTION=\"UpdatingProcess\">\r\n");
      out.write("<h1>Outgoing ");
      out.print(lettername);
      out.write(" Tappal</h1>\r\n");
      out.write("<hr>\r\n");
      out.write("\r\n");
      out.write("\t<TABLE  cellspacing=5 cellpadding=5>\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>LetterName:</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"radio\" NAME=\"lettername\" value=\"local\">Local</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"radio\" NAME=\"lettername\" value=\"headquarters\">HeadQuarters</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"radio\" NAME=\"lettername\" value=\"others\">Others</TD>\r\n");
      out.write("</TR>\r\n");
      out.write("<tr>\r\n");
      out.write("<TD><INPUT TYPE=\"checkbox\" NAME=\"demiofficial\" value=\"yes\">Demiofficial</TD>\r\n");
      out.write("</tr>\r\n");
      out.write("</table>\r\n");
      out.write("\r\n");
      out.write("<TABLE cellspacing=5 cellpadding=5>\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>SNO</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"text\" NAME=\"serial\" value='");
      out.print(serial);
      out.write("'  readonly></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>LETTER NO</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"text\" NAME=\"letterno\" value='");
      out.print(letterno);
      out.write("'></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>DATE</TD>\r\n");
      out.write("\t<TD><input type=\"text\" name=\"entrydate\" id=\"t2\" readonly ></TD>\r\n");
      out.write("\t\r\n");
      out.write("</TR>\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>TIME</TD>\r\n");
      out.write("\t<TD><input type=\"text\" name=\"entrytime\" id=\"t3\" readonly></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>SUBJECT</TD>\r\n");
      out.write("\t<TD><TEXTAREA NAME=\"subject\" ROWS=\"3\" COLS=\"25\">");
      out.print(subject);
      out.write("</TEXTAREA></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD>SEND TO</TD>\r\n");
      out.write("\t<TD><INPUT TYPE=\"text\" NAME=\"sendto\" value='");
      out.print(sendto);
      out.write("' ></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("<TR>\r\n");
      out.write("\t<TD><INPUT TYPE=\"button\" VALUE=\"submit\" onclick=\"validate2()\"></TD>\r\n");
      out.write("\t<TD align=\"center\"><INPUT TYPE=\"RESET\"></TD>\r\n");
      out.write("</TR>\r\n");
      out.write("\t<tr><td><input type=\"hidden\" name=\"lettertype\"  VALUE=\"outgoing\" readonly></td></tr>\r\n");
      out.write("\t\r\n");
      out.write("\r\n");
      out.write("</TABLE>\r\n");
      out.write("  \r\n");
      out.write("</FORM>\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("</center>\r\n");
      out.write("</body>\r\n");
      out.write("</html>");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
