|  | @@ -18,6 +18,7 @@ using InABox.Core;
 | 
	
		
			
				|  |  |  using InABox.DynamicGrid;
 | 
	
		
			
				|  |  |  using InABox.WPF;
 | 
	
		
			
				|  |  |  using Microsoft.Win32;
 | 
	
		
			
				|  |  | +using NPOI.OpenXmlFormats.Wordprocessing;
 | 
	
		
			
				|  |  |  using PRS.Shared;
 | 
	
		
			
				|  |  |  using PRSDesktop.Grids;
 | 
	
		
			
				|  |  |  using Syncfusion.UI.Xaml.Grid;
 | 
	
	
		
			
				|  | @@ -29,931 +30,957 @@ using Activity = Comal.Classes.Activity;
 | 
	
		
			
				|  |  |  using Columns = InABox.Core.Columns;
 | 
	
		
			
				|  |  |  using SelectionChangedEventArgs = System.Windows.Controls.SelectionChangedEventArgs;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -namespace PRSDesktop
 | 
	
		
			
				|  |  | +namespace PRSDesktop;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +public class LeaveValue
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    public class LeaveValue
 | 
	
		
			
				|  |  | +    public LeaveValue(Guid id, Guid employee, DateTime date, Guid activity, LeaveRequestStatus status, bool standard)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -        public LeaveValue(Guid id, Guid employee, DateTime date, Guid activity, LeaveRequestStatus status, bool standard)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            ID = id;
 | 
	
		
			
				|  |  | -            Employee = employee;
 | 
	
		
			
				|  |  | -            Date = date;
 | 
	
		
			
				|  |  | -            Activity = activity;
 | 
	
		
			
				|  |  | -            Status = status;
 | 
	
		
			
				|  |  | -            Standard = standard;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        public Guid ID { get; set; }
 | 
	
		
			
				|  |  | -        public Guid Employee { get; set; }
 | 
	
		
			
				|  |  | -        public DateTime Date { get; set; }
 | 
	
		
			
				|  |  | -        public Guid Activity { get; set; }
 | 
	
		
			
				|  |  | -        public LeaveRequestStatus Status { get; set; }
 | 
	
		
			
				|  |  | -        public bool Standard { get; set; }
 | 
	
		
			
				|  |  | +        ID = id;
 | 
	
		
			
				|  |  | +        Employee = employee;
 | 
	
		
			
				|  |  | +        Date = date;
 | 
	
		
			
				|  |  | +        Activity = activity;
 | 
	
		
			
				|  |  | +        Status = status;
 | 
	
		
			
				|  |  | +        Standard = standard;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public class LeaveBackgroundConverter : IValueConverter
 | 
	
		
			
				|  |  | -    {
 | 
	
		
			
				|  |  | -        public Dictionary<Guid, Color>? Colors { get; set; }
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -        // Guid - EmployeeID
 | 
	
		
			
				|  |  | -        // DateTime - Employee Start Date
 | 
	
		
			
				|  |  | -        // DateTime - Employee Finish Date
 | 
	
		
			
				|  |  | -        // EmployeeRoster[] Roster Data
 | 
	
		
			
				|  |  | -        // DateTime - Roster Start
 | 
	
		
			
				|  |  | -        public List<Tuple<Guid, DateTime, DateTime, EmployeeRosterItem[], DateTime>> Rosters { get; set; }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            if(value is not LeaveValue val)
 | 
	
		
			
				|  |  | -                return DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            if (val.ID == Guid.Empty)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                var tuple = Rosters?.FirstOrDefault(x => x.Item1 == val.Employee);
 | 
	
		
			
				|  |  | -                if (tuple == null)
 | 
	
		
			
				|  |  | -                    return new SolidColorBrush(System.Windows.Media.Colors.Red) { Opacity = 0.8 };
 | 
	
		
			
				|  |  | -                
 | 
	
		
			
				|  |  | -                if ( (!tuple.Item2.IsEmpty() && (tuple.Item2 > val.Date)) || (!tuple.Item3.IsEmpty() && (tuple.Item3 < val.Date)))
 | 
	
		
			
				|  |  | -                    return new SolidColorBrush(System.Windows.Media.Colors.LightGray) { Opacity = 0.8 };
 | 
	
		
			
				|  |  | -                    
 | 
	
		
			
				|  |  | -                var roster = RosterUtils.GetRoster(tuple?.Item4, tuple?.Item5, val.Date);
 | 
	
		
			
				|  |  | -                return (roster?.Enabled == true)
 | 
	
		
			
				|  |  | -                    ? roster?.Duration < 5.0F
 | 
	
		
			
				|  |  | -                        ? new System.Windows.Media.LinearGradientBrush(
 | 
	
		
			
				|  |  | -                            System.Windows.Media.Colors.LightYellow,
 | 
	
		
			
				|  |  | -                            System.Windows.Media.Colors.LightGray,
 | 
	
		
			
				|  |  | -                            90.0F
 | 
	
		
			
				|  |  | -                            ) { Opacity = 0.8 }
 | 
	
		
			
				|  |  | -                        : new SolidColorBrush(System.Windows.Media.Colors.LightYellow) { Opacity = 0.8 }
 | 
	
		
			
				|  |  | -                    : new SolidColorBrush(System.Windows.Media.Colors.LightGray) { Opacity = 0.8 };
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            else
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                if (val.Status != LeaveRequestStatus.Approved)
 | 
	
		
			
				|  |  | -                    return new SolidColorBrush(System.Windows.Media.Colors.DimGray) { Opacity = 0.8 };
 | 
	
		
			
				|  |  | +    public Guid ID { get; set; }
 | 
	
		
			
				|  |  | +    public Guid Employee { get; set; }
 | 
	
		
			
				|  |  | +    public DateTime Date { get; set; }
 | 
	
		
			
				|  |  | +    public Guid Activity { get; set; }
 | 
	
		
			
				|  |  | +    public LeaveRequestStatus Status { get; set; }
 | 
	
		
			
				|  |  | +    public bool Standard { get; set; }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                if (Colors != null)
 | 
	
		
			
				|  |  | -                    if (Colors.ContainsKey(val.Activity))
 | 
	
		
			
				|  |  | -                        return new SolidColorBrush(Colors[val.Activity]) { Opacity = 0.5 };
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +public class LeaveBackgroundConverter : IValueConverter
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    public Dictionary<Guid, Color>? Colors { get; set; }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    // Guid - EmployeeID
 | 
	
		
			
				|  |  | +    // DateTime - Employee Start Date
 | 
	
		
			
				|  |  | +    // DateTime - Employee Finish Date
 | 
	
		
			
				|  |  | +    // EmployeeRoster[] Roster Data
 | 
	
		
			
				|  |  | +    // DateTime - Roster Start
 | 
	
		
			
				|  |  | +    public List<Tuple<Guid, DateTime, DateTime, EmployeeRosterItem[], DateTime>> Rosters { get; set; }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if(value is not LeaveValue val)
 | 
	
		
			
				|  |  |              return DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | +        if (val.ID == Guid.Empty)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            throw new NotImplementedException();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +            var tuple = Rosters?.FirstOrDefault(x => x.Item1 == val.Employee);
 | 
	
		
			
				|  |  | +            if (tuple == null)
 | 
	
		
			
				|  |  | +                return new SolidColorBrush(System.Windows.Media.Colors.Red) { Opacity = 0.8 };
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            if ( (!tuple.Item2.IsEmpty() && (tuple.Item2 > val.Date)) || (!tuple.Item3.IsEmpty() && (tuple.Item3 < val.Date)))
 | 
	
		
			
				|  |  | +                return new SolidColorBrush(System.Windows.Media.Colors.LightGray) { Opacity = 0.8 };
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +            var roster = RosterUtils.GetRoster(tuple?.Item4, tuple?.Item5, val.Date);
 | 
	
		
			
				|  |  | +            return (roster?.Enabled == true)
 | 
	
		
			
				|  |  | +                ? roster?.Duration < 5.0F
 | 
	
		
			
				|  |  | +                    ? new System.Windows.Media.LinearGradientBrush(
 | 
	
		
			
				|  |  | +                        System.Windows.Media.Colors.LightYellow,
 | 
	
		
			
				|  |  | +                        System.Windows.Media.Colors.LightGray,
 | 
	
		
			
				|  |  | +                        90.0F
 | 
	
		
			
				|  |  | +                        ) { Opacity = 0.8 }
 | 
	
		
			
				|  |  | +                    : new SolidColorBrush(System.Windows.Media.Colors.LightYellow) { Opacity = 0.8 }
 | 
	
		
			
				|  |  | +                : new SolidColorBrush(System.Windows.Media.Colors.LightGray) { Opacity = 0.8 };
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        else
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            if (val.Status != LeaveRequestStatus.Approved)
 | 
	
		
			
				|  |  | +                return new SolidColorBrush(System.Windows.Media.Colors.DimGray) { Opacity = 0.8 };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (Colors != null)
 | 
	
		
			
				|  |  | +                if (Colors.ContainsKey(val.Activity))
 | 
	
		
			
				|  |  | +                    return new SolidColorBrush(Colors[val.Activity]) { Opacity = 0.5 };
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public class LeaveForegroundConverter : IValueConverter
 | 
	
		
			
				|  |  | +    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            if (value is LeaveValue val
 | 
	
		
			
				|  |  | -                && val.ID != Guid.Empty 
 | 
	
		
			
				|  |  | -                && val.Status != LeaveRequestStatus.Approved)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                return new SolidColorBrush(Colors.LightGray);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            return DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        throw new NotImplementedException();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | +public class LeaveForegroundConverter : IValueConverter
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (value is LeaveValue val
 | 
	
		
			
				|  |  | +            && val.ID != Guid.Empty 
 | 
	
		
			
				|  |  | +            && val.Status != LeaveRequestStatus.Approved)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            throw new NotImplementedException();
 | 
	
		
			
				|  |  | +            return new SolidColorBrush(Colors.LightGray);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        return DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public class LeaveFontStyleConverter : IValueConverter
 | 
	
		
			
				|  |  | +    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            if (value is LeaveValue val
 | 
	
		
			
				|  |  | -                && val.ID != Guid.Empty
 | 
	
		
			
				|  |  | -                && val.Status != LeaveRequestStatus.Approved)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                return FontStyles.Italic;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            return DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        throw new NotImplementedException();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | +public class LeaveFontStyleConverter : IValueConverter
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (value is LeaveValue val
 | 
	
		
			
				|  |  | +            && val.ID != Guid.Empty
 | 
	
		
			
				|  |  | +            && val.Status != LeaveRequestStatus.Approved)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            throw new NotImplementedException();
 | 
	
		
			
				|  |  | +            return FontStyles.Italic;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        return DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public class LeaveFontWeightConverter : IValueConverter
 | 
	
		
			
				|  |  | +    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            return FontWeights.Bold;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        throw new NotImplementedException();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            throw new NotImplementedException();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +public class LeaveFontWeightConverter : IValueConverter
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        return FontWeights.Bold;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public class LeaveContentConverter : IValueConverter
 | 
	
		
			
				|  |  | +    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -        public Dictionary<Guid, string>? Abbreviations { get; set; }
 | 
	
		
			
				|  |  | +        throw new NotImplementedException();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            if (value is not LeaveValue val)
 | 
	
		
			
				|  |  | -                return DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  | -            return Abbreviations?.ContainsKey(val.Activity) == true ? Abbreviations[val.Activity] : DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +public class LeaveContentConverter : IValueConverter
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    public Dictionary<Guid, string>? Abbreviations { get; set; }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            throw new NotImplementedException();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (value is not LeaveValue val)
 | 
	
		
			
				|  |  | +            return DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  | +        return Abbreviations?.ContainsKey(val.Activity) == true ? Abbreviations[val.Activity] : DependencyProperty.UnsetValue;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    /// <summary>
 | 
	
		
			
				|  |  | -    ///     Interaction logic for LeaveCalendar.xaml
 | 
	
		
			
				|  |  | -    /// </summary>
 | 
	
		
			
				|  |  | -    public partial class LeaveCalendar : UserControl
 | 
	
		
			
				|  |  | +    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -        private readonly CoreTable _activities;
 | 
	
		
			
				|  |  | -        private readonly Dictionary<Guid, string> _activityCodes = new();
 | 
	
		
			
				|  |  | -        private readonly Dictionary<Guid, Color> _activityColors = new();
 | 
	
		
			
				|  |  | -        private readonly Dictionary<Guid, string> _employees = new();
 | 
	
		
			
				|  |  | -        private readonly List<Tuple<Guid, DateTime, DateTime, EmployeeRosterItem[], DateTime>> _rosters = new();
 | 
	
		
			
				|  |  | -        private readonly CoreTable _employeeteams;
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -        private LeaveSettings _settings;
 | 
	
		
			
				|  |  | -        private readonly Dictionary<Guid, string> _teams = new();
 | 
	
		
			
				|  |  | +        throw new NotImplementedException();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/// <summary>
 | 
	
		
			
				|  |  | +///     Interaction logic for LeaveCalendar.xaml
 | 
	
		
			
				|  |  | +/// </summary>
 | 
	
		
			
				|  |  | +public partial class LeaveCalendar : UserControl
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    private readonly CoreTable _activities;
 | 
	
		
			
				|  |  | +    private readonly Dictionary<Guid, string> _activityCodes = new();
 | 
	
		
			
				|  |  | +    private readonly Dictionary<Guid, Color> _activityColors = new();
 | 
	
		
			
				|  |  | +    private readonly Dictionary<Guid, string> _employees = new();
 | 
	
		
			
				|  |  | +    private readonly List<Tuple<Guid, DateTime, DateTime, EmployeeRosterItem[], DateTime>> _rosters = new();
 | 
	
		
			
				|  |  | +    private readonly CoreTable _employeeteams;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    private LeaveSettings _settings;
 | 
	
		
			
				|  |  | +    private readonly Dictionary<Guid, string> _teams = new();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private bool bReady;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private LeaveRequestGrid? lg;
 | 
	
		
			
				|  |  | +    private StandardLeaveGrid? sg;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    public LeaveCalendar()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        InitializeComponent();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //dataGrid.ScrollMode = ScrollMode.Async;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        LoadSettings();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private bool bReady;
 | 
	
		
			
				|  |  | +        StartDate.DateTime = DateTime.Today;
 | 
	
		
			
				|  |  | +        EndDate.DateTime = DateTime.Today.AddYears(1);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private LeaveRequestGrid? lg;
 | 
	
		
			
				|  |  | -        private StandardLeaveGrid? sg;
 | 
	
		
			
				|  |  | +        var setups = new MultiQuery();
 | 
	
		
			
				|  |  | +        setups.Add<EmployeeTeam>(null, null, new SortOrder<EmployeeTeam>(x => x.TeamLink.Code).ThenBy(x => x.EmployeeLink.Name));
 | 
	
		
			
				|  |  | +        setups.Add<Activity>(new Filter<Activity>(x => x.IsLeave).IsEqualTo(true));
 | 
	
		
			
				|  |  | +        setups.Query();
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  | -        public LeaveCalendar()
 | 
	
		
			
				|  |  | +        _employeeteams = setups.Get<EmployeeTeam>();
 | 
	
		
			
				|  |  | +        _activities = setups.Get<Activity>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        _teams = _employeeteams.ToDictionary<EmployeeTeam, Guid, string>(c => c.TeamLink.ID, c => c.TeamLink.Name);
 | 
	
		
			
				|  |  | +        if (_teams.ContainsKey(Guid.Empty))
 | 
	
		
			
				|  |  | +            _teams.Remove(Guid.Empty);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        var teams = _employeeteams.ToDictionary<EmployeeTeam, Guid, string>(c => c.TeamLink.ID, c => c.TeamLink.Name);
 | 
	
		
			
				|  |  | +        teams[CoreUtils.FullGuid] = "Multiple Teams";
 | 
	
		
			
				|  |  | +        Teams.ItemsSource = teams;
 | 
	
		
			
				|  |  | +        Teams.SelectedValue = _settings.GroupID;
 | 
	
		
			
				|  |  | +        ChangeSelectedTeams(_settings.GroupID);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        OnlyShowLeaveBox.IsChecked = _settings.OnlyShowLeave;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        SelectedTeams.ItemsSource = _teams;
 | 
	
		
			
				|  |  | +        foreach (KeyValuePair<Guid, string> pair in SelectedTeams.Items)
 | 
	
		
			
				|  |  | +            if (_settings.SelectedGroups.Contains(pair.Key))
 | 
	
		
			
				|  |  | +                SelectedTeams.SelectedItems.Add(pair);
 | 
	
		
			
				|  |  | +        LoadEmployees(false);
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        foreach (var row in _activities.Rows)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            InitializeComponent();
 | 
	
		
			
				|  |  | +            var id = row.Get<Activity, Guid>(c => c.ID);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            //dataGrid.ScrollMode = ScrollMode.Async;
 | 
	
		
			
				|  |  | +            var color = row.Get<Activity, string>(c => c.Color);
 | 
	
		
			
				|  |  | +            if (!string.IsNullOrWhiteSpace(color))
 | 
	
		
			
				|  |  | +                _activityColors[id] = (Color)ColorConverter.ConvertFromString(color);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            LoadSettings();
 | 
	
		
			
				|  |  | +            var code = Codify(row.Get<Activity, string>(c => c.Description));
 | 
	
		
			
				|  |  | +            _activityCodes[id] = Codify(code);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        var rosterstarts = _employeeteams.ToDictionary<EmployeeTeam, Guid, DateTime>(x => x.EmployeeLink.ID, x => x.EmployeeLink.RosterStart);
 | 
	
		
			
				|  |  | +        var startdates = _employeeteams.ToDictionary<EmployeeTeam, Guid, DateTime>(x => x.EmployeeLink.ID, x => x.EmployeeLink.StartDate);
 | 
	
		
			
				|  |  | +        var finishdates = _employeeteams.ToDictionary<EmployeeTeam, Guid, DateTime>(x => x.EmployeeLink.ID, x => x.EmployeeLink.FinishDate);
 | 
	
		
			
				|  |  | +        var rosters = _employeeteams.ToDictionary<EmployeeTeam, Guid, String>(x => x.EmployeeLink.ID, x => x.EmployeeLink.Roster);
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        foreach (var empid in startdates.Keys)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            var startdate = startdates[empid];
 | 
	
		
			
				|  |  | +            var finishdate = finishdates[empid];
 | 
	
		
			
				|  |  | +            var roster = !String.IsNullOrWhiteSpace(rosters[empid])
 | 
	
		
			
				|  |  | +                ? Serialization.Deserialize<List<EmployeeRosterItem>>(rosters[empid]).ToArray()
 | 
	
		
			
				|  |  | +                : null;
 | 
	
		
			
				|  |  | +            var rosterstart = rosterstarts[empid];
 | 
	
		
			
				|  |  | +            _rosters.Add(new Tuple<Guid, DateTime, DateTime, EmployeeRosterItem[], DateTime>(empid, startdate, finishdate, roster, rosterstart));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        bReady = true;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            StartDate.DateTime = DateTime.Today;
 | 
	
		
			
				|  |  | -            EndDate.DateTime = DateTime.Today.AddYears(1);
 | 
	
		
			
				|  |  | +    private static string Codify(string name)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (string.IsNullOrWhiteSpace(name))
 | 
	
		
			
				|  |  | +            return "??";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        var result = "";
 | 
	
		
			
				|  |  | +        var comps = name.ToUpper().Split(' ');
 | 
	
		
			
				|  |  | +        foreach (var comp in comps)
 | 
	
		
			
				|  |  | +            if (comp.Any())
 | 
	
		
			
				|  |  | +                result += comp.First();
 | 
	
		
			
				|  |  | +        return string.IsNullOrWhiteSpace(result) ? "??" : result;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            var setups = new MultiQuery();
 | 
	
		
			
				|  |  | -            setups.Add<EmployeeTeam>(null, null, new SortOrder<EmployeeTeam>(x => x.TeamLink.Code).ThenBy(x => x.EmployeeLink.Name));
 | 
	
		
			
				|  |  | -            setups.Add<Activity>(new Filter<Activity>(x => x.IsLeave).IsEqualTo(true));
 | 
	
		
			
				|  |  | -            setups.Query();
 | 
	
		
			
				|  |  | -            
 | 
	
		
			
				|  |  | -            _employeeteams = setups.Get<EmployeeTeam>();
 | 
	
		
			
				|  |  | -            _activities = setups.Get<Activity>();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            _teams = _employeeteams.ToDictionary<EmployeeTeam, Guid, string>(c => c.TeamLink.ID, c => c.TeamLink.Name);
 | 
	
		
			
				|  |  | -            if (_teams.ContainsKey(Guid.Empty))
 | 
	
		
			
				|  |  | -                _teams.Remove(Guid.Empty);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            var teams = _employeeteams.ToDictionary<EmployeeTeam, Guid, string>(c => c.TeamLink.ID, c => c.TeamLink.Name);
 | 
	
		
			
				|  |  | -            teams[CoreUtils.FullGuid] = "Multiple Teams";
 | 
	
		
			
				|  |  | -            Teams.ItemsSource = teams;
 | 
	
		
			
				|  |  | -            Teams.SelectedValue = _settings.GroupID;
 | 
	
		
			
				|  |  | -            ChangeSelectedTeams(_settings.GroupID);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            SelectedTeams.ItemsSource = _teams;
 | 
	
		
			
				|  |  | -            foreach (KeyValuePair<Guid, string> pair in SelectedTeams.Items)
 | 
	
		
			
				|  |  | -                if (_settings.SelectedGroups.Contains(pair.Key))
 | 
	
		
			
				|  |  | -                    SelectedTeams.SelectedItems.Add(pair);
 | 
	
		
			
				|  |  | -            LoadEmployees(false);
 | 
	
		
			
				|  |  | -            
 | 
	
		
			
				|  |  | -            foreach (var row in _activities.Rows)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                var id = row.Get<Activity, Guid>(c => c.ID);
 | 
	
		
			
				|  |  | +    [MemberNotNull(nameof(_settings))]
 | 
	
		
			
				|  |  | +    private void LoadSettings()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        _settings = new UserConfiguration<LeaveSettings>().Load();
 | 
	
		
			
				|  |  | +        if (!_settings.SelectedGroups.Any() && _settings.GroupID != Guid.Empty)
 | 
	
		
			
				|  |  | +            _settings.SelectedGroups.Add(_settings.GroupID);
 | 
	
		
			
				|  |  | +        if (_settings.ListSize == 0.0F)
 | 
	
		
			
				|  |  | +            _settings.ListSize = 200.0F;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                var color = row.Get<Activity, string>(c => c.Color);
 | 
	
		
			
				|  |  | -                if (!string.IsNullOrWhiteSpace(color))
 | 
	
		
			
				|  |  | -                    _activityColors[id] = (Color)ColorConverter.ConvertFromString(color);
 | 
	
		
			
				|  |  | +    private void SaveSettings()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (!bReady)
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        try
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            _settings.GroupID = Teams.SelectedValue != null ? (Guid)Teams.SelectedValue : Guid.Empty;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                var code = Codify(row.Get<Activity, string>(c => c.Description));
 | 
	
		
			
				|  |  | -                _activityCodes[id] = Codify(code);
 | 
	
		
			
				|  |  | +            _settings.SelectedGroups.Clear();
 | 
	
		
			
				|  |  | +            foreach (var sel in SelectedTeams.SelectedItems)
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                var grp = (KeyValuePair<Guid, string>)sel;
 | 
	
		
			
				|  |  | +                _settings.SelectedGroups.Add(grp.Key);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            
 | 
	
		
			
				|  |  | -            var rosterstarts = _employeeteams.ToDictionary<EmployeeTeam, Guid, DateTime>(x => x.EmployeeLink.ID, x => x.EmployeeLink.RosterStart);
 | 
	
		
			
				|  |  | -            var startdates = _employeeteams.ToDictionary<EmployeeTeam, Guid, DateTime>(x => x.EmployeeLink.ID, x => x.EmployeeLink.StartDate);
 | 
	
		
			
				|  |  | -            var finishdates = _employeeteams.ToDictionary<EmployeeTeam, Guid, DateTime>(x => x.EmployeeLink.ID, x => x.EmployeeLink.FinishDate);
 | 
	
		
			
				|  |  | -            var rosters = _employeeteams.ToDictionary<EmployeeTeam, Guid, String>(x => x.EmployeeLink.ID, x => x.EmployeeLink.Roster);
 | 
	
		
			
				|  |  | -            
 | 
	
		
			
				|  |  | -            foreach (var empid in startdates.Keys)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            _settings.SelectedEmployees.Clear();
 | 
	
		
			
				|  |  | +            foreach (var sel in SelectedEmployees.SelectedItems)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                var startdate = startdates[empid];
 | 
	
		
			
				|  |  | -                var finishdate = finishdates[empid];
 | 
	
		
			
				|  |  | -                var roster = !String.IsNullOrWhiteSpace(rosters[empid])
 | 
	
		
			
				|  |  | -                    ? Serialization.Deserialize<List<EmployeeRosterItem>>(rosters[empid]).ToArray()
 | 
	
		
			
				|  |  | -                    : null;
 | 
	
		
			
				|  |  | -                var rosterstart = rosterstarts[empid];
 | 
	
		
			
				|  |  | -                _rosters.Add(new Tuple<Guid, DateTime, DateTime, EmployeeRosterItem[], DateTime>(empid, startdate, finishdate, roster, rosterstart));
 | 
	
		
			
				|  |  | +                var grp = (KeyValuePair<Guid, string>)sel;
 | 
	
		
			
				|  |  | +                _settings.SelectedEmployees.Add(grp.Key);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            
 | 
	
		
			
				|  |  | -            bReady = true;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private static string Codify(string name)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            if (string.IsNullOrWhiteSpace(name))
 | 
	
		
			
				|  |  | -                return "??";
 | 
	
		
			
				|  |  | +            if (EmployeeGrid.RowDefinitions[1].ActualHeight != 0.0F)
 | 
	
		
			
				|  |  | +                _settings.ListSize = EmployeeGrid.RowDefinitions[1].ActualHeight;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            var result = "";
 | 
	
		
			
				|  |  | -            var comps = name.ToUpper().Split(' ');
 | 
	
		
			
				|  |  | -            foreach (var comp in comps)
 | 
	
		
			
				|  |  | -                if (comp.Any())
 | 
	
		
			
				|  |  | -                    result += comp.First();
 | 
	
		
			
				|  |  | -            return string.IsNullOrWhiteSpace(result) ? "??" : result;
 | 
	
		
			
				|  |  | +            _settings.OnlyShowLeave = OnlyShowLeaveBox.IsChecked == true;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        [MemberNotNull(nameof(_settings))]
 | 
	
		
			
				|  |  | -        private void LoadSettings()
 | 
	
		
			
				|  |  | +        catch (Exception e)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            _settings = new UserConfiguration<LeaveSettings>().Load();
 | 
	
		
			
				|  |  | -            if (!_settings.SelectedGroups.Any() && _settings.GroupID != Guid.Empty)
 | 
	
		
			
				|  |  | -                _settings.SelectedGroups.Add(_settings.GroupID);
 | 
	
		
			
				|  |  | -            if (_settings.ListSize == 0.0F)
 | 
	
		
			
				|  |  | -                _settings.ListSize = 200.0F;
 | 
	
		
			
				|  |  | +            Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void SaveSettings()
 | 
	
		
			
				|  |  | +        Task.Run(() => { new UserConfiguration<LeaveSettings>().Save(_settings); });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    public void Refresh()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (!bReady)
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        using (new WaitCursor())
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            if (!bReady)
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | -            try
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                _settings.GroupID = Teams.SelectedValue != null ? (Guid)Teams.SelectedValue : Guid.Empty;
 | 
	
		
			
				|  |  | +            _employees.Clear();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                _settings.SelectedGroups.Clear();
 | 
	
		
			
				|  |  | -                foreach (var sel in SelectedTeams.SelectedItems)
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    var grp = (KeyValuePair<Guid, string>)sel;
 | 
	
		
			
				|  |  | -                    _settings.SelectedGroups.Add(grp.Key);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +            var crosstab = new List<LeaveValue>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            MultiQuery query = new MultiQuery();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                _settings.SelectedEmployees.Clear();
 | 
	
		
			
				|  |  | -                foreach (var sel in SelectedEmployees.SelectedItems)
 | 
	
		
			
				|  |  | +            var empfilter = new Filter<LeaveRequest>(x => x.EmployeeLink.ID).IsEqualTo(CoreUtils.FullGuid);
 | 
	
		
			
				|  |  | +            foreach (var sel in SelectedEmployees.Items)
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                var emp = (KeyValuePair<Guid, string>)sel;
 | 
	
		
			
				|  |  | +                if (SelectedEmployees.SelectedItems.Contains(emp))
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                    var grp = (KeyValuePair<Guid, string>)sel;
 | 
	
		
			
				|  |  | -                    _settings.SelectedEmployees.Add(grp.Key);
 | 
	
		
			
				|  |  | +                    empfilter = empfilter.Or(x => x.EmployeeLink.ID).IsEqualTo(emp.Key);
 | 
	
		
			
				|  |  | +                    _employees[emp.Key] = emp.Value;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                if (EmployeeGrid.RowDefinitions[1].ActualHeight != 0.0F)
 | 
	
		
			
				|  |  | -                    _settings.ListSize = EmployeeGrid.RowDefinitions[1].ActualHeight;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            catch (Exception e)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var start = StartDate.DateTime ?? DateTime.Today;
 | 
	
		
			
				|  |  | +            var end = EndDate.DateTime ?? DateTime.Today.AddYears(1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var leavefilter = new Filter<LeaveRequest>(x => x.To).IsGreaterThanOrEqualTo(start)
 | 
	
		
			
				|  |  | +                .And(x => x.From).IsLessThanOrEqualTo(end)
 | 
	
		
			
				|  |  | +                .And(x => x.Status).IsNotEqualTo(LeaveRequestStatus.Rejected);
 | 
	
		
			
				|  |  | +            leavefilter.Ands.Add(empfilter);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            query.Add<LeaveRequest>(
 | 
	
		
			
				|  |  | +                leavefilter,
 | 
	
		
			
				|  |  | +                Columns.None<LeaveRequest>().Add(x => x.ID)
 | 
	
		
			
				|  |  | +                    .Add(x => x.EmployeeLink.ID)
 | 
	
		
			
				|  |  | +                    .Add(x => x.From)
 | 
	
		
			
				|  |  | +                    .Add(x=>x.FromTime)
 | 
	
		
			
				|  |  | +                    .Add(x => x.To)
 | 
	
		
			
				|  |  | +                    .Add(x=>x.ToTime)
 | 
	
		
			
				|  |  | +                    .Add(x => x.LeaveType.ID)
 | 
	
		
			
				|  |  | +                    .Add(x => x.LeaveType.Description)
 | 
	
		
			
				|  |  | +                    .Add(x => x.Status)
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            query.Add<StandardLeave>(
 | 
	
		
			
				|  |  | +                new Filter<StandardLeave>(x => x.To).IsGreaterThanOrEqualTo(start).And(x => x.From).IsLessThanOrEqualTo(end),
 | 
	
		
			
				|  |  | +                Columns.None<StandardLeave>().Add(x => x.ID)
 | 
	
		
			
				|  |  | +                    .Add(x => x.From)
 | 
	
		
			
				|  |  | +                    .Add(x=>x.FromTime)
 | 
	
		
			
				|  |  | +                    .Add(x => x.To)
 | 
	
		
			
				|  |  | +                    .Add(x=>x.ToTime)
 | 
	
		
			
				|  |  | +                    .Add(x => x.LeaveType.ID)
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            query.Query();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var leaverequests = query.Get<LeaveRequest>();
 | 
	
		
			
				|  |  | +            var standardleaves = query.Get<StandardLeave>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            // Set of Employee IDs so that we can restrict the columns only to employees with leave requests.
 | 
	
		
			
				|  |  | +            var employeeSet = new HashSet<Guid>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            foreach (var standardrow in standardleaves.Rows)
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                var id = standardrow.Get<StandardLeave, Guid>(x => x.ID);
 | 
	
		
			
				|  |  | +                var actid = standardrow.Get<StandardLeave, Guid>(x => x.LeaveType.ID);
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                var from = standardrow.Get<StandardLeave, DateTime>(x => x.From);
 | 
	
		
			
				|  |  | +                from = from < start ? start : from;
 | 
	
		
			
				|  |  | +                var to = standardrow.Get<StandardLeave, DateTime>(x => x.To);
 | 
	
		
			
				|  |  | +                to = to > end ? end : to;    
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                for (var date = from; date <= to; date = date.AddDays(1))
 | 
	
		
			
				|  |  | +                    foreach (var empid in _employees.Keys)
 | 
	
		
			
				|  |  | +                        crosstab.Add(new LeaveValue(id, empid, date, actid, LeaveRequestStatus.Approved, true));
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            Task.Run(() => { new UserConfiguration<LeaveSettings>().Save(_settings); });
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -        public void Refresh()
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            if (!bReady)
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | -            
 | 
	
		
			
				|  |  | -            using (new WaitCursor())
 | 
	
		
			
				|  |  | +            foreach (var leaverow in leaverequests.Rows)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                _employees.Clear();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                var crosstab = new List<LeaveValue>();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                MultiQuery query = new MultiQuery();
 | 
	
		
			
				|  |  | +                var id = leaverow.Get<LeaveRequest, Guid>(x => x.ID); 
 | 
	
		
			
				|  |  | +                var empid = leaverow.Get<LeaveRequest, Guid>(x => x.EmployeeLink.ID);
 | 
	
		
			
				|  |  | +                var actid = leaverow.Get<LeaveRequest, Guid>(x => x.LeaveType.ID);
 | 
	
		
			
				|  |  | +                var status = leaverow.Get<LeaveRequest, LeaveRequestStatus>(x => x.Status);
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                var from = leaverow.Get<LeaveRequest, DateTime>(x => x.From);
 | 
	
		
			
				|  |  | +                from = from < start ? start : from;
 | 
	
		
			
				|  |  | +                var to = leaverow.Get<LeaveRequest, DateTime>(x => x.To);
 | 
	
		
			
				|  |  | +                to = to > end ? end : to;
 | 
	
		
			
				|  |  | +                var totime = leaverow.Get<LeaveRequest, TimeSpan>(x => x.ToTime);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                var empfilter = new Filter<LeaveRequest>(x => x.EmployeeLink.ID).IsEqualTo(CoreUtils.FullGuid);
 | 
	
		
			
				|  |  | -                foreach (var sel in SelectedEmployees.Items)
 | 
	
		
			
				|  |  | +                for (var date = from; date < to.Add(totime); date = date.AddDays(1))
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                    var emp = (KeyValuePair<Guid, string>)sel;
 | 
	
		
			
				|  |  | -                    if (SelectedEmployees.SelectedItems.Contains(emp))
 | 
	
		
			
				|  |  | +                    if(status == LeaveRequestStatus.InProgress || status == LeaveRequestStatus.Approved)
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  | -                        empfilter = empfilter.Or(x => x.EmployeeLink.ID).IsEqualTo(emp.Key);
 | 
	
		
			
				|  |  | -                        _employees[emp.Key] = emp.Value;
 | 
	
		
			
				|  |  | +                        employeeSet.Add(empid);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | +                    crosstab.Add(new LeaveValue(id, empid, date, actid, status, false));
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                var start = StartDate.DateTime ?? DateTime.Today;
 | 
	
		
			
				|  |  | -                var end = EndDate.DateTime ?? DateTime.Today.AddYears(1);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                var leavefilter = new Filter<LeaveRequest>(x => x.To).IsGreaterThanOrEqualTo(start)
 | 
	
		
			
				|  |  | -                    .And(x => x.From).IsLessThanOrEqualTo(end)
 | 
	
		
			
				|  |  | -                    .And(x => x.Status).IsNotEqualTo(LeaveRequestStatus.Rejected);
 | 
	
		
			
				|  |  | -                leavefilter.Ands.Add(empfilter);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                query.Add<LeaveRequest>(
 | 
	
		
			
				|  |  | -                    leavefilter,
 | 
	
		
			
				|  |  | -                    Columns.None<LeaveRequest>().Add(x => x.ID)
 | 
	
		
			
				|  |  | -                        .Add(x => x.EmployeeLink.ID)
 | 
	
		
			
				|  |  | -                        .Add(x => x.From)
 | 
	
		
			
				|  |  | -                        .Add(x=>x.FromTime)
 | 
	
		
			
				|  |  | -                        .Add(x => x.To)
 | 
	
		
			
				|  |  | -                        .Add(x=>x.ToTime)
 | 
	
		
			
				|  |  | -                        .Add(x => x.LeaveType.ID)
 | 
	
		
			
				|  |  | -                        .Add(x => x.LeaveType.Description)
 | 
	
		
			
				|  |  | -                        .Add(x => x.Status)
 | 
	
		
			
				|  |  | -                );
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                query.Add<StandardLeave>(
 | 
	
		
			
				|  |  | -                    new Filter<StandardLeave>(x => x.To).IsGreaterThanOrEqualTo(start).And(x => x.From).IsLessThanOrEqualTo(end),
 | 
	
		
			
				|  |  | -                    Columns.None<StandardLeave>().Add(x => x.ID)
 | 
	
		
			
				|  |  | -                        .Add(x => x.From)
 | 
	
		
			
				|  |  | -                        .Add(x=>x.FromTime)
 | 
	
		
			
				|  |  | -                        .Add(x => x.To)
 | 
	
		
			
				|  |  | -                        .Add(x=>x.ToTime)
 | 
	
		
			
				|  |  | -                        .Add(x => x.LeaveType.ID)
 | 
	
		
			
				|  |  | -                );
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                query.Query();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                var leaverequests = query.Get<LeaveRequest>();
 | 
	
		
			
				|  |  | -                var standardleaves = query.Get<StandardLeave>();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                foreach (var standardrow in standardleaves.Rows)
 | 
	
		
			
				|  |  | +            if (_settings.OnlyShowLeave)
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                var toRemove = _employees.Keys.Where(x => !employeeSet.Contains(x));
 | 
	
		
			
				|  |  | +                foreach(var employee in toRemove)
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                    var id = standardrow.Get<StandardLeave, Guid>(x => x.ID);
 | 
	
		
			
				|  |  | -                    var actid = standardrow.Get<StandardLeave, Guid>(x => x.LeaveType.ID);
 | 
	
		
			
				|  |  | -                    
 | 
	
		
			
				|  |  | -                    var from = standardrow.Get<StandardLeave, DateTime>(x => x.From);
 | 
	
		
			
				|  |  | -                    from = from < start ? start : from;
 | 
	
		
			
				|  |  | -                    var to = standardrow.Get<StandardLeave, DateTime>(x => x.To);
 | 
	
		
			
				|  |  | -                    to = to > end ? end : to;    
 | 
	
		
			
				|  |  | -                    
 | 
	
		
			
				|  |  | -                    for (var date = from; date <= to; date = date.AddDays(1))
 | 
	
		
			
				|  |  | -                        foreach (var empid in _employees.Keys)
 | 
	
		
			
				|  |  | -                            crosstab.Add(new LeaveValue(id, empid, date, actid, LeaveRequestStatus.Approved, true));
 | 
	
		
			
				|  |  | +                    _employees.Remove(employee);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            var data = new DataTable();
 | 
	
		
			
				|  |  | +            data.Columns.Add("Date", typeof(DateTime));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                foreach (var leaverow in leaverequests.Rows)
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    var id = leaverow.Get<LeaveRequest, Guid>(x => x.ID); 
 | 
	
		
			
				|  |  | -                    var empid = leaverow.Get<LeaveRequest, Guid>(x => x.EmployeeLink.ID);
 | 
	
		
			
				|  |  | -                    var actid = leaverow.Get<LeaveRequest, Guid>(x => x.LeaveType.ID);
 | 
	
		
			
				|  |  | -                    var status = leaverow.Get<LeaveRequest, LeaveRequestStatus>(x => x.Status);
 | 
	
		
			
				|  |  | -                    
 | 
	
		
			
				|  |  | -                    var from = leaverow.Get<LeaveRequest, DateTime>(x => x.From);
 | 
	
		
			
				|  |  | -                    from = from < start ? start : from;
 | 
	
		
			
				|  |  | -                    var to = leaverow.Get<LeaveRequest, DateTime>(x => x.To);
 | 
	
		
			
				|  |  | -                    to = to > end ? end : to;
 | 
	
		
			
				|  |  | -                    var totime = leaverow.Get<LeaveRequest, TimeSpan>(x => x.ToTime);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    for (var date = from; date < to.Add(totime); date = date.AddDays(1))
 | 
	
		
			
				|  |  | -                        crosstab.Add(new LeaveValue(id, empid, date, actid, status, false));
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                
 | 
	
		
			
				|  |  | -                var data = new DataTable();
 | 
	
		
			
				|  |  | -                data.Columns.Add("Date", typeof(DateTime));
 | 
	
		
			
				|  |  | +            foreach (var employee in _employees.Keys)
 | 
	
		
			
				|  |  | +                data.Columns.Add(employee.ToString(), typeof(object));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +            for (var date = start; date <= end; date = date.AddDays(1))
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                var values = new List<object> { date };
 | 
	
		
			
				|  |  |                  foreach (var employee in _employees.Keys)
 | 
	
		
			
				|  |  | -                    data.Columns.Add(employee.ToString(), typeof(object));
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                for (var date = start; date <= end; date = date.AddDays(1))
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                    var values = new List<object> { date };
 | 
	
		
			
				|  |  | -                    foreach (var employee in _employees.Keys)
 | 
	
		
			
				|  |  | +                    LeaveValue value = null;
 | 
	
		
			
				|  |  | +                    var roster = _rosters.FirstOrDefault(x => x.Item1 == employee);
 | 
	
		
			
				|  |  | +                    if (roster != null)
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  | -                        LeaveValue value = null;
 | 
	
		
			
				|  |  | -                        var roster = _rosters.FirstOrDefault(x => x.Item1 == employee);
 | 
	
		
			
				|  |  | -                        if (roster != null)
 | 
	
		
			
				|  |  | +                        var curroster = RosterUtils.GetRoster(roster.Item4, roster.Item5, date);
 | 
	
		
			
				|  |  | +                        if (curroster?.Enabled == true)
 | 
	
		
			
				|  |  |                          {
 | 
	
		
			
				|  |  | -                            var curroster = RosterUtils.GetRoster(roster.Item4, roster.Item5, date);
 | 
	
		
			
				|  |  | -                            if (curroster?.Enabled == true)
 | 
	
		
			
				|  |  | -                            {
 | 
	
		
			
				|  |  | -                                value = crosstab.FirstOrDefault(x => x.Employee.Equals(employee) && x.Date.Equals(date) && x.Standard);
 | 
	
		
			
				|  |  | -                                if (value == null)
 | 
	
		
			
				|  |  | -                                    value = crosstab.FirstOrDefault(x => x.Employee.Equals(employee) && x.Date.Equals(date) && !x.Standard);
 | 
	
		
			
				|  |  | -                            }
 | 
	
		
			
				|  |  | +                            value = crosstab.FirstOrDefault(x => x.Employee.Equals(employee) && x.Date.Equals(date) && x.Standard);
 | 
	
		
			
				|  |  | +                            if (value == null)
 | 
	
		
			
				|  |  | +                                value = crosstab.FirstOrDefault(x => x.Employee.Equals(employee) && x.Date.Equals(date) && !x.Standard);
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | -                        values.Add(value ?? new LeaveValue(Guid.Empty, employee, date, Guid.Empty, LeaveRequestStatus.InProgress, false));
 | 
	
		
			
				|  |  | -                        
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    data.Rows.Add(values.ToArray());
 | 
	
		
			
				|  |  | +                    values.Add(value ?? new LeaveValue(Guid.Empty, employee, date, Guid.Empty, LeaveRequestStatus.InProgress, false));
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                dataGrid.ItemsSource = data;
 | 
	
		
			
				|  |  | +                data.Rows.Add(values.ToArray());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void DataGrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            e.Column.TextAlignment = TextAlignment.Center;
 | 
	
		
			
				|  |  | -            e.Column.HorizontalHeaderContentAlignment = HorizontalAlignment.Center;
 | 
	
		
			
				|  |  | -            e.Column.ColumnSizer = GridLengthUnitType.None;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            var value = (e.Column.ValueBinding as Binding)!;
 | 
	
		
			
				|  |  | -            if (value.Path.Path.Equals("Date"))
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                e.Column.Width = 100;
 | 
	
		
			
				|  |  | -                e.Column.HeaderStyle = Resources["DateHeaderStyle"] as Style;
 | 
	
		
			
				|  |  | -                e.Column.AllowFocus = false;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            else
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                var style = new Style(typeof(GridCell));
 | 
	
		
			
				|  |  | -                style.Setters.Add(new Setter(BackgroundProperty,
 | 
	
		
			
				|  |  | -                    new Binding(value.Path.Path)
 | 
	
		
			
				|  |  | -                    {
 | 
	
		
			
				|  |  | -                        Converter = new LeaveBackgroundConverter
 | 
	
		
			
				|  |  | -                        {
 | 
	
		
			
				|  |  | -                            Colors = _activityColors,
 | 
	
		
			
				|  |  | -                            Rosters = _rosters
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                    }));
 | 
	
		
			
				|  |  | -                style.Setters.Add(new Setter(ForegroundProperty, new Binding(value.Path.Path) { Converter = new LeaveForegroundConverter() }));
 | 
	
		
			
				|  |  | -                style.Setters.Add(new Setter(FontStyleProperty, new Binding(value.Path.Path) { Converter = new LeaveFontStyleConverter() }));
 | 
	
		
			
				|  |  | -                style.Setters.Add(new Setter(FontWeightProperty, new Binding(value.Path.Path) { Converter = new LeaveFontWeightConverter() }));
 | 
	
		
			
				|  |  | -                e.Column.CellStyle = style;
 | 
	
		
			
				|  |  | -                e.Column.Width = 30;
 | 
	
		
			
				|  |  | -                e.Column.HeaderStyle = Resources["ContentHeaderStyle"] as Style;
 | 
	
		
			
				|  |  | -                e.Column.HeaderText = _employees[Guid.Parse(value.Path.Path)];
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                e.Column.DisplayBinding = new Binding
 | 
	
		
			
				|  |  | -                    { Path = new PropertyPath(e.Column.MappingName), Converter = new LeaveContentConverter { Abbreviations = _activityCodes } };
 | 
	
		
			
				|  |  | -                //e.Column.ValueBinding = new Binding() { Path = new PropertyPath(e.Column.MappingName), Converter = new LeaveContentConverter() };
 | 
	
		
			
				|  |  | -                //e.Column.UseBindingValue = true;
 | 
	
		
			
				|  |  | -                e.Column.AllowFocus = true;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +            dataGrid.ItemsSource = data;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        //private void DataGrid_FilterItemsPopulating(object sender, GridFilterItemsPopulatingEventArgs e)
 | 
	
		
			
				|  |  | -        //{
 | 
	
		
			
				|  |  | -        //    e.FilterControl.FilterMode = FilterMode.AdvancedFilter;
 | 
	
		
			
				|  |  | -        //}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        private void GetSelectionData(out DateTime from, out DateTime to, out Guid[] ids)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            var emps = new List<Guid>();
 | 
	
		
			
				|  |  | -            from = DateTime.MaxValue;
 | 
	
		
			
				|  |  | -            to = DateTime.MinValue;
 | 
	
		
			
				|  |  | -            foreach (var cell in dataGrid.GetSelectedCells())
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                var binding = (cell.Column.ValueBinding as Binding)!;
 | 
	
		
			
				|  |  | -                if (Guid.TryParse(binding.Path.Path, out var emp))
 | 
	
		
			
				|  |  | -                    if (!emps.Contains(emp))
 | 
	
		
			
				|  |  | -                        emps.Add(emp);
 | 
	
		
			
				|  |  | -                var row = (cell.RowData as DataRowView)!;
 | 
	
		
			
				|  |  | -                var date = (DateTime)row.Row.ItemArray.First()!;
 | 
	
		
			
				|  |  | -                if (date < from)
 | 
	
		
			
				|  |  | -                    from = date;
 | 
	
		
			
				|  |  | -                if (date > to)
 | 
	
		
			
				|  |  | -                    to = date;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            ids = emps.Any() ? emps.ToArray() : _employees.Keys.ToArray();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    private void DataGrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        e.Column.TextAlignment = TextAlignment.Center;
 | 
	
		
			
				|  |  | +        e.Column.HorizontalHeaderContentAlignment = HorizontalAlignment.Center;
 | 
	
		
			
				|  |  | +        e.Column.ColumnSizer = GridLengthUnitType.None;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private bool HasData()
 | 
	
		
			
				|  |  | +        var value = (e.Column.ValueBinding as Binding)!;
 | 
	
		
			
				|  |  | +        if (value.Path.Path.Equals("Date"))
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            foreach (var cell in dataGrid.GetSelectedCells())
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                if (!cell.IsDataRowCell)
 | 
	
		
			
				|  |  | -                    continue;
 | 
	
		
			
				|  |  | -                var propertyCollection = dataGrid.View.GetPropertyAccessProvider();
 | 
	
		
			
				|  |  | -                var cellValue = propertyCollection.GetValue(cell.RowData, cell.Column.MappingName);
 | 
	
		
			
				|  |  | -                if (cellValue is LeaveValue leaveValue && leaveValue.ID != Guid.Empty)
 | 
	
		
			
				|  |  | -                    return true;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            return false;
 | 
	
		
			
				|  |  | +            e.Column.Width = 100;
 | 
	
		
			
				|  |  | +            e.Column.HeaderStyle = Resources["DateHeaderStyle"] as Style;
 | 
	
		
			
				|  |  | +            e.Column.AllowFocus = false;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -        private Guid[] GetLeaveIDs(bool standard)
 | 
	
		
			
				|  |  | +        else
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            List<Guid> result = new List<Guid>();
 | 
	
		
			
				|  |  | -            foreach (var cell in dataGrid.GetSelectedCells())
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                if (cell.IsDataRowCell)
 | 
	
		
			
				|  |  | +            var style = new Style(typeof(GridCell));
 | 
	
		
			
				|  |  | +            style.Setters.Add(new Setter(BackgroundProperty,
 | 
	
		
			
				|  |  | +                new Binding(value.Path.Path)
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                        var propertyCollection = dataGrid.View.GetPropertyAccessProvider();
 | 
	
		
			
				|  |  | -                        var cellvalue = propertyCollection.GetValue(cell.RowData, cell.Column.MappingName) as LeaveValue;
 | 
	
		
			
				|  |  | -                        if (cellvalue != null && (cellvalue.ID != Guid.Empty) && (cellvalue.Standard == standard) && !result.Contains(cellvalue.ID))
 | 
	
		
			
				|  |  | -                            result.Add(cellvalue.ID);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            return result.ToArray();
 | 
	
		
			
				|  |  | +                    Converter = new LeaveBackgroundConverter
 | 
	
		
			
				|  |  | +                    {
 | 
	
		
			
				|  |  | +                        Colors = _activityColors,
 | 
	
		
			
				|  |  | +                        Rosters = _rosters
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }));
 | 
	
		
			
				|  |  | +            style.Setters.Add(new Setter(ForegroundProperty, new Binding(value.Path.Path) { Converter = new LeaveForegroundConverter() }));
 | 
	
		
			
				|  |  | +            style.Setters.Add(new Setter(FontStyleProperty, new Binding(value.Path.Path) { Converter = new LeaveFontStyleConverter() }));
 | 
	
		
			
				|  |  | +            style.Setters.Add(new Setter(FontWeightProperty, new Binding(value.Path.Path) { Converter = new LeaveFontWeightConverter() }));
 | 
	
		
			
				|  |  | +            e.Column.CellStyle = style;
 | 
	
		
			
				|  |  | +            e.Column.Width = 30;
 | 
	
		
			
				|  |  | +            e.Column.HeaderStyle = Resources["ContentHeaderStyle"] as Style;
 | 
	
		
			
				|  |  | +            e.Column.HeaderText = _employees[Guid.Parse(value.Path.Path)];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            e.Column.DisplayBinding = new Binding
 | 
	
		
			
				|  |  | +                { Path = new PropertyPath(e.Column.MappingName), Converter = new LeaveContentConverter { Abbreviations = _activityCodes } };
 | 
	
		
			
				|  |  | +            //e.Column.ValueBinding = new Binding() { Path = new PropertyPath(e.Column.MappingName), Converter = new LeaveContentConverter() };
 | 
	
		
			
				|  |  | +            //e.Column.UseBindingValue = true;
 | 
	
		
			
				|  |  | +            e.Column.AllowFocus = true;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private LeaveValue? GetData(GridCellInfo cell)
 | 
	
		
			
				|  |  | +    //private void DataGrid_FilterItemsPopulating(object sender, GridFilterItemsPopulatingEventArgs e)
 | 
	
		
			
				|  |  | +    //{
 | 
	
		
			
				|  |  | +    //    e.FilterControl.FilterMode = FilterMode.AdvancedFilter;
 | 
	
		
			
				|  |  | +    //}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void GetSelectionData(out DateTime from, out DateTime to, out Guid[] ids)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        var emps = new List<Guid>();
 | 
	
		
			
				|  |  | +        from = DateTime.MaxValue;
 | 
	
		
			
				|  |  | +        to = DateTime.MinValue;
 | 
	
		
			
				|  |  | +        foreach (var cell in dataGrid.GetSelectedCells())
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            var binding = (cell.Column.ValueBinding as Binding)!;
 | 
	
		
			
				|  |  | +            if (Guid.TryParse(binding.Path.Path, out var emp))
 | 
	
		
			
				|  |  | +                if (!emps.Contains(emp))
 | 
	
		
			
				|  |  | +                    emps.Add(emp);
 | 
	
		
			
				|  |  | +            var row = (cell.RowData as DataRowView)!;
 | 
	
		
			
				|  |  | +            var date = (DateTime)row.Row.ItemArray.First()!;
 | 
	
		
			
				|  |  | +            if (date < from)
 | 
	
		
			
				|  |  | +                from = date;
 | 
	
		
			
				|  |  | +            if (date > to)
 | 
	
		
			
				|  |  | +                to = date;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        ids = emps.Any() ? emps.ToArray() : _employees.Keys.ToArray();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private bool HasData()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        foreach (var cell in dataGrid.GetSelectedCells())
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              if (!cell.IsDataRowCell)
 | 
	
		
			
				|  |  | -                return null;
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  |              var propertyCollection = dataGrid.View.GetPropertyAccessProvider();
 | 
	
		
			
				|  |  |              var cellValue = propertyCollection.GetValue(cell.RowData, cell.Column.MappingName);
 | 
	
		
			
				|  |  | -            return cellValue is LeaveValue leaveValue && leaveValue.ID != Guid.Empty ? leaveValue : null;
 | 
	
		
			
				|  |  | +            if (cellValue is LeaveValue leaveValue && leaveValue.ID != Guid.Empty)
 | 
	
		
			
				|  |  | +                return true;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private bool HasData(GridCellInfo cell)
 | 
	
		
			
				|  |  | +        return false;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    private Guid[] GetLeaveIDs(bool standard)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        List<Guid> result = new List<Guid>();
 | 
	
		
			
				|  |  | +        foreach (var cell in dataGrid.GetSelectedCells())
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            if (cell?.IsDataRowCell != true)
 | 
	
		
			
				|  |  | -                return false;
 | 
	
		
			
				|  |  | -            var propertyCollection = dataGrid.View.GetPropertyAccessProvider();
 | 
	
		
			
				|  |  | -            var cellValue = propertyCollection.GetValue(cell.RowData, cell.Column.MappingName);
 | 
	
		
			
				|  |  | -            return cellValue is LeaveValue leaveValue && leaveValue.ID != Guid.Empty;
 | 
	
		
			
				|  |  | +            if (cell.IsDataRowCell)
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                    var propertyCollection = dataGrid.View.GetPropertyAccessProvider();
 | 
	
		
			
				|  |  | +                    var cellvalue = propertyCollection.GetValue(cell.RowData, cell.Column.MappingName) as LeaveValue;
 | 
	
		
			
				|  |  | +                    if (cellvalue != null && (cellvalue.ID != Guid.Empty) && (cellvalue.Standard == standard) && !result.Contains(cellvalue.ID))
 | 
	
		
			
				|  |  | +                        result.Add(cellvalue.ID);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        return result.ToArray();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private LeaveValue? GetData(GridCellInfo cell)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (!cell.IsDataRowCell)
 | 
	
		
			
				|  |  | +            return null;
 | 
	
		
			
				|  |  | +        var propertyCollection = dataGrid.View.GetPropertyAccessProvider();
 | 
	
		
			
				|  |  | +        var cellValue = propertyCollection.GetValue(cell.RowData, cell.Column.MappingName);
 | 
	
		
			
				|  |  | +        return cellValue is LeaveValue leaveValue && leaveValue.ID != Guid.Empty ? leaveValue : null;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void CreateLeaveRequestClick(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | +    private bool HasData(GridCellInfo cell)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (cell?.IsDataRowCell != true)
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        var propertyCollection = dataGrid.View.GetPropertyAccessProvider();
 | 
	
		
			
				|  |  | +        var cellValue = propertyCollection.GetValue(cell.RowData, cell.Column.MappingName);
 | 
	
		
			
				|  |  | +        return cellValue is LeaveValue leaveValue && leaveValue.ID != Guid.Empty;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void CreateLeaveRequestClick(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        var activity = ((sender as MenuItem)!.Tag as Activity)!;
 | 
	
		
			
				|  |  | +        GetSelectionData(out var from, out var to, out var ids);
 | 
	
		
			
				|  |  | +        var leaves = new List<LeaveRequest>();
 | 
	
		
			
				|  |  | +        foreach (var id in ids)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            var activity = ((sender as MenuItem)!.Tag as Activity)!;
 | 
	
		
			
				|  |  | -            GetSelectionData(out var from, out var to, out var ids);
 | 
	
		
			
				|  |  | -            var leaves = new List<LeaveRequest>();
 | 
	
		
			
				|  |  | -            foreach (var id in ids)
 | 
	
		
			
				|  |  | +            var leave = new LeaveRequest
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                var leave = new LeaveRequest
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    From = from,
 | 
	
		
			
				|  |  | -                    To = to
 | 
	
		
			
				|  |  | -                };
 | 
	
		
			
				|  |  | -                leave.LeaveType.ID = activity.ID;
 | 
	
		
			
				|  |  | -                leave.EmployeeLink.ID = id;
 | 
	
		
			
				|  |  | -                leaves.Add(leave);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +                From = from,
 | 
	
		
			
				|  |  | +                To = to
 | 
	
		
			
				|  |  | +            };
 | 
	
		
			
				|  |  | +            leave.LeaveType.ID = activity.ID;
 | 
	
		
			
				|  |  | +            leave.EmployeeLink.ID = id;
 | 
	
		
			
				|  |  | +            leaves.Add(leave);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            lg ??= new LeaveRequestGrid();
 | 
	
		
			
				|  |  | -            if (lg.EditItems(leaves.ToArray()))
 | 
	
		
			
				|  |  | +        lg ??= new LeaveRequestGrid();
 | 
	
		
			
				|  |  | +        if (lg.EditItems(leaves.ToArray()))
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            Progress.ShowModal("Checking Forms...", progress =>
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                Progress.ShowModal("Checking Forms...", progress =>
 | 
	
		
			
				|  |  | +                List<LeaveRequestForm> updates = new List<LeaveRequestForm>();
 | 
	
		
			
				|  |  | +                var table = new Client<ActivityForm>().Query(
 | 
	
		
			
				|  |  | +                    new Filter<ActivityForm>(x => x.Activity.ID).IsEqualTo(leaves.First().LeaveType.ID)
 | 
	
		
			
				|  |  | +                        .And(x => x.Form.AppliesTo)
 | 
	
		
			
				|  |  | +                        .IsEqualTo(typeof(LeaveRequest).EntityName().Split('.').Last())
 | 
	
		
			
				|  |  | +                );
 | 
	
		
			
				|  |  | +                foreach (var leave in leaves)
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                    List<LeaveRequestForm> updates = new List<LeaveRequestForm>();
 | 
	
		
			
				|  |  | -                    var table = new Client<ActivityForm>().Query(
 | 
	
		
			
				|  |  | -                        new Filter<ActivityForm>(x => x.Activity.ID).IsEqualTo(leaves.First().LeaveType.ID)
 | 
	
		
			
				|  |  | -                            .And(x => x.Form.AppliesTo)
 | 
	
		
			
				|  |  | -                            .IsEqualTo(typeof(LeaveRequest).EntityName().Split('.').Last())
 | 
	
		
			
				|  |  | -                    );
 | 
	
		
			
				|  |  | -                    foreach (var leave in leaves)
 | 
	
		
			
				|  |  | +                    foreach (var row in table.Rows)
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  | -                        foreach (var row in table.Rows)
 | 
	
		
			
				|  |  | -                        {
 | 
	
		
			
				|  |  | -                            var activityform = row.ToObject<ActivityForm>();
 | 
	
		
			
				|  |  | -                            var leaveform = new LeaveRequestForm();
 | 
	
		
			
				|  |  | -                            leaveform.Parent.ID = leave.ID;
 | 
	
		
			
				|  |  | -                            leaveform.Form.ID = activityform.Form.ID;
 | 
	
		
			
				|  |  | -                            leaveform.Form.Synchronise(activityform.Form);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                            var model =
 | 
	
		
			
				|  |  | -                                new DigitalFormDataModel<LeaveRequest, LeaveRequestLink, LeaveRequestForm>(leave, leaveform, []);
 | 
	
		
			
				|  |  | -                            leaveform.Description = model.EvaluateExpression(activityform.Form.DescriptionExpression) ?? activityform.Form.Description;
 | 
	
		
			
				|  |  | -                            updates.Add(leaveform);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | +                        var activityform = row.ToObject<ActivityForm>();
 | 
	
		
			
				|  |  | +                        var leaveform = new LeaveRequestForm();
 | 
	
		
			
				|  |  | +                        leaveform.Parent.ID = leave.ID;
 | 
	
		
			
				|  |  | +                        leaveform.Form.ID = activityform.Form.ID;
 | 
	
		
			
				|  |  | +                        leaveform.Form.Synchronise(activityform.Form);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        var model =
 | 
	
		
			
				|  |  | +                            new DigitalFormDataModel<LeaveRequest, LeaveRequestLink, LeaveRequestForm>(leave, leaveform, []);
 | 
	
		
			
				|  |  | +                        leaveform.Description = model.EvaluateExpression(activityform.Form.DescriptionExpression) ?? activityform.Form.Description;
 | 
	
		
			
				|  |  | +                        updates.Add(leaveform);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    if (updates.Any())
 | 
	
		
			
				|  |  | -                    {
 | 
	
		
			
				|  |  | -                        progress.Report("Saving forms...");
 | 
	
		
			
				|  |  | -                        new Client<LeaveRequestForm>().Save(updates, "Created from Leave Calendar");
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                });
 | 
	
		
			
				|  |  | -                Refresh();
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +                if (updates.Any())
 | 
	
		
			
				|  |  | +                {
 | 
	
		
			
				|  |  | +                    progress.Report("Saving forms...");
 | 
	
		
			
				|  |  | +                    new Client<LeaveRequestForm>().Save(updates, "Created from Leave Calendar");
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            Refresh();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    private void CreateStandardLeaveClick(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        GetSelectionData(out var from, out var to, out var ids);
 | 
	
		
			
				|  |  | +        var leave = new StandardLeave
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            From = from,
 | 
	
		
			
				|  |  | +            To = to
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        sg ??= new StandardLeaveGrid();
 | 
	
		
			
				|  |  | +        if (sg.EditItems(new StandardLeave[] { leave }))
 | 
	
		
			
				|  |  | +            Refresh();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private IEnumerable<LeaveRequest> GetSelectedLeaveRequests()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  | -        private void CreateStandardLeaveClick(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | +        var ids = GetLeaveIDs(false);
 | 
	
		
			
				|  |  | +        if (ids.Any())
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            lg ??= new LeaveRequests();
 | 
	
		
			
				|  |  | +            var table = new Client<LeaveRequest>().Query(
 | 
	
		
			
				|  |  | +                    new Filter<LeaveRequest>(x => x.ID).InList(ids),
 | 
	
		
			
				|  |  | +                    lg.LoadEditorColumns()
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            var result = table.Rows.Select(x => x.ToObject<LeaveRequest>()).ToArray();
 | 
	
		
			
				|  |  | +            return result;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return new LeaveRequest[] { };
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private IEnumerable<StandardLeave> GetSelectedStandardLeaves()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        var ids = GetLeaveIDs(true);
 | 
	
		
			
				|  |  | +        if (ids.Any())
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            GetSelectionData(out var from, out var to, out var ids);
 | 
	
		
			
				|  |  | -            var leave = new StandardLeave
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                From = from,
 | 
	
		
			
				|  |  | -                To = to
 | 
	
		
			
				|  |  | -            };
 | 
	
		
			
				|  |  |              sg ??= new StandardLeaveGrid();
 | 
	
		
			
				|  |  | -            if (sg.EditItems(new StandardLeave[] { leave }))
 | 
	
		
			
				|  |  | -                Refresh();
 | 
	
		
			
				|  |  | +            var table = new Client<StandardLeave>().Query(
 | 
	
		
			
				|  |  | +                new Filter<StandardLeave>(x => x.ID).InList(ids),
 | 
	
		
			
				|  |  | +                sg.LoadEditorColumns()
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            var result = table.Rows.Select(x => x.ToObject<StandardLeave>()).ToArray();
 | 
	
		
			
				|  |  | +            return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private IEnumerable<LeaveRequest> GetSelectedLeaveRequests()
 | 
	
		
			
				|  |  | +        return new StandardLeave[] { };        
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void EditLeaveClick(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        var requests = GetSelectedLeaveRequests().ToArray();
 | 
	
		
			
				|  |  | +        if (requests.Any())
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            
 | 
	
		
			
				|  |  | -            var ids = GetLeaveIDs(false);
 | 
	
		
			
				|  |  | -            if (ids.Any())
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                lg ??= new LeaveRequests();
 | 
	
		
			
				|  |  | -                var table = new Client<LeaveRequest>().Query(
 | 
	
		
			
				|  |  | -                        new Filter<LeaveRequest>(x => x.ID).InList(ids),
 | 
	
		
			
				|  |  | -                        lg.LoadEditorColumns()
 | 
	
		
			
				|  |  | -                );
 | 
	
		
			
				|  |  | -                var result = table.Rows.Select(x => x.ToObject<LeaveRequest>()).ToArray();
 | 
	
		
			
				|  |  | -                return result;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +            lg ??= new LeaveRequests();
 | 
	
		
			
				|  |  | +            if (lg.EditItems(requests))
 | 
	
		
			
				|  |  | +                Refresh();
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            return new LeaveRequest[] { };
 | 
	
		
			
				|  |  | +        var standards = GetSelectedStandardLeaves().ToArray();
 | 
	
		
			
				|  |  | +        if (standards.Any())
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            sg ??= new StandardLeaveGrid();
 | 
	
		
			
				|  |  | +            if (sg.EditItems(standards))
 | 
	
		
			
				|  |  | +                Refresh();
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private IEnumerable<StandardLeave> GetSelectedStandardLeaves()
 | 
	
		
			
				|  |  | +        MessageBox.Show("Nothing to edit!");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void DeleteLeaveClick(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        var requests = GetSelectedLeaveRequests().ToArray();
 | 
	
		
			
				|  |  | +        if (requests.Any())
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            var ids = GetLeaveIDs(true);
 | 
	
		
			
				|  |  | -            if (ids.Any())
 | 
	
		
			
				|  |  | +            if (MessageBox.Show("Delete Leave Request  Information?", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning) ==
 | 
	
		
			
				|  |  | +                MessageBoxResult.Yes)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                sg ??= new StandardLeaveGrid();
 | 
	
		
			
				|  |  | -                var table = new Client<StandardLeave>().Query(
 | 
	
		
			
				|  |  | -                    new Filter<StandardLeave>(x => x.ID).InList(ids),
 | 
	
		
			
				|  |  | -                    sg.LoadEditorColumns()
 | 
	
		
			
				|  |  | -                );
 | 
	
		
			
				|  |  | -                var result = table.Rows.Select(x => x.ToObject<StandardLeave>()).ToArray();
 | 
	
		
			
				|  |  | -                return result;
 | 
	
		
			
				|  |  | +                using (new WaitCursor())
 | 
	
		
			
				|  |  | +                    new Client<LeaveRequest>().Delete(requests, "Deleted from Calendar");
 | 
	
		
			
				|  |  | +                Refresh();
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            return new StandardLeave[] { };        
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        private void EditLeaveClick(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        var standards = GetSelectedStandardLeaves().ToArray();
 | 
	
		
			
				|  |  | +        if (standards.Any())
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            var requests = GetSelectedLeaveRequests().ToArray();
 | 
	
		
			
				|  |  | -            if (requests.Any())
 | 
	
		
			
				|  |  | +            if (MessageBox.Show("Delete Standard Leave Information?", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning) ==
 | 
	
		
			
				|  |  | +                MessageBoxResult.Yes)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                lg ??= new LeaveRequests();
 | 
	
		
			
				|  |  | -                if (lg.EditItems(requests))
 | 
	
		
			
				|  |  | -                    Refresh();
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | +                using (new WaitCursor())
 | 
	
		
			
				|  |  | +                    new Client<StandardLeave>().Delete(standards, "Deleted from Calendar");
 | 
	
		
			
				|  |  | +                Refresh();
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            var standards = GetSelectedStandardLeaves().ToArray();
 | 
	
		
			
				|  |  | -            if (standards.Any())
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                sg ??= new StandardLeaveGrid();
 | 
	
		
			
				|  |  | -                if (sg.EditItems(standards))
 | 
	
		
			
				|  |  | -                    Refresh();
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +        MessageBox.Show("Nothing to delete!");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            MessageBox.Show("Nothing to edit!");
 | 
	
		
			
				|  |  | +    // private void DataGrid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
 | 
	
		
			
				|  |  | +    // {
 | 
	
		
			
				|  |  | +    //     if (e.RightButton == MouseButtonState.Pressed)
 | 
	
		
			
				|  |  | +    //     {
 | 
	
		
			
				|  |  | +    //         var vc = dataGrid.GetVisualContainer();
 | 
	
		
			
				|  |  | +    //         var point = e.GetPosition(vc);
 | 
	
		
			
				|  |  | +    //         var rci = vc.PointToCellRowColumnIndex(point);
 | 
	
		
			
				|  |  | +    //
 | 
	
		
			
				|  |  | +    //         if (rci.RowIndex == 0 || rci.ColumnIndex == 0)
 | 
	
		
			
				|  |  | +    //             return;
 | 
	
		
			
				|  |  | +    //
 | 
	
		
			
				|  |  | +    //         var menu = new ContextMenu();
 | 
	
		
			
				|  |  | +    //         if (!HasData(dataGrid.CurrentCellInfo))
 | 
	
		
			
				|  |  | +    //             foreach (var row in _activities.Rows)
 | 
	
		
			
				|  |  | +    //             {
 | 
	
		
			
				|  |  | +    //                 var createleave = new MenuItem
 | 
	
		
			
				|  |  | +    //                 {
 | 
	
		
			
				|  |  | +    //                     Header = row.Get<Activity, string>(c => c.Description),
 | 
	
		
			
				|  |  | +    //                     Tag = row.ToObject<Activity>()
 | 
	
		
			
				|  |  | +    //                 };
 | 
	
		
			
				|  |  | +    //                 createleave.Click += CreateLeaveRequestClick;
 | 
	
		
			
				|  |  | +    //                 menu.Items.Add(createleave);
 | 
	
		
			
				|  |  | +    //             }
 | 
	
		
			
				|  |  | +    //
 | 
	
		
			
				|  |  | +    //         if (HasData())
 | 
	
		
			
				|  |  | +    //         {
 | 
	
		
			
				|  |  | +    //             var deleteleave = new MenuItem { Header = "Delete Leave" };
 | 
	
		
			
				|  |  | +    //             deleteleave.Click += DeleteLeaveClick;
 | 
	
		
			
				|  |  | +    //             menu.Items.Add(deleteleave);
 | 
	
		
			
				|  |  | +    //         }
 | 
	
		
			
				|  |  | +    //
 | 
	
		
			
				|  |  | +    //         dataGrid.ContextMenu = menu;
 | 
	
		
			
				|  |  | +    //         menu.IsOpen = true;
 | 
	
		
			
				|  |  | +    //     }
 | 
	
		
			
				|  |  | +    // }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void DataGrid_ContextMenuOpening(object sender, ContextMenuEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        var vc = dataGrid.GetVisualContainer();
 | 
	
		
			
				|  |  | +        var p = Mouse.GetPosition(vc);
 | 
	
		
			
				|  |  | +        var rci = vc.PointToCellRowColumnIndex(p);
 | 
	
		
			
				|  |  | +        if (rci.RowIndex < 1 || rci.ColumnIndex < 1)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            e.Handled = true;
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void DeleteLeaveClick(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | +        dataGrid.ContextMenu.Items.Clear();
 | 
	
		
			
				|  |  | +        var bCreate = !HasData(dataGrid.CurrentCellInfo);
 | 
	
		
			
				|  |  | +        var bEdit = HasData();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (bCreate)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            var requests = GetSelectedLeaveRequests().ToArray();
 | 
	
		
			
				|  |  | -            if (requests.Any())
 | 
	
		
			
				|  |  | +            var createleaveheader = new MenuItem { Header = "Create Leave Request" };
 | 
	
		
			
				|  |  | +            foreach (var row in _activities.Rows)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                if (MessageBox.Show("Delete Leave Request  Information?", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning) ==
 | 
	
		
			
				|  |  | -                    MessageBoxResult.Yes)
 | 
	
		
			
				|  |  | +                var createleave = new MenuItem
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                    using (new WaitCursor())
 | 
	
		
			
				|  |  | -                        new Client<LeaveRequest>().Delete(requests, "Deleted from Calendar");
 | 
	
		
			
				|  |  | -                    Refresh();
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | +                    Header = row.Get<Activity, string>(c => c.Description),
 | 
	
		
			
				|  |  | +                    Tag = row.ToObject<Activity>()
 | 
	
		
			
				|  |  | +                };
 | 
	
		
			
				|  |  | +                createleave.Click += CreateLeaveRequestClick;
 | 
	
		
			
				|  |  | +                createleaveheader.Items.Add(createleave);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            dataGrid.ContextMenu.Items.Add(createleaveheader);
 | 
	
		
			
				|  |  |              
 | 
	
		
			
				|  |  | -            var standards = GetSelectedStandardLeaves().ToArray();
 | 
	
		
			
				|  |  | -            if (standards.Any())
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                if (MessageBox.Show("Delete Standard Leave Information?", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning) ==
 | 
	
		
			
				|  |  | -                    MessageBoxResult.Yes)
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    using (new WaitCursor())
 | 
	
		
			
				|  |  | -                        new Client<StandardLeave>().Delete(standards, "Deleted from Calendar");
 | 
	
		
			
				|  |  | -                    Refresh();
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            MessageBox.Show("Nothing to delete!");
 | 
	
		
			
				|  |  | +            dataGrid.ContextMenu.Items.Add(new Separator());
 | 
	
		
			
				|  |  | +            var createstandardleave = new MenuItem { Header = "Create Standard Leave" };
 | 
	
		
			
				|  |  | +            createstandardleave.Click += CreateStandardLeaveClick;
 | 
	
		
			
				|  |  | +            dataGrid.ContextMenu.Items.Add(createstandardleave);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        // private void DataGrid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
 | 
	
		
			
				|  |  | -        // {
 | 
	
		
			
				|  |  | -        //     if (e.RightButton == MouseButtonState.Pressed)
 | 
	
		
			
				|  |  | -        //     {
 | 
	
		
			
				|  |  | -        //         var vc = dataGrid.GetVisualContainer();
 | 
	
		
			
				|  |  | -        //         var point = e.GetPosition(vc);
 | 
	
		
			
				|  |  | -        //         var rci = vc.PointToCellRowColumnIndex(point);
 | 
	
		
			
				|  |  | -        //
 | 
	
		
			
				|  |  | -        //         if (rci.RowIndex == 0 || rci.ColumnIndex == 0)
 | 
	
		
			
				|  |  | -        //             return;
 | 
	
		
			
				|  |  | -        //
 | 
	
		
			
				|  |  | -        //         var menu = new ContextMenu();
 | 
	
		
			
				|  |  | -        //         if (!HasData(dataGrid.CurrentCellInfo))
 | 
	
		
			
				|  |  | -        //             foreach (var row in _activities.Rows)
 | 
	
		
			
				|  |  | -        //             {
 | 
	
		
			
				|  |  | -        //                 var createleave = new MenuItem
 | 
	
		
			
				|  |  | -        //                 {
 | 
	
		
			
				|  |  | -        //                     Header = row.Get<Activity, string>(c => c.Description),
 | 
	
		
			
				|  |  | -        //                     Tag = row.ToObject<Activity>()
 | 
	
		
			
				|  |  | -        //                 };
 | 
	
		
			
				|  |  | -        //                 createleave.Click += CreateLeaveRequestClick;
 | 
	
		
			
				|  |  | -        //                 menu.Items.Add(createleave);
 | 
	
		
			
				|  |  | -        //             }
 | 
	
		
			
				|  |  | -        //
 | 
	
		
			
				|  |  | -        //         if (HasData())
 | 
	
		
			
				|  |  | -        //         {
 | 
	
		
			
				|  |  | -        //             var deleteleave = new MenuItem { Header = "Delete Leave" };
 | 
	
		
			
				|  |  | -        //             deleteleave.Click += DeleteLeaveClick;
 | 
	
		
			
				|  |  | -        //             menu.Items.Add(deleteleave);
 | 
	
		
			
				|  |  | -        //         }
 | 
	
		
			
				|  |  | -        //
 | 
	
		
			
				|  |  | -        //         dataGrid.ContextMenu = menu;
 | 
	
		
			
				|  |  | -        //         menu.IsOpen = true;
 | 
	
		
			
				|  |  | -        //     }
 | 
	
		
			
				|  |  | -        // }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        private void DataGrid_ContextMenuOpening(object sender, ContextMenuEventArgs e)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            var vc = dataGrid.GetVisualContainer();
 | 
	
		
			
				|  |  | -            var p = Mouse.GetPosition(vc);
 | 
	
		
			
				|  |  | -            var rci = vc.PointToCellRowColumnIndex(p);
 | 
	
		
			
				|  |  | -            if (rci.RowIndex < 1 || rci.ColumnIndex < 1)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                e.Handled = true;
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +        if (bEdit && bCreate)
 | 
	
		
			
				|  |  | +            dataGrid.ContextMenu.Items.Add(new Separator());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            dataGrid.ContextMenu.Items.Clear();
 | 
	
		
			
				|  |  | -            var bCreate = !HasData(dataGrid.CurrentCellInfo);
 | 
	
		
			
				|  |  | -            var bEdit = HasData();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (bCreate)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                var createleaveheader = new MenuItem { Header = "Create Leave Request" };
 | 
	
		
			
				|  |  | -                foreach (var row in _activities.Rows)
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    var createleave = new MenuItem
 | 
	
		
			
				|  |  | -                    {
 | 
	
		
			
				|  |  | -                        Header = row.Get<Activity, string>(c => c.Description),
 | 
	
		
			
				|  |  | -                        Tag = row.ToObject<Activity>()
 | 
	
		
			
				|  |  | -                    };
 | 
	
		
			
				|  |  | -                    createleave.Click += CreateLeaveRequestClick;
 | 
	
		
			
				|  |  | -                    createleaveheader.Items.Add(createleave);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                dataGrid.ContextMenu.Items.Add(createleaveheader);
 | 
	
		
			
				|  |  | -                
 | 
	
		
			
				|  |  | -                dataGrid.ContextMenu.Items.Add(new Separator());
 | 
	
		
			
				|  |  | -                var createstandardleave = new MenuItem { Header = "Create Standard Leave" };
 | 
	
		
			
				|  |  | -                createstandardleave.Click += CreateStandardLeaveClick;
 | 
	
		
			
				|  |  | -                dataGrid.ContextMenu.Items.Add(createstandardleave);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +        if (bEdit)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            var editleave = new MenuItem { Header = "Edit Leave" };
 | 
	
		
			
				|  |  | +            editleave.Click += EditLeaveClick;
 | 
	
		
			
				|  |  | +            dataGrid.ContextMenu.Items.Add(editleave);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (bEdit && bCreate)
 | 
	
		
			
				|  |  | -                dataGrid.ContextMenu.Items.Add(new Separator());
 | 
	
		
			
				|  |  | +            dataGrid.ContextMenu.Items.Add(new Separator());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +            var deleteleave = new MenuItem { Header = "Delete Leave" };
 | 
	
		
			
				|  |  | +            deleteleave.Click += DeleteLeaveClick;
 | 
	
		
			
				|  |  | +            dataGrid.ContextMenu.Items.Add(deleteleave);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (bEdit)
 | 
	
		
			
				|  |  | +            var cell = GetData(dataGrid.CurrentCellInfo); // not-null because bEdit.
 | 
	
		
			
				|  |  | +            if (cell != null)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                var editleave = new MenuItem { Header = "Edit Leave" };
 | 
	
		
			
				|  |  | -                editleave.Click += EditLeaveClick;
 | 
	
		
			
				|  |  | -                dataGrid.ContextMenu.Items.Add(editleave);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |                  dataGrid.ContextMenu.Items.Add(new Separator());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                var deleteleave = new MenuItem { Header = "Delete Leave" };
 | 
	
		
			
				|  |  | -                deleteleave.Click += DeleteLeaveClick;
 | 
	
		
			
				|  |  | -                dataGrid.ContextMenu.Items.Add(deleteleave);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                var cell = GetData(dataGrid.CurrentCellInfo); // not-null because bEdit.
 | 
	
		
			
				|  |  | -                if (cell != null)
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    dataGrid.ContextMenu.Items.Add(new Separator());
 | 
	
		
			
				|  |  | -                    var formsItem = new MenuItem { Header = "Digital Forms" };
 | 
	
		
			
				|  |  | -                    DynamicGridUtils.PopulateFormMenu<LeaveRequestForm, LeaveRequest, LeaveRequestLink>(
 | 
	
		
			
				|  |  | -                        formsItem,
 | 
	
		
			
				|  |  | -                        cell.ID,
 | 
	
		
			
				|  |  | -                        () => new Client<LeaveRequest>().Load(new Filter<LeaveRequest>(x => x.ID).IsEqualTo(cell.ID)).First());
 | 
	
		
			
				|  |  | -                    dataGrid.ContextMenu.Items.Add(formsItem);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +                var formsItem = new MenuItem { Header = "Digital Forms" };
 | 
	
		
			
				|  |  | +                DynamicGridUtils.PopulateFormMenu<LeaveRequestForm, LeaveRequest, LeaveRequestLink>(
 | 
	
		
			
				|  |  | +                    formsItem,
 | 
	
		
			
				|  |  | +                    cell.ID,
 | 
	
		
			
				|  |  | +                    () => new Client<LeaveRequest>().Load(new Filter<LeaveRequest>(x => x.ID).IsEqualTo(cell.ID)).First());
 | 
	
		
			
				|  |  | +                dataGrid.ContextMenu.Items.Add(formsItem);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void DateTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (!bReady)
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        Refresh();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void DateTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 | 
	
		
			
				|  |  | +    private void SyncSelectedTeams(Guid teamid)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        var bOldReady = bReady;
 | 
	
		
			
				|  |  | +        bReady = false;
 | 
	
		
			
				|  |  | +        if (teamid != CoreUtils.FullGuid)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            if (!bReady)
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | -            Refresh();
 | 
	
		
			
				|  |  | +            SelectedTeams.SelectedItems.Clear();
 | 
	
		
			
				|  |  | +            foreach (KeyValuePair<Guid, string> sel in SelectedTeams.Items)
 | 
	
		
			
				|  |  | +                if (sel.Key == teamid)
 | 
	
		
			
				|  |  | +                    SelectedTeams.SelectedItems.Add(sel);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void SyncSelectedTeams(Guid teamid)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            var bOldReady = bReady;
 | 
	
		
			
				|  |  | -            bReady = false;
 | 
	
		
			
				|  |  | -            if (teamid != CoreUtils.FullGuid)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                SelectedTeams.SelectedItems.Clear();
 | 
	
		
			
				|  |  | -                foreach (KeyValuePair<Guid, string> sel in SelectedTeams.Items)
 | 
	
		
			
				|  |  | -                    if (sel.Key == teamid)
 | 
	
		
			
				|  |  | -                        SelectedTeams.SelectedItems.Add(sel);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +        LoadEmployees(true);
 | 
	
		
			
				|  |  | +        bReady = bOldReady;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            LoadEmployees(true);
 | 
	
		
			
				|  |  | -            bReady = bOldReady;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    private void GroupsSelectionChanged(object sender, SelectionChangedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (Teams.SelectedValue == null)
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void GroupsSelectionChanged(object sender, SelectionChangedEventArgs e)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            if (Teams.SelectedValue == null)
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | +        var teamid = (Guid)Teams.SelectedValue;
 | 
	
		
			
				|  |  | +        ChangeSelectedTeams(teamid);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            var teamid = (Guid)Teams.SelectedValue;
 | 
	
		
			
				|  |  | -            ChangeSelectedTeams(teamid);
 | 
	
		
			
				|  |  | +        SyncSelectedTeams(teamid);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            SyncSelectedTeams(teamid);
 | 
	
		
			
				|  |  | +    private void ChangeSelectedTeams(Guid teamid)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (teamid == CoreUtils.FullGuid)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            EmployeeGrid.RowDefinitions[1].Height = new GridLength(_settings.ListSize, GridUnitType.Pixel);
 | 
	
		
			
				|  |  | +            EmployeeGrid.RowDefinitions[2].Height = new GridLength(1, GridUnitType.Auto);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        private void ChangeSelectedTeams(Guid teamid)
 | 
	
		
			
				|  |  | +        else
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            if (teamid == CoreUtils.FullGuid)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                EmployeeGrid.RowDefinitions[1].Height = new GridLength(_settings.ListSize, GridUnitType.Pixel);
 | 
	
		
			
				|  |  | -                EmployeeGrid.RowDefinitions[2].Height = new GridLength(1, GridUnitType.Auto);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            else
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                var oldbReady = bReady;
 | 
	
		
			
				|  |  | -                bReady = false;
 | 
	
		
			
				|  |  | -                EmployeeGrid.RowDefinitions[1].Height = new GridLength(0, GridUnitType.Pixel);
 | 
	
		
			
				|  |  | -                EmployeeGrid.RowDefinitions[2].Height = new GridLength(0, GridUnitType.Pixel);
 | 
	
		
			
				|  |  | -                bReady = oldbReady;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            //bHandled = false;
 | 
	
		
			
				|  |  | +            var oldbReady = bReady;
 | 
	
		
			
				|  |  | +            bReady = false;
 | 
	
		
			
				|  |  | +            EmployeeGrid.RowDefinitions[1].Height = new GridLength(0, GridUnitType.Pixel);
 | 
	
		
			
				|  |  | +            EmployeeGrid.RowDefinitions[2].Height = new GridLength(0, GridUnitType.Pixel);
 | 
	
		
			
				|  |  | +            bReady = oldbReady;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        //bHandled = false;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        //bool bHandled = false;
 | 
	
		
			
				|  |  | +    //bool bHandled = false;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        //private void SelectedTeams_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 | 
	
		
			
				|  |  | -        //{
 | 
	
		
			
				|  |  | -        //    if (!bReady)
 | 
	
		
			
				|  |  | -        //        return;
 | 
	
		
			
				|  |  | +    //private void SelectedTeams_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 | 
	
		
			
				|  |  | +    //{
 | 
	
		
			
				|  |  | +    //    if (!bReady)
 | 
	
		
			
				|  |  | +    //        return;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        //    if (!bHandled)
 | 
	
		
			
				|  |  | -        //        LoadEmployees();
 | 
	
		
			
				|  |  | -        //    bHandled = !bHandled;
 | 
	
		
			
				|  |  | -        //}
 | 
	
		
			
				|  |  | +    //    if (!bHandled)
 | 
	
		
			
				|  |  | +    //        LoadEmployees();
 | 
	
		
			
				|  |  | +    //    bHandled = !bHandled;
 | 
	
		
			
				|  |  | +    //}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void SelectedTeams_ItemChecked(object sender, ItemCheckedEventArgs e)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            if (!bReady)
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | -            LoadEmployees(true);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        private void LoadEmployees(bool selectall)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            var emps = new Dictionary<Guid, string>();
 | 
	
		
			
				|  |  | -            foreach (var pair in SelectedTeams.SelectedItems)
 | 
	
		
			
				|  |  | -                if (pair != null)
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    var key = ((KeyValuePair<Guid, string>)pair).Key;
 | 
	
		
			
				|  |  | -                    foreach (var row in _employeeteams.Rows.Where(r =>
 | 
	
		
			
				|  |  | -                                 r.Get<EmployeeTeam, Guid>(c => c.TeamLink.ID).Equals(key) || key.Equals(CoreUtils.FullGuid)))
 | 
	
		
			
				|  |  | -                        emps[row.Get<EmployeeTeam, Guid>(c => c.EmployeeLink.ID)] = row.Get<EmployeeTeam, string>(c => c.EmployeeLink.Name);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +    private void SelectedTeams_ItemChecked(object sender, ItemCheckedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (!bReady)
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        LoadEmployees(true);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            var bOldReady = bReady;
 | 
	
		
			
				|  |  | -            bReady = false;
 | 
	
		
			
				|  |  | -            SelectedEmployees.ItemsSource = emps;
 | 
	
		
			
				|  |  | -            foreach (var item in SelectedEmployees.Items)
 | 
	
		
			
				|  |  | -            {
 | 
	
		
			
				|  |  | -                var pair = (KeyValuePair<Guid, string>)item;
 | 
	
		
			
				|  |  | -                if (_settings.SelectedEmployees.Contains(pair.Key) || selectall)
 | 
	
		
			
				|  |  | -                    SelectedEmployees.SelectedItems.Add(item);
 | 
	
		
			
				|  |  | +    private void LoadEmployees(bool selectall)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        var emps = new Dictionary<Guid, string>();
 | 
	
		
			
				|  |  | +        foreach (var pair in SelectedTeams.SelectedItems)
 | 
	
		
			
				|  |  | +            if (pair != null)
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                var key = ((KeyValuePair<Guid, string>)pair).Key;
 | 
	
		
			
				|  |  | +                foreach (var row in _employeeteams.Rows.Where(r =>
 | 
	
		
			
				|  |  | +                             r.Get<EmployeeTeam, Guid>(c => c.TeamLink.ID).Equals(key) || key.Equals(CoreUtils.FullGuid)))
 | 
	
		
			
				|  |  | +                    emps[row.Get<EmployeeTeam, Guid>(c => c.EmployeeLink.ID)] = row.Get<EmployeeTeam, string>(c => c.EmployeeLink.Name);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            bReady = bOldReady;
 | 
	
		
			
				|  |  | -            SaveSettings();
 | 
	
		
			
				|  |  | -            Refresh();
 | 
	
		
			
				|  |  | +        var bOldReady = bReady;
 | 
	
		
			
				|  |  | +        bReady = false;
 | 
	
		
			
				|  |  | +        SelectedEmployees.ItemsSource = emps;
 | 
	
		
			
				|  |  | +        foreach (var item in SelectedEmployees.Items)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            var pair = (KeyValuePair<Guid, string>)item;
 | 
	
		
			
				|  |  | +            if (_settings.SelectedEmployees.Contains(pair.Key) || selectall)
 | 
	
		
			
				|  |  | +                SelectedEmployees.SelectedItems.Add(item);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void EmployeesSelectionChanged(object sender, SelectionChangedEventArgs e)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            if (!bReady || e.AddedItems.Count == 0 || e.AddedItems[0] == null)
 | 
	
		
			
				|  |  | -                return;
 | 
	
		
			
				|  |  | +        bReady = bOldReady;
 | 
	
		
			
				|  |  | +        SaveSettings();
 | 
	
		
			
				|  |  | +        Refresh();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            //ReloadColumns();
 | 
	
		
			
				|  |  | -            SaveSettings();
 | 
	
		
			
				|  |  | -            Refresh();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    private void EmployeesSelectionChanged(object sender, SelectionChangedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (!bReady || e.AddedItems.Count == 0 || e.AddedItems[0] == null)
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void Export_Click(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            var options = new ExcelExportingOptions
 | 
	
		
			
				|  |  | +        //ReloadColumns();
 | 
	
		
			
				|  |  | +        SaveSettings();
 | 
	
		
			
				|  |  | +        Refresh();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void Export_Click(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        var options = new ExcelExportingOptions
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            ExcelVersion = ExcelVersion.Excel2013
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        var excelEngine = dataGrid.ExportToExcel(dataGrid.View, options);
 | 
	
		
			
				|  |  | +        var workBook = excelEngine.Excel.Workbooks[0];
 | 
	
		
			
				|  |  | +        var dlg = new SaveFileDialog
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            Filter = "Excel Files (*.xlsx)|*.xlsx",
 | 
	
		
			
				|  |  | +            FileName = typeof(LeaveRequest).EntityName().Split('.').Last() + ".xlsx"
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        if (dlg.ShowDialog() == true)
 | 
	
		
			
				|  |  | +            try
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                ExcelVersion = ExcelVersion.Excel2013
 | 
	
		
			
				|  |  | -            };
 | 
	
		
			
				|  |  | -            var excelEngine = dataGrid.ExportToExcel(dataGrid.View, options);
 | 
	
		
			
				|  |  | -            var workBook = excelEngine.Excel.Workbooks[0];
 | 
	
		
			
				|  |  | -            var dlg = new SaveFileDialog
 | 
	
		
			
				|  |  | +                workBook.SaveAs(dlg.FileName);
 | 
	
		
			
				|  |  | +                Process.Start(new ProcessStartInfo(dlg.FileName) { UseShellExecute = true });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            catch (Exception e2)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                Filter = "Excel Files (*.xlsx)|*.xlsx",
 | 
	
		
			
				|  |  | -                FileName = typeof(LeaveRequest).EntityName().Split('.').Last() + ".xlsx"
 | 
	
		
			
				|  |  | -            };
 | 
	
		
			
				|  |  | -            if (dlg.ShowDialog() == true)
 | 
	
		
			
				|  |  | -                try
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    workBook.SaveAs(dlg.FileName);
 | 
	
		
			
				|  |  | -                    Process.Start(new ProcessStartInfo(dlg.FileName) { UseShellExecute = true });
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                catch (Exception e2)
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    MessageBox.Show("Error saving spreadsheet!\n\n" + e2.Message);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            //workBook.SaveAs("Leave Requests.xlsx");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +                MessageBox.Show("Error saving spreadsheet!\n\n" + e2.Message);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        //workBook.SaveAs("Leave Requests.xlsx");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private void SelectedTeams_SizeChanged(object sender, SizeChangedEventArgs e)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            SaveSettings();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    private void SelectedTeams_SizeChanged(object sender, SizeChangedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        SaveSettings();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void OnlyShowLeaveBox_Checked(object sender, RoutedEventArgs e)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        SaveSettings();
 | 
	
		
			
				|  |  | +        Refresh();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |