using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using Comal.Classes; using InABox.Clients; using InABox.Core; using Syncfusion.SfSchedule.XForms; using Xamarin.Forms; using Xamarin.Forms.Xaml; using XF.Material.Forms; using XF.Material.Forms.UI.Dialogs; using XF.Material.Forms.UI.Dialogs.Configurations; namespace comal.timesheets.iOS.Assignments { public class AssignmentColumnChangedArgs : EventArgs { } public delegate void AssignmentColumnChangedDelegate(object sender, AssignmentColumnChangedArgs args); [XamlCompilation(XamlCompilationOptions.Compile)] public partial class AssignmentColumn : ContentView { public event AssignmentColumnChangedDelegate OnChanged; public Guid EmployeeID { get; set; } public string EmployeeName { get { return Header.Text; } set { Header.Text = value; } } public DateTime Date { get { return Schedule.SelectedDate ?? DateTime.MinValue; } set { Schedule.MoveToDate = value; } } public bool ShowTime { get { return Schedule.DayViewSettings.TimeRulerSize > 0.0F; } set { Schedule.DayViewSettings.TimeRulerSize = value ? 50F : 0F; } } public void Load(IEnumerable items) { Header.Margin = ShowTime ? new Thickness(45F, 0F, -5F, -5F) : new Thickness(-5F, 0F, -5F, -5F); Schedule.DataSource = new ObservableCollection(items); } public AssignmentColumn() { InitializeComponent(); Schedule.DayViewSettings.DayLabelSettings = new DayLabelSettings() { TimeFormat = "HH:mm" }; } private async void Schedule_OnCellTapped(object sender, CellTappedEventArgs e) { if (e.Appointment is AssignmentShell item) { var editor = new AssignmentEdit(item); Navigation.PushAsync(editor); } } private async void Schedule_OnCellLongPressed(object sender, CellTappedEventArgs e) { if (e.Appointment == null) { if (InABox.Core.Security.CanEdit()) { var assignment = new Assignment() { Date = e.Datetime.Date, Title = "New Assignment" }; assignment.Booked.Start = e.Datetime.TimeOfDay; assignment.Booked.Finish = e.Datetime.TimeOfDay.Add(new TimeSpan(1, 0, 0)); assignment.Booked.Duration = new TimeSpan(1, 0, 0); assignment.EmployeeLink.ID = App.Data.Me.ID; var editor = new AssignmentEdit(assignment); Navigation.PushAsync(editor); } } else if (InABox.Core.Security.CanDelete()) { var confirm = await MaterialDialog.Instance.ConfirmAsync( "Are you sure you wish to delete this assignment?", "Confirm Deletion", "Yes, Delete", "Cancel", new MaterialAlertDialogConfiguration() { ButtonFontFamily = Material.FontFamily.Body2 } ); if (confirm == true) { using(await MaterialDialog.Instance.LoadingDialogAsync(message: "Deleting Assignment")) { var assignment = new Assignment() { ID = (e.Appointment as AssignmentShell).Id }; new Client().Delete(assignment, "Deleted on Mobile Device"); } OnChanged?.Invoke(this, new AssignmentColumnChangedArgs()); } } } private void Schedule_OnFocusChangeRequested(object sender, FocusRequestArgs e) { e.Focus = false; e.Result = true; } private void Schedule_OnFocused(object sender, FocusEventArgs e) { } } }