AssignmentColumn.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Comal.Classes;
  8. using InABox.Clients;
  9. using InABox.Core;
  10. using Syncfusion.SfSchedule.XForms;
  11. using Xamarin.Forms;
  12. using Xamarin.Forms.Xaml;
  13. using XF.Material.Forms;
  14. using XF.Material.Forms.UI.Dialogs;
  15. using XF.Material.Forms.UI.Dialogs.Configurations;
  16. namespace comal.timesheets.iOS.Assignments
  17. {
  18. public class AssignmentColumnChangedArgs : EventArgs
  19. {
  20. }
  21. public delegate void AssignmentColumnChangedDelegate(object sender, AssignmentColumnChangedArgs args);
  22. [XamlCompilation(XamlCompilationOptions.Compile)]
  23. public partial class AssignmentColumn : ContentView
  24. {
  25. public event AssignmentColumnChangedDelegate OnChanged;
  26. public Guid EmployeeID { get; set; }
  27. public string EmployeeName
  28. {
  29. get { return Header.Text; }
  30. set { Header.Text = value; }
  31. }
  32. public DateTime Date
  33. {
  34. get { return Schedule.SelectedDate ?? DateTime.MinValue; }
  35. set { Schedule.MoveToDate = value; }
  36. }
  37. public bool ShowTime
  38. {
  39. get { return Schedule.DayViewSettings.TimeRulerSize > 0.0F; }
  40. set { Schedule.DayViewSettings.TimeRulerSize = value ? 50F : 0F; }
  41. }
  42. public void Load(IEnumerable<AssignmentListDataModelItem> items)
  43. {
  44. Header.Margin = ShowTime ? new Thickness(45F, 0F, -5F, -5F) : new Thickness(-5F, 0F, -5F, -5F);
  45. Schedule.DataSource = new ObservableCollection<AssignmentListDataModelItem>(items);
  46. }
  47. public AssignmentColumn()
  48. {
  49. InitializeComponent();
  50. Schedule.DayViewSettings.DayLabelSettings = new DayLabelSettings() { TimeFormat = "HH:mm" };
  51. }
  52. private async void Schedule_OnCellTapped(object sender, CellTappedEventArgs e)
  53. {
  54. if (e.Appointment is AssignmentListDataModelItem item)
  55. {
  56. var editor = new AssignmentEdit(item);
  57. Navigation.PushAsync(editor);
  58. }
  59. }
  60. private async void Schedule_OnCellLongPressed(object sender, CellTappedEventArgs e)
  61. {
  62. if (e.Appointment == null)
  63. {
  64. if (InABox.Core.Security.CanEdit<Assignment>())
  65. {
  66. var assignment = new Assignment()
  67. {
  68. Date = e.Datetime.Date,
  69. Title = "New Assignment"
  70. };
  71. assignment.Booked.Start = e.Datetime.TimeOfDay;
  72. assignment.Booked.Finish = e.Datetime.TimeOfDay.Add(new TimeSpan(1, 0, 0));
  73. assignment.Booked.Duration = new TimeSpan(1, 0, 0);
  74. assignment.EmployeeLink.ID = App.Data.Employee.ID;
  75. var editor = new AssignmentEdit(assignment);
  76. Navigation.PushAsync(editor);
  77. }
  78. }
  79. else if (InABox.Core.Security.CanDelete<Assignment>())
  80. {
  81. var confirm = await MaterialDialog.Instance.ConfirmAsync(
  82. "Are you sure you wish to delete this assignment?",
  83. "Confirm Deletion",
  84. "Yes, Delete",
  85. "Cancel",
  86. new MaterialAlertDialogConfiguration()
  87. {
  88. ButtonFontFamily = Material.FontFamily.Body2
  89. }
  90. );
  91. if (confirm == true)
  92. {
  93. using(await MaterialDialog.Instance.LoadingDialogAsync(message: "Deleting Assignment"))
  94. {
  95. var assignment = new Assignment() { ID = (e.Appointment as AssignmentListDataModelItem).Id };
  96. new Client<Assignment>().Delete(assignment, "Deleted on Mobile Device");
  97. }
  98. OnChanged?.Invoke(this, new AssignmentColumnChangedArgs());
  99. }
  100. }
  101. }
  102. private void Schedule_OnFocusChangeRequested(object sender, FocusRequestArgs e)
  103. {
  104. e.Focus = false;
  105. e.Result = true;
  106. }
  107. private void Schedule_OnFocused(object sender, FocusEventArgs e)
  108. {
  109. }
  110. }
  111. }