/*
 * 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.SzakacsDAO;
import com.HotelServices.model.dto.EtelDTO;
import com.HotelServices.model.dto.SzakacsDTO;
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 SzakacsDAOImpl extends AbstractGenericDAOImpl<SzakacsDTO, Long>
	implements SzakacsDAO{

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

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

    public boolean menuKiir(String a1, String a2, String a3, String b1, String b2, String b3, String nap, String nev) {
        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(idEtel) FROM etel");
            int i = 0;
            ResultSet rs = stmt.executeQuery();
            if (rs.next()) {
                i = rs.getInt(1) + 1;
//                System.out.println(i);
            }

            int j = new Bejelentkezik().userAzon(nev)-400;
            
            stmt = (PreparedStatement) con.prepareStatement("INSERT INTO etel VALUES(?,?,?,?,?,?,?)");
            stmt.setLong(1, new Long(i));
            stmt.setString(2,nap );
            stmt.setString(3,"A" );
            stmt.setString(4,a1 );
            stmt.setString(5,a2 );
            stmt.setString(6,a3 );
            stmt.setInt(7, j);
            stmt.execute();
            
            stmt = (PreparedStatement) con.prepareStatement("INSERT INTO etel VALUES(?,?,?,?,?,?,?)");
            stmt.setLong(1, new Long(i)+1);
            stmt.setString(2,nap );
            stmt.setString(3,"B" );
            stmt.setString(4,b1 );
            stmt.setString(5,b2 );
            stmt.setString(6,b3 );
            stmt.setInt(7, j);
            stmt.execute();
            
            stmt.close();
            con.close();
            return true;
         
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
        }
        
        return false;
    }

    public LinkedList<EtelDTO> menuk() {
        LinkedList<EtelDTO> ll = new LinkedList<EtelDTO>();
        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 etel");
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                EtelDTO etel = new EtelDTO();
                etel.setId(rs.getInt(1));
                etel.setNap(rs.getString(2));
                etel.setMenu(rs.getString(3));
                etel.setEloetel(rs.getString(4));
                etel.setFoetel(rs.getString(5));
                etel.setDesszert(rs.getString(6));
                etel.setSzakacs_id(rs.getInt(7));
//                System.out.println(szoba.getAr());
                ll.addLast(etel);
                
            }
            con.close();
            stmt.close();

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

    
}
