|
|
@@ -387,13 +387,12 @@ namespace PRSDesktop
|
|
|
|
|
|
public event TimeSheetConfirmedEvent OnTimeSheetConfirmed;
|
|
|
|
|
|
- private void PopulateFavourites(ItemsControl menu, RoutedEventHandler action, DateTime time, bool filltime)
|
|
|
+ private void PopulateFavourites(ItemsControl menu, CalendarTimeSlot slot, bool filltime)
|
|
|
{
|
|
|
|
|
|
menu.Items.RemoveAt(0);
|
|
|
var create = new MenuItem { Header = "Create New Assignment" };
|
|
|
- create.Tag = new Tuple<DateTime, AssignmentFavourite?>(time, null);
|
|
|
- create.Click += action;
|
|
|
+ create.Click += (o, e) => CreateNewAssignment(slot, null);
|
|
|
menu.Items.Insert(0,create);
|
|
|
|
|
|
if (_settings.Favourites?.Any() == true)
|
|
|
@@ -403,8 +402,7 @@ namespace PRSDesktop
|
|
|
foreach (var favourite in _settings.Favourites)
|
|
|
{
|
|
|
var fav = new MenuItem { Header = favourite.Title };
|
|
|
- fav.Tag = new Tuple<DateTime, AssignmentFavourite?>(time, favourite);
|
|
|
- fav.Click += action;
|
|
|
+ fav.Click += (o, e) => CreateNewAssignment(slot, favourite);
|
|
|
menu.Items.Insert(i,fav);
|
|
|
i++;
|
|
|
}
|
|
|
@@ -419,9 +417,9 @@ namespace PRSDesktop
|
|
|
|
|
|
if (args is CalendarDataEventArgs<CalendarTimeSlot> slot)
|
|
|
{
|
|
|
- PopulateFavourites(menu, CreateAssignment_Click, slot.Item.Time, false);
|
|
|
+ PopulateFavourites(menu, slot.Item, false);
|
|
|
}
|
|
|
- else if (args is CalendarDataEventArgs<AssignmentModel> model)
|
|
|
+ else if (args is CalendarDataEventArgs<Assignment> model)
|
|
|
{
|
|
|
menu.Items.Insert(1,new Separator());
|
|
|
var SetAsFavouriteMenu = new MenuItem { Header = GetFavourite(model.Item) == null ? "Set As Favourite" : "Update Favourite"};
|
|
|
@@ -439,12 +437,12 @@ namespace PRSDesktop
|
|
|
}
|
|
|
|
|
|
|
|
|
- private AssignmentFavourite? GetFavourite(AssignmentModel? model)
|
|
|
+ private AssignmentFavourite? GetFavourite(Assignment? model)
|
|
|
{
|
|
|
- return model == null ? null : _settings.Favourites.FirstOrDefault(x => string.Equals(x.Title, model.Subject));
|
|
|
+ return model == null ? null : _settings.Favourites.FirstOrDefault(x => string.Equals(x.Title, model.Title));
|
|
|
}
|
|
|
|
|
|
- private void SetAsFavourite(AssignmentModel? model)
|
|
|
+ private void SetAsFavourite(Assignment? model)
|
|
|
{
|
|
|
if (model == null)
|
|
|
{
|
|
|
@@ -457,17 +455,17 @@ namespace PRSDesktop
|
|
|
if (favourite == null)
|
|
|
{
|
|
|
bCreated = true;
|
|
|
- favourite = new AssignmentFavourite { Title = model.Subject };
|
|
|
+ favourite = new AssignmentFavourite { Title = model.Title };
|
|
|
_settings.Favourites.Add(favourite);
|
|
|
}
|
|
|
|
|
|
- favourite.JobID = model.JobID;
|
|
|
- favourite.JobNumber = model.JobNumber;
|
|
|
- favourite.ITPID = model.ItpID;
|
|
|
- favourite.ITPCode = model.ItpCode;
|
|
|
- favourite.ActivityID = model.ActivityID;
|
|
|
- favourite.ActivityColor = model.Color;
|
|
|
- favourite.ActivityName = model.ActivityCode;
|
|
|
+ favourite.JobID = model.JobLink.ID;
|
|
|
+ favourite.JobNumber = model.JobLink.JobNumber;
|
|
|
+ favourite.ITPID = model.ITP.ID;
|
|
|
+ favourite.ITPCode = model.ITP.Code;
|
|
|
+ favourite.ActivityID = model.ActivityLink.ID;
|
|
|
+ favourite.ActivityColor = model.ActivityLink.Color;
|
|
|
+ favourite.ActivityName = model.ActivityLink.Code;
|
|
|
new UserConfiguration<DailyActivityScreenSettings>().Save(_settings);
|
|
|
|
|
|
MessageBox.Show(bCreated ? "Favourite Created!" : "Favourite Updated!");
|
|
|
@@ -493,21 +491,16 @@ namespace PRSDesktop
|
|
|
//UpdateDayButtons();
|
|
|
}
|
|
|
|
|
|
- private void CreateAssignment_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- var fav = (sender as MenuItem)?.Tag as Tuple<DateTime, AssignmentFavourite?>;
|
|
|
- var start = fav != null ? fav.Item1.TimeOfDay : Calendar.SelectedDate.TimeOfDay;
|
|
|
- CreateNewAssignment(start, fav?.Item2);
|
|
|
- }
|
|
|
-
|
|
|
- private void CreateNewAssignment(TimeSpan start, AssignmentFavourite? favourite)
|
|
|
+ private void CreateNewAssignment(CalendarTimeSlot slot, AssignmentFavourite? favourite)
|
|
|
{
|
|
|
CalendarDataEvent populate = (sender, args) => PopulateFavourite(args.Item as Assignment, favourite);
|
|
|
Calendar.ItemCreated += populate;
|
|
|
- var ass = Calendar.CreateAssignment(new CalendarTimeSlot(Employee.ID, Calendar.SelectedDate.Add(start)));
|
|
|
+ var ass = Calendar.CreateAssignment(slot);
|
|
|
Calendar.ItemCreated -= populate;
|
|
|
- SelectAssignment(ass);
|
|
|
-
|
|
|
+ if(ass is not null)
|
|
|
+ {
|
|
|
+ SelectAssignment(ass);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void PopulateFavourite(Assignment? assignment, AssignmentFavourite? favourite)
|
|
|
@@ -708,7 +701,7 @@ namespace PRSDesktop
|
|
|
}
|
|
|
);
|
|
|
|
|
|
- Calendar.UpdateAssignment(SelectedAssignment);
|
|
|
+ // TODO: Calendar.UpdateAssignment(SelectedAssignment);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -936,28 +929,19 @@ namespace PRSDesktop
|
|
|
private void ConfirmTimesheet_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
var bBlankActivities = false;
|
|
|
- var bOverlapping = true;
|
|
|
+ var bOverlapping = false;
|
|
|
|
|
|
- var rows = Calendar.GetAssignments(Employee.ID, DatePicker.SelectedDate.Value);
|
|
|
+ var rows = Calendar.GetAssignments(Employee.ID, Calendar.SelectedDate);
|
|
|
foreach (var row in rows)
|
|
|
{
|
|
|
- var id = row.Get<Assignment, Guid>(c => c.ID);
|
|
|
- var date = row.Get<Assignment, DateTime>(c => c.Date);
|
|
|
- var start = row.Get<Assignment, TimeSpan>(c => c.Actual.Start);
|
|
|
- var finish = row.Get<Assignment, TimeSpan>(c => c.Actual.Finish);
|
|
|
- if (rows.Any(r =>
|
|
|
- r.Get<Assignment, Guid>(c => c.ID) != id
|
|
|
- && r.Get<Assignment, DateTime>(c => c.Date) == date
|
|
|
- && r.Get<Assignment, TimeSpan>(c => c.Actual.Finish) > start
|
|
|
- && r.Get<Assignment, TimeSpan>(c => c.Actual.Start) < finish
|
|
|
- ))
|
|
|
- bOverlapping = false;
|
|
|
-
|
|
|
- if (Security.IsAllowed<RequireActivityCodesOnDailyReports>())
|
|
|
- bBlankActivities = rows.Any(r => !Entity.IsEntityLinkValid<Assignment, AssignmentActivityLink>(x => x.ActivityLink, r));
|
|
|
+ bOverlapping = bOverlapping
|
|
|
+ || rows.Any(x => x.ID != row.ID && x.Date == row.Date && x.Actual.Finish > row.Actual.Start && x.Actual.Start < row.Actual.Finish);
|
|
|
}
|
|
|
|
|
|
- if (!bOverlapping)
|
|
|
+ if (Security.IsAllowed<RequireActivityCodesOnDailyReports>())
|
|
|
+ bBlankActivities = rows.Any(x => x.ActivityLink.ID == Guid.Empty);
|
|
|
+
|
|
|
+ if (bOverlapping)
|
|
|
{
|
|
|
MessageBox.Show("This report contains overlapping blocks!\n\nPlease correct before confirming this timesheet.");
|
|
|
return;
|