123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- 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;
- }
- }
-
- /// <summary>
- /// Interaction logic for EmployeePanel.xaml
- /// </summary>
- public partial class EmployeePanel : UserControl, IPanel<Employee>
- {
- private enum Suppress
- {
- Events
- }
- private EmployeePanelSettings _settings;
- private void DoLoadSettings()
- {
- using (new EventSuppressor(Suppress.Events))
- {
- _settings = new UserConfiguration<EmployeePanelSettings>().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<EmployeePanelSettings>().Save(_settings);
- }
-
- public EmployeePanel()
- {
- using (new EventSuppressor(Suppress.Events))
- InitializeComponent();
- }
- public bool IsReady { get; set; }
- public event DataModelUpdateEvent? OnUpdateDataModel;
- public Dictionary<string, object[]> Selected()
- {
- return new Dictionary<string, object[]> { { 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<Employee>()
- && Security.CanView<Role>()
- && Security.CanView<EmployeeRole>() ? Visibility.Visible : Visibility.Collapsed;
- var visibleTabItems = Tab.Items.OfType<DynamicTabItem>().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<Employee>(new Filter<Employee>(x => x.ID).InList(ids));
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- public Dictionary<Type, CoreTable> DataEnvironment()
- {
- var env = new Dictionary<Type, CoreTable>();
- env[typeof(Job)] = Employees.Data;
- return env;
- }
- private void Employees_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
- {
- var employee = e.Rows?.FirstOrDefault()?.ToObject<Employee>() ?? 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<Document>().Query(
- // new Filter<Document>(x => x.ID).IsEqualTo(imageid),
- // new Columns<Document>(x => x.ID, x => x.Data),
- // null,
- // (o, e) => Dispatcher.Invoke(() =>
- // {
- // if (o?.Rows.Any() == true)
- // {
- // var ms = new MemoryStream(o.Rows.First().Get<Document, byte[]>(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);
- }
- }
- }
|