JobFormsGrid.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 = new Client<JobForm>().Query(
  32. new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(JobID),
  33. new Columns<JobForm>(
  34. x => x.ID,
  35. x => x.FormCompleted,
  36. x => x.Form.Description,
  37. x => x.FormCompletedBy.UserID,
  38. x => x.FormStarted,
  39. x => x.Form.ID
  40. )
  41. );
  42. if (!table.Rows.Any())
  43. return;
  44. List<DataGridViewModelItem> shells = new List<DataGridViewModelItem>();
  45. foreach (CoreRow row in table.Rows)
  46. {
  47. List<Tuple<string, string>> tuples = new List<Tuple<string, string>>
  48. {
  49. new Tuple<string, string>("Name", row.Get<JobForm, string>(x => x.Form.Description)),
  50. new Tuple<string, string>("Started", row.Get<JobForm, DateTime>(x => x.FormStarted).ToString("dd MMM yy")),
  51. 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")),
  52. new Tuple<string, string>("User", row.Get<JobForm, string>(x => x.FormCompletedBy.UserID))
  53. };
  54. shells.Add(new DataGridViewModelItem
  55. (
  56. id: row.Get<JobForm, Guid>(x => x.ID),
  57. data: tuples
  58. ));
  59. }
  60. Setup(shells, typeof(JobForm), savetype);
  61. }
  62. });
  63. }
  64. }
  65. }