EmployeePanel.xaml.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using Comal.Classes;
  10. using InABox.Configuration;
  11. using InABox.Core;
  12. using InABox.DynamicGrid;
  13. using InABox.WPF;
  14. using InABox.Wpf;
  15. namespace PRSDesktop
  16. {
  17. public class EmployeePanelSettings : IUserConfigurationSettings
  18. {
  19. public DynamicSplitPanelView View { get; set; }
  20. public double AnchorWidth { get; set; }
  21. public double RoleHeight { get; set; }
  22. public double RosterHeight { get; set; }
  23. public EmployeePanelSettings()
  24. {
  25. View = DynamicSplitPanelView.Combined;
  26. AnchorWidth = 250;
  27. RoleHeight = 250;
  28. RosterHeight = 400;
  29. }
  30. }
  31. /// <summary>
  32. /// Interaction logic for EmployeePanel.xaml
  33. /// </summary>
  34. public partial class EmployeePanel : UserControl, IPanel<Employee>
  35. {
  36. private enum Suppress
  37. {
  38. Events
  39. }
  40. private EmployeePanelSettings _settings;
  41. private void DoLoadSettings()
  42. {
  43. using (new EventSuppressor(Suppress.Events))
  44. {
  45. _settings = new UserConfiguration<EmployeePanelSettings>().Load();
  46. SplitPanel.View = _settings.View;
  47. SplitPanel.AnchorWidth = _settings.AnchorWidth;
  48. RoleGridRow.Height = new GridLength(_settings.RoleHeight, GridUnitType.Pixel);
  49. RosterGridRow.Height = new GridLength(_settings.RosterHeight, GridUnitType.Pixel);
  50. }
  51. }
  52. private void DoSaveSettings()
  53. {
  54. _settings.View = SplitPanel.View;
  55. _settings.AnchorWidth = SplitPanel.AnchorWidth;
  56. _settings.RoleHeight = RoleGridRow.Height.Value;
  57. _settings.RosterHeight = RosterGridRow.Height.Value;
  58. new UserConfiguration<EmployeePanelSettings>().Save(_settings);
  59. }
  60. public EmployeePanel()
  61. {
  62. using (new EventSuppressor(Suppress.Events))
  63. InitializeComponent();
  64. }
  65. public bool IsReady { get; set; }
  66. public event DataModelUpdateEvent? OnUpdateDataModel;
  67. public Dictionary<string, object[]> Selected()
  68. {
  69. return new Dictionary<string, object[]> { { typeof(Employee).EntityName(), Employees.SelectedRows } };
  70. }
  71. public void Setup()
  72. {
  73. using (new EventSuppressor(Suppress.Events))
  74. {
  75. DoLoadSettings();
  76. Employees.HiddenColumns.Add(x => x.RosterTemplate.ID);
  77. Employees.HiddenColumns.Add(x => x.RosterStart);
  78. Employees.Refresh(true, false);
  79. Rosters.Refresh(true, false);
  80. Teams.Refresh(true, false);
  81. Roles.Refresh(true, false);
  82. Activities.Refresh(true, false);
  83. Forms.Refresh(true, false);
  84. Qualifications.Refresh(true, false);
  85. Spreadsheets.Refresh(true, false);
  86. Jobs.Refresh(true, false);
  87. RoleCrossTab.Visibility = Security.CanView<Employee>()
  88. && Security.CanView<Role>()
  89. && Security.CanView<EmployeeRole>() ? Visibility.Visible : Visibility.Collapsed;
  90. var visibleTabItems = Tab.Items.OfType<DynamicTabItem>().Where(x => x.Visibility == Visibility.Visible).ToList();
  91. if(visibleTabItems.Count <= 1)
  92. {
  93. foreach(var tab in visibleTabItems)
  94. {
  95. tab.Visibility = Visibility.Collapsed;
  96. Tab.SelectedItem = tab;
  97. }
  98. }
  99. }
  100. }
  101. public void Shutdown(CancelEventArgs? cancel)
  102. {
  103. }
  104. public void CreateToolbarButtons(IPanelHost host)
  105. {
  106. HumanResourcesSetupActions.SecurityGroups(host);
  107. host.CreateSetupSeparator();
  108. HumanResourcesSetupActions.EmployeeGroups(host);
  109. HumanResourcesSetupActions.EmployeePositions(host);
  110. HumanResourcesSetupActions.EmployeeRoles(host);
  111. HumanResourcesSetupActions.EmployeeTeams(host);
  112. HumanResourcesSetupActions.EmployeeActivities(host);
  113. HumanResourcesSetupActions.EmployeeQualifications(host);
  114. HumanResourcesSetupActions.EmployeeRosters(host);
  115. host.CreateSetupSeparator();
  116. HumanResourcesSetupActions.EmployeeOvertimeRules(host);
  117. HumanResourcesSetupActions.EmployeeOvertime(host);
  118. HumanResourcesSetupActions.EmployeeStandardLeave(host);
  119. host.CreateSetupSeparator();
  120. HumanResourcesSetupActions.EmployeeSpreadsheetTemplates(host);
  121. }
  122. private bool _loaded = false;
  123. private void Tab_SelectionChanged(object sender, SelectionChangedEventArgs e)
  124. {
  125. if (sender != Tab || !_loaded) return;
  126. RefreshCurrentTab();
  127. }
  128. private void RefreshCurrentTab()
  129. {
  130. if (Tab.SelectedTab == EmployeeTab)
  131. {
  132. RefreshEmployeeTab();
  133. }
  134. else if (Tab.SelectedTab == RoleCrossTab)
  135. {
  136. RefreshRoleTab();
  137. }
  138. }
  139. private void RefreshRoleTab()
  140. {
  141. EmployeeRoles.Refresh(true, true);
  142. }
  143. private void RefreshEmployeeTab()
  144. {
  145. Employees.Refresh(false, true);
  146. Rosters.Refresh(false, true);
  147. Teams.Refresh(false, true);
  148. Roles.Refresh(false, true);
  149. Activities.Refresh(false, true);
  150. Forms.Refresh(false, true);
  151. Qualifications.Refresh(false, true);
  152. Spreadsheets.Refresh(false, true);
  153. Jobs.Refresh(false, true);
  154. }
  155. public void Refresh()
  156. {
  157. RefreshCurrentTab();
  158. _loaded = true;
  159. }
  160. public string SectionName => "Employees";
  161. public DataModel DataModel(Selection selection)
  162. {
  163. var ids = Employees.ExtractValues(x => x.ID, selection).ToArray();
  164. return new AutoDataModel<Employee>(new Filter<Employee>(x => x.ID).InList(ids));
  165. }
  166. public void Heartbeat(TimeSpan time)
  167. {
  168. }
  169. public Dictionary<Type, CoreTable> DataEnvironment()
  170. {
  171. var env = new Dictionary<Type, CoreTable>();
  172. env[typeof(Job)] = Employees.Data;
  173. return env;
  174. }
  175. private void Employees_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  176. {
  177. var employee = e.Rows?.FirstOrDefault()?.ToObject<Employee>() ?? new Employee();
  178. Rosters.Load(employee, null);
  179. //Rosters.Refresh(false, true);
  180. Teams.EmployeeID = employee.ID;
  181. Teams.Refresh(false, true);
  182. //LoadEmployeeThumbnail(employee.Thumbnail.ID);
  183. Roles.EmployeeID = employee.ID;
  184. Roles.Refresh(false, true);
  185. Activities.Left = employee;
  186. Activities.Refresh(false,true);
  187. Forms.Left = employee;
  188. Forms.Refresh(false, true);
  189. Qualifications.Load(employee, null);
  190. Spreadsheets.Master = employee;
  191. Spreadsheets.Refresh(false,true);
  192. Jobs.Left = employee;
  193. Jobs.Refresh(false, true);
  194. }
  195. // private void LoadEmployeeThumbnail(Guid imageid)
  196. // {
  197. // Thumbnail.Source = null;
  198. // if (imageid == Guid.Empty)
  199. // return;
  200. // Bitmap result = null;
  201. // new Client<Document>().Query(
  202. // new Filter<Document>(x => x.ID).IsEqualTo(imageid),
  203. // new Columns<Document>(x => x.ID, x => x.Data),
  204. // null,
  205. // (o, e) => Dispatcher.Invoke(() =>
  206. // {
  207. // if (o?.Rows.Any() == true)
  208. // {
  209. // var ms = new MemoryStream(o.Rows.First().Get<Document, byte[]>(x => x.Data));
  210. // Thumbnail.Source = new Bitmap(ms).AsBitmapImage();
  211. // }
  212. // })
  213. // );
  214. // }
  215. private void SplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
  216. {
  217. if (EventSuppressor.IsSet(Suppress.Events))
  218. return;
  219. DoSaveSettings();
  220. }
  221. private void Roles_OnSizeChanged(object sender, SizeChangedEventArgs e)
  222. {
  223. if (EventSuppressor.IsSet(Suppress.Events))
  224. return;
  225. DoSaveSettings();
  226. }
  227. private void Roles_OnOnChanged(object sender, EventArgs args)
  228. {
  229. Activities.Refresh(false,true);
  230. Forms.Refresh(false, true);
  231. }
  232. private void Rosters_OnOnChanged(object sender, EventArgs args)
  233. {
  234. //Employees.Refresh(false, true);
  235. }
  236. private void Rosters_OnSizeChanged(object sender, SizeChangedEventArgs e)
  237. {
  238. if (EventSuppressor.IsSet(Suppress.Events))
  239. return;
  240. DoSaveSettings();
  241. }
  242. private void Rosters_EmployeeChanged()
  243. {
  244. Employees.Refresh(false, true);
  245. }
  246. }
  247. }