WidgetDashboard.xaml.cs 4.0 KB

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