Exemplo n.º 1
0
        //This method handles the validation process of a journey. It checks if it is valid, and if it is, registers it into the database. If it isn't, an error message appears for the user, indicating what he must change.
        private async void Valider(object sender, EventArgs e)
        {
            //First check : the user must fill the values
            if (depAd.Text == null || arrAd.Text == null || pasNum == null || depVil == null || arrVil == null || disNum == null)
            {
                depAd.PlaceholderColor  = Color.PaleVioletRed;
                arrAd.PlaceholderColor  = Color.PaleVioletRed;
                depVil.PlaceholderColor = Color.PaleVioletRed;
                arrVil.PlaceholderColor = Color.PaleVioletRed;
                pasNum.PlaceholderColor = Color.PaleVioletRed;
                disNum.PlaceholderColor = Color.PaleVioletRed;
                await DisplayAlert("Erreur", "Veuillez remplir tous les champs.", "OK");

                return;
            }
            //Second check : the cities must exist
            if (!DatabaseInteraction.DoesCityExist(depVil.Text) || !DatabaseInteraction.DoesCityExist(arrVil.Text))
            {
                await DisplayAlert("Erreur", "Une des villes entrées n'existe pas.", "OK");

                return;
            }

            int passengers = 0;
            int km         = 0;

            try
            {
                passengers = int.Parse(pasNum.Text);
                km         = int.Parse(disNum.Text);
            }
            catch
            {
                await DisplayAlert("Erreur", "Les champs \"Passagers\" et/ou \"KM\" sont incorrects.", "OK");

                return;
            }

            Journey j = new Journey(0, depAd.Text, depVil.Text.ToUpper(), arrAd.Text, arrVil.Text.ToUpper(), DepartureDate.Date.ToString("yyyy-MM-dd") + " " + DepartureTime.Time.ToString(), ArrDate.Date.ToString("yyyy-MM-dd") + " " + ArrTime.Time.ToString(), km, passengers, comm.Text, dog.BackgroundColor == Color.Green, smoke.BackgroundColor == Color.Green, music.BackgroundColor == Color.Green, talk.BackgroundColor == Color.Green);

            try
            {   //Third check : the user must be an existing one on the database
                if (DatabaseInteraction.CheckIfClientExist(InfoExchanger.Email))
                {
                    DatabaseInteraction.ProposeNewJourney(InfoExchanger.Email, j);
                    await DisplayAlert("Trajet ajouté", "Votre trajet a bien été pris en compte", "OK");

                    depAd.Text          = ""; arrAd.Text = ""; DepartureTime.Time = DateTime.Now.TimeOfDay; pasNum.Text = ""; comm.Text = ""; depVil.Text = ""; arrVil.Text = ""; disNum.Text = "";
                    dog.BackgroundColor = Color.Green; smoke.BackgroundColor = Color.Green; music.BackgroundColor = Color.Green; talk.BackgroundColor = Color.Green;
                }
                else
                {
                    await DisplayAlert("Erreur de connexion", "Il semblerait que vous n'êtes pas connecté à un compte existant. Vérifiez et réessayez.", "OK");
                }
            }   //If something goes wrong with the databse, we display an alert popup to the user
            catch (Exception ex) { DatabaseInteraction.ConnectionCloser(); await DisplayAlert("Erreur de traitement", "Une erreur est survenue pendant le traitement de votre requête. Vérifiez que vous soyez connecté.", "OK"); }
        }
Exemplo n.º 2
0
        //This method is called when the "s'inscrire" button is pushed.
        //The first thing one must ddo when handling entries is checking if neither's text attribute is null. Otherwise on any acces, a nullpointerexception will be raised
        //Once this verification is done, we check if what the user entered is valid
        private async void ConfirmInscription(object sender, EventArgs e)
        {
            bool isInscriptionAllowed = true;

            // /!\/!\/!\/!\/!\/!\ BIEN VERIFIER QUE TOUS LES CHAMPS TEXTES NE SONT PAS NULL SOUS PEINE DE NULLPOINTEREXCEPTION /!\/!\/!\ 
            if (mail.Text == null || name.Text == null || surname.Text == null || telephone.Text == null || Password.Text == null || PasswordConfirmation.Text == null)
            {
                FailedPasswordText.Text      = "Veuillez renseigner tous les champs";
                FailedPasswordText.TextColor = Color.Red;
                isInscriptionAllowed         = false;
            }
            else
            {
                //The password must be the same as the password confirmation
                if (Password.Text != PasswordConfirmation.Text)
                {
                    FailedPasswordText.Text      = "Les deux mots de passes que vous avez entrés ne se correspondent pas, veuillez réessayer";
                    FailedPasswordText.TextColor = Color.Red;
                    isInscriptionAllowed         = false;
                }
                //The password's length musn't be 0
                if (Password.Text.Length == 0)
                {
                    FailedPasswordText.Text      = "Votre mot de passe a une longueur de 0, veuillez rentrer un mot de passe plus long";
                    FailedPasswordText.TextColor = Color.Red;
                    isInscriptionAllowed         = false;
                }
                //The email must contain an @
                if (!(mail.Text.Contains("@")))
                {
                    FailedPasswordText.Text      = "Votre adresse email a un format invalide. (il manque un @)";
                    FailedPasswordText.TextColor = Color.Red;
                    isInscriptionAllowed         = false;
                }
                //The client's email musn't already exist in the database
                if (DatabaseInteraction.CheckIfClientExist(mail.Text))
                {
                    FailedPasswordText.Text      = "Votre adresse mail existe déjà dans la base, veuillez en saisir une nouvelle";
                    FailedPasswordText.TextColor = Color.Red;
                    isInscriptionAllowed         = false;
                }
                //The phone number must be 10 digit long
                if (telephone.Text.Length != 10)
                {
                    FailedPasswordText.Text      = "Votre numéro de téléphone ne fait pas 10 chiffres, veuillez réessayer";
                    FailedPasswordText.TextColor = Color.Red;
                    isInscriptionAllowed         = false;
                }
                //The phone number musn't already exist in the database
                if (DatabaseInteraction.CheckIfPhoneExists(telephone.Text))
                {
                    FailedPasswordText.Text      = "Votre numéro de téléphone existe déjà dans la base, veuillez réessayer";
                    FailedPasswordText.TextColor = Color.Red;
                    isInscriptionAllowed         = false;
                }
            }



            //If the inscription is allowed, we add the new user to the database, and return on the homepage. The user will then have to login
            if (isInscriptionAllowed)
            {
                DatabaseInteraction.AddNewUser(mail.Text, name.Text, surname.Text, telephone.Text, Password.Text);
                await Shell.Current.Navigation.PopAsync(true);

                await Shell.Current.Navigation.PopAsync(true);
            }
        }