WidgetDashboard.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using Comal.Classes;
  7. using InABox.Clients;
  8. using InABox.Core;
  9. using InABox.Wpf;
  10. namespace PRSDesktop
  11. {
  12. /// <summary>
  13. /// Interaction logic for WidgetDashboard.xaml
  14. /// </summary>
  15. public partial class WidgetDashboard : UserControl, IBasePanel
  16. {
  17. private Dictionary<Guid, string> groups;
  18. public WidgetDashboard()
  19. {
  20. InitializeComponent();
  21. }
  22. public event DataModelUpdateEvent? OnUpdateDataModel;
  23. public bool IsReady { get; set; } = false;
  24. public void CreateToolbarButtons(IPanelHost host)
  25. {
  26. }
  27. public string SectionName => "Widget Dashboard";
  28. public DataModel DataModel(Selection selection)
  29. {
  30. return new WidgetDashboardDataModel();
  31. }
  32. public void Heartbeat(TimeSpan time)
  33. {
  34. }
  35. public void Refresh()
  36. {
  37. Timesheets.Refresh();
  38. Tasks.Refresh();
  39. Manufacturing.Refresh();
  40. }
  41. public Dictionary<string, object[]> Selected()
  42. {
  43. return new Dictionary<string, object[]>();
  44. }
  45. public void Setup()
  46. {
  47. LoadGroups();
  48. Timesheets.Setup();
  49. Tasks.Setup();
  50. Manufacturing.Setup();
  51. }
  52. public void Shutdown(CancelEventArgs? cancel)
  53. {
  54. Timesheets.Shutdown(cancel);
  55. if (cancel?.Cancel == true) return;
  56. Tasks.Shutdown(cancel);
  57. if (cancel?.Cancel == true) return;
  58. Manufacturing.Shutdown(cancel);
  59. }
  60. private void LoadGroups()
  61. {
  62. groups = null;
  63. new Client<EmployeeGroup>().Query(
  64. null,
  65. Columns.None<EmployeeGroup>().Add(
  66. x => x.ID,
  67. x => x.Description
  68. ),
  69. new SortOrder<EmployeeGroup>(x => x.Description),
  70. CoreRange.All,
  71. (o, e) =>
  72. {
  73. groups = new Dictionary<Guid, string>
  74. {
  75. { CoreUtils.FullGuid, "All Employees" },
  76. { Guid.Empty, "(No Group Assigned)" }
  77. };
  78. o.LoadDictionary<EmployeeGroup, Guid, string>(groups, x => x.ID, x => x.Description);
  79. Dispatcher.Invoke(
  80. () =>
  81. {
  82. SelectEmployees.SelectedValue = null;
  83. SelectEmployees.ItemsSource = groups;
  84. SelectEmployees.SelectedIndex = 0;
  85. }
  86. );
  87. }
  88. );
  89. }
  90. private void PrevDay_Click(object sender, RoutedEventArgs e)
  91. {
  92. SelectDate.DateTime = SelectDate.DateTime.Value.AddDays(-1);
  93. }
  94. private void NextDay_Click(object sender, RoutedEventArgs e)
  95. {
  96. SelectDate.DateTime = SelectDate.DateTime.Value.AddDays(1);
  97. }
  98. private void SelectDate_DateTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  99. {
  100. if (IsReady)
  101. {
  102. Timesheets.Date = SelectDate.DateTime.Value;
  103. Tasks.Date = SelectDate.DateTime.Value;
  104. Manufacturing.Date = SelectDate.DateTime.Value;
  105. }
  106. }
  107. private void SelectEmployees_SelectionChanged(object sender, SelectionChangedEventArgs e)
  108. {
  109. if (!IsReady || SelectEmployees.SelectedValue == null)
  110. return;
  111. Timesheets.GroupID = (Guid)SelectEmployees.SelectedValue;
  112. Tasks.GroupID = (Guid)SelectEmployees.SelectedValue;
  113. Manufacturing.GroupID = (Guid)SelectEmployees.SelectedValue;
  114. }
  115. }
  116. }