// Path: src/main/java/com/storage/mywarehouse/Dao/CustomerDAO.java
// public class CustomerDAO {
//     @SuppressWarnings("unchecked")
//     public static List<Customer> findAll() {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction tx = session.beginTransaction();
//         List customers = session.createCriteria(Customer.class).list();
//         tx.commit();
//         session.close();
//         return customers;
//     }
// 
//     public static void save(Customer customer) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction tx = session.beginTransaction();
//         Customer customerWithHighestId = (Customer) session.createCriteria(Customer.class).addOrder(Order.desc("customerId")).setMaxResults(1).uniqueResult();
//         int nextId;
//         if (customerWithHighestId == null) {
//             nextId = 0;
//         } else {
//             nextId = customerWithHighestId.getCustomerId() + 1;
//         }
//         customer.setCustomerId(nextId);
//         session.save(customer);
//         tx.commit();
//         session.close();
//     }
// 
//     public static void update(Customer customer) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction tx = session.beginTransaction();
//         session.update(customer);
//         tx.commit();
//         session.close();
//     }
// 
//     public static void delete(Customer customer) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction tx = session.beginTransaction();
//         session.delete(customer);
//         tx.commit();
//         session.close();
//     }
// 
//     public static void deleteAll(List<Customer> customers) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction tx = session.beginTransaction();
//         for (Customer c : customers) {
//             session.delete(c);
//         }
//         tx.commit();
//         session.close();
//     }
// }
// 
// Path: src/main/java/com/storage/mywarehouse/Entity/Customer.java
// public class Customer  implements java.io.Serializable {
// 
// 
//      private int customerId;
//      private String name;
//      private String lastName;
//      private String occupation;
//      private double discount;
//      private String email;
//      private String city;
//      private String postal;
//      private String telephone;
// 
// 
//     public Customer() {
//     }
// 
//     public Customer(int customerId, String name, String lastName, String occupation, double discount,
//                     String email, String city, String postal, String telephone) {
//         this.customerId = customerId;
//         this.name = name;
//         this.lastName = lastName;
//         this.occupation = occupation;
//         this.discount = discount;
//         this.email = email;
//         this.city = city;
//         this.postal = postal;
//         this.telephone = telephone;
//     }
// 
//     public int getCustomerId() {
//         return this.customerId;
//     }
//     
//     public void setCustomerId(int customerId) {
//         this.customerId = customerId;
//     }
//     public String getName() {
//         return this.name;
//     }
//     
//     public void setName(String name) {
//         this.name = name;
//     }
//     public String getLastName() {
//         return this.lastName;
//     }
//     
//     public void setLastName(String lastName) {
//         this.lastName = lastName;
//     }
//     public String getOccupation() {
//         return this.occupation;
//     }
//     
//     public void setOccupation(String occupation) {
//         this.occupation = occupation;
//     }
//     public double getDiscount() {
//         return this.discount;
//     }
//     
//     public void setDiscount(double discount) {
//         this.discount = discount;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getCity() {
//         return city;
//     }
// 
//     public void setCity(String city) {
//         this.city = city;
//     }
// 
//     public String getPostal() {
//         return postal;
//     }
// 
//     public void setPostal(String postal) {
//         this.postal = postal;
//     }
// 
//     public String getTelephone() {
//         return telephone;
//     }
// 
//     public void setTelephone(String telephone) {
//         this.telephone = telephone;
//     }
// }


import com.storage.mywarehouse.Dao.CustomerDAO;
import com.storage.mywarehouse.Entity.Customer;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void newClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newClientActionPerformed
        clientForm clf = new clientForm(frame);
        clf.setVisible(true);
        clf.setAlwaysOnTop(true);
        clf.requestFocusInWindow();
    }//GEN-LAST:event_newClientActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int row = jTable1.getSelectedRow();
        if (row != -1) {
            int sel = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete this customer?", "Confirm", JOptionPane.OK_CANCEL_OPTION);
            if (sel == 0) {
                tbmodel.removeRow(row);
            }

            Customer c = (Customer) customers.get(row);
            customers.remove(c);
// Path: src/main/java/com/storage/mywarehouse/Dao/CustomerDAO.java
// public class CustomerDAO {
//     @SuppressWarnings("unchecked")
//     public static List<Customer> findAll() {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction tx = session.beginTransaction();
//         List customers = session.createCriteria(Customer.class).list();
//         tx.commit();
//         session.close();
//         return customers;
//     }
// 
//     public static void save(Customer customer) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction tx = session.beginTransaction();
//         Customer customerWithHighestId = (Customer) session.createCriteria(Customer.class).addOrder(Order.desc("customerId")).setMaxResults(1).uniqueResult();
//         int nextId;
//         if (customerWithHighestId == null) {
//             nextId = 0;
//         } else {
//             nextId = customerWithHighestId.getCustomerId() + 1;
//         }
//         customer.setCustomerId(nextId);
//         session.save(customer);
//         tx.commit();
//         session.close();
//     }
// 
//     public static void update(Customer customer) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction tx = session.beginTransaction();
//         session.update(customer);
//         tx.commit();
//         session.close();
//     }
// 
//     public static void delete(Customer customer) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction tx = session.beginTransaction();
//         session.delete(customer);
//         tx.commit();
//         session.close();
//     }
// 
//     public static void deleteAll(List<Customer> customers) {
//         Session session = NewHibernateUtil.getSessionFactory().openSession();
//         Transaction tx = session.beginTransaction();
//         for (Customer c : customers) {
//             session.delete(c);
//         }
//         tx.commit();
//         session.close();
//     }
// }
// 
// Path: src/main/java/com/storage/mywarehouse/Entity/Customer.java
// public class Customer  implements java.io.Serializable {
// 
// 
//      private int customerId;
//      private String name;
//      private String lastName;
//      private String occupation;
//      private double discount;
//      private String email;
//      private String city;
//      private String postal;
//      private String telephone;
// 
// 
//     public Customer() {
//     }
// 
//     public Customer(int customerId, String name, String lastName, String occupation, double discount,
//                     String email, String city, String postal, String telephone) {
//         this.customerId = customerId;
//         this.name = name;
//         this.lastName = lastName;
//         this.occupation = occupation;
//         this.discount = discount;
//         this.email = email;
//         this.city = city;
//         this.postal = postal;
//         this.telephone = telephone;
//     }
// 
//     public int getCustomerId() {
//         return this.customerId;
//     }
//     
//     public void setCustomerId(int customerId) {
//         this.customerId = customerId;
//     }
//     public String getName() {
//         return this.name;
//     }
//     
//     public void setName(String name) {
//         this.name = name;
//     }
//     public String getLastName() {
//         return this.lastName;
//     }
//     
//     public void setLastName(String lastName) {
//         this.lastName = lastName;
//     }
//     public String getOccupation() {
//         return this.occupation;
//     }
//     
//     public void setOccupation(String occupation) {
//         this.occupation = occupation;
//     }
//     public double getDiscount() {
//         return this.discount;
//     }
//     
//     public void setDiscount(double discount) {
//         this.discount = discount;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getCity() {
//         return city;
//     }
// 
//     public void setCity(String city) {
//         this.city = city;
//     }
// 
//     public String getPostal() {
//         return postal;
//     }
// 
//     public void setPostal(String postal) {
//         this.postal = postal;
//     }
// 
//     public String getTelephone() {
//         return telephone;
//     }
// 
//     public void setTelephone(String telephone) {
//         this.telephone = telephone;
//     }
// }


// Path: src/main/java/com/storage/mywarehouse/ClientFrame.java
import com.storage.mywarehouse.Dao.CustomerDAO;
import com.storage.mywarehouse.Entity.Customer;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void newClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newClientActionPerformed
        clientForm clf = new clientForm(frame);
        clf.setVisible(true);
        clf.setAlwaysOnTop(true);
        clf.requestFocusInWindow();
    }//GEN-LAST:event_newClientActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int row = jTable1.getSelectedRow();
        if (row != -1) {
            int sel = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete this customer?", "Confirm", JOptionPane.OK_CANCEL_OPTION);
            if (sel == 0) {
                tbmodel.removeRow(row);
            }

            Customer c = (Customer) customers.get(row);
            customers.remove(c);
            CustomerDAO.delete(c);