using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows; using System.Windows.Controls; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.Wpf; namespace PRSDesktop { /// /// Interaction logic for WidgetDashboard.xaml /// public partial class WidgetDashboard : UserControl, IBasePanel { private Dictionary groups; public WidgetDashboard() { InitializeComponent(); } public event DataModelUpdateEvent? OnUpdateDataModel; public bool IsReady { get; set; } = false; public void CreateToolbarButtons(IPanelHost host) { } public string SectionName => "Widget Dashboard"; public DataModel DataModel(Selection selection) { return new WidgetDashboardDataModel(); } public void Heartbeat(TimeSpan time) { } public void Refresh() { Timesheets.Refresh(); Tasks.Refresh(); Manufacturing.Refresh(); } public Dictionary Selected() { return new Dictionary(); } public void Setup() { LoadGroups(); Timesheets.Setup(); Tasks.Setup(); Manufacturing.Setup(); } public void Shutdown(CancelEventArgs? cancel) { Timesheets.Shutdown(cancel); if (cancel?.Cancel == true) return; Tasks.Shutdown(cancel); if (cancel?.Cancel == true) return; Manufacturing.Shutdown(cancel); } public Dictionary DataEnvironment() { return new Dictionary(); } private void LoadGroups() { groups = null; new Client().Query( null, Columns.None().Add( x => x.ID, x => x.Description ), new SortOrder(x => x.Description), CoreRange.All, (o, e) => { groups = new Dictionary { { CoreUtils.FullGuid, "All Employees" }, { Guid.Empty, "(No Group Assigned)" } }; o.LoadDictionary(groups, x => x.ID, x => x.Description); Dispatcher.Invoke( () => { SelectEmployees.SelectedValue = null; SelectEmployees.ItemsSource = groups; SelectEmployees.SelectedIndex = 0; } ); } ); } private void PrevDay_Click(object sender, RoutedEventArgs e) { SelectDate.DateTime = SelectDate.DateTime.Value.AddDays(-1); } private void NextDay_Click(object sender, RoutedEventArgs e) { SelectDate.DateTime = SelectDate.DateTime.Value.AddDays(1); } private void SelectDate_DateTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (IsReady) { Timesheets.Date = SelectDate.DateTime.Value; Tasks.Date = SelectDate.DateTime.Value; Manufacturing.Date = SelectDate.DateTime.Value; } } private void SelectEmployees_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!IsReady || SelectEmployees.SelectedValue == null) return; Timesheets.GroupID = (Guid)SelectEmployees.SelectedValue; Tasks.GroupID = (Guid)SelectEmployees.SelectedValue; Manufacturing.GroupID = (Guid)SelectEmployees.SelectedValue; } } }