Exemple #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.profile);
            Android.Widget.Toolbar toolbar = FindViewById <Android.Widget.Toolbar>(Resource.Id.toolbarHomePage);
            adresa   = FindViewById <TextView>(Resource.Id.adresa);
            oib      = FindViewById <TextView>(Resource.Id.oib);
            email    = FindViewById <TextView>(Resource.Id.email);
            phone    = FindViewById <TextView>(Resource.Id.phone);
            username = FindViewById <TextView>(Resource.Id.username);

            SetActionBar(toolbar);
            ActionBar.Title = "Korisnički podaci";
            sifraDjelatnika = localUsername.GetString("sifraDjelatnika", null);
            user            = db.Query <KE_DJELATNICI>(
                "SELECT * " +
                "FROM KE_DJELATNICI " +
                "WHERE KE_MBR = ?", sifraDjelatnika).FirstOrDefault();

            username.Text = user.KE_IME + " " + user.KE_PREZIME;
            adresa.Text   = user.KE_ADRESA + ", " + user.KE_POSTA + ", " + user.KE_MJESTO;
            email.Text    = user.KE_EMAIL;
            oib.Text      = user.KE_OIB;
            phone.Text    = user.KE_MOBITEL;
        }
Exemple #2
0
        public async void LoginBtn_Click(object sender, EventArgs args)
        {
            EnableElements(false);

            if (String.IsNullOrEmpty(usernameInput.Text) || String.IsNullOrEmpty(passwordInput.Text))
            {
                loadingLayout.Visibility = Android.Views.ViewStates.Gone;


                if (String.IsNullOrEmpty(usernameInput.Text))
                {
                    errMessage.Visibility = Android.Views.ViewStates.Visible;
                    errMessage.Text       = "Unesite korisničko ime!";
                    usernameInput.RequestFocus();
                    return;
                }
                else
                {
                    errMessage.Visibility = Android.Views.ViewStates.Invisible;
                }

                if (String.IsNullOrEmpty(passwordInput.Text))
                {
                    errMessage.Visibility = Android.Views.ViewStates.Visible;
                    errMessage.Text       = "Unesite lozinku!";
                    passwordInput.RequestFocus();
                }
                else
                {
                    errMessage.Visibility = Android.Views.ViewStates.Invisible;
                }

                EnableElements(true);
            }
            else
            {
                //ako korisnik nema pristu internetu onda provjeri lokalno
                List <DID_DjelatnikUsername> user = db.Query <DID_DjelatnikUsername>(
                    "SELECT * " +
                    "FROM DID_DjelatnikUsername " +
                    "WHERE Username = ?", usernameInput.Text);

                if (user.Any())
                {
                    if (SecurePasswordHasher.Verify(passwordInput.Text, user.FirstOrDefault().Password))
                    {
                        // Ako je prvo pokretanje aplikacije skini maticne podatke sa servera
                        if (localUsername.GetBoolean("prvoPokretanje", false))
                        {
                            RunOnUiThread(() =>
                            {
                                flag = true;
                                loadingLayout.Visibility = Android.Views.ViewStates.Visible;
                            });

                            SyncDataSend = new DeratizacijaSyncData(user.FirstOrDefault().Username, user.FirstOrDefault().Password);
                            await Sinkornizacija();
                        }

                        KE_DJELATNICI djelatnik = db.Query <KE_DJELATNICI>(
                            "SELECT * " +
                            "FROM KE_DJELATNICI " +
                            "WHERE KE_MBR = ?", user.FirstOrDefault().Djelatnik).FirstOrDefault();

                        db.DeleteAll <RememberCredentials>();

                        if (zapamtiPrijavu.Checked)
                        {
                            db.Query <RememberCredentials>(
                                "INSERT INTO RememberCredentials (" +
                                "Username, " +
                                "Password)" +
                                "VALUES (?, ?)",
                                usernameInput.Text,
                                passwordInput.Text);
                        }

                        usernameEdit.PutString("username", user.FirstOrDefault().Username);
                        usernameEdit.PutString("nazivDjelatnika", djelatnik.KE_IME + ' ' + djelatnik.KE_PREZIME);
                        usernameEdit.PutString("sifraDjelatnika", djelatnik.KE_MBR);
                        usernameEdit.Commit();
                        errMessage.Visibility = Android.Views.ViewStates.Gone;
                        Toast.MakeText(this, "Uspješno ste se prijavili!", ToastLength.Short).Show();
                        Intent intent = new Intent(this, typeof(Activity_Pocetna));
                        StartActivity(intent);
                        Finish();
                        return;
                    }
                    else
                    {
                        EnableElements(true);

                        loadingLayout.Visibility = Android.Views.ViewStates.Gone;
                        errMessage.Text          = "Unesite ispravno korisničko ime i lozinku!";
                        passwordInput.Text       = "";
                        passwordInput.RequestFocus();
                    }
                }
                else
                {
                    EnableElements(true);

                    loadingLayout.Visibility = Android.Views.ViewStates.Gone;
                    errMessage.Visibility    = Android.Views.ViewStates.Visible;
                    errMessage.Text          = "Unesite ispravno korisničko ime i lozinku!";
                    passwordInput.Text       = "";
                    flagPassword             = true;
                    passwordInput.RequestFocus();
                }
            }
        }