EquipmentTasksList.xaml.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 Xamarin.Forms;
  10. using Xamarin.Forms.Xaml;
  11. namespace comal.timesheets
  12. {
  13. [XamlCompilation(XamlCompilationOptions.Compile)]
  14. public partial class EquipmentTasksList : ContentPage
  15. {
  16. List<EquipmentTaskListViewItem> items = new List<EquipmentTaskListViewItem>();
  17. Guid EquipmentID = Guid.Empty;
  18. public EquipmentTasksList(Guid equipmentid)
  19. {
  20. InitializeComponent();
  21. NavigationPage.SetHasBackButton(this, false);
  22. EquipmentID = equipmentid;
  23. }
  24. private void BackBtn_Clicked(object sender, EventArgs e)
  25. {
  26. Navigation.PopAsync();
  27. }
  28. protected override void OnAppearing()
  29. {
  30. LoadItems(EquipmentID);
  31. base.OnAppearing();
  32. }
  33. private void LoadItems(Guid id)
  34. {
  35. CoreTable table = new Client<Kanban>().Query(new Filter<Kanban>(x => x.Equipment.ID).IsEqualTo(id),
  36. new Columns<Kanban>(
  37. x => x.ID, //0
  38. x => x.Number, //1
  39. x => x.Title, //2
  40. x => x.Description, //3
  41. x => x.Completed, //4
  42. x => x.EmployeeLink.Name, //5
  43. x => x.Attachments //6
  44. ),
  45. new SortOrder<Kanban>(x => x.Completed, SortDirection.Descending));
  46. if (table.Rows.Any())
  47. {
  48. items.Clear();
  49. foreach (CoreRow row in table.Rows)
  50. {
  51. List<object> list = row.Values;
  52. if (list[0] == null) list[0] = Guid.Empty;
  53. if (list[1] == null) list[1] = 0;
  54. if (list[2] == null) list[2] = "";
  55. if (list[3] == null) list[3] = "";
  56. if (list[4] == null) list[4] = DateTime.MinValue;
  57. if (list[5] == null) list[5] = "";
  58. if (list[6] == null) list[6] = 0;
  59. EquipmentTaskListViewItem item = new EquipmentTaskListViewItem
  60. {
  61. ID = Guid.Parse(list[0].ToString()),
  62. Number = "Task " + list[1].ToString(),
  63. Title = list[2].ToString(),
  64. Description = CoreUtils.StripHTML(list[3].ToString()),
  65. Completed = DateTime.Parse(list[4].ToString()) == DateTime.MinValue ? "Open" : "Completed: " + DateTime.Parse(list[4].ToString()).ToString("dd MMM yy"),
  66. ImageVisible = int.Parse(list[6].ToString()) > 0,
  67. DescriptionVisible = !string.IsNullOrWhiteSpace(list[3].ToString()) ? true : false
  68. };
  69. if (!string.IsNullOrWhiteSpace(item.Description))
  70. {
  71. item.ExtraRowHeight = new GridLength(1, GridUnitType.Auto);
  72. item.DescriptionVisible = true;
  73. }
  74. item.ExtraColumnWidth = item.ImageVisible ? 35 : 0;
  75. if (item.Completed == "Open")
  76. items.Insert(0, item);
  77. else
  78. items.Add(item);
  79. }
  80. listView.ItemsSource = null;
  81. listView.ItemsSource = items;
  82. }
  83. }
  84. private async void Kanban_Tapped(object sender, EventArgs e)
  85. {
  86. EquipmentTaskListViewItem item = listView.SelectedItem as EquipmentTaskListViewItem;
  87. if (!item.ImageVisible)
  88. return;
  89. CoreTable table = new Client<KanbanDocument>().Query(new Filter<KanbanDocument>(x => x.EntityLink.ID).IsEqualTo(item.ID),
  90. new Columns<KanbanDocument>(x => x.DocumentLink.FileName, x => x.DocumentLink.ID));
  91. if (table.Rows.Any())
  92. {
  93. Dictionary<string, Guid> filenameIDS = new Dictionary<string, Guid>();
  94. foreach (CoreRow row in table.Rows)
  95. {
  96. List<object> list = row.Values;
  97. if (list[0] != null && list[1] != null)
  98. {
  99. filenameIDS.Add(list[0].ToString(), Guid.Parse(list[1].ToString()));
  100. }
  101. }
  102. if (filenameIDS.Count > 0)
  103. {
  104. PDFList pdflist = new PDFList(filenameIDS, true);
  105. Navigation.PushAsync(pdflist);
  106. }
  107. }
  108. }
  109. }
  110. public class EquipmentTaskListViewItem
  111. {
  112. public Guid ID { get; set; }
  113. public string Number { get; set; }
  114. public string Title { get; set; }
  115. public string Description { get; set; }
  116. public string Employee { get; set; }
  117. public string Completed { get; set; }
  118. public string ImageSource { get; set; }
  119. public bool ImageVisible { get; set; }
  120. public bool DescriptionVisible { get; set; }
  121. public double ExtraColumnWidth { get; set; }
  122. public GridLength ExtraRowHeight { get; set; }
  123. public EquipmentTaskListViewItem()
  124. {
  125. ID = Guid.Empty;
  126. Number = "";
  127. Title = "";
  128. Description = "";
  129. Employee = "";
  130. Completed = "";
  131. ImageSource = "paperclip.png";
  132. ImageVisible = false;
  133. DescriptionVisible = false;
  134. ExtraColumnWidth = 0;
  135. ExtraRowHeight = new GridLength(0, GridUnitType.Absolute);
  136. }
  137. }
  138. }