Просмотр исходного кода

PRS MOBILE - refactoring for stability - for iOS testing

Nick-PRSDigital@bitbucket.org 2 лет назад
Родитель
Сommit
621c4c9726

+ 35 - 7
prs.mobile/comal.timesheets/Data Classes/CacheLoader.cs

@@ -24,7 +24,9 @@ namespace comal.timesheets
 
                     if (GlobalVariables.IsJobOnlyEmployee)
                     {
-                        CoreTable table = new Client<JobEmployee>().Query(new Filter<JobEmployee>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID));
+                        CoreTable table = DoJobEmployeeQuery();
+                        while (table == null)
+                            table = DoJobEmployeeQuery();
                         if (!table.Rows.Any())
                             return;
 
@@ -33,8 +35,13 @@ namespace comal.timesheets
                     }
 
                     else
-                        foreach (CoreRow row in DoJobsQuery(AssignFilter()).Rows)
+                    {
+                        CoreTable table = DoJobsQuery(AssignFilter());
+                        while (table == null)
+                            table = DoJobsQuery(AssignFilter());
+                        foreach (CoreRow row in table.Rows)
                             jobShells.Add(CreateJobShell(row));
+                    }
 
                     AssignJobShells(jobShells);
                 }
@@ -43,6 +50,19 @@ namespace comal.timesheets
             });
         }
 
+        private static CoreTable DoJobEmployeeQuery()
+        {
+            try
+            {
+                return new Client<JobEmployee>().Query(new Filter<JobEmployee>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID));
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "DoJobEmployeeQuery()", ex.Message + ex.StackTrace, "CacheLoader");
+                return null;
+            }
+        }
+
         private static void AssignJobShells(List<JobShell> jobShells)
         {
             GlobalVariables.JobShells = jobShells;
@@ -73,11 +93,19 @@ namespace comal.timesheets
 
         private static CoreTable DoJobsQuery(Filter<Job> filter)
         {
-            return new Client<Job>().Query(
-                            filter,
-                            new Columns<Job>(x => x.ID, x => x.Name, x => x.JobNumber, x => x.JobStatus.Description, x => x.Color),
-                            new SortOrder<Job>(x => x.JobNumber)
-                            );
+            try
+            {
+                return new Client<Job>().Query(
+                                filter,
+                                new Columns<Job>(x => x.ID, x => x.Name, x => x.JobNumber, x => x.JobStatus.Description, x => x.Color),
+                                new SortOrder<Job>(x => x.JobNumber)
+                                );
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "DoJobsQuery", ex.Message + ex.StackTrace, "CacheLoader");
+                return null;
+            }
         }
 
         private static JobShell CreateJobShell(CoreRow row)

+ 32 - 11
prs.mobile/comal.timesheets/InOutBoard/StaffStatusPage.xaml.cs

@@ -214,7 +214,12 @@ namespace comal.timesheets
                 ShowLoading();
 
                 CoreTable employees = QueryEmployees();
+                while(employees == null)
+                    employees = QueryEmployees();
+
                 CoreTable timesheets = QueryTimeSheets();
+                while(timesheets == null) 
+                    timesheets = QueryTimeSheets();
 
                 List<StaffStatus> staff = new List<StaffStatus>();
 
@@ -332,20 +337,36 @@ namespace comal.timesheets
 
         private CoreTable QueryEmployees()
         {
-            return new Client<Employee>().Query(
-                    LookupFactory.DefineFilter<Employee>().And
-                    (x => x.Name).IsNotEqualTo("Administrator"),
-                    new Columns<Employee>(x => x.ID, x => x.Name, x => x.Mobile),
-                    new SortOrder<Employee>(x => x.Name)
-                );
+            try
+            {
+                return new Client<Employee>().Query(
+                        LookupFactory.DefineFilter<Employee>().And
+                        (x => x.Name).IsNotEqualTo("Administrator"),
+                        new Columns<Employee>(x => x.ID, x => x.Name, x => x.Mobile),
+                        new SortOrder<Employee>(x => x.Name)
+                    );
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "QueryEmployees()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
+            }
         }
         private CoreTable QueryTimeSheets()
         {
-            return new Client<TimeSheet>().Query(
-                    new Filter<TimeSheet>(x => x.Date).IsEqualTo(DateTime.Today),
-                    new Columns<TimeSheet>(x => x.EmployeeLink.ID, x => x.Start, x => x.Finish, x => x.Address),
-                    new SortOrder<TimeSheet>(x => x.EmployeeLink.ID).ThenBy(x => x.Start)
-                );
+            try
+            {
+                return new Client<TimeSheet>().Query(
+                        new Filter<TimeSheet>(x => x.Date).IsEqualTo(DateTime.Today),
+                        new Columns<TimeSheet>(x => x.EmployeeLink.ID, x => x.Start, x => x.Finish, x => x.Address),
+                        new SortOrder<TimeSheet>(x => x.EmployeeLink.ID).ThenBy(x => x.Start)
+                    );
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "QueryTimeSheets()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
+            }
         }
     }
 }

+ 21 - 14
prs.mobile/comal.timesheets/LiveMaps/LiveMapsTwo.xaml.cs

@@ -136,26 +136,33 @@ namespace comal.timesheets
         }
 
 
-        private async void LoadData()
+        private void LoadData()
         {
             Title = "Live Maps - Loading";
 
-            await Task.Run(() =>
+            Task.Run(() =>
             {
-                if (Application.Current.Properties.ContainsKey(saved))
+                try
                 {
-                    equipmentShellsToDisplay = Application.Current.Properties[saved] as List<EquipmentShell>;
-                    DisplayMarkersFromList();
+                    if (Application.Current.Properties.ContainsKey(saved))
+                    {
+                        equipmentShellsToDisplay = Application.Current.Properties[saved] as List<EquipmentShell>;
+                        DisplayMarkersFromList();
+                    }
+                    LoadGroups();
+                    LoadEquipment();
+                    LoadExpanders();
+                    double width = (DeviceWidth / 10) * 4;
+                    Thread.Sleep(300);
+                    Device.BeginInvokeOnMainThread(async () =>
+                    {
+                        jobsBtn.RotateTo(360, 1000);
+                    });
+                }
+                catch (Exception ex)
+                {
+                    var log = new MobileLogging(LogType.Query, " LoadData()", ex.Message + ex.StackTrace, this.GetType().Name);
                 }
-                LoadGroups();
-                LoadEquipment();
-                LoadExpanders();
-                double width = (DeviceWidth / 10) * 4;
-                Thread.Sleep(300);
-                Device.BeginInvokeOnMainThread(async () =>
-                {
-                    jobsBtn.RotateTo(360, 1000);
-                });
             });
         }
 

+ 150 - 100
prs.mobile/comal.timesheets/Main/MainPage.xaml.cs

@@ -47,7 +47,6 @@ namespace comal.timesheets
 
                 LoadCacheLists();
 
-                //if (GlobalVariables.EmpID == Guid.Parse("40f6ccd9-5272-4b1a-99bf-de7542205aac"))
                 RunCustomScript();
             }
             catch (Exception e) { }
@@ -1172,19 +1171,12 @@ namespace comal.timesheets
             GlobalVariables.ProductsLoaded = false;
             GlobalVariables.JobsLoaded = false;
             GlobalVariables.GetXamarinWidth();
+
             CacheLoader.LoadJobs();
             LoadEmployeeShells();
-
-            //spread out loading
-            Task.Run(() =>
-            {
-                Thread.Sleep(1000);
-
-                LoadCompanyDevices();
-                LoadBlueToothAddresses();
-                Thread.Sleep(1000);
-                LoadProducts();
-            });
+            LoadCompanyDevices();
+            LoadBlueToothAddresses();
+            LoadProducts();
 
             //LoadHRToDos(); to be uncommented when ready for roll out
         }
@@ -1196,13 +1188,9 @@ namespace comal.timesheets
                 if (!string.IsNullOrWhiteSpace(MainPageUtils.deviceName) && MainPageUtils.deviceName != "unknown")
                 {
                     List<Equipment> companyDevices = new List<Equipment>();
-                    CoreTable table = new Client<Equipment>().Query
-                    (
-                        new Filter<Equipment>(x => x.GroupLink.Code).IsEqualTo("DEVICE"),
-                        new Columns<Equipment>(
-                            x => x.TrackerLink.DeviceID
-                            )
-                        );
+                    CoreTable table = DoEquipmentQuery();
+                    while (table == null)
+                        table = DoEquipmentQuery();
                     if (table.Rows.Any())
                     {
                         foreach (CoreRow row in table.Rows)
@@ -1218,81 +1206,142 @@ namespace comal.timesheets
             });
         }
 
+        private CoreTable DoEquipmentQuery()
+        {
+            try
+            {
+                return new Client<Equipment>().Query
+                        (
+                            new Filter<Equipment>(x => x.GroupLink.Code).IsEqualTo("DEVICE"),
+                            new Columns<Equipment>(
+                                x => x.TrackerLink.DeviceID
+                                )
+                            );
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "DoEquipmentQuery()", ex.Message + ex.StackTrace, "CacheLoader");
+                return null;
+            }
+        }
+
         private void LoadEmployeeShells()
         {
             Task.Run(() =>
             {
                 try
                 {
-                    List<EmployeeShell> employeeShells = new List<EmployeeShell>();
-                    List<EmployeeShell> teamEmployeeShells = new List<EmployeeShell>();
-
-                    MultiQuery query = new MultiQuery();
+                    AddEmployees();
+                    AddTeams();
+                    AddTeamEmployees();
+                }
+                catch (Exception ex)
+                {
+                    var log = new MobileLogging(LogType.Query, "LoadEmployeeShells()", ex.Message + ex.StackTrace, this.GetType().Name);
+                }
+            });
+        }
 
-                    query.Add<Employee>(
-                        LookupFactory.DefineFilter<Employee>(),
-                        new Columns<Employee>(x => x.ID)
-                            .Add(x => x.Code)
-                            .Add(x => x.Name),
-                        LookupFactory.DefineSort<Employee>()
-                    );
+        private void AddEmployees()
+        {
+            List<EmployeeShell> employeeShells = new List<EmployeeShell>();
+            CoreTable emps = DoEmployeeQuery();
+            while (emps == null)
+                emps = DoEmployeeQuery();
 
-                    query.Add<Team>(
-                        LookupFactory.DefineFilter<Team>(),
-                        new Columns<Team>(x => x.Name),
-                        new SortOrder<Team>(x => x.Name)
-                    );
-
-                    query.Add<EmployeeTeam>(
-                        LookupFactory.DefineFilter<EmployeeTeam>(),
-                        new Columns<EmployeeTeam>(x => x.EmployeeLink.ID)
-                            .Add(x => x.EmployeeLink.Code)
-                            .Add(x => x.EmployeeLink.Name)
-                            .Add(x => x.TeamLink.Name),
-                        new SortOrder<EmployeeTeam>(x => x.EmployeeLink.Name)
-                    );
-
-                    query.Query();
-
-                    CoreTable emps = query.Get<Employee>();
-                    foreach (var row in emps.Rows)
+            foreach (var row in emps.Rows)
+            {
+                employeeShells.Add(
+                    new EmployeeShell()
                     {
-                        employeeShells.Add(
-                            new EmployeeShell()
-                            {
-                                ID = row.Get<Employee, Guid>(x => x.ID),
-                                Code = row.Get<Employee, String>(x => x.Code),
-                                Name = row.Get<Employee, String>(x => x.Name),
-                                TeamName = "All Staff"
-                            }
-                        );
+                        ID = row.Get<Employee, Guid>(x => x.ID),
+                        Code = row.Get<Employee, String>(x => x.Code),
+                        Name = row.Get<Employee, String>(x => x.Name),
+                        TeamName = "All Staff"
                     }
+                );
+            }
+            GlobalVariables.EmployeeShells = employeeShells;
+        }
 
-                    GlobalVariables.TeamNames = query.Get<Team>().Rows.Select(r => r.Get<Team, String>(c => c.Name)).ToList();
+        private void AddTeamEmployees()
+        {
+            List<EmployeeShell> teamEmployeeShells = new List<EmployeeShell>();
+            CoreTable members = DoEmployeeTeamQuery();
+            while (members == null)
+                members = DoEmployeeTeamQuery();
 
-                    CoreTable members = query.Get<EmployeeTeam>();
-                    foreach (var row in members.Rows)
+            foreach (var row in members.Rows)
+            {
+                teamEmployeeShells.Add(
+                    new EmployeeShell()
                     {
-                        teamEmployeeShells.Add(
-                            new EmployeeShell()
-                            {
-                                ID = row.Get<EmployeeTeam, Guid>(x => x.EmployeeLink.ID),
-                                Code = row.Get<EmployeeTeam, String>(x => x.EmployeeLink.Code),
-                                Name = row.Get<EmployeeTeam, String>(x => x.EmployeeLink.Name),
-                                TeamName = row.Get<EmployeeTeam, String>(x => x.TeamLink.Name)
-                            }
-                        );
+                        ID = row.Get<EmployeeTeam, Guid>(x => x.EmployeeLink.ID),
+                        Code = row.Get<EmployeeTeam, String>(x => x.EmployeeLink.Code),
+                        Name = row.Get<EmployeeTeam, String>(x => x.EmployeeLink.Name),
+                        TeamName = row.Get<EmployeeTeam, String>(x => x.TeamLink.Name)
                     }
+                );
+            }
+            GlobalVariables.TeamEmployeeShells = teamEmployeeShells;
+        }
 
-                    GlobalVariables.EmployeeShells = employeeShells;
-                    GlobalVariables.TeamEmployeeShells = teamEmployeeShells;
-                }
-                catch (Exception ex)
-                {
-                    var log = new MobileLogging(LogType.Query, "LoadEmployeeShells()", ex.Message + ex.StackTrace, this.GetType().Name);
-                }
-            });
+        private void AddTeams()
+        {
+            var teamsTable = DoTeamsQuery();
+            while (teamsTable == null)
+                teamsTable = DoTeamsQuery();
 
+            GlobalVariables.TeamNames = teamsTable.Rows.Select(r => r.Get<Team, String>(c => c.Name)).ToList();
+        }
+
+        private CoreTable DoEmployeeQuery()
+        {
+            try
+            {
+                return new Client<Employee>().Query(
+                    LookupFactory.DefineFilter<Employee>(),
+                    new Columns<Employee>(x => x.ID, x => x.Code, x => x.Name),
+                    LookupFactory.DefineSort<Employee>());
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "DoEmployeeQuery()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
+            }
+        }
+
+        private CoreTable DoTeamsQuery()
+        {
+            try
+            {
+                return new Client<Team>().Query(LookupFactory.DefineFilter<Team>(),
+                        new Columns<Team>(x => x.Name),
+                        new SortOrder<Team>(x => x.Name));
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "DoTeamsQuery()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
+            }
+        }
+
+        private CoreTable DoEmployeeTeamQuery()
+        {
+            try
+            {
+                return new Client<EmployeeTeam>().Query(LookupFactory.DefineFilter<EmployeeTeam>(),
+                            new Columns<EmployeeTeam>(x => x.EmployeeLink.ID)
+                                .Add(x => x.EmployeeLink.Code)
+                                .Add(x => x.EmployeeLink.Name)
+                                .Add(x => x.TeamLink.Name),
+                            new SortOrder<EmployeeTeam>(x => x.EmployeeLink.Name));
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "DoTeamsQuery()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
+            }
         }
 
         private async void LoadHRToDos()
@@ -1330,39 +1379,40 @@ namespace comal.timesheets
 
         private void LoadProducts()
         {
-            try
+            Task.Run(() =>
             {
-                Task.Run(() =>
-                {
-                    ProductsLoader productsLoader = new ProductsLoader();
-                });
-            }
-            catch { }
+                ProductsLoader productsLoader = new ProductsLoader();
+            });
         }
 
         private async void LoadBlueToothAddresses()
         {
-            try
+            Task.Run(() =>
             {
-                //if (bSharedDevice)
-                //    return;
-                await Task.Run(() =>
+                GlobalVariables.GPSTrackerCache = new List<GPSTracker>();
+                CoreTable table = QueryGPSTrackers();
+                while (table == null)
+                    table = QueryGPSTrackers();
+                foreach (CoreRow row in table.Rows)
                 {
-                    GlobalVariables.GPSTrackerCache = new List<GPSTracker>();
-                    CoreTable table = new Client<GPSTracker>().Query(new Filter<GPSTracker>(x => x.Type.Description).Contains("Kontakt"));
-                    foreach (CoreRow row in table.Rows)
-                    {
-                        GPSTracker tracker = row.ToObject<GPSTracker>();
-                        GlobalVariables.GPSTrackerCache.Add(tracker);
-                        App.Bluetooth.KnownBlueToothMACAddresses.Add(tracker.DeviceID);
-                    }
-                });
+                    GPSTracker tracker = row.ToObject<GPSTracker>();
+                    GlobalVariables.GPSTrackerCache.Add(tracker);
+                    App.Bluetooth.KnownBlueToothMACAddresses.Add(tracker.DeviceID);
+                }
+            });
+        }
+
+        private CoreTable QueryGPSTrackers()
+        {
+            try
+            {
+                return new Client<GPSTracker>().Query(new Filter<GPSTracker>(x => x.Type.Description).Contains("Kontakt"));
             }
             catch (Exception ex)
             {
-                var log = new MobileLogging(LogType.Query, "LoadBlueToothAddresses()", ex.Message + ex.StackTrace, this.GetType().Name);
+                var log = new MobileLogging(LogType.Query, "QueryGPSTrackers()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
             }
-
         }
         #endregion
         #endregion

+ 22 - 6
prs.mobile/comal.timesheets/Main/MainPageUtils.cs

@@ -169,21 +169,37 @@ namespace comal.timesheets
             Thread.Sleep(5000);
             StartAssignmentTimer();
 
-            CoreTable table = new Client<Assignment>().Query(
+            CoreTable table = QueryAssignment();
+            while (table == null)
+                table = QueryAssignment();
+
+            if (!table.Rows.Any())
+            {
+                Job.OnJobIDChanged += OnJobIDChanged;
+                return null;
+            }
+            else
+                return table.Rows.LastOrDefault().ToObject<Assignment>();
+
+        }
+
+        private static CoreTable QueryAssignment()
+        {
+            try
+            {
+                return new Client<Assignment>().Query(
                      new Filter<Assignment>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID)
                      .And(x => x.Date).IsEqualTo(DateTime.Today.Date)
                      .And(x => x.Completed).IsEqualTo(null)
                      .And(x => x.Booked.Finish).IsEqualTo(null),
                      null,
                      new SortOrder<Assignment>(x => x.Actual.Start, SortDirection.Ascending));
-            if (!table.Rows.Any())
+            }
+            catch (Exception ex)
             {
-                Job.OnJobIDChanged += OnJobIDChanged;
+                var log = new MobileLogging(LogType.Query, "QueryAssignment()", ex.Message + ex.StackTrace, "MainPageUtils");
                 return null;
             }
-            else
-                return table.Rows.LastOrDefault().ToObject<Assignment>();
-
         }
 
         private static void StartAssignmentTimer()

+ 92 - 12
prs.mobile/comal.timesheets/StoreRequis/StoreRequiConfirmationPage.xaml.cs

@@ -150,11 +150,9 @@ namespace comal.timesheets.StoreRequis
         {
             if (requisition.Documents != 0)
             {
-                var table = new Client<RequisitionDocument>().Query(
-                new Filter<RequisitionDocument>(x => x.EntityLink.ID).IsEqualTo(requisition.ID),
-                new Columns<RequisitionDocument>(x => x.DocumentLink.ID),
-                null
-                );
+                var table = QueryPhotos();
+                while (table == null)
+                    table = QueryPhotos();
                 if (table.Rows.Count != 0)
                 {
                     foreach (var row in table.Rows)
@@ -198,6 +196,23 @@ namespace comal.timesheets.StoreRequis
 
             }
         }
+
+        private CoreTable QueryPhotos()
+        {
+            try
+            {
+                return new Client<RequisitionDocument>().Query(
+                new Filter<RequisitionDocument>(x => x.EntityLink.ID).IsEqualTo(requisition.ID),
+                new Columns<RequisitionDocument>(x => x.DocumentLink.ID),
+                null
+                );
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "QueryPhotos()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
+            }
+        }
         #endregion
 
         #region Selection
@@ -411,7 +426,7 @@ namespace comal.timesheets.StoreRequis
                 if (isNewRequest)
                 {
                     requisition.Request = notesEdt.Text;
-                    new Client<Requisition>().Save(requisition, "Created on Mobile Device");
+                    DoSaveRequi(requisition);
                     DisplayAlert("Success", "Requisition " + requisition.Number + " Created", "Ok");
                 }
                 else
@@ -440,12 +455,25 @@ namespace comal.timesheets.StoreRequis
                 }
             }
         }
+        private Requisition DoSaveRequi(Requisition requisition)
+        {
+            try
+            {
+                new Client<Requisition>().Save(requisition, "Created on Mobile Device");
+                return requisition;
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Save, "DoSaveRequi()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return DoSaveRequi(requisition);
+            }
+        }
 
         private void SaveRequi()
         {
             requisition.Filled = DateTime.Now;
             requisition.Notes = new string[] { notesEdt.Text };
-            new Client<Requisition>().Save(requisition, "Saved requi on mobile device");
+            DoSaveRequi(requisition);
         }
 
         private void SaveItems()
@@ -465,7 +493,7 @@ namespace comal.timesheets.StoreRequis
                     }
                     if (toDelete.Count > 0)
                     {
-                        new Client<RequisitionItem>().Delete(toDelete, "Updated from mobile device");
+                        DoDeleteRequiItems(toDelete);
                     }
                 }
             });
@@ -483,7 +511,7 @@ namespace comal.timesheets.StoreRequis
                 item.Description = requiItemShell.ProductName;
                 item.Code = requiItemShell.ProductCode;
                 item.Job.ID = requiItemShell.JobID;
-                item.Style.ID = requiItemShell.StyleID;            
+                item.Style.ID = requiItemShell.StyleID;
 
                 item.Picked = item.Picked == DateTime.MinValue ? DateTime.Now : item.Picked;
 
@@ -507,7 +535,33 @@ namespace comal.timesheets.StoreRequis
 
                 toSave.Add(item);
             }
-            new Client<RequisitionItem>().Save(toSave, "Saved requi on mobile device");
+            DoSaveRequiItems(toSave);
+        }
+
+        private void DoDeleteRequiItems(List<RequisitionItem> toDelete)
+        {
+            try
+            {
+                new Client<RequisitionItem>().Delete(toDelete, "Updated from mobile device");
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Delete, "DoDeleteRequiItems()", ex.Message + ex.StackTrace, this.GetType().Name);
+                DoDeleteRequiItems(toDelete);
+            }
+        }
+
+        private void DoSaveRequiItems(List<RequisitionItem> toSave)
+        {
+            try
+            {
+                new Client<RequisitionItem>().Save(toSave, "Saved requi on mobile device");
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Save, "DoSaveRequiItems", ex.Message + ex.StackTrace, this.GetType().Name);
+                DoSaveRequiItems(toSave);
+            }
         }
 
         private void SavePhotos()
@@ -516,7 +570,7 @@ namespace comal.timesheets.StoreRequis
             {
                 if (imagesDocuments.Count != 0)
                 {
-                    new Client<Document>().Save(imagesDocuments.Values, "Photo Taken on Mobile device Requis module");
+                    DoSaveDocuments();
                     List<RequisitionDocument> newRequiDocuments = new List<RequisitionDocument>();
                     foreach (Document doc in imagesDocuments.Values)
                     {
@@ -526,11 +580,37 @@ namespace comal.timesheets.StoreRequis
                         requiDocument.DocumentLink.FileName = doc.FileName;
                         newRequiDocuments.Add(requiDocument);
                     }
-                    new Client<RequisitionDocument>().Save(newRequiDocuments, "Photo Taken on Mobile device Requis module");
+                    DoSaveRequiDocuments(newRequiDocuments);
                 }
             });
         }
 
+        private void DoSaveDocuments()
+        {
+            try
+            {
+                new Client<Document>().Save(imagesDocuments.Values, "Photo Taken on Mobile device Requis module");
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Save, "DoSaveDocuments()", ex.Message + ex.StackTrace, this.GetType().Name);
+                DoSaveDocuments();
+            }
+        }
+
+        private void DoSaveRequiDocuments(List<RequisitionDocument> newRequiDocuments)
+        {
+            try
+            {
+                new Client<RequisitionDocument>().Save(newRequiDocuments, "Photo Taken on Mobile device Requis module");
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Save, "DoSaveRequiDocuments", ex.Message + ex.StackTrace, this.GetType().Name);
+                DoSaveRequiDocuments(newRequiDocuments);
+            }
+        }
+
         private bool CheckSaveOk()
         {
             bool bOK = false;

+ 39 - 32
prs.mobile/comal.timesheets/StoreRequis/StoreRequiList.xaml.cs

@@ -20,7 +20,6 @@ namespace comal.timesheets.StoreRequis
         public StoreRequiList()
         {
             InitializeComponent();
-            //LoadHoldingsCache();
             HoldingsLoaded = true;
             if (Device.RuntimePlatform.Equals(Device.iOS))
             {
@@ -41,43 +40,25 @@ namespace comal.timesheets.StoreRequis
             base.OnAppearing();
         }
 
-        private async void LoadList()
+        private void LoadList()
         {
-            await Task.Run(() =>
+            Task.Run(() =>
             {
                 requiShells.Clear();
-                CoreTable table = new Client<Requisition>().Query(
-                        new Filter<Requisition>(x => x.Filled).IsEqualTo(DateTime.MinValue),
-                        new Columns<Requisition>(
-                            x => x.ID, //0
-                            x => x.Number, //1
-                            x => x.Due, //2
-                            x => x.RequestedBy.Name, //3
-                            x => x.JobLink.JobNumber, //4
-                            x => x.JobLink.Name, //5
-                            x => x.Request, //6
-                            x => x.Notes
-                            ),
-                        new SortOrder<Requisition>(x => x.Due)
-                    );
+
+                CoreTable table = DoRequisitionQuery();
+                while (table == null)
+                    table = DoRequisitionQuery();
+
                 foreach (var row in table.Rows)
                 {
-                    List<object> list = row.Values;
-                    if (list[0] == null) { list[0] = Guid.Empty; } //0
-                    if (list[1] == null) { list[1] = 0; } //1
-                    if (list[2] == null) { list[2] = DateTime.MinValue; } //2
-                    if (list[3] == null) { list[3] = ""; } //3
-                    if (list[4] == null) { list[4] = ""; } //4
-                    if (list[5] == null) { list[5] = ""; } //5
-                    if (list[6] == null) { list[6] = ""; } //6
-
                     RequiShell requiShell = new RequiShell();
-                    requiShell.ID = Guid.Parse(list[0].ToString());
-                    requiShell.Number = "No. " + list[1].ToString();
-                    requiShell.Due = "Due " + DateTime.Parse(list[2].ToString()).ToString("dd MMM yy");
-                    requiShell.Contact = "Contact: " + list[3].ToString();
-                    requiShell.Job = "(" + list[4].ToString() + ") " + list[5].ToString();
-                    requiShell.Request = list[6].ToString();
+                    requiShell.ID = row.Get<Requisition, Guid>(x => x.ID);
+                    requiShell.Number = "No. " + row.Get<Requisition,int>(x => x.Number);
+                    requiShell.Due = "Due " + row.Get<Requisition, DateTime>(x => x.Due).ToString("dd MMM yy");
+                    requiShell.Contact = "Contact: " + row.Get<Requisition, string>(x => x.RequestedBy.Name);
+                    requiShell.Job = "(" + row.Get<Requisition, string>(x => x.JobLink.JobNumber) + ") " + row.Get<Requisition, string>(x => x.JobLink.Name);
+                    requiShell.Request = row.Get<Requisition, string>(x => x.Request);
                     string notes = CheckNotes(row.Get<Requisition, string[]>(x => x.Notes));
                     requiShell.Request = requiShell.Request + System.Environment.NewLine + notes;
 
@@ -92,6 +73,32 @@ namespace comal.timesheets.StoreRequis
             });
         }
 
+        private CoreTable DoRequisitionQuery()
+        {
+            try
+            {
+                return new Client<Requisition>().Query(
+                            new Filter<Requisition>(x => x.Filled).IsEqualTo(DateTime.MinValue),
+                            new Columns<Requisition>(
+                                x => x.ID, 
+                                x => x.Number,
+                                x => x.Due,
+                                x => x.RequestedBy.Name,
+                                x => x.JobLink.JobNumber,
+                                x => x.JobLink.Name,
+                                x => x.Request,
+                                x => x.Notes
+                                ),
+                            new SortOrder<Requisition>(x => x.Due)
+                        );
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "DoRequisitionQuery()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
+            }
+        }
+
         private string CheckNotes(string[] notes)
         {
             string combinednotes = "----------" + System.Environment.NewLine + "NOTES: " + System.Environment.NewLine;

+ 88 - 47
prs.mobile/comal.timesheets/StoreRequis/StoreRequiScannerPage.xaml.cs

@@ -107,9 +107,10 @@ namespace comal.timesheets
         {
             await Task.Run(() =>
             {
-                requisition = new Client<Requisition>().Query(
-                       new Filter<Requisition>(x => x.ID).IsEqualTo(requisition.ID)
-                       ).Rows.FirstOrDefault().ToObject<Requisition>();
+                CoreTable table = QueryRequi();
+                while(table == null)
+                    table = QueryRequi();
+                requisition = table.Rows.FirstOrDefault().ToObject<Requisition>();
 
                 string notes = CheckNotes(requisition.Notes);
 
@@ -130,20 +131,9 @@ namespace comal.timesheets
 
             await Task.Run(() =>
             {
-                CoreTable table = new Client<RequisitionItem>().Query
-                   (
-                   new Filter<RequisitionItem>(x => x.RequisitionLink.ID).IsEqualTo(requisition.ID),
-                   new Columns<RequisitionItem>(
-                       x => x.ID,
-                       x => x.Product.ID,
-                       x => x.Product.Name,
-                       x => x.Product.Code,
-                       x => x.Quantity,
-                       x => x.Location.ID,
-                       x => x.Location.Description,
-                       x => x.Picked
-                       )
-                   );
+                CoreTable table = QueryRequiItems();
+                while(table == null)
+                    table = QueryRequiItems();
                 if (table.Rows.Any())
                 {
                     Device.BeginInvokeOnMainThread(() => { saveBtn.IsVisible = true; });
@@ -179,6 +169,47 @@ namespace comal.timesheets
             });
         }
 
+        private CoreTable QueryRequi()
+        {
+            try
+            {
+                return new Client<Requisition>().Query(
+                       new Filter<Requisition>(x => x.ID).IsEqualTo(requisition.ID)
+                       );
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "QueryRequi()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
+            }
+        }
+
+        private CoreTable QueryRequiItems()
+        {
+            try 
+            {
+            return new Client<RequisitionItem>().Query
+                   (
+                   new Filter<RequisitionItem>(x => x.RequisitionLink.ID).IsEqualTo(requisition.ID),
+                   new Columns<RequisitionItem>(
+                       x => x.ID,
+                       x => x.Product.ID,
+                       x => x.Product.Name,
+                       x => x.Product.Code,
+                       x => x.Quantity,
+                       x => x.Location.ID,
+                       x => x.Location.Description,
+                       x => x.Picked
+                       )
+                   );
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "QueryRequiItems()", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
+            }
+        }
+
         private string CheckNotes(string[] notes)
         {
             string combinednotes = "----------" + System.Environment.NewLine + "NOTES: " + System.Environment.NewLine;
@@ -350,6 +381,8 @@ namespace comal.timesheets
             List<StoreRequiIHoldingShell> list = new List<StoreRequiIHoldingShell>();
 
             CoreTable table = DoHoldingsQuery(productID);
+            while (table == null)
+                table = DoHoldingsQuery(productID);
 
             foreach (CoreRow row in table.Rows)
             {
@@ -363,36 +396,44 @@ namespace comal.timesheets
 
         private CoreTable DoHoldingsQuery(Guid productID)
         {
-            return new Client<StockHolding>().Query(
-                new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(productID),
-                new Columns<StockHolding>(
-                    x => x.ID,
-                    x => x.Product.ID,
-                    x => x.Location.ID,
-                    x => x.Location.Description,
-                    x => x.Units,
-                    x => x.Job.ID,
-                    x => x.Job.JobNumber,
-                    x => x.Job.Name,
-                    x => x.Style.ID,
-                    x => x.Style.Code,
-                    x => x.Style.Description,
-                    x => x.Dimensions.Unit.ID,
-                    x => x.Dimensions.Unit.HasQuantity,
-                    x => x.Dimensions.Unit.HasLength,
-                    x => x.Dimensions.Unit.HasHeight,
-                    x => x.Dimensions.Unit.HasWeight,
-                    x => x.Dimensions.Unit.HasWidth,
-                    x => x.Dimensions.Quantity,
-                    x => x.Dimensions.Length,
-                    x => x.Dimensions.Height,
-                    x => x.Dimensions.Weight,
-                    x => x.Dimensions.Width,
-                    x => x.Dimensions.Unit.Format,
-                    x => x.Dimensions.Unit.Formula,
-                    x => x.Dimensions.UnitSize
-                    )
-                );
+            try
+            {
+                return new Client<StockHolding>().Query(
+                    new Filter<StockHolding>(x => x.Product.ID).IsEqualTo(productID),
+                    new Columns<StockHolding>(
+                        x => x.ID,
+                        x => x.Product.ID,
+                        x => x.Location.ID,
+                        x => x.Location.Description,
+                        x => x.Units,
+                        x => x.Job.ID,
+                        x => x.Job.JobNumber,
+                        x => x.Job.Name,
+                        x => x.Style.ID,
+                        x => x.Style.Code,
+                        x => x.Style.Description,
+                        x => x.Dimensions.Unit.ID,
+                        x => x.Dimensions.Unit.HasQuantity,
+                        x => x.Dimensions.Unit.HasLength,
+                        x => x.Dimensions.Unit.HasHeight,
+                        x => x.Dimensions.Unit.HasWeight,
+                        x => x.Dimensions.Unit.HasWidth,
+                        x => x.Dimensions.Quantity,
+                        x => x.Dimensions.Length,
+                        x => x.Dimensions.Height,
+                        x => x.Dimensions.Weight,
+                        x => x.Dimensions.Width,
+                        x => x.Dimensions.Unit.Format,
+                        x => x.Dimensions.Unit.Formula,
+                        x => x.Dimensions.UnitSize
+                        )
+                    );
+            }
+            catch (Exception ex)
+            {
+                var log = new MobileLogging(LogType.Query, "DoHoldingsQuery", ex.Message + ex.StackTrace, this.GetType().Name);
+                return null;
+            }
         }
 
         private StoreRequiIHoldingShell CreateHoldingShell(CoreRow row)