Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. package javaBeans;
  2.  
  3. import gestionErreurs.TraitementException;
  4.  
  5. import java.math.BigDecimal;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.sql.Statement;
  11. import java.util.ArrayList;
  12.  
  13. public class BOperations {
  14. private String noDeCompte;
  15. private String nom;
  16. private String prenom;
  17.  
  18. private BigDecimal solde;
  19. private Connection connect;
  20. private ResultSet set;
  21.  
  22. private BigDecimal ancienSolde;
  23. private BigDecimal nouveauSolde;
  24. private String op;
  25. private BigDecimal valeur;
  26.  
  27. private String dateInf;
  28. private String dateSup;
  29. private ArrayList<ArrayList<String>> operationsParDates;
  30.  
  31. public String getNoDeCompte() {
  32. return noDeCompte;
  33. }
  34.  
  35. public void setNoDeCompte(String noDeCompte) {
  36. this.noDeCompte = noDeCompte;
  37. }
  38.  
  39. public String getNom() {
  40. return nom;
  41. }
  42.  
  43. public String getPrenom() {
  44. return prenom;
  45. }
  46.  
  47. public BigDecimal getSolde() {
  48. return solde;
  49. }
  50.  
  51. public BigDecimal getAncienSolde() {
  52. return ancienSolde;
  53. }
  54.  
  55. public BigDecimal getNouveauSolde() {
  56. return nouveauSolde;
  57. }
  58.  
  59. public String getOp() {
  60. return op;
  61. }
  62.  
  63. public String getValeur() {
  64. return String.valueOf(valeur);
  65. }
  66.  
  67. public void setOp(String op) {
  68. this.op = op;
  69. }
  70.  
  71. public void setValeur(String valeur) {
  72. this.valeur = new BigDecimal(valeur);
  73. }
  74.  
  75. public String getDateInf() {
  76. return dateInf;
  77. }
  78.  
  79. public String getDateSup() {
  80. return dateSup;
  81. }
  82.  
  83. public ArrayList<ArrayList<String>> getOperationsParDates() {
  84. return operationsParDates;
  85. }
  86.  
  87. public void setDateInf(String dateInf) {
  88. this.dateInf = dateInf;
  89. }
  90.  
  91. public void setDateSup(String dateSup) {
  92. this.dateSup = dateSup;
  93. }
  94.  
  95. public void ouvrirConnexion() throws TraitementException{
  96. try {
  97. connect = DriverManager.getConnection(
  98. "jdbc:mysql://sqletud.univ-mlv.fr/vtissero_db?user=vtissero&password=dD5oabey");
  99. } catch (SQLException e) {
  100. throw new TraitementException("3");
  101. }
  102. }
  103.  
  104. public void fermerConnexion(){
  105. try {
  106. connect.close();
  107. } catch (SQLException e) {
  108. System.out.println("Problème lors de la fermeture");
  109. }
  110. }
  111.  
  112. public void consulter() throws TraitementException{
  113. Statement statement;
  114. try {
  115. statement = connect.createStatement();
  116. set = statement.executeQuery("select * from COMPTE where NOCOMPTE='"+noDeCompte+"'");
  117. set.next();
  118. nom = set.getString("NOM");
  119.  
  120. } catch (SQLException e) {
  121. throw new TraitementException("21");
  122. }
  123. }
  124.  
  125. public void traiter() throws TraitementException{
  126.  
  127. Statement statement;
  128.  
  129. try {
  130. statement = connect.createStatement();
  131. set = statement.executeQuery("select * from COMPTE where NOCOMPTE='"+noDeCompte+"'");
  132. set.next();
  133. ancienSolde = set.getBigDecimal("SOLDE");
  134.  
  135. if(op == "+"){
  136. nouveauSolde = ancienSolde.add(valeur);
  137. }
  138. else{
  139. nouveauSolde = ancienSolde.subtract(valeur);
  140. }
  141.  
  142. if(nouveauSolde.signum() < 0){
  143. throw new TraitementException("24");
  144. }
  145. else{
  146. System.out.println("Modification du compte ...");
  147. statement.executeUpdate("update COMPTE set SOLDE="+nouveauSolde+"where NOCOMPTE='"+noDeCompte+"'");
  148. statement.executeUpdate("insert into OPERATION(NOCOMPTE,DATE,HEURE,OP,VALEUR) values('"+noDeCompte+"',CURRENT_DATE,CURRENT_TIME,'"+op+"','"+valeur+"')");
  149. System.out.println("Modification OK");
  150. }
  151.  
  152. } catch (SQLException e) {
  153. throw new TraitementException("21");
  154. }
  155. solde = nouveauSolde;
  156. }
  157.  
  158. public void listerParDates() throws TraitementException{
  159. ArrayList<String> liste = new ArrayList<String>();
  160. operationsParDates = new ArrayList<ArrayList<String>>();
  161. Statement statement;
  162.  
  163. try {
  164. statement = connect.createStatement();
  165. set = statement.executeQuery("select * from OPERATION where DATE BETWEEN '"+dateInf+"' and '"+dateSup+"' and NOCOMPTE='"+noDeCompte+"'");
  166.  
  167. while(set.next() == true){
  168. liste.add(set.getDate("DATE").toString());
  169. liste.add(set.getString("OP"));
  170. liste.add(String.valueOf(set.getFloat("VALEUR")));
  171. operationsParDates.add(liste);
  172. }
  173.  
  174. System.out.println(operationsParDates);
  175.  
  176. } catch (SQLException e) {
  177. throw new TraitementException("21");
  178. }
  179. }
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement