Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
  2. Connection conn = null;
  3. PreparedStatement psm = null;
  4. String cod = txtCod.getText();
  5. String sql = "SELECT * FROM produtos WHERE cod = "+cod;
  6. String nome = null;
  7. float valor = 0;
  8. String desc = null;
  9. try{
  10. conn = DatabaseConnection.MysqlConnection();
  11. psm = conn.prepareStatement(sql);
  12. psm.execute();
  13.  
  14. ResultSet result = psm.executeQuery(sql);
  15.  
  16. while(result.next()){
  17. nome = result.getString("nome");
  18. valor = result.getFloat("valor_m2");
  19. desc = result.getString("descricao");
  20. }
  21. if(txtHeight.getText().equals("") && txtWidth.getText().equals("")){
  22. float a2 = Float.parseFloat(JOptionPane.showInputDialog(rootPane, "Por favor insira a área da peça", "Área", HEIGHT));
  23.  
  24. float valorm = a2 * valor;
  25.  
  26. MainForm mf = new MainForm();
  27. mf.addInTable(cod, nome, a2, valor, valorm);
  28.  
  29. this.setVisible(false);
  30. psm.close();
  31. conn.close();
  32. }
  33. else{
  34. float alt = Float.parseFloat(txtHeight.getText());
  35. float lag = Float.parseFloat(txtWidth.getText());
  36.  
  37. float area = alt * lag;
  38. float valorm = area * valor;
  39.  
  40. MainForm mf = new MainForm();
  41. mf.addInTable(cod, nome, area, valor, valorm);
  42.  
  43. this.setVisible(false);
  44. psm.close();
  45. conn.close();
  46. }
  47. }
  48. catch(Exception ex){
  49. System.out.println(ex);;
  50. }
  51.  
  52. public void addInTable(String cod, String prod, float area, float prec, float precTot){
  53. String nom = prod;
  54. String con = cod;
  55. String are = Float.toString(area);
  56. String pre = Float.toString(prec);
  57. String tot = Float.toString(precTot);
  58.  
  59. DefaultTableModel model = (DefaultTableModel) tblMain.getModel();
  60. model.addRow(new Object[]{con, nom, are, pre, tot});
  61.  
  62. float total = 0;
  63. total = total + precTot;
  64.  
  65.  
  66. lblTrue.setText(Float.toString(total));
  67.  
  68. public List<EssaClasseVolta> findAll(){
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement