예제 #1
0
        //TODO Fix This
        private async void Create_Clicked(object sender, EventArgs e)
        {
            if (created)
            {
                return;
            }
            string n = e_name.Text;
            string p = e_pass.Text;

            if (n != null && p != null)
            {
                if (!(n.Length >= MIN_U_LENGTH && n.Length <= MAX_U_LENGTH))
                {
                    DisplayAlert("Fel", "ID ska vara mellan " + MIN_U_LENGTH
                                 + " och " + MAX_U_LENGTH, "Ok");
                    return;
                }
                if (!(p.Length >= MIN_P_LENGTH && p.Length <= MAX_P_LENGTH))
                {
                    DisplayAlert("Fel", "Lösenordet ska vara mellan " +
                                 MIN_P_LENGTH + " och " + MAX_P_LENGTH, "Ok");
                    return;
                }
                created = true;
                //App.StartLoading("Register");
                //await DBActions.LoadUsers();
                bool found = true;
                foreach (Accounts users in DBActions.accounts)
                {
                    if (users.DUsername.ToLower() == n.ToLower())
                    {
                        found = false;
                        break;
                    }
                }
                if (found)
                {
                    success = await DBActions.Process("adduser", new Accounts
                    {
                        DUsername = n,
                        DPassword = p,
                        DUType    = 0
                    });

                    if (success)
                    {
                        await DBActions.LoadAccounts();
                        await DisplayAlert("Success", "Konto har skapats!", "Ok");

                        Navigation.PopAsync();
                    }
                    else
                    {
                        created = false;
                    }
                }
                else
                {
                    created = false;
                    DisplayAlert("Fel", "Kontot med ID: " + n + " finns redan!", "Ok");
                }
                // App.FinishLoading("Register");
                return;
            }
            else
            {
                DisplayAlert("Fel", "Ange ID och lösenord.", "Ok");
            }
            created = false;
        }
        private async void Button_Create_Clicked(object s, EventArgs a)
        {
            if (created)
            {
                return;
            }
            string n = e_name.Text;
            string p = e_pass.Text;

            if (n != null && p != null)
            {
                if (!(n.Length >= MIN_U_LENGTH && n.Length <= MAX_U_LENGTH))
                {
                    DisplayAlert("Fel", "ID ska vara mellan " + MIN_U_LENGTH
                                 + " och " + MAX_U_LENGTH, "Ok");
                    return;
                }
                if (!(p.Length >= MIN_P_LENGTH && p.Length <= MAX_P_LENGTH))
                {
                    DisplayAlert("Fel", "Lösenordet ska vara mellan " +
                                 MIN_P_LENGTH + " och " + MAX_P_LENGTH, "Ok");
                    return;
                }
                created = true;
                App.StartLoading("Register");
                await DBActions.LoadUsers();

                bool found = true;
                foreach (Admins admin in DBActions.admins)
                {
                    if (admin.ID.ToLower() == n.ToLower())
                    {
                        found = false;
                        break;
                    }
                }
                foreach (Guests guest in DBActions.guests)
                {
                    if (guest.Name.ToLower() == n.ToLower())
                    {
                        found = false;
                        break;
                    }
                }
                if (found)
                {
                    success = await DBActions.Process("adduser", new Guests {
                        Name = n, Password = p
                    });

                    if (success)
                    {
                        await DBActions.LoadAccounts();

                        PlaySuccess();
                    }
                    else
                    {
                        created = false;
                    }
                }
                else
                {
                    an.Pause();
                    an.IsVisible = false;
                    created      = false;
                    DisplayAlert("Fel", "Kontot med ID: " + n + " finns redan!", "Ok");
                }
                App.FinishLoading("Register");
                return;
            }
            else
            {
                DisplayAlert("Fel", "Ange ID och lösenord.", "Ok");
            }
            created = false;
        }