Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None | 0 0
  1. btnInsertarReg_1.addActionListener(new ActionListener() {
  2.             public void actionPerformed(ActionEvent e) {
  3.                 try {
  4.                     int empNo = Integer.parseInt(empno.getText());
  5.                     float Salario = Float.parseFloat(salario.getText());
  6.                     int Comision = Integer.parseInt(comision.getText());
  7.                     String fecha = fechaalt.getText().toString();
  8.                     DateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
  9.                     formato.setLenient(true);
  10.                         Date mifecha = (Date) formato.parse(fecha);
  11.                         java.sql.Date sqlDate1 = new java.sql.Date(mifecha.getTime());
  12.                     int Dept_no = Integer.parseInt(comboDep.getSelectedItem().toString());
  13.                     int Dir = Integer.parseInt(comboDirec.getSelectedItem().toString());
  14.                    
  15.                     String mensaje2=OperacionesEmple.insertaremple(conexion, empNo, apellido.getText(),
  16.                             oficio.getText(), Salario, Comision,
  17.                             sqlDate1, Dept_no, Dir);
  18.                    
  19.                     textArea_1.setText(mensaje2);
  20.                    
  21.                     }catch(NumberFormatException a){
  22.                         textArea_1.setText("ERROR EL DATO TIENE QUE SER NUMÉRICO");
  23.                     }catch(ParseException e3) {
  24.                         textArea_1.setText("LA FECHA NO ES VALIDA");
  25.                     }
  26.                
  27.             }
  28.         });
  29.  
  30. JComboBox comboDirec = new JComboBox();
  31.         String consulta2="select count(*) from empleados";
  32.         Statement sentencia2;
  33.         try {
  34.             sentencia2 = conexion.createStatement();
  35.             ResultSet resul2;
  36.             resul2 = sentencia2.executeQuery(consulta2);
  37.             resul2.next();
  38.             int filas = resul2.getInt(1);
  39.             resul2.close();
  40.            
  41.             String sql = "select emp_no from empleados";
  42.             Statement sentencia = conexion.createStatement();
  43.             ResultSet res  = sentencia.executeQuery(sql);
  44.             String[] dir = new String[filas];
  45.             int i = 0;
  46.             if (res.next())
  47.             {
  48.                 do {
  49.                     dir[i]=res.getString(1);
  50.                     i++;
  51.                 }while (res.next());
  52.                
  53.             }
  54.             else {
  55.                 textArea.append(" NO HAY DIRECTORES ");
  56.             }
  57.             comboDirec.setModel(new DefaultComboBoxModel(dir));
  58.         } catch (SQLException e3) {
  59.             // TODO Auto-generated catch block
  60.             e3.printStackTrace();
  61.         }
  62.  
  63.         comboDirec.setBounds(163, 91, 122, 20);
  64.         panelempleados.add(comboDirec);
  65.        
  66.         JComboBox comboDep = new JComboBox();
  67.         String consulta3="select count(*) from DEPARTAMENTOS";
  68.         Statement sentencia3;
  69.         try {
  70.             sentencia3 = conexion.createStatement();
  71.             ResultSet resul3;
  72.             resul3 = sentencia3.executeQuery(consulta3);
  73.             resul3.next();
  74.             int filas = resul3.getInt(1);
  75.             resul3.close();
  76.            
  77.             String sql = "select dept_no from departamentos";
  78.             Statement sentencia = conexion.createStatement();
  79.             ResultSet res  = sentencia.executeQuery(sql);
  80.             String[] dir = new String[filas];
  81.             int i = 0;
  82.             if (res.next())
  83.             {
  84.                 do {
  85.                     dir[i]=res.getString(1);
  86.                     i++;
  87.                 }while (res.next());
  88.                
  89.             }
  90.             else {
  91.                 textArea.append(" NO HAY DEPARTAMENTOS ");
  92.             }
  93.             comboDep.setModel(new DefaultComboBoxModel(dir));
  94.         } catch (SQLException e3) {
  95.             // TODO Auto-generated catch block
  96.             e3.printStackTrace();
  97.         }
  98.         comboDep.setBounds(491, 94, 111, 20);
  99.         panelempleados.add(comboDep);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement