Beispiel #1
0
        private void btnIngresar_Click(object sender, RoutedEventArgs e)
        {
            List <PerfildeCargo> PCargo   = col.ReadAllPerfilesdeCargo();
            List <Perfil>        perfiles = col.ReadAllPerfiles();

            try
            {
                Usuario us = new Usuario();
                us.RUT = txtRut.Text;
                UsuarioOperacion usOp = new UsuarioOperacion(us);

                XML    formato = new XML();
                string xml     = formato.Serializar(us);
                WFBS.Presentation.ServiceWFBS.ServiceWFBSClient servicio = new WFBS.Presentation.ServiceWFBS.ServiceWFBSClient();

                if (servicio.LeerUsuario(xml) == null)
                {
                    if (txtNombre.Text.Length > 0 && txtRut.Text.Length > 0 && txtPassword.Password.Length > 0)
                    {
                        if (validarRut())
                        {
                            if (txtPassword.Password == txtPassword2.Password)
                            {
                                us.NOMBRE   = txtNombre.Text;
                                us.PASSWORD = txtPassword.Password;
                                if (cmbPerfil.SelectedIndex == 2)
                                {
                                    us.JEFE_RESPECTIVO = cmbJefe.SelectedItem.ToString();
                                }
                                else
                                {
                                    us.JEFE_RESPECTIVO = "";
                                }
                                if (rbFemenino.IsChecked == true)
                                {
                                    us.SEXO = "F";
                                }
                                if (rbMasculino.IsChecked == true)
                                {
                                    us.SEXO = "M";
                                }

                                foreach (PerfildeCargo a in PCargo)
                                {
                                    if (a.DESCRIPCION == (string)cmbArea.SelectedItem)
                                    {
                                        us.ID_PERFIL_DE_CARGO = Convert.ToInt32(a.ID_PERFIL_DE_CARGO);
                                    }
                                }
                                foreach (Perfil p in perfiles)
                                {
                                    if (p.TIPO_USUARIO == (string)cmbPerfil.SelectedItem)
                                    {
                                        us.ID_PERFIL = Convert.ToInt32(p.ID_PERFIL);
                                    }
                                }
                                if (rbNoObsoleto.IsChecked == true)
                                {
                                    us.OBSOLETO = 0;
                                }
                                if (rbSiObsoleto.IsChecked == true)
                                {
                                    us.OBSOLETO = 1;
                                }

                                string xml2 = formato.Serializar(us);

                                if (servicio.CrearUsuario(xml2))
                                {
                                    MessageBox.Show("Agregado correctamente", "Éxito!");
                                    this.Limpiar();
                                    NavigationService  navService = NavigationService.GetNavigationService(this);
                                    MantenedorUsuarios nextPage   = new MantenedorUsuarios();
                                    navService.Navigate(nextPage);
                                }
                                else
                                {
                                    MessageBox.Show("No se pudo agregar el Usuario, verifique que los datos sean correctos", "Aviso");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Las contraseñas no coinciden", "Aviso");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Debe ingresar un Rut valido", "Aviso");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Debe completar los campos antes de ingresar", "Aviso");
                    }
                }
                else
                {
                    MessageBox.Show("El rut ingresado ya posee un cuenta", "Aviso!");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("No se pudo agregar el Usuario!", "Alerta");
            }
        }