123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using System;
- using System.Data;
- using System.Linq;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using PRSDesktop.WidgetGroups;
- namespace PRSDesktop
- {
- public class TaskWidgetProperties : IDashboardProperties { }
- public class TaskWidgetElement : DashboardElement<TaskWidget, Common, TaskWidgetProperties> { }
- /// <summary>
- /// Interaction logic for TaskWidget.xaml
- /// </summary>
- public partial class TaskWidget : UserControl, IDashboardWidget<Common, TaskWidgetProperties>
- {
- 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 void Setup()
- {
- }
- public void Refresh()
- {
- LoadTasks();
- }
- public void Shutdown()
- {
- }
- private void LoadTasks()
- {
- Report.ItemsSource = null;
- tasks = null;
- var filter = new Filter<Kanban>(x => x.Created).IsLessThanOrEqualTo(Date.AddDays(1));
- filter.Ands.Add(new Filter<Kanban>(x => x.EmployeeLink.StartDate).IsEqualTo(DateTime.MinValue).Or(x => x.EmployeeLink.StartDate)
- .IsLessThanOrEqualTo(Date));
- filter.Ands.Add(new Filter<Kanban>(x => x.EmployeeLink.FinishDate).IsEqualTo(DateTime.MinValue).Or(x => x.EmployeeLink.FinishDate)
- .IsGreaterThanOrEqualTo(Date));
- filter.Ands.Add(new Filter<Kanban>(x => x.Completed).IsEqualTo(DateTime.MinValue).Or(x => x.Completed).IsGreaterThanOrEqualTo(Date));
- filter.Ands.Add(new Filter<Kanban>(x => x.Closed).IsEqualTo(DateTime.MinValue).Or(x => x.Closed).IsGreaterThanOrEqualTo(Date));
- if (!_groupid.Equals(CoreUtils.FullGuid))
- filter.Ands.Add(new Filter<Kanban>(x => x.EmployeeLink.Group.ID).IsEqualTo(_groupid).Or(x => x.ManagerLink.ID).IsEqualTo(_groupid));
- new Client<Kanban>().Query(
- filter,
- null,
- new SortOrder<Kanban>(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<Kanban, Guid>(x => x.EmployeeLink.ID);
- var empValid = Entity.IsEntityLinkValid<Kanban, EmployeeLink>(x => x.EmployeeLink, task);
- var empname = task.Get<Kanban, string>(x => x.EmployeeLink.Name);
- if (empValid && report.Rows.Find(empid) == null)
- {
- var rows = tasks.Rows.Where(r => r.Get<Kanban, Guid>(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<Kanban, Guid>(x => x.EmployeeLink.ID);
- var taskmgr = row.Get<Kanban, Guid>(x => x.ManagerLink.ID);
- var taskcreated = row.Get<Kanban, DateTime>(x => x.Created).Date;
- var taskclosed = row.Get<Kanban, DateTime>(x => x.Completed).Date;
- if (taskclosed.IsEmpty())
- taskclosed = row.Get<Kanban, DateTime>(x => x.Closed).Date;
- var taskdue = row.Get<Kanban, DateTime>(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; });
- }
- }
- }
|