Browse Source

PRS MOBILE - main page safer loading

Nick-PRSDigital@bitbucket.org 2 years ago
parent
commit
2e4736eb61

+ 20 - 16
prs.mobile/comal.timesheets/Main/MainPage.xaml.cs

@@ -94,25 +94,29 @@ namespace comal.timesheets
         {
         {
             Task.Run(() =>
             Task.Run(() =>
             {
             {
-                var assgn = MainPageUtils.CheckCurrentAssignment();
+                try
+                {
+                    var assgn = MainPageUtils.CheckCurrentAssignment();
 
 
-                if (assgn == null)
-                    return;
+                    if (assgn == null)
+                        return;
 
 
-                Device.BeginInvokeOnMainThread(async () =>
-                {
-                    string chosenOption = await DisplayActionSheet("Continue with current unfinished assignment? (" + assgn.Title + " )", "Cancel", null, "Yes", "No");
-                    switch (chosenOption)
+                    Device.BeginInvokeOnMainThread(async () =>
                     {
                     {
-                        case "Yes":
-                            MainPageUtils.UseCurrentAssignment(assgn);
-                            RefreshJobBtn();
-                            break;
-                        default:
-                            MainPageUtils.Job.OnJobIDChanged += MainPageUtils.OnJobIDChanged;
-                            break;
-                    };
-                });
+                        string chosenOption = await DisplayActionSheet("Continue with current unfinished assignment? (" + assgn.Title + " )", "Cancel", null, "Yes", "No");
+                        switch (chosenOption)
+                        {
+                            case "Yes":
+                                MainPageUtils.UseCurrentAssignment(assgn);
+                                RefreshJobBtn();
+                                break;
+                            default:
+                                MainPageUtils.Job.OnJobIDChanged += MainPageUtils.OnJobIDChanged;
+                                break;
+                        };
+                    });
+                }
+                catch { }
             });
             });
         }
         }
 
 

+ 27 - 15
prs.mobile/comal.timesheets/Main/MainPageUtils.cs

@@ -50,28 +50,40 @@ namespace comal.timesheets
         }
         }
         private static void InitEvents()
         private static void InitEvents()
         {
         {
-            App.GPS.OnLocationFound += LocationFound;
-            App.GPS.OnLocationError += LocationError;
-            App.Bluetooth.OnScanFinished += ScanFinished;
-            App.Data.DataChanged += (s, t, e) => { OnRefreshScreen?.Invoke(); };
-            App.Data.DataRefreshed += () => { OnRefreshScreen?.Invoke(); };
-        }
+            try
+            {
+                App.GPS.OnLocationFound += LocationFound;
+                App.GPS.OnLocationError += LocationError;
+                App.Bluetooth.OnScanFinished += ScanFinished;
+                App.Data.DataChanged += (s, t, e) => { OnRefreshScreen?.Invoke(); };
+                App.Data.DataRefreshed += () => { OnRefreshScreen?.Invoke(); };
+            }
+            catch { }
+            }
 
 
         private static void InitData()
         private static void InitData()
         {
         {
-            GlobalVariables.EmpID = GlobalVariables.GetEmployeeID();
-            GlobalVariables.EmpName = GlobalVariables.GetEmployeeName();
+            try
+            {
+                GlobalVariables.EmpID = GlobalVariables.GetEmployeeID();
+                GlobalVariables.EmpName = GlobalVariables.GetEmployeeName();
 
 
-            App.Data.Employee.ID = GlobalVariables.EmpID;
-            App.Data.Employee.Name = GlobalVariables.EmpName;
+                App.Data.Employee.ID = GlobalVariables.EmpID;
+                App.Data.Employee.Name = GlobalVariables.EmpName;
+            }
+            catch { }
 
 
-            _timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
-            _employee = App.Data.Employee;
-            _jobs = App.Data.Jobs;
+            try
+            {
+                _timesheet = App.Data.TimeSheets?.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
+                _employee = App.Data.Employee;
+                _jobs = App.Data.Jobs;
 
 
-            deviceName = MobileUtils.GetDeviceID();
+                deviceName = MobileUtils.GetDeviceID();
 
 
-            firstLoad = false;
+                firstLoad = false;
+            }
+            catch { }
         }
         }
 
 
         private static void InitTimers()
         private static void InitTimers()