SetoutPacketGrid.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 Xamarin.Forms;
  9. namespace comal.timesheets
  10. {
  11. public class SetoutPacketGrid : Frame
  12. {
  13. public SetoutShell Shell;
  14. Dictionary<string, Guid> fileNameIDS = new Dictionary<string, Guid>();
  15. public SetoutPacketGrid(SetoutShell shell)
  16. {
  17. Margin = 0;
  18. Padding = 0;
  19. BorderColor = Color.Gray;
  20. HasShadow = false;
  21. Shell = shell;
  22. Grid mainGrid = new Grid();
  23. mainGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
  24. mainGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) });
  25. mainGrid.Children.Add(SetupSetoutColumn(shell));
  26. mainGrid.Children.Add(SetupPacketsColumn(shell));
  27. Content = mainGrid;
  28. GestureRecognizers.Add(OpenPDFCommand(shell));
  29. }
  30. private View SetupPacketsColumn(SetoutShell shell)
  31. {
  32. StackLayout layout = new StackLayout
  33. {
  34. Orientation = StackOrientation.Vertical
  35. };
  36. layout.SetValue(Grid.ColumnProperty, 1);
  37. foreach (var packet in shell.Packets)
  38. {
  39. layout.Children.Add(CreatePacketView(packet));
  40. }
  41. return layout;
  42. }
  43. private View CreatePacketView(MiniManufacturingPacket packet)
  44. {
  45. Frame frame = new Frame();
  46. frame.Margin = 1;
  47. frame.Padding = 0;
  48. frame.BorderColor = Color.Gray;
  49. frame.HasShadow = false;
  50. frame.Content = new Label
  51. {
  52. Text = packet.Serial + " / " + packet.Location,
  53. Margin = new Thickness(5, 0, 0, 0)
  54. };
  55. frame.GestureRecognizers.Add(OpenPacketCommand(packet));
  56. return frame;
  57. }
  58. private IGestureRecognizer OpenPacketCommand(MiniManufacturingPacket packet)
  59. {
  60. var tapped = new TapGestureRecognizer();
  61. tapped.Tapped += async (s, e) =>
  62. {
  63. ManufacturingPacketPopup popup = new ManufacturingPacketPopup(packet.ID, packet.OrderID);
  64. Navigation.PushAsync(popup);
  65. };
  66. return tapped;
  67. }
  68. private IGestureRecognizer OpenPDFCommand(SetoutShell shell)
  69. {
  70. var tapped = new TapGestureRecognizer();
  71. tapped.Tapped += async (s, e) =>
  72. {
  73. fileNameIDS.Clear();
  74. CoreTable table = new Client<SetoutDocument>().Query
  75. (
  76. new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(shell.ID),
  77. new Columns<SetoutDocument>(x => x.DocumentLink.ID, x => x.DocumentLink.FileName)
  78. );
  79. if (table.Rows.Any())
  80. {
  81. foreach (CoreRow row in table.Rows)
  82. {
  83. if (!fileNameIDS.ContainsKey(row.Get<string>("DocumentLink.FileName")))
  84. fileNameIDS.Add(row.Get<string>("DocumentLink.FileName"), row.Get<Guid>("DocumentLink.ID"));
  85. }
  86. PDFList list = new PDFList(fileNameIDS);
  87. Navigation.PushAsync(list);
  88. }
  89. };
  90. return tapped;
  91. }
  92. #region Setup Setout column
  93. private Grid SetupSetoutColumn(SetoutShell shell)
  94. {
  95. Grid grid = new Grid();
  96. grid.SetValue(Grid.ColumnProperty, 0);
  97. grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
  98. grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
  99. Label label = new Label
  100. {
  101. Text = shell.Number,
  102. LineBreakMode = LineBreakMode.WordWrap,
  103. Margin = new Thickness(5, 0, 0, 0)
  104. };
  105. label.SetValue(Grid.RowProperty, 0);
  106. Label label1 = new Label
  107. {
  108. Text = shell.Description,
  109. LineBreakMode = LineBreakMode.WordWrap,
  110. Margin = new Thickness(5, 0, 0, 0)
  111. };
  112. label1.SetValue(Grid.RowProperty, 1);
  113. grid.Children.Add(label);
  114. grid.Children.Add(label1);
  115. return grid;
  116. }
  117. private View CreateLabel(string text, double rownumber)
  118. {
  119. Label label = new Label
  120. {
  121. Text = text,
  122. LineBreakMode = LineBreakMode.WordWrap
  123. };
  124. label.SetValue(Grid.RowProperty, rownumber);
  125. return label;
  126. }
  127. #endregion
  128. }
  129. }