WidgetDashboard.xaml.cs 3.8 KB

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