EmployeePanel.xaml.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. namespace PRSDesktop
  15. {
  16. public class EmployeePanelSettings : IUserConfigurationSettings
  17. {
  18. public DynamicSplitPanelView View { get; set; }
  19. public double AnchorWidth { get; set; }
  20. public double RoleHeight { get; set; }
  21. public double RosterHeight { get; set; }
  22. public EmployeePanelSettings()
  23. {
  24. View = DynamicSplitPanelView.Combined;
  25. AnchorWidth = 250;
  26. RoleHeight = 250;
  27. RosterHeight = 400;
  28. }
  29. }
  30. /// <summary>
  31. /// Interaction logic for EmployeePanel.xaml
  32. /// </summary>
  33. public partial class EmployeePanel : UserControl, IPanel<Employee>
  34. {
  35. private enum Suppress
  36. {
  37. Events
  38. }
  39. private EmployeePanelSettings _settings;
  40. private void DoLoadSettings()
  41. {
  42. using (new EventSuppressor(Suppress.Events))
  43. {
  44. _settings = new UserConfiguration<EmployeePanelSettings>().Load();
  45. SplitPanel.View = _settings.View;
  46. SplitPanel.AnchorWidth = _settings.AnchorWidth;
  47. RoleGridRow.Height = new GridLength(_settings.RoleHeight, GridUnitType.Pixel);
  48. RosterGridRow.Height = new GridLength(_settings.RosterHeight, GridUnitType.Pixel);
  49. }
  50. }
  51. private void DoSaveSettings()
  52. {
  53. _settings.View = SplitPanel.View;
  54. _settings.AnchorWidth = SplitPanel.AnchorWidth;
  55. _settings.RoleHeight = RoleGridRow.Height.Value;
  56. _settings.RosterHeight = RosterGridRow.Height.Value;
  57. new UserConfiguration<EmployeePanelSettings>().Save(_settings);
  58. }
  59. public EmployeePanel()
  60. {
  61. using (new EventSuppressor(Suppress.Events))
  62. InitializeComponent();
  63. }
  64. public bool IsReady { get; set; }
  65. public event DataModelUpdateEvent? OnUpdateDataModel;
  66. public Dictionary<string, object[]> Selected()
  67. {
  68. return new Dictionary<string, object[]> { { typeof(Employee).EntityName(), Employees.SelectedRows } };
  69. }
  70. public void Setup()
  71. {
  72. using (new EventSuppressor(Suppress.Events))
  73. {
  74. DoLoadSettings();
  75. Employees.HiddenColumns.Add(x => x.RosterTemplate.ID);
  76. Employees.HiddenColumns.Add(x => x.RosterStart);
  77. Employees.Refresh(true, false);
  78. Rosters.Refresh(true, false);
  79. Teams.Refresh(true, false);
  80. Roles.Refresh(true, false);
  81. Activities.Refresh(true, false);
  82. Forms.Refresh(true, false);
  83. Qualifications.Refresh(true, false);
  84. Spreadsheets.Refresh(true, false);
  85. Jobs.Refresh(true, false);
  86. }
  87. }
  88. public void Shutdown(CancelEventArgs? cancel)
  89. {
  90. }
  91. public void CreateToolbarButtons(IPanelHost host)
  92. {
  93. }
  94. public void Refresh()
  95. {
  96. Employees.Refresh(false, true);
  97. Rosters.Refresh(false, true);
  98. Teams.Refresh(false,true);
  99. Roles.Refresh(false, true);
  100. Activities.Refresh(false, true);
  101. Forms.Refresh(false, true);
  102. Qualifications.Refresh(false, true);
  103. Spreadsheets.Refresh(false, true);
  104. Jobs.Refresh(false, true);
  105. }
  106. public string SectionName => "Employees";
  107. public DataModel DataModel(Selection selection)
  108. {
  109. var ids = Employees.ExtractValues(x => x.ID, selection).ToArray();
  110. return new AutoDataModel<Employee>(new Filter<Employee>(x => x.ID).InList(ids));
  111. }
  112. public void Heartbeat(TimeSpan time)
  113. {
  114. }
  115. public Dictionary<Type, CoreTable> DataEnvironment()
  116. {
  117. var env = new Dictionary<Type, CoreTable>();
  118. env[typeof(Job)] = Employees.Data;
  119. return env;
  120. }
  121. private void Employees_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  122. {
  123. Employee employee = (e.Rows == null) || (e.Rows.Length != 1)
  124. ? new Employee()
  125. : e.Rows[0].ToObject<Employee>();
  126. Rosters.Load(employee, null);
  127. //Rosters.Refresh(false, true);
  128. Teams.EmployeeID = employee.ID;
  129. Teams.Refresh(false, true);
  130. //LoadEmployeeThumbnail(employee.Thumbnail.ID);
  131. Roles.EmployeeID = employee.ID;
  132. Roles.Refresh(false, true);
  133. Activities.Left = employee;
  134. Activities.Refresh(false,true);
  135. Forms.Left = employee;
  136. Forms.Refresh(false, true);
  137. Qualifications.Load(employee, null);
  138. Spreadsheets.Entity = employee;
  139. Spreadsheets.Refresh(false,true);
  140. Jobs.Left = employee;
  141. Jobs.Refresh(false, true);
  142. }
  143. // private void LoadEmployeeThumbnail(Guid imageid)
  144. // {
  145. // Thumbnail.Source = null;
  146. // if (imageid == Guid.Empty)
  147. // return;
  148. // Bitmap result = null;
  149. // new Client<Document>().Query(
  150. // new Filter<Document>(x => x.ID).IsEqualTo(imageid),
  151. // new Columns<Document>(x => x.ID, x => x.Data),
  152. // null,
  153. // (o, e) => Dispatcher.Invoke(() =>
  154. // {
  155. // if (o?.Rows.Any() == true)
  156. // {
  157. // var ms = new MemoryStream(o.Rows.First().Get<Document, byte[]>(x => x.Data));
  158. // Thumbnail.Source = new Bitmap(ms).AsBitmapImage();
  159. // }
  160. // })
  161. // );
  162. // }
  163. private void SplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
  164. {
  165. if (EventSuppressor.IsSet(Suppress.Events))
  166. return;
  167. DoSaveSettings();
  168. }
  169. private void Roles_OnSizeChanged(object sender, SizeChangedEventArgs e)
  170. {
  171. if (EventSuppressor.IsSet(Suppress.Events))
  172. return;
  173. DoSaveSettings();
  174. }
  175. private void Roles_OnOnChanged(object sender, EventArgs args)
  176. {
  177. Activities.Refresh(false,true);
  178. Forms.Refresh(false, true);
  179. }
  180. private void Rosters_OnOnChanged(object sender, EventArgs args)
  181. {
  182. //Employees.Refresh(false, true);
  183. }
  184. private void Rosters_OnSizeChanged(object sender, SizeChangedEventArgs e)
  185. {
  186. if (EventSuppressor.IsSet(Suppress.Events))
  187. return;
  188. DoSaveSettings();
  189. }
  190. }
  191. }