private void checkRUT() { RUTResult result = verifyRUT2(rutNumber_TXT.Text); Debug.WriteLine(rutNumber_TXT.Text + " => " + result.ToString()); isValidRUT.Text = result.ToString(); }
private String addRUTVerificationPart(String RUTDigitPart) { String[] verificationCharacters = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "K" }; int verificationCharIndex = 0; String RUTWithChecksum = ""; RUTResult result1 = RUTResult.BAD_CHECKSUM; RUTResult result2 = RUTResult.BAD_CHECKSUM; do { RUTWithChecksum = RUTDigitPart + "-" + verificationCharacters[verificationCharIndex]; result1 = verifyRUT1(RUTWithChecksum); result2 = verifyRUT2(RUTWithChecksum); if (result1 != RUTResult.VALID) { Debug.WriteLine(result1 + " retrying..."); } if (result2 != RUTResult.VALID) { Debug.WriteLine(result2 + " retrying..."); } verificationCharIndex++; } while ((result1 != RUTResult.VALID && verificationCharIndex < verificationCharacters.Length) || result1 != result2); if (result1 != result2) { throw new Exception("Inconsistent RUT verification results (" + result1 + " vs " + result2 + ") for '" + RUTDigitPart + "'"); } else if (result1 != RUTResult.VALID) { throw new Exception("Couldn't generate verification digit for '" + RUTDigitPart + "'"); } else { Debug.WriteLine("Found valid RUT: " + RUTWithChecksum); } return(RUTWithChecksum); }