public int ActualizarReferencias(RefecenciasE refE, int id, ref string oerro)
 {
     try
     {
         return _referenciasDAL.ActualizarReferencias(refE, id, ref oerro);
     }
     catch (Exception)
     {
         oerro = "Ocurrio un error al ingresar  los datos";
         throw;
     }
 }
 public int GuardarReferencias(RefecenciasE preferencias, ref string oerro)
 {
     try
     {
         return _referenciasDAL.GuardarReferencias(preferencias, ref oerro);
     }
     catch (Exception)
     {
         oerro = "Ocurrio un error al ingresar  los datos";
         throw;
     }
 }
        //************************************************************************
        protected void agregarReferencia()
        {
            string TipoReferencia, Nombre, Telefono, Descripcion;
            int idReferencia;

            idReferencia = Convert.ToInt32(cb_tipoRef.SelectedValue);
            TipoReferencia = cb_tipoRef.Text.ToString();
            Nombre = txt_nombreRef.Text;
            Telefono = txt_telefonoRef.Text;
            Descripcion = txt_descripcionREF.Text;

            //Procedimiento para agregar referencia a la base

            RefecenciasE refE = new RefecenciasE();
            int returReferencias = 0;

            refE.id_tipoReferencias = idReferencia;
            refE.nombre = Nombre;
            refE.telefono = Telefono;
            refE.descripcion = Descripcion;

            bool agregar = true;
            foreach (DataRowView dr in DataGrid_Referencias.Items)
            {
                if (dr.Row.ItemArray[1].ToString() == idReferencia.ToString() && dr.Row.ItemArray[2].ToString().ToLower() == TipoReferencia.ToLower() &&
                  dr.Row.ItemArray[3].ToString().ToLower() == Nombre.ToLower() && dr.Row.ItemArray[4].ToString().ToLower() == Telefono.ToLower() &&
                  dr.Row.ItemArray[5].ToString().ToLower() == Descripcion.ToLower())
                {
                    agregar = false;
                }
            }
            if (agregar)
            {

                returReferencias = _referenciasBL.AgregarReferencias(refE, Int32.Parse(idCandidato), ref oerro);

                //************************************************************************

                tablaReference.Rows.Add(returReferencias, idReferencia, TipoReferencia, Nombre, Telefono, Descripcion);

            }
            else
            {
                MessageBox.Show("Esa informacion ya ha sido ingresada, por favor revisar los datos.");
                agregar = true;
            }

            cb_tipoRef.Text = string.Empty;
            txt_nombreRef.Text = string.Empty;
            txt_telefonoRef.Text = string.Empty;
            txt_descripcionREF.Text = string.Empty;
        }
        private void BTOAgregarTipoReferencia_Click(object sender, RoutedEventArgs e)
        {
            if (!(string.IsNullOrEmpty(cb_tipoRef.Text) | string.IsNullOrEmpty(txt_nombreRef.Text) | string.IsNullOrEmpty(txt_telefonoRef.Text) |
                string.IsNullOrEmpty(txt_descripcionREF.Text)))
            {
                if (nuevoRefe == false)
                {
                    tablaReference.Rows.Remove(RowPivotInfoAca);

                    RowPivotInfoAca = null;
                    string TipoReferencia, Nombre, Telefono, Descripcion;
                    int idReferencia;

                    idReferencia = Convert.ToInt32(cb_tipoRef.SelectedValue);
                    TipoReferencia = cb_tipoRef.Text.ToString();
                    Nombre = txt_nombreRef.Text;
                    Telefono = txt_telefonoRef.Text;
                    Descripcion = txt_descripcionREF.Text;

                    RefecenciasE refeObj = new RefecenciasE();
                    refeObj.id_referencias = int.Parse(idUpdateRefe);
                    refeObj.id_tipoReferencias = idReferencia;
                    refeObj.nombre = Nombre;
                    refeObj.telefono = Telefono;
                    refeObj.descripcion = Descripcion;

                    bool agregar = true;
                    foreach (DataRowView dr in DataGrid_Referencias.Items)
                    {
                        if (dr.Row.ItemArray[1].ToString() == idReferencia.ToString() && dr.Row.ItemArray[2].ToString().ToLower() == TipoReferencia.ToLower() &&
                          dr.Row.ItemArray[3].ToString().ToLower() == Nombre.ToLower() && dr.Row.ItemArray[4].ToString().ToLower() == Telefono.ToLower() &&
                          dr.Row.ItemArray[5].ToString().ToLower() == Descripcion.ToLower())
                        {
                            agregar = false;
                        }
                    }
                    if (agregar)
                    {

                        ReferenciasBLL refeBll = new ReferenciasBLL();
                        refeBll.ActualizarReferencias(refeObj, int.Parse(idCandidato), ref oerro);

                        tablaReference.Rows.Add(refeObj.id_referencias, idReferencia, TipoReferencia, Nombre, Telefono, Descripcion);

                    }
                    else
                    {
                        MessageBox.Show("Esa informacion ya ha sido ingresada, por favor revisar los datos.");
                        agregar = true;
                    }

                    cb_tipoRef.Text = string.Empty;
                    txt_nombreRef.Text = string.Empty;
                    txt_telefonoRef.Text = string.Empty;
                    txt_descripcionREF.Text = string.Empty;
                    nuevoRefe = true;
                }
                else
                {
                    agregarReferencia();
                }
            }
            else
            {
                MessageBox.Show("Inserte todos los datos solicitados");
            }
        }
        private void btn_Referencias_Click(object sender, RoutedEventArgs e)
        {
            //VARIABLE PARA MANDAR MENSAJE PARA GUARDAR REFERENCIA
            int returVariable4 = 0;

            //    BOTON PARA GUARDAR REFERECNCIASS  (EVENTO)
            string oerror = "";
            RefecenciasE refE = new RefecenciasE();
            foreach (DataRowView row in DataGrid_Referencias.Items)
            {
                refE.id_tipoReferencias = Convert.ToInt32(row[0]);
                refE.nombre = Convert.ToString(row[2]);
                refE.telefono = Convert.ToString(row[3]);
                refE.descripcion = Convert.ToString(row[4]);

                returVariable4 = _referenciasBL.GuardarReferencias(refE, ref oerror);
            }
            if (returVariable4 > 0)
            {
                MessageBox.Show("Registro fue guardado con exito..", "Informacion", MessageBoxButton.OK, MessageBoxImage.Information);
                tcPrincipal.SelectedIndex = 6;
                tab6.IsEnabled = false;

                Busqueda _bw = new Busqueda();
                _bw.InitializeComponent();
                this.Close();
                _bw.Show();

            }
        }
        //***BOTON PARA GUARDAR TODA LA INFORMACION DE UN NUEVO PERFIL***///
        private void GuardarTodo_Click(object sender, RoutedEventArgs e)
        {
            //VARIABLE DE MENSAJE AL GUARDAR INFORMACION ACADEMICA

            int returVariable3 = 0;
            int variable1 = 2;
            int variable2 = 0;
            if (variable1 != returVariable3 && variable2 != returVariable3)
            { }
            else if (variable1 != returVariable3 || variable2 != returVariable3) { }
            string cadenaFaltanDatos = "";

            ///////////////////////////////***FIN DEL IF*** //////////////////////////////
            //VALIDA LOS CAMPOS OBLIGATORIOS DEL TAB 1
            if (string.IsNullOrEmpty(txtNombreInfBasica.Text) || string.IsNullOrEmpty(DateFechNacInfoBasica.Text) || string.IsNullOrEmpty(txtNombreInfBasica.Text) || (string.IsNullOrEmpty(cbDeptos.Text)) ||
                (string.IsNullOrEmpty(cbMunic.Text)) || (string.IsNullOrEmpty(cb_profesionesIB.Text)) || (string.IsNullOrEmpty(cbSitLab.Text)) || (string.IsNullOrEmpty(txtTeNocelularInfBasica.Text)) ||
                (string.IsNullOrEmpty(txtCorreoInfBasica.Text)) || (string.IsNullOrEmpty(txtNoduiInfBasica.Text)) || (string.IsNullOrEmpty(txtNnitInfBasica.Text))
                )
            {
                MessageBox.Show("Este fomulario tiene campos obligatorios '*' ", "Informacion", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {

                if (DateTime.Compare(DateTime.Now.Date, DateFechNacInfoBasica.SelectedDate.Value.Date) > 0)
                {
                    //SE VALIDAN QUE LOS DEMAS GRID CONTENGAN DATOS, SE RECOMIENDA AGREGAR AQUELLOS GRID QUE CONSIDEREN SEAN NECESARIOS.
                    if (DataG_Habilidades.Items.Count == 0 || DataGrid_InfAcademica.Items.Count == 0)
                    {
                        cadenaFaltanDatos = ", YA QUE NO A INGRESADO TODA LA INFORMACION NECESARIA.";
                        MessageBox.Show("Ingrese informacion acdemica y habilidades ya que son formularios requeridos", "Infomacion", MessageBoxButton.OK, MessageBoxImage.Information);

                    }
                    else
                    {
                        //PARAMETROS QUE INGRESARAN A LA BASE TAB INFOMACION BASICA
                        InfoBasicaE _InfoBasicaE = new InfoBasicaE();
                        DateTime edad = DateFechNacInfoBasica.SelectedDate.Value;
                        _InfoBasicaE.nombre = txtNombreInfBasica.Text.ToUpper();
                        _InfoBasicaE.nacionalidad = txtNacionalidadInfBasica.Text.ToUpper();
                        _InfoBasicaE.telefono_celular = txtTeNocelularInfBasica.Text.ToUpper();
                        _InfoBasicaE.telefono_fijo = txtTelefonoCasaInfBasica.Text.ToUpper();
                        //_InfoBasicaE.profesiones = cb_profesionesIB.Text.ToUpper();
                        _InfoBasicaE.id_profesiones = Convert.ToInt32(cb_profesionesIB.SelectedValue);
                        _InfoBasicaE.correo = txtCorreoInfBasica.Text;
                        _InfoBasicaE.fecha_nacimiento = DateFechNacInfoBasica.SelectedDate.Value;
                        _InfoBasicaE.direccion = txtLugarResidenciaInfBasica.Text.ToUpper();
                        //_Imagen = ControlImagen.ObtenerImagenEnObjecto(_Imagen.RutaImagen);
                        _InfoBasicaE.FotoCandidato = _Imagen.OnlyName;
                        if (rbsexoM.IsChecked == true)
                        {
                            _InfoBasicaE.id_genero = 1;
                        }
                        else if (rbsexoF.IsChecked == true)
                        {
                            _InfoBasicaE.id_genero = 2;
                        }

                        _InfoBasicaE.DUI = txtNoduiInfBasica.Text;
                        _InfoBasicaE.NIT = txtNnitInfBasica.Text;
                        _InfoBasicaE.AFP = txtNafpInfBasica.Text;
                        _InfoBasicaE.ISSS = txtNiss.Text;
                        _InfoBasicaE.id_municipio = Convert.ToInt32(cbMunic.SelectedValue);
                        _InfoBasicaE.id_situacionProfesional = Convert.ToInt32(cbSitLab.SelectedValue);
                        string oerro = "";

                        int returinfobasica = 0;
                        returinfobasica = _InfobasicaBL.GudarInfBasica(_InfoBasicaE, ref oerro);

                        // BOTON PARA GUARDAR INFORMACION ACADEMICA (EVENTO)

                        InformacionAcademicaE refinfoAcademica = new InformacionAcademicaE();
                        int returinfoacademica = 0;
                        foreach (DataRowView row in DataGrid_InfAcademica.Items)
                        {
                            refinfoAcademica.id_tipoEducacion = Convert.ToInt32(row[0]);
                            refinfoAcademica.titulo = Convert.ToString(row[2]);
                            refinfoAcademica.institucion = Convert.ToString(row[3]);
                            refinfoAcademica.anio_de_finalizacion = Convert.ToInt32(row[4]);
                            refinfoAcademica.id_statusAcademico = Convert.ToInt32(row[6]);

                            returinfoacademica = _informacionAcademicaBL.GuardarInfomacionAcademica(refinfoAcademica, ref oerro);
                        }

                        //BOTON PARA GUARDAR INFORMACION LABORAL

                        ExpLaboralE refExpL = new ExpLaboralE();
                        int returinfoLaboral = 0;
                        foreach (DataRowView row1 in DataGrid_Inf_Laboral.Items)
                        {
                            refExpL.nombreEmpresa = Convert.ToString(row1[0]);
                            refExpL.cargoDesp = Convert.ToString(row1[1]);
                            refExpL.descripPuesto = Convert.ToString(row1[2]);
                            refExpL.fechaInicio = Convert.ToString(row1[3]);
                            refExpL.fechaFin = Convert.ToString(row1[4]);

                            returinfoLaboral = _experienciaLabBL.GuardarexperienciaLab(refExpL, ref oerro);

                        }

                        // BOTON PARA GUARDARRR LOS DATOS HABILIDADES  (METODOS)

                        HabCandidatoE refHabCandidato = new HabCandidatoE();
                        int returnHabilidades = 0;
                        foreach (DataRowView row3 in DataG_Habilidades.Items)
                        {

                            refHabCandidato.idhabilidadTecnica = Convert.ToInt32(row3[0]);
                            refHabCandidato.id_nivel = Convert.ToInt32(row3[2]);
                            refHabCandidato.id_habilidadAplicacion = Convert.ToInt32(row3[4]);

                            returnHabilidades = _habilidadCandidatoBL.GuardarHabilidadCandidato(refHabCandidato, ref oerro);

                        }

                        //BOTON PARA GUARDAR CERTIFICACIONES EN LA BASE (METODOS)

                        CertificacionesE certifi = new CertificacionesE();
                        int returnCertificaciones = 0;

                        foreach (DataRowView row2 in DataGrid_Certificaciones.Items)
                        {
                            certifi.nombre = Convert.ToString(row2[0]);
                            certifi.institucion = Convert.ToString(row2[1]);
                            certifi.anio = Convert.ToInt16(row2[2]);

                            returnCertificaciones = _certificanesBL.GuardarCertificacionesLAB(certifi, ref oerro);

                        }

                        //BOTON PARA INGRESAR REFERENCIAS A
                        RefecenciasE refE = new RefecenciasE();
                        int returReferencias = 0;
                        foreach (DataRowView row5 in DataGrid_Referencias.Items)
                        {
                            refE.id_tipoReferencias = Convert.ToInt32(row5[0]);
                            refE.nombre = Convert.ToString(row5[2]);
                            refE.telefono = Convert.ToString(row5[3]);
                            refE.descripcion = Convert.ToString(row5[4]);

                            returReferencias = _referenciasBL.GuardarReferencias(refE, ref oerro);

                        }
                        if (oerro == "")
                        {
                            #region Capturar imgen por genero
                            string pMensaje = "", pURL = "";
                            switch (_InfoBasicaE.id_genero)
                            {
                                case 1:
                                    pMensaje = "candidato";
                                    pURL = string.IsNullOrEmpty(_Imagen.RutaImagen) ? @"C:\Imagenes\Fotos\User_default\Userman.png" : _Imagen.RutaImagen;
                                    break;
                                case 2:
                                    pMensaje = "candidata";
                                    pURL = string.IsNullOrEmpty(_Imagen.RutaImagen) ? @"C:\Imagenes\Fotos\User_default\userwoman.png" : _Imagen.RutaImagen;
                                    break;
                            }
                            #endregion

                            if (Elijiomagen)
                                ControlImagen.GuardarImagenEnRuta(_Imagen);

                            #region Mostrar mensaje personalizado

                            SimpleAlert simpleAlert = new SimpleAlert();
                            simpleAlert.Title = "Nuevo Registro";
                            simpleAlert.NamePeople = txtNombreInfBasica.Text;
                            simpleAlert.Url = pURL;

                            simpleAlert.Message = "Se ha creado el nuevo " + pMensaje;
                            simpleAlert.ShowDialog();

                            #region Redireccionamiento
                            Busqueda _menusBusqueda = new Busqueda();
                            _menusBusqueda.InitializeComponent();
                            this.Close();
                            _menusBusqueda.Show();
                            #endregion
                            #endregion

                        }

                        else
                        {
                            MessageBoxResult mbr = MessageBox.Show("OCURRIO UN ERROR AL GUARDAR SUS DATOS... ERROR: " + oerro, "Infomacion", MessageBoxButton.OK, MessageBoxImage.Information);

                        }
                    }
                }
                else
                {
                    MessageBox.Show("La fecha de nacimiento debe ser menor a la fecha actual.","Error", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }