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

import DataEntryBean.RationCardTypeDetailsBean;
import DataEntryBean.RationCardTypeHeaderBean;
import DataEntryBean.VendorMasterDtlBean;
import DataEntryBean.VendorMasterHeaderBean;
import LoginDb.DbHandler;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.sql.CallableStatement;
import java.sql.Connection;
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 RationCardTypeServlet 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 {

        Connection con = null;
        CallableStatement proc = null;
        String message = "";
        String ScreenStatus = "";
        String hdrID = "";
        HttpSession session = request.getSession(false);

      //  String ServletName = request.getParameter("handle_id");

        RationCardTypeHeaderBean oRationCardTypeHeaderBean = new RationCardTypeHeaderBean();
        RationCardTypeDetailsBean oRationCardTypeDetailsBean = new RationCardTypeDetailsBean();
        oRationCardTypeDetailsBean = null;
        ArrayList<RationCardTypeDetailsBean> alRationCardTypeDetailsBean = new ArrayList<RationCardTypeDetailsBean>();


        //For Amend Div

        ArrayList<RationCardTypeDetailsBean> alRationCardTypeDetailsBeanNew = new ArrayList<RationCardTypeDetailsBean>();
        ArrayList<RationCardTypeDetailsBean> alRationCardTypeDetailsBeanDeleted = new ArrayList<RationCardTypeDetailsBean>();
        ArrayList<RationCardTypeDetailsBean> alRationCardTypeDetailsBeanUpdated = new ArrayList<RationCardTypeDetailsBean>();

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


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

            try {
                con = DbHandler.getDBConnection();
                try {
                    proc = con.prepareCall("{ call PARAMETER.Upsert_card_type_hdr(?,?,?,?,?,?,?) }");
                } catch (SQLException ex) {
                   // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex);
                   System.out.println("Error occurred during processing.");
                }

                proc.setString(1, oRationCardTypeHeaderBean.getCardMstIdAmend());
                proc.setString(2, oRationCardTypeHeaderBean.getCardType());
                proc.setString(3, oRationCardTypeHeaderBean.getCardDescription());
                proc.setString(4, oRationCardTypeHeaderBean.getStatus());
                proc.setString(5, ServletName);
                proc.registerOutParameter(6, java.sql.Types.VARCHAR);
                proc.registerOutParameter(7, java.sql.Types.VARCHAR);

                proc.execute();

                //message = proc.getString(6);
                hdrID = proc.getString(7);



            } catch (SQLException ex) {
                try {
                   // con.rollback();
                } catch (Exception ex1) {
                   // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex1);
                   System.out.println("Error occurred during processing.");
                }
               // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex);
               System.out.println("Error occurred during processing.");
            } finally {
                try {
                    proc.close();
                } catch (SQLException e) {
                    System.out.println("Error occurred during proc close.");
                }
                try {
                    con.close();
                } catch (SQLException ex) {
                   // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex);
                   System.out.println("Error occurred during connection close.");
                }

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

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

                   // String productId = request.getParameter("product_id" + i);
                    String quantiyUnit = request.getParameter("quantiyUnit" + i);
                   // String quantity = request.getParameter("quantity" + i);
                   // String eligibility = request.getParameter("eligibility" + i);
                   // String frequency = request.getParameter("frequency" + i);
                   // String saleRatePerUnit = request.getParameter("saleRatePerUnit" + i);
                   // String expiryDate = request.getParameter("expiryDate" + i);




                    if (productId != null) {
                        oRationCardTypeDetailsBean = new RationCardTypeDetailsBean();
                        oRationCardTypeDetailsBean.setProduct_id(productId);
                        oRationCardTypeDetailsBean.setQuantity(quantity);
                        oRationCardTypeDetailsBean.setFrequency(frequency);
                        oRationCardTypeDetailsBean.setSaleRatePerUnit(saleRatePerUnit);
                        oRationCardTypeDetailsBean.setEligibility(eligibility);
                        oRationCardTypeDetailsBean.setExpiryDate(expiryDate);

                        alRationCardTypeDetailsBean.add(oRationCardTypeDetailsBean);
                    }
                } catch (Exception e) {
                    System.out.println("Error occurred during processing.");
                }
            }
            if ((alRationCardTypeDetailsBean.size() > 0) && (!message.equalsIgnoreCase("")) && (!hdrID.equalsIgnoreCase(""))) {

                try {
                    con = DbHandler.getDBConnection();
                    try {
                        proc = con.prepareCall("{ call parameter.Upsert_card_type_dtl(?,?,?,?,?,?,?,?,?) }");
                    } catch (SQLException ex) {
                       // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex);
                       System.out.println("Error occurred during processing.");
                    }


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

                        oRationCardTypeDetailsBean = alRationCardTypeDetailsBean.get(j);


                        proc.setString(1, hdrID);
                        proc.setString(2, oRationCardTypeDetailsBean.getDetailId());
                        proc.setString(3, oRationCardTypeDetailsBean.getProduct_id());
                        proc.setString(4, oRationCardTypeDetailsBean.getQuantity());
                        proc.setString(5, oRationCardTypeDetailsBean.getEligibility());
                        proc.setString(6, oRationCardTypeDetailsBean.getFrequency());
                        proc.setString(7, oRationCardTypeDetailsBean.getSaleRatePerUnit());
                        proc.setString(8, oRationCardTypeDetailsBean.getExpiryDate());
                        proc.setString(9, ServletName);
                        proc.addBatch();


                    }

                    proc.executeBatch();

                } catch (SQLException ex) {
                    try {
                       // con.rollback();
                    } catch (Exception ex1) {
                       // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex1);
                       System.out.println("Error occurred during processing.");
                    }
                   // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex);
                   // System.out.println(ex.toString());
                   System.out.println("Error occurred during processing.");
                } finally {
                    try {
                        proc.close();
                    } catch (SQLException e) {
                       // System.out.println(e.toString());
                       System.out.println("Error occurred during proc close.");
                    }
                    try {
                        con.close();
                    } catch (SQLException ex) {
                       // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex);
                       // System.out.println(ex.toString());
                       System.out.println("Error occurred during connection close.");
                    }
                }
            }

            request.setAttribute("message", message);
            request.getRequestDispatcher("/Pds_JSP/pdsRationCardTypeMaster.jsp").forward(request, response);

        } else if ("Search".equalsIgnoreCase(ServletName)) {

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

            Connection connection = null;
            ResultSet resultset = null;
            Statement statement = null;
            connection = DbHandler.getDBConnection();
            int SeachFound = 0;

            try {
                statement = connection.createStatement();
            } catch (SQLException ex) {
               // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
               System.out.println("Error occurred during processing.");
            }
            try {

               // ResultSet rs = statement.executeQuery("select card_type_id,card_type,card_desc,status from pds_card_type_mst where card_type_id= '" + oRationCardTypeHeaderBean.getCard_type_mst_id() + "' ");

                while (rs.next()) {

                    oRationCardTypeHeaderBean.setCardMstIdAmend(rs.getString("card_type_id"));
                    oRationCardTypeHeaderBean.setCardType(rs.getString("card_type"));
                    oRationCardTypeHeaderBean.setCardDescription(rs.getString("card_desc"));
                    oRationCardTypeHeaderBean.setStatus(rs.getString("status"));


                    SeachFound = 1;
                    request.setAttribute("displayFlag", "Y");

                }

               // statement.close();


            } catch (SQLException ex) {
               // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
               System.out.println("Error occurred during processing.");
            } finally {
                try {
                statement.close();
                } catch (Exception e) {
                    System.out.println("Error occurred during connection close.");
                }
            }

            if (SeachFound == 0) {
                message = "Card Type not exists in the system";
                request.setAttribute("message", message);
            }

            //For Details Part Populate

            try {
                statement = connection.createStatement();
            } catch (SQLException ex) {
               // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
               System.out.println("Error occurred during processing.");
            }
            try {

                //ResultSet rs = statement.executeQuery(" Select p.id,(p.item_type||':'||p.type_desc) as type_dtls,(p.item_subtype||':'||p.subtype_desc) as sub_dtls, "
                        + " t.elig_qty,t.id as detailId,t.elig_expiry,t.unit_sell_rate,t.elig_basis,t.frequency,decode(p.unit,'1','K.g.','2','Lt.','3','Packets') unit, nvl(sum(l.qty_remaining),0) as qty_remaining  "
                        + " from pds_card_type_dtl t,pds_card_type_mst m,pds_product_mst p,pds_ration_ledger l,pds_card_holders h "
                        + " where m.card_type_id=t.hdr_id  and t.prod_id=p.id and l.holder_id=h.id(+) and l.prod_id(+) =t.prod_id "
                        + " and t.hdr_id= '" + oRationCardTypeHeaderBean.getCardMstIdAmend() + "'"
                        + " group by p.id,(p.item_type || ':' || p.type_desc) ,(p.item_subtype || ':' || p.subtype_desc),"
                        + "t.elig_qty,t.id ,t.elig_expiry,t.unit_sell_rate,t.elig_basis,t.frequency,"
                        + "decode(p.unit, '1', 'K.g.', '2', 'Lt.', '3', 'Packets')  ");

                while (rs.next()) {

                    oRationCardTypeDetailsBean = new RationCardTypeDetailsBean();
                    oRationCardTypeDetailsBean.setProduct_id(rs.getString("id"));
                    oRationCardTypeDetailsBean.setProductType(rs.getString("type_dtls"));
                    oRationCardTypeDetailsBean.setProductSubType(rs.getString("sub_dtls"));
                    oRationCardTypeDetailsBean.setQuantity(rs.getString("elig_qty"));
                    oRationCardTypeDetailsBean.setExpiryDate(rs.getString("elig_expiry"));
                    oRationCardTypeDetailsBean.setSaleRatePerUnit(rs.getString("unit_sell_rate"));
                    oRationCardTypeDetailsBean.setEligibility(rs.getString("elig_basis"));
                    oRationCardTypeDetailsBean.setFrequency(rs.getString("frequency"));
                    oRationCardTypeDetailsBean.setDetailId(rs.getString("detailId"));
                    oRationCardTypeDetailsBean.setQuantityUnit(rs.getString("unit"));
                    oRationCardTypeDetailsBean.setLedgerQty_remaining(rs.getString("qty_remaining"));

                    alRationCardTypeDetailsBean.add(oRationCardTypeDetailsBean);

                }

               // statement.close();
               // connection.close();

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

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

            }

            request.setAttribute("orationCardTypeHeaderBean", oRationCardTypeHeaderBean);
            request.setAttribute("alRationCardTypeDetailsBeanApend", alRationCardTypeDetailsBean);
            request.getRequestDispatcher("/Pds_JSP/pdsRationCardTypeMaster.jsp").forward(request, response);

        } else if (ServletName.equalsIgnoreCase("Update")) {

            String productId = null;
            String rowStatus = null;
            String detailID = null;
            String deletedRows = null;

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

            try {
                con = DbHandler.getDBConnection();
                try {
                    proc = con.prepareCall("{ call PARAMETER.Upsert_card_type_hdr(?,?,?,?,?,?,?) }");
                } catch (SQLException ex) {
                   // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
                   System.out.println("Error occurred during processing.");
                }

                proc.setString(1, oRationCardTypeHeaderBean.getCardMstIdAmend());
                proc.setString(2, oRationCardTypeHeaderBean.getCardTypeAmend());
                proc.setString(3, oRationCardTypeHeaderBean.getCardDescriptionAmend());
                proc.setString(4, oRationCardTypeHeaderBean.getStatusAmend());
                proc.setString(5, ServletName);
                proc.registerOutParameter(6, java.sql.Types.VARCHAR);
                proc.registerOutParameter(7, java.sql.Types.VARCHAR);



                proc.execute();

               // message = proc.getString(6);
                hdrID = proc.getString(7);

                
            } catch (SQLException ex) {
                try {
                   // con.rollback();
                } catch (Exception ex1) {
                   // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex1);
                   System.out.println("Error occurred during processing.");
                }
               // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
               System.out.println("Error occurred during processing.");
            } finally {
                try {
                    proc.close();
                } catch (SQLException e) {
                    System.out.println("Error occurred during proc close.");
                }
                try {
                    con.close();
                } catch (SQLException ex) {
                   // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
                   System.out.println("Error occurred during connection close.");
                }

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

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

                   // productId = request.getParameter("product_id_Amend" + i);
                    String quantiyUnit = request.getParameter("quantiyUnitAmend" + i);
                    //String quantity = request.getParameter("quantityAmend" + i);
                    //String eligibility = request.getParameter("eligibilityAmend" + i);
                    //String frequency = request.getParameter("frequencyAmend" + i);
                    //String saleRatePerUnit = request.getParameter("saleRatePerUnitAmend" + i);
                    //detailID = request.getParameter("detailIDAmend" + i);
                    rowStatus = request.getParameter("rowStatus" + i);
                   // String expiryDate = request.getParameter("expiryDateAmend" + i);


                    if (productId != null && rowStatus != null) {
                        oRationCardTypeDetailsBean = new RationCardTypeDetailsBean();
                        oRationCardTypeDetailsBean.setProduct_id(productId);
                        oRationCardTypeDetailsBean.setQuantity(quantity);
                        oRationCardTypeDetailsBean.setFrequency(frequency);
                        oRationCardTypeDetailsBean.setSaleRatePerUnit(saleRatePerUnit);
                        oRationCardTypeDetailsBean.setDetailId(detailID);
                        oRationCardTypeDetailsBean.setEligibility(eligibility);
                        oRationCardTypeDetailsBean.setExpiryDate(expiryDate);

                        if (rowStatus.equals("N")) {
                            alRationCardTypeDetailsBeanNew.add(oRationCardTypeDetailsBean);
                        } else {
                            alRationCardTypeDetailsBeanUpdated.add(oRationCardTypeDetailsBean);
                        }


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

            //For Deletion

           // deletedRows = request.getParameter("deletedRows");

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

                while (tokenizer.hasMoreTokens()) {

                    oRationCardTypeDetailsBean = new RationCardTypeDetailsBean();
                    oRationCardTypeDetailsBean.setDetailId(tokenizer.nextToken());

                    alRationCardTypeDetailsBeanDeleted.add(oRationCardTypeDetailsBean);

                }
            }

            
            if ((alRationCardTypeDetailsBeanUpdated.size() > 0) && (!message.equalsIgnoreCase("")) && (!hdrID.equalsIgnoreCase(""))) {

                try {
                    con = DbHandler.getDBConnection();
                    try {
                        proc = con.prepareCall("{ call parameter.Upsert_card_type_dtl(?,?,?,?,?,?,?,?,?) }");
                    } catch (SQLException ex) {
                       // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
                       System.out.println("Error occurred during processing.");
                    }

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

                        oRationCardTypeDetailsBean = new RationCardTypeDetailsBean();

                        oRationCardTypeDetailsBean = alRationCardTypeDetailsBeanUpdated.get(j);

                        proc.setString(1, hdrID);
                        proc.setString(2, oRationCardTypeDetailsBean.getDetailId());
                        proc.setString(3, oRationCardTypeDetailsBean.getProduct_id());
                        proc.setString(4, oRationCardTypeDetailsBean.getQuantity());
                        proc.setString(5, oRationCardTypeDetailsBean.getEligibility());
                        proc.setString(6, oRationCardTypeDetailsBean.getFrequency());
                        proc.setString(7, oRationCardTypeDetailsBean.getSaleRatePerUnit());
                        proc.setString(8, oRationCardTypeDetailsBean.getExpiryDate());
                        proc.setString(9, ServletName);
                        proc.addBatch();

                    }

                    proc.executeBatch();

                } catch (SQLException ex) {
                    try {
                       // con.rollback();
                    } catch (Exception ex1) {
                       // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex1);
                       System.out.println("Error occurred during processing.");
                    }
                   // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
                   // System.out.println(ex.toString());
                   System.out.println("Error occurred during processing.");
                } finally {
                    try {
                        proc.close();
                    } catch (SQLException e) {
                       // System.out.println(e.toString());
                       System.out.println("Error occurred during proc close.");
                    }
                    try {
                        con.close();
                    } catch (SQLException ex) {
//                        Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
//                        System.out.println(ex.toString());
                        System.out.println("Error occurred during connection close.");
                    }
                }
            }

            //for deletion

            if ((alRationCardTypeDetailsBeanDeleted.size() > 0) && (!message.equalsIgnoreCase("")) && (!hdrID.equalsIgnoreCase(""))) {

                try {
                    con = DbHandler.getDBConnection();
                    try {
                        proc = con.prepareCall("{ call parameter.Upsert_card_type_dtl(?,?,?,?,?,?,?,?,?) }");
                    } catch (SQLException ex) {
                       // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
                       System.out.println("Error occurred during processing.");
                    }


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

                        oRationCardTypeDetailsBean = new RationCardTypeDetailsBean();

                        oRationCardTypeDetailsBean = alRationCardTypeDetailsBeanDeleted.get(j);


                        proc.setString(1, hdrID);
                        proc.setString(2, oRationCardTypeDetailsBean.getDetailId());
                        proc.setString(3, null);
                        proc.setString(4, null);
                        proc.setString(5, null);
                        proc.setString(6, null);
                        proc.setString(7, null);
                        proc.setString(8, null);
                        proc.setString(9, "Delete");
                        proc.addBatch();


                    }

                    proc.executeBatch();

                } catch (SQLException ex) {
                    try {
                       // con.rollback();
                    } catch (Exception ex1) {
                       // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex1);
                       System.out.println("Error occurred during processing.");
                    }
                   // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
                   // System.out.println(ex.toString());
                   System.out.println("Error occurred during processing.");
                } finally {
                    try {
                        proc.close();
                    } catch (SQLException e) {
                       // System.out.println(e.toString());
                       System.out.println("Error occurred during proc close.");
                    }
                    try {
                        con.close();
                    } catch (SQLException ex) {
//                        Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
//                        System.out.println(ex.toString());
                        System.out.println("Error occurred during connection close.");
                    }
                }
            }


            //For New Insertion


            if ((alRationCardTypeDetailsBeanNew.size() > 0) && (!message.equalsIgnoreCase("")) && (!hdrID.equalsIgnoreCase(""))) {

                try {
                    con = DbHandler.getDBConnection();
                    try {
                        proc = con.prepareCall("{ call parameter.Upsert_card_type_dtl(?,?,?,?,?,?,?,?,?) }");
                    } catch (SQLException ex) {
                       // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
                       System.out.println("Error occurred during processing.");
                    }


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

                        oRationCardTypeDetailsBean = new RationCardTypeDetailsBean();
                        oRationCardTypeDetailsBean = alRationCardTypeDetailsBeanNew.get(j);


                        proc.setString(1, hdrID);
                        proc.setString(2, oRationCardTypeDetailsBean.getDetailId());
                        proc.setString(3, oRationCardTypeDetailsBean.getProduct_id());
                        proc.setString(4, oRationCardTypeDetailsBean.getQuantity());
                        proc.setString(5, oRationCardTypeDetailsBean.getEligibility());
                        proc.setString(6, oRationCardTypeDetailsBean.getFrequency());
                        proc.setString(7, oRationCardTypeDetailsBean.getSaleRatePerUnit());
                        proc.setString(8, oRationCardTypeDetailsBean.getExpiryDate());
                        proc.setString(9, "Create");
                        proc.addBatch();


                    }

                    proc.executeBatch();

                } catch (SQLException ex) {
                    try {
                       // con.rollback();
                    } catch (Exception ex1) {
                       // Logger.getLogger(RationCardTypeServlet.class.getName()).log(Level.SEVERE, null, ex1);
                       System.out.println("Error occurred during processing.");
                    }
                   // Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
                   // System.out.println(ex.toString());
                   System.out.println("Error occurred during processing.");
                } finally {
                    try {
                        proc.close();
                    } catch (SQLException e) {
                       // System.out.println(e.toString());
                       System.out.println("Error occurred during proc close.");
                    }
                    try {
                        con.close();
                    } catch (SQLException ex) {
//                        Logger.getLogger(VendorMasterServlet.class.getName()).log(Level.SEVERE, null, ex);
//                        System.out.println(ex.toString());
                        System.out.println("Error occurred during connection close.");
                    }
                }
            }


            request.setAttribute("message", message);
            request.getRequestDispatcher("/Pds_JSP/pdsRationCardTypeMaster.jsp").forward(request, response);

        }
    }
    // <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>
}
