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

import DataEntryBean.DepositMiscellaneousBean;
import LoginDb.DbHandler;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.beanutils.BeanUtils;

/**
 *
 * @author 986137
 */
public class TDRepayMethodServlet 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 depositAccSearch = "";
        ResultSet rs = null;
        int SeachFound = 0;
        String message = "";
        String resetBy=null;
        String action = request.getParameter("handle_id");
        String pacsId = (String) session.getAttribute("pacsId");
        String user = (String) session.getAttribute("user");
        //added by rajdiip
        StringBuilder query = null;
        PreparedStatement ps = null;
        int res = 0;
       // String txnOrAccntNo = null;

       // DepositMiscellaneousBean oDepositMiscellaneousBean = new DepositMiscellaneousBean();

            Connection con = null;
            CallableStatement proc = null;

              try {
                    con = DbHandler.getDBConnection();
                   // String acc = request.getParameter("depAccount");
                    //String trfMode = request.getParameter("methodType");
                    //String trfAcc = request.getParameter("trfAccount");
           
                    proc = con.prepareCall("{ call operations2.td_mat_trf_modechange(?,?,?,?,?,?) }");

                    proc.setString(1, acc);
                    proc.setString(2, pacsId);
                    proc.setString(3, user);
                    proc.setString(4, trfMode);
                    proc.setString(5, trfAcc);
                    proc.registerOutParameter(6, java.sql.Types.VARCHAR);

                    proc.execute();
                 //   message = proc.getString(6);

                    request.setAttribute("message", message);

                request.getRequestDispatcher("/Deposit/TDRepayMethod.jsp").forward(request, response);
        }
                
             catch (SQLException ex) {
                // ex.printStackTrace();
                System.out.println("Exception occured  in TDRepayMethodServlet for user Id :" + user);
                message= "Error occured. Please try again";
                // Logger.getLogger(AccountModeOfOperationServlet.class.getName()).log(Level.SEVERE, null, ex);
                System.out.println("Error occurred during processing.");
            } 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>
}
