using System; using System.Collections.Generic; using System.Linq; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; namespace PRSDesktop { public class MeetingAssignmentGrid :DynamicDataGrid { public MeetingModel? Model { get; set; } public MeetingAssignmentGrid() { Options.BeginUpdate() .Clear() .Add(DynamicGridOption.AddRows) .Add(DynamicGridOption.DeleteRows) .Add(DynamicGridOption.MultiSelect) .EndUpdate(); } protected override DynamicGridColumns LoadColumns() { return new DynamicGridColumns() { new DynamicGridColumn() { ColumnName = CoreUtils.GetFullPropertyName(x => x.EmployeeLink.Name, "."), Width = 0 } }; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder? sort, Action action) { var meetingfilter = (Model == null) || (Model.ID == Guid.Empty) ? new Filter().None() : new Filter(x => x.Meeting.Link.ID).IsEqualTo(Model.ID); criteria.Add(meetingfilter); base.Reload(criteria, columns, ref sort, action); } protected override bool CanCreateItems() { return Model == null ? false : base.CanCreateItems(); } protected override Assignment CreateItem() { var result = base.CreateItem(); result.Meeting.Link.ID = Model.ID; return result; } protected override void DoAdd(bool OpenEditorOnDirectEdit = false) { var employeeids = Data.ExtractValues(x => x.EmployeeLink.ID).Distinct().ToArray(); var existingfilter = employeeids.Any() ? new Filter(x => x.ID).NotInList(employeeids) : null; var defaultfilter = LookupFactory.DefineFilter(); var filter = existingfilter != null ? existingfilter.And(defaultfilter) : defaultfilter; MultiSelectDialog dlg = new MultiSelectDialog(filter, LookupFactory.DefineColumns(), true); if (dlg.ShowDialog() == true) { List updates = new List(); foreach (var item in dlg.Items()) { Assignment assignment = new Assignment(); assignment.EmployeeLink.ID = item.ID; assignment.EmployeeLink.Synchronise(item); assignment.Meeting.Link.ID = Model.ID; assignment.Date = Model.Date; assignment.Booked.Start = Model.Start; assignment.Booked.Finish = Model.Finish; assignment.ActivityLink.ID = Model.ActivityID; assignment.Title = Model.Title; assignment.Description = Model.Description; updates.Add(assignment); } if (updates.Any()) new Client().Save(updates, "Added by Meeting Editor"); Refresh(false, true); } } } }