SiteForms.xaml.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using Xamarin.Forms;
  6. using Xamarin.Forms.Xaml;
  7. namespace PRS.Mobile
  8. {
  9. [XamlCompilation(XamlCompilationOptions.Compile)]
  10. public partial class SiteForms
  11. {
  12. private JobFormModel _model;
  13. public SiteForms(JobShell job) : base(job)
  14. {
  15. _model = new JobFormModel(App.Data, () => new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(Job.ID));
  16. InitializeComponent();
  17. ProgressVisible = true;
  18. _forms.DataModel = _model;
  19. _forms.AppliesTo = "Job";
  20. _forms.Property = model => _model.Items.OfType<IDigitalFormInstanceShell>().ToArray();
  21. RefreshData(false, true);
  22. }
  23. private void RefreshData(bool force, bool async)
  24. {
  25. if (async)
  26. _model.Refresh(force, () => Device.BeginInvokeOnMainThread(RefreshScreen));
  27. else
  28. {
  29. _model.Refresh(force);
  30. RefreshScreen();
  31. }
  32. }
  33. private void RefreshScreen()
  34. {
  35. _forms.Refresh();
  36. ProgressVisible = false;
  37. }
  38. private void AddForm_Clicked(object sender, EventArgs e)
  39. {
  40. var selector = new NewForms() { AppliesTo = _forms.AppliesTo };
  41. selector.ItemSelected += CreateNewForm;
  42. Navigation.PushAsync(selector);
  43. }
  44. private async void CreateNewForm(object sender, NewFormSelectedArgs args)
  45. {
  46. var instance = _model.AddItem();
  47. instance.ParentID = Job.ID;
  48. instance.FormID = args.Form.ID;
  49. instance.FormCode = args.Form.Code;
  50. instance.FormDescription = args.Form.Description;
  51. instance.Save("Created on Mobile Device");
  52. Device.BeginInvokeOnMainThread(() =>
  53. {
  54. _forms.RefreshData(false,false);
  55. _forms.EditForm<Job,JobLink,JobForm>(instance,Job.Entity);
  56. });
  57. }
  58. private void _forms_OnFormTapped(object sender, ExistingFormTappedEventArgs args)
  59. {
  60. ProgressVisible = true;
  61. _forms.EditForm<Job, JobLink, JobForm>(args.Shell, Job.Entity);
  62. ProgressVisible = false;
  63. }
  64. }
  65. }