private void revisarRut() { try { string dv; int aux1, aux2, suma = 0, aux3 = 2, DigVerif; aux1 = Convert.ToInt32(txtRut.Text); while (aux1 > 0) { aux2 = aux1 % 10; aux1 = aux1 / 10; suma = suma + aux2 * aux3; aux3++; if (aux3 == 8) { aux3 = 2; } } DigVerif = (suma % 11); DigVerif = 11 - DigVerif; if (DigVerif == 11) { dv = "0"; } else { if (DigVerif == 10) { dv = "k"; } else { dv = DigVerif.ToString(); } } if (dv != txtDV.Text) { pbRut.Visible = true; pbRutB.Visible = false; } else { pbRutB.Visible = true; pbRut.Visible = false; } } catch (Exception ex) { MessageBox.Show("Error al ingresar el rut. Intente nuevamente.", "Rut", MessageBoxButtons.OK, MessageBoxIcon.Error); txtRut.Clear(); txtDV.Clear(); txtRut.Focus(); } }
private void revisarRut() { try { string dv; int aux1, aux2, suma = 0, aux3 = 2, DigVerif; aux1 = Convert.ToInt32(maskedTextBox1.Text.Replace(",", string.Empty)); while (aux1 > 0) { aux2 = aux1 % 10; aux1 = aux1 / 10; suma = suma + aux2 * aux3; aux3++; if (aux3 == 8) { aux3 = 2; } } DigVerif = (suma % 11); DigVerif = 11 - DigVerif; if (DigVerif == 11) { dv = "0"; } else { if (DigVerif == 10) { dv = "k"; } else { dv = DigVerif.ToString(); } } label8.Text = dv; } catch (Exception ex) { //MessageBox.Show("Error al ingresar los datos"); } }
private void textBox1_Leave(object sender, EventArgs e) { string dv; int aux1, aux2, suma = 0, aux3 = 2, DigVerif; aux1 = Convert.ToInt32(textBox1.Text); while (aux1 > 0) { aux2 = aux1 % 10; aux1 = aux1 / 10; suma = suma + aux2 * aux3; aux3++; if (aux3 == 8) { aux3 = 2; } } DigVerif = (suma % 11); DigVerif = 11 - DigVerif; if (DigVerif == 11) { dv = "0"; } else { if (DigVerif == 10) { dv = "k"; } else { dv = DigVerif.ToString(); } } label1.Text = dv; }