Exemplo n.º 1
0
 public Consulta pesquisarConsultaPorAgendamento(Consulta consulta) throws Exception {
   Consulta con = null;
   Criteria cr =
       session
           .createCriteria(Consulta.class)
           .add(Restrictions.eq("dataConsulta", consulta.getDataConsulta()))
           .add(Restrictions.eq("horaConsulta", consulta.getHoraConsulta()))
           .add(Restrictions.eq("dentista", consulta.getDentista()))
           .add(Restrictions.eq("statusConsulta", "AGENDADA"));
   con = (Consulta) cr.uniqueResult();
   closeSession();
   return con;
 }
  private void btnCadastrarActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnCadastrarActionPerformed
    try {
      long matricula = Long.parseLong(txtMatricula.getText());
      int crm = Integer.parseInt(txtCRM.getText());
      String data = txtData.getText();
      String horario = Util.hourToStr(((Date) spinHorario.getValue()));

      if (!util.Util.isDataValida(data, 1)) {
        JOptionPane.showMessageDialog(
            this, "Data da consulta inválida!", "Cadastrar Consulta", JOptionPane.ERROR_MESSAGE);
        return;
      }

      // cadastra consulta
      Consulta umaConsulta = new Consulta(-1, data, horario, crm, matricula);
      long n = new servico.ConsultaAppService().inclui(umaConsulta);
      if (n >= 0) {
        // System.out.println("everything went better than expected");
        JOptionPane.showMessageDialog(
            this,
            "Consulta marcada dia " + umaConsulta.getDia() + " às " + umaConsulta.getHora() + ".",
            "Consulta marcada",
            JOptionPane.INFORMATION_MESSAGE);
        util.APAE.log("Consulta Cadastrada: " + umaConsulta.toString());
        tp.adicionarNaTabelaConsulta(new Object[] {n, data, horario, crm, matricula});
      }
      this.dispose();
    } catch (java.lang.NumberFormatException | ObjetoNaoEncontradoException o) {
      JOptionPane.showMessageDialog(
          this,
          "Verifique os campos 'Matricula' e 'CRM' digitados e tente novamente.",
          "Dados Inválidos",
          JOptionPane.ERROR_MESSAGE);
    }
  } // GEN-LAST:event_btnCadastrarActionPerformed