| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using InABox.Configuration;
- using InABox.Mobile;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using LogType = InABox.Core.LogType;
- using SelectionChangedEventArgs = Syncfusion.XForms.Buttons.SelectionChangedEventArgs;
- namespace PRS.Mobile
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class SiteManufacturing : SitePage
- {
- private JobShell _job;
- private ManufacturingPacketModel _packets;
- private SetoutModel _setouts;
- private SetoutDocumentModel _documents;
-
- public SiteManufacturing(JobShell job) : base(job)
- {
- _job = job;
-
- _packets = new ManufacturingPacketModel(App.Data,
- () => new Filter<ManufacturingPacket>(x=>x.SetoutLink.JobLink.ID).IsEqualTo(_job.ID),
- () => CoreRepository.CacheFileName<ManufacturingPacket>($"{_job.ID}")
- );
- _setouts = new SetoutModel(App.Data,
- () => new Filter<Setout>(x => x.JobLink.ID).IsEqualTo(_job.ID),
- () => CoreRepository.CacheFileName<Setout>($"{_job.ID}")
- );
-
- _documents = new SetoutDocumentModel(App.Data,
- () => new Filter<SetoutDocument>(x => x.EntityLink.ID)
- .InQuery<Setout>(new Filter<Setout>(x=>x.JobLink.ID).IsEqualTo(_job.ID),x=>x.ID),
- () => CoreRepository.CacheFileName<SetoutDocument>($"{_job.ID}")
- );
-
-
- InitializeComponent();
- ProgressVisible = true;
-
- Title = Job?.DisplayName ?? "Manufacturing";
-
- Packets.Packets = _packets;
- Packets.JobID = Job?.ID ?? CoreUtils.FullGuid;
- Packets.FactoryID = Guid.Empty;
-
- Setouts.Setouts = _setouts;
- Setouts.Packets = _packets;
- Setouts.Documents = _documents;
- Setouts.JobID = Job?.ID ?? CoreUtils.FullGuid;
-
- RefreshData(false, true);
- }
- private void RefreshData(bool force, bool async)
- {
- Task[] tasks = new Task[]
- {
- Task.Run(() => _packets.Refresh(force)),
- Task.Run(() => _setouts.Refresh(force)),
- Task.Run(() => _documents.Refresh(force))
- };
- if (async)
- Task.WhenAll(tasks).ContinueWith((_) => Device.BeginInvokeOnMainThread(RefreshScreen));
- else
- {
- Task.WaitAll(tasks);
- RefreshScreen();
- }
- }
- private void RefreshScreen()
- {
- Packets.Refresh();
- Setouts.Refresh();
- ProgressVisible = false;
- }
- private void UpdateFactoryButton()
- {
- var factory = App.Data.ManufacturingFactories.FirstOrDefault(x => x.ID == Packets.FactoryID);
- _factory.Text = factory != null
- ? factory.Name
- : "All Factories";
- }
-
- private View CreateFactorySelection(String caption, Action<ManufacturingFactoryShell> selected)
- {
- SelectionView selection = new SelectionView
- {
- VerticalOptions = LayoutOptions.Fill,
- HorizontalOptions = LayoutOptions.Fill,
- CanSearch = false
- };
- selection.Configure += (sender, args) =>
- {
- args.Columns
- .BeginUpdate()
- .Clear()
- .Add(new MobileGridTextColumn<ManufacturingFactoryShell>() { Column = x=>x.Name, Width = GridLength.Star, Caption = caption})
- .EndUpdate();
- };
- selection.Refresh += (sender, args) => App.Data.ManufacturingFactories.Refresh(false);
- selection.SelectionChanged += (sender, args) =>
- {
- selected(args.SelectedItems.FirstOrDefault() as ManufacturingFactoryShell);
- DismissPopup();
- };
- selection.AddButton("All Factories", () =>
- {
- selected(null);
- DismissPopup();
- });
- selection.Load();
- return selection;
- }
- private void _selectfactory_OnClicked(object sender, MobileButtonClickEventArgs args)
- {
- var selection = CreateFactorySelection("Select Factory", (factory) =>
- {
- Packets.FactoryID = factory?.ID ?? Guid.Empty;
- UpdateFactoryButton();
- RefreshData(false,true);
- });
- ShowPopup(() => selection);
- }
- }
- }
|