示例#1
0
        // Simulates background work that happens behind the splash screen
        async void SimulateStartup()
        {
            Log.Debug(TAG, "Performing some startup work that takes a bit of time.");
            await Task.Delay(1000); // Simulate a bit of startup work.

            Log.Debug(TAG, "Startup work is finished - starting MainActivity.");


            Context        mContext         = Android.App.Application.Context;
            AppPreferences ap               = new AppPreferences(mContext);
            Dictionary <string, string> key = ap.getAccessKey();

            if (key.Count != 0)
            {
                StartActivity(new Intent(Application.Context, typeof(MainActivity)));
            }
            else
            {
                StartActivity(new Intent(Application.Context, typeof(LoginIntent)));
            }
        }
示例#2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            //DECLARACIONES Y ASIGNACIONES

            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.preferences_intent);

            AutoCompleteTextView genresSelector = FindViewById <AutoCompleteTextView>(Resource.Id.buscadorGeneros);

            mContext = Android.App.Application.Context;
            ap       = new AppPreferences(mContext);
            key      = ap.getAccessKey();

            ArrayAdapter <String> adapter;
            ProgressBar           progressbar = FindViewById <ProgressBar>(Resource.Id.genresSearchProgresBar);

            btnSavePreferences = FindViewById <Button>(Resource.Id.btnSavePreferences);

            //EVENTOS

            genresSelector.BeforeTextChanged += (sender, args) =>
            {
                progressbar.Visibility = ViewStates.Visible;
            };

            genresSelector.TextChanged += async(sender, args) =>
            {
                try
                {
                    var currentGenres = await clienteHTTP.FindEntriesAsync("tblCustomerPreferences?$filter=customer_id eq 2");

                    allGenresID.Clear();
                    allGenresName.Clear();
                    var genres = await clienteHTTP.FindEntriesAsync("tblGenres?$filter=substringof('" + args.Text + "', name)");

                    foreach (var genre in genres)
                    {
                        allGenresID.Add(genre["genre_id"].ToString());
                        allGenresName.Add(genre["name"].ToString());
                    }
                    adapter = new ArrayAdapter <String>(this, Resource.Layout.list_item, allGenresName);
                    genresSelector.Adapter = adapter;
                    progressbar.Visibility = ViewStates.Invisible;
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
                }
            };

            genresSelector.ItemClick += (sender, args) =>
            {
                Toast.MakeText(this, genresSelector.Text, ToastLength.Long).Show();
                currentGenresID.Add(allGenresID[allGenresName.FindIndex(x => x.Equals(genresSelector.Text))]);
                currentGenresName.Add(genresSelector.Text);
                adaptador.Add(genresSelector.Text);
                genresSelector.Text = "";
            };

            btnSavePreferences.Click += async(sender, args) =>
            {
                string preferences = string.Join(",", currentGenresID.ToArray());
                var    registry    = new
                {
                    preference_value = preferences,
                    //create_time = Convert.ToDateTime(DateTime.Now),
                    update_time = Convert.ToDateTime(DateTime.Now)
                };

                try
                {
                    var result = await clienteHTTP.For("tblCustomerPreferences").Key(int.Parse(key["userID"]), 9).Set(registry).UpdateEntryAsync();

                    //var result = await clienteHTTP.For("tblCustomerPreferences").Key(suma).Set(registry).UpdateEntryAsync();
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
                }
            };
        }
示例#3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.login_Intent);

            Button   loginButton    = FindViewById <Button>(Resource.Id.btnLogin);
            Button   registerButton = FindViewById <Button>(Resource.Id.btnRegister);
            TextView txtUsername    = FindViewById <TextView>(Resource.Id.txtUsername);
            TextView txtPassword    = FindViewById <TextView>(Resource.Id.txtPassword);
            string   url            = "http://192.168.0.111/culturalcities/webservice/";

            //string url = "http://192.168.0.111:44322/webservice/";

            loginButton.Click += async(sender, args) =>
            {
                try
                {
                    var clienteHTTP = new ODataClient(url);
                    if (string.IsNullOrWhiteSpace(txtUsername.Text) || string.IsNullOrWhiteSpace(txtPassword.Text))
                    {
                        throw new Exception("Username or Password cannot be blank or just spaces...");
                    }
                    var user = await clienteHTTP.FindEntriesAsync("tblCustomers?$filter=username eq '" + txtUsername.Text.Trim() + "'");

                    if (user.Count() != 1)
                    {
                        Toast.MakeText(this, "Fallo la autenticación o el usuario es incorrecto", ToastLength.Long).Show();
                        return;
                    }
                    foreach (var usuario in user)
                    {
                        if (usuario["password"].ToString().Trim() == txtPassword.Text.Trim())
                        {
                            var userPreferences = await clienteHTTP.FindEntriesAsync("tblCustomerPreferences?" +
                                                                                     "$select=tblPreferenceValue/preference_name,preference_value&" +
                                                                                     "$filter=customer_id+eq+" + usuario["customer_id"] + "&" +
                                                                                     "$expand=tblPreferenceValue");

                            var prefNameDict = new Dictionary <string, object>();
                            var prefName     = "";
                            var prefValue    = "";
                            foreach (var preference in userPreferences)
                            {
                                prefValue    = preference["preference_value"].ToString();
                                prefNameDict = (Dictionary <string, object>)preference["tblPreferenceValue"];
                                prefName     = prefNameDict["preference_name"].ToString();
                            }


                            Context        mContext           = Android.App.Application.Context;
                            AppPreferences ap                 = new AppPreferences(mContext);
                            Dictionary <string, string> prefs = new Dictionary <string, string>
                            {
                                { "username", txtUsername.Text },
                                { "userid", usuario["customer_id"].ToString() }
                            };
                            ap.saveAccessKey(prefs);

                            //Usuario correcto
                            Toast.MakeText(this, "Login succesful", ToastLength.Long).Show();
                            StartActivity(new Intent(Application.Context, typeof(MainActivity)));
                        }
                        else
                        {
                            //Usuario incorrecto
                            Toast.MakeText(this, "Login failed", ToastLength.Long).Show();
                        }
                    }
                }
                catch (Exception ex)
                {
                    string nombreArchivo = "BaseFile.txt";
                    string ruta          = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                    string rutaCompleta  = Path.Combine(ruta, nombreArchivo);

                    using (var writer = File.CreateText(rutaCompleta))
                    {
                        await writer.WriteLineAsync(ex.ToString());
                    }
                    Toast.MakeText(this, rutaCompleta /*ex.Message*/, ToastLength.Long).Show();
                }
            };

            registerButton.Click += (sender, args) =>
            {
                StartActivity(new Intent(this, typeof(CustomerRegistration_tblCustomer)));
            };

            txtPassword.EditorAction += (sender, args) =>
            {
                if (args.ActionId == ImeAction.Send)
                {
                    loginButton.PerformClick();
                }
                else
                {
                    args.Handled = false;
                }
            };
        }