JobFormsGrid.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Comal.Classes;
  2. using InABox.Clients;
  3. using InABox.Core;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using XF.Material.Forms.UI.Dialogs;
  10. namespace comal.timesheets
  11. {
  12. public class JobFormsGrid : MobileDataGrid
  13. {
  14. Guid JobID = Guid.Empty;
  15. public JobFormsGrid(Guid jobid, DataGridSaveType savetype)
  16. {
  17. JobID = jobid;
  18. OnItemSelected += JobFormsGrid_OnItemSelected;
  19. LoadItems(savetype);
  20. }
  21. private object JobFormsGrid_OnItemSelected(DataGridViewModelItem item)
  22. {
  23. return null;
  24. }
  25. private void LoadItems(DataGridSaveType savetype)
  26. {
  27. Task.Run(async () =>
  28. {
  29. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  30. {
  31. CoreTable table = DoQuery();
  32. while (table == null)
  33. table = DoQuery();
  34. if (!table.Rows.Any())
  35. return;
  36. List<DataGridViewModelItem> shells = new List<DataGridViewModelItem>();
  37. foreach (CoreRow row in table.Rows)
  38. {
  39. List<Tuple<string, string>> tuples = new List<Tuple<string, string>>
  40. {
  41. new Tuple<string, string>("Name", row.Get<JobForm, string>(x => x.Form.Description)),
  42. new Tuple<string, string>("Started", row.Get<JobForm, DateTime>(x => x.FormStarted).ToString("dd MMM yy")),
  43. new Tuple<string, string>("Completed", row.Get<JobForm, DateTime>(x => x.FormCompleted) == DateTime.MinValue? " " : row.Get<JobForm, DateTime>(x => x.FormCompleted).ToString("dd MMM yy")),
  44. new Tuple<string, string>("User", row.Get<JobForm, string>(x => x.FormCompletedBy.UserID))
  45. };
  46. shells.Add(new DataGridViewModelItem
  47. (
  48. id: row.Get<JobForm, Guid>(x => x.ID),
  49. data: tuples
  50. ));
  51. }
  52. Setup(shells, typeof(JobForm), savetype);
  53. }
  54. });
  55. }
  56. private CoreTable DoQuery()
  57. {
  58. try
  59. {
  60. return new Client<JobForm>().Query(
  61. new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(JobID),
  62. new Columns<JobForm>(
  63. x => x.ID,
  64. x => x.FormCompleted,
  65. x => x.Form.Description,
  66. x => x.FormCompletedBy.UserID,
  67. x => x.FormStarted,
  68. x => x.Form.ID
  69. ));
  70. }
  71. catch (Exception ex)
  72. {
  73. MobileLogging.Log(LogType.Query, "Job Forms Grid", ex.Message + ex.StackTrace, this.GetType().Name);
  74. return null;
  75. }
  76. }
  77. }
  78. }