WidgetDashboard.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. public Dictionary<Type, CoreTable> DataEnvironment()
  61. {
  62. return new Dictionary<Type, CoreTable>();
  63. }
  64. private void LoadGroups()
  65. {
  66. groups = null;
  67. new Client<EmployeeGroup>().Query(
  68. null,
  69. Columns.None<EmployeeGroup>().Add(
  70. x => x.ID,
  71. x => x.Description
  72. ),
  73. new SortOrder<EmployeeGroup>(x => x.Description),
  74. CoreRange.All,
  75. (o, e) =>
  76. {
  77. groups = new Dictionary<Guid, string>
  78. {
  79. { CoreUtils.FullGuid, "All Employees" },
  80. { Guid.Empty, "(No Group Assigned)" }
  81. };
  82. o.LoadDictionary<EmployeeGroup, Guid, string>(groups, x => x.ID, x => x.Description);
  83. Dispatcher.Invoke(
  84. () =>
  85. {
  86. SelectEmployees.SelectedValue = null;
  87. SelectEmployees.ItemsSource = groups;
  88. SelectEmployees.SelectedIndex = 0;
  89. }
  90. );
  91. }
  92. );
  93. }
  94. private void PrevDay_Click(object sender, RoutedEventArgs e)
  95. {
  96. SelectDate.DateTime = SelectDate.DateTime.Value.AddDays(-1);
  97. }
  98. private void NextDay_Click(object sender, RoutedEventArgs e)
  99. {
  100. SelectDate.DateTime = SelectDate.DateTime.Value.AddDays(1);
  101. }
  102. private void SelectDate_DateTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  103. {
  104. if (IsReady)
  105. {
  106. Timesheets.Date = SelectDate.DateTime.Value;
  107. Tasks.Date = SelectDate.DateTime.Value;
  108. Manufacturing.Date = SelectDate.DateTime.Value;
  109. }
  110. }
  111. private void SelectEmployees_SelectionChanged(object sender, SelectionChangedEventArgs e)
  112. {
  113. if (!IsReady || SelectEmployees.SelectedValue == null)
  114. return;
  115. Timesheets.GroupID = (Guid)SelectEmployees.SelectedValue;
  116. Tasks.GroupID = (Guid)SelectEmployees.SelectedValue;
  117. Manufacturing.GroupID = (Guid)SelectEmployees.SelectedValue;
  118. }
  119. }
  120. }