using System; using System.ComponentModel; using System.Data; using System.Linq; using System.Windows.Controls; using Comal.Classes; using InABox.Clients; using InABox.Configuration; using InABox.Core; using PRSDesktop.WidgetGroups; namespace PRSDesktop { public class TaskWidgetProperties : IUserConfigurationSettings, IDashboardProperties { } public class TaskWidgetElement : DashboardElement { } /// /// Interaction logic for TaskWidget.xaml /// public partial class TaskWidget : UserControl, IDashboardWidget { private DateTime _date = DateTime.Today; private Guid _groupid = CoreUtils.FullGuid; private readonly DataTable report = new(); private CoreTable tasks; public TaskWidget() { InitializeComponent(); report.Columns.Add("ID", typeof(Guid)); report.Columns.Add("Name", typeof(string)); report.Columns.Add("Current", typeof(int)); report.Columns.Add("Others", typeof(int)); report.Columns.Add("New", typeof(int)); report.Columns.Add("Closed", typeof(int)); report.Columns.Add("Overdue", typeof(int)); report.PrimaryKey = new[] { report.Columns[0] }; } public DateTime Date { get => _date; set { _date = value; LoadTasks(); } } public Guid GroupID { get => _groupid; set { _groupid = value; LoadTasks(); } } public TaskWidgetProperties Properties { get; set; } public event LoadSettings? LoadSettings; public event SaveSettings? SaveSettings; public void Setup() { } public void Refresh() { LoadTasks(); } public void Shutdown(CancelEventArgs? cancel) { } private void LoadTasks() { Report.ItemsSource = null; tasks = null; var filter = new Filter(x => x.Created).IsLessThanOrEqualTo(Date.AddDays(1)); filter.Ands.Add(new Filter(x => x.EmployeeLink.StartDate).IsEqualTo(DateTime.MinValue).Or(x => x.EmployeeLink.StartDate) .IsLessThanOrEqualTo(Date)); filter.Ands.Add(new Filter(x => x.EmployeeLink.FinishDate).IsEqualTo(DateTime.MinValue).Or(x => x.EmployeeLink.FinishDate) .IsGreaterThanOrEqualTo(Date)); filter.Ands.Add(new Filter(x => x.Completed).IsEqualTo(DateTime.MinValue).Or(x => x.Completed).IsGreaterThanOrEqualTo(Date)); filter.Ands.Add(new Filter(x => x.Closed).IsEqualTo(DateTime.MinValue).Or(x => x.Closed).IsGreaterThanOrEqualTo(Date)); if (!_groupid.Equals(CoreUtils.FullGuid)) filter.Ands.Add(new Filter(x => x.EmployeeLink.Group.ID).IsEqualTo(_groupid).Or(x => x.ManagerLink.ID).IsEqualTo(_groupid)); new Client().Query( filter, null, new SortOrder(x => x.EmployeeLink.Name), (o, e) => { tasks = o; CheckData(); } ); } private void CheckData() { if (tasks != null) ProcessData(); } private void ProcessData() { try { report.Rows.Clear(); foreach (var task in tasks.Rows) { var empid = task.Get(x => x.EmployeeLink.ID); var empValid = Entity.IsEntityLinkValid(x => x.EmployeeLink, task); var empname = task.Get(x => x.EmployeeLink.Name); if (empValid && report.Rows.Find(empid) == null) { var rows = tasks.Rows.Where(r => r.Get(c => c.EmployeeLink.ID).Equals(empid)); int? mine = null; int? others = null; int? created = null; int? closed = null; int? overdue = null; foreach (var row in rows) { var taskemp = row.Get(x => x.EmployeeLink.ID); var taskmgr = row.Get(x => x.ManagerLink.ID); var taskcreated = row.Get(x => x.Created).Date; var taskclosed = row.Get(x => x.Completed).Date; if (taskclosed.IsEmpty()) taskclosed = row.Get(x => x.Closed).Date; var taskdue = row.Get(x => x.DueDate).Date; if (taskemp.Equals(empid)) mine = mine.HasValue ? mine.Value + 1 : 1; if (taskmgr.Equals(empid) && !taskemp.Equals(empid)) others = others.HasValue ? others.Value + 1 : 1; if (taskcreated.Equals(_date) && taskemp.Equals(empid)) created = created.HasValue ? created.Value + 1 : 1; if (taskclosed.Equals(_date) && taskemp.Equals(empid)) closed = closed.HasValue ? closed.Value + 1 : 1; if (taskdue < _date && taskclosed.IsEmpty()) overdue = overdue.HasValue ? overdue.Value + 1 : 1; } if (mine.HasValue || others.HasValue || created.HasValue || closed.HasValue || overdue.HasValue) report.Rows.Add(empid, empname, mine, others, created, closed, overdue); } } } catch (Exception e) { Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace)); } Dispatcher.Invoke(() => { Report.ItemsSource = report; }); } } }