public void actionPerformed(ActionEvent ev) {
        try {
          // stok
          String query = "DELETE FROM stok_produk WHERE id_produk=" + idProduk;
          int hasil1 = stm.executeUpdate(query);

          // pemasukkan
          query = "DELETE FROM pemasukan WHERE id_produk=" + idProduk;
          int hasil2 = stm.executeUpdate(query);

          // pengeluaran
          query = "DELETE FROM pengeluaran WHERE id_produk=" + idProduk;
          int hasil3 = stm.executeUpdate(query);

          // produk
          query = "DELETE FROM produk WHERE id_produk=" + idProduk;
          int hasil4 = stm.executeUpdate(query);

          if (hasil1 == 1 || hasil2 == 1 || hasil3 == 1 && hasil4 == 1) {
            setDataTabel();
            JOptionPane.showMessageDialog(null, "berhasil hapus");
          } else {
            JOptionPane.showMessageDialog(null, "gagal");
          }
        } catch (SQLException SQLerr) {
          SQLerr.printStackTrace();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
Esempio n. 2
0
  private void btnDeleteActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnDeleteActionPerformed
    // TODO add your handling code here:

    if (txtKodeAbsen.getText().equals("")) {
      JOptionPane.showMessageDialog(
          null, "Isi Kode Absen yang Akan dihapus !!!", "Peringatan", JOptionPane.ERROR_MESSAGE);
      txtKodeAbsen.requestFocus();
    } else {
      try {
        Class.forName(KoneksiDatabase.driver);
        java.sql.Connection c =
            DriverManager.getConnection(
                KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass);
        Statement s = c.createStatement();
        String sql = "DELETE FROM absensi_lembur where kd_absen ='" + txtKodeAbsen.getText() + "'";
        s.executeUpdate(sql);
        JOptionPane.showMessageDialog(null, "Data Berhasil Dihapus !");
        Baru();
      } catch (Exception e) {
        JOptionPane.showMessageDialog(
            null, "Kemungkinan terjadi kegagalan koneksi", "Warning", JOptionPane.ERROR_MESSAGE);
      }
    }
  } // GEN-LAST:event_btnDeleteActionPerformed
Esempio n. 3
0
  private void Simpan() {

    if (btnSave.getText().equals("Edit")) {
      try {
        Class.forName(KoneksiDatabase.driver);
        java.sql.Connection c =
            DriverManager.getConnection(
                KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass);
        Statement s = c.createStatement();

        String sql;
        sql = "update absensi_lembur set tipehari = '";
        sql += cmbJenisHari.getSelectedItem() + "', tot_waktu_lembur='";
        sql += txtTotalLembur.getText() + "'";
        sql += "where kd_absen = '" + txtKodeAbsen.getText() + "'";
        s.executeQuery(sql);

        JOptionPane.showMessageDialog(
            null, "Data Berhasil Disimpan!!!", "Informasi", JOptionPane.INFORMATION_MESSAGE);
      } catch (Exception e) {
        JOptionPane.showMessageDialog(
            null,
            "Gagal Disimpan, Data Harus Lengkap !!!",
            "Peringatan",
            JOptionPane.WARNING_MESSAGE);
      }
    }
    Baru();
  }
 public void excluir(Oriundo oriundo) throws SQLException {
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           new conexao().config.getString("usuario"),
           new conexao().config.getString("senha"));
   PreparedStatement ps = null;
   String sqlExcluir = "DELETE FROM oriundo WHERE codigo=?";
   try {
     ps = con.prepareStatement(sqlExcluir);
     ps.setInt(1, oriundo.getCodigo());
     ps.executeUpdate();
     JOptionPane.showMessageDialog(
         null, "Ecluido Com Sucesso: ", "Mensagem do Sistema - Excluir", 1);
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Excluir", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Excluir", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
 }
Esempio n. 5
0
  private void LoginButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_LoginButtonActionPerformed
    // TODO add your handling code here:
    String sql = "select * from bruker where brukerNavn=? and brukerPassord=?";

    try {
      int userType = accountType.getSelectedIndex();

      pst = conn.prepareStatement(sql);
      pst.setString(1, UsrInput.getText());
      pst.setString(2, PswdInput.getText());
      rs = pst.executeQuery();

      if (rs.next()) {
        // JOptionPane.showMessageDialog(null,"Username and password is correct");
        close();
        if (userType == 0) {
          MainPage m = new MainPage();
          m.setVisible(true);
        } else {
          fMainPage fm = new fMainPage();
          fm.setVisible(true);
        }

      } else {
        JOptionPane.showMessageDialog(null, "Username or password is incorrect");
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
    }
  } // GEN-LAST:event_LoginButtonActionPerformed
Esempio n. 6
0
  public void excluirLote(List<JobLote> listaExcluir) {

    Connection conn = null;
    PreparedStatement stmt = null;
    String sql = "delete from joblote where job = ? and operacao = ? and lote =? ";

    try {

      conn = GerenciaConexaoSQLServer.abreConexao();
      conn.setAutoCommit(false);

      for (int i = 0; i <= listaExcluir.size() - 1; i++) {

        JobLote job = listaExcluir.get(i);

        stmt = conn.prepareStatement(sql);
        stmt.setString(1, job.getJob().trim().replace(".", ""));
        stmt.setInt(2, job.getOperNum());
        stmt.setInt(3, job.getLote());
        stmt.executeUpdate();

        alteraJobAposExclusao(conn, job);

        gravaJobsExcluidos(
            conn, job.getJob().trim().replace(".", ""), job.getOperNum(), job.getLote());
      }

      // adiciona a op na tela inicial
      for (int i = 0; i <= listaExcluir.size() - 1; i++) {
        JobLote job = listaExcluir.get(i);
        JobProtheus jobProtheus = retornaJob(conn, job);
        adicionaOPTelaInicial(conn, jobProtheus, job);
      }

      JOptionPane.showMessageDialog(this, "Job Excluido com Sucesso!");
      conn.commit();

    } catch (SQLException e) {

      if (conn != null) {

        try {

          conn.rollback();
          conn.setAutoCommit(true);

          JOptionPane.showMessageDialog(null, "Não foi possivel excluir! Descrição: " + e);

        } catch (SQLException ex) {
          JOptionPane.showMessageDialog(null, "Erro ao fazer o rollback! Descrição: " + ex);
        }
      }

    } finally {
      GerenciaConexaoSQLServer.closeConexao(conn, stmt);
    }
  }
Esempio n. 7
0
 private void passwordTextBoxKeyPressed(
     java.awt.event.KeyEvent evt) { // GEN-FIRST:event_passwordTextBoxKeyPressed
   // TODO add your handling code here:
   int key = evt.getKeyCode();
   if (key == KeyEvent.VK_ENTER) {
     boolean verify = false;
     String user = usernameTextBox.getText();
     String passwd = passwordTextBox.getText();
     if (user.equals("") || passwd.equals("")) {
       JOptionPane.showMessageDialog(
           AdminLogin.this, "Sorry! You must enter a Username and Password to login ");
       usernameTextBox.requestFocus();
     } else {
       Connection con = getConnection();
       try {
         ResultSet rows;
         Statement s =
             con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
         String select = "Select * from admin;";
         rows = s.executeQuery(select);
         while (rows.next()) {
           String username = rows.getString("Username");
           String password = rows.getString("Password");
           if (user.equals(username) && passwd.equals(password)) {
             verify = true;
             this.dispose();
             //                       btn.btnEnabled();
             break;
           }
         }
         if (verify == false) {
           verify = false;
           JOptionPane.showMessageDialog(
               AdminLogin.this, "Access Denied! Invalid Username or Password");
           usernameTextBox.setText("");
           passwordTextBox.setText("");
           usernameTextBox.requestFocus();
         }
       } catch (SQLException e) {
         System.out.println(e.getMessage());
       }
       if (verify == false) {
         JOptionPane.showMessageDialog(
             AdminLogin.this, "Access Denied!  Invalid Username or Password");
         usernameTextBox.setText("");
         passwordTextBox.setText("");
         usernameTextBox.requestFocus();
       } // TODO add your handling code here:
     }
   }
   if (key == KeyEvent.VK_UP) {
     usernameTextBox.grabFocus();
   }
   if (key == KeyEvent.VK_KP_UP) {
     usernameTextBox.grabFocus();
   }
 } // GEN-LAST:event_passwordTextBoxKeyPressed
Esempio n. 8
0
  private void buttonLoginActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_buttonLoginActionPerformed
    boolean verify = false;
    String userName = usernameTextBox.getText();
    String passwd = passwordTextBox.getText();
    if (userName.equals("") && passwd.equals("")) {
      JOptionPane.showMessageDialog(
          AdminLogin.this, "Sorry! You must enter a Username and Password to login ");
      usernameTextBox.requestFocus();
    } else if (passwd.equals("")) {
      JOptionPane.showMessageDialog(AdminLogin.this, "Sorry! You must enter a Password to login ");
      usernameTextBox.requestFocus();
    } else if (userName.equals("")) {
      JOptionPane.showMessageDialog(AdminLogin.this, "Sorry! You must enter a Username to login ");
      usernameTextBox.requestFocus();
    } else {
      System.out.println("check: admin login success");
      Query query = null;
      //		EntityManagerFactory emf = Persistence.createEntityManagerFactory("smsPU");
      //		EntityManager em = emf.createEntityManager();

      query =
          School.manager
              .createQuery(
                  "select a from Administrator a where a.userName = :userName AND a.password = :password")
              .setParameter("userName", userName)
              .setParameter("password", passwd);
      System.out.println("Number of admins is/are : " + query.getResultList().size());
      verify = (query.getResultList().size() == 1) ? true : false;
      //		verify = (passwd.equals(admin.getPassword()) && userName.equals(admin.getUserName())) ?
      // true : false;
      if (verify) {

        Administrator admin = (Administrator) query.getSingleResult();
        this.dispose();
        AdminMainView adminView = new AdminMainView();
        adminView.btnEnabled();
        adminView.setVisible(true);
      } else {
        JOptionPane.showMessageDialog(
            AdminLogin.this, "Access Denied! Invalid Username or Password");
        usernameTextBox.setText("");
        passwordTextBox.setText("");
        usernameTextBox.requestFocus();
      }
      //            } catch (SQLException e) {
      //                System.out.println(e.getMessage());
      //            }

      // TODO add your handling code here:
    }
  } // GEN-LAST:event_buttonLoginActionPerformed
 private void prosesEdit(String query) {
   try {
     int hasil = stm.executeUpdate(query);
     if (hasil == 1) {
       setDataTabel();
       JOptionPane.showMessageDialog(null, "edit berhasil");
     } else {
       JOptionPane.showMessageDialog(null, "gagal");
     }
   } catch (SQLException SQLerr) {
     SQLerr.printStackTrace();
   }
 }
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    if (source == bRes) {
      tname.setText("");
      textra.setText("");
    } else {
      if (it.isSelected()) field = 1;
      else if (civil.isSelected()) field = 2;
      else if (mech.isSelected()) field = 3;

      if (tname.getText().equals("") | textra.getText().equals("") | field == 0)
        JOptionPane.showMessageDialog(null, "Please Fill in All Entries!!");
      else {
        String sal = (String) cbsal.getSelectedItem();

        try {
          // Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          // Connection conn=DriverManager.getConnection("jdbc:odbc:go");
          Class.forName("com.mysql.jdbc.Driver").newInstance();
          Connection conn = DriverManager.getConnection("jdbc:mysql:///go", "root", "");
          Statement pst = conn.createStatement();

          pst.executeUpdate(
              "Insert into company values('"
                  + tname.getText()
                  + "','"
                  + textra.getText()
                  + "','"
                  + (String) sal
                  + "','"
                  + field
                  + "','"
                  + tusr.getText()
                  + "','"
                  + tpwd.getText()
                  + "')");
          conn.close();
          String msg =
              "Your Details are Stored. Login again to View Related applicants!  Thank You!!";
          JOptionPane.showMessageDialog(null, msg);
          setVisible(false);
          login ab = new login();

        } catch (Exception exc) {
          JOptionPane.showMessageDialog(null, tname.getText() + " : " + exc);
          System.exit(0);
        }
      }
    }
  }
 public List<Oriundo> listar() throws SQLException {
   List<Oriundo> resultado = new ArrayList<Oriundo>();
   conexao propCon = new conexao();
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           propCon.config.getString("usuario"),
           propCon.config.getString("senha"));
   PreparedStatement ps = null;
   ResultSet rs = null;
   String sqlListar = "SELECT * FROM oriundo Order by codigo DESC";
   Oriundo oriundo;
   try {
     ps = con.prepareStatement(sqlListar);
     rs = ps.executeQuery();
     // if(rs==null){
     // return null;
     // }
     while (rs.next()) {
       oriundo = new Oriundo();
       oriundo.setCodigo(rs.getInt("codigo"));
       oriundo.setDescricao(rs.getString("descricao"));
       oriundo.setData_cadastro(rs.getDate("data_cadastro"));
       oriundo.setDia_fechamento(rs.getInt("dia_fechamento"));
       oriundo.setDia_pag(rs.getInt("dia_pag"));
       resultado.add(oriundo);
     }
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Localizar", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
   return resultado;
 }
Esempio n. 12
0
  public void actionPerformed(ActionEvent ae) {

    try {
      if (ae.getSource() == b7) {

        rs = st.executeQuery("select count(*) from employeemaster");
        if (rs.next()) {
          t6.setText(rs.getString(1));
        }

        rs = st.executeQuery("select * from Head");
        if (rs.next()) {
          t1.setText(rs.getString(1));
          t2.setText(rs.getString(2));
          t7.setText(rs.getString(3));
          t4.setText(rs.getString(4));
          t5.setText(rs.getString(5));
          t3.setText(rs.getString(6));
        }
      } else if (ae.getSource() == b6) {
        dispose();
      }

    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, "Error is" + e);
    }
  }
Esempio n. 13
0
 private void showHelp(Graphics g)
       //  PRE:  g must be initialized.
       //  POST: Displays the help image to the screen.
     {
   JOptionPane.showMessageDialog(this, "Once you are satisfied, click anywhere to continue!");
   Drawing.drawImage(g, 0, 0, getWidth(), getHeight(), ".\\images\\help.jpg");
 }
Esempio n. 14
0
  public void atualizaTabela() {

    try {

      if (!modelo.isEmpty()) {
        modelo.limpaLista();
      }
      lista.clear();
      // refaz a consulta
      SistemaDao2 dao2 = new SistemaDao2();
      lista = dao2.retornaJobLoteFechadoPorWorkCenter();

      // adicionar uma lista vazia ao modelo dá erro, so podemos adicionar se a lista nao estiver
      // vazia
      if (!lista.isEmpty()) {
        // adiciona lista ao modelo e ordena a tabela
        modelo.adicionaLista(lista);
        sorter = new TableRowSorter<ExclusaoTableModel>(modelo);
        tabela.setRowSorter(sorter);
        modelo.fireTableDataChanged();
      }

      ajustaTabelaParaMobile();

    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, "Erro ao atualizar a tabela: " + e);
    }
  }
Esempio n. 15
0
  /**
   * metoda pobierajaca wszystkie rekordy z BD1.
   *
   * @return
   */
  public ArrayList<StudentFirst> getAllStudentFromDBfirst() {
    logger.info("getAllContactFromDB");
    ResultSet result = null;
    ArrayList<StudentFirst> students = new ArrayList<>();
    try {
      prepStmt = conn.prepareStatement("SELECT * FROM student1");
      result = prepStmt.executeQuery();
      int id, index;
      String name, surname, university, faculty, field;

      for (int i = 0; result.next(); i++) {
        id = result.getInt("stud1_id");
        index = result.getInt("stud1_index");
        name = result.getString("stud1_name");
        surname = result.getString("stud1_lastname");
        university = result.getString("stud1_university");
        faculty = result.getString("stud1_faculty");
        field = result.getString("stud1_field");
        students.add(new StudentFirst(id, index, name, surname, university, faculty, field));
        logger.info(students.get(i).toString());
      }

      if (students.size() == 0) {
        logger.info("Pusta BD?");
      }
      return students;
    } catch (SQLException e1) {
      JOptionPane.showMessageDialog(null, e1);
      e1.printStackTrace();
      return null;
    }
  }
Esempio n. 16
0
    public void actionPerformed(ActionEvent e) {
      int k = 0;
      try {
        rs = statement.executeQuery("select * from hostelStatus");
        while (rs.next()) {
          data[k][0] = rs.getString(1);
          data[k][1] = rs.getString(2);
          data[k][2] = rs.getString(3);
          k++;
        }

        data[k][0] = " ";
        data[k][1] = " ";
        data[k][2] = " ";

        table = new JTable(data, col);
        table.setFont(new Font("Serif", Font.BOLD, 16));
        table.setBackground(new Color(250, 250, 250));

        JScrollPane jsp = new JScrollPane(table);
        jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        jsp.setBounds(5, 100, 590, 200);
        cn.add(jsp);

      } catch (Exception sq) {
        JOptionPane.showMessageDialog(null, "error" + sq);
      }
    }
Esempio n. 17
0
  public void actionPerformed(ActionEvent ae) {
    if (ae.getSource() == b1) {
      try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con =
            DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "123");
        PreparedStatement ps =
            con.prepareStatement("select * from LoginForm where username=? and password=?");
        String UserName = t1.getText();
        String Password = jp1.getText();
        ps.setString(1, UserName);
        ps.setString(2, Password);
        ResultSet rs = ps.executeQuery();
        boolean flag = rs.next();
        if (flag) {
          new Main();
          f.setVisible(false);
        } else {
          JOptionPane.showMessageDialog(null, "Please Enter valid Name And Password");
        }

      } catch (Exception e) {
        System.out.println("Error:" + e);
      }
    } else if (ae.getSource() == b2) {
      t1.setText("");
      jp1.setText("");
    } else if (ae.getSource() == b3) {

      f.setVisible(false);
    }
  }
  public void display(ResultSet rs) {
    try {
      boolean recordNumber = rs.next();
      if (recordNumber) {
        payNo = rs.getString(1);
        pasNo = rs.getString(2);
        pasName = rs.getString(3);
        mode = rs.getString(4);
        dt = rs.getString(5);
        amount = rs.getString(6);
        rev = rs.getString(7);

        text1.setText(payNo);
        combo1.setSelectedItem(pasNo);
        combo2.setSelectedItem(pasName);
        combo4.setSelectedItem(mode);
        p_date.setText(dt);
        combo8.setSelectedItem(amount);
        combo3.setSelectedItem(rev);

      } else {
        JOptionPane.showMessageDialog(
            null, "Record Not found", "ERROR", JOptionPane.DEFAULT_OPTION);
      }
    } catch (SQLException sqlex) {
      sqlex.printStackTrace();
    }
  }
Esempio n. 19
0
  private void Baru() {
    btnSave.setText("Save");
    txtNip.requestFocus();
    txtNip.setText("");

    try {
      Class.forName(KoneksiDatabase.driver);
      java.sql.Connection c =
          DriverManager.getConnection(
              KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass);
      Statement s = c.createStatement();
      String sql = "select * from absensi_lembur";
      ResultSet rs = s.executeQuery(sql);

      final String[] headers = {
        "Kd Absen",
        "NIP",
        "Tgl Absen",
        "Masuk",
        "Pulang",
        "Hari",
        "Tipe Hari",
        "Terlambat",
        "Lembur",
        "Tipe Lembur",
        "Tot Lembur",
        "Tunj Makan",
        "Tunj Transport"
      };
      rs.last();

      int n = rs.getRow();
      Object[][] data = new Object[n][13];
      int p = 0;
      rs.beforeFirst();
      while (rs.next()) {
        data[p][0] = rs.getString(1);
        data[p][1] = rs.getString(2);
        data[p][2] = rs.getString(3);
        data[p][3] = rs.getString(4);
        data[p][4] = rs.getString(5);
        data[p][5] = rs.getString(6);
        data[p][6] = rs.getString(7);
        data[p][7] = rs.getString(8);
        data[p][8] = rs.getString(9);
        data[p][9] = rs.getString(10);
        data[p][10] = rs.getString(11);
        data[p][11] = rs.getString(12);
        data[p][12] = rs.getString(13);
        p++;
      }
      tblLembur.setModel(new DefaultTableModel(data, headers));
      tblLembur.setAlignmentX(CENTER_ALIGNMENT);

    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          null, "Gagal Koneksi, Ada Kesalahan.", "Warning", JOptionPane.WARNING_MESSAGE);
    }
  }
Esempio n. 20
0
  public static void updateDoljnost() {
    try {
      DBClass db = new DBClass();
      ArrayList<Doljnost> d = db.doljnostFromDB();
      comboBox_doljnost.removeAllItems();
      for (int i = 0; i < d.size(); i++) {
        comboBox_doljnost.addItem(d.get(i));
      }

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(null, ee.getMessage());
    }
  }
Esempio n. 21
0
  public static void updateKvalification() {
    try {

      DBClass db2 = new DBClass();
      ArrayList<Kvalification> k = db2.kvalificationFromDB();
      comboBox_kvalification.removeAllItems();
      for (int i = 0; i < k.size(); i++) {
        comboBox_kvalification.addItem(k.get(i));
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(null, ee.getMessage());
    }
  }
 public Oriundo localizar(Integer codigo) throws SQLException {
   Connection con =
       DriverManager.getConnection(
           new conexao().url,
           new conexao().config.getString("usuario"),
           new conexao().config.getString("senha"));
   PreparedStatement ps = null;
   ResultSet rs = null;
   String sqlLocalizar = "SELECT * FROM oriundo WHERE codigo=?";
   Oriundo oriundo = new Oriundo();
   try {
     ps = con.prepareStatement(sqlLocalizar);
     ps.setInt(1, codigo);
     rs = ps.executeQuery();
     // if(!rs.next()){
     // return null;
     // }
     oriundo.setCodigo(rs.getInt("codigo"));
     oriundo.setDescricao(rs.getString("descricao"));
     oriundo.setData_cadastro(rs.getDate("data_cadastro"));
     oriundo.setDia_fechamento(rs.getInt("dia_fechamento"));
     oriundo.setDia_pag(rs.getInt("dia_pag"));
     return oriundo;
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(
         null, "NumberFormaterExeption Erro: " + e.getMessage(), "ClasseDAO Func.Localizar", 0);
     e.printStackTrace();
   } catch (NullPointerException e) {
     JOptionPane.showMessageDialog(
         null, "NullPointerException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (SQLException e) {
     JOptionPane.showMessageDialog(
         null, "SQLException Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Exception Erro: " + e.getMessage(), "ClasseDAO Func. Localizar", 0);
     e.printStackTrace();
   } finally {
     ps.close();
     con.close();
   }
   return oriundo;
 }
 public OriundoDAO() {
   try {
     Class.forName(new conexao().config.getString("driver"));
   } catch (ClassNotFoundException ex) {
     JOptionPane.showMessageDialog(
         null, "Driver Erro: " + ex.getMessage(), "Construtor da Classe", 0);
     ex.printStackTrace();
   }
 }
Esempio n. 24
0
  private void jBPesquisarActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jBPesquisarActionPerformed
    // TODO add your handling code here:

    String text = jTFPesquisar.getText();

    if (text.length() == 0) {
      sorter.setRowFilter(null);
    } else {
      try {
        sorter.setRowFilter(RowFilter.regexFilter(text));
      } catch (PatternSyntaxException pse) {
        JOptionPane.showMessageDialog(null, "Bad regex pattern");

      } catch (RuntimeException ex2) {
        JOptionPane.showMessageDialog(null, "Erro: " + ex2.getMessage());
      }
    }
  } // GEN-LAST:event_jBPesquisarActionPerformed
Esempio n. 25
0
  public static void goer() throws Exception {

    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con =
        (Connection) DriverManager.getConnection("jdbc:oracle:thin:@localhost", "system", "system");
    String query2 = "select * from logger";
    Statement st2 = con.createStatement();
    ResultSet rs = st2.executeQuery(query2);
    boolean b = false;
    while (rs.next()) {
      if ((rs.getString(3)).equals(p2.str3)) {
        b = true;
      }
    }
    if (b == false) {
      String query1 =
          "insert into logger values('"
              + p2.str1
              + "','"
              + p2.str2
              + "','"
              + p2.str3
              + "','"
              + p2.str4
              + "','"
              + p2.str5
              + "','"
              + p2.str7
              + "','"
              + p2.str8
              + "','"
              + p2.str9
              + "','"
              + p2.str13
              + "')";
      Statement st1 = con.createStatement();
      st1.executeQuery(query1);
      JOptionPane.showMessageDialog(null, "welcome\n now you are a meber of our team ");
    } else {
      JOptionPane.showMessageDialog(null, "this username already exist");
    }
  }
Esempio n. 26
0
  // Вид формы при изменении сотрудника
  public void sotrDiaUpdate(Sotrudnik s) {
    label_id_hidden.setText(Integer.toString(s.getId_sotrudnika()));
    textField_familiya.setText(s.getFamiliya());
    textField_imya.setText(s.getImya());
    textField_otchestvo.setText(s.getOtchestvo());
    textField_phone.setText(s.getPhone());
    textField_date.setText(s.getData_priema().toString());
    comboBox_doljnost.removeAllItems();
    comboBox_kvalification.removeAllItems();

    try {
      DBClass db = new DBClass();
      ArrayList<Doljnost> d = db.doljnostFromDB();
      DBClass db2 = new DBClass();
      Doljnost dd = db2.doljnostFromDB(s);
      for (int i = 0; i < d.size(); i++) {
        comboBox_doljnost.addItem(d.get(i));
        Doljnost ddd = (Doljnost) comboBox_doljnost.getItemAt(i);
        if (dd.getNazvanie_doljnosti().equals(ddd.getNazvanie_doljnosti())) dd = ddd;
      }
      comboBox_doljnost.setSelectedItem(dd);

      DBClass db3 = new DBClass();
      ArrayList<Kvalification> k = db3.kvalificationFromDB();
      DBClass db4 = new DBClass();
      Kvalification kk = db4.kvalificationFromDB(s);
      for (int i = 0; i < k.size(); i++) {
        comboBox_kvalification.addItem(k.get(i));
        Kvalification kkk = (Kvalification) comboBox_kvalification.getItemAt(i);
        if (kk.getNazvanie_kvalification().equals(kkk.getNazvanie_kvalification())) kk = kkk;
      }

      comboBox_kvalification.setSelectedItem(kk);

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(panelException, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(panelException, ee.getMessage());
    }
  }
Esempio n. 27
0
 private static Connection getConnection() {
   Connection con = null;
   try {
     Class.forName("com.mysql.jdbc.Driver");
     String url = "jdbc:mysql://localhost:3306/SMS";
     String user = "******";
     String pw = "";
     con = DriverManager.getConnection(url, user, pw);
   } catch (ClassNotFoundException e) {
     System.out.println("Unable to locate class");
     System.out.println(e.getMessage());
     JOptionPane.showMessageDialog(null, " Database not connected");
     // System.exit(0);
   } catch (SQLException e) {
     System.out.println(e.getMessage());
     JOptionPane.showMessageDialog(null, " Database not connected");
     // System.exit(0);
   }
   return con;
 }
Esempio n. 28
0
 public FirstDBrepo() {
   try {
     logger.info("FirstDBrepo construct");
     Class.forName("org.sqlite.JDBC");
     conn = DriverManager.getConnection("jdbc:sqlite:projekt3.sqlite");
     logger.info("Success, connection with DB!");
   } catch (Exception e) {
     JOptionPane.showMessageDialog(null, e);
     e.printStackTrace();
   }
 }
Esempio n. 29
0
  // Вид формы при добавлении нового сотрудника
  public void sotrDiaInsert() {
    label_id_hidden.setText("Новый сотрудник");
    textField_familiya.setText("");
    textField_imya.setText("");
    textField_otchestvo.setText("");
    textField_phone.setText("");
    comboBox_doljnost.removeAllItems();
    comboBox_kvalification.removeAllItems();

    Calendar calend = Calendar.getInstance();
    if (calend.get(Calendar.MONTH) <= 9) {
      textField_date.setText(
          String.valueOf(
              (calend.get(Calendar.YEAR) + "-" + ("0" + (1 + calend.get(Calendar.MONTH))) + "-")
                  + (calend.get(Calendar.DATE))));
    } else
      textField_date.setText(
          String.valueOf(
              ((calend.get(Calendar.YEAR)) + "-" + (1 + calend.get(Calendar.MONTH)) + "-")
                  + (calend.get(Calendar.DATE))));
    textField_date.setEnabled(false);

    try {
      DBClass db = new DBClass();
      ArrayList<Doljnost> d = db.doljnostFromDB();
      for (int i = 0; i < d.size(); i++) {
        comboBox_doljnost.addItem(d.get(i));
      }
      DBClass db2 = new DBClass();
      ArrayList<Kvalification> k = db2.kvalificationFromDB();
      for (int i = 0; i < k.size(); i++) {
        comboBox_kvalification.addItem(k.get(i));
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(panelException, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(panelException, ee.getMessage());
    }
  }
Esempio n. 30
0
  private void jBPesquisarKeyTyped(
      java.awt.event.KeyEvent evt) { // GEN-FIRST:event_jBPesquisarKeyTyped

    if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
      if (evt.getSource() == jBPesquisar) {

        String text = jTFPesquisar.getText();
        if (text.length() == 0) {
          sorter.setRowFilter(null);
        } else {
          try {
            sorter.setRowFilter(RowFilter.regexFilter(text));
          } catch (PatternSyntaxException pse) {
            JOptionPane.showMessageDialog(this, "Erro na pesquisa");
          } catch (RuntimeException ex2) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex2.getMessage());
          }
        }
      }
    }
  } // GEN-LAST:event_jBPesquisarKeyTyped