Ejemplo n.º 1
0
        private async Task Login(string username, string password, string macAddr)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            bool loginResult = await serviceManager.VerifyLogin(username, password, macAddr).ConfigureAwait(false);

            sw.Stop();

            AndHUD.Shared.Dismiss(this);

            int elapsed = sw.Elapsed.Seconds;

            if (elapsed <= timeLimit)
            {
                loginCheckCallObserver.Dispose();
                loginCheckCallObserver = null;
            }

            if (loginResult)
            {
                if (Core.Globals.LoginStatus == BL.Enums.LoginStatusType.Success)
                {
                    // Login Success
                    var appPreferences = new AppPreferences(this.ApplicationContext);
                    appPreferences.SaveUsername(username);
                    appPreferences.SavePassword(password);
                    appPreferences.SaveLoginSkipped(false);

                    TransitionToDownload();
                }
                else if (Core.Globals.LoginStatus == BL.Enums.LoginStatusType.LoginError)
                {
                    // Login Failure/Error
                    ShowError();
                }
            }
            else
            {
                RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(this);
                    builder.SetTitle("Error");
                    builder.SetMessage("Something went wrong. Please try it later.");
                    builder.SetPositiveButton("OK", (sender, e) =>
                    {
                    });
                    builder.Show();
                });
            }
        }
Ejemplo n.º 2
0
        private void ListItemClicked(int position)
        {
            Android.Support.V4.App.Fragment fragment = null;
            switch (position)
            {
            case 0:
                this.Title = "Dashboard";
                fragment   = new DashboardFragment();
                break;

            case 1:
                this.Title = "Outlet List";
                fragment   = new OutletListFragment();
                break;

            case 2:
                this.Title = "Unit of Measurement";
                fragment   = new UOMFragment();
                break;

            case 3:
                this.Title = "Synchronization";
                fragment   = new SyncFragment();
                break;

            case 4:
                this.Title = "About";
                fragment   = new AboutFragment();
                break;

            case 5:
                Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(this);
                builder.SetTitle("Confirm");
                builder.SetMessage("Are you sure you want to log out?");
                builder.SetPositiveButton("NO", (sender, e) =>
                {
                });
                builder.SetNegativeButton("YES", (sender, e) =>
                {
                    var appPreferences = new AppPreferences(this.ApplicationContext);
                    appPreferences.SaveUsername("");
                    appPreferences.SavePassword("");
                    appPreferences.SaveMasterDBDownloaded(false);
                    appPreferences.SaveAuditDBDownloaded(false);

                    string masterDBPath = new FileUtil().GetMasterDBPath();
                    if (File.Exists(masterDBPath))
                    {
                        File.Delete(masterDBPath);
                    }

                    string auditDBPath = new FileUtil().GetAuditDBPath();
                    if (File.Exists(auditDBPath))
                    {
                        File.Delete(auditDBPath);
                    }

                    string auditDBBlankPath = new FileUtil().GetAuditDBBlankPath();
                    if (File.Exists(auditDBBlankPath))
                    {
                        File.Delete(auditDBBlankPath);
                    }

                    string tempZipFile = new FileUtil().GetTempZipFileName();
                    if (File.Exists(tempZipFile))
                    {
                        File.Delete(tempZipFile);
                    }

                    string tempDirectoryPath = new FileUtil().GetTempDirectoryPath();
                    string auditZipPath      = System.IO.Path.Combine(tempDirectoryPath, Core.Globals.LoginUsername + ".zip");
                    if (File.Exists(auditZipPath))
                    {
                        File.Delete(auditZipPath);
                    }

                    FileUtil.ClearCache();
                    FileUtil.DeleteCache(this.ApplicationContext);

                    GlobalsAndroid.masterDB = null;

                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    Finish();
                });
                builder.Show();
                return;
            }

            if (!IsFinishing)
            {
                SupportFragmentManager.BeginTransaction()
                .Replace(Resource.Id.content_frame, fragment)
                .CommitAllowingStateLoss();
            }
        }