| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- using System;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using Comal.Classes;
- using InABox.Configuration;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using InABox.Core;
- using InABox.Mobile;
- using InABox.Mobile.Shared;
- using XF.Material.Forms.UI.Dialogs;
- using XF.Material.Forms.UI.Dialogs.Configurations;
- namespace PRS.Mobile
- {
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class SiteModule
- {
- private JobShell _job;
- private SiteModuleSettings _settings;
-
- private CancellationTokenSource _pollingToken;
-
- public SiteModule()
- {
- _settings = new LocalConfiguration<SiteModuleSettings>().Load();
-
- InitializeComponent();
-
- ProgressVisible = true;
-
- SiteDocuments.IsVisible = Security.IsAllowed<CanViewJobDocumentMileStoneFiles>();
-
- // ** Not Yet Implemented **
- //CanApproveJobRequisitions.IsVisible = InABox.Core.Security.CanView<PurchaseOrder>()
-
- Manufacturing.IsVisible = Security.IsAllowed<CanViewManufacturingOnMobile>();
- JobTasks.IsVisible = Security.IsAllowed<CanViewOthersTasks>();
-
- Task.Run(() =>
- {
- App.Data.Jobs.Refresh(false);
- _job = App.Data.Jobs.FirstOrDefault(x => x.ID == _settings.JobID);
- }).BeginInvokeOnMainThread((task) =>
- {
- SelectJob.Text = _job?.DisplayName ?? "Select Job";
- SiteForms.Alert = "";
- SelectJob.IsEnabled = true;
- EnableModules();
- ProgressVisible = false;
- });
- }
- protected override void OnAppearing()
- {
- _pollingToken = new CancellationTokenSource();
- StartMonitoringITPForms();
- StartMonitoringForms();
- StartMonitoringTasks();
- base.OnAppearing();
- }
- protected override void OnDisappearing()
- {
- base.OnDisappearing();
- _pollingToken.Cancel();
- }
-
- private void StartMonitoringITPForms()
- {
- var token = _pollingToken.Token;
- Task.Run(() =>
- {
-
- while (!_pollingToken.Token.IsCancellationRequested)
- {
- Guid jobid = _job?.ID ?? Guid.Empty;
- if (App.Data.IsConnected() && (jobid != Guid.Empty))
- {
- var _model = new JobITPFormModel(App.Data,
- () => new Filter<JobITPForm>(x => x.Parent.Job.ID).IsEqualTo(jobid).And(x=>x.Form.ID).IsNotEqualTo(Guid.Empty)
- );
- _model.Refresh(true);
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- int count = _model.Items.Count(x => x.Completed.IsEmpty());
- SiteITPForms.Alert = count > 0
- ? count.ToString()
- : "";
- });
- }
- else
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- SiteITPForms.Alert = "";
- });
- Task.Delay(TimeSpan.FromSeconds(30), token)
- .Wait(token);
- }
- },
- token
- );
- }
-
- private void StartMonitoringForms()
- {
- var token = _pollingToken.Token;
- Task.Run(() =>
- {
-
- while (!_pollingToken.Token.IsCancellationRequested)
- {
- Guid jobid = _job?.ID ?? Guid.Empty;
- if (App.Data.IsConnected() && (jobid != Guid.Empty))
- {
- JobFormModel _model = new JobFormModel(App.Data,
- () => new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(jobid));
- _model.Refresh(true);
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- int count = _model.Items.Count(x => x.Completed.IsEmpty());
- SiteForms.Alert = count > 0
- ? count.ToString()
- : "";
- });
- }
- else
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- SiteForms.Alert = "";
- });
- Task.Delay(TimeSpan.FromSeconds(30), token)
- .Wait(token);
- }
- },
- token
- );
- }
- private void StartMonitoringTasks()
- {
- var token = _pollingToken.Token;
- Task.Run(
- async () =>
- {
- while (!_pollingToken.Token.IsCancellationRequested)
- {
- Guid jobid = _job?.ID ?? Guid.Empty;
- if (App.Data.IsConnected() && (jobid != Guid.Empty))
- {
- var _model = new JobKanbanModel(
- App.Data,
- () => new Filter<Kanban>(x => x.JobLink.ID).IsEqualTo(jobid)
- );
- _model.Refresh(true);
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- int count = _model.Items.Count(x=>String.Equals(x.Category, Kanban.OPEN));
- JobTasks.Alert = count > 0
- ? count.ToString()
- : "";
- });
- }
- else
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- JobTasks.Alert = "";
- });
-
- Task.Delay(TimeSpan.FromSeconds(30), token)
- .Wait(token);
- }
- },
- token
- );
- }
-
- protected override void UpdateTransportStatus()
- {
- base.UpdateTransportStatus();
- EnableModules();
- }
- private void EnableModules()
- {
- foreach (var menu in Menu.Items)
- menu.IsEnabled = App.Data.IsConnected() && (_job != null);
- }
- private void SelectJobBtn_Clicked(object sender, EventArgs e)
- {
- SelectionPage jobs = new JobSelectionPage(
- (job) =>
- {
- new LocalConfiguration<SiteModuleSettings>().Save(new SiteModuleSettings() { JobID = job.ID });
- _job = job;
- SelectJob.Text = _job?.DisplayName ?? "Select Job";
- SiteForms.Alert = "";
- });
- Navigation.PushAsync(jobs);
- }
-
- private void SiteITPForms_OnTapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- Navigation.PushAsync(new SiteITPs(_job));
- }
- private void SiteDocuments_OnTapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- Navigation.PushAsync(new SiteDocuments(_job));
- }
- private void SiteForms_OnTapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- Navigation.PushAsync(new SiteForms(_job));
- }
- private void GeneralDocuments_OnTapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- Navigation.PushAsync(new JobWebDocuments(_job));
- }
- // private void JobRequisitions_OnTapped(ModuleMenuItem sender, ModuleMenuItemTappedArgs args)
- // {
- // throw new NotImplementedException();
- // }
-
- private void Manufacturing_OnTapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- Navigation.PushAsync(new SiteManufacturing(_job));
- }
- private void JobTasks_OnTapped(MobileModuleItem sender, ModuleMenuItemTappedArgs args)
- {
- var model = new JobKanbanModel(
- App.Data,
- () => new Filter<Kanban>(x => x.JobLink.ID).IsEqualTo(_job?.ID ?? CoreUtils.FullGuid)
- );
- model.FileName = $"{_job.ID}.tasks";
- model.ItemAdded += (o, createdArgs) =>
- {
- createdArgs.Item.JobID = _job.ID;
- createdArgs.Item.JobNumber = _job.JobNumber;
- createdArgs.Item.JobName = _job.Name;
- };
- var jobtasks = new KanbanList()
- {
- Model = model,
- Title = "Job Tasks"
- };
- Navigation.PushAsync(jobtasks);
- }
-
- }
- }
|