PurchaseOrderDetails.xaml.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using Comal.Classes;
  2. using InABox.Clients;
  3. using InABox.Core;
  4. using iText.StyledXmlParser.Node;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Xamarin.Forms;
  11. using Xamarin.Forms.Xaml;
  12. namespace comal.timesheets
  13. {
  14. [XamlCompilation(XamlCompilationOptions.Compile)]
  15. public partial class PurchaseOrderDetails : ContentPage
  16. {
  17. List<PurchaseOrderRequiItemShell> shells = new List<PurchaseOrderRequiItemShell>();
  18. public PurchaseOrderDetails(PurchaseOrderShell purchaseOrderShell)
  19. {
  20. InitializeComponent();
  21. NavigationPage.SetHasBackButton(this, false);
  22. LoadList(purchaseOrderShell);
  23. }
  24. private void ExitBtn_Clicked(object sender, EventArgs e)
  25. {
  26. Navigation.PopAsync();
  27. }
  28. private void LoadList(PurchaseOrderShell purchaseOrderShell)
  29. {
  30. try
  31. {
  32. CoreTable table = DoPOItemQuery(purchaseOrderShell.ID);
  33. if (table.Rows.Any())
  34. GenerateShells(table);
  35. purchaseOrderItemListView.ItemsSource = shells;
  36. }
  37. catch { }
  38. }
  39. private void GenerateShells(CoreTable table)
  40. {
  41. foreach (CoreRow row in table.Rows)
  42. {
  43. shells.Add(CreateShell(row));
  44. }
  45. }
  46. private CoreTable DoPOItemQuery(Guid ID)
  47. {
  48. return new Client<PurchaseOrderItem>().Query(new Filter<PurchaseOrderItem>(x => x.PurchaseOrderLink.ID).IsEqualTo(ID),
  49. new Columns<PurchaseOrderItem>(
  50. x => x.ID,
  51. x => x.Job.JobNumber,
  52. x => x.Description,
  53. x => x.Qty,
  54. x => x.ReceivedDate
  55. )
  56. );
  57. }
  58. private PurchaseOrderRequiItemShell CreateShell(CoreRow row)
  59. {
  60. PurchaseOrderRequiItemShell shell = new PurchaseOrderRequiItemShell
  61. {
  62. ID = row.Get<PurchaseOrderItem, Guid>(x => x.ID),
  63. JobNumber = row.Get<PurchaseOrderItem, string>(x => x.Job.JobNumber),
  64. Description = row.Get<PurchaseOrderItem, string>(x => x.Description),
  65. Qty = row.Get<PurchaseOrderItem, double>(x => x.Qty).ToString()
  66. };
  67. if (row.Get<PurchaseOrderItem, DateTime>(x => x.ReceivedDate) != DateTime.MinValue)
  68. shell.ReceivedDate = (row.Get<PurchaseOrderItem, DateTime>(x => x.ReceivedDate)).ToString("dd MMM yy HH:mm");
  69. return shell;
  70. }
  71. private void PoItem_Tapped(object sender, EventArgs e)
  72. {
  73. PurchaseOrderRequiItemShell shell = purchaseOrderItemListView.SelectedItem as PurchaseOrderRequiItemShell;
  74. if (shell.RequiVisible)
  75. {
  76. var foundShell = shells.FirstOrDefault(x => x.ID == shell.ID);
  77. int index = shells.IndexOf(foundShell);
  78. foundShell.RequiVisible = false;
  79. foundShell.RequiRowHeight = 0;
  80. shells.RemoveAt(index);
  81. shells.Insert(index, foundShell);
  82. purchaseOrderItemListView.ItemsSource = null;
  83. purchaseOrderItemListView.ItemsSource = shells;
  84. }
  85. else
  86. {
  87. CoreTable table = new Client<JobRequisitionItem>().Query(new Filter<JobRequisitionItem>(x => x.PurchaseOrderItem.ID).IsEqualTo(shell.ID),
  88. new Columns<JobRequisitionItem>(x => x.ID, x => x.Qty, x => x.Requisition.Number, x => x.Product.Code, x => x.Product.Name)
  89. );
  90. if (table.Rows.Any())
  91. {
  92. CoreRow row = table.Rows.FirstOrDefault();
  93. var foundShell = shells.FirstOrDefault(x => x.ID == shell.ID);
  94. int index = shells.IndexOf(foundShell);
  95. foundShell.RequiNumber = "NO." + (row.Get<JobRequisitionItem, int>(x => x.Requisition.Number)).ToString();
  96. foundShell.RequiQty = (row.Get<JobRequisitionItem, double>(x => x.Qty)).ToString();
  97. foundShell.ProductCode = row.Get<JobRequisitionItem, string>(x => x.Product.Name);
  98. foundShell.RequiVisible = true;
  99. foundShell.RequiRowHeight = CalculateHeight(foundShell.ProductCode.Length);
  100. shells.RemoveAt(index);
  101. shells.Insert(index, foundShell);
  102. purchaseOrderItemListView.ItemsSource = null;
  103. purchaseOrderItemListView.ItemsSource = shells;
  104. }
  105. }
  106. }
  107. private int CalculateHeight(int calculatedHeight)
  108. {
  109. if (calculatedHeight > 25)
  110. calculatedHeight = 25;
  111. else if (calculatedHeight <= 25 && calculatedHeight < 50)
  112. calculatedHeight = 50;
  113. else if (calculatedHeight <= 50 && calculatedHeight < 75)
  114. calculatedHeight = 75;
  115. calculatedHeight = calculatedHeight + 60;
  116. return calculatedHeight;
  117. }
  118. }
  119. public class PurchaseOrderRequiItemShell
  120. {
  121. public Guid ID { get; set; }
  122. public string JobNumber { get; set; }
  123. public string Description { get; set; }
  124. public string Qty { get; set; }
  125. public string ReceivedDate { get; set; }
  126. public int RequiRowHeight { get; set; }
  127. public bool RequiVisible { get; set; }
  128. public string RequiNumber { get; set; }
  129. public string ProductCode { get; set; }
  130. public string RequiQty { get; set; }
  131. public PurchaseOrderRequiItemShell()
  132. {
  133. ID = Guid.Empty;
  134. JobNumber = "";
  135. Description = "";
  136. Qty = "";
  137. ReceivedDate = "";
  138. RequiRowHeight = 0;
  139. RequiVisible = false;
  140. RequiNumber = "";
  141. ProductCode = "";
  142. RequiQty = "";
  143. }
  144. }
  145. }