| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using System;
- using System.Linq;
- using System.Threading.Tasks;
- using InABox.Configuration;
- using InABox.Mobile;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace PRS.Mobile
- {
-
- public class MobileManufacturingSettings : ILocalConfigurationSettings
- {
- public Guid FactoryID { get; set; }
- public Guid JobID { get; set; }
- }
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class ManufacturingList
- {
-
- private MobileManufacturingSettings _settings;
-
- public ManufacturingList()
- {
- var _setup = new Task[]
- {
- Task.Run(() => _settings = new LocalConfiguration<MobileManufacturingSettings>().Load()),
- Task.Run(() => App.Data.Jobs.Refresh(false)),
- Task.Run(() => App.Data.ManufacturingFactories.Refresh(false))
- };
-
- InitializeComponent();
- Task.WaitAll(_setup);
- UpdateJobButton();
- UpdateFactoryButton();
- _items.JobID = _settings.JobID;
- _items.FactoryID = _settings.FactoryID;
- _items.RefreshData(false,true);
- }
- private void UpdateJobButton()
- {
- var job = App.Data.Jobs.FirstOrDefault(x => x.ID == _settings.JobID);
- _selectjob.Text = job != null
- ? job.DisplayName
- : "All Jobs";
- }
-
- private void UpdateFactoryButton()
- {
- var factory = App.Data.ManufacturingFactories.FirstOrDefault(x => x.ID == _settings.FactoryID);
- _factory.Text = factory != null
- ? factory.Name
- : "All Factories";
- }
- private void _selectjob_OnClicked(object sender, MobileButtonClickEventArgs args)
- {
- var selection = CreateJobSelection("Select Job", (joblookupshell) =>
- {
- _settings.JobID = joblookupshell?.ID ?? Guid.Empty;
- new LocalConfiguration<MobileManufacturingSettings>().Save(_settings);
- UpdateJobButton();
- _items.JobID = _settings.JobID;
- _items.RefreshData(false,true);
- });
- ShowPopup(() => selection);
- }
-
- private View CreateJobSelection(String caption, Action<JobShell> selected)
- {
- SelectionView selection = new SelectionView
- {
- VerticalOptions = LayoutOptions.Fill,
- HorizontalOptions = LayoutOptions.Fill,
- CanSearch = true
- };
- selection.Configure += (sender, args) =>
- {
- args.Columns
- .BeginUpdate()
- .Clear()
- .Add(new MobileGridTextColumn<JobShell>() { Column = x=>x.JobNumber, Width = GridLength.Auto, Caption = "Job #"})
- .Add(new MobileGridTextColumn<JobShell>() { Column = x=>x.Name, Width = GridLength.Star, Caption = caption})
- .EndUpdate();
- args.Filters.AddRange(App.Data.Jobs.AvailableFilters().Select(x=>x.Name));
- };
- selection.Refresh += (sender, args) => App.Data.Jobs.Refresh(false);
- selection.SelectionChanged += (sender, args) =>
- {
- selected(args.SelectedItems.FirstOrDefault() as JobShell);
- DismissPopup();
- };
- selection.AddButton("All Jobs", () =>
- {
- selected(null);
- DismissPopup();
- });
- selection.Load();
- return selection;
- }
-
- 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) =>
- {
- _settings.FactoryID = factory?.ID ?? Guid.Empty;
- new LocalConfiguration<MobileManufacturingSettings>().Save(_settings);
- UpdateFactoryButton();
- _items.FactoryID = _settings.FactoryID;
- _items.RefreshData(false,true);
- });
- ShowPopup(() => selection);
- }
- }
-
- }
|