123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using InABox.Mobile;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using LogType = InABox.Core.LogType;
- using SelectionChangedEventArgs = Syncfusion.XForms.Buttons.SelectionChangedEventArgs;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class SiteManufacturing : SitePage
- {
- #region Constructor / Fields
-
- List<SiteManufacturingPacketShell> packets = new List<SiteManufacturingPacketShell>();
- public SiteManufacturing()
- {
- InitializeComponent();
- }
-
- protected override void JobLoaded()
- {
- RefreshOnJobChange(Job);
- LoadPackets();
- }
-
- #endregion
- #region Loading
-
-
- private void LoadPackets()
- {
- Task.Run(() =>
- {
- QueryAndAddPackets();
- Device.BeginInvokeOnMainThread(() =>
- {
- ShowList();
- RefreshOnListChange(packets);
- });
- });
- }
- private void RefreshOnJobChange(JobDetailModel job)
- {
- packets.Clear();
- RefreshOnListChange(packets);
- locationSearchEnt.Text = "";
- serialSearchEnt.Text = "";
- setoutSearchEnt.Text = "";
-
- ShowLoading();
- }
- private void ShowLoading()
- {
- loadingLbl.Text = "Loading...";
- loadingCol.Width = new GridLength(1, GridUnitType.Star);
- loadingLbl.IsVisible = true;
- listCol.Width = 0;
- listView.IsVisible = false;
- }
- private void ShowList()
- {
- listCol.Width = new GridLength(1, GridUnitType.Star);
- listView.IsVisible = true;
- loadingCol.Width = 0;
- loadingLbl.IsVisible = false;
- }
- private void QueryAndAddPackets()
- {
- CoreTable packetstable = QueryPackets();
- while (packetstable == null)
- packetstable = QueryPackets();
- foreach (CoreRow row in packetstable.Rows)
- CreateAndAddPacket(row);
- }
- private CoreTable QueryPackets()
- {
- try
- {
- return new Client<ManufacturingPacket>().Query(
- new Filter<ManufacturingPacket>(
- x => x.SetoutLink.JobLink.ID).IsEqualTo(Job.Item.ID)
- .And(x => x.Serial).IsNotEqualTo(null)
- .And(x => x.Location).IsNotEqualTo(null)
- ,
- new Columns<ManufacturingPacket>(
- x => x.ID,
- x => x.OrderItem.ID,
- x => x.Serial,
- x => x.Location,
- x => x.SetoutLink.ID,
- x => x.SetoutLink.Number
- ));
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex);
- return null;
- }
- }
- private void CreateAndAddPacket(CoreRow row)
- {
- packets.Add(new SiteManufacturingPacketShell
- {
- ID = row.Get<ManufacturingPacket, Guid>(x => x.ID),
- OrderID = row.Get<ManufacturingPacket, Guid>(x => x.OrderItem.ID),
- Serial = "Serial: " + row.Get<ManufacturingPacket, string>(x => x.Serial),
- Location = "Location: " + row.Get<ManufacturingPacket, string>(x => x.Location),
- SetoutID = row.Get<ManufacturingPacket, Guid>(x => x.SetoutLink.ID),
- Setout = "Setout: " + row.Get<ManufacturingPacket, string>(x => x.SetoutLink.Number)
- });
- }
- #endregion
- #region Taps
- private void ExitBtn_Clicked(object sender, EventArgs e)
- {
- Navigation.PopAsync();
- }
- private void Packet_Tapped(object sender, EventArgs e)
- {
- try
- {
- SiteManufacturingPacketShell packet = listView.SelectedItem as SiteManufacturingPacketShell;
- ManufacturingPacketPopup popup = new ManufacturingPacketPopup(packet.ID, packet.OrderID);
- Navigation.PushAsync(popup);
- }
- catch (Exception ex)
- {
- DisplayAlert("Error", ex.Message, "OK");
- }
- }
- private void PDFs_Tapped(object sender, EventArgs e)
- {
- try
- {
- var item = ((TappedEventArgs)e).Parameter as SiteManufacturingPacketShell;
- if (item == null) return;
- Dictionary<string, Guid> fileNameIDS = new Dictionary<string, Guid>();
- Filter<SetoutDocument> filter = new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(item.SetoutID)
- .And(x => x.Superceded).IsEqualTo(DateTime.MinValue);
- CoreTable table = new Client<SetoutDocument>().Query
- (
- filter,
- new Columns<SetoutDocument>(x => x.DocumentLink.ID, x => x.DocumentLink.FileName)
- );
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- if (!fileNameIDS.ContainsKey(row.Get<string>("DocumentLink.FileName")))
- fileNameIDS.Add(row.Get<string>("DocumentLink.FileName"), row.Get<Guid>("DocumentLink.ID"));
- }
- PDFList list = new PDFList(); //fileNameIDS);
- Navigation.PushAsync(list);
- }
- else
- DisplayAlert("Alert", "No Drawings found", "OK");
- }
- catch (Exception ex)
- {
- DisplayAlert("Error", ex.Message, "OK");
- }
- }
- #endregion
- #region Searching
- List<SiteManufacturingPacketShell> serialSearchList = new List<SiteManufacturingPacketShell>();
- List<SiteManufacturingPacketShell> locationSearchList = new List<SiteManufacturingPacketShell>();
- List<SiteManufacturingPacketShell> setoutSearchList = new List<SiteManufacturingPacketShell>();
- bool bSerialSearch = false;
- bool bLocationSearch = false;
- bool bSetoutSearch = false;
- private void SerialSearchEnt_Changed(object sender, EventArgs e)
- {
- serialSearchList.Clear();
- if (!string.IsNullOrWhiteSpace(serialSearchEnt.Text))
- {
- bSerialSearch = true;
- serialSearchList = CreateSerialSearchList(packets);
- }
- else
- bSerialSearch = false;
- RunSearch();
- }
- private void LocationSearchEnt_Changed(object sender, EventArgs e)
- {
- locationSearchList.Clear();
- if (!string.IsNullOrWhiteSpace(locationSearchEnt.Text))
- {
- bLocationSearch = true;
- locationSearchList = CreateLocationSearchList(packets);
- }
- else
- bLocationSearch = false;
- RunSearch();
- }
- private void SetoutSearchEnt_Changed(object sender, EventArgs e)
- {
- setoutSearchList.Clear();
- if (!string.IsNullOrWhiteSpace(setoutSearchEnt.Text))
- {
- bSetoutSearch = true;
- setoutSearchList = CreateSetoutSearchList(packets);
- }
- else
- bSetoutSearch = false;
- RunSearch();
- }
- private void RunSearch()
- {
- List<SiteManufacturingPacketShell> searchList = new List<SiteManufacturingPacketShell>();
- if (bSerialSearch && bLocationSearch && bSetoutSearch)
- {
- searchList = serialSearchList;
- searchList = CreateLocationSearchList(searchList);
- searchList = CreateSetoutSearchList(searchList);
- }
- else if (bSerialSearch && bLocationSearch && !bSetoutSearch)
- {
- searchList = serialSearchList;
- searchList = CreateLocationSearchList(searchList);
- }
- else if (bSerialSearch && !bLocationSearch && bSetoutSearch)
- {
- searchList = serialSearchList;
- searchList = CreateSetoutSearchList(searchList);
- }
- else if (!bSerialSearch && bLocationSearch && bSetoutSearch)
- {
- searchList = locationSearchList;
- searchList = CreateSetoutSearchList(searchList);
- }
- else if (bSerialSearch && !bLocationSearch && !bSetoutSearch)
- searchList = serialSearchList;
- else if (!bSerialSearch && bLocationSearch && !bSetoutSearch)
- searchList = locationSearchList;
- else if (!bSerialSearch && !bLocationSearch && bSetoutSearch)
- searchList = setoutSearchList;
- if (bSerialSearch || bLocationSearch || bSetoutSearch)
- RefreshOnListChange(searchList);
- else
- RefreshOnListChange(packets);
- }
- private List<SiteManufacturingPacketShell> CreateLocationSearchList(List<SiteManufacturingPacketShell> sublist)
- {
- return sublist
- .Where(x => x.Location.ToUpper().Contains(locationSearchEnt.Text.ToUpper()))
- .ToList();
- }
- private List<SiteManufacturingPacketShell> CreateSerialSearchList(List<SiteManufacturingPacketShell> sublist)
- {
- return sublist
- .Where(x => x.Serial.ToUpper().Contains(serialSearchEnt.Text.ToUpper()))
- .ToList();
- }
- private List<SiteManufacturingPacketShell> CreateSetoutSearchList(List<SiteManufacturingPacketShell> sublist)
- {
- return sublist
- .Where(x=>x.Setout.ToUpper().Contains(setoutSearchEnt.Text.ToUpper()))
- .ToList();
- }
- private void RefreshOnListChange(IEnumerable<SiteManufacturingPacketShell> list)
- {
- listView.ItemsSource = null;
- listView.ItemsSource = list;
- Title = "Packets (" + list.Count() + ")";
- }
- #endregion
-
- private void Display_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- throw new NotImplementedException();
- }
- }
- #region Classes
- /// <summary>
- /// ViewModel class for SiteManufacturing Module
- /// </summary>
- public class SiteManufacturingPacketShell
- {
- public Guid ID { get; set; }
- public Guid OrderID { get; set; }
- public Guid SetoutID { get; set; }
- public string Serial { get; set; }
- public string Location { get; set; }
- public string Setout { get; set; }
- public SiteManufacturingPacketShell()
- {
- ID = Guid.Empty;
- OrderID = Guid.Empty;
- Serial = "";
- Location = "";
- SetoutID = Guid.Empty;
- Setout = "";
- }
- }
- #endregion
- }
|