Procházet zdrojové kódy

PRS MOBILE - Timesheet changes, viewing PDF from native app for android

Nick-PRSDigital@bitbucket.org před 2 roky
rodič
revize
2b02f1c413

+ 81 - 73
prs.mobile/comal.timesheets/DigitalForms/Renderer/QAFormViewer.cs

@@ -13,6 +13,7 @@ using Syncfusion.XForms.SignaturePad;
 using comal.timesheets.Tasks;
 using Comal.Classes;
 using PRSClasses;
+using Newtonsoft.Json;
 
 namespace comal.timesheets.QAForms
 {
@@ -584,95 +585,102 @@ namespace comal.timesheets.QAForms
 
         private Tuple<View, Boolean> LoadOptionPicker(View view, DFLayoutControl element, string value)
         {
-            var isrequired = false;
-
-            DFLayoutOptionField dfLayoutOptionField = element as DFLayoutOptionField;
-            isrequired = dfLayoutOptionField.Properties.Required;
-            if (GlobalVariables.DeviceString == "i" || GlobalVariables.DeviceString == "I")
+            try
             {
-                CustomPickeriOS item = new CustomPickeriOS();
-                string s = dfLayoutOptionField.Properties.Options;
-                string[] substrings = s.Split(',');
-                var optionList = substrings.ToList();
-                item.AddItems(optionList);
-                if (!string.IsNullOrEmpty(dfLayoutOptionField.Properties.Default))
-                {
-                    int index = optionList.IndexOf(dfLayoutOptionField.Properties.Default);
-                    item.SelectedIndex = index;
-                    item.SelectedItem = optionList[index];
-                    item.SetDefault(optionList[index]);
-                }
-                if (loadData.TryGetValue(dfLayoutOptionField.Name, out value))
-                {
-                    int index = optionList.IndexOf(value);
-                    item.SelectedIndex = index;
-                    item.SelectedItem = optionList[index];
-                    item.SetDefault(optionList[index]);
-                }
-                if (loadRetainedForm)
+                var isrequired = false;
+
+                DFLayoutOptionField dfLayoutOptionField = element as DFLayoutOptionField;
+                isrequired = dfLayoutOptionField.Properties.Required;
+                if (GlobalVariables.DeviceString == "i" || GlobalVariables.DeviceString == "I")
                 {
-                    if (RetainedResults.Results.TryGetValue(dfLayoutOptionField.Name, out value))
+                    CustomPickeriOS item = new CustomPickeriOS();
+                    string s = dfLayoutOptionField.Properties.Options;
+                    string[] substrings = s.Split(',');
+                    var optionList = substrings.ToList();
+                    item.AddItems(optionList);
+                    if (!string.IsNullOrEmpty(dfLayoutOptionField.Properties.Default))
+                    {
+                        int index = optionList.IndexOf(dfLayoutOptionField.Properties.Default);
+                        item.SelectedIndex = index;
+                        item.SelectedItem = optionList[index];
+                        item.SetDefault(optionList[index]);
+                    }
+                    if (loadData.TryGetValue(dfLayoutOptionField.Name, out value))
                     {
                         int index = optionList.IndexOf(value);
                         item.SelectedIndex = index;
                         item.SelectedItem = optionList[index];
                         item.SetDefault(optionList[index]);
                     }
+                    if (loadRetainedForm)
+                    {
+                        if (RetainedResults.Results.TryGetValue(dfLayoutOptionField.Name, out value))
+                        {
+                            int index = optionList.IndexOf(value);
+                            item.SelectedIndex = index;
+                            item.SelectedItem = optionList[index];
+                            item.SetDefault(optionList[index]);
+                        }
+                    }
+                    if (isrequired)
+                    {
+                        item.BackgroundColor = isRequiredColor;
+                        item.SetBackGroundColor(isRequiredColor);
+                    }
+                    item.CustomPickeriOSValueChanged += () =>
+                    {
+                        dfLayout.ChangeField(dfLayoutOptionField.Name);
+                    };
+                    view = item;
                 }
-                if (isrequired)
-                {
-                    item.BackgroundColor = isRequiredColor;
-                    item.SetBackGroundColor(isRequiredColor);
-                }
-                item.CustomPickeriOSValueChanged += () =>
-                {
-                    dfLayout.ChangeField(dfLayoutOptionField.Name);
-                };
-                view = item;
-            }
-            else
-            {
-                Picker picker = new Picker();
-                picker.Title = "Select an option";
-                picker.VerticalTextAlignment = TextAlignment.Center;
-                picker.HorizontalTextAlignment = TextAlignment.Center;
-                string s = dfLayoutOptionField.Properties.Options;
-                string[] substrings = s.Split(',');
-                var optionList = substrings.ToList();
-                picker.ItemsSource = optionList;
-                if (!string.IsNullOrEmpty(dfLayoutOptionField.Properties.Default))
-                {
-                    int index = optionList.IndexOf(dfLayoutOptionField.Properties.Default);
-                    picker.SelectedIndex = index;
-                    picker.SelectedItem = optionList[index];
-                }
-                if (loadData.TryGetValue(dfLayoutOptionField.Name, out value))
-                {
-                    int index = optionList.IndexOf(value);
-                    picker.SelectedIndex = index;
-                    picker.SelectedItem = optionList[index];
-                }
-                if (loadRetainedForm)
+                else
                 {
-                    if (RetainedResults.Results.TryGetValue(dfLayoutOptionField.Name, out value))
+                    Picker picker = new Picker();
+                    picker.Title = "Select an option";
+                    picker.VerticalTextAlignment = TextAlignment.Center;
+                    picker.HorizontalTextAlignment = TextAlignment.Center;
+                    string s = dfLayoutOptionField.Properties.Options;
+                    string[] substrings = s.Split(',');
+                    var optionList = substrings.ToList();
+                    picker.ItemsSource = optionList;
+                    if (!string.IsNullOrEmpty(dfLayoutOptionField.Properties.Default))
+                    {
+                        int index = optionList.IndexOf(dfLayoutOptionField.Properties.Default);
+                        picker.SelectedIndex = index;
+                        picker.SelectedItem = optionList[index];
+                    }
+                    if (loadData.TryGetValue(dfLayoutOptionField.Name, out value))
                     {
                         int index = optionList.IndexOf(value);
                         picker.SelectedIndex = index;
                         picker.SelectedItem = optionList[index];
                     }
+                    if (loadRetainedForm)
+                    {
+                        if (RetainedResults.Results.TryGetValue(dfLayoutOptionField.Name, out value))
+                        {
+                            int index = optionList.IndexOf(value);
+                            picker.SelectedIndex = index;
+                            picker.SelectedItem = optionList[index];
+                        }
+                    }
+                    if (isrequired)
+                    {
+                        picker.BackgroundColor = isRequiredColor;
+                    }
+                    picker.SelectedIndexChanged += (object sender, EventArgs e) =>
+                    {
+                        dfLayout.ChangeField(dfLayoutOptionField.Name);
+                    };
+                    view = picker;
                 }
-                if (isrequired)
-                {
-                    picker.BackgroundColor = isRequiredColor;
-                }
-                picker.SelectedIndexChanged += (object sender, EventArgs e) =>
-                {
-                    dfLayout.ChangeField(dfLayoutOptionField.Name);
-                };
-                view = picker;
-            }
 
-            return new Tuple<View, Boolean>(view, isrequired);
+                return new Tuple<View, Boolean>(view, isrequired);
+            }
+            catch
+            {
+                return new Tuple<View, Boolean>(view, false);
+            }
         }
 
         private Tuple<View, Boolean> LoadImage(View view, DFLayoutControl element)
@@ -2046,7 +2054,7 @@ namespace comal.timesheets.QAForms
 
         public void SetFieldColour(string field, System.Drawing.Color? colour = null)
         {
-            
+
         }
         #endregion
 

+ 5 - 15
prs.mobile/comal.timesheets/Main/MainPage.xaml.cs

@@ -433,7 +433,7 @@ namespace comal.timesheets
                                 jobnumber = row.Get<JobTracker, String>(x => x.JobLink.JobNumber);
                                 jobname = row.Get<JobTracker, String>(x => x.JobLink.Name);
                             }
-                            CreateTimeSheet(jobid, jobnumber, jobname, App.Data.Employee.UsualActivity.ID, App.Data.Employee.UsualActivity.Code, App.Data.Employee.UsualActivity.Description, here, App.GPS.Address, "Clocking On");
+                            CreateTimeSheet(jobid, jobnumber, jobname, here, App.GPS.Address, "Clocking On");
                         }
                         else
                         {
@@ -891,7 +891,7 @@ namespace comal.timesheets
                                             jobnumber = row.Get<JobTracker, String>(x => x.JobLink.JobNumber);
                                             jobname = row.Get<JobTracker, String>(x => x.JobLink.Name);
                                         }
-                                        CreateTimeSheet(jobid, jobnumber, jobname, App.Data.Employee.UsualActivity.ID, App.Data.Employee.UsualActivity.Code, App.Data.Employee.UsualActivity.Description, here, App.GPS.Address, "Clocking On");
+                                        CreateTimeSheet(jobid, jobnumber, jobname, here, App.GPS.Address, "Clocking On");
                                     }
                                     else
                                     {
@@ -957,7 +957,7 @@ namespace comal.timesheets
                     string chosenOption = await DisplayActionSheet("Choose job site", "Cancel", null, array);
                     if (string.IsNullOrEmpty(chosenOption) || chosenOption.Equals("Cancel"))
                     {
-                        CreateTimeSheet(selectedJob.ID, selectedJob.JobNumber, selectedJob.Name, App.Data.Employee.UsualActivity.ID, App.Data.Employee.UsualActivity.Code, App.Data.Employee.UsualActivity.Description, here, App.GPS.Address, "Clocking On");
+                        CreateTimeSheet(selectedJob.ID, selectedJob.JobNumber, selectedJob.Name, here, App.GPS.Address, "Clocking On");
                         return;
                     }
                     else
@@ -969,7 +969,7 @@ namespace comal.timesheets
                 {
                     selectedJob = nearbyJobs.Values.First();
                 }
-                CreateTimeSheet(selectedJob.ID, selectedJob.JobNumber, selectedJob.Name, App.Data.Employee.UsualActivity.ID, App.Data.Employee.UsualActivity.Code, App.Data.Employee.UsualActivity.Description, here, App.GPS.Address, "Clocking On");
+                CreateTimeSheet(selectedJob.ID, selectedJob.JobNumber, selectedJob.Name, here, App.GPS.Address, "Clocking On");
             }
             catch { }
         }
@@ -1033,9 +1033,6 @@ namespace comal.timesheets
                 }
                 else
                 {
-                    Guid activityid = timesheet.ActivityLink.ID;
-                    String activitycode = timesheet.ActivityLink.Code;
-                    String activitydescription = timesheet.ActivityLink.Description;
                     InABox.Core.Location here = new InABox.Core.Location()
                     {
                         Latitude = App.GPS.Latitude,
@@ -1051,9 +1048,6 @@ namespace comal.timesheets
                         job.ID,
                         job.JobNumber,
                         job.Name,
-                        activityid,
-                        activitycode,
-                        activitydescription,
                         here,
                         App.GPS.Address,
                         auditmessage
@@ -1149,14 +1143,13 @@ namespace comal.timesheets
             return false;
         }
 
-        private async void CreateTimeSheet(Guid jobid, string jobnumber, String jobname, Guid activityid, String activitycode, String activitydescription, InABox.Core.Location location, String address, String auditmessage)
+        private async void CreateTimeSheet(Guid jobid, string jobnumber, String jobname, InABox.Core.Location location, String address, String auditmessage)
         {
             try
             {
                 var timesheet = new TimeSheet();
                 using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
                 {
-                    timesheet.EmployeeID = App.Data.Employee.ID;
                     timesheet.EmployeeLink.ID = App.Data.Employee.ID;
                     timesheet.Date = DateTime.Today;
                     TimeSpan tod = DateTime.Now - DateTime.Today;
@@ -1166,9 +1159,6 @@ namespace comal.timesheets
                     timesheet.JobLink.ID = jobid;
                     timesheet.JobLink.JobNumber = jobnumber;
                     timesheet.JobLink.Name = jobname;
-                    timesheet.ActivityLink.ID = activityid;
-                    timesheet.ActivityLink.Code = activitycode;
-                    timesheet.ActivityLink.Description = activitydescription;
                     timesheet.Address = address;
                     timesheet.SoftwareVersion = MobileUtils.AppVersion.InstalledVersionNumber + GlobalVariables.DeviceString;
 

+ 2 - 2
prs.mobile/comal.timesheets/MyHR/Timesheets.xaml.cs

@@ -41,8 +41,8 @@ namespace comal.timesheets
             {
                 List<TimesheetModel> records = new List<TimesheetModel>();
                 CoreTable timesheets = new Client<TimeSheet>().Query(
-                    new Filter<TimeSheet>(X => X.EmployeeID).IsEqualTo(EmployeeID)
-                     .And(X => X.Processed).IsEqualTo(DateTime.MinValue)
+                    new Filter<TimeSheet>(x => x.EmployeeLink.ID).IsEqualTo(EmployeeID)
+                     .And(x => x.Processed).IsEqualTo(DateTime.MinValue)
                      .And(x => x.Date).IsLessThanOrEqualTo(DateTime.Now)
                      .And(x => x.Date).IsGreaterThanOrEqualTo(DateTime.Now.AddDays(DaysFilter)),
                     new Columns<TimeSheet>(X => X.Date, X => X.Start, X => X.Finish, X => X.Duration),

+ 24 - 3
prs.mobile/comal.timesheets/Site/JobDocViewer.xaml.cs

@@ -318,7 +318,7 @@ namespace comal.timesheets
             file.Type = mileStone.Type;
             file.DocSetDescription = mileStone.DocSetDescription;
             file.Issued = mileStone.Issued;
-            
+
             file.TrimmedIssued = TrimWhiteSpace(file.Issued);
 
             byte[] data = filerow.Get<byte[]>("Thumbnail");
@@ -397,8 +397,29 @@ namespace comal.timesheets
         void List_Tapped(object sender, EventArgs e)
         {
             var shell = listView.SelectedItem as JobDocSetFileShell;
-            PDFViewer viewer = new PDFViewer(shell.DocLinkID);
-            Navigation.PushAsync(viewer);
+            if (Device.RuntimePlatform.Equals(Device.Android) && Security.IsAllowed<CanOpenMobileNativePDFViewer>())
+                OpenNativeViewer(shell.DocLinkID);
+            else
+            {
+                PDFViewer viewer = new PDFViewer(shell.DocLinkID);
+                Navigation.PushAsync(viewer);
+            }
+        }
+
+        private async void OpenNativeViewer(Guid docID)
+        {
+            CoreTable table = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(docID),
+            new Columns<Document>(x => x.Data, x => x.FileName));
+            Document doc = table.Rows.First().ToObject<Document>();
+
+            var filePath = Path.Combine(FileSystem.AppDataDirectory, doc.FileName);
+
+            File.WriteAllBytes(filePath, doc.Data);
+
+            await Launcher.OpenAsync(new OpenFileRequest
+            {
+                File = new ReadOnlyFile(filePath)
+            });
         }
 
         void Image_Tapped(object sender, EventArgs e)

+ 0 - 6
prs.mobile/comal.timesheets/Site/Site.xaml.cs

@@ -122,12 +122,6 @@ namespace comal.timesheets
             }
         }
 
-        private async void LoadPDFScreen()
-        {
-            PDFList pdfList = new PDFList(job.ID);
-            Navigation.PushAsync(pdfList);
-        }
-
         private async void SiteDocs_Tapped(object sender, EventArgs e)
         {
             try