import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import javax.swing.border.*;
import java.sql.*;
//import oracle.jdbc.*;

public class Ujhallg extends JDialog implements ActionListener{
	
	private final String strOK = "OK";
    private final String strMegsem = "M\u00e9gsem";
    private JButton okGomb;
    private JButton megsemGomb;
    private JPanel gombPanel;
    private JPanel adatPanel;
    private JTextField m_loginNameBox;
    private JTextField m_neptunBox;
    private JTextField m_szulidoBox;
    private JTextField m_anyjaneveBox;
    private JPanel kontener;
    private String m_loginName;
    private String m_neptunName;
    private String m_password;
    private String m_szulido;
    private String m_anyjaneve;
    private JComboBox cbox;
    private Menu1 szuloPanel;
    private String kod;
    
    public Ujhallg(JFrame parent) {
    	super(parent, "\u00daj hallgat\u00f3:", true);
    	szuloPanel = (Menu1)parent;
    	setBounds(355,250,300,240);
    	setDefaultCloseOperation(HIDE_ON_CLOSE);
    	cbox = new JComboBox();
    	cbox.setPreferredSize(new Dimension(180,20));
    	try{
    	Statement statement = szuloPanel.con.createStatement();       
        ResultSet res = statement.executeQuery("SELECT Szak_kod FROM SZAK" );
        String s;
        while ( res.next() )
        {
            s = res.getString(1);
            cbox.addItem(s);
        }
    	}
    	catch(SQLException e){
    		System.err.println( e.getMessage() );
    	}
    	cbox.addActionListener(this);
    	okGomb = new JButton(strOK);
	    okGomb.addActionListener(this);
	    megsemGomb = new JButton(strMegsem);
	    megsemGomb.addActionListener(this);
	
      	gombPanel = new JPanel(new FlowLayout( FlowLayout.RIGHT));
	    gombPanel.add(okGomb);
	    gombPanel.add(megsemGomb);
    	
    	adatPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
	    adatPanel.setBorder(new EmptyBorder(10,0,0,10));
	    
	    adatPanel.add(new JLabel("     Hallg.n\u00e9v:       "));
        m_loginNameBox = new JTextField("",16);
	    adatPanel.add(m_loginNameBox);
	    
	    adatPanel.add(new JLabel("     Neptun k\u00f3d:   "));
	    m_neptunBox = new JTextField("",16);
	    adatPanel.add(m_neptunBox);
	    
	    adatPanel.add(new JLabel("     Szak:               "));
	    adatPanel.add(cbox);
	    
	    adatPanel.add(new JLabel("    Sz\u00fcl.id\u0151:          "));
        m_szulidoBox = new JTextField("",16);
	    adatPanel.add(m_szulidoBox);
	    
	    adatPanel.add(new JLabel("   Anyja neve:     "));
        m_anyjaneveBox = new JTextField("",16);
	    adatPanel.add(m_anyjaneveBox);
	    
	    kontener = new JPanel(new BorderLayout());
	    kontener.add(adatPanel,BorderLayout.CENTER);
	    kontener.add(gombPanel,BorderLayout.SOUTH);
	    getContentPane().add(kontener);
        setLocationRelativeTo(parent);

	    
    }
    
    public void actionPerformed(ActionEvent ae){
 	   String str = ae.getActionCommand();
 	   if(str.equals(strOK)){
		
			String enev = m_loginNameBox.getText(); 
        	String ekod = m_neptunBox.getText();
        	kod=(String)cbox.getSelectedItem();
        	Date eszulido=null;
        	try{ eszulido = Date.valueOf(m_szulidoBox.getText());}
        	catch( IllegalArgumentException e){ JOptionPane.showMessageDialog(this,"A megfelel\u00f5 d\u00e1tumform\u00e1tum: YYYY-MM-DD","Rossz d\u00e1tumform\u00e1tum",JOptionPane.ERROR_MESSAGE); };     //IllegalArgumentException
        	String eanyanev = m_anyjaneveBox.getText();
        	
        	try{
	               CallableStatement cs = szuloPanel.con.prepareCall("{call hallg_beszur(?, ?, ?, ?, ?)}");
                   cs.setString(1,enev);
                   cs.setString(2,ekod);
                   cs.setDate(3,eszulido);
                   cs.setString(4,eanyanev);
                   cs.setString(5,kod);
                   
                   ResultSet rs = cs.executeQuery();
            }
            catch(SQLException x){
	        JOptionPane.showMessageDialog(this,x.getMessage(),"HIBA",JOptionPane.ERROR_MESSAGE);
    	
            }
            szuloPanel.removePanel(this);
           
       		
 	   }
 	   else if(str.equals(strMegsem)){
 		szuloPanel.removePanel(this);
 	   }
    }
  
     
    public String getLoginName(){
 	   return m_loginName;	
    }
    public String getNeptunCode(){
  	   return m_neptunName;	
    }
    public String getSzulIdo(){
  	   return m_szulido;	
    }
    public String getAnyaNev(){
  	   return m_anyjaneve;	
    }
    public Object getComboBox(){
  	   Object o = cbox.getSelectedItem();
  	   return o;	
    }
}