123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- 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.Threading.Tasks;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace comal.timesheets
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class SiteManufacturing : ContentPage
- {
- #region Constructor / Fields
- List<MiniManufacturingPacket> packets = new List<MiniManufacturingPacket>();
- Guid JobID = new Guid();
- public SiteManufacturing(Guid jobid = new Guid())
- {
- InitializeComponent();
- NavigationPage.SetHasBackButton(this, false);
- JobID = jobid;
- if (JobID != Guid.Empty)
- QueryJobAndLoadScreen();
- }
- #endregion
- #region Loading
- private void QueryJobAndLoadScreen()
- {
- Job job = new Client<Job>().Query(new Filter<Job>(x => x.ID).IsEqualTo(JobID)).Rows.FirstOrDefault().ToObject<Job>();
- JobShell jobShell = new JobShell()
- {
- ID = JobID,
- Name = job.Name,
- JobNumber = job.JobNumber
- };
- LoadFromJob(jobShell);
- }
- private void LoadFromJob(JobShell job)
- {
- RefreshOnJobChange(job);
- LoadPackets();
- }
- private void JobsBtn_Clicked(object sender, EventArgs e)
- {
- JobSelectionPage page = new JobSelectionPage();
- page.OnItemSelected += () =>
- {
- LoadFromJob(page.Job);
- };
- Navigation.PushAsync(page);
- }
- private void LoadPackets()
- {
- Task.Run(() =>
- {
- QueryAndAddPackets();
- Device.BeginInvokeOnMainThread(() =>
- {
- ShowList();
- RefreshOnListChange(packets);
- });
- });
- }
- private void RefreshOnJobChange(JobShell job)
- {
- packets.Clear();
- RefreshOnListChange(packets);
- locationSearchEnt.Text = "";
- serialSearchEnt.Text = "";
- setoutSearchEnt.Text = "";
- JobID = job.ID;
- jobBtn.Text = job.JobNumber + " " + job.Name;
- 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();
- foreach (CoreRow row in packetstable.Rows)
- CreateAndAddPacket(row);
- }
- private CoreTable QueryPackets()
- {
- return new Client<ManufacturingPacket>().Query(
- new Filter<ManufacturingPacket>(
- x => x.SetoutLink.JobLink.ID).IsEqualTo(JobID)
- .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
- ));
- }
- private void CreateAndAddPacket(CoreRow row)
- {
- packets.Add(new MiniManufacturingPacket
- {
- 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
- {
- MiniManufacturingPacket packet = listView.SelectedItem as MiniManufacturingPacket;
- 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 MiniManufacturingPacket;
- 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<MiniManufacturingPacket> locationSearchList = new List<MiniManufacturingPacket>();
- List<MiniManufacturingPacket> serialSearchList = new List<MiniManufacturingPacket>();
- List<MiniManufacturingPacket> setoutSearchList = new List<MiniManufacturingPacket>();
- private void LocationSearchEnt_Changed(object sender, EventArgs e)
- {
- locationSearchList.Clear();
- if (!string.IsNullOrWhiteSpace(locationSearchEnt.Text))
- locationSearchList = CreateLocationSearchList(packets);
- RunSearch(locationSearchEnt.Text);
- }
- private void SerialSearchEnt_Changed(object sender, EventArgs e)
- {
- serialSearchList.Clear();
- if (!string.IsNullOrWhiteSpace(serialSearchEnt.Text))
- serialSearchList = CreateSerialSearchList(packets);
- RunSearch(serialSearchEnt.Text);
- }
- private void SetoutSearchEnt_Changed(object sender, EventArgs e)
- {
- setoutSearchList.Clear();
- if (!string.IsNullOrWhiteSpace(setoutSearchEnt.Text))
- setoutSearchList = CreateSetoutSearchList(packets);
- RunSearch(setoutSearchEnt.Text);
- }
- private void RunSearch(string search)
- {
- List<MiniManufacturingPacket> searchList = new List<MiniManufacturingPacket>();
- if (locationSearchList.Count > 0 && serialSearchList.Count > 0 && setoutSearchList.Count > 0)
- {
- searchList = CreateLocationSearchList(packets);
- searchList = CreateSerialSearchList(searchList);
- searchList = CreateSetoutSearchList(searchList);
- }
- else if (locationSearchList.Count > 0 && serialSearchList.Count > 0)
- {
- searchList = CreateLocationSearchList(packets);
- searchList = CreateSerialSearchList(searchList);
- }
- else if (locationSearchList.Count > 0 && setoutSearchList.Count > 0)
- {
- searchList = CreateLocationSearchList(packets);
- searchList = CreateSetoutSearchList(searchList);
- }
- else if (serialSearchList.Count > 0 && setoutSearchList.Count > 0)
- {
- searchList = CreateSerialSearchList(packets);
- searchList = CreateSetoutSearchList(searchList);
- }
- else if (locationSearchList.Count > 0 && serialSearchList.Count == 0 && setoutSearchList.Count == 0)
- {
- searchList = CreateLocationSearchList(packets);
- }
- else if (serialSearchList.Count > 0 && locationSearchList.Count == 0 && setoutSearchList.Count == 0)
- {
- searchList = CreateSerialSearchList(packets);
- }
- else if (setoutSearchList.Count > 0 && serialSearchList.Count == 0 && locationSearchList.Count == 0)
- {
- searchList = CreateSetoutSearchList(packets);
- }
- if (searchList.Count > 0)
- RefreshOnListChange(searchList);
- else
- RefreshOnListChange(packets);
- }
- private List<MiniManufacturingPacket> CreateLocationSearchList(List<MiniManufacturingPacket> sublist)
- {
- string search = locationSearchEnt.Text;
- List<MiniManufacturingPacket> returnList = new List<MiniManufacturingPacket>();
- var list = sublist.Where(
- x => x.Location.Contains(search)
- || x.Location.Contains(SearchUtils.UpperCaseFirst(search))
- || x.Location.Contains(SearchUtils.LowerCaseFirst(search))
- || x.Location.Contains(search.ToLower())
- || x.Location.Contains(search.ToUpper())
- );
- foreach (var v in list)
- {
- returnList.Add(v);
- }
- return returnList;
- }
- private List<MiniManufacturingPacket> CreateSerialSearchList(List<MiniManufacturingPacket> sublist)
- {
- string search = serialSearchEnt.Text;
- List<MiniManufacturingPacket> returnList = new List<MiniManufacturingPacket>();
- var list = sublist.Where(
- x => x.Serial.Contains(search)
- || x.Serial.Contains(SearchUtils.UpperCaseFirst(search))
- || x.Serial.Contains(SearchUtils.LowerCaseFirst(search))
- || x.Serial.Contains(search.ToLower())
- || x.Serial.Contains(search.ToUpper())
- );
- foreach (var v in list)
- {
- returnList.Add(v);
- }
- return returnList;
- }
- private List<MiniManufacturingPacket> CreateSetoutSearchList(List<MiniManufacturingPacket> sublist)
- {
- string search = setoutSearchEnt.Text;
- List<MiniManufacturingPacket> returnList = new List<MiniManufacturingPacket>();
- var list = sublist.Where(
- x => x.Setout.Contains(search)
- || x.Setout.Contains(SearchUtils.UpperCaseFirst(search))
- || x.Setout.Contains(SearchUtils.LowerCaseFirst(search))
- || x.Setout.Contains(search.ToLower())
- || x.Setout.Contains(search.ToUpper())
- );
- foreach (var v in list)
- {
- returnList.Add(v);
- }
- return returnList;
- }
- private void RefreshOnListChange(IEnumerable<MiniManufacturingPacket> list)
- {
- listView.ItemsSource = null;
- listView.ItemsSource = list;
- titleLbl.Text = "Packets (" + list.Count() + ")";
- }
- #endregion
- }
- #region Classes
- /// <summary>
- /// ViewModel class for SiteManufacturing Module
- /// </summary>
- public class MiniManufacturingPacket
- {
- 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 MiniManufacturingPacket()
- {
- ID = Guid.Empty;
- OrderID = Guid.Empty;
- Serial = "";
- Location = "";
- SetoutID = Guid.Empty;
- Setout = "";
- }
- }
- #endregion
- }
|