public void executeAction(ActionEvent event) {
    if (mode.equals(Constant.SCHEDULE_REMOVE)) {
      for (ScheduleBranch row : listScheduleBranch) {
        if (row.getState() == 1) {
          tableService.removeSchedule(
              row.getCrmDoctorSchedule().getCrmBranch().getId(),
              row.getCrmDoctorSchedule().getCrmDoctor().getId());
        }
      }
    }

    int count = 0;
    for (ScheduleBranch row : listScheduleBranch) {
      if (row.getState() == 1) {
        String message = FacesUtil.getMessage("msg_record_ok");
        row.setMessage(message);
        tableService.saveDoctorSchedule(row.getCrmDoctorSchedule());
        count++;
      }
    }

    disabledButton = true;
    disabledExecuteButton = true;
    String message = FacesUtil.getMessage("msg_load_ok", String.valueOf(count));
    FacesUtil.addInfo(message);
  }
  public void saveAction() {
    String message = null;

    int result = tablesService.saveProfile(selected);
    if (result == 0) {
      list = tablesService.getListProfile();
      model = new ProfileDataModel(list);
      message = FacesUtil.getMessage("msg_record_ok");
      FacesUtil.addInfo(message);
    } else if (result == -1) {
      String paramValue = FacesUtil.getMessage("pro_code");
      message = FacesUtil.getMessage("msg_record_unique_exception", paramValue);
      FacesUtil.addError(message);
    }
  }
  public void handleFileUpload(FileUploadEvent event) {
    String message = FacesUtil.getMessage("file_msg_upload", event.getFile().getFileName());

    FacesUtil.addInfo(message);
    disabledButton = false;
    disabledExecuteButton = true;
    try {
      fileName =
          FacesUtil.getParameterTextValue("RUTA_ARCHIVOS_TEMPORALES")
              + "/"
              + event.getFile().getFileName();
      copyFile(fileName, event.getFile().getInputstream());
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  public void analyzeAction(ActionEvent event) {
    listScheduleBranch = new ArrayList<ScheduleBranch>();
    File file = new File(fileName);
    BufferedReader reader = null;

    try {
      reader = new BufferedReader(new FileReader(file));
      String text = null;

      // repeat until all lines is read
      while ((text = reader.readLine()) != null) {
        ScheduleBranch scheduleBranch = new ScheduleBranch();
        scheduleBranch.setState(1);

        String[] columns = text.split(";");
        scheduleBranch.setLine(text);
        if (columns.length == 5) {
          BigDecimal idDoctor = null;
          Integer day = 0;
          Date startHour = null;
          Date endHour = null;
          BigDecimal idBranch = null;

          try {
            idDoctor = new BigDecimal(columns[0]);
          } catch (Exception ex) {
            scheduleBranch.setMessage("Columna Doctor inválido");
            scheduleBranch.setState(0);
          }

          if (scheduleBranch.getState() == 1) {
            try {
              day = Integer.parseInt(columns[1]);
            } catch (Exception ex) {
              scheduleBranch.setMessage("Columna Día inválido");
              scheduleBranch.setState(0);
            }
          }

          if (scheduleBranch.getState() == 1) {
            startHour = FacesUtil.stringTOSDate(columns[2], "HH:mm");
            if (startHour == null) {
              scheduleBranch.setMessage("Columna Hora Inicial inválido");
              scheduleBranch.setState(0);
            }
          }

          if (scheduleBranch.getState() == 1) {
            endHour = FacesUtil.stringTOSDate(columns[3], "HH:mm");
            if (endHour == null) {
              scheduleBranch.setMessage("Columna Hora Final inválido");
              scheduleBranch.setState(0);
            }
          }

          if (scheduleBranch.getState() == 1) {
            try {
              idBranch = new BigDecimal(columns[4]);
            } catch (Exception ex) {
              scheduleBranch.setMessage("Columna Sucursal inválido");
              scheduleBranch.setState(0);
            }
          }

          if (scheduleBranch.getState() == 1) {
            CrmDoctorSchedule crmDoctorSchedule = new CrmDoctorSchedule();
            crmDoctorSchedule.setDay(day);
            crmDoctorSchedule.setStartHour(startHour);
            crmDoctorSchedule.setEndHour(endHour);

            CrmDoctor crmDctor = new CrmDoctor();
            crmDctor.setId(idDoctor);
            crmDoctorSchedule.setCrmDoctor(crmDctor);

            CrmBranch crmBranch = new CrmBranch();
            crmBranch.setId(idBranch);
            crmDoctorSchedule.setCrmBranch(crmBranch);
            scheduleBranch.setCrmDoctorSchedule(crmDoctorSchedule);

            scheduleBranch.setMessage("Listo para Procesar");
            disabledExecuteButton = false;
          }
        } else {
          scheduleBranch.setMessage(
              "El número de columnas no corresponde al mínimo requerido (Doctor, Día, Hora Inicial, Hora Final, Sucursal)");
          scheduleBranch.setState(0);
        }
        listScheduleBranch.add(scheduleBranch);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (reader != null) {
          reader.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }