using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Configuration;
using Oracle.Web.Security;
using Oracle.DataAccess.Client;
using System.Data;

namespace VEtterem
{
    public partial class Registration : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            (Master.FindControl("LabelContentCim") as Label).Text = "Regisztráció";
        }

        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            string[] s =  Roles.GetAllRoles();
            if(s.Contains("ugyfel")) {
                // Az újonnan regisztrált ügyfél szerepkörét "ugyfel"-re állítja
                Roles.AddUserToRole(CreateUserWizard1.UserName, "ugyfel");
            }

            string nev = this.CreateUserWizard1.UserName;
            string email = this.CreateUserWizard1.Email;
            string teljnev = ((TextBox)this.CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TeljesNevTB")).Text;
            string cim = ((TextBox)this.CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("CimTB")).Text;
            string tel = ((TextBox)this.CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TelTB")).Text;

            OracleConnection oc = new OracleConnection();
            oc.ConnectionString = ConfigurationManager.ConnectionStrings["VCS"].ConnectionString;
            OracleCommand ocmd = new OracleCommand("INSERT INTO Ugyfel VALUES(UGYFEL_SEQ.NEXTVAL, :pnev, :pemail, :pteljesnev, :pcim, :ptel)", oc);

            ocmd.Parameters.Add("pnev", OracleDbType.Varchar2).Value = nev;
            ocmd.Parameters.Add("pemail", OracleDbType.Varchar2).Value = email;
            ocmd.Parameters.Add("pteljesnev", OracleDbType.Varchar2).Value = teljnev;
            ocmd.Parameters.Add("pcim", OracleDbType.Varchar2).Value = cim;
            ocmd.Parameters.Add("ptel", OracleDbType.Varchar2).Value = tel;
            
            try
            {
                oc.Open();
                int beszurva = ocmd.ExecuteNonQuery();
                Naplo.NaplobaIr(User.Identity.Name, Request.UserHostAddress, Esemeny.Reg);
            }
            catch (OracleException oe)
            {
                //TODO: kivétel naplózása
            }
            finally
            {
                oc.Close();
            }
        }

               
    }
}
