private void createSoleDistributor(
      HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws Exception {
    HttpSession session = request.getSession();
    ArrayList<OperatingRegion> soleDisList = new ArrayList<OperatingRegion>();
    // int listIndex = Integer.parseInt(request.getParameter("listIndex"));
    soleDisList = (ArrayList) session.getAttribute("soleDistributionList");
    String custId =
        (request.getParameter("inquirer_id") != null) ? request.getParameter("inquirer_id") : "";
    if (custId.equals("")) {
      String json =
          gson.toJson(
              new JsonReturnMsg(
                  "Create Sole Distributor", "Please Chose A Whole Saler First. ", "error"));
      out.println(json);
    } else {
      Customer c = customerFacade.find(Long.parseLong(custId));
      String exist = "";
      for (OperatingRegion sd : soleDisList) {

        exist = soleDistributionFacade.checkSoleDistributionExist(sd.getRegion());
        if (!exist.equals("")) {
          String json =
              gson.toJson(
                  new JsonReturnMsg(
                      "Create Sole Distribution",
                      "<span style='color: red'>"
                          + exist
                          + "'s</span> Sole Distributionship Already Taken.",
                      "error"));
          out.println(json);
          break;
        }
      }

      if (exist.equals("")) {
        for (OperatingRegion sd : soleDisList) {
          soleDistributionFacade.addSoleDistribution(sd.getRegion(), c.getInquirer_id());
          //                    //check
          //                    soleDistributionFacade.create(sd);
          //                    sd.setCustomer(c);
          //                    soleDistributionFacade.edit(sd);
          //
          //                    c.getSoleDistribution().add(sd);
          //                    customerFacade.edit(c);
        }
        String json =
            gson.toJson(
                new JsonReturnMsg("Create Sole Distributor", "Sole Distributor Created.", "info"));
        out.println(json);
      }
    }
  }
  private void loadPage(HttpServletRequest request, HttpServletResponse response, PrintWriter out)
      throws Exception {
    String content = request.getParameter("content");
    if (content.equals("table")) {

      // paging
      int page =
          (request.getParameter("page") != null)
              ? Integer.parseInt(request.getParameter("page"))
              : 1;
      int rows =
          (request.getParameter("rows") != null)
              ? Integer.parseInt(request.getParameter("rows"))
              : 10;
      String sort =
          (request.getParameter("sort") != null) ? request.getParameter("sort") : "inquirer_id";
      String order =
          (request.getParameter("order") != null) ? request.getParameter("order") : "asc";

      // filter
      String f_id = (request.getParameter("f_id") != null) ? request.getParameter("f_id") : "";
      String f_name =
          (request.getParameter("f_name") != null) ? request.getParameter("f_name") : "";
      String f_region =
          (request.getParameter("f_region") != null) ? request.getParameter("f_region") : "";

      ArrayList<Customer> customerList =
          new ArrayList(
              soleDistributionFacade.findFilteredSoleDistributors(
                  rows, page, f_id, f_name, f_region, sort, order));

      for (Customer c : customerList) {
        c = (Customer) ConvertToJsonObject.convert(c);
      }

      System.out.println(customerList.size());
      int totalRecord =
          soleDistributionFacade.countFilteredSoleDistributors(f_id, f_name, f_region);
      String json = gson.toJson(new JsonReturnTable(totalRecord + "", customerList));
      out.println(json);
    } else if (content.equals("details")) {
      long cId = Long.parseLong(request.getParameter("inquirer_id"));
      Customer cl = customerFacade.find(cId);

      cl = (Customer) ConvertToJsonObject.convert(cl);

      String json = gson.toJson(cl);
      out.println(json);
    } else if (content.equals("dialog")) {

      // paging
      int page =
          (request.getParameter("page") != null)
              ? Integer.parseInt(request.getParameter("page"))
              : 1;
      int rows =
          (request.getParameter("rows") != null)
              ? Integer.parseInt(request.getParameter("rows"))
              : 10;
      String sort =
          (request.getParameter("sort") != null) ? request.getParameter("sort") : "inquirer_id";
      String order =
          (request.getParameter("order") != null) ? request.getParameter("order") : "asc";

      String wholesaler_company =
          (request.getParameter("wholesaler_company") != null)
              ? request.getParameter("wholesaler_company")
              : "";

      ArrayList<Customer> customerList =
          new ArrayList(
              soleDistributionFacade.findFilteredWholesalers(
                  page, rows, sort, order, wholesaler_company));

      for (Customer c : customerList) {
        c = (Customer) ConvertToJsonObject.convert(c);
      }

      System.out.println(customerList.size());
      int totalRecord =
          soleDistributionFacade.countFilteredWholesalers(
              page, rows, sort, order, wholesaler_company);
      String json = gson.toJson(new JsonReturnTable(totalRecord + "", customerList));
      out.println(json);
    } else if (content.equals("dropdown")) {
      // String selected= request.getParameter("selected");
      String json = JsonReturnDropDown.populate(Customer.CustomerType.values());
      out.println(json);
    } else if (content.equals("addDistributorShipTable")) {
      HttpSession session = request.getSession();
      System.out.println("eeeee");
      if (request.getParameter("reset") != null) {

        String reset = request.getParameter("reset");
        if (reset.equals("true")) {

          session.setAttribute("soleDistributionList", new ArrayList());
        }
      }

      ArrayList soleDisList =
          (ArrayList<OperatingRegion>) session.getAttribute("soleDistributionList");
      int totalRecord = (soleDisList != null) ? soleDisList.size() : 0;
      String json = gson.toJson(new JsonReturnTable(totalRecord + "", soleDisList));
      // System.out.println(json);
      out.println(json);
    } else if (content.equals("updateDistributorShipTable")) {
      System.out.println(request.getParameter("inquirer_id") + "!!!!!");
      long cId = Long.parseLong(request.getParameter("inquirer_id"));
      ArrayList<OperatingRegion> soleDisList =
          new ArrayList<OperatingRegion>(soleDistributionFacade.findSoleDistributorsByInquier(cId));
      int totalRecord = (soleDisList != null) ? soleDisList.size() : 0;
      // System.out.println(totalRecord);

      for (OperatingRegion sd : soleDisList) {
        sd = (OperatingRegion) ConvertToJsonObject.convert(sd);
      }
      String json = gson.toJson(new JsonReturnTable(totalRecord + "", soleDisList));
      // System.out.println(json);
      out.println(json);
    }
  }