

/**
 *
 * @author 981898
 */
package Controller;

import DataEntryBean.InvestmentCreationBean;
//import DataEntryBean.InvestmentCreationDetailBean;
import LoginDb.DbHandler;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.sql.BatchUpdateException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
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;
import java.sql.Statement;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;

/**
 *
 * @author TCS
 */
public class InvestmentCreationServlet extends HttpServlet {


    /**
     * stmtesses 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 stmtessRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    }

    // <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 {
        stmtessRequest(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 {

        HttpSession session = request.getSession(false);
        Connection con = null;
        Connection con1 = null;
        CallableStatement stmt = null;
        Statement proc = null;
        ResultSet rs = null;
        int SeachFound = 0;
        String message = "";
        String hdrId = "";
        String pacsId = (String) session.getAttribute("pacsId");
        String user = (String) session.getAttribute("user");
        String handle_id = request.getParameter("handle_id");
       // String gl_ac = request.getParameter("glName");
        String message2 = "";

        InvestmentCreationBean oInvestmentCreationBean = new InvestmentCreationBean();
        //InvestmentCreationDetailBean oInvestmentCreationDetailBean = new InvestmentCreationDetailBean();
        ArrayList<InvestmentCreationBean> alInvestmentCreationDetailBean = new ArrayList<InvestmentCreationBean>();

        //For Update

        //ArrayList<InvestmentCreationDetailBean> alDepositKYCCreationDetailBeanNew = new ArrayList<InvestmentCreationDetailBean>();
       // ArrayList<InvestmentCreationDetailBean> alDepositKYCCreationDetailBeanUpdated = new ArrayList<InvestmentCreationDetailBean>();
       // ArrayList<InvestmentCreationDetailBean> alDepositKYCCreationDetailBeanDeleted = new ArrayList<InvestmentCreationDetailBean>();


        BatchExecutionFailedOperation BatchExecutionFailedOperationObject = new BatchExecutionFailedOperation();
        boolean SuccessFlag;


        try {
           // BeanUtils.populate(oInvestmentCreationBean, request.getParameterMap());
        } catch (IllegalAccessException ex) {
           // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
             System.out.println("Error Occurred during processing.");
        } catch (InvocationTargetException ex) {
           // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("Error Occurred during processing.");
        }

        try {
           // BeanUtils.populate(oInvestmentCreationBean, request.getParameterMap());
        } catch (IllegalAccessException ex) {
           // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
           System.out.println("Error Occurred during processing.");
        } catch (InvocationTargetException ex) {
           // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
           System.out.println("Error Occurred during processing.");
        }




        if ("Create".equalsIgnoreCase(handle_id)) {


            ServletContext servletContext = getServletContext();

            //File oldfile = new File(uploadPath + File.separator + oDepositKYCCreationBean.getFile() + ".jpg");

            //oldPhotoName = oDepositKYCCreationBean.getFile();
            //System.out.println(oldPhotoName);
            //START HEADER PART
            try {

               // con = DbHandler.getDBConnection();


                int counter = Integer.parseInt(request.getParameter("rowCounter"));

                for (int i = 1; i <= counter; i++) {
                    try {

                        String ckbox=request.getParameter("chckbox" + i);
                        //if()
                        //String document_mst_id = request.getParameter("document_mst_id" + i);
                        //String bank_name = request.getParameter("bankName" + i);
                        //String branch_name = request.getParameter("branchName" + i);
                        //String ac_no = request.getParameter("accountNo" + i);
                        //String amount= request.getParameter("amount" + i);
                        //String mat_amt= request.getParameter("maturityAmount" + i);
                       // String int_rate= request.getParameter("interestRate" + i);
                        //String ac_opn_dt= request.getParameter("acOpenDate" + i);
                        //String ac_mat_dt= request.getParameter("acMatDate" + i);
                        //String act_flag= request.getParameter("active" + i);

                        if (ckbox.equalsIgnoreCase("on")) {
                            oInvestmentCreationBean = new InvestmentCreationBean();
                            oInvestmentCreationBean.setAcno(ac_no);
                            oInvestmentCreationBean.setAc_opn_dt(ac_opn_dt);
                            oInvestmentCreationBean.setActive_flag(act_flag);
                            oInvestmentCreationBean.setAmt(amount);
                            oInvestmentCreationBean.setBank_name(bank_name);
                            oInvestmentCreationBean.setBranch_name(branch_name);
                            oInvestmentCreationBean.setInt_rate(int_rate);
                            oInvestmentCreationBean.setMat_amt(mat_amt);
                            oInvestmentCreationBean.setMat_dt(ac_mat_dt);


                            alInvestmentCreationDetailBean.add(oInvestmentCreationBean);
                        }
                    } catch (Exception e) {
                        System.out.println("Error Occurred during processing.");
                    }
                }

            if (alInvestmentCreationDetailBean.size() > 0) {
                    try {
                        con = DbHandler.getDBConnection();
                        stmt = con.prepareCall("{ call investment_create(?,?,?,?,?,?,?,?,?,?,?) }");
                        for (int j = 0; j < alInvestmentCreationDetailBean.size(); j++) {
                            oInvestmentCreationBean = alInvestmentCreationDetailBean.get(j);
                            stmt.setString(1,gl_ac);
                            stmt.setString(2, oInvestmentCreationBean.getAcno());
                            stmt.setString(3, oInvestmentCreationBean.getBank_name());
                            stmt.setString(4, oInvestmentCreationBean.getBranch_name());
                            stmt.setString(5, oInvestmentCreationBean.getInt_rate());
                            stmt.setString(6, oInvestmentCreationBean.getMat_amt());
                            stmt.setString(7, oInvestmentCreationBean.getAc_opn_dt());
                            stmt.setString(8, oInvestmentCreationBean.getMat_dt());
                            stmt.setString(9, oInvestmentCreationBean.getActive_flag());
                            stmt.setString(10, oInvestmentCreationBean.getAmt());
                            stmt.setString(11, pacsId);
                            stmt.addBatch();

                        }

                        stmt.executeBatch();
                         message="Details have been successfully inserted";



                //hdrId = (message.split("#")[1]).trim();

               //For Signature


                //File newfile = new File(uploadPath + File.separator + hdrId + ".jpg");
                //oldfile.renameTo(newfile);
                //new File(uploadPath + File.separator + oDepositKYCCreationBean.getFile() + ".jpg").renameTo(new File(uploadPath + File.separator + hdrId + ".jpg"));

            } catch (BatchUpdateException ex) {
                try {
                   // con.rollback();
                     message="Details insertion has failed";
                } catch (Exception ex1) {
                   // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex1);
                   System.out.println("Error Occurred during processing.");
                }
               // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
               // System.out.println(ex.toString());
               System.out.println("Error Occurred during processing.");
            } finally {
                try {
                    stmt.close();
                } catch (SQLException e) {
                    System.out.println("Error Occurred during stmt close.");
                }
                try {
                    con.close();
                } catch (SQLException ex) {
                   // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                   System.out.println("Error Occurred during connection close.");
                }

            }

            //END HEADER PART
            //START DETAIL PART


                    } else
                        message="No details saved for the selected GL account";

                }catch (SQLException e) {
                    message="Details insertion has failed";
                }
            }



    else if (("Search").equalsIgnoreCase(handle_id)) {

            Connection connection = null;
            ResultSet resultset = null;
            Statement statement = null;
            connection = DbHandler.getDBConnection();
            //String gl_no=request.getParameter("glNameAmend");
            //String balance=request.getParameter("glBalAmend");
            ArrayList<InvestmentCreationBean> alInvestmentCreationDetailBean2 = new ArrayList<InvestmentCreationBean>();

            try {
                statement = connection.createStatement();
            } catch (SQLException ex) {
               // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
               System.out.println("Error Occurred during processing.");
            }
            try {
               // resultset = statement.executeQuery("select i.ac_no,i.bank_name,i.branch_name,i.amt,i.maturity_amt,i.int_rate,to_char(i.ac_opn_dt,'DD/MM/RRRR') as ac_opn_dt,to_char(i.maturity_date,'DD/MM/RRRR') as maturity_date,i.active_flag from investment_dtl i where i.gl_id='" + gl_no + "'");

                while (resultset.next()) {
                            oInvestmentCreationBean = new InvestmentCreationBean();
                            oInvestmentCreationBean.setAcno(resultset.getString("ac_no"));
                            oInvestmentCreationBean.setAc_opn_dt(resultset.getString("ac_opn_dt"));
                            oInvestmentCreationBean.setActive_flag(resultset.getString("active_flag"));
                            oInvestmentCreationBean.setAmt(resultset.getString("amt"));
                            oInvestmentCreationBean.setBank_name(resultset.getString("bank_name"));
                            oInvestmentCreationBean.setBranch_name(resultset.getString("branch_name"));
                            oInvestmentCreationBean.setInt_rate(resultset.getString("int_rate"));
                            oInvestmentCreationBean.setMat_amt(resultset.getString("maturity_amt"));
                            oInvestmentCreationBean.setMat_dt(resultset.getString("maturity_date"));


                            alInvestmentCreationDetailBean2.add(oInvestmentCreationBean);


                    SeachFound = 1;


                }
                request.setAttribute("displayFlag", "Y");
               // statement.close();
               // resultset.close();
               // connection.close();

            } catch (SQLException ex) {
               // Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
               System.out.println("Error Occurred during processing.");
            } finally {
                try {
                    if(statement !=null)
                        statement.close();
                    if(resultset !=null)
                        resultset.close();
                    if (connection != null)
                    connection.close();

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

            }


            //Detail Part Populate


            request.setAttribute("GL_Account", gl_no);
            request.setAttribute("balance", balance);
            request.setAttribute("Option", "Amend");
            request.setAttribute("oInvestmentCreationBeanObj", oInvestmentCreationBean);
            request.setAttribute("alInvestmentCreationDetailBean2", alInvestmentCreationDetailBean2);


        }



    else if ("Update".equalsIgnoreCase(handle_id)) {


            ServletContext servletContext = getServletContext();
            int counter = Integer.parseInt(request.getParameter("rowCounterAmend"));

            //File oldfile = new File(uploadPath + File.separator + oDepositKYCCreationBean.getFile() + ".jpg");

            //oldPhotoName = oDepositKYCCreationBean.getFile();
            //System.out.println(oldPhotoName);
            //START HEADER PART
            try {
               // gl_ac=request.getParameter("hidden_gl_no");
                con = DbHandler.getDBConnection();
                proc = con.createStatement();
                rs = proc.executeQuery("delete from investment_dtl where gl_id = '" + gl_ac + "'");
                proc.close();
                } catch (Exception e) {
                   // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, e);
                       // System.out.println(e.toString());
                       System.out.println("Error Occurred during processing.");
                }

            try {
                for (int i = 1; i <= counter; i++) {
                    try {

                        String ckbox=request.getParameter("chckboxAmend"+i);
                        //if()
                        //String document_mst_id = request.getParameter("document_mst_id" + i);
                       // String bank_name = request.getParameter("bankNameAmend" + i);
                       // String branch_name = request.getParameter("branchNameAmend" + i);
                       // String ac_no = request.getParameter("accountNoAmend" + i);
                       // String amount= request.getParameter("amountAmend" + i);
                       // String mat_amt= request.getParameter("maturityAmountAmend" + i);
                       // String int_rate= request.getParameter("interestRateAmend" + i);
                       // String ac_opn_dt= request.getParameter("acOpenDateAmend" + i);
                       // String ac_mat_dt= request.getParameter("acMatDateAmend" + i);
                       // String act_flag= request.getParameter("activeAmend" + i);

                        if (ckbox.equalsIgnoreCase("on")) {
                            oInvestmentCreationBean = new InvestmentCreationBean();
                            oInvestmentCreationBean.setAcno(ac_no);
                            oInvestmentCreationBean.setAc_opn_dt(ac_opn_dt);
                            oInvestmentCreationBean.setActive_flag(act_flag);
                            oInvestmentCreationBean.setAmt(amount);
                            oInvestmentCreationBean.setBank_name(bank_name);
                            oInvestmentCreationBean.setBranch_name(branch_name);
                            oInvestmentCreationBean.setInt_rate(int_rate);
                            oInvestmentCreationBean.setMat_amt(mat_amt);
                            oInvestmentCreationBean.setMat_dt(ac_mat_dt);


                            alInvestmentCreationDetailBean.add(oInvestmentCreationBean);
                        }

                       // con.close();
                    } catch (Exception e) {
                       // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, e);
                       // System.out.println(e.toString());
                       System.out.println("Error Occurred during processing.");
                    } finally {
                        try {
                            if (con !=null) {
                                con.close();
                            }
                        } catch (Exception e) {
                            System.out.println("Error Occurred during connection close.");
                        }
                        
                    }
                }

            if (alInvestmentCreationDetailBean.size() > 0) {
                    try {
                        con = DbHandler.getDBConnection();
                        stmt = con.prepareCall("{ call investment_update(?,?,?,?,?,?,?,?,?,?,?) }");
                        for (int j = 0; j < alInvestmentCreationDetailBean.size(); j++) {
                            oInvestmentCreationBean = alInvestmentCreationDetailBean.get(j);
                            stmt.setString(1,gl_ac);
                            stmt.setString(2, oInvestmentCreationBean.getAcno());
                            stmt.setString(3, oInvestmentCreationBean.getBank_name());
                            stmt.setString(4, oInvestmentCreationBean.getBranch_name());
                            stmt.setString(5, oInvestmentCreationBean.getInt_rate());
                            stmt.setString(6, oInvestmentCreationBean.getMat_amt());
                            stmt.setString(7, oInvestmentCreationBean.getAc_opn_dt());
                            stmt.setString(8, oInvestmentCreationBean.getMat_dt());
                            stmt.setString(9, oInvestmentCreationBean.getActive_flag());
                            stmt.setString(10, oInvestmentCreationBean.getAmt());
                            stmt.setString(11, pacsId);
                            stmt.addBatch();

                        }

                        stmt.executeBatch();

                        message="Changes have been successfully updated";


                //hdrId = (message.split("#")[1]).trim();

               //For Signature


                //File newfile = new File(uploadPath + File.separator + hdrId + ".jpg");
                //oldfile.renameTo(newfile);
                //new File(uploadPath + File.separator + oDepositKYCCreationBean.getFile() + ".jpg").renameTo(new File(uploadPath + File.separator + hdrId + ".jpg"));

            } catch (BatchUpdateException ex) {
                try {
                   // con.rollback();
                    message="Updation failed";
                } catch (Exception ex1) {
                   // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex1);
                   System.out.println("Error Occurred during processing.");
                }
               // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
               // System.out.println(ex.toString());
               System.out.println("Error Occurred during processing.");
            } finally {
                try {
                    stmt.close();
                } catch (SQLException e) {
                    System.out.println("Error Occurred during stmt close.");
                }
                try {
                    con.close();
                } catch (SQLException ex) {
                   // Logger.getLogger(InvestmentCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                   System.out.println("Error Occurred during connection close.");
                }

            }

            //END HEADER PART
            //START DETAIL PART


                    }

                }catch (SQLException e) {
                    System.out.println("Error occurred during processing.");
                }
            }

            request.setAttribute("message", message);
            request.getRequestDispatcher("/investment_creation.jsp").forward(request, response);
    }

    /* else if (handle_id.equalsIgnoreCase("Update")) {

            try {
                BeanUtils.populate(oDepositKYCCreationBean, request.getParameterMap());
            } catch (IllegalAccessException ex) {
                Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InvocationTargetException ex) {
                Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
            }

            try {
                BeanUtils.populate(oDepositKYCCreationDetailBean, request.getParameterMap());
            } catch (IllegalAccessException ex) {
                Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InvocationTargetException ex) {
                Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
            }

            ServletContext servletContext = getServletContext();
            uploadPathMain = servletContext.getRealPath(File.separator);
            uploadPath = uploadPathMain + "/" + "UploadedFiles";
            File destinationDir = new File(uploadPath);

            try {
                con = DbHandler.getDBConnection();
                try {
                    stmt = con.prepareCall("{ call Operations.kyc_Deposit_hdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) }");

                } catch (SQLException ex) {
                    Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                }

                stmt.setString(1, oDepositKYCCreationBean.getcTypeAmend());
                stmt.setString(2, oDepositKYCCreationBean.getTittleAmend());
                stmt.setString(3, oDepositKYCCreationBean.getfNameAmend());
                stmt.setString(4, oDepositKYCCreationBean.getmNameAmend());
                stmt.setString(5, oDepositKYCCreationBean.getlNameAmend());
                stmt.setString(6, oDepositKYCCreationBean.getgNameAmend());
                stmt.setString(7, oDepositKYCCreationBean.getAdd1Amend());
                stmt.setString(8, oDepositKYCCreationBean.getAdd2Amend());
                stmt.setString(9, oDepositKYCCreationBean.getAdd3Amend());
                stmt.setString(10, oDepositKYCCreationBean.getDistnameAmend());
                stmt.setString(11, oDepositKYCCreationBean.getCitynameAmend());
                stmt.setString(12, oDepositKYCCreationBean.getStatenameAmend());
                stmt.setString(13, oDepositKYCCreationBean.getDobAmend());
                stmt.setString(14, oDepositKYCCreationBean.getGenderAmend());
                stmt.setString(15, oDepositKYCCreationBean.getmNumberAmend());
                stmt.setString(16, oDepositKYCCreationBean.getBlockAmend());
                stmt.setString(17, oDepositKYCCreationBean.getCifNoAmend());
                stmt.setString(18, handle_id);
                stmt.setString(19, pacsId);
                stmt.setString(20, oDepositKYCCreationBean.getFile());
                stmt.registerOutParameter(21, java.sql.Types.VARCHAR);
                stmt.setString(22, oDepositKYCCreationBean.getSigUpld());
                stmt.execute();
                message = stmt.getString(21);
                hdrId = (message.split("#")[1]).trim();

                if (!lastPhotoName.isEmpty()) {
                    File f = null;
                    File f1 = null;
                    try {
                        // create new File objects
                        f = new File(uploadPath + File.separator + lastPhotoName);
                        f1 = new File(uploadPath + File.separator + hdrId + ".jpg");

                        if(f1.exists()){
                            f1.delete();
                        }
                        // rename file
                        t = f.renameTo(f1);
                    } catch (Exception e) {
                        // if any error occurs
                        e.printStackTrace();
                    }
                }

                //For Signature
                if (!sigPhotoName.isEmpty()) {
                    File f = null;
                    File f1 = null;
                    try {
                        // create new File objects
                        f = new File(uploadPath + File.separator + sigPhotoName);
                        f1 = new File(uploadPath + File.separator + "sig-" + hdrId + ".jpg");

                        if(f1.exists()){
                            f1.delete();
                        }
                        // rename file
                        t = f.renameTo(f1);
                    } catch (Exception e) {
                        // if any error occurs
                        e.printStackTrace();
                    }
                }

                session.setAttribute("lastPhotoName", "");
                session.setAttribute("sigPhotoName", "");

            } catch (SQLException ex) {
                try {
                    con.rollback();
                } catch (SQLException ex1) {
                    Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex1);
                }
                Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                System.out.println(ex.toString());
            }

            //Detail Part Starts here
            int counterfor_Detail = Integer.parseInt(request.getParameter("rowCounter"));

            for (int i = 1; i <= counterfor_Detail; i++) {
                try {
                    String idTypeAmend = request.getParameter("idTypeAmend" + i);
                    String ScoreAmend = request.getParameter("ScoreAmend" + i);
                    String idNumberAmend = request.getParameter("idNumberAmend" + i);
                    String idIssueAtAmend = request.getParameter("idIssueAtAmend" + i);
                    String idIssueDateAmend = request.getParameter("idIssueDateAmend" + i);
                    String document_mst_idAmend = request.getParameter("document_mst_idAmend" + i);
                    String rowStatus = request.getParameter("rowStatus" + i);
                    String KYCCreation_dtl_id = request.getParameter("KYCCreation_dtl_id" + i);

                    if (document_mst_idAmend != null && rowStatus != null) {
                        oDepositKYCCreationDetailBean = new DepositKYCCreationDetailBean();
                        oDepositKYCCreationDetailBean.setIdTypeAmend(idTypeAmend);
                        oDepositKYCCreationDetailBean.setIDScoreAmend(ScoreAmend);
                        oDepositKYCCreationDetailBean.setIdNumberAmend(idNumberAmend);
                        oDepositKYCCreationDetailBean.setIdIssueAtAmend(idIssueAtAmend);
                        oDepositKYCCreationDetailBean.setIdIssueDateAmend(idIssueDateAmend);
                        oDepositKYCCreationDetailBean.setDocument_mst_idAmend(document_mst_idAmend);
                        oDepositKYCCreationDetailBean.setKYCCreation_dtl_id(KYCCreation_dtl_id);

                        if (rowStatus.equals("N")) {
                            alDepositKYCCreationDetailBeanNew.add(oDepositKYCCreationDetailBean);
                        } else {
                            alDepositKYCCreationDetailBeanUpdated.add(oDepositKYCCreationDetailBean);
                        }
                    }
                } catch (Exception e) {
                }
            }

            //For Deletion in Detail Part
            String deletedRows = request.getParameter("deletedRows");

            if ((!deletedRows.equalsIgnoreCase(null)) || (!deletedRows.equalsIgnoreCase(""))) {
                StringTokenizer tokenizer = new StringTokenizer(deletedRows, ",");

                while (tokenizer.hasMoreTokens()) {
                    oDepositKYCCreationDetailBean = new DepositKYCCreationDetailBean();
                    oDepositKYCCreationDetailBean.setKYCCreation_dtl_id(tokenizer.nextToken());

                    alDepositKYCCreationDetailBeanDeleted.add(oDepositKYCCreationDetailBean);
                }
            }

            if ((alDepositKYCCreationDetailBeanUpdated.size() > 0) && (!hdrId.equalsIgnoreCase(""))) {
                try {
                    con = DbHandler.getDBConnection();
                    try {
                        stmt = con.prepareCall("{ call Operations.deposit_kyc_dtl(?,?,?,?,?,?,?) }");
                    } catch (SQLException ex) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                    }


                    for (int j = 0; j < alDepositKYCCreationDetailBeanUpdated.size(); j++) {
                        oDepositKYCCreationDetailBean = alDepositKYCCreationDetailBeanUpdated.get(j);

                        stmt.setString(1, oDepositKYCCreationBean.getCifNoAmend());
                        stmt.setString(2, oDepositKYCCreationDetailBean.getKYCCreation_dtl_id());
                        stmt.setString(3, oDepositKYCCreationDetailBean.getDocument_mst_idAmend());
                        stmt.setString(4, oDepositKYCCreationDetailBean.getIdNumberAmend());
                        stmt.setString(5, oDepositKYCCreationDetailBean.getIdIssueAtAmend());
                        stmt.setString(6, oDepositKYCCreationDetailBean.getIdIssueDateAmend());
                        stmt.setString(7, handle_id);
                        stmt.addBatch();
                    }

                    stmt.executeBatch();

                } catch (BatchUpdateException ex) {

                    try {
                        con.rollback();

                        //SuccessFlag = BatchExecutionFailedOperationObject.BatchExecutionFailedOperation("DepositKYCCreation.jsp", hdrId);

                        message = "Atleast one entered ID Number already tagged to anothe CIF!";
                        // message = ex.toString();


                    } catch (SQLException ex1) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex1);
                    }


                    Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                    System.out.println(ex.toString());
                } catch (SQLException ex) {
                    try {
                        con.rollback();
                    } catch (SQLException ex1) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex1);
                    }
                    Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                    System.out.println(ex.toString());
                } finally {
                    try {
                        stmt.close();
                    } catch (SQLException e) {
                        System.out.println(e.toString());
                    }
                    try {
                        con.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                        System.out.println(ex.toString());
                    }
                }
            }

            if ((alDepositKYCCreationDetailBeanDeleted.size() > 0) && (!hdrId.equalsIgnoreCase(""))) {
                try {
                    con = DbHandler.getDBConnection();
                    try {
                        stmt = con.prepareCall("{ call Operations.deposit_kyc_dtl(?,?,?,?,?,?,?) }");
                    } catch (SQLException ex) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    for (int j = 0; j < alDepositKYCCreationDetailBeanDeleted.size(); j++) {

                        oDepositKYCCreationDetailBean = new DepositKYCCreationDetailBean();
                        oDepositKYCCreationDetailBean = alDepositKYCCreationDetailBeanDeleted.get(j);

                        stmt.setString(1, oDepositKYCCreationBean.getCifNoAmend());
                        stmt.setString(2, oDepositKYCCreationDetailBean.getKYCCreation_dtl_id());
                        stmt.setString(3, oDepositKYCCreationDetailBean.getDocument_mst_idAmend());
                        stmt.setString(4, oDepositKYCCreationDetailBean.getIdNumberAmend());
                        stmt.setString(5, oDepositKYCCreationDetailBean.getIdIssueAtAmend());
                        stmt.setString(6, oDepositKYCCreationDetailBean.getIdIssueDateAmend());
                        stmt.setString(7, "Delete");
                        stmt.addBatch();
                    }
                    stmt.executeBatch();
                } catch (SQLException ex) {
                    try {
                        con.rollback();
                    } catch (SQLException ex1) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex1);
                    }
                    Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                    System.out.println(ex.toString());
                } finally {
                    try {
                        stmt.close();
                    } catch (SQLException e) {
                        System.out.println(e.toString());
                    }
                    try {
                        con.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                        System.out.println(ex.toString());
                    }
                }
            }

            if ((alDepositKYCCreationDetailBeanNew.size() > 0) && (!hdrId.equalsIgnoreCase(""))) {
                try {
                    con = DbHandler.getDBConnection();
                    try {
                        stmt = con.prepareCall("{call Operations.deposit_kyc_dtl(?,?,?,?,?,?,?) }");
                    } catch (SQLException ex) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                    }


                    for (int j = 0; j < alDepositKYCCreationDetailBeanNew.size(); j++) {
                        oDepositKYCCreationDetailBean = new DepositKYCCreationDetailBean();
                        oDepositKYCCreationDetailBean = alDepositKYCCreationDetailBeanNew.get(j);

                        stmt.setString(1, oDepositKYCCreationBean.getCifNoAmend());
                        stmt.setString(2, oDepositKYCCreationDetailBean.getKYCCreation_dtl_id());
                        stmt.setString(3, oDepositKYCCreationDetailBean.getDocument_mst_idAmend());
                        stmt.setString(4, oDepositKYCCreationDetailBean.getIdNumberAmend());
                        stmt.setString(5, oDepositKYCCreationDetailBean.getIdIssueAtAmend());
                        stmt.setString(6, oDepositKYCCreationDetailBean.getIdIssueDateAmend());
                        stmt.setString(7, "Create");
                        stmt.addBatch();
                    }
                    stmt.executeBatch();
                    message = message2;
                } catch (BatchUpdateException ex) {

                    try {
                        con.rollback();

                        //SuccessFlag = BatchExecutionFailedOperationObject.BatchExecutionFailedOperation("DepositKYCCreation.jsp", hdrId);

                        message = "Atleast one entered ID Number already tagged to anothe CIF!";
                        // message = ex.toString();


                    } catch (SQLException ex1) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex1);
                    }


                    Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                    System.out.println(ex.toString());
                } catch (SQLException ex) {
                    try {
                        con.rollback();
                    } catch (SQLException ex1) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex1);
                    }
                    Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                    System.out.println(ex.toString());
                } finally {
                    try {
                        stmt.close();
                    } catch (SQLException e) {
                        System.out.println(e.toString());
                    }
                    try {
                        con.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(DepositKYCCreationServlet.class.getName()).log(Level.SEVERE, null, ex);
                        System.out.println(ex.toString());
                    }
                }
            }

            request.setAttribute("message", message);
            request.getRequestDispatcher("/Deposit/DepositKYCInquiry.jsp").forward(request, response);

        }
    }*/

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