AssignmentForms.xaml.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using comal.timesheets.QAForms;
  8. using Comal.Classes;
  9. using InABox.Clients;
  10. using InABox.Core;
  11. using Xamarin.Forms;
  12. using Xamarin.Forms.Xaml;
  13. using XF.Material.Forms.UI;
  14. using XF.Material.Forms.UI.Dialogs;
  15. namespace comal.timesheets
  16. {
  17. [XamlCompilation(XamlCompilationOptions.Compile)]
  18. public partial class AssignmentForms : ContentView, IAssignmentPage
  19. {
  20. public AssignmentDetailModel DataModel => BindingContext as AssignmentDetailModel;
  21. public AssignmentForms()
  22. {
  23. InitializeComponent();
  24. }
  25. public void Load()
  26. {
  27. NoForms.IsVisible = !DataModel.Forms.Any();
  28. Forms.IsVisible = DataModel.Forms.Any();
  29. Forms.ItemsSource = DataModel.Forms.ToArray();
  30. }
  31. private async void MaterialCard_OnClicked(object sender, EventArgs e)
  32. {
  33. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
  34. {
  35. var instance = (sender as MaterialCard).BindingContext as AssignmentFormShell;
  36. var form = new Client<AssignmentForm>()
  37. .Query(new Filter<AssignmentForm>(x => x.ID).IsEqualTo(instance.ID))
  38. .Rows
  39. .Select(x => x.ToObject<AssignmentForm>())
  40. .FirstOrDefault();
  41. var model = new DigitalFormHostModel<Assignment, AssignmentLink, AssignmentForm>();
  42. model.LoadItems(DataModel.Item.Entity, form, null);
  43. var host = new DigitalFormHost(model);
  44. host.OnClosing += (o, args) =>
  45. {
  46. if (args.Changed)
  47. {
  48. //instance.Completed = !model.DigitalFormDataModel.Instance.FormCompleted.IsEmpty();
  49. }
  50. };
  51. Navigation.PushAsync(host);
  52. }
  53. }
  54. private void AddForm_OnClicked(object sender, EventArgs e)
  55. {
  56. GenericSelectionPage page = new GenericSelectionPage
  57. (
  58. "Select Type",
  59. new SelectionViewModel<EmployeeDigitalForm>
  60. (
  61. new Filter<EmployeeDigitalForm>(x => x.Form.AppliesTo).IsEqualTo(typeof(Assignment).EntityName().Split('.').Last())
  62. .And(x=>x.Employee.ID).IsEqualTo(DataModel.Item.EmployeeID)
  63. .And(x=>x.Form.Active).IsEqualTo(true)
  64. .And(x=>x.Form.Secure).IsEqualTo(false),
  65. new Expression<Func<EmployeeDigitalForm, object>>[] { x => x.Form.Code, x => x.Form.Description },
  66. new Expression<Func<EmployeeDigitalForm, object>>[] { x => x.Form.ID },
  67. new SortOrder<EmployeeDigitalForm>(x => x.Form.Code)
  68. ));
  69. page.OnItemSelected += (row) =>
  70. {
  71. var form = new AssignmentForm();
  72. form.Parent.ID = DataModel.Item.ID;
  73. form.Form.ID = row.Get<EmployeeDigitalForm, Guid>(x => x.Form.ID);
  74. form.Form.Code = row.Get<EmployeeDigitalForm, String>(x => x.Form.Code);
  75. form.Form.Description = row.Get<EmployeeDigitalForm, String>(x => x.Form.Description);
  76. new Client<AssignmentForm>().Save(form,"Created on Mobile Device",
  77. (o, e) =>
  78. {
  79. Dispatcher.BeginInvokeOnMainThread(
  80. () => {
  81. // DataModel.Forms.Add(
  82. // new AssignmentFormShell()
  83. // {
  84. // ID = o.ID,
  85. // Description = o.Form.Description,
  86. // Completed = false
  87. // }
  88. // );
  89. Forms.ItemsSource = DataModel.Forms.ToArray();
  90. }
  91. );
  92. }
  93. );
  94. };
  95. Navigation.PushAsync(page);
  96. }
  97. }
  98. }