| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 | 
							- using comal.timesheets.CustomControls;
 
- using comal.timesheets.Data_Classes;
 
- using Comal.Classes;
 
- using InABox.Clients;
 
- using InABox.Core;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading;
 
- using System.Threading.Tasks;
 
- using Xamarin.Forms;
 
- using Xamarin.Forms.Xaml;
 
- using XF.Material.Forms.UI.Dialogs;
 
- namespace comal.timesheets
 
- {
 
-     [XamlCompilation(XamlCompilationOptions.Compile)]
 
-     public partial class SetoutsScreen : ContentPage
 
-     {
 
-         #region Constructor / navigation
 
-         Guid JobID = new Guid();
 
-         List<SetoutShell> Setouts = new List<SetoutShell>();
 
-         List<ManufacturingPacketShell> packetShells = new List<ManufacturingPacketShell>();
 
-         List<MiniManufacturingPacket> packets = new List<MiniManufacturingPacket>();
 
-         public SetoutsScreen()
 
-         {
 
-             InitializeComponent();
 
-             NavigationPage.SetHasBackButton(this, false);
 
-         }
 
-         private void ExitBtn_Clicked(object sender, EventArgs e)
 
-         {
 
-             Navigation.PopAsync();
 
-         }
 
-         #endregion
 
-         #region Loading Setouts
 
-         private async void LoadSetouts()
 
-         {
 
-             try
 
-             {
 
-                 using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
 
-                 {
 
-                     AddSetoutsToList(DoSetoutsQuery());
 
-                 }
 
-             }
 
-             catch { }
 
-         }
 
-         private CoreTable DoSetoutsQuery()
 
-         {
 
-             CoreTable table = new Client<Setout>().Query
 
-                     (
 
-                     new Filter<Setout>(x => x.JobLink.ID).IsEqualTo(JobID),
 
-                     new Columns<Setout>(
 
-                         x => x.ID,
 
-                         x => x.Number,
 
-                         x => x.Description
 
-                         )
 
-                     );
 
-             DoPacketsQuery(table);
 
-             return table;
 
-         }
 
-         private void DoPacketsQuery(CoreTable table)
 
-         {
 
-             List<Guid> ids = new List<Guid>();
 
-             foreach (CoreRow row in table.Rows)
 
-                 ids.Add(row.Get<Setout, Guid>(x => x.ID));
 
-             CoreTable packetstable = new Client<ManufacturingPacket>().Query(new Filter<ManufacturingPacket>(x => x.SetoutLink.ID).InList(ids.ToArray())
 
-                 , Columns);
 
-             foreach (CoreRow row in packetstable.Rows)
 
-             {
 
-                 packets.Add(new MiniManufacturingPacket
 
-                 {
 
-                     ID = row.Get<ManufacturingPacket, Guid>(x => x.ID),
 
-                     OrderID = row.Get<ManufacturingPacket, Guid>(x => x.OrderItem.ID),
 
-                     Serial = row.Get<ManufacturingPacket, string>(x => x.Serial),
 
-                     Location = row.Get<ManufacturingPacket, string>(x => x.Location),
 
-                     SetoutID = row.Get<ManufacturingPacket, Guid>(x => x.SetoutLink.ID),
 
-                 });
 
-             }
 
-         }
 
-         private void AddSetoutsToList(CoreTable table)
 
-         {
 
-             foreach (CoreRow row in table.Rows)
 
-                 Setouts.Add(CreateSetoutShell(row));
 
-             foreach (var shell in Setouts)
 
-             {
 
-                 var item = CreateSetOutViewItem(shell);
 
-                 setoutsList.Children.Add(item);
 
-             }
 
-             titleLbl.Text = "Setouts (" + setoutsList.Children.Count().ToString() + ")";
 
-         }
 
-         private SetoutPacketGrid CreateSetOutViewItem(SetoutShell shell)
 
-         {
 
-             return new SetoutPacketGrid(shell);
 
-         }
 
-         private SetoutShell CreateSetoutShell(CoreRow row)
 
-         {
 
-             SetoutShell shell = AddSetoutDetails(row);
 
-             shell = AddPacketDetails(shell);
 
-             return shell;
 
-         }
 
-         private SetoutShell AddSetoutDetails(CoreRow row)
 
-         {
 
-             SetoutShell shell = new SetoutShell();
 
-             shell.ID = row.Get<Setout, Guid>(x => x.ID);
 
-             shell.Number = row.Get<Setout, string>(x => x.Number);
 
-             shell.Description = row.Get<Setout, string>(x => x.Description);
 
-             return shell;
 
-         }
 
-         private SetoutShell AddPacketDetails(SetoutShell shell)
 
-         {
 
-             var list = packets.Where(x => x.SetoutID == shell.ID);
 
-             foreach (var packet in list)
 
-             {
 
-                 shell.Packets.Add(packet);
 
-             }
 
-             return shell;
 
-         }
 
-         #endregion
 
-         #region Button Presses
 
-         private void JobsBtn_Clicked(object sender, EventArgs e)
 
-         {
 
-             JobSelectionPage page = new JobSelectionPage();
 
-             page.OnItemSelected += () =>
 
-             {
 
-                 JobID = page.Job.ID;
 
-                 jobBtn.Text = page.Job.JobNumber + " " + page.Job.Name;
 
-                 LoadSetouts();
 
-             };
 
-             Navigation.PushAsync(page);
 
-         }
 
-         #endregion
 
-         Columns<ManufacturingPacket> Columns = new Columns<ManufacturingPacket>(
 
-                         x => x.ID,
 
-                         x => x.OrderItem.ID,
 
-                         x => x.Serial,
 
-                         x => x.Location,
 
-                         x => x.SetoutLink.ID
 
-                         );
 
-         #region Searching
 
-         private void SearchEnt_Changed(object sender, EventArgs e)
 
-         {
 
-             if (!string.IsNullOrWhiteSpace(searchEnt.Text))
 
-             {
 
-                 int count = 0;
 
-                 foreach (var child in setoutsList.Children)
 
-                 {
 
-                     if (ConditionsMet(child, searchEnt.Text))
 
-                     {
 
-                         child.IsVisible = true;
 
-                         count++;
 
-                     }
 
-                     else
 
-                         child.IsVisible = false;
 
-                 }
 
-                 titleLbl.Text = "Setouts (" + count.ToString() + ")";
 
-             }
 
-             else
 
-             {
 
-                 foreach (var c in setoutsList.Children)
 
-                 {
 
-                     c.IsVisible = true;
 
-                 }
 
-                 titleLbl.Text = "Setouts (" + setoutsList.Children.Count().ToString() + ")";
 
-             }
 
-         }
 
-         private bool ConditionsMet(View child, string text)
 
-         {
 
-             var item = child as SetoutPacketGrid;
 
-             if (SetOutConditionsMatch(item, text) || PacketConditionsMet(item, text))
 
-                 return true;
 
-             else
 
-                 return false;
 
-         }
 
-         private bool SetOutConditionsMatch(SetoutPacketGrid child, string text)
 
-         {
 
-             if (child.Shell.Number.Contains(text) || child.Shell.Number.Contains(text.ToLower()) || child.Shell.Number.Contains(text.ToUpper())
 
-                 || child.Shell.Number.Contains(SearchUtils.UpperCaseFirst(text)) ||
 
-                 child.Shell.Description.Contains(text) || child.Shell.Description.Contains(text.ToLower()) || child.Shell.Description.Contains(text.ToUpper())
 
-                 || child.Shell.Description.Contains(SearchUtils.UpperCaseFirst(text)))
 
-                 return true;
 
-             else
 
-                 return false;
 
-         }
 
-         private bool PacketConditionsMet(SetoutPacketGrid child, string text)
 
-         {
 
-             foreach (var packet in child.Shell.Packets)
 
-             {
 
-                 if (packet.Serial.Contains(text) || packet.Serial.Contains(text.ToUpper()) || packet.Serial.Contains(text.ToLower())
 
-                     || packet.Serial.Contains(SearchUtils.UpperCaseFirst(text))
 
-                     || packet.Location.Contains(text) || packet.Location.Contains(text.ToUpper()) || packet.Location.Contains(text.ToLower())
 
-                     || packet.Location.Contains(SearchUtils.UpperCaseFirst(text)))
 
-                     return true;
 
-             }
 
-             return false;
 
-         }
 
-         #endregion
 
-     }
 
-     public class SetoutShell
 
-     {
 
-         public Guid ID { get; set; }
 
-         public string Number { get; set; }
 
-         public string Description { get; set; }
 
-         public List<MiniManufacturingPacket> Packets { get; set; }
 
-         public SetoutShell()
 
-         {
 
-             ID = Guid.Empty;
 
-             Number = "";
 
-             Description = "";
 
-             Packets = new List<MiniManufacturingPacket>();
 
-         }
 
-     }
 
- }
 
 
  |