Advertisement
mouhsineelachbi

Administrateur

Dec 14th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.35 KB | None | 0 0
  1.     /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package GeoPharmacie;
  7.  
  8.  
  9.  
  10. import java.sql.Connection;
  11. import java.sql.DriverManager;
  12. import java.sql.PreparedStatement;
  13. import java.sql.ResultSet;
  14. import java.sql.SQLException;
  15. import java.sql.Statement;
  16. import java.text.ParseException;
  17. import java.util.ArrayList;
  18. import java.util.Date;
  19. import java.util.LinkedList;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import javax.smartcardio.CommandAPDU;
  23.  
  24. /**
  25.  *
  26.  * @author Hamza
  27.  */
  28.  
  29. public class baseD {
  30.     private Connection con;
  31.     public baseD () throws SQLException{
  32.         try {
  33.             Class.forName("com.mysql.jdbc.Driver");
  34.         } catch (ClassNotFoundException ex) {
  35.             Logger.getLogger(baseD.class.getName()).log(Level.SEVERE, null, ex);
  36.         }
  37.           this.con = DriverManager.getConnection(
  38.                          "jdbc:mysql://localhost:3306/geophar",
  39.                          "root",
  40.                          "");
  41.        
  42.     }
  43.  
  44.     //**********************************************************INSERTION dans L'ADMIN******************************************************************************************
  45.     public void insertInToAdmin( String nom,String prenom,String tele,String cin,String email,String pseudo,String adresse,String motDepasse,int numeroAdmin) throws SQLException
  46.      {
  47.  
  48.             ////Connection con=connexion();
  49.             Statement stmt = con.createStatement();
  50.            
  51.             String query="INSERT INTO administrateur VALUES (' "+nom+"',' "+prenom+"',"
  52.                     + ""+ tele+",'"+ cin+"',' "+email+"','"+ pseudo+"','"
  53.                     + adresse+"','"+motDepasse+"',"+numeroAdmin+")";
  54.              
  55.              stmt.executeUpdate(query);
  56.            
  57.              
  58.      }
  59.         //**********************************************************INSERTION dans Le client******************************************************************************************
  60.    
  61.      public void insertInToClient( String nom,String prenom,String tele,String cin,String email,String pseudo,String adresse,String motDepasse,int numeroClient) throws SQLException
  62.      {
  63.  
  64.           //  //Connection con=connexion();
  65.          System.out.println("ibase de donneeeeeeet************************");
  66.             Statement stmt = con.createStatement();
  67.             if(!VerifierExistanceClient(cin))
  68.             {
  69.             String query="INSERT INTO client VALUES (' "+nom+"',' "+prenom+"','"+ cin+"','"
  70.                     +tele+"',' "+email+"','"+ pseudo+"','"
  71.                     + adresse+"',"+numeroClient+",'"+motDepasse+"')";
  72.              System.out.println("ibase de clientttttt************************");
  73.              stmt.executeUpdate(query);
  74.             }
  75.             else{
  76.             }
  77.              
  78.      }
  79.      //************************************************************************************************************************************************
  80.     public void insertInToPharmacien( String nom,String prenom,String tele,String cin,String email,String pseudo,String adresse,String motDepasse,int numeroPharmacien,int idPharmacie) throws SQLException
  81.      {
  82.  
  83.            // //Connection con=connexion();
  84.             Statement stmt = con.createStatement();
  85.            
  86.             String query="INSERT INTO pharmacien VALUES ("+numeroPharmacien+",'"+nom+"',' "+prenom+"','"
  87.                     + cin+"','"+ tele+"',' "+email+"','"+ pseudo+"','"+ adresse+"','"+motDepasse+"','"+idPharmacie+"')";
  88.              System.out.println("ibase de pharmacien************************");
  89.              stmt.executeUpdate(query);
  90.            
  91.              
  92.      }
  93.     //*************************************************************************************************************
  94.     public void insertIntoCommande(int numeroCommande,String DateCommande,String EtatCommande)throws SQLException{
  95.        // //Connection con=connexion();
  96.         Statement stmt =con.createStatement();
  97.        
  98.         String query="INSERT INTO commande VALUES("+numeroCommande+",'"+DateCommande+"','"+EtatCommande+"')";
  99.         stmt.execute(query);
  100.        
  101.     }
  102.     //*********************************************************************************************************************
  103.    
  104.     public void insertIntoFacture(int numeroFacture,String DateFacture,double SommeTotale) throws SQLException{
  105.         // //Connection con=connexion();
  106.         Statement stmt =con.createStatement();
  107.        
  108.         String query="INSERT INTO facture VALUES("+numeroFacture+",'"+DateFacture+"',"+SommeTotale+")";
  109.         stmt.execute(query);
  110.        
  111.     }
  112.     //********************************************************************************************************************************
  113.     public void insertIntoLineCommande(int numeroProduit,int numeroCommande,double quantite) throws SQLException{
  114.         ////Connection con=connexion();
  115.         Statement stmt =con.createStatement();
  116.        
  117.         String query="INSERT INTO linecommande VALUES("+numeroProduit+","+numeroCommande+","+quantite+")";
  118.         stmt.execute(query);
  119.     }
  120.     //************************************************************************************************************************************
  121.     public void insertIntoPaiementcarte(String datePaiement,double montant,int payer,String nomProprietaire,String prenomProprietaire,String numeroCarte,String adresseProprietaire,String CinClient) throws SQLException{
  122.    //payer normalement boolean    
  123.          //Connection con=connexion();
  124.         Statement stmt =con.createStatement();
  125.        
  126.         String query="INSERT INTO paiementcarte(datePaiement,montant,payer,nomProprietaire,prenomProprietaire,numeroCarte,adresseProprietaire,CinClient) VALUES('"+datePaiement+"',"+montant+","+payer+",'"
  127.                 +nomProprietaire+"','"+prenomProprietaire+"','"+numeroCarte+"','"+adresseProprietaire+"','"+CinClient+"')";
  128.         stmt.execute(query);
  129.        
  130.  
  131.     }
  132.     //*****************************************************************************************************************************
  133.      public void insertIntoPaiementLivraison(String datePaiement,double montant,int payer,String nomClient,String prenomClient,String emailClient,String teleClient,String adresseClient,String CinClient) throws SQLException{
  134.    //payer normalement boolean    
  135.          //Connection con=connexion();
  136.         Statement stmt =con.createStatement();
  137.        
  138.         String query="INSERT INTO paiementlivraision(datePaiement,montant,payer,nomClient,prenomClient,emailClient,teleClient,adresseClient,CinClient) VALUES('"+datePaiement+"',"+montant+","+payer+",'"
  139.                 +nomClient+"','"+prenomClient+"','"+emailClient+"','"+teleClient+"','"+adresseClient+"','"+CinClient+"')";
  140.         stmt.execute(query);
  141.        
  142.  
  143.     }
  144.     //*******************************************************************************************************************
  145.     public void insertIntoProduit(int referenceProduit,String libelle,String DateExpiration,String DateFabrication,double TemperatureStock,int numeroProduit,double prix,int idPharmacie) throws SQLException{
  146.         //Connection con=connexion();
  147.         Statement stmt =con.createStatement();
  148.        
  149.         String query="INSERT INTO produit( referenceProduit, libelle,DateExpiration, DateFabrication, TemperatureStock,numeroProduit, prix,idPharmacie)Values ("
  150.                 +referenceProduit+", '"+libelle+"','"+DateExpiration+"', '"+DateFabrication+"', "
  151.                 +TemperatureStock+","+numeroProduit+", "+prix+","+idPharmacie+")";
  152.         stmt.execute(query);
  153.     }
  154. //*******************************************************************************************************************
  155.     public void insertIntoPlanning(String dateOuverture,String dateFermeture,String dateFerie,String dateGarde) throws SQLException{
  156.         //Connection con=connexion();
  157.         Statement stmt =con.createStatement();
  158.        
  159.         String query="INSERT INTO planning( dateOuverture, dateFermeture,dateFerie,dateGarde)Values ('"+dateOuverture
  160.                 +"', '"+dateFermeture+"','"+dateFerie+"','"+dateGarde+"')";
  161.         stmt.execute(query);
  162.     }
  163.     //******************************************************************SUPPRIMER PRODUIT**************
  164.     public void deletProduit(int numeroProduit) throws SQLException{
  165.         //Connection con=connexion();
  166.     Statement stmt = con.createStatement();
  167.  
  168.     String query="delete from produit where numeroProduit = "+numeroProduit;
  169.     stmt.executeUpdate(query);
  170.     }
  171.     //******************************************************************SUPPRIMER COMMANDE**************
  172.     public void deletCommande(int numeroCommande) throws SQLException{
  173.         //Connection con=connexion();
  174.     Statement stmt = con.createStatement();
  175.  
  176.     String query="delete from commande where numeroCommande = "+numeroCommande;
  177.     stmt.executeUpdate(query);
  178.     }
  179.     //-------------------------------****************************************Affichage de la liste des ADMINASTRATEURS***********************--------------------
  180.    
  181.     public ArrayList<Administrateur> selectAdmin() throws SQLException {
  182.  
  183.     //Connection con=connexion();
  184.     Statement stmt = con.createStatement();
  185.    
  186.     String query="select * from administrateur";
  187.     stmt.executeQuery(query);
  188.     ResultSet rs=stmt.executeQuery(query);
  189.     ArrayList<Administrateur> A=new ArrayList<Administrateur>();
  190.       while(rs.next())
  191.     {
  192.        
  193.         String adresse=rs.getString("adresse");
  194.         String cin=rs.getString("cin");
  195.         String email=rs.getString("email");
  196.         String motDepasse=rs.getString("motDepasse");
  197.         String nom=rs.getString("nom");
  198.         int numeroAdmin=rs.getInt("numeroAdmin");
  199.         String prenom=rs.getString("prenom");
  200.         String pseudo=rs.getString("pseudo");
  201.         String tele=rs.getString("tele");
  202.         Administrateur ad=new Administrateur(numeroAdmin, nom, prenom, cin, tele, email, adresse, pseudo, motDepasse);
  203.         A.add(ad);
  204.                 }
  205.         return A;
  206.    
  207.     }
  208.     //-------------------------------****************************************Affichage de la liste des CLIETS***********************--------------------
  209.     public boolean VerifierExistanceClient(String cin) throws SQLException{
  210.        String req="select numeroClient from client where cin='"+cin+"'";
  211.        Statement smt=con.createStatement();
  212.        ResultSet rs=smt.executeQuery(req);
  213.  
  214.        return rs.next();
  215.     }
  216.     public ArrayList<Client> selectClient() throws SQLException {
  217.  
  218.     //Connection con=connexion();
  219.     Statement stmt = con.createStatement();
  220.    
  221.     String query="select * from client";
  222.     stmt.executeQuery(query);
  223.     ResultSet rs=stmt.executeQuery(query);
  224.     ArrayList<Client> C=new ArrayList<Client>();
  225.       while(rs.next())
  226.     {
  227.        
  228.         String adresse=rs.getString("adresse");
  229.         String cin=rs.getString("cin");
  230.         String email=rs.getString("email");
  231.         String motDepasse=rs.getString("motdepasse");
  232.         String nom=rs.getString("nom");
  233.         int numeroAdmin=rs.getInt("numeroClient");
  234.         String prenom=rs.getString("prenom");
  235.         String pseudo=rs.getString("pseudo");
  236.         String tele=rs.getString("tele");
  237.         Client cl=new Client(numeroAdmin, nom, prenom, cin, tele, email, adresse, pseudo, motDepasse);
  238.         C.add(cl);
  239.                 }
  240.         return C;
  241.    
  242.     }
  243.     //***********************************************************************************************************
  244.      public boolean VerifierExistancePharmacien(String cin) throws SQLException{
  245.        String req="select numeroPharmacien from pharmacien where cin='"+cin+"'";
  246.        Statement smt=con.createStatement();
  247.        ResultSet rs=smt.executeQuery(req);
  248.  
  249.        return rs.next();
  250.     }
  251.     ///**********************************************************************************************************
  252.      public ArrayList<Pharmacien> selectPharmacien() throws SQLException {
  253.  
  254.     //Connection con=connexion();
  255.     Statement stmt = con.createStatement();
  256.    
  257.     String query="select * from pharmacien";
  258.     stmt.executeQuery(query);
  259.     ResultSet rs=stmt.executeQuery(query);
  260.     ArrayList<Pharmacien> P=new ArrayList<Pharmacien>();
  261.       while(rs.next())
  262.     {
  263.        
  264.         String adresse=rs.getString("adresse");
  265.         String cin=rs.getString("cin");
  266.         String email=rs.getString("email");
  267.         String motDepasse=rs.getString("motdepasse");
  268.         String nom=rs.getString("nom");
  269.         int numeroAdmin=rs.getInt("numeroPharmacien");
  270.         String prenom=rs.getString("prenom");
  271.         String pseudo=rs.getString("pseudo");
  272.         String tele=rs.getString("tele");
  273.         Pharmacien ph=new Pharmacien(numeroAdmin, nom, prenom, cin, tele, email, adresse, pseudo, motDepasse);
  274.         P.add(ph);
  275.                 }
  276.         return P;
  277.    
  278.     }
  279.      //******************************************************************************************************************
  280.      public ArrayList<Commande> selectCommande() throws SQLException {
  281.  
  282.     //Connection con=connexion();
  283.     Statement stmt = con.createStatement();
  284.    
  285.     String query="select * from commande";
  286.     stmt.executeQuery(query);
  287.     ResultSet rs=stmt.executeQuery(query);
  288.     ArrayList<Commande> Co=new ArrayList<Commande>();
  289.      while(rs.next())
  290.     {
  291.        String dateCommande=rs.getString("dateCommande");
  292.        String EtatCommade=rs.getString("EtatCommade");
  293.        int numeroCommande=rs.getInt("numeroCommande");
  294.        Commande com=new Commande( numeroCommande, dateCommande, EtatCommade);
  295.        Co.add(com);
  296.    
  297.    
  298.      }
  299.     return Co;
  300.      }
  301.      //*****************************************************************************************************************************
  302.      public LinkedList<Produit> AfficherProduit(int numeroProduit) throws SQLException{
  303.         String req = "select * from produit where numeroProduit="+numeroProduit;
  304.         LinkedList<Produit> p = new LinkedList<Produit>();
  305.         Statement st = con.createStatement();
  306.         ResultSet rst = st.executeQuery(req);
  307.         while(rst.next()){
  308.             int num = rst.getInt(1);
  309.             int ref = rst.getInt(2);
  310.             String libelle = rst.getString(3);
  311.             String d1 = rst.getString(4);
  312.             String d2 = rst.getString(5);
  313.             Double temp = rst.getDouble(6);
  314.             Double prix = rst.getDouble(7);
  315.           //  String d1 = new java.util.Date(dateEx.getTime());
  316.            // String d2 = new java.util.Date(dateFb.getTime());
  317.            
  318.             Produit pr = new Produit(num, ref, libelle, d1, d2, temp, prix);
  319.             p.add(pr);
  320.         }
  321.         return p;
  322.     }
  323.  
  324.     public LinkedList<Facture> AfficherFacture(int numerofacture) throws SQLException{
  325.         String req = "select * from facture where numerofacture="+numerofacture;
  326.         LinkedList<Facture> p = new LinkedList<Facture>();
  327.         Statement st = con.createStatement();
  328.         ResultSet rst = st.executeQuery(req);
  329.         while(rst.next()){
  330.             int num = rst.getInt(1);
  331.            String d1 = rst.getString(2);
  332.             Double some = rst.getDouble(3);
  333.            
  334.             Facture f = new Facture(num, d1, some);
  335.             p.add(f);
  336.         }
  337.         return p;
  338.     }
  339. //// UPDATE ADMIN
  340.  
  341.     public void modifierAdmin(int numeroAdmin ,String nom, String prenom, String cin, String tel, String email, String adresse, String pseudo, String motdepasse) throws SQLException{
  342.         PreparedStatement stm = con.prepareStatement("update administrateur SET nom=?, prenom=?, cin=?, tele=?, email=?, adresse=?, pseudo=?, motdepasse=? where numeroadmin=?");
  343.         stm.setString(1, nom);
  344.         stm.setString(2, prenom);
  345.         stm.setString(3,cin);
  346.         stm.setString(4, tel);
  347.         stm.setString(5, email);
  348.         stm.setString(6, adresse);
  349.         stm.setString(7, pseudo);
  350.         stm.setString(8, motdepasse);
  351.         stm.setInt(9, numeroAdmin);
  352.         stm.executeUpdate();
  353.     }
  354.  
  355. // UPDATE COMMANDE
  356.     public void modifierCommande(int numeroCommande, String dateCommande, String EtatCommande) throws SQLException{
  357.         PreparedStatement stm = con.prepareStatement("update Commande SET dateCommande=?, EtatCommande=? where numeroCommande=?");
  358.     stm.setString(1, dateCommande);
  359.     stm.setString(2, EtatCommande);
  360.         stm.setInt(3, numeroCommande);
  361.         stm.executeUpdate();
  362.     }
  363.  
  364. // UPDATE CLIENT
  365.      public void modifierClient(int numeroClient, String nom, String prenom, String cin, String tel, String email, String adresse, String pseudo, String motdepasse) throws SQLException{
  366.         PreparedStatement stm = con.prepareStatement("update client SET nom=?, prenom=?, cin=?, tele=?, email=?, adresse=?, pseudo=?, motdepasse=? where numeroClient=?");
  367.         stm.setString(1, nom);
  368.     stm.setString(2, prenom);
  369.     stm.setString(3,cin);
  370.     stm.setString(4, tel);
  371.     stm.setString(5, email);
  372.     stm.setString(6, adresse);
  373.     stm.setString(7, pseudo);
  374.     stm.setString(8, motdepasse);
  375.     stm.setInt(9, numeroClient);
  376.         stm.executeUpdate();
  377.     }
  378.  
  379. // UPDATE FACTURE
  380.     public void modifierFacture(int numeroFacture, String DateFacture, double SommeTotale) throws SQLException{
  381.         PreparedStatement stm = con.prepareStatement("update Facture SET DateFacture=?, SommeTotale=? where numeroFacture=?");
  382.         stm.setString(1, DateFacture);
  383.     stm.setDouble(2, SommeTotale);
  384.     stm.setInt(3, numeroFacture);
  385.         stm.executeUpdate();
  386.     }
  387.  
  388. // UPDATE PHARMACIEN
  389.     public void modifierPharmacien(int numeroPharmacien, String nom, String prenom, String cin, String tel, String email, String adresse, String pseudo, String motdepasse) throws SQLException{
  390.         PreparedStatement stm = con.prepareStatement("update pharmacien SET nom=?, prenom=?, cin=?, tele=?, email=?, adresse=?, pseudo=?, motdepasse=? where numeroPharmacien=?");
  391.         stm.setString(1, nom);
  392.     stm.setString(2, prenom);
  393.     stm.setString(3,cin);
  394.     stm.setString(4, tel);
  395.     stm.setString(5, email);
  396.     stm.setString(6, adresse);
  397.     stm.setString(7, pseudo);
  398.     stm.setString(8, motdepasse);
  399.     stm.setInt(9, numeroPharmacien);
  400.         stm.executeUpdate();
  401.     }
  402.  
  403. // UPDATE PRODUIT
  404.     public void modifierProduit(int numeroProduit, int referenceProduit, String libelle, String dateExpiration, String dateFabrication, double TemperaturStock, double prix) throws SQLException{
  405.         PreparedStatement stm = con.prepareStatement("update produit SET referenceProduit=?, libelle=?, dateExpiration=?, dateFabrication=?, TemperatureStock=?, prix=? where numeroProduit=?");
  406.         stm.setInt(1, referenceProduit);
  407.     stm.setString(2, libelle);
  408.     stm.setString(3, dateExpiration);
  409.     stm.setString(4, dateFabrication);
  410.     stm.setDouble(5, TemperaturStock);
  411.     stm.setDouble(6, prix);
  412.     stm.setInt(7, numeroProduit);
  413.         stm.executeUpdate();
  414.     }
  415.    
  416.    
  417.    
  418.    
  419.    
  420.    
  421.    
  422.    
  423.    
  424.    
  425.    
  426.    
  427.    
  428.    
  429.    
  430.    
  431.    
  432.    
  433.      public static void main(String[] args) throws SQLException, ParseException, ClassNotFoundException{
  434.        baseD mydb = new baseD();// makandirouch had chi tanchedo la base données o tandiroha f classe bohdha chouf
  435.      
  436.      // mydb.insertInToAdmin("nomAdmin12","prenom2", "0670044061"," mc256482"," email"," pseudo"," adresse",3," motDepasse", 0);
  437.       mydb.insertInToClient("hh", "pm"," tele", "in", "email", "pseudo", "adresse", "1234", 0);
  438.     // mydb.insertInToPharmacien("nom"," prenom"," tele11", "cin"," email"," pseudo", "adresse", "motDepasse", 0,2);
  439.      // mydb.insertIntoCommande(0, "2018-1-14", "EtatCommande");
  440.      // mydb.insertIntoFacture(0,"2018-1-14",1523);
  441.      // mydb.insertIntoLineCommande(8, 17, 7);
  442.      // mydb.insertIntoPaiementcarte("2017-5-14", 121.0, 1, "nomp", "prenomProprietaire","123", "rue najd el jadida", "mc456182");
  443.      // mydb.insertIntoPaiementLivraison("2017-4-14", 0, 0, "nomClient"," prenomClient"," emailClient"," teleClient"," adresseClient", "CinClient");
  444.    // mydb.insertIntoProduit(0, "libelle", "2017-12-14", "2017-5-14", 2, 0, 12,2);
  445.     // mydb.insertIntoPlanning("2018-1-14","2018-1-14","2018-1-14","2018-1-14");
  446.    // mydb.deletProduit(1);
  447.     }
  448.    
  449. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement