/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.HotelServices.model.dto.impl;

import com.HotelServices.model.dao.SzallodavezetoDAO;
import com.HotelServices.model.dto.EmberDTO;
import com.HotelServices.model.dto.ProgramokDTO;
import com.HotelServices.model.dto.SzallodavezetoDTO;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.LinkedList;

/**
 *
 * @author Sensei
 */
public class SzallodavezetoDAOImpl extends AbstractGenericDAOImpl<SzallodavezetoDTO, Long>
	implements SzallodavezetoDAO{

    public boolean insert(SzallodavezetoDTO entity) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean deleteById(Long entityId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean programReg(String nev, String datum, String ido, String vezetonev) {
        Connection con = null;
    
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/hotelservices", "root", "admin");
            PreparedStatement stmt = (PreparedStatement) con.prepareStatement("SELECT max(idProgramok) FROM programok");
            int i = 0;
            ResultSet rs = stmt.executeQuery();
            if (rs.next()) {
                i = rs.getInt(1) + 1;
                System.out.println(i);
            }

            int vezeto = new Bejelentkezik().userAzon(vezetonev);
            
            
            
            stmt = (PreparedStatement) con.prepareStatement("INSERT INTO programok VALUES(?,?,?,?,?)");
            stmt.setLong(1, new Long(i));
            stmt.setString(2, nev);
            stmt.setString(3, datum);
            stmt.setString(4, ido);
            stmt.setInt(5, vezeto-300);
            stmt.execute();
            
            stmt.close();
            con.close();
            return true;
         
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
        }
        
        return false;
    }

    public boolean programtorol() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean alkalmazottReg(String felhasznalonev, String jelszo, String jelszoUjra, String nev, int iranyitoszam, String cim, String telszam, String tipus) {
        Connection con = null;
        if (jelszo.equals(jelszoUjra)){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/hotelservices", "root", "admin");
            PreparedStatement stmt ;
            if(tipus.equals("Szakacs")){
              stmt = (PreparedStatement) con.prepareStatement("SELECT max(idSzakacs) FROM szakacs");
            }
            if(tipus.equals("Recepcios")){
              stmt = (PreparedStatement) con.prepareStatement("SELECT max(idRecepcios) FROM recepcios");
            }
            else{
             stmt = (PreparedStatement) con.prepareStatement("SELECT max(idTakarito) FROM takarito");
            }
            
            int i = 0;
            ResultSet rs = stmt.executeQuery();
            if (rs.next()) {
                i = rs.getInt(1) + 1;
                System.out.println(i);
            }

            stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM vendeg where FelhasznaloNev = ?");
            stmt.setString(1, felhasznalonev);
            rs = stmt.executeQuery();
            if (rs.next()) {
                con.close();
                return false;
            }
            stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM recepcios where FelhasznaloNev = ?");
            stmt.setString(1, felhasznalonev);
            rs = stmt.executeQuery();
            if (rs.next()) {
                con.close();
                return false;
            }
            stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM szakacs where FelhasznaloNev = ?");
            stmt.setString(1, felhasznalonev);
            rs = stmt.executeQuery();
            if (rs.next()) {
                con.close();
                return false;
            }
            stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM takarito where FelhasznaloNev = ?");
            stmt.setString(1, felhasznalonev);
            rs = stmt.executeQuery();
            if (rs.next()) {
                con.close();
                return false;
            }
            stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM szallodavezeto where FelhasznaloNev = ?");
            stmt.setString(1, felhasznalonev);
            rs = stmt.executeQuery();
            if (rs.next()) {
                con.close();
                return false;
            } 
            if(tipus.equals("Szakacs")){
            
            stmt = (PreparedStatement) con.prepareStatement("INSERT INTO szakacs VALUES(?,?,?,?,?,?,?)");
            stmt.setLong(1, new Long(i));
            stmt.setString(2, felhasznalonev);
            stmt.setString(3, jelszo);
            stmt.setString(4, nev);
            stmt.setInt(5, iranyitoszam);
            stmt.setString(6, cim);
            stmt.setString(7, telszam);
            stmt.execute();
            
            stmt.close();
            con.close();
            return true;
            }
            if(tipus.equals("Recepcios")){
            
            stmt = (PreparedStatement) con.prepareStatement("INSERT INTO recepcios VALUES(?,?,?,?,?,?,?)");
            stmt.setLong(1, new Long(i));
            stmt.setString(2, felhasznalonev);
            stmt.setString(3, jelszo);
            stmt.setString(4, nev);
            stmt.setInt(5, iranyitoszam);
            stmt.setString(6, cim);
            stmt.setString(7, telszam);
            stmt.execute();
            
            stmt.close();
            con.close();
            return true;
            }
            if(tipus.equals("Takarito")){
                
            stmt = (PreparedStatement) con.prepareStatement("INSERT INTO takarito VALUES(?,?,?,?,?,?,?)");
            stmt.setLong(1, new Long(i));
            stmt.setString(2, felhasznalonev);
            stmt.setString(3, jelszo);
            stmt.setString(4, nev);
            stmt.setInt(5, iranyitoszam);
            stmt.setString(6, cim);
            stmt.setString(7, telszam);
            stmt.execute();
            
            stmt.close();
            con.close();
            return true;
            }
            return false;
            
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
        }
        }
        return false;
    }

    public boolean alkalmazottTorol() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public LinkedList<ProgramokDTO> listazProgramok() {
     LinkedList<ProgramokDTO> ll = new LinkedList<ProgramokDTO>();
        Connection con = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/hotelservices", "root", "admin");
            
            PreparedStatement stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM programok");
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                ProgramokDTO program = new ProgramokDTO();
                program.setProgramokId(rs.getInt(1));
                program.setNev(rs.getString(2));
                program.setDatum(rs.getString(3));
                program.setIdo(rs.getString(4));
                program.setVezetoAzon(rs.getInt(5));
//                System.out.println(szoba.getAr());
                ll.addLast(program);
                
            }
            con.close();
            stmt.close();

        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
        }
    return ll;     
    }

    public LinkedList<EmberDTO> listazAlkalmazottak() {
        LinkedList<EmberDTO> ll = new LinkedList<EmberDTO>();
        Connection con = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/hotelservices", "root", "admin");
            
            PreparedStatement stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM szakacs");
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                EmberDTO ember = new EmberDTO();
                ember.setFelhasznalonev(rs.getString(2));
                ember.setJelszo(rs.getString(3));
                ember.setNev(rs.getString(4));
                ember.setISzam(rs.getInt(5));
                ember.setCim(rs.getString(6));
                ember.setTelszam(rs.getString(7));
                ember.setBeosztas("Szakács");
//                System.out.println(szoba.getAr());
                ll.addLast(ember);
                
            }
            
            stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM recepcios");
            rs = stmt.executeQuery();
            while (rs.next()) {
                EmberDTO ember = new EmberDTO();
                ember.setFelhasznalonev(rs.getString(2));
                ember.setJelszo(rs.getString(3));
                ember.setNev(rs.getString(4));
                ember.setISzam(rs.getInt(5));
                ember.setCim(rs.getString(6));
                ember.setTelszam(rs.getString(7));
                ember.setBeosztas("Recepciós");
//                System.out.println(szoba.getAr());
                ll.addLast(ember);
                
            }
            
            stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM takarito");
            rs = stmt.executeQuery();
            while (rs.next()) {
                EmberDTO ember = new EmberDTO();
                ember.setFelhasznalonev(rs.getString(2));
                ember.setJelszo(rs.getString(3));
                ember.setNev(rs.getString(4));
                ember.setISzam(rs.getInt(5));
                ember.setCim(rs.getString(6));
                ember.setTelszam(rs.getString(7));
                ember.setBeosztas("Takarító");
//                System.out.println(szoba.getAr());
                ll.addLast(ember);
                
            }
            con.close();
            stmt.close();

        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
        }
    return ll;     
    }

}
