SetoutPacketGrid.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 = new Thickness(1, 1, 2, 1);
  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. Spacing = 0
  36. };
  37. layout.SetValue(Grid.ColumnProperty, 1);
  38. foreach (var packet in shell.Packets)
  39. {
  40. ViewPosition position = ViewPosition.Middle;
  41. if (packet == shell.Packets.First())
  42. position = ViewPosition.First;
  43. else if (packet == shell.Packets.Last())
  44. position = ViewPosition.Last;
  45. layout.Children.Add(CreatePacketView(packet, position));
  46. }
  47. return layout;
  48. }
  49. private View CreatePacketView(MiniManufacturingPacket packet, ViewPosition position)
  50. {
  51. Frame frame = new Frame();
  52. frame.Margin = new Thickness(0, 1.5, 0, 1.5);
  53. if(position == ViewPosition.First)
  54. frame.Margin = new Thickness(0, 0, 0, 1.5);
  55. else if (position == ViewPosition.Last)
  56. frame.Margin = new Thickness(0, 1.5, 0, 0);
  57. frame.Padding = 0;
  58. frame.BorderColor = Color.Gray;
  59. frame.HasShadow = false;
  60. frame.Content = new Label
  61. {
  62. Text = packet.Serial + " / " + packet.Location,
  63. Margin = new Thickness(5, 0, 0, 0)
  64. };
  65. frame.GestureRecognizers.Add(OpenPacketCommand(packet));
  66. return frame;
  67. }
  68. private IGestureRecognizer OpenPacketCommand(MiniManufacturingPacket packet)
  69. {
  70. var tapped = new TapGestureRecognizer();
  71. tapped.Tapped += async (s, e) =>
  72. {
  73. ManufacturingPacketPopup popup = new ManufacturingPacketPopup(packet.ID, packet.OrderID);
  74. Navigation.PushAsync(popup);
  75. };
  76. return tapped;
  77. }
  78. private IGestureRecognizer OpenPDFCommand(SetoutShell shell)
  79. {
  80. var tapped = new TapGestureRecognizer();
  81. tapped.Tapped += async (s, e) =>
  82. {
  83. fileNameIDS.Clear();
  84. CoreTable table = new Client<SetoutDocument>().Query
  85. (
  86. new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(shell.ID),
  87. new Columns<SetoutDocument>(x => x.DocumentLink.ID, x => x.DocumentLink.FileName)
  88. );
  89. if (table.Rows.Any())
  90. {
  91. foreach (CoreRow row in table.Rows)
  92. {
  93. if (!fileNameIDS.ContainsKey(row.Get<string>("DocumentLink.FileName")))
  94. fileNameIDS.Add(row.Get<string>("DocumentLink.FileName"), row.Get<Guid>("DocumentLink.ID"));
  95. }
  96. PDFList list = new PDFList(fileNameIDS);
  97. Navigation.PushAsync(list);
  98. }
  99. };
  100. return tapped;
  101. }
  102. #region Setup Setout column
  103. private Grid SetupSetoutColumn(SetoutShell shell)
  104. {
  105. Grid grid = new Grid();
  106. grid.SetValue(Grid.ColumnProperty, 0);
  107. grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
  108. grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
  109. Label label = new Label
  110. {
  111. Text = shell.Number,
  112. LineBreakMode = LineBreakMode.WordWrap,
  113. Margin = new Thickness(5, 0, 0, 0)
  114. };
  115. label.SetValue(Grid.RowProperty, 0);
  116. Label label1 = new Label
  117. {
  118. Text = shell.Description,
  119. LineBreakMode = LineBreakMode.WordWrap,
  120. Margin = new Thickness(5, 0, 0, 0)
  121. };
  122. label1.SetValue(Grid.RowProperty, 1);
  123. grid.Children.Add(label);
  124. grid.Children.Add(label1);
  125. return grid;
  126. }
  127. private View CreateLabel(string text, double rownumber)
  128. {
  129. Label label = new Label
  130. {
  131. Text = text,
  132. LineBreakMode = LineBreakMode.WordWrap
  133. };
  134. label.SetValue(Grid.RowProperty, rownumber);
  135. return label;
  136. }
  137. enum ViewPosition
  138. {
  139. First,
  140. Middle,
  141. Last
  142. }
  143. #endregion
  144. }
  145. }