/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;


import LoginDb.DbHandler;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author 986137
 */
public class UpdatePacsDetailsServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        HttpSession session = request.getSession(false);
        String message = "";
        String pacsId = (String) session.getAttribute("pacsId");
        String user = (String) session.getAttribute("user");

            Connection con = null;
            CallableStatement proc = null;
                  //  String pacsName = request.getParameter("pacsName");
                  //  String addrs1 = request.getParameter("add1");
                  //  String addrs2 = request.getParameter("add2");
                  //  String addrs3 = request.getParameter("add3");
                  //  String gst = request.getParameter("gstin");

              try {
                    con = DbHandler.getDBConnection();                    
           
                    proc = con.prepareCall("{ call operations2.PACS_ADDRESS_CHANGE(?,?,?,?,?,?,?,?) }");

                    proc.setString(1, pacsId);
                    proc.setString(2, user);
                    proc.setString(3, pacsName);
                    proc.setString(4, addrs1);
                    proc.setString(5, addrs2);
                    proc.setString(6, addrs3);
                    proc.registerOutParameter(7, java.sql.Types.VARCHAR);
                    proc.setString(8, gst);
                    
                    proc.execute();
                  //  message = proc.getString(7);

                    request.setAttribute("message", message);

                request.getRequestDispatcher("/Deposit/UpdatePacsDetails.jsp").forward(request, response);
        }
                
             catch (SQLException ex) {
                // ex.printStackTrace();
                System.out.println("Error occurred during processing.");
                System.out.println("Exception occured  in UpdatePacsDetailsServlet for user Id :" + user);
                message= "Exception occured  in UpdatePacsDetailsServlet for user Id :" + user +".";

                request.setAttribute("message", message);
                request.getRequestDispatcher("/Deposit/UpdatePacsDetails.jsp").forward(request, response);
           
             } finally {
                try {
                    if(proc !=null)
                        proc.close();
                    if (con != null)
                    con.close();

            } catch (Exception e) {
               // e.printStackTrace();
               System.out.println("Error occurred during connection close.");
            }

            }        
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
