Click here to Skip to main content
14,937,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Goodnight,
I send this email since I need if you can post 2 queries that I need to do about xamarin to see if you can help me.

1: I am doing a validation in one of the texts that I need to do a validation I have the code that performs the validation but it is in c #.

The button does the validations in the methods and I have it like this

C#
if (string.IsNullOrEmpty(this.RutTxt))
{
    await Application.Current.MainPage.DisplayAlert(
        "Error",
        "Ingrese el Rut",
        "Aceptar");
    return;
}
else if (this.RutTxt.Length != 7)
{
    await Application.Current.MainPage.DisplayAlert("Advertencia", "Faltan digitos, favor de ingresar el rut debe tener al menos 7 digitos.", "Aceptar");
    return;
}
else
{
    if (!this.RutTxt.ToCharArray().All(Char.IsDigit))
    {
        await Application.Current.MainPage.DisplayAlert("Advertencia", "El formato del rut es incorrecto, solo se aceptan numeros.", "Aceptar");
        return;
    }
}


I already have 3 different validations that validate the data of the rut that are only numbers but I need it to validate the check digit

this is the check digit button:

C#
if (string.IsNullOrEmpty(this.DvTxt))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "Ingrese el Rut",
                    "Aceptar");
                return;
            }


that this is the code in C #

C#
public static string Digito(int rut)
{
    int suma = 0;
    int multiplicador = 1;
    while (rut != 0)
    {
        multiplicador++;
        if (multiplicador == 8)
            multiplicador = 2;
        suma += (rut % 10) * multiplicador;
        rut = rut / 10;
    }
    suma = 11 - (suma % 11);
    if (suma == 11)
    {
        return "0";
    }
    else if (suma == 10)
    {
        return "K";
    }
    else
    {
        return suma.ToString();
    }
}


And the truth of the things that I do not know how to do the validation properly so that it really validates the information.

2: On the other hand I have 2 Piker and a texbox that I need to activate when I actually enter some information

For example

If I have in the Piker called user type and I have selected a Supplier, the supplier category texbox must be activated and if in the piker I have a worker selected, the other piker that is from the position must be activated.

I thank you in advance and I hope you have an excellent day.

What I have tried:

I have tried so far to try to call the class but it does not work for me and I really do not know how to solve it, if someone knows how to perform this validation I would appreciate it.
Posted
Updated 16-May-21 10:24am
v5
Comments
OriginalGriff 13-May-21 0:41am
   
This is an English language site, and we only accept and answer question in that language.
Please use Google Translate (or similar) to translate your questions as I have done for you in your query - and please check that what it resulted in does not lose the "sense" of what you are asking.

1 solution

All you need to do in a "check digit" routine is return a "bool"; i.e true / false; yes / no ... meaning: it is valid or not valid.

In your "validation" it's just:

C#
if ( IsCheckDigitValid( x ) {
...
} else {
...
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900