using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Comal.Classes;
using InABox.Configuration;
using InABox.Core;
using InABox.DynamicGrid;
using InABox.WPF;
using InABox.Wpf;
namespace PRSDesktop
{
public class EmployeePanelSettings : IUserConfigurationSettings
{
public DynamicSplitPanelView View { get; set; }
public double AnchorWidth { get; set; }
public double RoleHeight { get; set; }
public double RosterHeight { get; set; }
public EmployeePanelSettings()
{
View = DynamicSplitPanelView.Combined;
AnchorWidth = 250;
RoleHeight = 250;
RosterHeight = 400;
}
}
///
/// Interaction logic for EmployeePanel.xaml
///
public partial class EmployeePanel : UserControl, IPanel
{
private enum Suppress
{
Events
}
private EmployeePanelSettings _settings;
private void DoLoadSettings()
{
using (new EventSuppressor(Suppress.Events))
{
_settings = new UserConfiguration().Load();
SplitPanel.View = _settings.View;
SplitPanel.AnchorWidth = _settings.AnchorWidth;
RoleGridRow.Height = new GridLength(_settings.RoleHeight, GridUnitType.Pixel);
RosterGridRow.Height = new GridLength(_settings.RosterHeight, GridUnitType.Pixel);
}
}
private void DoSaveSettings()
{
_settings.View = SplitPanel.View;
_settings.AnchorWidth = SplitPanel.AnchorWidth;
_settings.RoleHeight = RoleGridRow.Height.Value;
_settings.RosterHeight = RosterGridRow.Height.Value;
new UserConfiguration().Save(_settings);
}
public EmployeePanel()
{
using (new EventSuppressor(Suppress.Events))
InitializeComponent();
}
public bool IsReady { get; set; }
public event DataModelUpdateEvent? OnUpdateDataModel;
public Dictionary Selected()
{
return new Dictionary { { typeof(Employee).EntityName(), Employees.SelectedRows } };
}
public void Setup()
{
using (new EventSuppressor(Suppress.Events))
{
DoLoadSettings();
Employees.HiddenColumns.Add(x => x.RosterTemplate.ID);
Employees.HiddenColumns.Add(x => x.RosterStart);
Employees.Refresh(true, false);
Rosters.Refresh(true, false);
Teams.Refresh(true, false);
Roles.Refresh(true, false);
Activities.Refresh(true, false);
Forms.Refresh(true, false);
Qualifications.Refresh(true, false);
Spreadsheets.Refresh(true, false);
Jobs.Refresh(true, false);
RoleCrossTab.Visibility = Security.CanView()
&& Security.CanView()
&& Security.CanView() ? Visibility.Visible : Visibility.Collapsed;
var visibleTabItems = Tab.Items.OfType().Where(x => x.Visibility == Visibility.Visible).ToList();
if(visibleTabItems.Count <= 1)
{
foreach(var tab in visibleTabItems)
{
tab.Visibility = Visibility.Collapsed;
Tab.SelectedItem = tab;
}
}
}
}
public void Shutdown(CancelEventArgs? cancel)
{
}
public void CreateToolbarButtons(IPanelHost host)
{
HumanResourcesSetupActions.SecurityGroups(host);
host.CreateSetupSeparator();
HumanResourcesSetupActions.EmployeeGroups(host);
HumanResourcesSetupActions.EmployeePositions(host);
HumanResourcesSetupActions.EmployeeRoles(host);
HumanResourcesSetupActions.EmployeeTeams(host);
HumanResourcesSetupActions.EmployeeActivities(host);
HumanResourcesSetupActions.EmployeeQualifications(host);
HumanResourcesSetupActions.EmployeeRosters(host);
host.CreateSetupSeparator();
HumanResourcesSetupActions.EmployeeOvertimeRules(host);
HumanResourcesSetupActions.EmployeeOvertime(host);
HumanResourcesSetupActions.EmployeeStandardLeave(host);
host.CreateSetupSeparator();
HumanResourcesSetupActions.EmployeeSpreadsheetTemplates(host);
}
private bool _loaded = false;
private void Tab_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender != Tab || !_loaded) return;
RefreshCurrentTab();
}
private void RefreshCurrentTab()
{
if (Tab.SelectedTab == EmployeeTab)
{
RefreshEmployeeTab();
}
else if (Tab.SelectedTab == RoleCrossTab)
{
RefreshRoleTab();
}
}
private void RefreshRoleTab()
{
EmployeeRoles.Refresh(true, true);
}
private void RefreshEmployeeTab()
{
Employees.Refresh(false, true);
Rosters.Refresh(false, true);
Teams.Refresh(false, true);
Roles.Refresh(false, true);
Activities.Refresh(false, true);
Forms.Refresh(false, true);
Qualifications.Refresh(false, true);
Spreadsheets.Refresh(false, true);
Jobs.Refresh(false, true);
}
public void Refresh()
{
RefreshCurrentTab();
_loaded = true;
}
public string SectionName => "Employees";
public DataModel DataModel(Selection selection)
{
var ids = Employees.ExtractValues(x => x.ID, selection).ToArray();
return new AutoDataModel(new Filter(x => x.ID).InList(ids));
}
public void Heartbeat(TimeSpan time)
{
}
public Dictionary DataEnvironment()
{
var env = new Dictionary();
env[typeof(Job)] = Employees.Data;
return env;
}
private void Employees_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
{
var employee = e.Rows?.FirstOrDefault()?.ToObject() ?? new Employee();
Rosters.Load(employee, null);
//Rosters.Refresh(false, true);
Teams.EmployeeID = employee.ID;
Teams.Refresh(false, true);
//LoadEmployeeThumbnail(employee.Thumbnail.ID);
Roles.EmployeeID = employee.ID;
Roles.Refresh(false, true);
Activities.Left = employee;
Activities.Refresh(false,true);
Forms.Left = employee;
Forms.Refresh(false, true);
Qualifications.Load(employee, null);
Spreadsheets.Master = employee;
Spreadsheets.Refresh(false,true);
Jobs.Left = employee;
Jobs.Refresh(false, true);
}
// private void LoadEmployeeThumbnail(Guid imageid)
// {
// Thumbnail.Source = null;
// if (imageid == Guid.Empty)
// return;
// Bitmap result = null;
// new Client().Query(
// new Filter(x => x.ID).IsEqualTo(imageid),
// new Columns(x => x.ID, x => x.Data),
// null,
// (o, e) => Dispatcher.Invoke(() =>
// {
// if (o?.Rows.Any() == true)
// {
// var ms = new MemoryStream(o.Rows.First().Get(x => x.Data));
// Thumbnail.Source = new Bitmap(ms).AsBitmapImage();
// }
// })
// );
// }
private void SplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
{
if (EventSuppressor.IsSet(Suppress.Events))
return;
DoSaveSettings();
}
private void Roles_OnSizeChanged(object sender, SizeChangedEventArgs e)
{
if (EventSuppressor.IsSet(Suppress.Events))
return;
DoSaveSettings();
}
private void Roles_OnOnChanged(object sender, EventArgs args)
{
Activities.Refresh(false,true);
Forms.Refresh(false, true);
}
private void Rosters_OnOnChanged(object sender, EventArgs args)
{
//Employees.Refresh(false, true);
}
private void Rosters_OnSizeChanged(object sender, SizeChangedEventArgs e)
{
if (EventSuppressor.IsSet(Suppress.Events))
return;
DoSaveSettings();
}
private void Rosters_EmployeeChanged()
{
Employees.Refresh(false, true);
}
}
}