SetoutsScreen.xaml.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using comal.timesheets.CustomControls;
  2. using comal.timesheets.Data_Classes;
  3. using Comal.Classes;
  4. using InABox.Clients;
  5. using InABox.Core;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using Xamarin.Forms;
  13. using Xamarin.Forms.Xaml;
  14. using XF.Material.Forms.UI.Dialogs;
  15. namespace comal.timesheets
  16. {
  17. [XamlCompilation(XamlCompilationOptions.Compile)]
  18. public partial class SetoutsScreen : ContentPage
  19. {
  20. #region Constructor / navigation
  21. Guid JobID = new Guid();
  22. List<SetoutShell> Setouts = new List<SetoutShell>();
  23. List<ManufacturingPacketShell> packetShells = new List<ManufacturingPacketShell>();
  24. List<MiniManufacturingPacket> packets = new List<MiniManufacturingPacket>();
  25. public SetoutsScreen()
  26. {
  27. InitializeComponent();
  28. NavigationPage.SetHasBackButton(this, false);
  29. }
  30. private void ExitBtn_Clicked(object sender, EventArgs e)
  31. {
  32. Navigation.PopAsync();
  33. }
  34. #endregion
  35. #region Loading Setouts
  36. private async void LoadSetouts()
  37. {
  38. try
  39. {
  40. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  41. {
  42. AddSetoutsToList(DoSetoutsQuery());
  43. }
  44. }
  45. catch { }
  46. }
  47. private CoreTable DoSetoutsQuery()
  48. {
  49. CoreTable table = new Client<Setout>().Query
  50. (
  51. new Filter<Setout>(x => x.JobLink.ID).IsEqualTo(JobID),
  52. new Columns<Setout>(
  53. x => x.ID,
  54. x => x.Number,
  55. x => x.Description
  56. )
  57. );
  58. DoPacketsQuery(table);
  59. return table;
  60. }
  61. private void DoPacketsQuery(CoreTable table)
  62. {
  63. List<Guid> ids = new List<Guid>();
  64. foreach (CoreRow row in table.Rows)
  65. ids.Add(row.Get<Setout, Guid>(x => x.ID));
  66. CoreTable packetstable = new Client<ManufacturingPacket>().Query(new Filter<ManufacturingPacket>(x => x.SetoutLink.ID).InList(ids.ToArray())
  67. , Columns);
  68. foreach (CoreRow row in packetstable.Rows)
  69. {
  70. packets.Add(new MiniManufacturingPacket
  71. {
  72. ID = row.Get<ManufacturingPacket, Guid>(x => x.ID),
  73. OrderID = row.Get<ManufacturingPacket, Guid>(x => x.OrderItem.ID),
  74. Serial = row.Get<ManufacturingPacket, string>(x => x.Serial),
  75. Location = row.Get<ManufacturingPacket, string>(x => x.Location),
  76. SetoutID = row.Get<ManufacturingPacket, Guid>(x => x.SetoutLink.ID),
  77. });
  78. }
  79. }
  80. private void AddSetoutsToList(CoreTable table)
  81. {
  82. foreach (CoreRow row in table.Rows)
  83. Setouts.Add(CreateSetoutShell(row));
  84. foreach (var shell in Setouts)
  85. {
  86. var item = CreateSetOutViewItem(shell);
  87. setoutsList.Children.Add(item);
  88. }
  89. titleLbl.Text = "Setouts (" + setoutsList.Children.Count().ToString() + ")";
  90. }
  91. private SetoutPacketGrid CreateSetOutViewItem(SetoutShell shell)
  92. {
  93. return new SetoutPacketGrid(shell);
  94. }
  95. private SetoutShell CreateSetoutShell(CoreRow row)
  96. {
  97. SetoutShell shell = AddSetoutDetails(row);
  98. shell = AddPacketDetails(shell);
  99. return shell;
  100. }
  101. private SetoutShell AddSetoutDetails(CoreRow row)
  102. {
  103. SetoutShell shell = new SetoutShell();
  104. shell.ID = row.Get<Setout, Guid>(x => x.ID);
  105. shell.Number = row.Get<Setout, string>(x => x.Number);
  106. shell.Description = row.Get<Setout, string>(x => x.Description);
  107. return shell;
  108. }
  109. private SetoutShell AddPacketDetails(SetoutShell shell)
  110. {
  111. var list = packets.Where(x => x.SetoutID == shell.ID);
  112. foreach (var packet in list)
  113. {
  114. shell.Packets.Add(packet);
  115. }
  116. return shell;
  117. }
  118. #endregion
  119. #region Button Presses
  120. private void JobsBtn_Clicked(object sender, EventArgs e)
  121. {
  122. JobSelectionPage page = new JobSelectionPage();
  123. page.OnItemSelected += () =>
  124. {
  125. JobID = page.Job.ID;
  126. jobBtn.Text = page.Job.JobNumber + " " + page.Job.Name;
  127. LoadSetouts();
  128. };
  129. Navigation.PushAsync(page);
  130. }
  131. #endregion
  132. Columns<ManufacturingPacket> Columns = new Columns<ManufacturingPacket>(
  133. x => x.ID,
  134. x => x.OrderItem.ID,
  135. x => x.Serial,
  136. x => x.Location,
  137. x => x.SetoutLink.ID
  138. );
  139. #region Searching
  140. private void SearchEnt_Changed(object sender, EventArgs e)
  141. {
  142. if (!string.IsNullOrWhiteSpace(searchEnt.Text))
  143. {
  144. int count = 0;
  145. foreach (var child in setoutsList.Children)
  146. {
  147. if (ConditionsMet(child, searchEnt.Text))
  148. {
  149. child.IsVisible = true;
  150. count++;
  151. }
  152. else
  153. child.IsVisible = false;
  154. }
  155. titleLbl.Text = "Setouts (" + count.ToString() + ")";
  156. }
  157. else
  158. {
  159. foreach (var c in setoutsList.Children)
  160. {
  161. c.IsVisible = true;
  162. }
  163. titleLbl.Text = "Setouts (" + setoutsList.Children.Count().ToString() + ")";
  164. }
  165. }
  166. private bool ConditionsMet(View child, string text)
  167. {
  168. var item = child as SetoutPacketGrid;
  169. if (SetOutConditionsMatch(item, text) || PacketConditionsMet(item, text))
  170. return true;
  171. else
  172. return false;
  173. }
  174. private bool SetOutConditionsMatch(SetoutPacketGrid child, string text)
  175. {
  176. if (child.Shell.Number.Contains(text) || child.Shell.Number.Contains(text.ToLower()) || child.Shell.Number.Contains(text.ToUpper())
  177. || child.Shell.Number.Contains(SearchUtils.UpperCaseFirst(text)) ||
  178. child.Shell.Description.Contains(text) || child.Shell.Description.Contains(text.ToLower()) || child.Shell.Description.Contains(text.ToUpper())
  179. || child.Shell.Description.Contains(SearchUtils.UpperCaseFirst(text)))
  180. return true;
  181. else
  182. return false;
  183. }
  184. private bool PacketConditionsMet(SetoutPacketGrid child, string text)
  185. {
  186. foreach (var packet in child.Shell.Packets)
  187. {
  188. if (packet.Serial.Contains(text) || packet.Serial.Contains(text.ToUpper()) || packet.Serial.Contains(text.ToLower())
  189. || packet.Serial.Contains(SearchUtils.UpperCaseFirst(text))
  190. || packet.Location.Contains(text) || packet.Location.Contains(text.ToUpper()) || packet.Location.Contains(text.ToLower())
  191. || packet.Location.Contains(SearchUtils.UpperCaseFirst(text)))
  192. return true;
  193. }
  194. return false;
  195. }
  196. #endregion
  197. }
  198. public class SetoutShell
  199. {
  200. public Guid ID { get; set; }
  201. public string Number { get; set; }
  202. public string Description { get; set; }
  203. public List<MiniManufacturingPacket> Packets { get; set; }
  204. public SetoutShell()
  205. {
  206. ID = Guid.Empty;
  207. Number = "";
  208. Description = "";
  209. Packets = new List<MiniManufacturingPacket>();
  210. }
  211. }
  212. }