| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Collections.ObjectModel;
 
- using System.Globalization;
 
- using System.Linq;
 
- using System.Linq.Expressions;
 
- using System.Reflection;
 
- using System.Windows;
 
- using System.Windows.Controls;
 
- using System.Windows.Data;
 
- using System.Windows.Input;
 
- using System.Windows.Media;
 
- using System.Windows.Media.Imaging;
 
- using Comal.Classes;
 
- using InABox.Clients;
 
- using InABox.Core;
 
- using InABox.DynamicGrid;
 
- using InABox.WPF;
 
- using org.omg.CORBA;
 
- using Syncfusion.UI.Xaml.Kanban;
 
- using Color = System.Drawing.Color;
 
- namespace PRSDesktop
 
- {
 
-     public class EmployeeModel
 
-     {
 
-         public EmployeeModel(Guid id, string name, Guid thumbnail, BitmapImage image)
 
-         {
 
-             ID = id;
 
-             Name = name;
 
-             Image = image;
 
-             ThumbnailID = thumbnail;
 
-         }
 
-         public Guid ID { get; set; }
 
-         public string Name { get; set; }
 
-         public BitmapImage Image { get; set; }
 
-         public Guid ThumbnailID { get; set; }
 
-     }
 
-     public class StatusTasksHeaderTimeConverter : IValueConverter
 
-     {
 
-         public static IEnumerable<TaskModel> Tasks { get; set; }
 
-         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 
-         {
 
-             if (Tasks == null)
 
-                 return "0:00";
 
-             var dataContext = value as ColumnTag;
 
-             if (dataContext == null)
 
-                 return "0:00";
 
-             var getter = dataContext.GetType().GetProperty("Column", BindingFlags.NonPublic | BindingFlags.Instance);
 
-             if (getter == null)
 
-                 return "0:00";
 
-             var column = (KanbanColumn)getter.GetValue(dataContext);
 
-             if (column == null)
 
-                 return "0:00";
 
-             double result = 0.0F;
 
-             foreach (var kanban in Tasks.Where(x => Equals(x.Category, column.Categories)))
 
-                 result += kanban.EstimatedTime.TotalHours;
 
-             return string.Format("{0:F2}", result);
 
-         }
 
-         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 
-         {
 
-             throw new NotImplementedException();
 
-         }
 
-     }
 
-     public class BoolToVisibilityConverter : IValueConverter
 
-     {
 
-         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 
-         {
 
-             if (Equals(value, true))
 
-                 return Visibility.Visible;
 
-             return Visibility.Collapsed;
 
-         }
 
-         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 
-         {
 
-             throw new NotImplementedException();
 
-         }
 
-     }
 
-     /// <summary>
 
-     ///     Interaction logic for KanbanPanel.xaml
 
-     /// </summary>
 
-     public partial class TasksByStatusControl : UserControl, ITaskControl
 
-     {
 
-         private BitmapImage _attachimg = PRSDesktop.Resources.attachment.AsBitmapImage();
 
-         private readonly ObservableCollection<EmployeeModel> _employeelist = new();
 
-         private CoreTable _employees;
 
-         public CoreTable _kanbans;
 
-         private BitmapImage _lockimg = PRSDesktop.Resources.lock_sml.AsBitmapImage();
 
-         private ObservableCollection<TaskModel> _models = new();
 
-         private CoreTable _types;
 
-         public List<string> CheckedKanbans = new();
 
-         // CoreUtils.FullGuid => All Staff
 
-         // Guid.Empty => Unallocated
 
-         // Anything Else => Actual Staff Member
 
-         private Guid EmployeeID = Guid.Empty;
 
-         private Guid? MyID;
 
-         private string MyName = "";
 
-         private string searchtext = "";
 
-         private Guid selectedtype = CoreUtils.FullGuid;
 
-         public TasksByStatusControl()
 
-         {
 
-             InitializeComponent();
 
-         }
 
-         public string SectionName => "Tasks By Status";
 
-         public DataModel DataModel(Selection selection)
 
-         {
 
-             var ids = SelectedModels().Select(x => Guid.Parse(x.ID)).ToArray();
 
-             return new AutoDataModel<Kanban>(new Filter<Kanban>(x => x.ID).InList(ids));
 
-         }
 
-         private void ResizeColumns()
 
-         {
 
-             //if (!bResizeRequired)
 
-             //    return;
 
-             using (var d = Dispatcher.DisableProcessing())
 
-             {
 
-                 var CollapsedWidth = 50;
 
-                 var CollapsedColumns = 0;
 
-                 Array.ForEach(Kanban.Columns.ToArray(), x => { CollapsedColumns += x.IsExpanded ? 0 : 1; });
 
-                 if (Kanban.Columns.Count > 0 && CollapsedColumns != Kanban.Columns.Count)
 
-                 {
 
-                     var ColumnWidth = (Kanban.ActualWidth - CollapsedColumns * CollapsedWidth) / (Kanban.Columns.Count - CollapsedColumns) - 2;
 
-                     if (ColumnWidth != Kanban.ColumnWidth) Kanban.ColumnWidth = ColumnWidth;
 
-                     //bResizeRequired = false;
 
-                 }
 
-             }
 
-         }
 
-         private void TaskMenu_Opened(object sender, RoutedEventArgs e)
 
-         {
 
-             Host.PopulateMenu(this, sender as ContextMenu);
 
-         }
 
-         private void Kanban_SizeChanged(object sender, SizeChangedEventArgs e)
 
-         {
 
-             Kanban.ColumnWidth = Kanban.ActualWidth / Kanban.Columns.Count - 1.0F;
 
-         }
 
-         private void Kanban_CardDragStart(object sender, KanbanDragStartEventArgs e)
 
-         {
 
-             var models = SelectedModels(e.SelectedCard.Content as TaskModel);
 
-             if (models.Any(x => x.Locked))
 
-                 e.IsCancel = true;
 
-         }
 
-         private void Kanban_CardDragEnd(object sender, KanbanDragEndEventArgs e)
 
-         {
 
-             using (new WaitCursor())
 
-             {
 
-                 var target = e.TargetColumn.Categories;
 
-                 var models = SelectedModels(e.SelectedCard.Content as TaskModel).Where(x => !Equals(x.Category, target)).ToArray();
 
-                 if (!models.Any())
 
-                     return;
 
-                 var kanbans = Host.LoadKanbans(models, new Columns<Kanban>(x => x.ID, x => x.Category));
 
-                 foreach (var kanban in kanbans)
 
-                     kanban.Category = target;
 
-                 new Client<Kanban>().Save(kanbans, string.Format("Task Status Updated to {0}", target), (o, err) => { });
 
-                 foreach (var model in models)
 
-                 {
 
-                     model.Checked = false;
 
-                     model.Category = target;
 
-                 }
 
-                 FilterKanbans();
 
-             }
 
-         }
 
-         private void Search_KeyUp(object sender, KeyEventArgs e)
 
-         {
 
-             if (string.IsNullOrWhiteSpace(Search.Text) || e.Key == Key.Return)
 
-             {
 
-                 searchtext = Search.Text;
 
-                 Refresh(true);
 
-             }
 
-         }
 
-         private void TaskTypes_SelectionChanged(object sender, SelectionChangedEventArgs e)
 
-         {
 
-             if (!IsReady)
 
-                 return;
 
-             if (e.AddedItems.Count > 0)
 
-             {
 
-                 var item = (KeyValuePair<Guid, string>)e.AddedItems[0];
 
-                 selectedtype = item.Key;
 
-             }
 
-             else
 
-             {
 
-                 selectedtype = CoreUtils.FullGuid;
 
-             }
 
-             Host.Settings.StatusSettings.SelectedType = selectedtype;
 
-             Host.SaveSettings();
 
-             ReloadKanbans();
 
-         }
 
-         private void IncludeCompleted_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             if (!IsReady)
 
-                 return;
 
-             Host.Settings.StatusSettings.IncludeCompleted = IncludeCompleted.IsChecked.Value;
 
-             Host.SaveSettings();
 
-             SetupColumns();
 
-             ReloadKanbans();
 
-         }
 
-         private void IncludeObserved_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             if (!IsReady)
 
-                 return;
 
-             Host.Settings.StatusSettings.IncludeObserved = IncludeObserved.IsChecked.Value;
 
-             Host.SaveSettings();
 
-             ReloadKanbans();
 
-         }
 
-         private void IncludeLocked_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             if (!IsReady)
 
-                 return;
 
-             Host.Settings.StatusSettings.IncludeLocked = IncludeLocked.IsChecked.Value;
 
-             Host.SaveSettings();
 
-             ReloadKanbans();
 
-         }
 
-         private void ViewType_SelectionChanged(object sender, SelectionChangedEventArgs e)
 
-         {
 
-             if (Kanban != null)
 
-                 Kanban.CardTemplate = ViewType.SelectedIndex > 0
 
-                     ? Resources["CompactKanban"] as DataTemplate
 
-                     : Resources["FullKanban"] as DataTemplate;
 
-             if (IsReady)
 
-             {
 
-                 Host.Settings.StatusSettings.CompactView = ViewType.SelectedIndex > 0;
 
-                 Host.SaveSettings();
 
-             }
 
-         }
 
-         private static bool UpdatingEmployees = false;
 
-         private void Employees_SelectionChanged(object sender, SelectionChangedEventArgs e)
 
-         {
 
-             if (UpdatingEmployees)
 
-                 return;
 
-             if (e.AddedItems.Count == 0)
 
-             {
 
-                 EmployeeID = Guid.Empty;
 
-             }
 
-             else
 
-             {
 
-                 var model = _employeelist[Employees.SelectedIndex];
 
-                 EmployeeID = model.ID;
 
-             }
 
-             CheckedKanbans.Clear();
 
-             if (IsReady)
 
-                 Refresh(true);
 
-         }
 
-         private void Export_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var form = new DynamicExportForm(typeof(Kanban), _kanbans.Columns.Select(x => x.ColumnName));
 
-             if (form.ShowDialog() != true)
 
-                 return;
 
-             var export = new Client<Kanban>().Query(
 
-                 GetKanbanFilter(),
 
-                 new Columns<Kanban>(form.Fields),
 
-                 LookupFactory.DefineSort<Kanban>()
 
-             );
 
-             var employee = "Tasks for All Staff";
 
-             if (EmployeeID != CoreUtils.FullGuid)
 
-             {
 
-                 if (EmployeeID == Guid.Empty)
 
-                 {
 
-                     employee = "Unallocated Tasks";
 
-                 }
 
-                 else
 
-                 {
 
-                     var model = _employeelist.FirstOrDefault(x => x.ID.Equals(EmployeeID));
 
-                     employee = model == null ? "Tasks for (Unknown)" : "Tasks for " + (model.ID == MyID ? MyName : model.Name);
 
-                 }
 
-             }
 
-             ExcelExporter.DoExport<Kanban>(
 
-                 export,
 
-                 string.Format(
 
-                     "{0} ({1:dd-MMM-yy})",
 
-                     employee,
 
-                     DateTime.Today
 
-                 )
 
-             );
 
-         }
 
-         #region ITaskControl Support
 
-         public bool IsReady { get; set; }
 
-         public ITaskHost Host { get; set; }
 
-         public KanbanView KanbanView => KanbanView.Status;
 
-         public IEnumerable<TaskModel> SelectedModels(TaskModel sender = null)
 
-         {
 
-             var result = _models.Where(x => x.Checked).ToList();
 
-             if (sender != null && !result.Contains(sender))
 
-                 result.Add(sender);
 
-             return result;
 
-         }
 
-         #endregion
 
-         #region Setup
 
-         public void Setup()
 
-         {
 
-             SetupToolbar();
 
-             SetupColumns();
 
-             SetupData();
 
-             SetupKanbanTypesLookup();
 
-             SetupMyEmployee();
 
-             SetupEmployeeList();
 
-         }
 
-         private void SetupMyEmployee()
 
-         {
 
-             var row = _employees.Rows.FirstOrDefault(r => r.Get<Employee, Guid>(c => c.UserLink.ID) == ClientFactory.UserGuid);
 
-             if (row != null)
 
-             {
 
-                 MyID = row.Get<Employee, Guid>(c => c.ID);
 
-                 MyName = row.Get<Employee, string>(x => x.Name);
 
-             }
 
-         }
 
-         private void SetupEmployeeList()
 
-         {
 
-             IEnumerable<CoreRow> active = null;
 
-             var anonymous = PRSDesktop.Resources.anonymous.AsBitmapImage();
 
-             if (Security.IsAllowed<CanViewOthersTasks>())
 
-             {
 
-                 active = _employees.Rows.Where(r =>
 
-                     r.Get<Employee, bool>(x => x.CanAllocateTasks) && (r.Get<Employee, DateTime>(x => x.FinishDate).IsEmpty() ||
 
-                                                                        r.Get<Employee, DateTime>(x => x.FinishDate) > DateTime.Today));
 
-                 _employeelist.Add(new EmployeeModel(CoreUtils.FullGuid, "All Staff", Guid.Empty, PRSDesktop.Resources.everyone.AsBitmapImage()));
 
-                 _employeelist.Add(new EmployeeModel(Guid.Empty, "Unallocated", Guid.Empty, null));
 
-             }
 
-             else
 
-             {
 
-                 active = _employees.Rows.Where(r => r.Get<Employee, Guid>(c => c.UserLink.ID).Equals(ClientFactory.UserGuid));
 
-             }
 
-             EmployeeModel selected = null;
 
-             foreach (var row in active)
 
-             {
 
-                 var id = row.Get<Employee, Guid>(x => x.ID);
 
-                 var userid = row.Get<Employee, Guid>(x => x.UserLink.ID);
 
-                 var thumbnailid = row.Get<Employee, Guid>(x => x.Thumbnail.ID);
 
-                 var name = userid.Equals(ClientFactory.UserGuid) ? "My Tasks" : row.Get<Employee, string>(x => x.Name);
 
-                 var model = new EmployeeModel(id, name, thumbnailid, anonymous);
 
-                 if (userid.Equals(ClientFactory.UserGuid))
 
-                 {
 
-                     _employeelist.Insert(0, model);
 
-                     selected = model;
 
-                 }
 
-                 else
 
-                 {
 
-                     _employeelist.Add(model);
 
-                 }
 
-             }
 
-             if (Security.IsAllowed<CanViewOthersTasks>())
 
-             {
 
-                 EmployeeListColumn.Width = new GridLength(1.0F, GridUnitType.Auto);
 
-                 var thumbnails = active
 
-                     .Select(r => r.EntityLinkID<Employee, ImageDocumentLink>(x => x.Thumbnail) ?? Guid.Empty)
 
-                     .Where(x => x != Guid.Empty).ToArray();
 
-                 Employees.ItemsSource = _employeelist;
 
-                 Employees.SelectedItem = _employeelist.First();
 
-                 EmployeeID = _employeelist.First().ID;
 
-                 if (thumbnails.Any())
 
-                     new Client<Document>().Query(
 
-                         new Filter<Document>(x => x.ID).InList(thumbnails),
 
-                         new Columns<Document>(x => x.ID, x => x.Data),
 
-                         null,
 
-                         (data, error) =>
 
-                         {
 
-                             if (data != null)
 
-                                 ProcessThumbnails(data);
 
-                         }
 
-                     );
 
-             }
 
-             else
 
-             {
 
-                 EmployeeListColumn.Width = new GridLength(0.0F, GridUnitType.Pixel);
 
-                 Employees.ItemsSource = _employeelist;
 
-                 Employees.SelectedItem = _employeelist.First();
 
-                 EmployeeID = _employeelist.First().ID;
 
-             }
 
-         }
 
-         private void ProcessThumbnails(CoreTable data)
 
-         {
 
-             Dispatcher.Invoke(() =>
 
-             {
 
-                 foreach (var row in data.Rows)
 
-                 {
 
-                     var id = row.Get<Document, Guid>(x => x.ID);
 
-                     var model = _employeelist.FirstOrDefault(x => x.ThumbnailID.Equals(id));
 
-                     if (model != null)
 
-                     {
 
-                         model.Image = new BitmapImage();
 
-                         model.Image.LoadImage(row.Get<Document, byte[]>(x => x.Data));
 
-                     }
 
-                 }
 
-                 UpdatingEmployees = true;
 
-                 Employees.ItemsSource = null;
 
-                 Employees.ItemsSource = _employeelist;
 
-                 Employees.SelectedItem = _employeelist.First();
 
-                 EmployeeID = _employeelist.First().ID;
 
-                 UpdatingEmployees = false;
 
-             });
 
-         }
 
-         private void SetupKanbanTypesLookup()
 
-         {
 
-             if (ClientFactory.IsSupported<KanbanType>())
 
-             {
 
-                 var tasktypes = new Dictionary<Guid, string>
 
-                 {
 
-                     { CoreUtils.FullGuid, "All Types" },
 
-                     { Guid.Empty, "Unallocated Types" }
 
-                 };
 
-                 _types.IntoDictionary<KanbanType, Guid, string>(tasktypes, x => x.ID, row => row.Get<KanbanType, string>(x => x.Description));
 
-                 TaskTypes.ItemsSource = tasktypes;
 
-                 if (tasktypes.ContainsKey(Host.Settings.StatusSettings.SelectedType))
 
-                     TaskTypes.SelectedValue = Host.Settings.StatusSettings.SelectedType;
 
-                 else
 
-                     TaskTypes.SelectedValue = CoreUtils.FullGuid;
 
-                 TaskTypesLabel.Visibility = Visibility.Visible;
 
-                 TaskTypes.Visibility = Visibility.Visible;
 
-             }
 
-             else
 
-             {
 
-                 TaskTypesLabel.Visibility = Visibility.Collapsed;
 
-                 TaskTypes.Visibility = Visibility.Collapsed;
 
-             }
 
-         }
 
-         private void SetupToolbar()
 
-         {
 
-             IncludeCompleted.Visibility = Security.IsAllowed<CanHideTaskCompletedColumn>() ? Visibility.Visible : Visibility.Collapsed;
 
-             IncludeCompleted.IsChecked = IncludeCompleted.Visibility == Visibility.Visible ? Host.Settings.StatusSettings.IncludeCompleted : true;
 
-             IncludeObserved.IsChecked = Host.Settings.StatusSettings.IncludeObserved;
 
-             ViewType.SelectedIndex = Host.Settings.StatusSettings.CompactView ? 1 : 0;
 
-         }
 
-         private void SetupColumns()
 
-         {
 
-             Kanban.Columns.Clear();
 
-             var indicatorColorPalette = new IndicatorColorPalette();
 
-             indicatorColorPalette.Add(new ColorMapping { Key = "Red", Color = Colors.LightSalmon });
 
-             indicatorColorPalette.Add(new ColorMapping { Key = "Orange", Color = Colors.Orange });
 
-             indicatorColorPalette.Add(new ColorMapping { Key = "Yellow", Color = Colors.LightYellow });
 
-             indicatorColorPalette.Add(new ColorMapping { Key = "Green", Color = Colors.LightGreen });
 
-             Kanban.IndicatorColorPalette = indicatorColorPalette;
 
-             Kanban.Columns.Add(new KanbanColumn
 
-             {
 
-                 Categories = "Open",
 
-                 Title = "To Do"
 
-             });
 
-             Kanban.Columns.Add(new KanbanColumn
 
-             {
 
-                 Categories = "In Progress",
 
-                 Title = "In Progress"
 
-             });
 
-             Kanban.Columns.Add(new KanbanColumn
 
-             {
 
-                 Categories = "Waiting",
 
-                 Title = "Waiting for Others"
 
-             });
 
-             if (Host.Settings.StatusSettings.IncludeCompleted)
 
-                 Kanban.Columns.Add(new KanbanColumn
 
-                 {
 
-                     Categories = "Complete",
 
-                     Title = "Completed"
 
-                 });
 
-             Kanban.InvalidateVisual();
 
-             foreach (var column in Kanban.Columns)
 
-             {
 
-                 var menu = new ContextMenu();
 
-                 menu.Tag = column;
 
-                 var item = new MenuItem { Header = "New Task" };
 
-                 item.Click += CreateTask;
 
-                 menu.Items.Add(item);
 
-                 menu.Items.Add(new Separator());
 
-                 item = new MenuItem { Header = "Select All " + column.Title + " Tasks", Tag = column };
 
-                 item.Click += SelectAll_Click;
 
-                 menu.Items.Add(item);
 
-                 item = new MenuItem { Header = "Unselect All " + column.Title + " Tasks", Tag = column };
 
-                 item.Click += UnSelectAll_Click;
 
-                 menu.Items.Add(item);
 
-                 column.ContextMenu = menu;
 
-             }
 
-             Kanban.ColumnWidth = Kanban.ActualWidth / Kanban.Columns.Count - 1.0F;
 
-         }
 
-         private void SetupData()
 
-         {
 
-             var query = new MultiQuery();
 
-             query.Add(
 
-                 null,
 
-                 new Columns<Employee>(x => x.ID, x => x.Name, x => x.Thumbnail.ID, x => x.CanAllocateTasks, x => x.Email, x => x.Mobile,
 
-                     x => x.FinishDate, x => x.UserLink.ID),
 
-                 new SortOrder<Employee>(x => x.Name)
 
-             );
 
-             if (ClientFactory.IsSupported<KanbanType>())
 
-                 query.Add(
 
-                     new Filter<KanbanType>(x => x.Hidden).IsEqualTo(false),
 
-                     new Columns<KanbanType>(x => x.ID, x => x.Description),
 
-                     new SortOrder<KanbanType>(x => x.Description)
 
-                 );
 
-             query.Query();
 
-             _employees = query.Get<Employee>();
 
-             _types = ClientFactory.IsSupported<KanbanType>()
 
-                 ? query.Get<KanbanType>()
 
-                 : null;
 
-         }
 
-         #endregion
 
-         #region Refresh / Reload
 
-         private Filter<T> GetSearchFilter<T>(Expression<Func<T, object>> expression) where T : Entity, new()
 
-         {
 
-             Filter<T> result = null;
 
-             var comps = searchtext.Trim().Split(' ');
 
-             foreach (var comp in comps)
 
-                 result = result == null ? new Filter<T>(expression).Contains(comp) : result.And(expression).Contains(comp);
 
-             return result;
 
-         }
 
-         private Filter<KanbanSubscriber> GetKanbanSubscriberFilter()
 
-         {
 
-             var filter = new Filter<KanbanSubscriber>(x => x.Kanban.Closed).IsEqualTo(DateTime.MinValue);
 
-             if (Host.JobID != Guid.Empty)
 
-                 filter = filter.And(x => x.Kanban.JobLink.ID).IsEqualTo(Host.JobID);
 
-             // All Tasks (EmployeeID.HasValue == false) or Unallocated (EmployeeID = Guid.Empty) are retrieved directly from the Kanban Table
 
-             // so if we are here, we can assume that we are pulling subscriber data
 
-             var empfilter = new Filter<KanbanSubscriber>(x => x.Employee.ID).IsEqualTo(EmployeeID);
 
-             filter.Ands.Add(empfilter);
 
-             if (EmployeeID != MyID)
 
-                 filter = filter.And(x => x.Kanban.Private).IsEqualTo(false);
 
-             //if (!includeobserved)
 
-             //    filter = filter.And(new Filter<KanbanSubscriber>(x => x.Assignee).IsEqualTo(true).Or(x => x.Manager).IsEqualTo(true));
 
-             //if (!includecompleted)
 
-             //    filter = filter.And(x => x.Kanban.Completed).IsEqualTo(DateTime.MinValue);
 
-             //if (selectedtype != CoreUtils.FullGuid)
 
-             //    filter = filter.And(x => x.Kanban.Type.ID).IsEqualTo(selectedtype);
 
-             if (!string.IsNullOrWhiteSpace(searchtext))
 
-             {
 
-                 var search = GetSearchFilter<KanbanSubscriber>(x => x.Kanban.JobLink.Name);
 
-                 search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.JobLink.JobNumber));
 
-                 search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.Summary));
 
-                 search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.Title));
 
-                 search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.ManagerLink.Name));
 
-                 search.Ors.Add(GetSearchFilter<KanbanSubscriber>(x => x.Kanban.EmployeeLink.Name));
 
-                 if (int.TryParse(searchtext.Trim(), out var tasknumber))
 
-                     search.Ors.Add(new Filter<KanbanSubscriber>(x => x.Kanban.Number).IsEqualTo(tasknumber));
 
-                 filter.Ands.Add(search);
 
-             }
 
-             return filter;
 
-         }
 
-         private Filter<Kanban> GetKanbanFilter()
 
-         {
 
-             var filter = new Filter<Kanban>(x => x.Closed).IsEqualTo(DateTime.MinValue);
 
-             if (Host.JobID != Guid.Empty)
 
-                 filter = filter.And(x => x.JobLink.ID).IsEqualTo(Host.JobID);
 
-             if (EmployeeID != CoreUtils.FullGuid)
 
-             {
 
-                 if (EmployeeID != Guid.Empty)
 
-                 {
 
-                     var empfilter = new Filter<Kanban>(x => x.EmployeeLink.ID).IsEqualTo(EmployeeID).Or(x => x.ManagerLink.ID).IsEqualTo(EmployeeID);
 
-                     filter.Ands.Add(empfilter);
 
-                 }
 
-                 else
 
-                 {
 
-                     filter = filter.And(x => x.EmployeeLink.ID).IsEqualTo(EmployeeID);
 
-                 }
 
-             }
 
-             if (EmployeeID != MyID)
 
-                 filter = filter.And(x => x.Private).IsEqualTo(false);
 
-             //if (!includecompleted)
 
-             //    filter = filter.And(x => x.Completed).IsEqualTo(DateTime.MinValue);
 
-             //if (selectedtype != CoreUtils.FullGuid)
 
-             //    filter = filter.And(x => x.Type.ID).IsEqualTo(selectedtype);
 
-             return filter;
 
-         }
 
-         public void Refresh(bool resetselection)
 
-         {
 
-             Application.Current.Dispatcher.Invoke(() => { Mouse.OverrideCursor = Cursors.Wait; });
 
-             if (EmployeeID != CoreUtils.FullGuid && EmployeeID != Guid.Empty)
 
-             {
 
-                 _kanbans = new Client<KanbanSubscriber>().Query(
 
-                     GetKanbanSubscriberFilter(),
 
-                     new Columns<KanbanSubscriber>
 
-                     (
 
-                         x => x.Kanban.ID,
 
-                         x => x.Kanban.DueDate,
 
-                         x => x.Kanban.Completed,
 
-                         //x => x.Kanban.Description,
 
-                         x => x.Kanban.Summary,
 
-                         x => x.Kanban.Category,
 
-                         x => x.Kanban.EmployeeLink.ID,
 
-                         x => x.Kanban.ManagerLink.ID,
 
-                         x => x.Kanban.Notes,
 
-                         x => x.Kanban.Title,
 
-                         x => x.Kanban.JobLink.ID,
 
-                         x => x.Kanban.JobLink.JobNumber,
 
-                         x => x.Kanban.JobLink.Name,
 
-                         x => x.Kanban.Type.ID,
 
-                         x => x.Kanban.Type.Code,
 
-                         x => x.Kanban.Number,
 
-                         x => x.Kanban.Attachments,
 
-                         x => x.Kanban.Locked
 
-                     ),
 
-                     new SortOrder<KanbanSubscriber>(x => x.Kanban.DueDate) { Direction = SortDirection.Ascending }
 
-                 );
 
-                 foreach (var column in _kanbans.Columns)
 
-                     column.ColumnName = column.ColumnName.Replace("Kanban.", "");
 
-             }
 
-             else
 
-             {
 
-                 _kanbans = new Client<Kanban>().Query(
 
-                     GetKanbanFilter(),
 
-                     new Columns<Kanban>
 
-                     (
 
-                         x => x.ID,
 
-                         x => x.DueDate,
 
-                         x => x.Completed,
 
-                         //x => x.Description,
 
-                         x => x.Summary,
 
-                         x => x.Category,
 
-                         x => x.EmployeeLink.ID,
 
-                         x => x.ManagerLink.ID,
 
-                         x => x.Notes,
 
-                         x => x.Title,
 
-                         x => x.JobLink.ID,
 
-                         x => x.JobLink.JobNumber,
 
-                         x => x.JobLink.Name,
 
-                         x => x.Type.ID,
 
-                         x => x.Type.Code,
 
-                         x => x.Number,
 
-                         x => x.Attachments,
 
-                         x => x.Locked
 
-                     ),
 
-                     new SortOrder<Kanban>(x => x.DueDate) { Direction = SortDirection.Ascending }
 
-                 );
 
-             }
 
-             ReloadKanbans();
 
-             Application.Current.Dispatcher.Invoke(() => { Mouse.OverrideCursor = null; });
 
-         }
 
-         private void ReloadKanbans()
 
-         {
 
-             //SetupColumns();
 
-             //ResizeColumns();
 
-             _models = new ObservableCollection<TaskModel>();
 
-             foreach (var row in _kanbans.Rows)
 
-                 try
 
-                 {
 
-                     var empid = row.Get<IKanban, Guid>(e => e.EmployeeLink.ID);
 
-                     var mgrid = row.EntityLinkID<IKanban, EmployeeLink>(x => x.ManagerLink) ?? Guid.Empty;
 
-                     var completed = row.Get<IKanban, DateTime>(e => e.Completed);
 
-                     var locked = row.Get<IKanban, bool>(e => e.Locked);
 
-                     var type = row.Get<IKanban, Guid>(e => e.Type.ID);
 
-                     var category = row.Get<IKanban, string>(x => x.Category);
 
-                     if (string.IsNullOrWhiteSpace(category))
 
-                         category = "Open";
 
-                     var bLockedOK = Host.Settings.StatusSettings.IncludeLocked || locked == false;
 
-                     var bObserveOK = EmployeeID == CoreUtils.FullGuid || Host.Settings.StatusSettings.IncludeObserved || empid == EmployeeID || mgrid == EmployeeID;
 
-                     var bCompleteOK = Host.Settings.StatusSettings.IncludeCompleted || completed.IsEmpty();
 
-                     var bTypeOK = selectedtype == CoreUtils.FullGuid || type == selectedtype;
 
-                     if (bLockedOK && bCompleteOK && bObserveOK && bTypeOK)
 
-                     {
 
-                         var model = new TaskModel();
 
-                         var EmployeeEntry = _employeelist.Where(x => x.ID.Equals(empid)).FirstOrDefault();
 
-                         var empimg = EmployeeEntry?.Image;
 
-                         var ManagerEntry = _employeelist.Where(x => x.ID.Equals(mgrid)).FirstOrDefault();
 
-                         //var description = row.Get<IKanban, String>(x => x.Summary);
 
-                         //if (String.IsNullOrWhiteSpace(description))
 
-                         //    description = String.Join("\r\n", row.Get<IKanban, String[]>(x => x.Notes)).Split(new String[] { "===============" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
 
-                         //if (String.IsNullOrWhiteSpace(description))
 
-                         //    description = CoreUtils.StripHTML(row.Get<IKanban, String>(x => x.Description));
 
-                         //if (String.IsNullOrWhiteSpace(description))
 
-                         //    description = "";
 
-                         var job = row.Get<IKanban, string>(x => x.JobLink.JobNumber);
 
-                         model.Title = row.Get<IKanban, string>(x => x.Title);
 
-                         model.ID = row.Get<IKanban, Guid>(x => x.ID).ToString();
 
-                         model.Description = row.Get<IKanban, string>(x => x.Summary) ?? "";
 
-                         model.Category = category;
 
-                         var color = EmployeeID == Guid.Empty || empid == EmployeeID || EmployeeID == CoreUtils.FullGuid
 
-                             ? TaskModel.KanbanColor(
 
-                                 row.Get<IKanban, DateTime>(x => x.DueDate),
 
-                                 row.Get<IKanban, DateTime>(x => x.Completed))
 
-                             : mgrid == EmployeeID
 
-                                 ? Color.Silver
 
-                                 : Color.Plum;
 
-                         if (row.Get<IKanban, bool>(x => x.Locked))
 
-                             color = color.MixColors(0.5F, Color.White);
 
-                         model.ColorKey = ImageUtils.ColorToString(color);
 
-                         model.Image = empimg;
 
-                         model.ImageURL = null;
 
-                         model.Attachments = row.Get<IKanban, int>(x => x.Attachments) > 0; // ? _attachimg : null;
 
-                         model.DueDate = row.Get<IKanban, DateTime>(x => x.DueDate);
 
-                         model.CompletedDate = row.Get<IKanban, DateTime>(x => x.Completed);
 
-                         model.Locked = row.Get<IKanban, bool>(x => x.Locked); // ? _lockimg : null;
 
-                         var notes = new List<List<string>> { new() };
 
-                         foreach (var line in row.Get<IKanban, string[]>(x => x.Notes))
 
-                         {
 
-                             if (line == "===================================")
 
-                             {
 
-                                 notes.Add(new());
 
-                             }
 
-                             else
 
-                             {
 
-                                 notes.Last().Add(line);
 
-                             }
 
-                         }
 
-                         model.Notes = string.Join("\n===================================\n", notes.Reverse<List<string>>().Select(x => string.Join('\n', x)));
 
-                         model.EmployeeID = empid;
 
-                         model.ManagerID = mgrid;
 
-                         var sEmp = "";
 
-                         if (empid != EmployeeID)
 
-                         {
 
-                             if (!Entity.IsEntityLinkValid<IKanban, EmployeeLink>(x => x.EmployeeLink, row))
 
-                             {
 
-                                 sEmp = "Unallocated";
 
-                             }
 
-                             else
 
-                             {
 
-                                 var tuple = _employeelist.FirstOrDefault(x => x.ID.Equals(empid));
 
-                                 sEmp = tuple != null ? tuple.ID == MyID ? MyName : tuple.Name : "";
 
-                             }
 
-                         }
 
-                         var sMgr = "";
 
-                         if (mgrid != EmployeeID)
 
-                             if (mgrid != Guid.Empty)
 
-                             {
 
-                                 var tuple = _employeelist.FirstOrDefault(x => x.ID.Equals(mgrid));
 
-                                 sMgr = tuple != null ? tuple.ID == MyID ? MyName : tuple.Name : "";
 
-                             }
 
-                         if (!string.IsNullOrEmpty(sEmp))
 
-                         {
 
-                             if (!string.IsNullOrWhiteSpace(sMgr) && !string.Equals(sMgr, sEmp))
 
-                                 model.AssignedTo = string.Format("Assigned to {0} by {1}", sEmp, sMgr);
 
-                             else
 
-                                 model.AssignedTo = string.Format("Assigned to {0} ", sEmp);
 
-                         }
 
-                         else
 
-                         {
 
-                             if (!string.IsNullOrWhiteSpace(sMgr))
 
-                                 model.AssignedTo = string.Format("Allocated by {0} ", sMgr);
 
-                         }
 
-                         //model.AssignedTo = String.Format("M: {0} / E: {1}", sMgr, sEmp);
 
-                         model.JobID = row.Get<IKanban, Guid>(x => x.JobLink.ID);
 
-                         model.JobNumber = row.Get<IKanban, string>(x => x.JobLink.JobNumber);
 
-                         if (string.IsNullOrWhiteSpace(model.JobNumber))
 
-                             model.JobNumber = "";
 
-                         model.JobName = row.Get<IKanban, string>(x => x.JobLink.Name);
 
-                         model.Checked = CheckedKanbans.Contains(row.Get<IKanban, Guid>(x => x.ID).ToString());
 
-                         model.Type = new KanbanType
 
-                         {
 
-                             ID = row.Get<IKanban, Guid>(x => x.Type.ID),
 
-                             Code = row.Get<IKanban, string>(x => x.Type.Code)
 
-                         };
 
-                         model.Number = row.Get<IKanban, int>(x => x.Number);
 
-                         _models.Add(model);
 
-                     }
 
-                 }
 
-                 catch (Exception e)
 
-                 {
 
-                     Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
 
-                 }
 
-             StatusTasksHeaderTimeConverter.Tasks = _models;
 
-             FilterKanbans();
 
-         }
 
-         private void FilterKanbans()
 
-         {
 
-             Kanban.ItemsSource = _models
 
-                 .Where(x => x.Search(Search.Text.Split()))
 
-                 .OrderBy(x => x.EmployeeID == EmployeeID ? 0 : 1).ThenBy(x => x.DueDate);
 
-             ;
 
-         }
 
-         #endregion
 
-         #region Kanban Selection Stuff
 
-         private void SelectColumn(KanbanColumn column, bool selected)
 
-         {
 
-             CheckedKanbans.Clear();
 
-             if (selected)
 
-             {
 
-                 CheckedKanbans.AddRange(_models.Where(x => Equals(x.Category, column.Categories)).Select(x => x.ID));
 
-                 foreach (var model in _models)
 
-                     model.Checked = Equals(model.Category, column.Categories);
 
-             }
 
-             FilterKanbans();
 
-         }
 
-         private void UnSelectAll_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var column = ((MenuItem)sender).Tag as KanbanColumn;
 
-             SelectColumn(column, false);
 
-         }
 
-         private void SelectAll_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var column = ((MenuItem)sender).Tag as KanbanColumn;
 
-             SelectColumn(column, true);
 
-         }
 
-         //private IEnumerable<Guid> GetSelectedKanbanIDs(String currentid)
 
-         //{
 
-         //    List<Guid> result = new List<Guid>();
 
-         //    if (!CheckedKanbans.Contains(currentid))
 
-         //        result.Add(Guid.Parse(currentid));
 
-         //    CheckedKanbans.ForEach((id) => result.Add(Guid.Parse(id)));
 
-         //    return result;
 
-         //}
 
-         //private Kanban[] GetSelectedKanbans(String currentid)
 
-         //{
 
-         //    var ids = GetSelectedKanbanIDs(currentid);
 
-         //    return Host.LoadKanbans(ids).ToArray();
 
-         //}
 
-         private void CheckBox_Checked(object sender, RoutedEventArgs e)
 
-         {
 
-             var task = ((CheckBox)sender).Tag as TaskModel;
 
-             if (task == null)
 
-                 return;
 
-             if (CheckedKanbans.Contains(task.ID))
 
-                 CheckedKanbans.Remove(task.ID);
 
-             else
 
-                 CheckedKanbans.Add(task.ID);
 
-         }
 
-         #endregion
 
-         #region Context Menu Actions
 
-         private void CreateTask(object sender, RoutedEventArgs e)
 
-         {
 
-             CreateKanban();
 
-         }
 
-         private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 
-         {
 
-             if (e.ClickCount > 1)
 
-             {
 
-                 var task = ((Border)sender).Tag as TaskModel;
 
-                 DoEdit(task);
 
-                 e.Handled = true;
 
-             }
 
-         }
 
-         private void EditTask_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var task = ((MenuItem)e.Source).Tag as TaskModel;
 
-             DoEdit(task);
 
-             e.Handled = true;
 
-         }
 
-         //private void CreateSetout_Click(object sender, RoutedEventArgs e)
 
-         //{
 
-         //    MenuItem menu = sender as MenuItem;
 
-         //    TaskModel task = menu.Tag as TaskModel;
 
-         //    if (task.JobID.Equals(Guid.Empty))
 
-         //    {
 
-         //        MessageBox.Show("Please link this task to a job before creating a setout!");
 
-         //        return;
 
-         //    }
 
-         //    if (MessageBox.Show("This will convert this task into a Setout.\n\nDo you wish to continue?", "Confirmation", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
 
-         //        return;
 
-         //    ManufacturingTemplate template = new Client<ManufacturingTemplate>().Load(new Filter<ManufacturingTemplate>(x => x.Code).IsEqualTo("PRS")).FirstOrDefault();
 
-         //    if (template == null)
 
-         //    {
 
-         //        MessageBox.Show("[Pressing] Template does not exist!");
 
-         //        return;
 
-         //    }
 
-         //    String setoutnumber = "";
 
-         //    Progress.ShowModal("Creating Setout", (progress) =>
 
-         //    {
 
-         //        MultiQuery query = new MultiQuery();
 
-         //        query.Add<ManufacturingTemplateStage>(
 
-         //            new Filter<ManufacturingTemplateStage>(x => x.Template.ID).IsEqualTo(template.ID),
 
-         //            null,
 
-         //            new SortOrder<ManufacturingTemplateStage>(x => x.Sequence)
 
-         //        );
 
-         //        query.Add<Kanban>(
 
-         //            new Filter<Kanban>(x => x.ID).IsEqualTo(task.ID),
 
-         //            null,
 
-         //            null
 
-         //        );
 
-         //        query.Query();
 
-         //        ManufacturingTemplateStage[] tstages = query.Get<ManufacturingTemplateStage>().Rows.Select(x => x.ToObject<ManufacturingTemplateStage>()).ToArray();
 
-         //        Kanban kanban = query.Get<Kanban>().Rows.FirstOrDefault()?.ToObject<Kanban>();
 
-         //        progress.Report("Creating Setouts");
 
-         //        CoreTable setouts = new Client<Setout>().Query(
 
-         //            new Filter<Setout>(x => x.JobLink.ID).IsEqualTo(kanban.JobLink.ID),
 
-         //            new Columns<Setout>(x => x.JobLink.JobNumber, x => x.Number),
 
-         //            null
 
-         //         );
 
-         //        int ireq = 0;
 
-         //        String sreq = "";
 
-         //        while (true)
 
-         //        {
 
-         //            ireq++;
 
-         //            sreq = String.Format("{0}-{1:yyMMdd}-{2}", kanban.JobLink.JobNumber, DateTime.Now, ireq);
 
-         //            if (!setouts.Rows.Any(r => sreq.Equals(r.Get<Setout, String>(c => c.Number))))
 
-         //                break;
 
-         //        }
 
-         //        Setout setout = new Setout();
 
-         //        setout.Number = sreq;
 
-         //        setout.JobLink.ID = kanban.JobLink.ID; // = new Client<Job>().Load(new Filter<Job>(x => x.ID).IsEqualTo(kanban.JobLink.ID)).FirstOrDefault();
 
-         //        setout.Reference = kanban.Title;
 
-         //        var notes = kanban.Notes.ToList();
 
-         //        var description = kanban.Summary;
 
-         //        if (String.IsNullOrWhiteSpace(description))
 
-         //            description = CoreUtils.StripHTML(kanban.Description);
 
-         //        if (!String.IsNullOrWhiteSpace(description))
 
-         //            notes.Insert(0, description);
 
-         //        setout.Description = String.Join("\n==========================================\n", notes);
 
-         //        new Client<Setout>().Save(setout, "Created from Task");
 
-         //        setoutnumber = setout.Number;
 
-         //        progress.Report("Creating Manufacturing Packet");
 
-         //        ManufacturingPacket packet = new ManufacturingPacket()
 
-         //        {
 
-         //            Group = template.Factory.Name,
 
-         //            Serial = template.Code,
 
-         //            Title = kanban.Title,
 
-         //            Quantity = 1,
 
-         //            BarcodeQty = 1,
 
-         //            DueDate = kanban.DueDate
 
-         //        };
 
-         //        packet.SetoutLink.ID = setout.ID;
 
-         //        //packet.JobLink.ID = setout.JobLink.ID;
 
-         //        packet.ManufacturingTemplateLink.ID = template.ID;
 
-         //        packet.ManufacturingTemplateLink.Code = template.Code;
 
-         //        new Client<ManufacturingPacket>().Save(packet, "Created from Task");
 
-         //        List<ManufacturingPacketStage> pstages = new List<ManufacturingPacketStage>();
 
-         //        foreach (var tstage in tstages)
 
-         //        {
 
-         //            var pstage = new ManufacturingPacketStage()
 
-         //            {
 
-         //                Time = tstage.Time,
 
-         //                Sequence = tstage.Sequence,
 
-         //                SequenceType = tstage.SequenceType,
 
-         //                Started = DateTime.MinValue,
 
-         //                PercentageComplete = 0.0F,
 
-         //                Completed = DateTime.MinValue,
 
-         //                QualityChecks = tstage.QualityChecks,
 
-         //                QualityStatus = QualityStatus.NotChecked,
 
-         //                QualityNotes = "",
 
-         //            };
 
-         //            pstage.Parent.ID = packet.ID;
 
-         //            pstage.ManufacturingSectionLink.ID = tstage.Section.ID;
 
-         //            pstage.ManufacturingSectionLink.Name = tstage.Section.Name;
 
-         //            pstages.Add(pstage);
 
-         //        }
 
-         //        new Client<ManufacturingPacketStage>().Save(pstages, "Created from Task", (_, __) => { });
 
-         //        progress.Report("Processing Documents");
 
-         //        List<SetoutDocument> _setoutdocuments = new List<SetoutDocument>();
 
-         //        List<KanbanDocument> _kanbandocuments = new List<KanbanDocument>();
 
-         //        KanbanDocument[] docrefs = new Client<KanbanDocument>().Load(new Filter<KanbanDocument>(x => x.EntityLink.ID).IsEqualTo(kanban.ID));
 
-         //        foreach (var docref in docrefs)
 
-         //        {
 
-         //            Guid docid = ProcessSetoutDocument(docref);
 
-         //            var newdoc = new SetoutDocument();
 
-         //            newdoc.EntityLink.ID = setout.ID;
 
-         //            newdoc.DocumentLink.ID = docid;
 
-         //            _setoutdocuments.Add(newdoc);
 
-         //            if (docid != docref.DocumentLink.ID)
 
-         //            {
 
-         //                docref.DocumentLink.ID = docid;
 
-         //                _kanbandocuments.Add(docref);
 
-         //            }
 
-         //        }
 
-         //        new Client<SetoutDocument>().Save(_setoutdocuments, "Converted from Task", (_, __) => { });
 
-         //        new Client<KanbanDocument>().Save(_kanbandocuments, "Converted to PDF", (_, __) => { });
 
-         //        SetoutKanban link = new SetoutKanban();
 
-         //        link.Entity.ID = setout.ID;
 
-         //        link.Kanban.ID = kanban.ID;
 
-         //        new Client<SetoutKanban>().Save(link, "Converting Task -> Setout", (_, __) => { });
 
-         //        progress.Report("Updating Task");
 
-         //        kanban.Title = kanban.Title + " (" + setoutnumber + ")";
 
-         //        kanban.Locked = true;
 
-         //        new Client<Kanban>().Save(kanban, "Converting Kanban to Setout");
 
-         //    });
 
-         //    MessageBox.Show(String.Format("Created Setout {0}", setoutnumber));
 
-         //    Refresh();
 
-         //}
 
-         //private Guid ProcessSetoutDocument(KanbanDocument docref)
 
-         //{
 
-         //    Guid result = docref.DocumentLink.ID;
 
-         //    String ext = System.IO.Path.GetExtension(docref.DocumentLink.FileName).ToLower();
 
-         //    if (ext.EndsWith("txt"))
 
-         //    {
 
-         //        var doc = new Client<Document>().Load(new Filter<Document>(x => x.ID).IsEqualTo(docref.DocumentLink.ID)).FirstOrDefault();
 
-         //        PdfDocument pdf = new PdfDocument();
 
-         //        PdfPage page = pdf.Pages.Add();
 
-         //        PdfGraphics graphics = page.Graphics;
 
-         //        PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12);
 
-         //        String text = System.Text.Encoding.UTF8.GetString(doc.Data);
 
-         //        graphics.DrawString(text, font, PdfBrushes.Black, new PointF(0, 0));
 
-         //        MemoryStream ms = new MemoryStream();
 
-         //        pdf.Save(ms);
 
-         //        pdf.Close(true);
 
-         //        byte[] data = ms.ToArray();
 
-         //        var newdoc = new Document()
 
-         //        {
 
-         //            Data = data,
 
-         //            FileName = System.IO.Path.ChangeExtension(docref.DocumentLink.FileName, "pdf"),
 
-         //            CRC = CoreUtils.CalculateCRC(data),
 
-         //            TimeStamp = DateTime.Now,
 
-         //        };
 
-         //        new Client<Document>().Save(newdoc, "Converted from Text");
 
-         //        return newdoc.ID;
 
-         //    }
 
-         //    else if (ext.EndsWith("png") || ext.EndsWith("bmp") || ext.EndsWith("jpg") || ext.EndsWith("jpeg"))
 
-         //    {
 
-         //        var doc = new Client<Document>().Load(new Filter<Document>(x => x.ID).IsEqualTo(docref.DocumentLink.ID)).FirstOrDefault();
 
-         //        PdfBitmap image = new PdfBitmap(new MemoryStream(doc.Data));
 
-         //        PdfDocument pdf = new PdfDocument();
 
-         //        pdf.PageSettings.Orientation = image.Height > image.Width ? PdfPageOrientation.Portrait : PdfPageOrientation.Landscape;
 
-         //        pdf.PageSettings.Size = new SizeF(image.Width, image.Height);
 
-         //        PdfPage page = pdf.Pages.Add();
 
-         //        PdfGraphics graphics = page.Graphics;
 
-         //        graphics.DrawImage(image, 0.0F, 0.0F);
 
-         //        MemoryStream ms = new MemoryStream();
 
-         //        pdf.Save(ms);
 
-         //        pdf.Close(true);
 
-         //        byte[] data = ms.ToArray();
 
-         //        var newdoc = new Document()
 
-         //        {
 
-         //            Data = data,
 
-         //            FileName = System.IO.Path.ChangeExtension(docref.DocumentLink.FileName, "pdf"),
 
-         //            CRC = CoreUtils.CalculateCRC(data),
 
-         //            TimeStamp = DateTime.Now,
 
-         //        };
 
-         //        new Client<Document>().Save(newdoc, "Converted from Image");
 
-         //        return newdoc.ID;
 
-         //    }
 
-         //    return result;
 
-         //}
 
-         //private void CreateRequisition_Click(object sender, RoutedEventArgs e)
 
-         //{
 
-         //    MenuItem menu = sender as MenuItem;
 
-         //    TaskModel task = menu.Tag as TaskModel;
 
-         //    if (task.JobID.Equals(Guid.Empty))
 
-         //    {
 
-         //        MessageBox.Show("Please link this task to a job before creating a requisition!");
 
-         //        return;
 
-         //    }
 
-         //    if (MessageBox.Show("This will convert this task into a Requisition.\n\nDo you wish to continue?", "Confirmation", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
 
-         //        return;
 
-         //    int requinumber = 0;
 
-         //    Progress.ShowModal("Creating Requisition", (progress) =>
 
-         //    {
 
-         //        Kanban kanban = new Client<Kanban>().Load(new Filter<Kanban>(x => x.ID).IsEqualTo(task.ID)).FirstOrDefault();
 
-         //        Requisition requi = new Requisition();
 
-         //        requi.JobLink.ID = kanban.JobLink.ID;
 
-         //        requi.RequestedBy.ID = kanban.ManagerLink.ID;
 
-         //        requi.Employee.ID = Guid.Empty;
 
-         //        requi.Title = kanban.Title;
 
-         //        requi.Request = String.IsNullOrWhiteSpace(kanban.Summary)
 
-         //            ? String.IsNullOrWhiteSpace(kanban.Summary)
 
-         //                ? String.Join("\n", kanban.Notes)
 
-         //                : CoreUtils.StripHTML(kanban.Description)
 
-         //            : kanban.Summary;
 
-         //        requi.Notes = kanban.Notes;
 
-         //        requi.Due = kanban.DueDate;
 
-         //        new Client<Requisition>().Save(requi, "Created from Task");
 
-         //        requinumber = requi.Number;
 
-         //        progress.Report("Updating Documents");
 
-         //        List<RequisitionDocument> _documents = new List<RequisitionDocument>();
 
-         //        KanbanDocument[] documents = new Client<KanbanDocument>().Load(new Filter<KanbanDocument>(x => x.EntityLink.ID).IsEqualTo(kanban.ID));
 
-         //        foreach (var document in documents)
 
-         //        {
 
-         //            var newdoc = new RequisitionDocument();
 
-         //            newdoc.EntityLink.ID = requi.ID;
 
-         //            newdoc.DocumentLink.ID = document.DocumentLink.ID;
 
-         //            _documents.Add(newdoc);
 
-         //        }
 
-         //        new Client<RequisitionDocument>().Save(_documents, "Converted from Task", (_, __) => { });
 
-         //        RequisitionKanban link = new RequisitionKanban();
 
-         //        link.Entity.ID = requi.ID;
 
-         //        link.Kanban.ID = kanban.ID;
 
-         //        new Client<RequisitionKanban>().Save(link, "Converting Task -> Requisition", (_, __) => { });
 
-         //        progress.Report("Updating Task");
 
-         //        kanban.Category = "Open";
 
-         //        kanban.Completed = DateTime.MinValue;
 
-         //        kanban.Locked = true;
 
-         //        kanban.Title = kanban.Title + " (Requi #" + requi.Number.ToString() + ")";
 
-         //        new Client<Kanban>().Save(kanban, "Converted to Requisition", (_, __) => { });
 
-         //    });
 
-         //    MessageBox.Show(String.Format("Created Requisition {0}", requinumber));
 
-         //    Refresh();
 
-         //}
 
-         //private void CreatePurchaseOrder_Click(object sender, RoutedEventArgs e)
 
-         //{
 
-         //    MenuItem menu = sender as MenuItem;
 
-         //    TaskModel task = menu.Tag as TaskModel;
 
-         //    if (MessageBox.Show("This will convert this task into a Purchase Order.\n\nDo you wish to continue?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
 
-         //    {
 
-         //        String ponumber = "";
 
-         //        Progress.ShowModal("Creating Purchase Order", (progress) =>
 
-         //        {
 
-         //            Kanban kanban = new Client<Kanban>().Load(new Filter<Kanban>(x => x.ID).IsEqualTo(task.ID)).FirstOrDefault();
 
-         //            PurchaseOrder order = new PurchaseOrder();
 
-         //            order.Notes = kanban.Summary;
 
-         //            order.RaisedBy.ID = kanban.EmployeeLink.ID;
 
-         //            new Client<PurchaseOrder>().Save(order, "Created from Task Screen");
 
-         //            ponumber = order.PONumber;
 
-         //            progress.Report("Updating Documents");
 
-         //            List<PurchaseOrderDocument> docs = new List<PurchaseOrderDocument>();
 
-         //            var taskdocs = new Client<KanbanDocument>().Load(new Filter<KanbanDocument>(x => x.EntityLink.ID).IsEqualTo(Guid.Parse(task.ID)));
 
-         //            foreach (var taskdoc in taskdocs)
 
-         //            {
 
-         //                PurchaseOrderDocument doc = new PurchaseOrderDocument();
 
-         //                doc.DocumentLink.ID = taskdoc.DocumentLink.ID;
 
-         //                doc.EntityLink.ID = order.ID;
 
-         //                docs.Add(doc);
 
-         //            }
 
-         //            new Client<PurchaseOrderDocument>().Save(docs, "", (_, __) => { });
 
-         //            progress.Report("Creating Links");
 
-         //            PurchaseOrderKanban link = new PurchaseOrderKanban();
 
-         //            link.Entity.ID = order.ID;
 
-         //            link.Kanban.ID = kanban.ID;
 
-         //            new Client<PurchaseOrderKanban>().Save(link, "Converting Task -> Purchase Order", (_, __) => { });
 
-         //            progress.Report("Updating Task");
 
-         //            kanban.Category = "Open";
 
-         //            kanban.Completed = DateTime.MinValue;
 
-         //            kanban.Locked = true;
 
-         //            kanban.Title = "(PO#" + order.PONumber.ToString() + ") " + kanban.Title;
 
-         //            new Client<Kanban>().Save(kanban, "Converted to Purchase Order", (_, __) => { });
 
-         //        });
 
-         //        MessageBox.Show(String.Format("Created Purchase Order {0}", ponumber));
 
-         //        Refresh();
 
-         //    }
 
-         //}
 
-         //private void CreateDelivery_Click(object sender, RoutedEventArgs e)
 
-         //{
 
-         //    MenuItem menu = sender as MenuItem;
 
-         //    TaskModel task = menu.Tag as TaskModel;
 
-         //    if (MessageBox.Show("This will convert this task into a Delivery.\n\nDo you wish to continue?", "Confirmation", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
 
-         //        return;
 
-         //    int deliverynumber = 0;
 
-         //    Progress.ShowModal("Creating Delivery", (progress) =>
 
-         //    {
 
-         //        Kanban kanban = new Client<Kanban>().Query(new Filter<Kanban>(x => x.ID).IsEqualTo(task.ID)).Rows.FirstOrDefault()?.ToObject<Kanban>();
 
-         //        Delivery delivery = new Delivery();
 
-         //        delivery.Due = kanban.DueDate;
 
-         //        delivery.Job.ID = kanban.JobLink.ID;
 
-         //        delivery.Job.Synchronise(kanban.JobLink);
 
-         //        delivery.Notes = kanban.Summary;
 
-         //        delivery.Employee.ID = kanban.ManagerLink.ID;
 
-         //        delivery.Employee.Synchronise(kanban.ManagerLink);
 
-         //        new Client<Delivery>().Save(delivery, "Created From Task");
 
-         //        deliverynumber = delivery.Number;
 
-         //        progress.Report("Updating Documents");
 
-         //        List<DeliveryDocument> docs = new List<DeliveryDocument>();
 
-         //        var taskdocs = new Client<KanbanDocument>().Load(new Filter<KanbanDocument>(x => x.EntityLink.ID).IsEqualTo(Guid.Parse(task.ID)));
 
-         //        foreach (var taskdoc in taskdocs)
 
-         //        {
 
-         //            DeliveryDocument doc = new DeliveryDocument();
 
-         //            doc.DocumentLink.ID = taskdoc.DocumentLink.ID;
 
-         //            doc.EntityLink.ID = delivery.ID;
 
-         //            docs.Add(doc);
 
-         //        }
 
-         //        new Client<DeliveryDocument>().Save(docs, "", (_, __) => { });
 
-         //        progress.Report("Creating Links");
 
-         //        DeliveryKanban link = new DeliveryKanban();
 
-         //        link.Entity.ID = delivery.ID;
 
-         //        link.Kanban.ID = kanban.ID;
 
-         //        new Client<DeliveryKanban>().Save(link, "Converting Task -> Delivery", (_, __) => { });
 
-         //        progress.Report("Updating Task");
 
-         //        kanban.Category = "Open";
 
-         //        kanban.Completed = DateTime.MinValue;
 
-         //        kanban.Locked = true;
 
-         //        kanban.Title = "(Del#" + delivery.Number.ToString() + ") " + kanban.Title;
 
-         //        new Client<Kanban>().Save(kanban, "Converted to Delivery", (_, __) => { });
 
-         //    });
 
-         //    MessageBox.Show(String.Format("Created Delivery {0}", deliverynumber));
 
-         //    Refresh();
 
-         //}
 
-         //private void CloseTask_Click(object sender, RoutedEventArgs e)
 
-         //{
 
-         //    if (MessageBox.Show("Are you sure you want to remove the selected tasks from the list?", "Confirm removal", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
 
-         //        return;
 
-         //    Progress.ShowModal("Closing Kanbans", (progress) =>
 
-         //    {
 
-         //        TaskModel task = ((MenuItem)e.Source).Tag as TaskModel;
 
-         //        Kanban[] kanbans = GetSelectedKanbans(task.ID);
 
-         //        for (int i = 0; i < kanbans.Length; i++)
 
-         //        {
 
-         //            Kanban kanban = kanbans[i];
 
-         //            kanban.Closed = DateTime.Now;
 
-         //        }
 
-         //        new Client<Kanban>().Save(kanbans, "Kanban Marked as Closed");
 
-         //        CheckedKanbans.Clear();
 
-         //    });
 
-         //    Refresh();
 
-         //}
 
-         //private void EmailTask_Click(object sender, RoutedEventArgs e)
 
-         //{
 
-         //    MenuItem menu = sender as MenuItem;
 
-         //    TaskModel task = menu.Tag as TaskModel;
 
-         //    Kanban kanban = new Client<Kanban>().Load(new Filter<Kanban>(x => x.ID).IsEqualTo(task.ID)).FirstOrDefault();
 
-         //    List<String> to = new List<string>();
 
-         //    String from = "";
 
-         //    String salutation = "";
 
-         //    if (MyID.HasValue)
 
-         //    {
 
-         //        CoreRow me = _employees.Rows.FirstOrDefault(r => r.Get<Employee, Guid>(c => c.ID).Equals(MyID));
 
-         //        if (me != null)
 
-         //            from = me.Get<Employee, String>(c => c.Name).Split(' ').FirstOrDefault();
 
-         //        if (kanban.EmployeeLink.ID != MyID.Value)
 
-         //        {
 
-         //            CoreRow emp = _employees.Rows.FirstOrDefault(r => r.Get<Employee, Guid>(c => c.ID).Equals(kanban.EmployeeLink.ID));
 
-         //            if (emp != null)
 
-         //            {
 
-         //                String email = emp.Get<Employee, String>(c => c.Email);
 
-         //                if (!string.IsNullOrEmpty(email))
 
-         //                {
 
-         //                    to.Add(email);
 
-         //                    String name = emp.Get<Employee, String>(c => c.Name).Split(' ').FirstOrDefault();
 
-         //                    salutation = salutation + (String.IsNullOrEmpty(salutation) ? "Hi " : " and ") + name;
 
-         //                }
 
-         //            }
 
-         //        }
 
-         //        if (kanban.ManagerLink.ID != MyID.Value)
 
-         //        {
 
-         //            CoreRow emp = _employees.Rows.FirstOrDefault(r => r.Get<Employee, Guid>(c => c.ID).Equals(kanban.ManagerLink.ID));
 
-         //            if (emp != null)
 
-         //            {
 
-         //                String email = emp.Get<Employee, String>(c => c.Email);
 
-         //                if (!string.IsNullOrEmpty(email))
 
-         //                {
 
-         //                    to.Add(email);
 
-         //                    String name = emp.Get<Employee, String>(c => c.Name).Split(' ').FirstOrDefault();
 
-         //                    salutation = salutation + (String.IsNullOrEmpty(salutation) ? "Hi " : " and ") + name;
 
-         //                }
 
-         //            }
 
-         //        }
 
-         //    }
 
-         //    Outlook.Application outlookApp = new Outlook.Application();
 
-         //    Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
 
-         //    mailItem.Subject = "PRS Task: " + kanban.Title;
 
-         //    mailItem.To = String.Join("; ", to);
 
-         //    mailItem.HTMLBody = String.Format("{0},<br><br>Please see the above task in PRS.<br><br>Regards,<br><br>{1}<br><br><b><u>Task Description:</u></b><br><i>{2}</i><br><br><b><u>Additional Notes:</u></b><br>{3}", salutation, from, CoreUtils.StripHTML(kanban.Description), String.Join("\r\n", kanban.Notes));
 
-         //    //mailItem.Attachments.Add(filename, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
 
-         //    mailItem.Display(false);
 
-         //}
 
-         //private void CompleteTask_Click(object sender, RoutedEventArgs e)
 
-         //{
 
-         //    if (MessageBox.Show("Are you sure you want to mark the selected tasks as complete?", "Confirm Completion", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
 
-         //        return;
 
-         //    TaskModel task = ((MenuItem)e.Source).Tag as TaskModel;
 
-         //    Progress.ShowModal("Completing Task", (progress) =>
 
-         //    {
 
-         //        Kanban[] kanbans = GetSelectedKanbans(task.ID);
 
-         //        for (int i = 0; i < kanbans.Length; i++)
 
-         //        {
 
-         //            Kanban kanban = kanbans[i];
 
-         //            kanban.Completed = DateTime.Now;
 
-         //            kanban.Category = "Complete";
 
-         //        }
 
-         //        new Client<Kanban>().Save(kanbans, "Kanban Marked as Completed");
 
-         //        CheckedKanbans.Clear();
 
-         //    });
 
-         //    Refresh();
 
-         //}
 
-         #endregion
 
-         #region Kanban Creation / Editing
 
-         public void CreateKanban()
 
-         {
 
-             var result = Host.CreateKanban(
 
-                 kanban =>
 
-                 {
 
-                     kanban.EmployeeLink.ID = EmployeeID != CoreUtils.FullGuid ? EmployeeID : MyID.Value;
 
-                     kanban.ManagerLink.ID = MyID.Value;
 
-                     kanban.ManagerLink.UserLink.ID = ClientFactory.UserGuid;
 
-                 });
 
-             if (result != null)
 
-                 Refresh(true);
 
-         }
 
-         private void DoEdit(TaskModel task)
 
-         {
 
-             if (task == null)
 
-                 return;
 
-             var result = Host.EditReferences(new[] { task });
 
-             if (result)
 
-                 Refresh(true);
 
-         }
 
-         #endregion
 
-     }
 
- }
 
 
  |