private async void txtRut_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtRut.Text != "")
                {
                    string verifica = new VerificarRut().ValidarRut(txtRut.Text);
                    string rut      = txtRut.Text;
                    /*Quitar los . las , y -*/
                    rut = rut.Replace(",", "");
                    rut = rut.Replace(".", "");
                    rut = rut.Replace("-", "");
                    /*ajustar el largo del rut a validar*/
                    if (rut.Length == 8)
                    {
                        rut = "0" + rut;
                    }
                }

                string ruti = txtRut.Text;
                rutificador(ruti);
                BibliotecaClase.Cliente cl = new BibliotecaClase.Cliente().Buscar1(txtRut.Text);
                if (cl != null)
                {
                    txtRut.Text = cl.Rut;
                }
            }
            catch (Exception)
            {
                await this.ShowMessageAsync(null, "erorcito");
            }
        }
        private void txtRut_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtRut.Text != "")
                {
                    string verifica = new VerificarRut().ValidarRut(txtRut.Text);
                    string rut      = txtRut.Text;
                    /*Quitar los . las , y -*/
                    rut = rut.Replace(",", "");
                    rut = rut.Replace(".", "");
                    rut = rut.Replace("-", "");
                    /*ajustar el largo del rut a validar*/
                    if (rut.Length == 8)
                    {
                        rut = "0" + rut;
                    }
                }

                string ruti = txtRut.Text;
                rutificador(ruti);
                BibliotecaClase.Cliente cl = new BibliotecaClase.Cliente().Buscar1(txtRut.Text);

                if (cl != null)
                {
                    int miid = (cl.IdTipoEmpresa) / 10;
                    txtRut.Text                = cl.Rut;
                    txtRazon.Text              = cl.Razon_social;
                    txtNombre.Text             = cl.Nom_contacto;
                    txtCorreo.Text             = cl.Correo;
                    txtDireccion.Text          = cl.Direccion;
                    txtTelefono.Text           = cl.Telefono;
                    cmbActividad.SelectedIndex = cl.idActividadEmpresa;
                    cmbTipo.SelectedIndex      = miid;
                    txtRut.IsEnabled           = false;
                }
                txtRazon.IsEnabled     = true;
                txtNombre.IsEnabled    = true;
                txtDireccion.IsEnabled = true;
                txtCorreo.IsEnabled    = true;
                txtTelefono.IsEnabled  = true;
                cmbActividad.IsEnabled = true;
                cmbTipo.IsEnabled      = true;
            }
            catch (Exception)
            {
                txtRut.Text = "";
            }
        }
Beispiel #3
0
        //añadir formato al rut

        private void txtRut_LostFocus(object sender, RoutedEventArgs e)
        {
            if (txtRut.Text.Length >= 7 && txtRut.Text.Length <= 8)
            {
                string v = new VerificarRut().ValidarRut(txtRut.Text);
                txtDV.Text = v;
                try
                {
                    string rutSinFormato = txtRut.Text;

                    //si el rut ingresado tiene "." o "," o "-" son ratirados para realizar la formula
                    rutSinFormato = rutSinFormato.Replace(",", "");
                    rutSinFormato = rutSinFormato.Replace(".", "");
                    rutSinFormato = rutSinFormato.Replace("-", "");
                    string rutFormateado = String.Empty;

                    //obtengo la parte numerica del RUT
                    //string rutTemporal = rutSinFormato.Substring(0, rutSinFormato.Length - 1);
                    string rutTemporal = rutSinFormato;
                    //obtengo el Digito Verificador del RUT
                    //string dv = rutSinFormato.Substring(rutSinFormato.Length - 1, 1);

                    Int64 rut;

                    //aqui convierto a un numero el RUT si ocurre un error lo deja en CERO
                    if (!Int64.TryParse(rutTemporal, out rut))
                    {
                        rut = 0;
                    }

                    //este comando es el que formatea con los separadores de miles
                    rutFormateado = rut.ToString("N0");

                    if (rutFormateado.Equals("0"))
                    {
                        rutFormateado = string.Empty;
                    }
                    else
                    {
                        //si no hubo problemas con el formateo agrego el DV a la salida
                        // rutFormateado += "-" + dv;

                        //y hago este replace por si el servidor tuviese configuracion anglosajona y reemplazo las comas por puntos
                        rutFormateado = rutFormateado.Replace(",", ".");
                    }

                    //se pasa a mayuscula si tiene letra k
                    rutFormateado = rutFormateado.ToUpper();

                    //la salida esperada para el ejemplo es 99.999.999-K
                    txtRut.Text = rutFormateado;
                }
                catch (Exception)
                {
                }
            }
            else
            {
                txtRut.Text = "";
            }
        }