Search in sources :

Example 1 with ElectronicDevice

use of entities.ElectronicDevice in project ConsoElectric by anakkarsara.

the class ElectronicDeviceDetails method doPost.

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("dev");
    EntityManager manager = factory.createEntityManager();
    DAO test = new DAO(manager);
    EntityTransaction tx = manager.getTransaction();
    tx.begin();
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    edd.createED(request.getParameter("name"), Double.parseDouble(request.getParameter("conso")), test.getPerson(Long.parseLong(request.getParameter("owner"))));
    out.println("<h2><a href=\"index.html\">Retour page d'acueil</a></h2>");
    out.println("<table border = 2 cellpadding = \"10\" cellspacing = \"10\" align= \"center\">  <tr>  <th>Name</th> <th>Conso</th> <th>Proprietaire</th> </tr>");
    for (ElectronicDevice next : edd.allEDs()) {
        out.println(" <tr>  <td>" + next.getEdName() + "</td>   <td>" + next.getConsoMoy() + "</td>   <td>" + next.getOwner().getFamilyName() + " " + next.getOwner().getFirstName() + "</td>  </tr>  ");
    }
    out.println("</table> ");
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) DAO(jpa.DAO) EntityManagerFactory(javax.persistence.EntityManagerFactory) ElectronicDevice(entities.ElectronicDevice) PrintWriter(java.io.PrintWriter)

Example 2 with ElectronicDevice

use of entities.ElectronicDevice in project ConsoElectric by anakkarsara.

the class ElectronicDeviceDetails method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<h2><a href=\"index.html\">Retour page d'acueil</a></h2>");
    out.println("<table border = 2 cellpadding = \"10\" cellspacing = \"10\" align= \"center\">  <tr>  <th>Name</th> <th>Conso</th> <th>Proprietaire</th> </tr>");
    for (ElectronicDevice next : edd.allEDs()) {
        out.println(" <tr>    <td>" + next.getEdName() + "</td>   <td>" + next.getConsoMoy() + "</td>   <td>" + next.getOwner().getFamilyName() + " " + next.getOwner().getFirstName() + "</td></tr>  ");
    }
    out.println("</table> ");
}
Also used : ElectronicDevice(entities.ElectronicDevice) PrintWriter(java.io.PrintWriter)

Example 3 with ElectronicDevice

use of entities.ElectronicDevice in project ConsoElectric by anakkarsara.

the class ElectronicDeviceDao method createED.

public void createED(String name, double conso, Person owner) {
    tx.begin();
    ElectronicDevice elec = new ElectronicDevice(name, conso, owner);
    try {
        manager.persist(elec);
    } catch (Exception e) {
        e.printStackTrace();
    }
    tx.commit();
}
Also used : ElectronicDevice(entities.ElectronicDevice)

Aggregations

ElectronicDevice (entities.ElectronicDevice)3 PrintWriter (java.io.PrintWriter)2 EntityManager (javax.persistence.EntityManager)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 EntityTransaction (javax.persistence.EntityTransaction)1 DAO (jpa.DAO)1